From 3a7fe7f7ed1332858148a63073f0b31e41ccdbc0 Mon Sep 17 00:00:00 2001 From: GenericHeroGuy Date: Sat, 18 Oct 2025 22:43:27 +0200 Subject: [PATCH] Cleanup and bugfixes --- src/d_clisrv.c | 2 +- src/doomdef.h | 1 - src/g_game.c | 38 +++++++++++++++++++------------------- src/g_game.h | 16 ++++++++-------- src/m_menu.c | 28 ++++++++++++++-------------- src/m_misc.cpp | 26 -------------------------- src/p_setup.c | 10 +++++----- src/z_zone.c | 28 ---------------------------- src/z_zone.h | 1 - 9 files changed, 47 insertions(+), 103 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 256f5dfe1..40187c6d6 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3623,7 +3623,7 @@ static void SV_GenContext(void) void D_QuitNetGame(void) { doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); - if (!netgame || !netbuffer) + if (!netgame || !doomcom) return; DEBFILE("===========================================================================\n" diff --git a/src/doomdef.h b/src/doomdef.h index 722e68ea9..1334be72f 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -304,7 +304,6 @@ extern char liveeventbackup[256]; void M_StartupLocale(void); void *M_Memcpy(void* dest, const void* src, size_t n); char *va(const char *format, ...) FUNCPRINTF; -char *xva(const char *format, ...) FUNCPRINTF; char *M_GetToken(const char *inputString); void M_UnGetToken(void); diff --git a/src/g_game.c b/src/g_game.c index 584ce61bc..3e9056bc1 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -724,7 +724,7 @@ tic_t G_GetBestTime(INT16 map) return besttime; for (UINT16 k = 0; k < record->numpresets; k++) - if (record->presets[k].besttime < besttime) + if (record->presets[k].besttime && record->presets[k].besttime < besttime) besttime = record->presets[k].besttime; return besttime; @@ -742,34 +742,34 @@ boolean G_EmblemsEnabled(void) char *G_GetRecordReplayFolder(boolean home, boolean breaker) { - return xva("%s%smedia"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s", + return strdup(va("%s%smedia"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s", home ? srb2home : "", home ? PATHSEP : "", breaker ? "itembreaker" : "timeattack", currentrecordpreset - ); + )); } -const char *tasuffixes[] = { - [TA_TIMEBEST] = "time-best", - [TA_LAPBEST] = "lap-best", - [TA_LAST] = "last", - [TA_GUEST] = "guest", +const char *replaysuffixes[] = { + [REPLAY_BESTTIME] = "time-best", + [REPLAY_BESTLAP] = "lap-best", + [REPLAY_LAST] = "last", + [REPLAY_GUEST] = "guest", }; -char *G_GetRecordReplay(const char *folder, UINT16 mapnum, UINT16 skinnum, timeattackreplay_e which) +char *G_GetRecordReplay(const char *folder, UINT16 mapnum, UINT16 skinnum, recordreplay_e which) { - const char *map = G_BuildMapName(mapnum), *suf = tasuffixes[which]; - if (which != TA_GUEST) - return xva("%s"PATHSEP"%s-%s-%s.lmp", folder, map, skins[skinnum].name, suf); + const char *map = G_BuildMapName(mapnum), *suf = replaysuffixes[which]; + if (which != REPLAY_GUEST) + return strdup(va("%s"PATHSEP"%s-%s-%s.lmp", folder, map, skins[skinnum].name, suf)); else - return xva("%s"PATHSEP"%s-%s.lmp", folder, map, suf); + return strdup(va("%s"PATHSEP"%s-%s.lmp", folder, map, suf)); } -boolean G_CheckRecordReplay(const char *folder, UINT16 mapnum, UINT16 skinnum, timeattackreplay_e which) +boolean G_CheckRecordReplay(const char *folder, UINT16 mapnum, UINT16 skinnum, recordreplay_e which) { - const char *map = G_BuildMapName(mapnum), *suf = tasuffixes[which]; - if (which != TA_GUEST) + const char *map = G_BuildMapName(mapnum), *suf = replaysuffixes[which]; + if (which != REPLAY_GUEST) return FIL_FileExists(va("%s"PATHSEP"%s-%s-%s.lmp", folder, map, skins[skinnum].name, suf)); else return FIL_FileExists(va("%s"PATHSEP"%s-%s.lmp", folder, map, suf)); @@ -817,14 +817,14 @@ static void G_UpdateRecordReplays(void) gpath = G_GetRecordReplayFolder(true, modeattacking == ATTACKING_ITEMBREAK); M_MkdirEach(gpath, M_PathParts(gpath) - 4, 0755); - lastdemo = G_GetRecordReplay(gpath, gamemap, cv_chooseskin.value, TA_LAST); + lastdemo = G_GetRecordReplay(gpath, gamemap, cv_chooseskin.value, REPLAY_LAST); if (FIL_FileExists(lastdemo)) { UINT8 *buf; size_t len = FIL_ReadFile(lastdemo, &buf); - CLEANUP(pfree) char *bestdemo = G_GetRecordReplay(gpath, gamemap, cv_chooseskin.value, TA_TIMEBEST); + CLEANUP(pfree) char *bestdemo = G_GetRecordReplay(gpath, gamemap, cv_chooseskin.value, REPLAY_BESTTIME); if (!FIL_FileExists(bestdemo) || G_CmpDemoTime(bestdemo, lastdemo) & 1) { // Better time, save this demo. if (FIL_FileExists(bestdemo)) @@ -836,7 +836,7 @@ static void G_UpdateRecordReplays(void) if (modeattacking == ATTACKING_TIME) { free(bestdemo); - bestdemo = G_GetRecordReplay(gpath, gamemap, cv_chooseskin.value, TA_LAPBEST); + bestdemo = G_GetRecordReplay(gpath, gamemap, cv_chooseskin.value, REPLAY_BESTLAP); if (!FIL_FileExists(bestdemo) || G_CmpDemoTime(bestdemo, lastdemo) & (1<<1)) { // Better lap time, save this demo. if (FIL_FileExists(bestdemo)) diff --git a/src/g_game.h b/src/g_game.h index f883a5e54..d14085597 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -314,12 +314,12 @@ typedef struct typedef enum { - TA_TIMEBEST, - TA_LAPBEST, - TA_LAST, - TA_GUEST, - TA__MAX, -} timeattackreplay_e; + REPLAY_BESTTIME, + REPLAY_BESTLAP, + REPLAY_LAST, + REPLAY_GUEST, + REPLAY__MAX, +} recordreplay_e; extern maprecord_t **maprecords; extern size_t nummaprecords; @@ -332,8 +332,8 @@ void G_ClearRecords(void); tic_t G_GetBestTime(INT16 map); boolean G_EmblemsEnabled(void); char *G_GetRecordReplayFolder(boolean home, boolean breaker); -char *G_GetRecordReplay(const char *folder, UINT16 mapnum, UINT16 skinnum, timeattackreplay_e which); -boolean G_CheckRecordReplay(const char *folder, UINT16 mapnum, UINT16 skinnum, timeattackreplay_e which); +char *G_GetRecordReplay(const char *folder, UINT16 mapnum, UINT16 skinnum, recordreplay_e which); +boolean G_CheckRecordReplay(const char *folder, UINT16 mapnum, UINT16 skinnum, recordreplay_e which); FUNCMATH INT32 G_TicsToHours(tic_t tics); FUNCMATH INT32 G_TicsToMinutes(tic_t tics, boolean full); diff --git a/src/m_menu.c b/src/m_menu.c index f1c490947..81a7ea02f 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -697,28 +697,28 @@ void Nextmap_OnChange(void) boolean showreplay = false, showguest = false; // best time - visible = G_CheckRecordReplay(gpath, cv_nextmap.value, cv_chooseskin.value, TA_TIMEBEST); + visible = G_CheckRecordReplay(gpath, cv_nextmap.value, cv_chooseskin.value, REPLAY_BESTTIME); M_SetItemVisible(MN_SP_REPLAY, "REPLAYTIME", visible); M_SetItemVisible(MN_SP_GUESTREPLAY, "SAVETIME", visible); if (visible) showreplay = showguest = true; // best lap - visible = levellistmode != LLM_ITEMBREAKER && G_CheckRecordReplay(gpath, cv_nextmap.value, cv_chooseskin.value, TA_LAPBEST); + visible = levellistmode != LLM_ITEMBREAKER && G_CheckRecordReplay(gpath, cv_nextmap.value, cv_chooseskin.value, REPLAY_BESTLAP); M_SetItemVisible(MN_SP_REPLAY, "REPLAYLAP", visible); M_SetItemVisible(MN_SP_GUESTREPLAY, "SAVELAP", visible); if (visible) showreplay = showguest = true; // last - visible = G_CheckRecordReplay(gpath, cv_nextmap.value, cv_chooseskin.value, TA_LAST); + visible = G_CheckRecordReplay(gpath, cv_nextmap.value, cv_chooseskin.value, REPLAY_LAST); M_SetItemVisible(MN_SP_REPLAY, "REPLAYLAST", visible); M_SetItemVisible(MN_SP_GUESTREPLAY, "SAVELAST", visible); if (visible) showreplay = showguest = true; // guest - visible = G_CheckRecordReplay(gpath, cv_nextmap.value, UINT16_MAX, TA_GUEST);; + visible = G_CheckRecordReplay(gpath, cv_nextmap.value, UINT16_MAX, REPLAY_GUEST);; M_SetItemVisible(MN_SP_REPLAY, "REPLAYGUEST", visible); M_SetItemVisible(MN_SP_GUESTREPLAY, "DELETE", visible); M_SetItemVisible(MN_SP_GHOST, "GUEST", visible); @@ -5315,7 +5315,7 @@ INT32 MR_Statistics(INT32 choice) if (!statsMapList || nummapheaders != statsMapListLen) { - statsMapList = Z_Realloc(statsMapList, nummapheaders * sizeof(*statsMapList), PU_LEVEL, NULL); + statsMapList = Z_Realloc(statsMapList, nummapheaders * sizeof(*statsMapList), PU_STATIC, NULL); statsMapListLen = nummapheaders; } @@ -5791,7 +5791,7 @@ INT32 MR_QuitTimeAttackMenu(INT32 choice) INT32 MR_ChooseTimeAttack(INT32 choice) { CLEANUP(pfree) char *gpath = G_GetRecordReplayFolder(true, levellistmode == LLM_ITEMBREAKER); - CLEANUP(pfree) char *demopath = G_GetRecordReplay(gpath, cv_nextmap.value, cv_chooseskin.value, TA_LAST); + CLEANUP(pfree) char *demopath = G_GetRecordReplay(gpath, cv_nextmap.value, cv_chooseskin.value, REPLAY_LAST); (void)choice; emeralds = 0; @@ -5841,7 +5841,7 @@ INT32 MR_TimeAttackPreset(INT32 arg) // Player has selected the "REPLAY" from the time attack screen INT32 MR_ReplayTimeAttack(INT32 arg) { - if (arg < 0 || arg >= TA__MAX) + if (arg < 0 || arg >= REPLAY__MAX) return false; CLEANUP(pfree) char *gpath = G_GetRecordReplayFolder(false, levellistmode == LLM_ITEMBREAKER); @@ -5853,7 +5853,7 @@ INT32 MR_ReplayTimeAttack(INT32 arg) static void M_EraseGuest(INT32 choice) { CLEANUP(pfree) char *gpath = G_GetRecordReplayFolder(true, levellistmode == LLM_ITEMBREAKER); - CLEANUP(pfree) char *rguest = G_GetRecordReplay(gpath, cv_nextmap.value, UINT16_MAX, TA_GUEST); + CLEANUP(pfree) char *rguest = G_GetRecordReplay(gpath, cv_nextmap.value, UINT16_MAX, REPLAY_GUEST); (void)choice; if (FIL_FileExists(rguest)) remove(rguest); @@ -5863,10 +5863,10 @@ static void M_EraseGuest(INT32 choice) M_StartMessage(M_GetText("Guest replay data erased.\n"),NULL,MM_NOTHING); } -static void M_OverwriteGuest(timeattackreplay_e which) +static void M_OverwriteGuest(recordreplay_e which) { CLEANUP(pfree) char *gpath = G_GetRecordReplayFolder(true, levellistmode == LLM_ITEMBREAKER); - CLEANUP(pfree) char *rguest = G_GetRecordReplay(gpath, cv_nextmap.value, UINT16_MAX, TA_GUEST); + CLEANUP(pfree) char *rguest = G_GetRecordReplay(gpath, cv_nextmap.value, UINT16_MAX, REPLAY_GUEST); CLEANUP(pfree) char *overwrite = G_GetRecordReplay(gpath, cv_nextmap.value, cv_chooseskin.value, which); UINT8 *buf; size_t len = FIL_ReadFile(overwrite, &buf); @@ -5887,19 +5887,19 @@ static void M_OverwriteGuest(timeattackreplay_e which) static void M_OverwriteGuest_Time(INT32 choice) { (void)choice; - M_OverwriteGuest(TA_TIMEBEST); + M_OverwriteGuest(REPLAY_BESTTIME); } static void M_OverwriteGuest_Lap(INT32 choice) { (void)choice; - M_OverwriteGuest(TA_LAPBEST); + M_OverwriteGuest(REPLAY_BESTLAP); } static void M_OverwriteGuest_Last(INT32 choice) { (void)choice; - M_OverwriteGuest(TA_LAST); + M_OverwriteGuest(REPLAY_LAST); } INT32 MR_SetGuestReplay(INT32 arg) @@ -5922,7 +5922,7 @@ INT32 MR_SetGuestReplay(INT32 arg) return true; } CLEANUP(pfree) char *gpath = G_GetRecordReplayFolder(true, levellistmode == LLM_ITEMBREAKER); - if (G_CheckRecordReplay(gpath, cv_nextmap.value, UINT16_MAX, TA_GUEST)) + if (G_CheckRecordReplay(gpath, cv_nextmap.value, UINT16_MAX, REPLAY_GUEST)) M_StartMessage(M_GetText("Are you sure you want to\noverwrite the guest replay data?\n\n(Press 'Y' to confirm)\n"), which, MM_YESNO); else which(0); diff --git a/src/m_misc.cpp b/src/m_misc.cpp index 0d0e190a1..89545b5bb 100644 --- a/src/m_misc.cpp +++ b/src/m_misc.cpp @@ -1827,32 +1827,6 @@ char *va(const char *format, ...) return string; } -/** Allocates and returns a string made out of varargs. - * - * \param format Format string. - * \return Pointer to the resulting string. - */ -char *xva(const char *format, ...) -{ - va_list argptr; - char *string; - - va_start(argptr, format); - int size = vsnprintf(NULL, 0, format, argptr); - if (size < 0) - I_Error("xva: can't format string"); - string = static_cast(malloc((unsigned)size+1)); - if (!string) - I_Error("xva: out of memory"); - va_end(argptr); - - va_start(argptr, format); - vsprintf(string, format, argptr); - va_end(argptr); - - return string; -} - /** Creates a string in the first argument that is the second argument followed * by the third argument followed by the first argument. * Useful for making filenames with full path. s1 = s2+s3+s1 diff --git a/src/p_setup.c b/src/p_setup.c index c913c10be..fe4177c0a 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -8247,7 +8247,7 @@ static void P_ResetSpawnpoints(void) skyboxviewpnts[i] = skyboxcenterpnts[i] = NULL; } -static void P_TryAddGhosts(const char *gpath, boolean all, timeattackreplay_e which) +static void P_TryAddGhosts(const char *gpath, boolean all, recordreplay_e which) { for (INT32 i = 0; i < numskins; i++) { @@ -8267,19 +8267,19 @@ static void P_LoadRecordGhosts(void) // Best Time ghost if (cv_ghost_besttime.value) - P_TryAddGhosts(gpath, cv_ghost_besttime.value != 1, TA_TIMEBEST); + P_TryAddGhosts(gpath, cv_ghost_besttime.value != 1, REPLAY_BESTTIME); // Best Lap ghost if (modeattacking != ATTACKING_ITEMBREAK && cv_ghost_bestlap.value) - P_TryAddGhosts(gpath, cv_ghost_bestlap.value != 1, TA_LAPBEST); + P_TryAddGhosts(gpath, cv_ghost_bestlap.value != 1, REPLAY_BESTLAP); // Last ghost if (cv_ghost_last.value) - P_TryAddGhosts(gpath, cv_ghost_last.value != 1, TA_LAST); + P_TryAddGhosts(gpath, cv_ghost_last.value != 1, REPLAY_LAST); // Guest ghost if (cv_ghost_guest.value) - P_TryAddGhosts(gpath, false, TA_GUEST); + P_TryAddGhosts(gpath, false, REPLAY_GUEST); // Staff Attack ghosts if (cv_ghost_staff.value) diff --git a/src/z_zone.c b/src/z_zone.c index 354c637c5..f11e57d01 100644 --- a/src/z_zone.c +++ b/src/z_zone.c @@ -654,31 +654,3 @@ char *Z_StrDup(const char *s) { return strcpy(ZZ_Alloc(strlen(s) + 1), s); } - -/** Allocates and returns a string made out of varargs. - * Allocated for Zone Memory. - * - * \param format Format string. - * \return Pointer to the resulting string. - */ -char *zva(INT32 tag, void *user, const char *format, ...) -{ - va_list argptr; - char *string; - - va_start(argptr, format); - int size = vsnprintf(NULL, 0, format, argptr); - if (size < 0) - I_Error("Z_xva: can't format string"); - string = Z_Malloc((unsigned)size+1, tag, user); - if (!string) - I_Error("Z_xva: out of memory"); - va_end(argptr); - - va_start(argptr, format); - vsprintf(string, format, argptr); - va_end(argptr); - - return string; -} - diff --git a/src/z_zone.h b/src/z_zone.h index f989ccd27..361f10cf8 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -146,7 +146,6 @@ size_t Z_TagsUsage(INT32 lowtag, INT32 hightag); // char *Z_StrDup(const char *in); #define Z_Unlock(p) (void)p // TODO: remove this now that NDS code has been removed -char *zva(INT32 tag, void *user, const char *format, ...); // for use with CLEANUP macro FUNCINLINE static ATTRINLINE void Z_Pfree(void *p)