]> git.localhorst.tv Git - blank.git/blobdiff - src/standalone/UnloadState.cpp
move standalone stuff to its own dir
[blank.git] / src / standalone / UnloadState.cpp
diff --git a/src/standalone/UnloadState.cpp b/src/standalone/UnloadState.cpp
new file mode 100644 (file)
index 0000000..db1d2a5
--- /dev/null
@@ -0,0 +1,59 @@
+#include "UnloadState.hpp"
+
+#include "../app/Environment.hpp"
+#include "../io/WorldSave.hpp"
+#include "../world/ChunkLoader.hpp"
+
+
+namespace blank {
+namespace standalone {
+
+UnloadState::UnloadState(
+       Environment &env,
+       ChunkStore &chunks,
+       const WorldSave &save)
+: env(env)
+, chunks(chunks)
+, save(save)
+, progress(env.assets.large_ui_font)
+, cur(chunks.begin())
+, end(chunks.end())
+, done(0)
+, total(chunks.NumLoaded())
+, per_update(64) {
+       progress.Position(glm::vec3(0.0f), Gravity::CENTER);
+       progress.Template("Unloading chunks: %d/%d (%d%%)");
+}
+
+
+void UnloadState::OnResume() {
+       cur = chunks.begin();
+       end = chunks.end();
+       done = 0;
+       total = chunks.NumLoaded();
+}
+
+
+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()) {
+                       save.Write(*cur);
+               }
+       }
+       if (cur == end) {
+               env.state.PopAll();
+       } else {
+               progress.Update(done, total);
+       }
+}
+
+void UnloadState::Render(Viewport &viewport) {
+       progress.Render(viewport);
+}
+
+}
+}