add P_FreeLevelState + extra stuff for D_ClearState

this just takes out the cleanup code from P_SetupLevel so it can be called from within D_ClearState and all the mapdata will be freed when going back to the main menu
Not super crazy and really necessary in kart, but why not tbh
this is mostly based on what RR does
This commit is contained in:
Alug committed 2025-09-17 01:31:15 +02:00
1 parent 9d122aa686
commit 098d1afb50
6 files changed
+79 -38

No files matched your search

+18 -3
View File
@@ -982,6 +982,7 @@ void D_ClearState(void)
// (otherwise the game still thinks we're playing!)
SV_StopServer();
SV_ResetServer();
serverlistultimatecount = 0;
for (i = 0; i < MAXPLAYERS; i++)
CL_ClearPlayer(i);
@@ -997,8 +998,11 @@ void D_ClearState(void)
// reset modeattacking
modeattacking = ATTACKING_NONE;
// empty maptol so mario/etc sounds don't play in sound test when they shouldn't
// empty some other semi-important state
maptol = 0;
nextmapoverride = 0;
skipstats = 0;
gamemap = 1;
gameaction = ga_nothing;
memset(displayplayers, 0, sizeof(displayplayers));
@@ -1007,16 +1011,26 @@ void D_ClearState(void)
gametype = GT_RACE; // SRB2kart
paused = false;
netgame = false; // title menu shouldnt be a netgame lmao
// clear cmd building stuff
memset(gamekeydown, 0, sizeof(gamekeydown));
memset(joyxmove, 0, sizeof(joyxmove));
memset(joyymove, 0, sizeof(joyymove));
mousex = mousey = 0;
// Reset the palette
if (rendermode != render_none)
V_SetPaletteLump("PLAYPAL");
G_ResetAllDeviceRumbles();
S_StopSounds();
S_ResetKeepAndSpecialMus(); // just in case
P_FreeLevelState();
netgame = false; // title menu shouldnt be a netgame lmao
G_SetGamestate(GS_NULL);
wipegamestate = GS_NULL;
}
//
@@ -1024,6 +1038,7 @@ void D_ClearState(void)
//
void D_StartTitle(void)
{
demo.title = false;
D_ClearState();
M_ClearMenus(true);
F_StartTitleScreen();
+8 -2
View File
@@ -3864,8 +3864,8 @@ static void G_StopTimingDemo(void)
D_StartTitle();
}
boolean G_CheckDemoStatus(void)
// Clean up all ghosts
void G_FreeGhosts(void)
{
while (ghosts)
{
@@ -3874,6 +3874,12 @@ boolean G_CheckDemoStatus(void)
ghosts = next;
}
ghosts = NULL;
}
boolean G_CheckDemoStatus(void)
{
G_FreeGhosts();
// DO NOT end metal sonic demos here
+1
View File
@@ -174,6 +174,7 @@ void G_ResetDemoRecording(void);
void G_DoPlayDemo(char *defdemoname);
void G_TimeDemo(const char *name);
void G_AddGhost(char *defdemoname);
void G_FreeGhosts(void);
void G_UpdateStaffGhostName(lumpnum_t l);
void G_DoPlayMetal(void);
void G_DoneLevelLoad(void);
+1 -2
View File
@@ -1391,8 +1391,7 @@ UINT32 HWR_GetLightTableID(extracolormap_t *colormap)
// call become invalid and must not be used.
void HWR_ClearLightTables(void)
{
if (vid.glstate == VID_GL_LIBRARY_LOADED)
GL_ClearLightTables();
GL_ClearLightTables();
}
#endif //HWRENDER
+50 -31
View File
@@ -2686,6 +2686,55 @@ static void P_SetupPlayer(void)
}
}
void P_FreeLevelState(void)
{
sector_t *ss;
if (numsectors)
{
LUA_InvalidateLevel();
for (ss = sectors; sectors+numsectors != ss; ss++)
{
Z_Free(ss->attached);
Z_Free(ss->attachedsolid);
}
// This is the simplest guard against double frees.
// No valid map has zero sectors. Or, come to think
// of it, less than two in general! ~toast 310525
numsectors = 0;
}
// Clear pointers that would be left dangling by the purge
R_FlushTranslationColormapCache();
#ifdef HWRENDER
// Free GPU textures before freeing patches.
if (vid.glstate == VID_GL_LIBRARY_LOADED)
{
if (rendermode == render_opengl)
HWR_ClearAllTextures();
// Delete light table textures
HWR_ClearLightTables();
}
#endif
G_FreeGhosts(); // ghosts are allocated with PU_LEVEL
Patch_FreeTag(PU_PATCH_LOWPRIORITY);
//Patch_FreeTag(PU_PATCH_ROTATED); // we keep those ty!
Z_FreeTags(PU_LEVEL, PU_PURGELEVEL - 1);
Y_VoteClear();
#if defined (WALLSPLATS) || defined (FLOORSPLATS)
// clear the splats from previous level
R_ClearLevelSplats();
#endif
}
/** Loads a level from a lump or external wad.
*
* \param fromnetsave If true, skip some stuff because we're loading a netgame snapshot.
@@ -2698,7 +2747,6 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate)
// Map header should always be in place at this point
INT32 i;
boolean ranspecialwipe = false;
sector_t *ss;
lumpnum_t encoreLump = LUMPERROR;
UINT8 levelfadecol;
@@ -2804,36 +2852,7 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate)
I_UpdateNoVsync();
}*/
LUA_InvalidateLevel();
for (ss = sectors; sectors+numsectors != ss; ss++)
{
Z_Free(ss->attached);
Z_Free(ss->attachedsolid);
}
// Clear pointers that would be left dangling by the purge
R_FlushTranslationColormapCache();
#ifdef HWRENDER
// Free GPU textures before freeing patches.
if (rendermode == render_opengl && (vid.glstate == VID_GL_LIBRARY_LOADED))
HWR_ClearAllTextures();
// Delete light table textures
HWR_ClearLightTables();
#endif
Patch_FreeTag(PU_PATCH_LOWPRIORITY);
//Patch_FreeTag(PU_PATCH_ROTATED); // we keep those ty!
Z_FreeTags(PU_LEVEL, PU_PURGELEVEL - 1);
Y_VoteClear();
#if defined (WALLSPLATS) || defined (FLOORSPLATS)
// clear the splats from previous level
R_ClearLevelSplats();
#endif
P_FreeLevelState();
R_InitializeLevelInterpolators();
+1
View File
@@ -67,6 +67,7 @@ extern line_t *spawnlines;
extern side_t *spawnsides;
void P_SetupLevelSky(INT32 skynum, boolean global);
void P_FreeLevelState(void);
boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate);
#ifdef HWRENDER