diff --git a/include/qbsp/map.hh b/include/qbsp/map.hh index 087cf3f1..6e44f8fb 100644 --- a/include/qbsp/map.hh +++ b/include/qbsp/map.hh @@ -204,11 +204,11 @@ struct quark_tx_info_t std::optional info; }; -int FindMiptex(const char *name, std::optional &extended_info, bool internal = false); -inline int FindMiptex(const char *name, bool internal = false) +int FindMiptex(const char *name, std::optional &extended_info, bool internal = false, bool recursive = true); +inline int FindMiptex(const char *name, bool internal = false, bool recursive = true) { std::optional extended_info; - return FindMiptex(name, extended_info, internal); + return FindMiptex(name, extended_info, internal, recursive); } int FindTexinfo(const mtexinfo_t &texinfo); diff --git a/qbsp/map.cc b/qbsp/map.cc index 9faeeec6..b628138b 100644 --- a/qbsp/map.cc +++ b/qbsp/map.cc @@ -167,7 +167,7 @@ static std::optional LoadWal(const char *name) return map.wal_cache.emplace(name, img::load_wal(name, wal, true)->meta).first->second; } -int FindMiptex(const char *name, std::optional &extended_info, bool internal) +int FindMiptex(const char *name, std::optional &extended_info, bool internal, bool recursive) { const char *pathsep; int i; @@ -223,8 +223,29 @@ int FindMiptex(const char *name, std::optional &extended_inf map.miptex.push_back({name, extended_info->flags, extended_info->value, extended_info->animation}); /* Handle animating textures carefully */ - if (!extended_info->animation.empty()) { - map.miptex[i].animation_miptex = FindMiptex(extended_info->animation.data(), internal); + if (!extended_info->animation.empty() && recursive) { + + int last_i = i; + + // recursively load animated textures until we loop back to us + while (true) + { + // looped back + if (wal->animation == name) + break; + + // texinfo base for animated wal + std::optional animation_info = extended_info; + animation_info->animation = wal->animation; + + // fetch animation chain + int next_i = FindMiptex(wal->animation.data(), animation_info, internal, false); + map.miptex[last_i].animation_miptex = next_i; + last_i = next_i; + + // wal for next chain + wal = LoadWal(wal->animation.c_str()); + } } }