From 23e4df3c905d21252a8d772016bd5efabed86643 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Thu, 29 Feb 2024 21:25:46 -0600 Subject: [PATCH] Add per-map time stats and TA/SPB time stats --- src/doomstat.h | 7 +++++++ src/g_gamedata.cpp | 31 +++++++++++++++++++++++++++++++ src/g_gamedata.h | 38 +++++++++++++++++++++++++++++++++++++- src/m_cond.c | 2 ++ src/m_cond.h | 2 ++ src/p_tick.c | 37 +++++++++++++++++++++++++++++++++++++ 6 files changed, 116 insertions(+), 1 deletion(-) diff --git a/src/doomstat.h b/src/doomstat.h index 20af72ed1..6a481a1a3 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -165,6 +165,13 @@ struct recorddata_t UINT8 mapvisited; recordtimes_t timeattack; ///< Best times for Time Attack recordtimes_t spbattack; ///< Best times for SPB Attack + UINT32 timeplayed; + UINT32 netgametimeplayed; + UINT32 modetimeplayed[5]; + UINT32 timeattacktimeplayed; + UINT32 spbattacktimeplayed; + UINT32 rounds; + UINT32 wins; }; #define KARTSPEED_AUTO -1 diff --git a/src/g_gamedata.cpp b/src/g_gamedata.cpp index 6779f2917..bc9f5a396 100644 --- a/src/g_gamedata.cpp +++ b/src/g_gamedata.cpp @@ -47,6 +47,8 @@ void srb2::save_ng_gamedata() ng.playtime.total = gamedata->totalplaytime; ng.playtime.netgame = gamedata->totalnetgametime; + ng.playtime.timeattack = gamedata->timeattackingtotaltime; + ng.playtime.spbattack = gamedata->spbattackingtotaltime; ng.playtime.race = gamedata->modeplaytime[GDGT_RACE]; ng.playtime.battle = gamedata->modeplaytime[GDGT_BATTLE]; ng.playtime.prisons = gamedata->modeplaytime[GDGT_PRISONS]; @@ -145,6 +147,15 @@ void srb2::save_ng_gamedata() map.stats.timeattack.bestlap = mapheaderinfo[i]->records.timeattack.lap; map.stats.spbattack.besttime = mapheaderinfo[i]->records.spbattack.time; map.stats.spbattack.bestlap = mapheaderinfo[i]->records.spbattack.lap; + map.stats.time.total = mapheaderinfo[i]->records.timeplayed; + map.stats.time.netgame = mapheaderinfo[i]->records.netgametimeplayed; + map.stats.time.race = mapheaderinfo[i]->records.modetimeplayed[GDGT_RACE]; + map.stats.time.battle = mapheaderinfo[i]->records.modetimeplayed[GDGT_BATTLE]; + map.stats.time.prisons = mapheaderinfo[i]->records.modetimeplayed[GDGT_PRISONS]; + map.stats.time.special = mapheaderinfo[i]->records.modetimeplayed[GDGT_SPECIAL]; + map.stats.time.custom = mapheaderinfo[i]->records.modetimeplayed[GDGT_CUSTOM]; + map.stats.time.timeattack = mapheaderinfo[i]->records.timeattacktimeplayed; + map.stats.time.spbattack = mapheaderinfo[i]->records.spbattacktimeplayed; ng.maps[lumpname] = std::move(map); } for (auto unloadedmap = unloadedmapheaders; unloadedmap; unloadedmap = unloadedmap->next) @@ -160,6 +171,15 @@ void srb2::save_ng_gamedata() map.stats.timeattack.bestlap = unloadedmap->records.timeattack.lap; map.stats.spbattack.besttime = unloadedmap->records.spbattack.time; map.stats.spbattack.bestlap = unloadedmap->records.spbattack.lap; + map.stats.time.total = unloadedmap->records.timeplayed; + map.stats.time.netgame = unloadedmap->records.netgametimeplayed; + map.stats.time.race = unloadedmap->records.modetimeplayed[GDGT_RACE]; + map.stats.time.battle = unloadedmap->records.modetimeplayed[GDGT_BATTLE]; + map.stats.time.prisons = unloadedmap->records.modetimeplayed[GDGT_PRISONS]; + map.stats.time.special = unloadedmap->records.modetimeplayed[GDGT_SPECIAL]; + map.stats.time.custom = unloadedmap->records.modetimeplayed[GDGT_CUSTOM]; + map.stats.time.timeattack = unloadedmap->records.timeattacktimeplayed; + map.stats.time.spbattack = unloadedmap->records.spbattacktimeplayed; ng.maps[lumpname] = std::move(map); } for (int i = 0; i < gamedata->numspraycans; i++) @@ -431,6 +451,8 @@ void srb2::load_ng_gamedata() gamedata->totalplaytime = js.playtime.total; gamedata->totalnetgametime = js.playtime.netgame; + gamedata->timeattackingtotaltime = js.playtime.timeattack; + gamedata->spbattackingtotaltime = js.playtime.spbattack; gamedata->modeplaytime[GDGT_RACE] = js.playtime.race; gamedata->modeplaytime[GDGT_BATTLE] = js.playtime.battle; gamedata->modeplaytime[GDGT_PRISONS] = js.playtime.prisons; @@ -582,6 +604,15 @@ void srb2::load_ng_gamedata() dummyrecord.timeattack.lap = mappair.second.stats.timeattack.bestlap; dummyrecord.spbattack.time = mappair.second.stats.spbattack.besttime; dummyrecord.spbattack.lap = mappair.second.stats.spbattack.bestlap; + dummyrecord.timeplayed = mappair.second.stats.time.total; + dummyrecord.netgametimeplayed = mappair.second.stats.time.netgame; + dummyrecord.modetimeplayed[GDGT_RACE] = mappair.second.stats.time.race; + dummyrecord.modetimeplayed[GDGT_BATTLE] = mappair.second.stats.time.battle; + dummyrecord.modetimeplayed[GDGT_PRISONS] = mappair.second.stats.time.prisons; + dummyrecord.modetimeplayed[GDGT_SPECIAL] = mappair.second.stats.time.special; + dummyrecord.modetimeplayed[GDGT_CUSTOM] = mappair.second.stats.time.custom; + dummyrecord.timeattacktimeplayed = mappair.second.stats.time.timeattack; + dummyrecord.spbattacktimeplayed = mappair.second.stats.time.spbattack; if (mapnum < nummapheaders && mapheaderinfo[mapnum]) { diff --git a/src/g_gamedata.h b/src/g_gamedata.h index 21d9c79be..3c21ea5c2 100644 --- a/src/g_gamedata.h +++ b/src/g_gamedata.h @@ -28,6 +28,8 @@ struct GamedataPlaytimeJson final { uint32_t total; uint32_t netgame; + uint32_t timeattack; + uint32_t spbattack; uint32_t race; uint32_t battle; uint32_t prisons; @@ -41,6 +43,8 @@ struct GamedataPlaytimeJson final GamedataPlaytimeJson, total, netgame, + timeattack, + spbattack, race, battle, prisons, @@ -194,12 +198,44 @@ struct GamedataMapStatsSpbAttackJson final NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(GamedataMapStatsSpbAttackJson, besttime, bestlap) }; +struct GamedataMapStatsPlaytimeJson final +{ + uint32_t total; + uint32_t netgame; + uint32_t race; + uint32_t battle; + uint32_t prisons; + uint32_t special; + uint32_t custom; + uint32_t timeattack; + uint32_t spbattack; + + NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT( + GamedataMapStatsPlaytimeJson, + total, + netgame, + race, + battle, + prisons, + special, + custom, + timeattack, + spbattack + ) +}; + struct GamedataMapStatsJson final { GamedataMapStatsTimeAttackJson timeattack; GamedataMapStatsSpbAttackJson spbattack; + GamedataMapStatsPlaytimeJson time; - NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(GamedataMapStatsJson, timeattack, spbattack) + NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT( + GamedataMapStatsJson, + timeattack, + spbattack, + time + ) }; struct GamedataMapJson final diff --git a/src/m_cond.c b/src/m_cond.c index 4d6ac752d..d9f8a255b 100644 --- a/src/m_cond.c +++ b/src/m_cond.c @@ -653,6 +653,8 @@ void M_ClearStats(void) UINT8 i; gamedata->totalplaytime = 0; gamedata->totalnetgametime = 0; + gamedata->timeattackingtotaltime = 0; + gamedata->spbattackingtotaltime = 0; for (i = 0; i < GDGT_MAX; ++i) gamedata->modeplaytime[i] = 0; gamedata->totalmenutime = 0; diff --git a/src/m_cond.h b/src/m_cond.h index 8d1281ad2..fc2b64c5a 100644 --- a/src/m_cond.h +++ b/src/m_cond.h @@ -370,6 +370,8 @@ struct gamedata_t // PLAY TIME UINT32 totalplaytime; UINT32 totalnetgametime; + UINT32 timeattackingtotaltime; + UINT32 spbattackingtotaltime; UINT32 modeplaytime[GDGT_MAX]; UINT32 totalmenutime; UINT32 totaltimestaringatstatistics; diff --git a/src/p_tick.c b/src/p_tick.c index 76cecc57b..961375410 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -941,13 +941,28 @@ void P_Ticker(boolean run) if (gamedata && gamestate == GS_LEVEL && !demo.playback) { + mapheader_t *mapheader; + + mapheader = mapheaderinfo[gamemap - 1]; + // Keep track of how long they've been playing! gamedata->totalplaytime++; + // Map playtime + if (mapheader) + { + mapheader->records.timeplayed++; + } + // Netgame total time if (netgame) { gamedata->totalnetgametime++; + + if (mapheader) + { + mapheader->records.netgametimeplayed++; + } } // Per-skin total playtime for all machine-local players @@ -983,6 +998,28 @@ void P_Ticker(boolean run) if (mode >= 0 && mode < GDGT_MAX) { gamedata->modeplaytime[mode]++; + if (mapheader) + { + mapheader->records.modetimeplayed[mode]++; + } + } + + // Attacking mode playtime + if ((modeattacking & ATTACKING_TIME) != 0) + { + gamedata->timeattackingtotaltime++; + if (mapheader) + { + mapheader->records.timeattacktimeplayed++; + } + } + else if ((modeattacking & ATTACKING_SPB) != 0) + { + gamedata->spbattackingtotaltime++; + if (mapheader) + { + mapheader->records.spbattacktimeplayed++; + } } // Per-skin mode playtime