From f210a86c1406ccc6dfd6f14181dd7a1274ee0de4 Mon Sep 17 00:00:00 2001 From: untodesu Date: Fri, 12 Sep 2025 15:09:01 +0500 Subject: Random ticking? In my game?! Hell yeah! --- game/server/world/random_tick.cc | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 game/server/world/random_tick.cc (limited to 'game/server/world/random_tick.cc') 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); + } + } +} -- cgit