g_demo.c -> g_demo.cpp

This commit is contained in:
Eidolon 2024-02-20 15:27:05 -06:00
parent 7b40b4c8c6
commit 0f96337124
2 changed files with 31 additions and 29 deletions

View file

@ -17,7 +17,7 @@ add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32
f_finale.c f_finale.c
f_wipe.cpp f_wipe.cpp
g_build_ticcmd.cpp g_build_ticcmd.cpp
g_demo.c g_demo.cpp
g_game.c g_game.c
g_gamedata.cpp g_gamedata.cpp
g_input.c g_input.c

View file

@ -11,6 +11,8 @@
/// \file g_demo.c /// \file g_demo.c
/// \brief Demo recording and playback /// \brief Demo recording and playback
#include <algorithm>
#include "doomdef.h" #include "doomdef.h"
#include "console.h" #include "console.h"
#include "d_main.h" #include "d_main.h"
@ -266,7 +268,7 @@ void G_ReadDemoExtraData(void)
break; break;
case DXD_PST_LEFT: case DXD_PST_LEFT:
CL_RemovePlayer(p, 0); CL_RemovePlayer(p, static_cast<kickreason_t>(0));
break; break;
} }
@ -353,9 +355,9 @@ void G_ReadDemoExtraData(void)
{ {
rng = READUINT32(demobuf.p); rng = READUINT32(demobuf.p);
if (P_GetRandSeed(i) != rng) if (P_GetRandSeed(static_cast<pr_class_t>(i)) != rng)
{ {
P_SetRandSeed(i, rng); P_SetRandSeed(static_cast<pr_class_t>(i), rng);
if (demosynced) if (demosynced)
CONS_Alert(CONS_WARNING, "Demo playback has desynced (RNG class %d)!\n", i); CONS_Alert(CONS_WARNING, "Demo playback has desynced (RNG class %d)!\n", i);
@ -494,7 +496,7 @@ void G_WriteDemoExtraData(void)
for (i = 0; i < PRNUMSYNCED; i++) for (i = 0; i < PRNUMSYNCED; i++)
{ {
WRITEUINT32(demobuf.p, P_GetRandSeed(i)); WRITEUINT32(demobuf.p, P_GetRandSeed(static_cast<pr_class_t>(i)));
} }
} }
} }
@ -706,7 +708,7 @@ void G_GhostAddHit(INT32 playernum, mobj_t *victim)
return; return;
ghostext[playernum].flags |= EZT_HIT; ghostext[playernum].flags |= EZT_HIT;
ghostext[playernum].hits++; ghostext[playernum].hits++;
ghostext[playernum].hitlist = Z_Realloc(ghostext[playernum].hitlist, ghostext[playernum].hits * sizeof(mobj_t *), PU_LEVEL, NULL); ghostext[playernum].hitlist = static_cast<mobj_t**>(Z_Realloc(ghostext[playernum].hitlist, ghostext[playernum].hits * sizeof(mobj_t *), PU_LEVEL, NULL));
P_SetTarget(ghostext[playernum].hitlist + (ghostext[playernum].hits-1), victim); P_SetTarget(ghostext[playernum].hitlist + (ghostext[playernum].hits-1), victim);
} }
@ -1400,7 +1402,7 @@ readghosttic:
} }
} }
if (xziptic & EZT_SPRITE) if (xziptic & EZT_SPRITE)
g->mo->sprite = READUINT16(g->p); g->mo->sprite = static_cast<spritenum_t>(READUINT16(g->p));
if (xziptic & EZT_ITEMDATA) if (xziptic & EZT_ITEMDATA)
g->p += 1 + 1 + 4; // itemtype, itemamount, health g->p += 1 + 1 + 4; // itemtype, itemamount, health
if (xziptic & EZT_STATDATA) if (xziptic & EZT_STATDATA)
@ -1467,7 +1469,7 @@ readghosttic:
follow->sprite2 = READUINT8(g->p); follow->sprite2 = READUINT8(g->p);
else else
follow->sprite2 = 0; follow->sprite2 = 0;
follow->sprite = READUINT16(g->p); follow->sprite = static_cast<spritenum_t>(READUINT16(g->p));
follow->frame = (READUINT8(g->p)) | (g->mo->frame & FF_TRANSMASK); follow->frame = (READUINT8(g->p)) | (g->mo->frame & FF_TRANSMASK);
follow->angle = g->mo->angle; follow->angle = g->mo->angle;
follow->color = READUINT16(g->p); follow->color = READUINT16(g->p);
@ -1582,7 +1584,7 @@ void G_StoreRewindInfo(void)
return; return;
timetolog = 8; timetolog = 8;
info = Z_Calloc(sizeof(rewindinfo_t), PU_STATIC, NULL); info = static_cast<rewindinfo_t*>(Z_Calloc(sizeof(rewindinfo_t), PU_STATIC, NULL));
for (i = 0; i < MAXPLAYERS; i++) for (i = 0; i < MAXPLAYERS; i++)
{ {
@ -1907,7 +1909,7 @@ static UINT8 G_CheckDemoExtraFiles(savebuffer_t *info, boolean quick)
{ {
if (!toomany) if (!toomany)
{ {
strlcpy(filename, (char *)info->p, min(P_SaveBufferRemaining(info) + 1, sizeof filename)); strlcpy(filename, (char *)info->p, std::min(P_SaveBufferRemaining(info) + 1, sizeof filename));
} }
SKIPSTRINGN(info->p, P_SaveBufferRemaining(info)); SKIPSTRINGN(info->p, P_SaveBufferRemaining(info));
@ -2011,7 +2013,7 @@ static democharlist_t *G_LoadDemoSkins(savebuffer_t *info, UINT8 *worknumskins,
if (!(*worknumskins)) if (!(*worknumskins))
return NULL; return NULL;
skinlist = Z_Calloc(sizeof(democharlist_t) * (*worknumskins), PU_STATIC, NULL); skinlist = static_cast<democharlist_t*>(Z_Calloc(sizeof(democharlist_t) * (*worknumskins), PU_STATIC, NULL));
if (!skinlist) if (!skinlist)
{ {
I_Error("G_LoadDemoSkins: Insufficient memory to allocate list"); I_Error("G_LoadDemoSkins: Insufficient memory to allocate list");
@ -2181,7 +2183,7 @@ void G_BeginRecording(void)
for (i = 0; i < PRNUMSYNCED; i++) for (i = 0; i < PRNUMSYNCED; i++)
{ {
WRITEUINT32(demobuf.p, P_GetInitSeed(i)); WRITEUINT32(demobuf.p, P_GetInitSeed(static_cast<pr_class_t>(i)));
} }
// Reserved for extrainfo location from start of file // Reserved for extrainfo location from start of file
@ -2584,7 +2586,7 @@ void G_LoadDemoInfo(menudemo_t *pdemo)
goto badreplay; goto badreplay;
} }
info.p += 4; // "PLAY" info.p += 4; // "PLAY"
READSTRINGN(info.p, mapname, min(P_SaveBufferRemaining(&info), sizeof(mapname))); READSTRINGN(info.p, mapname, std::min(P_SaveBufferRemaining(&info), sizeof(mapname)));
pdemo->map = G_MapNumber(mapname); pdemo->map = G_MapNumber(mapname);
info.p += 16; // mapmd5 info.p += 16; // mapmd5
@ -2602,7 +2604,7 @@ void G_LoadDemoInfo(menudemo_t *pdemo)
goto badreplay; goto badreplay;
} }
READSTRINGN(info.p, gtname, min(P_SaveBufferRemaining(&info), sizeof(gtname))); // gametype READSTRINGN(info.p, gtname, std::min(P_SaveBufferRemaining(&info), sizeof(gtname))); // gametype
pdemo->gametype = G_GetGametypeByName(gtname); pdemo->gametype = G_GetGametypeByName(gtname);
if (P_SaveBufferRemaining(&info) < 1) if (P_SaveBufferRemaining(&info) < 1)
@ -2774,7 +2776,7 @@ void G_DoPlayDemo(const char *defdemoname)
if (defdemoname == NULL) if (defdemoname == NULL)
{ {
demobuf.p = demobuf.buffer; demobuf.p = demobuf.buffer;
pdemoname = ZZ_Alloc(1); // Easier than adding checks for this everywhere it's freed pdemoname = static_cast<char*>(ZZ_Alloc(1)); // Easier than adding checks for this everywhere it's freed
} }
else else
{ {
@ -2787,7 +2789,7 @@ void G_DoPlayDemo(const char *defdemoname)
n--; n--;
if (n != defdemoname) if (n != defdemoname)
n++; n++;
pdemoname = ZZ_Alloc(strlen(n)+1); pdemoname = static_cast<char*>(ZZ_Alloc(strlen(n)+1));
strcpy(pdemoname,n); strcpy(pdemoname,n);
M_SetPlaybackMenuPointer(); M_SetPlaybackMenuPointer();
@ -3065,7 +3067,7 @@ void G_DoPlayDemo(const char *defdemoname)
grandprixinfo.gp = true; grandprixinfo.gp = true;
grandprixinfo.gamespeed = READUINT8(demobuf.p); grandprixinfo.gamespeed = READUINT8(demobuf.p);
grandprixinfo.masterbots = READUINT8(demobuf.p) != 0; grandprixinfo.masterbots = READUINT8(demobuf.p) != 0;
grandprixinfo.eventmode = READUINT8(demobuf.p); grandprixinfo.eventmode = static_cast<gpEvent_e>(READUINT8(demobuf.p));
} }
// Sigh ... it's an empty demo. // Sigh ... it's an empty demo.
@ -3236,7 +3238,7 @@ void G_DoPlayDemo(const char *defdemoname)
clientpowerlevels[p][gametype == GT_BATTLE ? PWRLV_BATTLE : PWRLV_RACE] = READUINT16(demobuf.p); clientpowerlevels[p][gametype == GT_BATTLE ? PWRLV_BATTLE : PWRLV_RACE] = READUINT16(demobuf.p);
// Followitem // Followitem
players[p].followitem = READUINT32(demobuf.p); players[p].followitem = static_cast<mobjtype_t>(READUINT32(demobuf.p));
// GP // GP
players[p].lives = READSINT8(demobuf.p); players[p].lives = READSINT8(demobuf.p);
@ -3262,7 +3264,7 @@ void G_DoPlayDemo(const char *defdemoname)
if (demo.attract == DEMO_ATTRACT_TITLE) if (demo.attract == DEMO_ATTRACT_TITLE)
{ {
splitscreen = M_RandomKey(6)-1; splitscreen = M_RandomKey(6)-1;
splitscreen = min(min(3, numslots-1), splitscreen); // Bias toward 1p and 4p views splitscreen = std::min<int>(std::min(3, numslots-1), splitscreen); // Bias toward 1p and 4p views
for (p = 0; p <= splitscreen; p++) for (p = 0; p <= splitscreen; p++)
G_ResetView(p+1, slots[M_RandomKey(numslots)], false); G_ResetView(p+1, slots[M_RandomKey(numslots)], false);
@ -3272,7 +3274,7 @@ void G_DoPlayDemo(const char *defdemoname)
for (i = 0; i < PRNUMSYNCED; i++) for (i = 0; i < PRNUMSYNCED; i++)
{ {
P_SetRandSeed(i, randseed[i]); P_SetRandSeed(static_cast<pr_class_t>(i), randseed[i]);
} }
G_InitNew((demoflags & DF_ENCORE) != 0, gamemap, true, true); // Doesn't matter whether you reset or not here, given changes to resetplayer. G_InitNew((demoflags & DF_ENCORE) != 0, gamemap, true, true); // Doesn't matter whether you reset or not here, given changes to resetplayer.
@ -3484,7 +3486,7 @@ void G_AddGhost(savebuffer_t *buffer, const char *defdemoname)
} }
gh = Z_Calloc(sizeof(demoghost), PU_LEVEL, NULL); gh = static_cast<demoghost*>(Z_Calloc(sizeof(demoghost), PU_LEVEL, NULL));
gh->next = ghosts; gh->next = ghosts;
gh->buffer = buffer->buffer; gh->buffer = buffer->buffer;
M_Memcpy(gh->checksum, md5, 16); M_Memcpy(gh->checksum, md5, 16);
@ -3651,7 +3653,7 @@ staffbrief_t *G_GetStaffGhostBrief(UINT8 *buffer)
M_Memcpy(temp.name, p, 16); M_Memcpy(temp.name, p, 16);
ret = Z_Malloc(sizeof(staffbrief_t), PU_STATIC, NULL); ret = static_cast<staffbrief_t*>(Z_Malloc(sizeof(staffbrief_t), PU_STATIC, NULL));
if (ret) if (ret)
M_Memcpy(ret, &temp, sizeof(staffbrief_t)); M_Memcpy(ret, &temp, sizeof(staffbrief_t));
@ -3836,7 +3838,7 @@ boolean G_CheckDemoStatus(void)
if (!demo.recording) if (!demo.recording)
return false; return false;
if (modeattacking || demo.savemode != DSM_NOTSAVING) if (modeattacking || demo.savemode != demovars_s::DSM_NOTSAVING)
{ {
if (demobuf.p) if (demobuf.p)
{ {
@ -3923,13 +3925,13 @@ void G_SaveDemo(void)
#endif #endif
if (FIL_WriteFile(demoname, demobuf.buffer, demobuf.p - demobuf.buffer)) // finally output the file. if (FIL_WriteFile(demoname, demobuf.buffer, demobuf.p - demobuf.buffer)) // finally output the file.
demo.savemode = DSM_SAVED; demo.savemode = demovars_s::DSM_SAVED;
Z_Free(demobuf.buffer); Z_Free(demobuf.buffer);
demo.recording = false; demo.recording = false;
if (!modeattacking) if (!modeattacking)
{ {
if (demo.savemode == DSM_SAVED) if (demo.savemode == demovars_s::DSM_SAVED)
{ {
CONS_Printf(M_GetText("Demo %s recorded\n"), demoname); CONS_Printf(M_GetText("Demo %s recorded\n"), demoname);
if (gamedata->eversavedreplay == false) if (gamedata->eversavedreplay == false)
@ -3957,13 +3959,13 @@ boolean G_DemoTitleResponder(event_t *ev)
// Only ESC and non-keyboard keys abort connection // Only ESC and non-keyboard keys abort connection
if (ch == KEY_ESCAPE) if (ch == KEY_ESCAPE)
{ {
demo.savemode = (cv_recordmultiplayerdemos.value == 2) ? DSM_WILLAUTOSAVE : DSM_NOTSAVING; demo.savemode = (cv_recordmultiplayerdemos.value == 2) ? demovars_s::DSM_WILLAUTOSAVE : demovars_s::DSM_NOTSAVING;
return true; return true;
} }
if (ch == KEY_ENTER || ch >= NUMKEYS) if (ch == KEY_ENTER || ch >= NUMKEYS)
{ {
demo.savemode = DSM_WILLSAVE; demo.savemode = demovars_s::DSM_WILLSAVE;
return true; return true;
} }
@ -4001,7 +4003,7 @@ boolean G_CheckDemoTitleEntry(void)
if (!G_PlayerInputDown(0, gc_b, 0) && !G_PlayerInputDown(0, gc_x, 0)) if (!G_PlayerInputDown(0, gc_b, 0) && !G_PlayerInputDown(0, gc_x, 0))
return false; return false;
demo.savemode = DSM_TITLEENTRY; demo.savemode = demovars_s::DSM_TITLEENTRY;
return true; return true;
} }