]> git.localhorst.tv Git - blank.git/blobdiff - src/world/ChunkLoader.hpp
special treatment for players
[blank.git] / src / world / ChunkLoader.hpp
index c9fb8aa2f574e1721ef568ce2be95604f31ff2b0..7cc8dfca917cce00ad8234d9f4339126173f2c7f 100644 (file)
@@ -11,6 +11,7 @@ namespace blank {
 
 class BlockTypeRegistry;
 class Generator;
+class WorldSave;
 
 class ChunkLoader {
 
@@ -21,12 +22,18 @@ public:
                int gen_limit = 16;
        };
 
-       ChunkLoader(const Config &, const BlockTypeRegistry &, const Generator &) noexcept;
+       ChunkLoader(
+               const Config &,
+               const BlockTypeRegistry &,
+               const Generator &,
+               const WorldSave &
+       ) noexcept;
 
-       void Generate(const Chunk::Pos &from, const Chunk::Pos &to);
-       void GenerateSurrounding(const Chunk::Pos &);
+       void Queue(const Chunk::Pos &from, const Chunk::Pos &to);
+       void QueueSurrounding(const Chunk::Pos &);
 
        std::list<Chunk> &Loaded() noexcept { return loaded; }
+       const WorldSave &SaveFile() const noexcept { return save; }
 
        Chunk *Loaded(const Chunk::Pos &) noexcept;
        bool Queued(const Chunk::Pos &) noexcept;
@@ -39,8 +46,13 @@ public:
        void Rebase(const Chunk::Pos &);
        void Update(int dt);
 
+       std::size_t ToLoad() const noexcept { return to_load.size(); }
+       // returns true if the chunk was generated
+       bool LoadOne();
+       void LoadN(std::size_t n);
+
 private:
-       Chunk &Generate(const Chunk::Pos &pos);
+       Chunk &Load(const Chunk::Pos &pos);
        // link given chunk to all loaded neighbors
        void Insert(Chunk &) noexcept;
        // remove a loaded chunk
@@ -55,9 +67,10 @@ private:
 
        const BlockTypeRegistry &reg;
        const Generator &gen;
+       const WorldSave &save;
 
        std::list<Chunk> loaded;
-       std::list<Chunk::Pos> to_generate;
+       std::list<Chunk::Pos> to_load;
        std::list<Chunk> to_free;
 
        IntervalTimer gen_timer;