X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FChunkLoader.hpp;h=0198651f2ab307e137d6b7e220c291461b51dd54;hb=13e676a6e49128ebc6c63b8dd08bef51d360e8e9;hp=7cc8dfca917cce00ad8234d9f4339126173f2c7f;hpb=43820582217f7e4b707d98f2e69d969eb77fc7c3;p=blank.git diff --git a/src/world/ChunkLoader.hpp b/src/world/ChunkLoader.hpp index 7cc8dfc..0198651 100644 --- a/src/world/ChunkLoader.hpp +++ b/src/world/ChunkLoader.hpp @@ -1,83 +1,40 @@ #ifndef BLANK_WORLD_CHUNKLOADER_HPP_ #define BLANK_WORLD_CHUNKLOADER_HPP_ -#include "Chunk.hpp" -#include "../app/IntervalTimer.hpp" - #include 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 &, + ChunkStore &, const Generator &, const WorldSave & ) noexcept; - 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; - 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_load.size(); } + int ToLoad() const noexcept; + // returns true if the chunk was generated + // (as opposed to loaded from file) bool LoadOne(); void LoadN(std::size_t n); private: - Chunk &Load(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::iterator Remove(std::list::iterator) noexcept; - -private: - Chunk::Pos base; - - const BlockTypeRegistry ® + ChunkStore &store; const Generator &gen; const WorldSave &save; - std::list loaded; - std::list to_load; - std::list to_free; - - IntervalTimer gen_timer; - - int load_dist; - int unload_dist; - }; }