Skip to content

Commit

Permalink
fix(tesseratos): build and clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
Scarface1809 committed Sep 30, 2024
1 parent e19500f commit 04a7735
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 38 deletions.
6 changes: 4 additions & 2 deletions engine/include/cubos/engine/voxels/voxel_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ namespace cubos::engine
/// @brief Constructs an empty VoxelModel
VoxelModel() = default;

static constexpr uint32_t MAX_MATERIALS = 65536;

uint16_t getMatricesSize() const;

const VoxelPalette& getPalette() const;
Expand Down Expand Up @@ -73,7 +75,7 @@ namespace cubos::engine
bool writeTo(core::memory::Stream& stream) const;

private:
std::vector<QBMatrix> matrices;
VoxelPalette palette;
std::vector<QBMatrix> mAtrices;
VoxelPalette mPalette;
};
} // namespace cubos::engine
6 changes: 3 additions & 3 deletions engine/src/assets/assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ AnyAsset Assets::getAsset(std::string_view path)
{
for (const auto& [uuid, entry] : mEntries)
{
auto path_meta = entry->meta.get("path");
if (path_meta.has_value() && path_meta.value() == path)
auto pathMeta = entry->meta.get("path");
if (pathMeta.has_value() && pathMeta.value() == path)
{
return AnyAsset(uuid);
return {uuid};
}
}
return {};
Expand Down
6 changes: 1 addition & 5 deletions engine/src/voxels/grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ VoxelGrid& VoxelGrid::operator=(VoxelGrid&& other) noexcept
return *this;
}

VoxelGrid::VoxelGrid(const VoxelGrid& other)
: mSize(other.mSize)
, mIndices(other.mIndices)
{
}
VoxelGrid::VoxelGrid(const VoxelGrid& other) = default;

VoxelGrid::VoxelGrid()
{
Expand Down
40 changes: 20 additions & 20 deletions engine/src/voxels/voxel_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,32 @@ CUBOS_REFLECT_IMPL(VoxelModel)

uint16_t VoxelModel::getMatricesSize() const
{
return static_cast<uint16_t>(matrices.size());
return static_cast<uint16_t>(mAtrices.size());
}

const VoxelPalette& VoxelModel::getPalette() const
{
return palette;
return mPalette;
}

void VoxelModel::setPalette(const VoxelPalette& palette)
{
this->palette = palette;
this->mPalette = palette;
}

const VoxelGrid& VoxelModel::getGrid(uint16_t index) const
{
return matrices[index].grid;
return mAtrices[index].grid;
}

void VoxelModel::setGrid(uint16_t index, const VoxelGrid& grid, const glm::ivec3& position)
{
if (index >= matrices.size())
if (index >= mAtrices.size())
{
matrices.resize(index + 1);
mAtrices.resize(index + 1);
}
matrices[index].grid = grid;
matrices[index].position = position;
mAtrices[index].grid = grid;
mAtrices[index].position = position;
}

bool VoxelModel::loadFrom(Stream& stream)
Expand Down Expand Up @@ -100,7 +100,7 @@ bool VoxelModel::loadFrom(Stream& stream)
}

// Parse the matrices.
matrices.resize(numMatrices);
mAtrices.resize(numMatrices);
for (uint32_t i = 0; i < numMatrices; ++i)
{
uint8_t nameLen;
Expand All @@ -123,7 +123,7 @@ bool VoxelModel::loadFrom(Stream& stream)
sizeX = memory::fromLittleEndian(sizeX);
sizeY = memory::fromLittleEndian(sizeY);
sizeZ = memory::fromLittleEndian(sizeZ);
matrices[i].grid.setSize({sizeX, sizeY, sizeZ});
mAtrices[i].grid.setSize({sizeX, sizeY, sizeZ});

// Read the matrix position.
stream.read(&posX, 4);
Expand All @@ -132,7 +132,7 @@ bool VoxelModel::loadFrom(Stream& stream)
posX = memory::fromLittleEndian(posX);
posY = memory::fromLittleEndian(posY);
posZ = memory::fromLittleEndian(posZ);
matrices[i].position = glm::ivec3(posX, posY, posZ);
mAtrices[i].position = glm::ivec3(posX, posY, posZ);

// Read the matrix voxels.
if (compressed == 0)
Expand Down Expand Up @@ -163,28 +163,28 @@ bool VoxelModel::loadFrom(Stream& stream)
std::size_t mat;
for (mat = 1; mat < nextMat; ++mat)
{
if (palette.get(static_cast<uint16_t>(mat)).color == colorVec)
if (mPalette.get(static_cast<uint16_t>(mat)).color == colorVec)
{
break;
}
}
if (mat == nextMat)
{
if (mat >= 65536)
if (mat >= MAX_MATERIALS)
{
CUBOS_ERROR("Too many materials, max is 65536");
CUBOS_ERROR("Too many materials, max is {}", MAX_MATERIALS);
return false;
}

// Add the material to the palette.
VoxelMaterial desc;
desc.color = colorVec;
palette.set(static_cast<uint16_t>(mat), desc);
mPalette.set(static_cast<uint16_t>(mat), desc);
nextMat += 1;
}

// Set the voxel.
matrices[i].grid.set(glm::ivec3(x, y, z), static_cast<uint16_t>(mat));
mAtrices[i].grid.set(glm::ivec3(x, y, z), static_cast<uint16_t>(mat));
}
}
}
Expand All @@ -210,7 +210,7 @@ bool VoxelModel::writeTo(core::memory::Stream& stream) const
uint32_t zAxisOrientation = 0; // Assuming 0
uint32_t compressed = 0; // No compression
uint32_t visibilityMaskEncoded = 0; // No visibility mask
uint32_t numMatrices = static_cast<uint32_t>(matrices.size());
auto numMatrices = static_cast<uint32_t>(mAtrices.size());

