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