diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp --- a/src/newgrf_spritegroup.cpp +++ b/src/newgrf_spritegroup.cpp @@ -11,6 +11,7 @@ #include #include "debug.h" #include "newgrf_spritegroup.h" +#include "newgrf_profiling.h" #include "core/pool_func.hpp" #include "safeguards.h" @@ -34,10 +35,23 @@ TemporaryStorageArray _tem /* static */ const SpriteGroup *SpriteGroup::Resolve(const SpriteGroup *group, ResolverObject &object, bool top_level) { if (group == nullptr) return nullptr; - if (top_level) { + + const GRFFile *grf = object.grffile; + auto profiler = std::find_if(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](const NewGRFProfiler &pr) { return pr.grffile == grf; }); + + if (profiler == _newgrf_profilers.end() || !profiler->active) { + if (top_level) _temp_store.ClearChanges(); + return group->Resolve(object); + } else if (top_level) { + profiler->BeginResolve(object); _temp_store.ClearChanges(); + const SpriteGroup *result = group->Resolve(object); + profiler->EndResolve(result); + return result; + } else { + profiler->RecursiveResolve(); + return group->Resolve(object); } - return group->Resolve(object); } RealSpriteGroup::~RealSpriteGroup()