stream.write(&colorFormat, 4);
stream.write(&zAxisOrientation, 4);
Expand All @@ -219,13 +219,13 @@ bool VoxelModel::writeTo(core::memory::Stream& stream) const
stream.write(&numMatrices, 4);

// Write each matrix.
for (const auto& matrix : matrices)
for (const auto& matrix : mAtrices)
{
const auto& grid = matrix.grid;

// Write the matrix name.
std::string name = "matrix"; // Assuming a default name or you may have a name in the matrix structure
uint8_t nameLen = static_cast<uint8_t>(name.size());
auto nameLen = static_cast<uint8_t>(name.size());
stream.write(&nameLen, 1);
stream.write(name.data(), nameLen);

Expand Down Expand Up @@ -277,7 +277,7 @@ bool VoxelModel::writeTo(core::memory::Stream& stream) const
else
{
// Write the color of the voxel.
auto matDesc = palette.get(voxel);
auto matDesc = mPalette.get(voxel);
auto colorVec = matDesc.color;

color[0] = static_cast<uint8_t>(colorVec.r * 255.0F);
Expand Down
2 changes: 1 addition & 1 deletion engine/src/voxels/voxel_model_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bool VoxelModelBridge::loadFromFile(Assets& assets, const AnyAsset& handle, Stre
VoxelModel model{};
if (model.loadFrom(stream))
{
assets.store(handle, std::move(model));
assets.store(handle, model);
return true;
}
return false;
Expand Down
14 changes: 7 additions & 7 deletions tools/tesseratos/src/tesseratos/importer/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ namespace

// Generic
AnyAsset currentAsset;
std::string currentAssetPath = "";
std::string currentAssetPath;
bool showError = false;
bool isModelLoaded = false;

// VoxelModel specifics
int gridMax = 0;
int gridCount = 0;
std::unordered_map<std::size_t, std::string> gridFilePaths;
std::string paletteFilePath = "";
std::string paletteFilePath;

// Other Imports...
};
Expand Down Expand Up @@ -169,7 +169,7 @@ static void showImport(Assets& assets, cubos::core::ecs::EventReader<AssetSelect
state.isModelLoaded = false;
return;
}
else if (assets.type(state.currentAsset).is<VoxelModel>())
if (assets.type(state.currentAsset).is<VoxelModel>())
{
std::optional<std::reference_wrapper<const VoxelModel>> voxelModelResult;
if (assetChanged)
Expand All @@ -195,7 +195,7 @@ static void showImport(Assets& assets, cubos::core::ecs::EventReader<AssetSelect

ImGui::Text("Palette File Path:");
char paletteBuffer[256] = "";
strncpy(paletteBuffer, state.paletteFilePath.c_str(), sizeof(paletteBuffer));
strncpy(paletteBuffer, state.paletteFilePath.c_str(), sizeof(paletteBuffer) - 1);
if (ImGui::InputTextWithHint("##paletteFilePath", "Ex:/assets/models/main.pal", paletteBuffer,
sizeof(paletteBuffer)))
{
Expand All @@ -216,11 +216,11 @@ static void showImport(Assets& assets, cubos::core::ecs::EventReader<AssetSelect
state.gridCount = state.gridMax;
}

for (int i = 0; i < state.gridCount; ++i)
for (unsigned long i = 0; i < static_cast<unsigned long>(state.gridCount); ++i)
{
char buffer[256];
snprintf(buffer, sizeof(buffer), "Grid File Path %d:", i + 1);
ImGui::Text(buffer);
ImGui::Text("%s", buffer);

char inputBuffer[256];
auto it = state.gridFilePaths.find(i);
Expand All @@ -230,7 +230,7 @@ static void showImport(Assets& assets, cubos::core::ecs::EventReader<AssetSelect
}

std::string& gridPath = state.gridFilePaths[i];
strncpy(inputBuffer, gridPath.c_str(), sizeof(inputBuffer));
strncpy(inputBuffer, gridPath.c_str(), sizeof(inputBuffer) - 1);
if (ImGui::InputTextWithHint(("##gridFilePath" + std::to_string(i)).c_str(), "Ex:/assets/models/car.grd",
inputBuffer, sizeof(inputBuffer)))
{
Expand Down

0 comments on commit 04a7735

Please sign in to comment.