X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2FUnloadState.cpp;fp=src%2Fapp%2FUnloadState.cpp;h=49801bfbc5dcaab19ed7a48d6c994d25959e8ccb;hb=29ee0558fdd951b25f41005ed721241b1f28aefa;hp=0000000000000000000000000000000000000000;hpb=071459d05271dd9376364fc3d8c33bf091724321;p=blank.git diff --git a/src/app/UnloadState.cpp b/src/app/UnloadState.cpp new file mode 100644 index 0000000..49801bf --- /dev/null +++ b/src/app/UnloadState.cpp @@ -0,0 +1,46 @@ +#include "UnloadState.hpp" + +#include "Environment.hpp" +#include "../world/ChunkLoader.hpp" +#include "../world/WorldSave.hpp" + + +namespace blank { + +UnloadState::UnloadState(Environment &env, ChunkLoader &loader) +: env(env) +, loader(loader) +, font(env.assets.LoadFont("DejaVuSans", 24)) +, progress(font) +, cur(loader.Loaded().begin()) +, end(loader.Loaded().end()) +, done(0) +, total(loader.Loaded().size()) +, per_update(64) { + progress.Position(glm::vec3(0.0f), Gravity::CENTER); + progress.Template("Unloading chunks: %d/%d (%d%%)"); +} + + +void UnloadState::Handle(const SDL_Event &) { + // ignore everything +} + +void UnloadState::Update(int dt) { + for (std::size_t i = 0; i < per_update && cur != end; ++i, ++cur, ++done) { + if (cur->ShouldUpdateSave()) { + loader.SaveFile().Write(*cur); + } + } + if (cur == end) { + env.state.PopAll(); + } else { + progress.Update(done, total); + } +} + +void UnloadState::Render(Viewport &viewport) { + progress.Render(viewport); +} + +}