summaryrefslogtreecommitdiffstats
path: root/game/server/world
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-09-12 16:16:06 +0500
committeruntodesu <kirill@untode.su>2025-09-12 16:16:06 +0500
commitfc80fa024fc93dac6ea89461ef36f455c5e468a2 (patch)
tree7c4ea8f03b6778572d59784dc28b600e3f8f2268 /game/server/world
parent12947aafcc6a6eb362cc454e2149796ec9265743 (diff)
parent522a7514012da86f7b9643179f0763746f3b232e (diff)
downloadvoxelius-fc80fa024fc93dac6ea89461ef36f455c5e468a2.tar.bz2
voxelius-fc80fa024fc93dac6ea89461ef36f455c5e468a2.zip
Merge pull request #15 from untodesu/metavoxels
Metavoxels
Diffstat (limited to 'game/server/world')
-rw-r--r--game/server/world/CMakeLists.txt2
-rw-r--r--game/server/world/overworld.cc12
-rw-r--r--game/server/world/random_tick.cc40
-rw-r--r--game/server/world/random_tick.hh14
4 files changed, 63 insertions, 5 deletions
diff --git a/game/server/world/CMakeLists.txt b/game/server/world/CMakeLists.txt
index e8fd4be..58a2216 100644
--- a/game/server/world/CMakeLists.txt
+++ b/game/server/world/CMakeLists.txt
@@ -2,6 +2,8 @@ target_sources(vserver PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/inhabited.hh"
"${CMAKE_CURRENT_LIST_DIR}/overworld.cc"
"${CMAKE_CURRENT_LIST_DIR}/overworld.hh"
+ "${CMAKE_CURRENT_LIST_DIR}/random_tick.cc"
+ "${CMAKE_CURRENT_LIST_DIR}/random_tick.hh"
"${CMAKE_CURRENT_LIST_DIR}/universe.cc"
"${CMAKE_CURRENT_LIST_DIR}/universe.hh"
"${CMAKE_CURRENT_LIST_DIR}/unloader.cc"
diff --git a/game/server/world/overworld.cc b/game/server/world/overworld.cc
index eb801de..43059d8 100644
--- a/game/server/world/overworld.cc
+++ b/game/server/world/overworld.cc
@@ -4,13 +4,15 @@
#include "core/math/vectors.hh"
+#include "shared/world/voxel.hh"
#include "shared/world/voxel_storage.hh"
#include "shared/coord.hh"
#include "shared/game_voxels.hh"
// FIXME: load these from a file
-static void compute_tree_feature(unsigned int height, world::Feature& feature, voxel_id log_voxel, voxel_id leaves_voxel)
+static void compute_tree_feature(unsigned int height, world::Feature& feature, const world::Voxel* log_voxel,
+ const world::Voxel* leaves_voxel)
{
// Ensure the tree height is too small
height = math::max<unsigned int>(height, 4U);
@@ -251,12 +253,12 @@ void world::Overworld::generate_terrain(const chunk_pos& cpos, VoxelStorage& vox
}
if(vpos.y < -variation) {
- voxels[i] = game_voxels::stone;
+ voxels[i] = game_voxels::stone->get_id();
continue;
}
if(is_inside_terrain(vpos)) {
- voxels[i] = game_voxels::stone;
+ voxels[i] = game_voxels::stone->get_id();
continue;
}
}
@@ -308,10 +310,10 @@ void world::Overworld::generate_surface(const chunk_pos& cpos, VoxelStorage& vox
if(depth < 5U) {
if(depth == 0U) {
- voxels[i] = game_voxels::grass;
+ voxels[i] = game_voxels::grass->get_id();
}
else {
- voxels[i] = game_voxels::dirt;
+ voxels[i] = game_voxels::dirt->get_id();
}
}
}
diff --git a/game/server/world/random_tick.cc b/game/server/world/random_tick.cc
new file mode 100644
index 0000000..c5fa47c
--- /dev/null
+++ b/game/server/world/random_tick.cc
@@ -0,0 +1,40 @@
+#include "server/pch.hh"
+
+#include "server/world/random_tick.hh"
+
+#include "core/config/number.hh"
+
+#include "core/io/config_map.hh"
+
+#include "shared/world/chunk.hh"
+#include "shared/world/dimension.hh"
+#include "shared/world/voxel.hh"
+
+#include "shared/coord.hh"
+
+#include "server/globals.hh"
+
+static config::Int random_tick_speed(2, 1, 1000);
+static std::mt19937_64 random_source;
+
+void world::random_tick::init(void)
+{
+ globals::server_config.add_value("world.random_tick_speed", random_tick_speed);
+
+ random_source.seed(std::random_device {}());
+}
+
+void world::random_tick::tick(const chunk_pos& cpos, Chunk* chunk)
+{
+ assert(chunk);
+
+ for(int i = 0; i < random_tick_speed.get_value(); ++i) {
+ auto voxel_index = random_source() % CHUNK_VOLUME;
+ auto lpos = coord::to_local(voxel_index);
+ auto vpos = coord::to_voxel(cpos, lpos);
+
+ if(auto voxel = chunk->get_voxel(lpos)) {
+ voxel->on_tick(chunk->get_dimension(), vpos);
+ }
+ }
+}
diff --git a/game/server/world/random_tick.hh b/game/server/world/random_tick.hh
new file mode 100644
index 0000000..4ef1691
--- /dev/null
+++ b/game/server/world/random_tick.hh
@@ -0,0 +1,14 @@
+#pragma once
+
+#include "shared/types.hh"
+
+namespace world
+{
+class Chunk;
+} // namespace world
+
+namespace world::random_tick
+{
+void init(void);
+void tick(const chunk_pos& cpos, Chunk* chunk);
+} // namespace world::random_tick