From 8b4bd6deeb933153dfd458aab3ae2f2b56716041 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 1 Jun 2022 17:42:37 -0400 Subject: [PATCH] non-recursive method for animated textures; makes it easier to follow and makes sure the chain ends in -1 --- include/qbsp/map.hh | 6 +++--- qbsp/map.cc | 27 ++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) 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()); + } } }