mirror of
https://github.com/mehah/otclient
synced 2026-08-15 16:29:06 -04:00
feat: add 'resume' and 'pause' functions to Stats class (#1764)
New Features: - Added the ability to pause and resume statistics collection. - While paused, new statistics are no longer recorded; previously gathered statistics remain intact. - Lua scripts can now control statistics collection using new pause and resume commands.
This commit is contained in:
parent
350e506aa7
commit
caba9cef63
3 changed files with 9 additions and 1 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<std::mutex> lock(m_mutex);
|
||||
|
||||
auto it = stats[type].data.emplace(stat->description, StatsData(0, 0, stat->extraDescription)).first;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue