From 554eb1c813df1a7f17b4c3e2d59d88b822968b62 Mon Sep 17 00:00:00 2001 From: hdr88 <54114819+hdr88@users.noreply.github.com> Date: Wed, 28 Aug 2019 20:33:07 +0200 Subject: [PATCH] Add current, max and average velocity as stat (#912) * Add current, max and average velocity as stat --- src/g_levellocals.h | 3 +++ src/gamedata/statistics.cpp | 10 ++++++++++ src/p_setup.cpp | 2 ++ src/p_tick.cpp | 4 ++++ 4 files changed, 19 insertions(+) diff --git a/src/g_levellocals.h b/src/g_levellocals.h index ad29e78bd7..863133705d 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -614,6 +614,9 @@ public: int total_monsters; int killed_monsters; + double max_velocity; + double avg_velocity; + double gravity; double aircontrol; double airfriction; diff --git a/src/gamedata/statistics.cpp b/src/gamedata/statistics.cpp index 0c63759342..7514bae90f 100644 --- a/src/gamedata/statistics.cpp +++ b/src/gamedata/statistics.cpp @@ -599,3 +599,13 @@ ADD_STAT(statistics) StoreLevelStats(primaryLevel); // Refresh the current level's results. return GetStatString(); } + +ADD_STAT(velocity) +{ + FString compose; + if (players[consoleplayer].mo != NULL && gamestate == GS_LEVEL) { + compose.AppendFormat("Current velocity: %.2f\n", players[consoleplayer].mo->Vel.Length()); + compose.AppendFormat("Level %s - Velocity Max: %.2f, Velocity Average: %.2f\n", primaryLevel->MapName.GetChars(), primaryLevel->max_velocity, primaryLevel->avg_velocity); + } + return compose; +} diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 814052a306..5ee6ac5a3e 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -264,6 +264,8 @@ void FLevelLocals::ClearLevelData() total_monsters = total_items = total_secrets = killed_monsters = found_items = found_secrets = 0; + max_velocity = avg_velocity = 0; + for (int i = 0; i < 4; i++) { UDMFKeys[i].Clear(); diff --git a/src/p_tick.cpp b/src/p_tick.cpp index 42b18224fa..72202c44ab 100644 --- a/src/p_tick.cpp +++ b/src/p_tick.cpp @@ -180,5 +180,9 @@ void P_Ticker (void) Level->maptime++; Level->totaltime++; } + if (players[consoleplayer].mo != NULL) { + if (players[consoleplayer].mo->Vel.Length() > primaryLevel->max_velocity) { primaryLevel->max_velocity = players[consoleplayer].mo->Vel.Length(); } + primaryLevel->avg_velocity += (players[consoleplayer].mo->Vel.Length() - primaryLevel->avg_velocity) / primaryLevel->maptime; + } StatusBar->CallTick(); // Status bar should tick AFTER the thinkers to properly reflect the level's state at this time. }