X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2Fapp.cpp;h=8f3801c3893709a0bc0c92ee652158e25c40c6fd;hb=65dbb0391afb6867bd9b388c6351b947a022abad;hp=3257f8b890867d4ae1e001cbd7816a58f1cab0d6;hpb=ede25c0a2f59e21521d1cd962e6ea9d78169ca12;p=blank.git diff --git a/src/app/app.cpp b/src/app/app.cpp index 3257f8b..8f3801c 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -4,6 +4,7 @@ #include "FrameCounter.hpp" #include "State.hpp" #include "StateControl.hpp" +#include "TextureIndex.hpp" #include "init.hpp" #include "../audio/Sound.hpp" @@ -239,7 +240,7 @@ CuboidShape slab_shape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.0f, 0.5f }}); } -void Assets::LoadBlockTypes(const std::string &set_name, BlockTypeRegistry ®) const { +void Assets::LoadBlockTypes(const std::string &set_name, BlockTypeRegistry ®, TextureIndex &tex_index) const { string full = data + set_name + ".types"; std::ifstream file(full); if (!file) { @@ -263,19 +264,8 @@ void Assets::LoadBlockTypes(const std::string &set_name, BlockTypeRegistry ®) if (name == "visible") { type.visible = in.GetBool(); } else if (name == "texture") { - // TODO: load textures as requested in.ReadString(tex_name); - if (tex_name == "rock-1") { - type.texture = 1; - } else if (tex_name == "rock-2") { - type.texture = 2; - } else if (tex_name == "rock-3") { - type.texture = 3; - } else if (tex_name == "debug") { - type.texture = 0; - } else { - throw runtime_error("unknown texture: " + tex_name); - } + type.texture = tex_index.GetID(tex_name); } else if (name == "color") { in.ReadVec(type.color); } else if (name == "label") { @@ -353,6 +343,30 @@ void Assets::LoadTexture(const string &name, ArrayTexture &tex, int layer) const SDL_FreeSurface(srf); } +void Assets::LoadTextures(const TextureIndex &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()) { + LoadTexture(entry.first, tex, entry.second); + } +} + + +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();