]> git.localhorst.tv Git - blank.git/blobdiff - src/chunk.hpp
recycle chunks flagged for deletion
[blank.git] / src / chunk.hpp
index 3c301803495038beeb99f59db847db5ffa6d1498..e442e4e289107ee735417c9677ffa6157b42396d 100644 (file)
@@ -5,6 +5,7 @@
 #include "geometry.hpp"
 #include "model.hpp"
 
+#include <list>
 #include <vector>
 #include <glm/glm.hpp>
 
@@ -18,7 +19,7 @@ public:
        using Pos = glm::tvec3<int>;
 
 public:
-       Chunk();
+       explicit Chunk(const BlockTypeRegistry &);
 
        Chunk(Chunk &&);
        Chunk &operator =(Chunk &&);
@@ -59,6 +60,8 @@ public:
        Block &BlockAt(const Block::Pos &pos) { return BlockAt(ToIndex(pos)); }
        const Block &BlockAt(const Block::Pos &pos) const { return BlockAt(ToIndex(pos)); }
 
+       const BlockType &Type(const Block &b) const { return *types->Get(b.type); }
+
        bool Intersection(
                const Ray &,
                const glm::mat4 &M,
@@ -70,13 +73,14 @@ public:
        const Pos &Position() const { return position; }
        glm::mat4 Transform(const Pos &offset) const;
 
+       void CheckUpdate();
        void Draw();
 
 private:
-       int VertexCount() const;
        void Update();
 
 private:
+       const BlockTypeRegistry *types;
        std::vector<Block> blocks;
        Model model;
        Pos position;
@@ -84,6 +88,41 @@ private:
 
 };
 
+
+class Generator;
+
+class ChunkLoader {
+
+public:
+       ChunkLoader(const BlockTypeRegistry &, const Generator &);
+
+       void Generate(const Chunk::Pos &from, const Chunk::Pos &to);
+
+       std::list<Chunk> &Loaded() { return loaded; }
+
+       Chunk *Loaded(const Chunk::Pos &);
+       bool Queued(const Chunk::Pos &);
+       bool Known(const Chunk::Pos &);
+       Chunk &ForceLoad(const Chunk::Pos &);
+
+       void Rebase(const Chunk::Pos &);
+       void Update();
+
+private:
+       Chunk::Pos base;
+
+       const BlockTypeRegistry &reg;
+       const Generator &gen;
+
+       std::list<Chunk> loaded;
+       std::list<Chunk::Pos> to_generate;
+       std::list<Chunk> to_free;
+
+       int load_dist;
+       int unload_dist;
+
+};
+
 }
 
 #endif