X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2Fapp.cpp;h=eb3dac1b8b4aa0eedcbd3456981a8554c408ebfa;hb=3a487f44c26f9bb9d1a1c831406b6497b2b3b425;hp=98c7286a7970916c70a7b107b90b5e0b301f08de;hpb=75ebb9101c7aec9c16ef418b822c39e81889f66f;p=blank.git diff --git a/src/app/app.cpp b/src/app/app.cpp index 98c7286..eb3dac1 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -13,7 +13,9 @@ #include "../graphics/Font.hpp" #include "../graphics/Texture.hpp" #include "../io/TokenStreamReader.hpp" -#include "../model/shapes.hpp" +#include "../model/bounds.hpp" +#include "../model/Shape.hpp" +#include "../model/ShapeRegistry.hpp" #include "../world/BlockType.hpp" #include "../world/BlockTypeRegistry.hpp" #include "../world/Entity.hpp" @@ -98,6 +100,8 @@ void HeadlessApplication::Run() { void HeadlessApplication::Loop(int dt) { env.counter.EnterFrame(); + HandleEvents(); + if (!HasState()) return; Update(dt); CommitStates(); if (!HasState()) return; @@ -303,13 +307,13 @@ Assets::Assets(const AssetLoader &loader) namespace { -CuboidShape block_shape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f }}); -StairShape stair_shape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f }}, { 0.0f, 0.0f }); -CuboidShape slab_shape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.0f, 0.5f }}); +CuboidBounds block_shape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f }}); +StairBounds stair_shape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f }}, { 0.0f, 0.0f }); +CuboidBounds slab_shape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.0f, 0.5f }}); } -void AssetLoader::LoadBlockTypes(const std::string &set_name, BlockTypeRegistry ®, TextureIndex &tex_index) const { +void AssetLoader::LoadBlockTypes(const string &set_name, BlockTypeRegistry ®, TextureIndex &tex_index) const { string full = data + set_name + ".types"; std::ifstream file(full); if (!file) { @@ -334,9 +338,21 @@ void AssetLoader::LoadBlockTypes(const std::string &set_name, BlockTypeRegistry type.visible = in.GetBool(); } else if (name == "texture") { in.ReadString(tex_name); - type.texture = tex_index.GetID(tex_name); - } else if (name == "color") { - in.ReadVec(type.color); + type.textures.push_back(tex_index.GetID(tex_name)); + } else if (name == "textures") { + in.Skip(Token::BRACKET_OPEN); + while (in.Peek().type != Token::BRACKET_CLOSE) { + in.ReadString(tex_name); + type.textures.push_back(tex_index.GetID(tex_name)); + if (in.Peek().type == Token::COMMA) { + in.Skip(Token::COMMA); + } + } + in.Skip(Token::BRACKET_CLOSE); + } else if (name == "rgb_mod") { + in.ReadVec(type.rgb_mod); + } else if (name == "hsl_mod") { + in.ReadVec(type.hsl_mod); } else if (name == "outline") { in.ReadVec(type.outline_color); } else if (name == "label") { @@ -481,6 +497,23 @@ Font AssetLoader::LoadFont(const string &name, int size) const { return Font(full.c_str(), size); } +void AssetLoader::LoadShapes(const string &set_name, ShapeRegistry &shapes) const { + string full = data + set_name + ".shapes"; + std::ifstream file(full); + if (!file) { + throw std::runtime_error("failed to open shape file " + full); + } + TokenStreamReader in(file); + string shape_name; + while (in.HasMore()) { + in.ReadIdentifier(shape_name); + in.Skip(Token::EQUALS); + Shape &shape = shapes.Add(shape_name); + shape.Read(in); + in.Skip(Token::SEMICOLON); + } +} + Sound AssetLoader::LoadSound(const string &name) const { string full = sounds + name + ".wav"; return Sound(full.c_str());