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