summaryrefslogtreecommitdiff
path: root/src/newgrf_spritegroup.cpp
diff options
context:
space:
mode:
authorNiels Martin Hansen <nielsm@indvikleren.dk>2020-01-26 13:45:51 +0100
committerGitHub <noreply@github.com>2020-01-26 13:45:51 +0100
commitc8779fb311c2665d3fc45c18b2f3460cd998d179 (patch)
tree15321da1e265a40fce50700182b218a87494d24a /src/newgrf_spritegroup.cpp
parentf88ac83408bff58022699b4d9488818d509ef974 (diff)
downloadopenttd-c8779fb311c2665d3fc45c18b2f3460cd998d179.tar.xz
Feature: NewGRF callback profiling (#7868)
Adds a console command newgrf_profile to collect some profiling data about NewGRF action 2 callbacks and produce a CSV file.
Diffstat (limited to 'src/newgrf_spritegroup.cpp')
-rw-r--r--src/newgrf_spritegroup.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp
index 76f8df20f..824ba0439 100644
--- a/src/newgrf_spritegroup.cpp
+++ b/src/newgrf_spritegroup.cpp
@@ -11,6 +11,7 @@
#include <algorithm>
#include "debug.h"
#include "newgrf_spritegroup.h"
+#include "newgrf_profiling.h"
#include "core/pool_func.hpp"
#include "safeguards.h"
@@ -34,10 +35,23 @@ TemporaryStorageArray<int32, 0x110> _temp_store;
/* 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()