class BlockTypeRegistry;
class CubeMap;
class ModelRegistry;
+class ResourceIndex;
class ShapeRegistry;
class Sound;
class Texture;
-class TextureIndex;
class AssetLoader {
void LoadBlockTypes(
const std::string &set_name,
BlockTypeRegistry &,
- TextureIndex &,
+ ResourceIndex &,
const ShapeRegistry &) const;
CubeMap LoadCubeMap(const std::string &name) const;
Font LoadFont(const std::string &name, int size) const;
void LoadModels(
const std::string &set_name,
ModelRegistry &,
- TextureIndex &,
+ ResourceIndex &,
const ShapeRegistry &) const;
void LoadShapes(const std::string &set_name, ShapeRegistry &) const;
Sound LoadSound(const std::string &name) const;
Texture LoadTexture(const std::string &name) const;
void LoadTexture(const std::string &name, ArrayTexture &, int layer) const;
- void LoadTextures(const TextureIndex &, ArrayTexture &) const;
+ void LoadTextures(const ResourceIndex &, ArrayTexture &) const;
private:
std::string fonts;
+++ /dev/null
-#include "FPSController.hpp"
-
-#include <glm/gtx/euler_angles.hpp>
-#include <glm/gtx/rotate_vector.hpp>
-
-
-namespace blank {
-
-FPSController::FPSController(Entity &entity) noexcept
-: entity(entity)
-, pitch(0)
-, yaw(0) {
- entity.Ref();
-}
-
-FPSController::~FPSController() {
- entity.UnRef();
-}
-
-
-void FPSController::Pitch(float p) noexcept {
- pitch = p;
- if (pitch > PI / 2) {
- pitch = PI / 2;
- } else if (pitch < -PI / 2) {
- pitch = -PI / 2;
- }
-}
-
-void FPSController::RotatePitch(float delta) noexcept {
- Pitch(pitch + delta);
-}
-
-void FPSController::Yaw(float y) noexcept {
- yaw = y;
- if (yaw > PI) {
- yaw -= PI * 2;
- } else if (yaw < -PI) {
- yaw += PI * 2;
- }
-}
-
-void FPSController::RotateYaw(float delta) noexcept {
- Yaw(yaw + delta);
-}
-
-
-void FPSController::Update(int dt) noexcept {
- entity.Orientation(glm::quat(glm::vec3(pitch, yaw, 0.0f)));
- entity.Velocity(glm::rotateY(velocity, yaw));
-}
-
-}
+++ /dev/null
-#ifndef BLANK_APP_FPSCONTROLLER_HPP_
-#define BLANK_APP_FPSCONTROLLER_HPP_
-
-#include "../model/geometry.hpp"
-#include "../world/Entity.hpp"
-
-#include <glm/glm.hpp>
-
-
-namespace blank {
-
-/// Sets entity rotation and velocity according to stored velocity
-/// and pitch/yaw components.
-/// Rotation is applied in yaw,pitch order (YX). Velocity is relative
-/// to yaw only (Y axis).
-class FPSController {
-
-public:
- explicit FPSController(Entity &) noexcept;
- ~FPSController();
-
- Entity &Controlled() noexcept { return entity; }
- const Entity &Controlled() const noexcept { return entity; }
-
- /// get position and face direction of controlled entity
- Ray Aim() const noexcept { return entity.Aim(entity.ChunkCoords()); }
-
- /// velocity, relative to heading (yaw only)
- const glm::vec3 &Velocity() const noexcept { return velocity; }
- void Velocity(const glm::vec3 &vel) noexcept { velocity = vel; }
-
- // all angles in radians (full circle = 2π)
- float Pitch() const noexcept { return pitch; }
- void Pitch(float p) noexcept;
- void RotatePitch(float delta) noexcept;
- float Yaw() const noexcept { return yaw; }
- void Yaw(float y) noexcept;
- void RotateYaw(float delta) noexcept;
-
- void Update(int dt) noexcept;
-
-private:
- Entity &entity;
-
- glm::vec3 velocity;
-
- float pitch;
- float yaw;
-
-};
-
-}
-
-#endif
+++ /dev/null
-#ifndef BLANK_APP_TEXTUREINDEX_HPP_
-#define BLANK_APP_TEXTUREINDEX_HPP_
-
-#include <map>
-#include <string>
-
-
-namespace blank {
-
-class TextureIndex {
-
- using MapType = std::map<std::string, int>;
-
-public:
- TextureIndex();
-
- int GetID(const std::string &);
-
- std::size_t Size() const noexcept { return id_map.size(); }
- const MapType &Entries() const noexcept { return id_map; }
-
-private:
- MapType id_map;
-
-};
-
-};
-
-#endif
#include "FrameCounter.hpp"
#include "State.hpp"
#include "StateControl.hpp"
-#include "TextureIndex.hpp"
#include "init.hpp"
#include "../audio/Sound.hpp"
#include "../model/ModelRegistry.hpp"
#include "../model/Shape.hpp"
#include "../model/ShapeRegistry.hpp"
+#include "../shared/ResourceIndex.hpp"
#include "../world/BlockType.hpp"
#include "../world/BlockTypeRegistry.hpp"
#include "../world/Entity.hpp"
void AssetLoader::LoadBlockTypes(
const string &set_name,
BlockTypeRegistry ®,
- TextureIndex &tex_index,
+ ResourceIndex &tex_index,
const ShapeRegistry &shapes
) const {
string full = data + set_name + ".types";
void AssetLoader::LoadModels(
const string &set_name,
ModelRegistry &models,
- TextureIndex &tex_index,
+ ResourceIndex &tex_index,
const ShapeRegistry &shapes
) const {
string full = data + set_name + ".models";
SDL_FreeSurface(srf);
}
-void AssetLoader::LoadTextures(const TextureIndex &index, ArrayTexture &tex) const {
+void AssetLoader::LoadTextures(const ResourceIndex &index, ArrayTexture &tex) const {
// TODO: where the hell should that size come from?
tex.Reserve(16, 16, index.Size(), Format());
for (const auto &entry : index.Entries()) {
}
-TextureIndex::TextureIndex()
-: id_map() {
-
-}
-
-int TextureIndex::GetID(const string &name) {
- auto entry = id_map.find(name);
- if (entry == id_map.end()) {
- auto result = id_map.emplace(name, Size());
- return result.first->second;
- } else {
- return entry->second;
- }
-}
-
-
void FrameCounter::EnterFrame() noexcept {
last_enter = SDL_GetTicks();
last_tick = last_enter;
#include "../app/IntervalTimer.hpp"
#include "../graphics/SkyBox.hpp"
#include "../io/WorldSave.hpp"
-#include "../model/ModelRegistry.hpp"
-#include "../model/ShapeRegistry.hpp"
#include "../net/Packet.hpp"
+#include "../shared/WorldResources.hpp"
#include "../ui/HUD.hpp"
#include "../ui/InteractiveManipulator.hpp"
#include "../ui/Interface.hpp"
-#include "../world/BlockTypeRegistry.hpp"
#include "../world/ChunkRenderer.hpp"
#include "../world/EntityState.hpp"
#include "../world/Player.hpp"
World &GetWorld() noexcept { return world; }
Player &GetPlayer() noexcept { return player; }
ChunkReceiver &GetChunkReceiver() noexcept { return chunk_receiver; }
- ModelRegistry &GetModels() noexcept { return models; }
void OnEnter() override;
private:
MasterState &master;
- ShapeRegistry shapes;
- BlockTypeRegistry block_types;
- ModelRegistry models;
+ WorldResources res;
WorldSave save;
World world;
Player &player;
#include "../app/Environment.hpp"
#include "../app/init.hpp"
-#include "../app/TextureIndex.hpp"
#include "../model/Model.hpp"
#include "../io/WorldSave.hpp"
#include "../world/ChunkIndex.hpp"
// TODO: this clutter is a giant mess
InteractiveState::InteractiveState(MasterState &master, uint32_t player_id)
: master(master)
-, shapes()
-, block_types()
-, models()
+, res()
, save(master.GetEnv().config.GetWorldPath(master.GetWorldConf().name, master.GetConfig().net.host))
-, world(block_types, master.GetWorldConf())
+, world(res.block_types, master.GetWorldConf())
, player(*world.AddPlayer(master.GetConfig().player.name))
, hud(master.GetEnv(), master.GetConfig(), player)
, manip(master.GetEnv(), player.GetEntity())
if (!save.Exists()) {
save.Write(master.GetWorldConf());
}
- TextureIndex tex_index;
- master.GetEnv().loader.LoadShapes("default", shapes);
- master.GetEnv().loader.LoadBlockTypes("default", block_types, tex_index, shapes);
- master.GetEnv().loader.LoadModels("default", models, tex_index, shapes);
- interface.SetInventorySlots(block_types.size() - 1);
- chunk_renderer.LoadTextures(master.GetEnv().loader, tex_index);
+ res.Load(master.GetEnv().loader, "default");
+ interface.SetInventorySlots(res.block_types.size() - 1);
+ chunk_renderer.LoadTextures(master.GetEnv().loader, res.tex_index);
chunk_renderer.FogDensity(master.GetWorldConf().fog_density);
loop_timer.Start();
if (save.Exists(player)) {
} else {
hud.FocusNone();
}
- hud.Display(block_types[player.GetInventorySlot() + 1]);
+ hud.Display(res.block_types[player.GetInventorySlot() + 1]);
loop_timer.Update(dt);
master.Update(dt);
chunk_receiver.Update(dt);
pack.ReadEntity(entity);
uint32_t skel_id;
pack.ReadSkeletonID(skel_id);
- if (skel_id > 0 && skel_id <= models.size()) {
- Model &skel = models.Get(skel_id);
+ if (skel_id > 0 && skel_id <= res.models.size()) {
+ Model &skel = res.models.Get(skel_id);
skel.Instantiate(entity.GetModel());
}
cout << "spawned entity #" << entity_id << " (" << entity.Name()
Block block;
pack.ReadIndex(index, i);
pack.ReadBlock(block, i);
- if (index < Chunk::size && block.type < block_types.size()) {
+ if (index < Chunk::size && block.type < res.block_types.size()) {
manip.SetBlock(*chunk, index, block);
}
}
class EntityMesh;
class Instance;
class Model;
+class ResourceIndex;
class Shape;
class ShapeRegistry;
-class TextureIndex;
class TokenStreamReader;
struct Part {
Part();
~Part();
- void Read(TokenStreamReader &, TextureIndex &, const ShapeRegistry &);
+ void Read(TokenStreamReader &, ResourceIndex &, const ShapeRegistry &);
Part &AddChild();
const std::list<Part> &Children() const noexcept { return children; }
#include "Shape.hpp"
#include "ShapeRegistry.hpp"
-#include "../app/TextureIndex.hpp"
#include "../io/TokenStreamReader.hpp"
#include "../graphics/DirectionalLighting.hpp"
#include "../graphics/EntityMesh.hpp"
+#include "../shared/ResourceIndex.hpp"
#include <iostream>
#include <glm/gtx/quaternion.hpp>
}
-void Part::Read(TokenStreamReader &in, TextureIndex &tex_index, const ShapeRegistry &shapes) {
+void Part::Read(TokenStreamReader &in, ResourceIndex &tex_index, const ShapeRegistry &shapes) {
std::string name;
std::string shape_name;
std::string tex_name;
#include "ServerState.hpp"
#include "../app/Environment.hpp"
-#include "../app/TextureIndex.hpp"
#include "../io/WorldSave.hpp"
#include "../net/io.hpp"
const Config &config
)
: env(env)
-, shapes()
-, block_types()
-, models()
-, world(block_types, wc)
+, res()
+, world(res.block_types, wc)
, generator(gc)
, chunk_loader(world.Chunks(), generator, ws)
-, spawner(world, models, env.rng)
+, spawner(world, res.models, env.rng)
, server(config.net, world, wc, ws)
, loop_timer(16) {
- TextureIndex tex_index;
- env.loader.LoadShapes("default", shapes);
- env.loader.LoadBlockTypes("default", block_types, tex_index, shapes);
- env.loader.LoadModels("default", models, tex_index, shapes);
- if (models.size() < 2) {
+ res.Load(env.loader, "default");
+ if (res.models.size() < 2) {
throw std::runtime_error("need at least two models to run");
}
- generator.LoadTypes(block_types);
- spawner.LimitModels(1, models.size());
- server.SetPlayerModel(models[0]);
+ generator.LoadTypes(res.block_types);
+ spawner.LimitModels(1, res.models.size());
+ server.SetPlayerModel(res.models[0]);
loop_timer.Start();
#include "../ai/Spawner.hpp"
#include "../app/IntervalTimer.hpp"
#include "../app/State.hpp"
-#include "../model/ModelRegistry.hpp"
-#include "../model/ShapeRegistry.hpp"
-#include "../world/BlockTypeRegistry.hpp"
+#include "../shared/WorldResources.hpp"
#include "../world/ChunkLoader.hpp"
#include "../world/Generator.hpp"
#include "../world/World.hpp"
private:
HeadlessEnvironment &env;
- ShapeRegistry shapes;
- BlockTypeRegistry block_types;
- ModelRegistry models;
+ WorldResources res;
World world;
Generator generator;
ChunkLoader chunk_loader;
--- /dev/null
+#ifndef BLANK_SHARED_RESOURCEINDEX_HPP_
+#define BLANK_SHARED_RESOURCEINDEX_HPP_
+
+#include <map>
+#include <string>
+
+
+namespace blank {
+
+class ResourceIndex {
+
+ using MapType = std::map<std::string, std::size_t>;
+
+public:
+ ResourceIndex();
+
+ std::size_t GetID(const std::string &);
+
+ std::size_t Size() const noexcept { return id_map.size(); }
+ const MapType &Entries() const noexcept { return id_map; }
+
+private:
+ MapType id_map;
+
+};
+
+};
+
+#endif
--- /dev/null
+#ifndef BLANK_SHARED_WORLDRESOURCES_HPP_
+#define BLANK_SHARED_WORLDRESOURCES_HPP_
+
+#include "ResourceIndex.hpp"
+#include "../model/ModelRegistry.hpp"
+#include "../model/ShapeRegistry.hpp"
+#include "../world/BlockTypeRegistry.hpp"
+
+#include <string>
+
+
+namespace blank {
+
+class AssetLoader;
+
+struct WorldResources {
+
+ ShapeRegistry shapes;
+ BlockTypeRegistry block_types;
+ ModelRegistry models;
+
+ ResourceIndex tex_index;
+
+
+ WorldResources();
+
+ void Load(const AssetLoader &, const std::string &set);
+
+};
+
+}
+
+#endif
--- /dev/null
+#include "ResourceIndex.hpp"
+#include "WorldResources.hpp"
+
+#include "../app/Assets.hpp"
+
+
+namespace blank {
+
+ResourceIndex::ResourceIndex()
+: id_map() {
+
+}
+
+std::size_t ResourceIndex::GetID(const std::string &name) {
+ auto entry = id_map.find(name);
+ if (entry == id_map.end()) {
+ auto result = id_map.emplace(name, Size());
+ return result.first->second;
+ } else {
+ return entry->second;
+ }
+}
+
+
+WorldResources::WorldResources()
+: shapes()
+, block_types()
+, models()
+, tex_index() {
+
+}
+
+void WorldResources::Load(const AssetLoader &loader, const std::string &set) {
+ loader.LoadShapes("default", shapes);
+ loader.LoadBlockTypes("default", block_types, tex_index, shapes);
+ loader.LoadModels("default", models, tex_index, shapes);
+}
+
+}
#include "../app/Config.hpp"
#include "../app/Environment.hpp"
#include "../app/init.hpp"
-#include "../app/TextureIndex.hpp"
#include "../io/WorldSave.hpp"
#include <SDL.h>
)
: config(config)
, env(env)
-, shapes()
-, block_types()
-, models()
+, res()
, save(save)
-, world(block_types, wc)
+, world(res.block_types, wc)
, spawn_index(world.Chunks().MakeIndex(wc.spawn, 3))
, player(*world.AddPlayer(config.player.name))
, spawn_player(false)
, generator(gc)
, chunk_loader(world.Chunks(), generator, save)
, chunk_renderer(player.GetChunks())
-, spawner(world, models, env.rng)
+, spawner(world, res.models, env.rng)
, sky(env.loader.LoadCubeMap("skybox"))
, preload(env, chunk_loader, chunk_renderer)
, unload(env, world.Chunks(), save) {
- TextureIndex tex_index;
- env.loader.LoadShapes("default", shapes);
- env.loader.LoadBlockTypes("default", block_types, tex_index, shapes);
- env.loader.LoadModels("default", models, tex_index, shapes);
- if (models.size() < 2) {
+ res.Load(env.loader, "default");
+ if (res.models.size() < 2) {
throw std::runtime_error("need at least two models to run");
}
- spawner.LimitModels(0, models.size());
- interface.SetInventorySlots(block_types.size() - 1);
- generator.LoadTypes(block_types);
- chunk_renderer.LoadTextures(env.loader, tex_index);
+ spawner.LimitModels(0, res.models.size());
+ interface.SetInventorySlots(res.block_types.size() - 1);
+ generator.LoadTypes(res.block_types);
+ chunk_renderer.LoadTextures(env.loader, res.tex_index);
chunk_renderer.FogDensity(wc.fog_density);
if (save.Exists(player)) {
save.Read(player);
} else {
hud.FocusNone();
}
- hud.Display(block_types[player.GetInventorySlot() + 1]);
+ hud.Display(res.block_types[player.GetInventorySlot() + 1]);
hud.Update(dt);
spawner.Update(dt);
world.Update(dt);
#include "UnloadState.hpp"
#include "../ai/Spawner.hpp"
#include "../graphics/SkyBox.hpp"
-#include "../model/ModelRegistry.hpp"
-#include "../model/ShapeRegistry.hpp"
+#include "../shared/WorldResources.hpp"
#include "../ui/DirectInput.hpp"
#include "../ui/HUD.hpp"
#include "../ui/InteractiveManipulator.hpp"
#include "../ui/Interface.hpp"
-#include "../world/BlockTypeRegistry.hpp"
#include "../world/ChunkIndex.hpp"
#include "../world/ChunkLoader.hpp"
#include "../world/ChunkRenderer.hpp"
private:
Config &config;
Environment &env;
- ShapeRegistry shapes;
- BlockTypeRegistry block_types;
- ModelRegistry models;
+ WorldResources res;
const WorldSave &save;
World world;
ChunkIndex &spawn_index;
class AssetLoader;
class BlockMesh;
class ChunkIndex;
-class TextureIndex;
+class ResourceIndex;
class Viewport;
class ChunkRenderer {
explicit ChunkRenderer(ChunkIndex &);
~ChunkRenderer();
- void LoadTextures(const AssetLoader &, const TextureIndex &);
+ void LoadTextures(const AssetLoader &, const ResourceIndex &);
void FogDensity(float d) noexcept { fog_density = d; }
int MissingChunks() const noexcept;
return index.MissingChunks();
}
-void ChunkRenderer::LoadTextures(const AssetLoader &loader, const TextureIndex &tex_index) {
+void ChunkRenderer::LoadTextures(const AssetLoader &loader, const ResourceIndex &tex_index) {
block_tex.Bind();
loader.LoadTextures(tex_index, block_tex);
block_tex.FilterNearest();