]> git.localhorst.tv Git - blank.git/blob - src/app/PreloadState.cpp
move server and client stuff around
[blank.git] / src / app / PreloadState.cpp
1 #include "PreloadState.hpp"
2
3 #include "Environment.hpp"
4 #include "../world/ChunkLoader.hpp"
5 #include "../world/ChunkRenderer.hpp"
6
7
8 namespace blank {
9
10 PreloadState::PreloadState(Environment &env, ChunkLoader &loader, ChunkRenderer &render)
11 : env(env)
12 , loader(loader)
13 , render(render)
14 , progress(env.assets.large_ui_font)
15 , total(loader.ToLoad())
16 , per_update(64) {
17         progress.Position(glm::vec3(0.0f), Gravity::CENTER);
18         progress.Template("Preloading chunks: %d/%d (%d%%)");
19 }
20
21
22 void PreloadState::Handle(const SDL_Event &e) {
23         if (e.type == SDL_QUIT) {
24                 env.state.PopAll();
25         }
26 }
27
28 void PreloadState::Update(int dt) {
29         loader.LoadN(per_update);
30         if (loader.ToLoad() <= 0) {
31                 env.state.Pop();
32                 render.Update(render.MissingChunks());
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 }