From: Daniel Karbach Date: Mon, 10 Aug 2015 14:48:59 +0000 (+0200) Subject: different limits for reading and generating chunks X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=071459d05271dd9376364fc3d8c33bf091724321;p=blank.git different limits for reading and generating chunks --- diff --git a/TODO b/TODO index 1ba83ab..4377b24 100644 --- a/TODO +++ b/TODO @@ -25,6 +25,12 @@ command line usefull for development and later on world administration +persistence + + add world shutdown state to save dirty chunks when exiting + + store some kind of byte order mark? + networking exchange of chunks and entities diff --git a/src/world/ChunkLoader.hpp b/src/world/ChunkLoader.hpp index b2730a6..81e7178 100644 --- a/src/world/ChunkLoader.hpp +++ b/src/world/ChunkLoader.hpp @@ -46,7 +46,8 @@ public: void Update(int dt); std::size_t ToLoad() const noexcept { return to_load.size(); } - void LoadOne(); + // returns true if the chunk was generated + bool LoadOne(); void LoadN(std::size_t n); private: diff --git a/src/world/chunk.cpp b/src/world/chunk.cpp index c4ce097..2d5b7ce 100644 --- a/src/world/chunk.cpp +++ b/src/world/chunk.cpp @@ -854,11 +854,23 @@ void ChunkLoader::QueueSurrounding(const Chunk::Pos &pos) { } void ChunkLoader::Update(int dt) { - // check if a chunk generation is scheduled for this frame - // and if there's a chunk waiting to be generated + // check if a chunk load is scheduled for this frame + // and if there's chunks waiting to be loaded gen_timer.Update(dt); if (gen_timer.Hit()) { - LoadOne(); + // we may + // load until one of load or generation limits was hit + constexpr int max_load = 10; + constexpr int max_gen = 1; + int loaded = 0; + int generated = 0; + while (!to_load.empty() && loaded < max_load && generated < max_gen) { + if (LoadOne()) { + ++generated; + } else { + ++loaded; + } + } } constexpr int max_save = 10; @@ -881,8 +893,8 @@ void ChunkLoader::LoadN(std::size_t n) { } } -void ChunkLoader::LoadOne() { - if (to_load.empty()) return; +bool ChunkLoader::LoadOne() { + if (to_load.empty()) return false; // take position of next chunk in queue Chunk::Pos pos(to_load.front()); @@ -893,7 +905,7 @@ void ChunkLoader::LoadOne() { if (iter->Position() == pos) { loaded.splice(loaded.end(), to_free, iter); Insert(loaded.back()); - return; + return false; } } @@ -906,14 +918,17 @@ void ChunkLoader::LoadOne() { loaded.splice(loaded.end(), to_free, to_free.begin()); } + bool generated = false; Chunk &chunk = loaded.back(); chunk.Position(pos); if (save.Exists(pos)) { save.Read(chunk); } else { gen(chunk); + generated = true; } Insert(chunk); + return generated; } }