From d967078d13162ee6787dfc8cc918ddc7ed768912 Mon Sep 17 00:00:00 2001 From: roby2014 Date: Wed, 11 Oct 2023 20:28:03 +0100 Subject: [PATCH] feat(engine): add push method to VoxelPalette --- engine/include/cubos/engine/voxels/palette.hpp | 6 ++++++ engine/src/cubos/engine/voxels/palette.cpp | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/engine/include/cubos/engine/voxels/palette.hpp b/engine/include/cubos/engine/voxels/palette.hpp index ea8b3b696..63b6c36aa 100644 --- a/engine/include/cubos/engine/voxels/palette.hpp +++ b/engine/include/cubos/engine/voxels/palette.hpp @@ -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. diff --git a/engine/src/cubos/engine/voxels/palette.cpp b/engine/src/cubos/engine/voxels/palette.cpp index e6cd6bebf..523844d83 100644 --- a/engine/src/cubos/engine/voxels/palette.cpp +++ b/engine/src/cubos/engine/voxels/palette.cpp @@ -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)