From d8f0fcb101c21b3c4d746d20da6e56e7591006e4 Mon Sep 17 00:00:00 2001 From: untodesu Date: Sat, 22 Mar 2025 13:11:48 +0500 Subject: Generate trees of different height --- game/server/overworld.cc | 19 ++++++++++++------- game/server/overworld.hh | 6 ++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/game/server/overworld.cc b/game/server/overworld.cc index eb32d3f..78747fc 100644 --- a/game/server/overworld.cc +++ b/game/server/overworld.cc @@ -67,7 +67,11 @@ Overworld::Overworld(const char *name) : Dimension(name, -30.0f) { m_bottommost_chunk.set_limits(-64, -4); m_terrain_variation.set_limits(16, 256); - compute_tree_feature(32U, m_feat_tree, game_voxels::oak_log, game_voxels::oak_leaves); + + compute_tree_feature(4U, m_feat_tree[0], game_voxels::oak_log, game_voxels::oak_leaves); + compute_tree_feature(5U, m_feat_tree[1], game_voxels::oak_log, game_voxels::oak_leaves); + compute_tree_feature(6U, m_feat_tree[2], game_voxels::oak_log, game_voxels::oak_leaves); + compute_tree_feature(8U, m_feat_tree[3], game_voxels::oak_log, game_voxels::oak_leaves); } void Overworld::init(Config &config) @@ -203,11 +207,12 @@ const Overworld_Metadata &Overworld::get_or_create_metadata(const chunk_pos_xz & } } - auto tree_density = static_cast(fnlGetNoise2D(&m_fnl_nvdi, cpos.x, cpos.y) * 2.0 + 2.0f); + auto nvdi_value = fnlGetNoise2D(&m_fnl_nvdi, cpos.x, cpos.y); + auto tree_density = (nvdi_value > 0.0f) ? 4U : 0U; // Generate tree locations for this chunk while(metadata.trees.size() < tree_density) { - auto lpos = local_pos_xz((twister() % CHUNK_SIZE), (twister() % CHUNK_SIZE)); + auto lpos = local_pos((twister() % CHUNK_SIZE), (twister() % OW_NUM_TREES), (twister() % CHUNK_SIZE)); auto is_unique = true; for(const auto &check_lpos : metadata.trees) { @@ -340,8 +345,8 @@ void Overworld::generate_features(const chunk_pos &cpos, VoxelStorage &voxels) const auto &cpos_xz = tree_chunks[i]; const auto &metadata = get_or_create_metadata(cpos_xz); - for(const auto &lpos_xz : metadata.trees) { - auto hdx = static_cast(lpos_xz.x + lpos_xz.y * CHUNK_SIZE); + for(const auto &tree_info : metadata.trees) { + auto hdx = static_cast(tree_info.x + tree_info.z * CHUNK_SIZE); auto height = metadata.heightmap[hdx]; if(height == std::numeric_limits::min()) { @@ -350,7 +355,7 @@ void Overworld::generate_features(const chunk_pos &cpos, VoxelStorage &voxels) } auto cpos_xyz = chunk_pos(cpos_xz.x, 0, cpos_xz.y); - auto lpos_xyz = local_pos(lpos_xz.x, 0, lpos_xz.y); + auto lpos_xyz = local_pos(tree_info.x, 0, tree_info.z); auto vpos = coord::to_voxel(cpos_xyz, lpos_xyz); vpos.y = height; @@ -360,7 +365,7 @@ void Overworld::generate_features(const chunk_pos &cpos, VoxelStorage &voxels) continue; } - m_feat_tree.place(vpos + DIR_UP, cpos, voxels); + m_feat_tree[tree_info.y].place(vpos + DIR_UP, cpos, voxels); } } } diff --git a/game/server/overworld.hh b/game/server/overworld.hh index 2f7b67e..979e5a3 100644 --- a/game/server/overworld.hh +++ b/game/server/overworld.hh @@ -8,10 +8,12 @@ #include "shared/dimension.hh" #include "shared/feature.hh" +constexpr static unsigned int OW_NUM_TREES = 4U; + struct Overworld_Metadata final { dimension_entropy_map entropy; dimension_height_map heightmap; - std::vector trees; + std::vector trees; }; class Overworld final : public Dimension { @@ -52,7 +54,7 @@ private: fnl_state m_fnl_nvdi; private: - Feature m_feat_tree; + Feature m_feat_tree[OW_NUM_TREES]; private: std::mutex m_mutex; -- cgit