X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FChunkLoader.hpp;h=7cc8dfca917cce00ad8234d9f4339126173f2c7f;hb=dbfcb12348b80e2582f710acb1e4ed0011889ba2;hp=98b352fbc6e228c08b25c75e15954f01a5652184;hpb=4db5e3765bc93606e340f704ae27ca840eae7045;p=blank.git diff --git a/src/world/ChunkLoader.hpp b/src/world/ChunkLoader.hpp index 98b352f..7cc8dfc 100644 --- a/src/world/ChunkLoader.hpp +++ b/src/world/ChunkLoader.hpp @@ -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 &Loaded() noexcept { return loaded; } + const WorldSave &SaveFile() const noexcept { return save; } Chunk *Loaded(const Chunk::Pos &) noexcept; bool Queued(const Chunk::Pos &) noexcept; @@ -39,19 +46,31 @@ 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; - 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::iterator Remove(std::list::iterator) noexcept; private: Chunk::Pos base; const BlockTypeRegistry ® const Generator &gen; + const WorldSave &save; std::list loaded; - std::list to_generate; + std::list to_load; std::list to_free; IntervalTimer gen_timer;