1 #include "UnloadState.hpp"
3 #include "Environment.hpp"
4 #include "../io/WorldSave.hpp"
5 #include "../world/ChunkLoader.hpp"
10 UnloadState::UnloadState(Environment &env, ChunkLoader &loader)
13 , progress(env.assets.large_ui_font)
14 , cur(loader.Loaded().begin())
15 , end(loader.Loaded().end())
17 , total(loader.Loaded().size())
19 progress.Position(glm::vec3(0.0f), Gravity::CENTER);
20 progress.Template("Unloading chunks: %d/%d (%d%%)");
24 void UnloadState::OnResume() {
25 cur = loader.Loaded().begin();
26 end = loader.Loaded().end();
28 total = loader.Loaded().size();
32 void UnloadState::Handle(const SDL_Event &) {
36 void UnloadState::Update(int dt) {
37 for (std::size_t i = 0; i < per_update && cur != end; ++i, ++cur, ++done) {
38 if (cur->ShouldUpdateSave()) {
39 loader.SaveFile().Write(*cur);
45 progress.Update(done, total);
49 void UnloadState::Render(Viewport &viewport) {
50 progress.Render(viewport);