X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2Fapp.cpp;h=367f3c21bc2e0bc175d2554d1d428616b7ac6fc1;hb=a26ca06878d45d3ce77cbc28b574f2553e121944;hp=1e82cab998b789e6a9be2fc62723defc2e012128;hpb=957b1df87d9a692c517a269221da81227100240e;p=blank.git diff --git a/src/app/app.cpp b/src/app/app.cpp index 1e82cab..367f3c2 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" @@ -305,13 +307,18 @@ 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 ShapeRegistry &shapes +) const { string full = data + set_name + ".types"; std::ifstream file(full); if (!file) { @@ -336,7 +343,17 @@ 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); + 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") { @@ -383,20 +400,12 @@ void AssetLoader::LoadBlockTypes(const std::string &set_name, BlockTypeRegistry type.commonness = in.GetFloat(); } else if (name == "shape") { in.ReadIdentifier(shape_name); - if (shape_name == "block") { - type.shape = &block_shape; - type.fill = { true, true, true, true, true, true }; - } else if (shape_name == "slab") { - type.shape = &slab_shape; - type.fill = { false, true, false, false, false, false }; - } else if (shape_name == "stair") { - type.shape = &stair_shape; - type.fill = { false, true, false, false, false, true }; - } else { - throw runtime_error("unknown block shape: " + shape_name); - } + type.shape = &shapes.Get(shape_name); } else { - throw runtime_error("unknown block property: " + name); + std::cerr << "warning: unknown block type property " << name << std::endl; + while (in.Peek().type != Token::SEMICOLON) { + in.Next(); + } } in.Skip(Token::SEMICOLON); } @@ -485,6 +494,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());