--- /dev/null
+#include "PreloadState.hpp"
+
+#include "Environment.hpp"
+#include "../world/ChunkLoader.hpp"
+
+#include <iostream>
+
+
+namespace blank {
+
+PreloadState::PreloadState(Environment &env, ChunkLoader &loader)
+: env(env)
+, loader(loader)
+, per_update(256) {
+
+}
+
+
+void PreloadState::Handle(const SDL_Event &) {
+}
+
+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();
+ }
+}
+
+void PreloadState::Render(Viewport &) {
+ // TODO: make a nice progress bar or some other fancy shit
+ std::cout << "preload: " << loader.ToLoad() << " chunks remaining" << std::endl;
+}
+
+}
--- /dev/null
+#ifndef BLANK_APP_PRELOADSTATE_HPP_
+#define BLANK_APP_PRELOADSTATE_HPP_
+
+#include "State.hpp"
+
+#include <cstddef>
+
+
+namespace blank {
+
+class ChunkLoader;
+class Environment;
+
+class PreloadState
+: public State {
+
+public:
+ PreloadState(Environment &, ChunkLoader &);
+
+ void Handle(const SDL_Event &) override;
+ void Update(int dt) override;
+ void Render(Viewport &) override;
+
+private:
+ Environment &env;
+ ChunkLoader &loader;
+ std::size_t per_update;
+
+};
+
+}
+
+#endif
void Update(int dt) override;
void Render(Viewport &) override;
+ World &GetWorld() noexcept { return world; }
+
private:
Environment &env;
World world;
#include "Application.hpp"
#include "Environment.hpp"
+#include "PreloadState.hpp"
#include "Runtime.hpp"
#include "WorldState.hpp"
Application app(env);
- WorldState state(env, config.interface, config.world);
- app.PushState(&state);
+ WorldState world_state(env, config.interface, config.world);
+ app.PushState(&world_state);
+
+ PreloadState preloader(env, world_state.GetWorld().Loader());
+ app.PushState(&preloader);
switch (mode) {
default:
void Rebase(const Chunk::Pos &);
void Update(int dt);
+ std::size_t ToLoad() const noexcept { return to_generate.size(); }
+ void LoadOne();
+ void LoadN(std::size_t n);
+
private:
Chunk &Generate(const Chunk::Pos &pos);
// link given chunk to all loaded neighbors
bool Intersection(const Entity &e, std::vector<WorldCollision> &);
void Resolve(Entity &e, std::vector<WorldCollision> &);
- BlockTypeRegistry &BlockTypes() { return blockType; }
+ BlockTypeRegistry &BlockTypes() noexcept { return blockType; }
+ ChunkLoader &Loader() noexcept { return chunks; }
Entity &Player() { return *player; }
Entity &AddEntity() { entities.emplace_back(); return entities.back(); }
// check if a chunk generation is scheduled for this frame
// and if there's a chunk waiting to be generated
gen_timer.Update(dt);
- if (!gen_timer.Hit() || to_generate.empty()) {
- return;
+ if (gen_timer.Hit()) {
+ LoadOne();
+ }
+}
+
+void ChunkLoader::LoadN(std::size_t n) {
+ std::size_t end = std::min(n, ToLoad());
+ for (std::size_t i = 0; i < end; ++i) {
+ LoadOne();
}
+}
+
+void ChunkLoader::LoadOne() {
+ if (to_generate.empty()) return;
// take position of next chunk in queue
Chunk::Pos pos(to_generate.front());