summary refs log tree commit diff
path: root/src/World/World.hpp
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-10-21 17:46:35 +0200
committerMel <einebeere@gmail.com>2022-10-21 17:46:35 +0200
commit20c53c7473fc6cc08944f502f078dfe57bcae1c9 (patch)
tree7e6b09cea68251d4564a363c1a372d6daf746dcf /src/World/World.hpp
parent6ed978051668c08f5a957c97570f364dd580c807 (diff)
downloadmeowcraft-20c53c7473fc6cc08944f502f078dfe57bcae1c9.tar.zst
meowcraft-20c53c7473fc6cc08944f502f078dfe57bcae1c9.zip
Broken infinite world
Diffstat (limited to 'src/World/World.hpp')
-rw-r--r--src/World/World.hpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/World/World.hpp b/src/World/World.hpp
new file mode 100644
index 0000000..3453b18
--- /dev/null
+++ b/src/World/World.hpp
@@ -0,0 +1,38 @@
+#pragma once
+
+#include <memory>
+#include <unordered_set>
+#include <utility>
+#include "Generator.hpp"
+#include "ChunkIndex.hpp"
+
+namespace MC::World {
+
+class World {
+public:
+    World() : m_generator(), m_chunks(), m_visible_chunks() {}
+
+    struct ChunkData {
+        ChunkData(ChunkIndex index, std::shared_ptr<Chunk> chunk)
+            : index(index), chunk(std::move(chunk)), mesh() {}
+
+        ChunkIndex index;
+        std::shared_ptr<Chunk> chunk;
+        std::optional<GFX::BindableMesh> mesh;
+    };
+
+    std::vector<ChunkData> get_visible_chunks(Vector<3> position);
+
+private:
+    std::unordered_set<ChunkIndex> get_visible_chunk_indices(Vector<3> position) const;
+    ChunkData& get_or_generate(ChunkIndex index);
+
+    uint8_t m_view_distance_radius = 6;
+
+    Generator m_generator;
+
+    std::unordered_map<ChunkIndex, ChunkData> m_chunks;
+    std::unordered_set<ChunkIndex> m_visible_chunks;
+};
+
+}