Skip to content
Permalink
Browse files

- 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.
  • Loading branch information...
coelckers committed Oct 7, 2019
1 parent 6f821a9 commit 2e7af1338cf40653f584a5439a105cc6d410b374
@@ -1136,7 +1136,6 @@ set (PCH_SOURCES
utility/nodebuilder/nodebuild_utility.cpp
utility/sc_man.cpp
utility/stats.cpp
utility/atterm.cpp
utility/cmdlib.cpp
utility/configfile.cpp
utility/i_time.cpp
@@ -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) {}
@@ -50,7 +50,6 @@
#include "types.h"
#include "scriptutil.h"
#include "i_system.h"
#include "atterm.h"

// MACROS ------------------------------------------------------------------

@@ -209,8 +208,6 @@ static int cregcmp (const void *a, const void *b) NO_SANITIZE

void PClass::StaticInit ()
{
atterm(StaticShutdown);

Namespaces.GlobalNamespace = Namespaces.NewNamespace(0);

FAutoSegIterator probe(CRegHead, CRegTail);
@@ -49,7 +49,6 @@
#include "vm.h"
#include "i_system.h"
#include "utf8.h"
#include "atterm.h"

#define ARTIFLASH_OFFSET (statusBar->invBarOffset+6)
enum
@@ -425,7 +424,7 @@ static const char *StatusBars[] =
NULL
};

static void FreeSBarInfoScript()
void FreeSBarInfoScript()
{
for(int i = 0;i < 2;i++)
{
@@ -439,9 +438,6 @@ static void FreeSBarInfoScript()

void SBarInfo::Load()
{
FreeSBarInfoScript();
MugShotStates.Clear();

if(gameinfo.statusbar.IsNotEmpty())
{
int lump = Wads.CheckNumForFullName(gameinfo.statusbar, true);
@@ -468,7 +464,6 @@ void SBarInfo::Load()
SBarInfoScript[SCRIPT_CUSTOM]->ParseSBarInfo(lump);
}
}
atterm(FreeSBarInfoScript);
}

//SBarInfo Script Reader
@@ -50,7 +50,6 @@
#include "g_levellocals.h"
#include "events.h"
#include "i_system.h"
#include "atterm.h"

static TArray<cluster_info_t> wadclusterinfos;
TArray<level_info_t> wadlevelinfos;
@@ -2376,7 +2375,7 @@ void FMapInfoParser::ParseMapInfo (int lump, level_info_t &gamedefaults, level_i

void DeinitIntermissions();

static void ClearMapinfo()
void G_ClearMapinfo()
{
wadclusterinfos.Clear();
wadlevelinfos.Clear();
@@ -2402,9 +2401,6 @@ void G_ParseMapInfo (FString basemapinfo)
int lump, lastlump = 0;
level_info_t gamedefaults;

ClearMapinfo();
atterm(ClearMapinfo);

// Parse the default MAPINFO for the current game. This lump *MUST* come from zdoom.pk3.
if (basemapinfo.IsNotEmpty())
{
@@ -454,6 +454,7 @@ level_info_t *CheckLevelRedirect (level_info_t *info);

FString CalcMapName (int episode, int level);

void G_ClearMapinfo();
void G_ParseMapInfo (FString basemapinfo);

enum ESkillProperty
@@ -62,7 +62,6 @@
#include "st_start.h"
#include "m_misc.h"
#include "doomerrors.h"
#include "atterm.h"
#include "cmdlib.h"

#include "i_net.h"
@@ -435,8 +434,6 @@ void StartNetwork (bool autoPort)
}
#endif

atterm(CloseNetwork);

netgame = true;
multiplayer = true;

@@ -66,7 +66,6 @@

#include "gameconfigfile.h"
#include "gstrings.h"
#include "atterm.h"

FGameConfigFile *GameConfig;

@@ -271,7 +270,8 @@ bool M_SaveDefaults (const char *filename)
FString oldpath;
bool success;

if (filename != NULL)
if (GameConfig == nullptr) return true;
if (filename != nullptr)
{
oldpath = GameConfig->GetPathName();
GameConfig->ChangePathName (filename);
@@ -282,7 +282,7 @@ bool M_SaveDefaults (const char *filename)
GameConfig->ArchiveGameData (gameinfo.ConfigName);
}
success = GameConfig->WriteConfigFile ();
if (filename != NULL)
if (filename != nullptr)
{
GameConfig->ChangePathName (filename);
}
@@ -291,12 +291,13 @@ bool M_SaveDefaults (const char *filename)

void M_SaveDefaultsFinal ()
{
while (!M_SaveDefaults (NULL) && I_WriteIniFailed ())
if (GameConfig == nullptr) return;
while (!M_SaveDefaults (nullptr) && I_WriteIniFailed ())
{
/* Loop until the config saves or I_WriteIniFailed() returns false */
}
delete GameConfig;
GameConfig = NULL;
GameConfig = nullptr;
}

UNSAFE_CCMD (writeini)
@@ -320,7 +321,6 @@ void M_LoadDefaults ()
{
GameConfig = new FGameConfigFile;
GameConfig->DoGlobalSetup ();
atterm(M_SaveDefaultsFinal);
}


@@ -50,7 +50,6 @@
#include "gstrings.h"
#include "teaminfo.h"
#include "r_data/sprites.h"
#include "atterm.h"
#include "zmusic/zmusic.h"


@@ -1011,9 +1010,6 @@ void M_ParseMenuDefs()
DefaultListMenuSettings->Reset();
DefaultOptionMenuSettings->Reset();

atterm( DeinitMenus);
DeinitMenus();

int IWADMenu = Wads.CheckNumForName("MENUDEF", ns_global, Wads.GetIwadNum());

while ((lump = Wads.FindLump ("MENUDEF", &lastlump)) != -1)
@@ -75,14 +75,12 @@
#include "i_system.h"
#include "v_video.h"
#include "fragglescript/t_script.h"
#include "atterm.h"
#include "s_music.h"

extern AActor *SpawnMapThing (int index, FMapThing *mthing, int position);

extern unsigned int R_OldBlend;

static void P_Shutdown ();

//===========================================================================
//
@@ -572,15 +570,13 @@ void P_SetupLevel(FLevelLocals *Level, int position, bool newGame)
//
void P_Init ()
{
atterm(P_Shutdown);

P_InitEffects (); // [RH]
P_InitTerrainTypes ();
P_InitKeyMessages ();
R_InitSprites ();
}

static void P_Shutdown ()
void P_Shutdown ()
{
for (auto Level : AllLevels())
{

0 comments on commit 2e7af13

Please sign in to comment.
You can’t perform that action at this time.