- the big cleanup of the exit cleanup is done!

atterm is gone and only a few system-side functions use atexit.
All game side cleanup is performed in D_DoomMain now.
This commit is contained in:
Christoph Oelckers 2019-10-07 20:28:55 +02:00
commit 2e7af1338c
37 changed files with 82 additions and 344 deletions

View file

@ -101,8 +101,8 @@
#include "i_system.h"
#include "g_cvars.h"
#include "r_data/r_vanillatrans.h"
#include "atterm.h"
#include "s_music.h"
#include "swrenderer/r_swcolormaps.h"
EXTERN_CVAR(Bool, hud_althud)
EXTERN_CVAR(Int, vr_mode)
@ -123,6 +123,12 @@ extern void M_SetDefaultMode ();
extern void G_NewInit ();
extern void SetupPlayerClasses ();
void DeinitMenus();
void CloseNetwork();
void P_Shutdown();
void M_SaveDefaultsFinal();
void R_Shutdown();
void I_ShutdownInput();
const FIWADInfo *D_FindIWAD(TArray<FString> &wadfiles, const char *iwad, const char *basewad);
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
@ -136,6 +142,7 @@ void D_LoadWadSettings ();
void ParseGLDefs();
void DrawFullscreenSubtitle(const char *text);
void D_Cleanup();
void FreeSBarInfoScript();
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
@ -1985,23 +1992,6 @@ static void SetMapxxFlag()
if (lump_name >= 0 || lump_wad >= 0 || lump_map >= 0) gameinfo.flags |= GI_MAPxx;
}
//==========================================================================
//
// FinalGC
//
// If this doesn't free everything, the debug CRT will let us know.
//
//==========================================================================
static void FinalGC()
{
delete Args;
Args = nullptr;
GC::FinalGC = true;
GC::FullGC();
GC::DelSoftRootHead(); // the soft root head will not be collected by a GC so we have to do it explicitly
}
//==========================================================================
//
// Initialize
@ -2030,8 +2020,6 @@ static void D_DoomInit()
// Check response files before coalescing file parameters.
M_FindResponseFile ();
atterm(FinalGC);
// Combine different file parameters with their pre-switch bits.
Args->CollectFiles("-deh", ".deh");
Args->CollectFiles("-bex", ".bex");
@ -2331,22 +2319,6 @@ static void NewFailure ()
I_FatalError ("Failed to allocate memory from system heap");
}
//==========================================================================
//
// I_Quit
//
//==========================================================================
void I_Quit()
{
if (demorecording)
{
G_CheckDemoStatus();
}
C_DeinitConsole();
}
//==========================================================================
//
// D_DoomMain
@ -2368,7 +2340,6 @@ static int D_DoomMain_Internal (void)
C_InitConsole(80*8, 25*8, false);
I_DetectOS();
atterm(I_Quit);
// +logfile gets checked too late to catch the full startup log in the logfile so do some extra check for it here.
FString logfile = Args->TakeValue("+logfile");
@ -2811,8 +2782,6 @@ static int D_DoomMain_Internal (void)
{
G_BeginRecording(NULL);
}
atterm(D_QuitNetGame); // killough
}
}
}
@ -2860,6 +2829,20 @@ int D_DoomMain()
// Unless something really bad happened, the game should only exit through this single point in the code.
// No more 'exit', please.
// Todo: Move all engine cleanup here instead of using exit handlers and replace the scattered 'exit' calls with a special exception.
D_Cleanup();
CloseNetwork();
GC::FinalGC = true;
GC::FullGC();
GC::DelSoftRootHead(); // the soft root head will not be collected by a GC so we have to do it explicitly
C_DeinitConsole();
R_DeinitColormaps();
R_Shutdown();
I_ShutdownGraphics();
I_ShutdownInput();
M_SaveDefaultsFinal();
DeleteStartupScreen();
delete Args;
Args = nullptr;
return ret;
}
@ -2871,23 +2854,28 @@ int D_DoomMain()
void D_Cleanup()
{
if (demorecording)
{
G_CheckDemoStatus();
}
// Music and sound should be stopped first
S_StopMusic(true);
S_StopAllChannels ();
S_ClearSoundData();
S_UnloadReverbDef();
G_ClearMapinfo();
M_ClearMenus(); // close menu if open
F_EndFinale(); // If an intermission is active, end it now
AM_ClearColorsets();
DeinitSWColorMaps();
FreeSBarInfoScript();
// clean up game state
ST_Clear();
D_ErrorCleanup ();
for (auto Level : AllLevels())
{
Level->Thinkers.DestroyThinkersInList(STAT_STATIC);
}
staticEventManager.Shutdown();
P_FreeLevelData();
P_Shutdown();
M_SaveDefaults(NULL); // save config before the restart
@ -3012,6 +3000,24 @@ void FStartupScreen::AppendStatusLine(const char *status)
{
}
//===========================================================================
//
// DeleteStartupScreen
//
// Makes sure the startup screen has been deleted before quitting.
//
//===========================================================================
void DeleteStartupScreen()
{
if (StartScreen != nullptr)
{
delete StartScreen;
StartScreen = nullptr;
}
}
void FStartupScreen::Progress(void) {}
void FStartupScreen::NetInit(char const *,int) {}