diff options
| author | untodesu <kirill@untode.su> | 2025-03-16 20:18:16 +0500 |
|---|---|---|
| committer | untodesu <kirill@untode.su> | 2025-03-16 20:18:16 +0500 |
| commit | a8fa9fe920d4ed48ed1b88a6e585cdbff648039e (patch) | |
| tree | 63520fe106ff2e445fa93d2992d14d4f7e60b8e5 /game/shared/feature.cc | |
| parent | 933ed978a21d5ffefc376d66f0dc9f5354292ca7 (diff) | |
| download | voxelius-a8fa9fe920d4ed48ed1b88a6e585cdbff648039e.tar.bz2 voxelius-a8fa9fe920d4ed48ed1b88a6e585cdbff648039e.zip | |
Improved terrain generation - features! [1/2]
- @reglnk asked me to commit this early to experiment with this
weird-ass heightmap bug that messes with tree placement
Diffstat (limited to 'game/shared/feature.cc')
| -rw-r--r-- | game/shared/feature.cc | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/game/shared/feature.cc b/game/shared/feature.cc new file mode 100644 index 0000000..6f884b2 --- /dev/null +++ b/game/shared/feature.cc @@ -0,0 +1,51 @@ +#include "shared/pch.hh" +#include "shared/feature.hh" + +#include "shared/chunk.hh" +#include "shared/coord.hh" +#include "shared/dimension.hh" +#include "shared/voxel_storage.hh" + +void Feature::place(const voxel_pos &vpos, Dimension *dimension, bool overwrite) const +{ + for(const auto &it : (*this)) { + auto it_vpos = vpos + it.first; + auto it_cpos = coord::to_chunk(it_vpos); + + if(auto chunk = dimension->create_chunk(it_cpos)) { + auto it_lpos = coord::to_local(it_vpos); + auto it_index = coord::to_index(it_lpos); + + 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; + } + + chunk->set_voxel(it.second, it_index); + } + } +} + +void Feature::place(const voxel_pos &vpos, const chunk_pos &cpos, VoxelStorage &voxels, bool overwrite) const +{ + for(const auto &it : (*this)) { + auto it_vpos = vpos + it.first; + 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; + } + + voxels[it_index] = it.second; + } + } +} |
