]> git.localhorst.tv Git - blank.git/blobdiff - src/world/ChunkLoader.hpp
made chunk neighbor linkage a little safer
[blank.git] / src / world / ChunkLoader.hpp
index b1d0c7b9e1e6272059b70f5f2920cb881c848f41..c9fb8aa2f574e1721ef568ce2be95604f31ff2b0 100644 (file)
@@ -2,6 +2,7 @@
 #define BLANK_WORLD_CHUNKLOADER_HPP_
 
 #include "Chunk.hpp"
+#include "../app/IntervalTimer.hpp"
 
 #include <list>
 
@@ -17,6 +18,7 @@ public:
        struct Config {
                int load_dist = 6;
                int unload_dist = 8;
+               int gen_limit = 16;
        };
 
        ChunkLoader(const Config &, const BlockTypeRegistry &, const Generator &) noexcept;
@@ -31,13 +33,22 @@ public:
        bool Known(const Chunk::Pos &) noexcept;
        Chunk &ForceLoad(const Chunk::Pos &);
 
+       bool OutOfRange(const Chunk &c) const noexcept { return OutOfRange(c.Position()); }
+       bool OutOfRange(const Chunk::Pos &) const noexcept;
+
        void Rebase(const Chunk::Pos &);
-       void Update();
+       void Update(int dt);
 
 private:
        Chunk &Generate(const Chunk::Pos &pos);
+       // link given chunk to all loaded neighbors
        void Insert(Chunk &) noexcept;
-       void Remove(Chunk &) noexcept;
+       // remove a loaded chunk
+       // this unlinks it from its neighbors as well as moves it to the free list
+       // given iterator must point to a chunk from the loaded list
+       // returns an iterator to the chunk following the removed one
+       // in the loaded list (end for the last one)
+       std::list<Chunk>::iterator Remove(std::list<Chunk>::iterator) noexcept;
 
 private:
        Chunk::Pos base;
@@ -49,6 +60,8 @@ private:
        std::list<Chunk::Pos> to_generate;
        std::list<Chunk> to_free;
 
+       IntervalTimer gen_timer;
+
        int load_dist;
        int unload_dist;