From f40d09cb8f712e87691af4912f3630d92d692779 Mon Sep 17 00:00:00 2001 From: untodesu Date: Thu, 11 Dec 2025 15:14:26 +0500 Subject: Shuffle stuff around - Use the new and improved hierarchy I figured out when making Prospero chat - Re-add NSIS scripts, again from Prospero - Update most build and utility scripts with their most recent versions --- src/game/shared/world/voxel_registry.cc | 64 +++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/game/shared/world/voxel_registry.cc (limited to 'src/game/shared/world/voxel_registry.cc') diff --git a/src/game/shared/world/voxel_registry.cc b/src/game/shared/world/voxel_registry.cc new file mode 100644 index 0000000..fae83fa --- /dev/null +++ b/src/game/shared/world/voxel_registry.cc @@ -0,0 +1,64 @@ +#include "shared/pch.hh" + +#include "shared/world/voxel_registry.hh" + +static std::uint64_t registry_checksum = 0U; +emhash8::HashMap world::voxel_registry::names; +std::vector> world::voxel_registry::voxels; + +static void recalculate_checksum(void) +{ + registry_checksum = 0U; + + for(const auto& voxel : world::voxel_registry::voxels) { + registry_checksum = voxel->get_checksum(registry_checksum); + } +} + +world::Voxel* world::voxel_registry::register_voxel(const VoxelBuilder& builder) +{ + assert(builder.get_name().size()); + assert(nullptr == find(builder.get_name())); + + const auto id = static_cast(1 + voxels.size()); + + std::unique_ptr voxel(builder.build(id)); + names.emplace(std::string(builder.get_name()), id); + voxels.push_back(std::move(voxel)); + + recalculate_checksum(); + + return voxels.back().get(); +} + +world::Voxel* world::voxel_registry::find(std::string_view name) +{ + const auto it = names.find(std::string(name)); + + if(it == names.end()) { + return nullptr; + } + + return voxels[it->second - 1].get(); +} + +world::Voxel* world::voxel_registry::find(voxel_id id) +{ + if(id == NULL_VOXEL_ID || id > voxels.size()) { + return nullptr; + } + + return voxels[id - 1].get(); +} + +void world::voxel_registry::purge(void) +{ + registry_checksum = 0U; + voxels.clear(); + names.clear(); +} + +std::uint64_t world::voxel_registry::get_checksum(void) +{ + return registry_checksum; +} -- cgit