]> git.localhorst.tv Git - blank.git/blob - src/standalone/PreloadState.cpp
basic message state
[blank.git] / src / standalone / PreloadState.cpp
1 #include "PreloadState.hpp"
2
3 #include "../app/Environment.hpp"
4 #include "../world/ChunkLoader.hpp"
5 #include "../world/ChunkRenderer.hpp"
6
7
8 namespace blank {
9 namespace standalone {
10
11 PreloadState::PreloadState(Environment &env, ChunkLoader &loader, ChunkRenderer &render)
12 : env(env)
13 , loader(loader)
14 , render(render)
15 , progress(env.assets.large_ui_font)
16 , total(loader.ToLoad())
17 , per_update(64) {
18         progress.Position(glm::vec3(0.0f), Gravity::CENTER);
19         progress.Template("Preloading chunks: %d/%d (%d%%)");
20 }
21
22
23 void PreloadState::Handle(const SDL_Event &e) {
24         if (e.type == SDL_QUIT) {
25                 env.state.PopAll();
26         }
27 }
28
29 void PreloadState::Update(int dt) {
30         loader.LoadN(per_update);
31         if (loader.ToLoad() <= 0) {
32                 env.state.Pop();
33                 render.Update(render.MissingChunks());
34         } else {
35                 progress.Update(total - loader.ToLoad(), total);
36         }
37 }
38
39 void PreloadState::Render(Viewport &viewport) {
40         progress.Render(viewport);
41 }
42
43 }
44 }