From 2eef7cf49b7a15559ee7bb6719411bcf67386213 Mon Sep 17 00:00:00 2001 From: Mel Date: Sat, 22 Jul 2023 17:35:00 +0200 Subject: Propagation in lighting system --- src/World/ChunkRegistry.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/World/ChunkRegistry.cpp (limited to 'src/World/ChunkRegistry.cpp') diff --git a/src/World/ChunkRegistry.cpp b/src/World/ChunkRegistry.cpp new file mode 100644 index 0000000..41fd1b0 --- /dev/null +++ b/src/World/ChunkRegistry.cpp @@ -0,0 +1,28 @@ +#include "ChunkRegistry.hpp" + +namespace MC::World { + +ChunkRegistry::Data& ChunkRegistry::get(ChunkIndex index) { + auto entry = m_chunks.find(index); + if (entry == m_chunks.end()) { + Data data{index, Status::Empty}; + + m_chunks.insert({index, std::move(data)}); + return m_chunks.at(index); + } + + return entry->second; +} + +ChunkRegistry::Data& ChunkRegistry::find(Position::BlockWorld pos) { + return get({ + static_cast(pos.x() / Chunk::Width), + static_cast(pos.z() / Chunk::Width) + }); +} + +ChunkRegistry::Data& ChunkRegistry::find(ChunkIndex chunk, Position::BlockLocal pos) { + return find(chunk.world(pos)); +} + +} \ No newline at end of file -- cgit 1.4.1