]> git.localhorst.tv Git - blank.git/blob - src/app/UnloadState.cpp
try to get every chunk change saved to disk
[blank.git] / src / app / UnloadState.cpp
1 #include "UnloadState.hpp"
2
3 #include "Environment.hpp"
4 #include "../world/ChunkLoader.hpp"
5 #include "../world/WorldSave.hpp"
6
7
8 namespace blank {
9
10 UnloadState::UnloadState(Environment &env, ChunkLoader &loader)
11 : env(env)
12 , loader(loader)
13 , font(env.assets.LoadFont("DejaVuSans", 24))
14 , progress(font)
15 , cur(loader.Loaded().begin())
16 , end(loader.Loaded().end())
17 , done(0)
18 , total(loader.Loaded().size())
19 , per_update(64) {
20         progress.Position(glm::vec3(0.0f), Gravity::CENTER);
21         progress.Template("Unloading chunks: %d/%d (%d%%)");
22 }
23
24
25 void UnloadState::Handle(const SDL_Event &) {
26         // ignore everything
27 }
28
29 void UnloadState::Update(int dt) {
30         for (std::size_t i = 0; i < per_update && cur != end; ++i, ++cur, ++done) {
31                 if (cur->ShouldUpdateSave()) {
32                         loader.SaveFile().Write(*cur);
33                 }
34         }
35         if (cur == end) {
36                 env.state.PopAll();
37         } else {
38                 progress.Update(done, total);
39         }
40 }
41
42 void UnloadState::Render(Viewport &viewport) {
43         progress.Render(viewport);
44 }
45
46 }