+++ /dev/null
-#include "PreloadState.hpp"
-
-#include "Environment.hpp"
-#include "../world/ChunkLoader.hpp"
-#include "../world/ChunkRenderer.hpp"
-
-
-namespace blank {
-
-PreloadState::PreloadState(Environment &env, ChunkLoader &loader, ChunkRenderer &render)
-: 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) {
- loader.LoadN(per_update);
- if (loader.ToLoad() <= 0) {
- env.state.Pop();
- render.Update(render.MissingChunks());
- } else {
- progress.Update(total - loader.ToLoad(), total);
- }
-}
-
-void PreloadState::Render(Viewport &viewport) {
- progress.Render(viewport);
-}
-
-}
+++ /dev/null
-#ifndef BLANK_APP_PRELOADSTATE_HPP_
-#define BLANK_APP_PRELOADSTATE_HPP_
-
-#include "State.hpp"
-
-#include "../ui/Progress.hpp"
-
-#include <cstddef>
-
-
-namespace blank {
-
-class ChunkLoader;
-class ChunkRenderer;
-class Environment;
-
-class PreloadState
-: public State {
-
-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;
-
-};
-
-}
-
-#endif
+++ /dev/null
-#include "UnloadState.hpp"
-
-#include "Environment.hpp"
-#include "../io/WorldSave.hpp"
-#include "../world/ChunkLoader.hpp"
-
-
-namespace blank {
-
-UnloadState::UnloadState(
- Environment &env,
- ChunkStore &chunks,
- const WorldSave &save)
-: 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%%)");
-}
-
-
-void UnloadState::OnResume() {
- cur = chunks.begin();
- end = chunks.end();
- done = 0;
- total = chunks.NumLoaded();
-}
-
-
-void UnloadState::Handle(const SDL_Event &) {
- // ignore everything
-}
-
-void UnloadState::Update(int dt) {
- for (std::size_t i = 0; i < per_update && cur != end; ++i, ++cur, ++done) {
- if (cur->ShouldUpdateSave()) {
- save.Write(*cur);
- }
- }
- if (cur == end) {
- env.state.PopAll();
- } else {
- progress.Update(done, total);
- }
-}
-
-void UnloadState::Render(Viewport &viewport) {
- progress.Render(viewport);
-}
-
-}
+++ /dev/null
-#ifndef BLANK_APP_UNLOADSTATE_HPP_
-#define BLANK_APP_UNLOADSTATE_HPP_
-
-#include "State.hpp"
-
-#include "../ui/Progress.hpp"
-
-#include <cstddef>
-#include <list>
-
-
-namespace blank {
-
-class Chunk;
-class ChunkStore;
-class Environment;
-class WorldSave;
-
-class UnloadState
-: public State {
-
-public:
- UnloadState(Environment &, ChunkStore &, const WorldSave &);
-
- void OnResume();
-
- 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;
- std::size_t total;
- std::size_t per_update;
-
-};
-
-}
-
-#endif
+++ /dev/null
-#include "WorldState.hpp"
-
-#include "Environment.hpp"
-#include "init.hpp"
-#include "TextureIndex.hpp"
-
-#include <SDL.h>
-
-
-namespace blank {
-
-WorldState::WorldState(
- Environment &env,
- const Generator::Config &gc,
- const Interface::Config &ic,
- const World::Config &wc,
- const WorldSave &save
-)
-: env(env)
-, block_types()
-, world(block_types, wc)
-, interface(ic, env, world, world.AddPlayer(ic.player_name))
-, generator(gc)
-, chunk_loader(world.Chunks(), generator, save)
-, chunk_renderer(*interface.GetPlayer().chunks)
-, skeletons()
-, spawner(world, skeletons, gc.seed)
-, sky(env.loader.LoadCubeMap("skybox"))
-, preload(env, chunk_loader, chunk_renderer)
-, unload(env, world.Chunks(), save) {
- TextureIndex tex_index;
- env.loader.LoadBlockTypes("default", block_types, tex_index);
- chunk_renderer.LoadTextures(env.loader, tex_index);
- chunk_renderer.FogDensity(wc.fog_density);
- skeletons.Load();
- spawner.LimitSkeletons(0, skeletons.Size());
- // TODO: better solution for initializing HUD
- interface.SelectNext();
-}
-
-
-void WorldState::OnEnter() {
- env.state.Push(&preload);
- env.window.GrabMouse();
-}
-
-
-void WorldState::Handle(const SDL_Event &event) {
- switch (event.type) {
- case SDL_KEYDOWN:
- interface.HandlePress(event.key);
- break;
- case SDL_KEYUP:
- interface.HandleRelease(event.key);
- break;
- case SDL_MOUSEBUTTONDOWN:
- interface.HandlePress(event.button);
- break;
- case SDL_MOUSEBUTTONUP:
- interface.HandleRelease(event.button);
- break;
- case SDL_MOUSEMOTION:
- interface.Handle(event.motion);
- break;
- case SDL_MOUSEWHEEL:
- interface.Handle(event.wheel);
- break;
- case SDL_QUIT:
- env.state.Switch(&unload);
- break;
- default:
- break;
- }
-}
-
-void WorldState::Update(int dt) {
- interface.Update(dt);
- spawner.Update(dt);
- world.Update(dt);
- chunk_loader.Update(dt);
- chunk_renderer.Update(dt);
-
- Entity &player = *interface.GetPlayer().entity;
-
- glm::mat4 trans = player.Transform(player.ChunkCoords());
- glm::vec3 dir(trans * glm::vec4(0.0f, 0.0f, -1.0f, 0.0f));
- glm::vec3 up(trans * glm::vec4(0.0f, 1.0f, 0.0f, 0.0f));
- env.audio.Position(player.Position());
- env.audio.Velocity(player.Velocity());
- env.audio.Orientation(dir, up);
-}
-
-void WorldState::Render(Viewport &viewport) {
- Entity &player = *interface.GetPlayer().entity;
- viewport.WorldPosition(player.Transform(player.ChunkCoords()));
- chunk_renderer.Render(viewport);
- world.Render(viewport);
- sky.Render(viewport);
-
- interface.Render(viewport);
-}
-
-}
+++ /dev/null
-#ifndef BLANK_APP_WORLDSTATE_HPP_
-#define BLANK_APP_WORLDSTATE_HPP_
-
-#include "PreloadState.hpp"
-#include "State.hpp"
-#include "UnloadState.hpp"
-#include "../ai/Spawner.hpp"
-#include "../graphics/SkyBox.hpp"
-#include "../model/Skeletons.hpp"
-#include "../ui/Interface.hpp"
-#include "../world/BlockTypeRegistry.hpp"
-#include "../world/ChunkLoader.hpp"
-#include "../world/ChunkRenderer.hpp"
-#include "../world/Generator.hpp"
-#include "../world/World.hpp"
-
-
-namespace blank {
-
-class Environment;
-
-class WorldState
-: public State {
-
-public:
- WorldState(
- Environment &,
- const Generator::Config &,
- const Interface::Config &,
- const World::Config &,
- const WorldSave &
- );
-
- void OnEnter() override;
-
- void Handle(const SDL_Event &) override;
- void Update(int dt) override;
- void Render(Viewport &) override;
-
- World &GetWorld() noexcept { return world; }
- Interface &GetInterface() noexcept { return interface; }
-
-private:
- Environment &env;
- BlockTypeRegistry block_types;
- World world;
- Interface interface;
- Generator generator;
- ChunkLoader chunk_loader;
- ChunkRenderer chunk_renderer;
- Skeletons skeletons;
- Spawner spawner;
-
- SkyBox sky;
-
- PreloadState preload;
- UnloadState unload;
-
-};
-
-}
-
-#endif
#include "Application.hpp"
#include "Environment.hpp"
#include "Runtime.hpp"
-#include "WorldState.hpp"
#include "init.hpp"
#include "../client/MasterState.hpp"
#include "../io/filesystem.hpp"
#include "../io/WorldSave.hpp"
#include "../server/ServerState.hpp"
+#include "../standalone/MasterState.hpp"
#include <cctype>
#include <cstdlib>
}
Application app(env);
- WorldState world_state(env, config.gen, config.interface, config.world, save);
+ standalone::MasterState world_state(env, config.gen, config.interface, config.world, save);
app.PushState(&world_state);
Run(app);
}
--- /dev/null
+#include "MasterState.hpp"
+
+#include "../app/Environment.hpp"
+#include "../app/init.hpp"
+#include "../app/TextureIndex.hpp"
+
+#include <SDL.h>
+
+
+namespace blank {
+namespace standalone {
+
+MasterState::MasterState(
+ Environment &env,
+ const Generator::Config &gc,
+ const Interface::Config &ic,
+ const World::Config &wc,
+ const WorldSave &save
+)
+: env(env)
+, block_types()
+, world(block_types, wc)
+, interface(ic, env, world, world.AddPlayer(ic.player_name))
+, generator(gc)
+, chunk_loader(world.Chunks(), generator, save)
+, chunk_renderer(*interface.GetPlayer().chunks)
+, skeletons()
+, spawner(world, skeletons, gc.seed)
+, sky(env.loader.LoadCubeMap("skybox"))
+, preload(env, chunk_loader, chunk_renderer)
+, unload(env, world.Chunks(), save) {
+ TextureIndex tex_index;
+ env.loader.LoadBlockTypes("default", block_types, tex_index);
+ chunk_renderer.LoadTextures(env.loader, tex_index);
+ chunk_renderer.FogDensity(wc.fog_density);
+ skeletons.Load();
+ spawner.LimitSkeletons(0, skeletons.Size());
+ // TODO: better solution for initializing HUD
+ interface.SelectNext();
+}
+
+
+void MasterState::OnEnter() {
+ env.state.Push(&preload);
+ env.window.GrabMouse();
+}
+
+
+void MasterState::Handle(const SDL_Event &event) {
+ switch (event.type) {
+ case SDL_KEYDOWN:
+ interface.HandlePress(event.key);
+ break;
+ case SDL_KEYUP:
+ interface.HandleRelease(event.key);
+ break;
+ case SDL_MOUSEBUTTONDOWN:
+ interface.HandlePress(event.button);
+ break;
+ case SDL_MOUSEBUTTONUP:
+ interface.HandleRelease(event.button);
+ break;
+ case SDL_MOUSEMOTION:
+ interface.Handle(event.motion);
+ break;
+ case SDL_MOUSEWHEEL:
+ interface.Handle(event.wheel);
+ break;
+ case SDL_QUIT:
+ env.state.Switch(&unload);
+ break;
+ default:
+ break;
+ }
+}
+
+void MasterState::Update(int dt) {
+ interface.Update(dt);
+ spawner.Update(dt);
+ world.Update(dt);
+ chunk_loader.Update(dt);
+ chunk_renderer.Update(dt);
+
+ Entity &player = *interface.GetPlayer().entity;
+
+ glm::mat4 trans = player.Transform(player.ChunkCoords());
+ glm::vec3 dir(trans * glm::vec4(0.0f, 0.0f, -1.0f, 0.0f));
+ glm::vec3 up(trans * glm::vec4(0.0f, 1.0f, 0.0f, 0.0f));
+ env.audio.Position(player.Position());
+ env.audio.Velocity(player.Velocity());
+ env.audio.Orientation(dir, up);
+}
+
+void MasterState::Render(Viewport &viewport) {
+ Entity &player = *interface.GetPlayer().entity;
+ viewport.WorldPosition(player.Transform(player.ChunkCoords()));
+ chunk_renderer.Render(viewport);
+ world.Render(viewport);
+ sky.Render(viewport);
+
+ interface.Render(viewport);
+}
+
+}
+}
--- /dev/null
+#ifndef BLANK_STANDALONE_MASTERSTATE_HPP_
+#define BLANK_STANDALONE_MASTERSTATE_HPP_
+
+#include "../app/State.hpp"
+
+#include "PreloadState.hpp"
+#include "UnloadState.hpp"
+#include "../ai/Spawner.hpp"
+#include "../graphics/SkyBox.hpp"
+#include "../model/Skeletons.hpp"
+#include "../ui/Interface.hpp"
+#include "../world/BlockTypeRegistry.hpp"
+#include "../world/ChunkLoader.hpp"
+#include "../world/ChunkRenderer.hpp"
+#include "../world/Generator.hpp"
+#include "../world/World.hpp"
+
+
+namespace blank {
+
+class Environment;
+
+namespace standalone {
+
+class MasterState
+: public State {
+
+public:
+ MasterState(
+ Environment &,
+ const Generator::Config &,
+ const Interface::Config &,
+ const World::Config &,
+ const WorldSave &
+ );
+
+ void OnEnter() override;
+
+ void Handle(const SDL_Event &) override;
+ void Update(int dt) override;
+ void Render(Viewport &) override;
+
+ World &GetWorld() noexcept { return world; }
+ Interface &GetInterface() noexcept { return interface; }
+
+private:
+ Environment &env;
+ BlockTypeRegistry block_types;
+ World world;
+ Interface interface;
+ Generator generator;
+ ChunkLoader chunk_loader;
+ ChunkRenderer chunk_renderer;
+ Skeletons skeletons;
+ Spawner spawner;
+
+ SkyBox sky;
+
+ PreloadState preload;
+ UnloadState unload;
+
+};
+
+}
+}
+
+#endif
--- /dev/null
+#include "PreloadState.hpp"
+
+#include "../app/Environment.hpp"
+#include "../world/ChunkLoader.hpp"
+#include "../world/ChunkRenderer.hpp"
+
+
+namespace blank {
+namespace standalone {
+
+PreloadState::PreloadState(Environment &env, ChunkLoader &loader, ChunkRenderer &render)
+: 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) {
+ loader.LoadN(per_update);
+ if (loader.ToLoad() <= 0) {
+ env.state.Pop();
+ render.Update(render.MissingChunks());
+ } else {
+ progress.Update(total - loader.ToLoad(), total);
+ }
+}
+
+void PreloadState::Render(Viewport &viewport) {
+ progress.Render(viewport);
+}
+
+}
+}
--- /dev/null
+#ifndef BLANK_STANDALONE_PRELOADSTATE_HPP_
+#define BLANK_STANDALONE_PRELOADSTATE_HPP_
+
+#include "../app/State.hpp"
+
+#include "../ui/Progress.hpp"
+
+#include <cstddef>
+
+
+namespace blank {
+
+class ChunkLoader;
+class ChunkRenderer;
+class Environment;
+
+namespace standalone {
+
+class PreloadState
+: public State {
+
+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;
+
+};
+
+}
+}
+
+#endif
--- /dev/null
+#include "UnloadState.hpp"
+
+#include "../app/Environment.hpp"
+#include "../io/WorldSave.hpp"
+#include "../world/ChunkLoader.hpp"
+
+
+namespace blank {
+namespace standalone {
+
+UnloadState::UnloadState(
+ Environment &env,
+ ChunkStore &chunks,
+ const WorldSave &save)
+: 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%%)");
+}
+
+
+void UnloadState::OnResume() {
+ cur = chunks.begin();
+ end = chunks.end();
+ done = 0;
+ total = chunks.NumLoaded();
+}
+
+
+void UnloadState::Handle(const SDL_Event &) {
+ // ignore everything
+}
+
+void UnloadState::Update(int dt) {
+ for (std::size_t i = 0; i < per_update && cur != end; ++i, ++cur, ++done) {
+ if (cur->ShouldUpdateSave()) {
+ save.Write(*cur);
+ }
+ }
+ if (cur == end) {
+ env.state.PopAll();
+ } else {
+ progress.Update(done, total);
+ }
+}
+
+void UnloadState::Render(Viewport &viewport) {
+ progress.Render(viewport);
+}
+
+}
+}
--- /dev/null
+#ifndef BLANK_STANDALONE_UNLOADSTATE_HPP_
+#define BLANK_STANDALONE_UNLOADSTATE_HPP_
+
+#include "../app/State.hpp"
+
+#include "../ui/Progress.hpp"
+
+#include <cstddef>
+#include <list>
+
+
+namespace blank {
+
+class Chunk;
+class ChunkStore;
+class Environment;
+class WorldSave;
+
+namespace standalone {
+
+class UnloadState
+: public State {
+
+public:
+ UnloadState(Environment &, ChunkStore &, const WorldSave &);
+
+ void OnResume();
+
+ 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;
+ std::size_t total;
+ std::size_t per_update;
+
+};
+
+}
+}
+
+#endif