X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2Fapp.cpp;h=7f5f02f0d5e1c557675c56dbdad3b7a1ac970189;hb=7e782291e0ce39eb2d4e8c1df28f682c313e6f8d;hp=367f3c21bc2e0bc175d2554d1d428616b7ac6fc1;hpb=a26ca06878d45d3ce77cbc28b574f2553e121944;p=blank.git diff --git a/src/app/app.cpp b/src/app/app.cpp index 367f3c2..7f5f02f 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -14,6 +14,8 @@ #include "../graphics/Texture.hpp" #include "../io/TokenStreamReader.hpp" #include "../model/bounds.hpp" +#include "../model/Model.hpp" +#include "../model/ModelRegistry.hpp" #include "../model/Shape.hpp" #include "../model/ShapeRegistry.hpp" #include "../world/BlockType.hpp" @@ -494,6 +496,43 @@ Font AssetLoader::LoadFont(const string &name, int size) const { return Font(full.c_str(), size); } +void AssetLoader::LoadModels( + const string &set_name, + ModelRegistry &models, + TextureIndex &tex_index, + const ShapeRegistry &shapes +) const { + string full = data + set_name + ".models"; + std::ifstream file(full); + if (!file) { + throw std::runtime_error("failed to open model file " + full); + } + TokenStreamReader in(file); + string model_name; + string prop_name; + while (in.HasMore()) { + in.ReadIdentifier(model_name); + in.Skip(Token::EQUALS); + in.Skip(Token::ANGLE_BRACKET_OPEN); + Model &model = models.Add(model_name); + while (in.HasMore() && in.Peek().type != Token::ANGLE_BRACKET_CLOSE) { + in.ReadIdentifier(prop_name); + in.Skip(Token::EQUALS); + if (prop_name == "root") { + model.RootPart().Read(in, tex_index, shapes); + } else { + while (in.HasMore() && in.Peek().type != Token::SEMICOLON) { + in.Next(); + } + } + in.Skip(Token::SEMICOLON); + } + model.Enumerate(); + in.Skip(Token::ANGLE_BRACKET_CLOSE); + in.Skip(Token::SEMICOLON); + } +} + void AssetLoader::LoadShapes(const string &set_name, ShapeRegistry &shapes) const { string full = data + set_name + ".shapes"; std::ifstream file(full);