]> git.localhorst.tv Git - blank.git/blobdiff - src/world/ChunkLoader.hpp
try to cleanly destruct world
[blank.git] / src / world / ChunkLoader.hpp
index 6a8c2c19ac30d2143d42f85f01512d68c63af531..1c0b98f792b349e69a9f7e997228038cdffcba5a 100644 (file)
@@ -1,73 +1,39 @@
 #ifndef BLANK_WORLD_CHUNKLOADER_HPP_
 #define BLANK_WORLD_CHUNKLOADER_HPP_
 
-#include "Chunk.hpp"
-#include "../app/IntervalTimer.hpp"
-
-#include <list>
+#include <cstddef>
 
 
 namespace blank {
 
-class BlockTypeRegistry;
+class ChunkStore;
 class Generator;
+class WorldSave;
 
 class ChunkLoader {
 
 public:
-       struct Config {
-               int load_dist = 6;
-               int unload_dist = 8;
-               int gen_limit = 16;
-       };
-
-       ChunkLoader(const Config &, const BlockTypeRegistry &, const Generator &) noexcept;
-
-       void Generate(const Chunk::Pos &from, const Chunk::Pos &to);
-       void GenerateSurrounding(const Chunk::Pos &);
+       ChunkLoader(
+               ChunkStore &,
+               const Generator &,
+               const WorldSave &
+       ) noexcept;
 
-       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;
-       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(int dt);
 
-       std::size_t ToLoad() const noexcept { return to_generate.size(); }
-       void LoadOne();
-       void LoadN(std::size_t n);
+       int ToLoad() const noexcept;
 
-private:
-       Chunk &Generate(const Chunk::Pos &pos);
-       // link given chunk to all loaded neighbors
-       void Insert(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;
+       // returns true if the chunk was generated
+       // (as opposed to loaded from file)
+       bool LoadOne();
+       void LoadN(std::size_t n);
 
 private:
-       Chunk::Pos base;
-
-       const BlockTypeRegistry &reg;
+       ChunkStore &store;
        const Generator &gen;
-
-       std::list<Chunk> loaded;
-       std::list<Chunk::Pos> to_generate;
-       std::list<Chunk> to_free;
-
-       IntervalTimer gen_timer;
-
-       int load_dist;
-       int unload_dist;
+       const WorldSave &save;
 
 };