--- /dev/null
+#include "ProgressState.hpp"
+
+#include "../app/Environment.hpp"
+
+
+namespace blank {
+
+ProgressState::ProgressState(Environment &env, const char *tpl)
+: env(env)
+, progress(env.assets.large_ui_font) {
+ progress.Position(glm::vec3(0.0f), Gravity::CENTER);
+ progress.Template(tpl);
+}
+
+void ProgressState::SetProgress(int value, int total) {
+ progress.Update(value, total);
+}
+
+void ProgressState::Handle(const SDL_Event &e) {
+ if (e.type == SDL_QUIT) {
+ env.state.PopAll();
+ }
+}
+
+void ProgressState::Render(Viewport &viewport) {
+ progress.Render(viewport);
+}
+
+}
--- /dev/null
+#ifndef BLANK_APP_PROGRESSSTATE_HPP_
+#define BLANK_APP_PROGRESSSTATE_HPP_
+
+#include "State.hpp"
+
+#include "../ui/Progress.hpp"
+
+
+namespace blank {
+
+class Environment;
+
+class ProgressState
+: public State {
+
+public:
+ ProgressState(Environment &env, const char *tpl);
+
+ void SetProgress(int value, int total);
+
+ void Handle(const SDL_Event &) override;
+ void Render(Viewport &) override;
+
+private:
+ Environment &env;
+ Progress progress;
+
+};
+
+}
+
+#endif
namespace standalone {
PreloadState::PreloadState(Environment &env, ChunkLoader &loader, ChunkRenderer &render)
-: env(env)
+: ProgressState(env, "Preloading chunks: %d/%d (%d%%)")
+, env(env)
, loader(loader)
, render(render)
-, 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 &e) {
- if (e.type == SDL_QUIT) {
- env.state.PopAll();
- }
}
void PreloadState::Update(int dt) {
env.state.Pop();
render.Update(render.MissingChunks());
} else {
- progress.Update(total - loader.ToLoad(), total);
+ SetProgress(total - loader.ToLoad(), total);
}
}
-void PreloadState::Render(Viewport &viewport) {
- progress.Render(viewport);
-}
-
}
}
#ifndef BLANK_STANDALONE_PRELOADSTATE_HPP_
#define BLANK_STANDALONE_PRELOADSTATE_HPP_
-#include "../app/State.hpp"
-
-#include "../ui/Progress.hpp"
+#include "../app/ProgressState.hpp"
#include <cstddef>
namespace standalone {
class PreloadState
-: public State {
+: public ProgressState {
public:
PreloadState(Environment &, ChunkLoader &, ChunkRenderer &);
- void Handle(const SDL_Event &) override;
void Update(int dt) override;
- void Render(Viewport &) override;
private:
Environment &env;
ChunkLoader &loader;
ChunkRenderer &render;
- Progress progress;
std::size_t total;
std::size_t per_update;
Environment &env,
ChunkStore &chunks,
const WorldSave &save)
-: env(env)
+: ProgressState(env, "Unloading chunks: %d/%d (%d%%)")
+, env(env)
, chunks(chunks)
, save(save)
-, progress(env.assets.large_ui_font)
, cur(chunks.begin())
, end(chunks.end())
, done(0)
, total(chunks.NumLoaded())
, per_update(64) {
- progress.Position(glm::vec3(0.0f), Gravity::CENTER);
- progress.Template("Unloading chunks: %d/%d (%d%%)");
+
}
}
}
if (cur == end) {
- env.state.PopAll();
+ env.state.Pop();
} else {
- progress.Update(done, total);
+ SetProgress(done, total);
}
}
-void UnloadState::Render(Viewport &viewport) {
- progress.Render(viewport);
-}
-
}
}
#ifndef BLANK_STANDALONE_UNLOADSTATE_HPP_
#define BLANK_STANDALONE_UNLOADSTATE_HPP_
-#include "../app/State.hpp"
-
-#include "../ui/Progress.hpp"
+#include "../app/ProgressState.hpp"
#include <cstddef>
#include <list>
namespace standalone {
class UnloadState
-: public State {
+: public ProgressState {
public:
UnloadState(Environment &, ChunkStore &, const WorldSave &);
void Handle(const SDL_Event &) override;
void Update(int dt) override;
- void Render(Viewport &) override;
private:
Environment &env;
ChunkStore &chunks;
const WorldSave &save;
- Progress progress;
std::list<Chunk>::iterator cur;
std::list<Chunk>::iterator end;
std::size_t done;