Skip to content

Commit

Permalink
feat(engine): add push method to VoxelPalette
Browse files Browse the repository at this point in the history
  • Loading branch information
roby2014 committed Oct 13, 2023
1 parent 85616ec commit d967078
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions engine/include/cubos/engine/voxels/palette.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ namespace cubos::engine
/// @return Index of the material in the palette (1-based, 0 is empty).
uint16_t add(const VoxelMaterial& material, float similarity = 1.0F);

/// @brief Pushes a material to the palette without checking for uniqueness.
/// @note If the palette is already at its maximum capacity, this function will abort.
/// @param material Material to push.
/// @return Size of the palette.
uint16_t push(const VoxelMaterial& material);

/// @brief Merges another palette into this one.
/// @note All materials equal to @ref VoxelMaterial::Empty will be considered empty and may be
/// overwritten.
Expand Down
11 changes: 11 additions & 0 deletions engine/src/cubos/engine/voxels/palette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ uint16_t VoxelPalette::add(const VoxelMaterial& material, float similarity)
return this->size();
}

uint16_t VoxelPalette::push(const VoxelMaterial& material)
{
if (this->size() == UINT16_MAX)
{
CUBOS_FAIL("Cannot add new material: palette is full");
}

mMaterials.push_back(material);
return this->size();
}

void VoxelPalette::merge(const VoxelPalette& palette, float similarity)
{
for (uint16_t i = 0; i < palette.size(); ++i)
Expand Down

0 comments on commit d967078

Please sign in to comment.