From 6ccef7201e5c89f273d7fa29a16f3ec319956200 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 12 Nov 2019 22:45:11 +0100 Subject: [PATCH] - hooked up the statistics code with EDuke and RedNukem frontends. Not sure about the end of game conditions, I wasn't able to test that part yet. --- source/common/statistics.cpp | 8 ++++++++ source/common/statistics.h | 7 +++++++ source/duke3d/src/game.cpp | 4 +++- source/duke3d/src/premap.cpp | 5 ++++- source/rr/src/game.cpp | 4 +++- source/rr/src/premap.cpp | 8 ++++++-- 6 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 source/common/statistics.h diff --git a/source/common/statistics.cpp b/source/common/statistics.cpp index 321b20fa1..24ac130a2 100644 --- a/source/common/statistics.cpp +++ b/source/common/statistics.cpp @@ -397,6 +397,7 @@ static void StoreLevelStats() void STAT_Update(bool endofgame) { + if (*StartEpisode == 0) return; const char* fn = "?"; // record the current level's stats. StoreLevelStats(); @@ -439,9 +440,16 @@ void STAT_Update(bool endofgame) LevelStatEntry(es, lsection, infostring, LevelData[i].leveltime); } SaveStatistics(statfile, EpisodeStatistics); + LevelData.Clear(); + *StartEpisode = *LevelName = 0; } } +void STAT_Cancel() +{ + LevelData.Clear(); + *StartEpisode = *LevelName = 0; +} //========================================================================== // diff --git a/source/common/statistics.h b/source/common/statistics.h new file mode 100644 index 000000000..c36982888 --- /dev/null +++ b/source/common/statistics.h @@ -0,0 +1,7 @@ +#pragma once + + +void STAT_StartNewGame(const char *episode, int skill); +void STAT_NewLevel(const char* mapname); +void STAT_Update(bool endofgame); +void STAT_Cancel(); diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index 9bca08dc2..15d32d993 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -44,7 +44,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "gameconfigfile.h" #include "printf.h" #include "m_argv.h" -#include "filesystem/filesystem.h" +#include "filesystem.h" +#include "statistics.h" // Uncomment to prevent anything except mirrors from drawing. It is sensible to // also uncomment ENGINE_CLEAR_SCREEN in build/src/engine_priv.h. @@ -6014,6 +6015,7 @@ static int G_EndOfLevel(void) { auto &p = *g_player[myconnectindex].ps; + STAT_Update(ud.eog); P_SetGamePalette(&p, BASEPAL, 0); P_UpdateScreenPal(&p); diff --git a/source/duke3d/src/premap.cpp b/source/duke3d/src/premap.cpp index 2d8dba18b..180ae4f38 100644 --- a/source/duke3d/src/premap.cpp +++ b/source/duke3d/src/premap.cpp @@ -28,6 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "duke3d.h" #include "menus.h" #include "savegame.h" +#include "statistics.h" BEGIN_DUKE_NS static uint8_t precachehightile[2][(MAXTILES+7)>>3]; @@ -1337,6 +1338,7 @@ void G_NewGame(int volumeNum, int levelNum, int skillNum) ud.secretlevel = 0; ud.skill_voice = -1; ud.volume_number = volumeNum; + STAT_StartNewGame(g_volumeNames[volumeNum], skillNum); g_lastAutoSaveArbitraryID = -1; g_lastautosave.reset(); @@ -1853,7 +1855,7 @@ int G_EnterLevel(int gameMode) OSD_Printf(OSD_ERROR "Map \"%s\" not found or invalid map version!\n", boardfilename); return 1; } - + STAT_NewLevel(boardfilename); G_LoadMapHack(levelName, boardfilename); G_SetupFilenameBasedMusic(levelName, boardfilename); } @@ -1864,6 +1866,7 @@ int G_EnterLevel(int gameMode) } else { + STAT_NewLevel(m.filename); G_LoadMapHack(levelName, m.filename); } diff --git a/source/rr/src/game.cpp b/source/rr/src/game.cpp index 7609b8bb9..562272d55 100644 --- a/source/rr/src/game.cpp +++ b/source/rr/src/game.cpp @@ -45,6 +45,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "printf.h" #include "m_argv.h" #include "filesystem/filesystem.h" +#include "statistics.h" // Uncomment to prevent anything except mirrors from drawing. It is sensible to // also uncomment ENGINE_CLEAR_SCREEN in build/src/engine_priv.h. @@ -7434,7 +7435,8 @@ void G_BackToMenu(void) static int G_EndOfLevel(void) { - P_SetGamePalette(g_player[myconnectindex].ps, BASEPAL, 0); + STAT_Update(ud.eog); + P_SetGamePalette(g_player[myconnectindex].ps, BASEPAL, 0); P_UpdateScreenPal(g_player[myconnectindex].ps); if (g_player[myconnectindex].ps->gm&MODE_EOL) diff --git a/source/rr/src/premap.cpp b/source/rr/src/premap.cpp index 558f132e7..b7f4b9316 100644 --- a/source/rr/src/premap.cpp +++ b/source/rr/src/premap.cpp @@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "demo.h" #include "savegame.h" #include "cmdline.h" +#include "statistics.h" BEGIN_RR_NS @@ -1899,6 +1900,7 @@ void G_NewGame(int volumeNum, int levelNum, int skillNum) ud.player_skill = skillNum; ud.secretlevel = 0; ud.from_bonus = 0; + STAT_StartNewGame(g_volumeNames[volumeNum], skillNum); ud.last_level = -1; g_lastAutoSaveArbitraryID = -1; @@ -2398,7 +2400,8 @@ int G_EnterLevel(int gameMode) return 1; } - G_LoadMapHack(levelName, boardfilename); + STAT_NewLevel(boardfilename); + G_LoadMapHack(levelName, boardfilename); G_SetupFilenameBasedMusic(levelName, boardfilename, m_level_number); } else if (engineLoadBoard(g_mapInfo[mii].filename, VOLUMEONE, &pPlayer->pos, &lbang, &pPlayer->cursectnum) < 0) @@ -2408,7 +2411,8 @@ int G_EnterLevel(int gameMode) } else { - G_LoadMapHack(levelName, g_mapInfo[mii].filename); + STAT_NewLevel(g_mapInfo[mii].filename); + G_LoadMapHack(levelName, g_mapInfo[mii].filename); } if (RR && !RRRA && ud.volume_number == 1 && ud.level_number == 1)