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