X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2FPreloadState.cpp;h=aca2502eaeacc92e2417204fec3f618739c95eb7;hb=f417749fb09718cde2faad77e8430cf175c68374;hp=c56e4fe5666ecf4ab63f083d052e5c478f4de583;hpb=22b25d4b9cc24e249bc8007757267cea00ab18d3;p=blank.git diff --git a/src/app/PreloadState.cpp b/src/app/PreloadState.cpp index c56e4fe..aca2502 100644 --- a/src/app/PreloadState.cpp +++ b/src/app/PreloadState.cpp @@ -3,37 +3,40 @@ #include "Environment.hpp" #include "../world/ChunkLoader.hpp" -#include - namespace blank { PreloadState::PreloadState(Environment &env, ChunkLoader &loader) : env(env) , loader(loader) -, per_update(256) { - +, progress(env.assets.large_ui_font) +, total(loader.ToLoad()) +, per_update(64) { + progress.Position(glm::vec3(0.0f), Gravity::CENTER); + progress.Template("Preloading chunks: %d/%d (%d%%)"); } -void PreloadState::Handle(const SDL_Event &) { +void PreloadState::Handle(const SDL_Event &e) { + if (e.type == SDL_QUIT) { + env.state.PopAll(); + } } void PreloadState::Update(int dt) { loader.LoadN(per_update); if (loader.ToLoad() == 0) { - std::cout << "preload: populating VBOs" << std::endl; for (auto &chunk : loader.Loaded()) { chunk.CheckUpdate(); } - std::cout << "preload: complete" << std::endl; env.state.Pop(); + } else { + progress.Update(total - loader.ToLoad(), total); } } -void PreloadState::Render(Viewport &) { - // TODO: make a nice progress bar or some other fancy shit - std::cout << "preload: " << loader.ToLoad() << " chunks remaining" << std::endl; +void PreloadState::Render(Viewport &viewport) { + progress.Render(viewport); } }