diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index 7d06f096c..a0b400095 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -295,6 +295,8 @@ void Application::registerLuaFunctions() g_lua.bindSingletonFunction("g_stats", "get", &Stats::get, &g_stats); g_lua.bindSingletonFunction("g_stats", "clear", &Stats::clear, &g_stats); g_lua.bindSingletonFunction("g_stats", "clearAll", &Stats::clearAll, &g_stats); + g_lua.bindSingletonFunction("g_stats", "pause", &Stats::pause, &g_stats); + g_lua.bindSingletonFunction("g_stats", "resume", &Stats::resume, &g_stats); g_lua.bindSingletonFunction("g_stats", "getSlow", &Stats::getSlow, &g_stats); g_lua.bindSingletonFunction("g_stats", "clearSlow", &Stats::clearSlow, &g_stats); g_lua.bindSingletonFunction("g_stats", "getSleepTime", &Stats::getSleepTime, &g_stats); diff --git a/src/framework/util/stats.cpp b/src/framework/util/stats.cpp index e946b209f..821470a0c 100644 --- a/src/framework/util/stats.cpp +++ b/src/framework/util/stats.cpp @@ -36,8 +36,10 @@ Stats g_stats; void Stats::add(int type, Stat* stat) { - if (type < 0 || type > STATS_LAST) + if (type < 0 || type > STATS_LAST || paused) { + delete stat; return; + } std::lock_guard lock(m_mutex); auto it = stats[type].data.emplace(stat->description, StatsData(0, 0, stat->extraDescription)).first; diff --git a/src/framework/util/stats.h b/src/framework/util/stats.h index c484e5f0f..20d05659d 100644 --- a/src/framework/util/stats.h +++ b/src/framework/util/stats.h @@ -107,6 +107,9 @@ public: inline void addCreature() { createdCreatures += 1; } inline void removeCreature() { destroyedCreatures += 1; } + inline void pause() { paused = true; } + inline void resume() { paused = false; } + private: struct { @@ -124,6 +127,7 @@ private: int destroyedThings = 0; int createdCreatures = 0; int destroyedCreatures = 0; + std::atomic_bool paused { false }; std::mutex m_mutex; };