From 68694a9c9d7d27d3b79c7b96bb67f56db2f75c45 Mon Sep 17 00:00:00 2001 From: untodesu Date: Thu, 11 Sep 2025 18:18:08 +0500 Subject: Metadata voxels! --- game/shared/world/feature.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'game/shared/world/feature.cc') diff --git a/game/shared/world/feature.cc b/game/shared/world/feature.cc index 4212043..cbf660e 100644 --- a/game/shared/world/feature.cc +++ b/game/shared/world/feature.cc @@ -4,7 +4,6 @@ #include "shared/world/chunk.hh" #include "shared/world/dimension.hh" -#include "shared/world/voxel_storage.hh" #include "shared/coord.hh" @@ -30,7 +29,7 @@ void world::Feature::place(const voxel_pos& vpos, Dimension* dimension) const } } -void world::Feature::place(const voxel_pos& vpos, const chunk_pos& cpos, VoxelStorage& voxels) const +void world::Feature::place(const voxel_pos& vpos, const chunk_pos& cpos, Chunk& chunk) const { for(const auto [rpos, voxel, overwrite] : (*this)) { auto it_vpos = vpos + rpos; @@ -40,14 +39,14 @@ void world::Feature::place(const voxel_pos& vpos, const chunk_pos& cpos, VoxelSt auto it_lpos = coord::to_local(it_vpos); auto it_index = coord::to_index(it_lpos); - if(voxels[it_index] && !overwrite) { + if(chunk.get_voxel(it_index) && !overwrite) { // There is something in the way // and the called intentionally requested // we do not force feature to overwrite voxels continue; } - voxels[it_index] = voxel; + chunk.set_voxel(voxel, it_index); } } } -- cgit From e9076f22fe2a49d1cd8933e54b7b00c5dd943269 Mon Sep 17 00:00:00 2001 From: untodesu Date: Fri, 12 Sep 2025 13:33:52 +0500 Subject: It compiles --- game/shared/world/feature.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'game/shared/world/feature.cc') diff --git a/game/shared/world/feature.cc b/game/shared/world/feature.cc index cbf660e..e704ced 100644 --- a/game/shared/world/feature.cc +++ b/game/shared/world/feature.cc @@ -4,6 +4,7 @@ #include "shared/world/chunk.hh" #include "shared/world/dimension.hh" +#include "shared/world/voxel.hh" #include "shared/coord.hh" @@ -50,3 +51,30 @@ void world::Feature::place(const voxel_pos& vpos, const chunk_pos& cpos, Chunk& } } } + +void world::Feature::place(const voxel_pos& vpos, const chunk_pos& cpos, VoxelStorage& voxels) const +{ + for(const auto [rpos, voxel, overwrite] : (*this)) { + auto it_vpos = vpos + rpos; + auto it_cpos = coord::to_chunk(it_vpos); + + if(it_cpos == cpos) { + auto it_lpos = coord::to_local(it_vpos); + auto it_index = coord::to_index(it_lpos); + + if(voxels[it_index] && !overwrite) { + // There is something in the way + // and the called intentionally requested + // we do not force feature to overwrite voxels + continue; + } + + if(voxel == nullptr) { + voxels[it_index] = NULL_VOXEL_ID; + } + else { + voxels[it_index] = voxel->get_id(); + } + } + } +} -- cgit From 73cbcdd6e8c849e32abbf9757e603e6a6654e870 Mon Sep 17 00:00:00 2001 From: untodesu Date: Fri, 12 Sep 2025 14:09:34 +0500 Subject: Metaitems --- game/shared/world/feature.cc | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'game/shared/world/feature.cc') diff --git a/game/shared/world/feature.cc b/game/shared/world/feature.cc index e704ced..8fe95f1 100644 --- a/game/shared/world/feature.cc +++ b/game/shared/world/feature.cc @@ -69,12 +69,7 @@ void world::Feature::place(const voxel_pos& vpos, const chunk_pos& cpos, VoxelSt continue; } - if(voxel == nullptr) { - voxels[it_index] = NULL_VOXEL_ID; - } - else { - voxels[it_index] = voxel->get_id(); - } + voxels[it_index] = voxel ? voxel->get_id() : NULL_VOXEL_ID; } } } -- cgit