summary refs log tree commit diff
path: root/src/World/ChunkRegistry.cpp
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2023-07-22 17:35:00 +0200
committerMel <einebeere@gmail.com>2023-07-22 17:35:00 +0200
commit2eef7cf49b7a15559ee7bb6719411bcf67386213 (patch)
tree11eb7a4f437da7bfdde620c10a043960fd423cfb /src/World/ChunkRegistry.cpp
parent23d88e5f1c8f0c8652a07050fcfa8ff126e85d4a (diff)
downloadmeowcraft-2eef7cf49b7a15559ee7bb6719411bcf67386213.tar.zst
meowcraft-2eef7cf49b7a15559ee7bb6719411bcf67386213.zip
Propagation in lighting system
Diffstat (limited to 'src/World/ChunkRegistry.cpp')
-rw-r--r--src/World/ChunkRegistry.cpp28
1 files changed, 28 insertions, 0 deletions
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<I32>(pos.x() / Chunk::Width),
+        static_cast<I32>(pos.z() / Chunk::Width)
+    });
+}
+
+ChunkRegistry::Data& ChunkRegistry::find(ChunkIndex chunk, Position::BlockLocal pos) {
+    return find(chunk.world(pos));
+}
+
+}
\ No newline at end of file