mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-04-26 12:01:47 +00:00
Merge branch 'more-demo-cleanup' into 'next'
More Demo code cleanup See merge request STJr/SRB2!942
This commit is contained in:
commit
2b3e9cd758
1 changed files with 93 additions and 89 deletions
134
src/g_demo.c
134
src/g_demo.c
|
|
@ -2332,6 +2332,38 @@ void G_DoneLevelLoad(void)
|
||||||
===================
|
===================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Writes the demo's checksum, or just random garbage if you can't do that for some reason.
|
||||||
|
static void WriteDemoChecksum(void)
|
||||||
|
{
|
||||||
|
UINT8 *p = demobuffer+16; // checksum position
|
||||||
|
#ifdef NOMD5
|
||||||
|
UINT8 i;
|
||||||
|
for (i = 0; i < 16; i++, p++)
|
||||||
|
*p = P_RandomByte(); // This MD5 was chosen by fair dice roll and most likely < 50% correct.
|
||||||
|
#else
|
||||||
|
md5_buffer((char *)p+16, demo_p - (p+16), p); // make a checksum of everything after the checksum in the file.
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stops recording a demo.
|
||||||
|
static void G_StopDemoRecording(void)
|
||||||
|
{
|
||||||
|
boolean saved = false;
|
||||||
|
WRITEUINT8(demo_p, DEMOMARKER); // add the demo end marker
|
||||||
|
WriteDemoChecksum();
|
||||||
|
saved = FIL_WriteFile(va(pandf, srb2home, demoname), demobuffer, demo_p - demobuffer); // finally output the file.
|
||||||
|
free(demobuffer);
|
||||||
|
demorecording = false;
|
||||||
|
|
||||||
|
if (modeattacking != ATTACKING_RECORD)
|
||||||
|
{
|
||||||
|
if (saved)
|
||||||
|
CONS_Printf(M_GetText("Demo %s recorded\n"), demoname);
|
||||||
|
else
|
||||||
|
CONS_Alert(CONS_WARNING, M_GetText("Demo %s not saved\n"), demoname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Stops metal sonic's demo. Separate from other functions because metal + replays can coexist
|
// Stops metal sonic's demo. Separate from other functions because metal + replays can coexist
|
||||||
void G_StopMetalDemo(void)
|
void G_StopMetalDemo(void)
|
||||||
{
|
{
|
||||||
|
|
@ -2349,20 +2381,8 @@ ATTRNORETURN void FUNCNORETURN G_StopMetalRecording(boolean kill)
|
||||||
boolean saved = false;
|
boolean saved = false;
|
||||||
if (demo_p)
|
if (demo_p)
|
||||||
{
|
{
|
||||||
UINT8 *p = demobuffer+16; // checksum position
|
WRITEUINT8(demo_p, (kill) ? METALDEATH : DEMOMARKER); // add the demo end (or metal death) marker
|
||||||
if (kill)
|
WriteDemoChecksum();
|
||||||
WRITEUINT8(demo_p, METALDEATH); // add the metal death marker
|
|
||||||
else
|
|
||||||
WRITEUINT8(demo_p, DEMOMARKER); // add the demo end marker
|
|
||||||
#ifdef NOMD5
|
|
||||||
{
|
|
||||||
UINT8 i;
|
|
||||||
for (i = 0; i < 16; i++, p++)
|
|
||||||
*p = P_RandomByte(); // This MD5 was chosen by fair dice roll and most likely < 50% correct.
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
md5_buffer((char *)p+16, demo_p - (p+16), (void *)p); // make a checksum of everything after the checksum in the file.
|
|
||||||
#endif
|
|
||||||
saved = FIL_WriteFile(va("%sMS.LMP", G_BuildMapName(gamemap)), demobuffer, demo_p - demobuffer); // finally output the file.
|
saved = FIL_WriteFile(va("%sMS.LMP", G_BuildMapName(gamemap)), demobuffer, demo_p - demobuffer); // finally output the file.
|
||||||
}
|
}
|
||||||
free(demobuffer);
|
free(demobuffer);
|
||||||
|
|
@ -2372,41 +2392,14 @@ ATTRNORETURN void FUNCNORETURN G_StopMetalRecording(boolean kill)
|
||||||
I_Error("Failed to save demo!");
|
I_Error("Failed to save demo!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset engine variable set for the demos
|
// Stops timing a demo.
|
||||||
// called from stopdemo command, map command, and g_checkdemoStatus.
|
static void G_StopTimingDemo(void)
|
||||||
void G_StopDemo(void)
|
|
||||||
{
|
|
||||||
Z_Free(demobuffer);
|
|
||||||
demobuffer = NULL;
|
|
||||||
demoplayback = false;
|
|
||||||
titledemo = false;
|
|
||||||
timingdemo = false;
|
|
||||||
singletics = false;
|
|
||||||
|
|
||||||
if (gamestate == GS_INTERMISSION)
|
|
||||||
Y_EndIntermission(); // cleanup
|
|
||||||
|
|
||||||
G_SetGamestate(GS_NULL);
|
|
||||||
wipegamestate = GS_NULL;
|
|
||||||
SV_StopServer();
|
|
||||||
SV_ResetServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean G_CheckDemoStatus(void)
|
|
||||||
{
|
|
||||||
boolean saved;
|
|
||||||
|
|
||||||
G_FreeGhosts();
|
|
||||||
|
|
||||||
// DO NOT end metal sonic demos here
|
|
||||||
|
|
||||||
if (timingdemo)
|
|
||||||
{
|
{
|
||||||
INT32 demotime;
|
INT32 demotime;
|
||||||
double f1, f2;
|
double f1, f2;
|
||||||
demotime = I_GetTime() - demostarttime;
|
demotime = I_GetTime() - demostarttime;
|
||||||
if (!demotime)
|
if (!demotime)
|
||||||
return true;
|
return;
|
||||||
G_StopDemo();
|
G_StopDemo();
|
||||||
timingdemo = false;
|
timingdemo = false;
|
||||||
f1 = (double)demotime;
|
f1 = (double)demotime;
|
||||||
|
|
@ -2454,6 +2447,37 @@ boolean G_CheckDemoStatus(void)
|
||||||
if (restorecv_vidwait != cv_vidwait.value)
|
if (restorecv_vidwait != cv_vidwait.value)
|
||||||
CV_SetValue(&cv_vidwait, restorecv_vidwait);
|
CV_SetValue(&cv_vidwait, restorecv_vidwait);
|
||||||
D_AdvanceDemo();
|
D_AdvanceDemo();
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset engine variable set for the demos
|
||||||
|
// called from stopdemo command, map command, and g_checkdemoStatus.
|
||||||
|
void G_StopDemo(void)
|
||||||
|
{
|
||||||
|
Z_Free(demobuffer);
|
||||||
|
demobuffer = NULL;
|
||||||
|
demoplayback = false;
|
||||||
|
titledemo = false;
|
||||||
|
timingdemo = false;
|
||||||
|
singletics = false;
|
||||||
|
|
||||||
|
if (gamestate == GS_INTERMISSION)
|
||||||
|
Y_EndIntermission(); // cleanup
|
||||||
|
|
||||||
|
G_SetGamestate(GS_NULL);
|
||||||
|
wipegamestate = GS_NULL;
|
||||||
|
SV_StopServer();
|
||||||
|
SV_ResetServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean G_CheckDemoStatus(void)
|
||||||
|
{
|
||||||
|
G_FreeGhosts();
|
||||||
|
|
||||||
|
// DO NOT end metal sonic demos here
|
||||||
|
|
||||||
|
if (timingdemo)
|
||||||
|
{
|
||||||
|
G_StopTimingDemo();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2473,27 +2497,7 @@ boolean G_CheckDemoStatus(void)
|
||||||
|
|
||||||
if (demorecording)
|
if (demorecording)
|
||||||
{
|
{
|
||||||
UINT8 *p = demobuffer+16; // checksum position
|
G_StopDemoRecording();
|
||||||
#ifdef NOMD5
|
|
||||||
UINT8 i;
|
|
||||||
WRITEUINT8(demo_p, DEMOMARKER); // add the demo end marker
|
|
||||||
for (i = 0; i < 16; i++, p++)
|
|
||||||
*p = P_RandomByte(); // This MD5 was chosen by fair dice roll and most likely < 50% correct.
|
|
||||||
#else
|
|
||||||
WRITEUINT8(demo_p, DEMOMARKER); // add the demo end marker
|
|
||||||
md5_buffer((char *)p+16, demo_p - (p+16), p); // make a checksum of everything after the checksum in the file.
|
|
||||||
#endif
|
|
||||||
saved = FIL_WriteFile(va(pandf, srb2home, demoname), demobuffer, demo_p - demobuffer); // finally output the file.
|
|
||||||
free(demobuffer);
|
|
||||||
demorecording = false;
|
|
||||||
|
|
||||||
if (modeattacking != ATTACKING_RECORD)
|
|
||||||
{
|
|
||||||
if (saved)
|
|
||||||
CONS_Printf(M_GetText("Demo %s recorded\n"), demoname);
|
|
||||||
else
|
|
||||||
CONS_Alert(CONS_WARNING, M_GetText("Demo %s not saved\n"), demoname);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue