X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2Fapp.cpp;h=ab5170f8ebc70233546b22b3d658ed92a629126d;hb=9c5308ba4108bd842af6d9d2e893ea575a7e6ca8;hp=367f3c21bc2e0bc175d2554d1d428616b7ac6fc1;hpb=ba55bf4293f3abc742eef710545a4b207ba2c820;p=blank.git diff --git a/src/app/app.cpp b/src/app/app.cpp index 367f3c2..ab5170f 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -4,7 +4,6 @@ #include "FrameCounter.hpp" #include "State.hpp" #include "StateControl.hpp" -#include "TextureIndex.hpp" #include "init.hpp" #include "../audio/Sound.hpp" @@ -14,8 +13,11 @@ #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 "../shared/ResourceIndex.hpp" #include "../world/BlockType.hpp" #include "../world/BlockTypeRegistry.hpp" #include "../world/Entity.hpp" @@ -316,7 +318,7 @@ CuboidBounds slab_shape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.0f, 0.5f }}); void AssetLoader::LoadBlockTypes( const string &set_name, BlockTypeRegistry ®, - TextureIndex &tex_index, + ResourceIndex &tex_index, const ShapeRegistry &shapes ) const { string full = data + set_name + ".types"; @@ -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, + ResourceIndex &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); @@ -545,7 +584,7 @@ void AssetLoader::LoadTexture(const string &name, ArrayTexture &tex, int layer) 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()) { @@ -554,22 +593,6 @@ void AssetLoader::LoadTextures(const TextureIndex &index, ArrayTexture &tex) con } -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;