summary refs log tree commit diff
path: root/src/World/ChunkRegistry.cpp
diff options
context:
space:
mode:
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