From 2e7af1338cf40653f584a5439a105cc6d410b374 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 7 Oct 2019 20:28:55 +0200 Subject: [PATCH] - 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. --- src/CMakeLists.txt | 1 - src/d_main.cpp | 98 ++++++++++++---------- src/dobjtype.cpp | 3 - src/g_statusbar/sbarinfo.cpp | 7 +- src/gamedata/g_mapinfo.cpp | 6 +- src/gamedata/g_mapinfo.h | 1 + src/i_net.cpp | 3 - src/m_misc.cpp | 12 +-- src/menu/menudef.cpp | 4 - src/p_setup.cpp | 6 +- src/posix/cocoa/i_joystick.cpp | 10 +-- src/posix/cocoa/i_main.mm | 9 +- src/posix/cocoa/i_main_except.cpp | 48 ----------- src/posix/cocoa/i_system.mm | 1 - src/posix/cocoa/i_video.mm | 2 - src/posix/cocoa/st_start.mm | 3 - src/posix/sdl/hardware.cpp | 3 - src/posix/sdl/i_joystick.cpp | 2 +- src/posix/sdl/i_main.cpp | 5 -- src/posix/sdl/i_system.cpp | 1 - src/posix/sdl/st_start.cpp | 24 ------ src/rendering/r_utility.cpp | 8 +- src/rendering/swrenderer/r_swcolormaps.cpp | 5 +- src/rendering/swrenderer/r_swcolormaps.h | 1 + src/rendering/v_video.cpp | 15 ---- src/sound/s_advsound.cpp | 4 +- src/sound/s_environment.cpp | 4 - src/sound/s_music.cpp | 1 - src/sound/s_sound.cpp | 3 - src/sound/s_sound.h | 1 + src/st_start.h | 1 + src/utility/atterm.cpp | 97 --------------------- src/utility/atterm.h | 6 -- src/win32/hardware.cpp | 2 - src/win32/i_input.cpp | 2 - src/win32/i_main.cpp | 20 ++--- src/win32/i_system.cpp | 7 +- 37 files changed, 82 insertions(+), 344 deletions(-) delete mode 100644 src/utility/atterm.cpp delete mode 100644 src/utility/atterm.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2e146bbdc..fd9bcb40b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/d_main.cpp b/src/d_main.cpp index d8ff73e0b..0d0e7ef0c 100644 --- a/src/d_main.cpp +++ b/src/d_main.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 &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) {} diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index fd430a352..53fe68291 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -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); diff --git a/src/g_statusbar/sbarinfo.cpp b/src/g_statusbar/sbarinfo.cpp index f8929c998..104895ed0 100644 --- a/src/g_statusbar/sbarinfo.cpp +++ b/src/g_statusbar/sbarinfo.cpp @@ -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 diff --git a/src/gamedata/g_mapinfo.cpp b/src/gamedata/g_mapinfo.cpp index df5a95bb2..2cf29aef1 100644 --- a/src/gamedata/g_mapinfo.cpp +++ b/src/gamedata/g_mapinfo.cpp @@ -50,7 +50,6 @@ #include "g_levellocals.h" #include "events.h" #include "i_system.h" -#include "atterm.h" static TArray wadclusterinfos; TArray 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()) { diff --git a/src/gamedata/g_mapinfo.h b/src/gamedata/g_mapinfo.h index e3f387f8f..6e287fadc 100644 --- a/src/gamedata/g_mapinfo.h +++ b/src/gamedata/g_mapinfo.h @@ -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 diff --git a/src/i_net.cpp b/src/i_net.cpp index d7f3fe6cd..d6284abed 100644 --- a/src/i_net.cpp +++ b/src/i_net.cpp @@ -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; diff --git a/src/m_misc.cpp b/src/m_misc.cpp index aa4650ca9..feef6e2c3 100644 --- a/src/m_misc.cpp +++ b/src/m_misc.cpp @@ -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); } diff --git a/src/menu/menudef.cpp b/src/menu/menudef.cpp index 506cbf30e..90f4fa2b0 100644 --- a/src/menu/menudef.cpp +++ b/src/menu/menudef.cpp @@ -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) diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 287c6d61a..fd04bb915 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -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()) { diff --git a/src/posix/cocoa/i_joystick.cpp b/src/posix/cocoa/i_joystick.cpp index 189845c4a..bebf43b42 100644 --- a/src/posix/cocoa/i_joystick.cpp +++ b/src/posix/cocoa/i_joystick.cpp @@ -42,7 +42,6 @@ #include "m_joy.h" #include "templates.h" #include "v_text.h" -#include "atterm.h" EXTERN_CVAR(Bool, joy_axespolling) @@ -1175,13 +1174,7 @@ void IOKitJoystickManager::OnDeviceRemoved(void* const refcon, io_service_t, con // --------------------------------------------------------------------------- -void I_ShutdownJoysticks() -{ - // Needed in order to support existing interface - // Left empty intentionally -} - -static void ShutdownJoysticks() +void I_ShutdownInput() { delete s_joystickManager; s_joystickManager = NULL; @@ -1198,7 +1191,6 @@ void I_GetJoysticks(TArray& sticks) if (NULL == s_joystickManager && !Args->CheckParm("-nojoy")) { s_joystickManager = new IOKitJoystickManager; - atterm(ShutdownJoysticks); } if (NULL != s_joystickManager) diff --git a/src/posix/cocoa/i_main.mm b/src/posix/cocoa/i_main.mm index ba4d72b78..df47ede3a 100644 --- a/src/posix/cocoa/i_main.mm +++ b/src/posix/cocoa/i_main.mm @@ -33,7 +33,6 @@ #include "i_common.h" #include "s_sound.h" -#include "atterm.h" #include @@ -145,13 +144,14 @@ int OriginalMainTry(int argc, char** argv) { Args = new FArgs(argc, argv); - atexit(call_terms); - NSString* exePath = [[NSBundle mainBundle] executablePath]; progdir = [[exePath stringByDeletingLastPathComponent] UTF8String]; progdir += "/"; - return D_DoomMain(); + auto ret = D_DoomMain(); + ShutdownJoysticks(); + FConsoleWindow::DeleteInstance(); + return ret; } namespace @@ -266,7 +266,6 @@ extern bool AppActive; forMode:NSDefaultRunLoopMode]; FConsoleWindow::CreateInstance(); - atterm(FConsoleWindow::DeleteInstance); const size_t argc = s_argv.Size(); TArray argv(argc + 1, true); diff --git a/src/posix/cocoa/i_main_except.cpp b/src/posix/cocoa/i_main_except.cpp index 5c136adca..e69de29bb 100644 --- a/src/posix/cocoa/i_main_except.cpp +++ b/src/posix/cocoa/i_main_except.cpp @@ -1,48 +0,0 @@ -/* - ** i_main_except.cpp - ** - **--------------------------------------------------------------------------- - ** Copyright 2012-2015 Alexey Lysiuk - ** All rights reserved. - ** - ** Redistribution and use in source and binary forms, with or without - ** modification, are permitted provided that the following conditions - ** are met: - ** - ** 1. Redistributions of source code must retain the above copyright - ** notice, this list of conditions and the following disclaimer. - ** 2. Redistributions in binary form must reproduce the above copyright - ** notice, this list of conditions and the following disclaimer in the - ** documentation and/or other materials provided with the distribution. - ** 3. The name of the author may not be used to endorse or promote products - ** derived from this software without specific prior written permission. - ** - ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - **--------------------------------------------------------------------------- - ** - */ -// Workaround for GCC Objective-C++ with C++ exceptions bug. - -#include - -#include "doomerrors.h" -#include "vm.h" -#include "atterm.h" - -// Import some functions from i_main.mm - -void OriginalMainTry(int argc, char** argv); - -void OriginalMainExcept(int argc, char** argv) -{ - OriginalMainTry(argc, argv); -} diff --git a/src/posix/cocoa/i_system.mm b/src/posix/cocoa/i_system.mm index 08ecb4a25..e28443490 100644 --- a/src/posix/cocoa/i_system.mm +++ b/src/posix/cocoa/i_system.mm @@ -48,7 +48,6 @@ #include "v_text.h" #include "x86.h" #include "cmdlib.h" -#include "atterm.h" void I_Tactile(int /*on*/, int /*off*/, int /*total*/) diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index 3dd0d0547..a2c4f3f85 100644 --- a/src/posix/cocoa/i_video.mm +++ b/src/posix/cocoa/i_video.mm @@ -54,7 +54,6 @@ #include "v_text.h" #include "version.h" #include "doomerrors.h" -#include "atterm.h" #include "gl/system/gl_framebuffer.h" #include "vulkan/system/vk_framebuffer.h" @@ -751,7 +750,6 @@ void I_ShutdownGraphics() void I_InitGraphics() { Video = new CocoaVideo; - atterm(I_ShutdownGraphics); } diff --git a/src/posix/cocoa/st_start.mm b/src/posix/cocoa/st_start.mm index 609bb7376..feaa5412f 100644 --- a/src/posix/cocoa/st_start.mm +++ b/src/posix/cocoa/st_start.mm @@ -172,8 +172,5 @@ FStartupScreen *FStartupScreen::CreateInstance(const int maxProgress) void ST_Endoom() { - extern void I_ShutdownJoysticks(); - I_ShutdownJoysticks(); - throw CExitEvent(0); } diff --git a/src/posix/sdl/hardware.cpp b/src/posix/sdl/hardware.cpp index b761529af..9493b7c48 100644 --- a/src/posix/sdl/hardware.cpp +++ b/src/posix/sdl/hardware.cpp @@ -43,7 +43,6 @@ #include "m_argv.h" #include "doomerrors.h" #include "swrenderer/r_swrenderer.h" -#include "atterm.h" IVideo *Video; @@ -83,6 +82,4 @@ void I_InitGraphics () if (Video == NULL) I_FatalError ("Failed to initialize display"); - - atterm(I_ShutdownGraphics); } diff --git a/src/posix/sdl/i_joystick.cpp b/src/posix/sdl/i_joystick.cpp index 98e4cf7c1..14015550b 100644 --- a/src/posix/sdl/i_joystick.cpp +++ b/src/posix/sdl/i_joystick.cpp @@ -301,7 +301,7 @@ void I_StartupJoysticks() if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) >= 0) JoystickManager = new SDLInputJoystickManager(); } -void I_ShutdownJoysticks() +void I_ShutdownInput() { if(JoystickManager) { diff --git a/src/posix/sdl/i_main.cpp b/src/posix/sdl/i_main.cpp index c3954b96b..8b9414ec9 100644 --- a/src/posix/sdl/i_main.cpp +++ b/src/posix/sdl/i_main.cpp @@ -56,13 +56,9 @@ #include "doomerrors.h" #include "i_system.h" #include "g_game.h" -#include "atterm.h" // MACROS ------------------------------------------------------------------ -// The maximum number of functions that can be registered with atterm. -#define MAX_TERMS 64 - // TYPES ------------------------------------------------------------------- // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- @@ -151,7 +147,6 @@ void I_DetectOS() } void I_StartupJoysticks(); -void I_ShutdownJoysticks(); int main (int argc, char **argv) { diff --git a/src/posix/sdl/i_system.cpp b/src/posix/sdl/i_system.cpp index 530fdb2b2..b18cd42c8 100644 --- a/src/posix/sdl/i_system.cpp +++ b/src/posix/sdl/i_system.cpp @@ -51,7 +51,6 @@ #include "d_net.h" #include "g_game.h" #include "c_dispatch.h" -#include "atterm.h" #include "gameconfigfile.h" diff --git a/src/posix/sdl/st_start.cpp b/src/posix/sdl/st_start.cpp index 59d04a99c..d213b26fd 100644 --- a/src/posix/sdl/st_start.cpp +++ b/src/posix/sdl/st_start.cpp @@ -42,7 +42,6 @@ #include "doomdef.h" #include "i_system.h" #include "c_cvars.h" -#include "atterm.h" // MACROS ------------------------------------------------------------------ @@ -71,12 +70,8 @@ class FTTYStartupScreen : public FStartupScreen // PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- -void I_ShutdownJoysticks(); - // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- -static void DeleteStartupScreen(); - // EXTERNAL DATA DECLARATIONS ---------------------------------------------- // PUBLIC DATA DEFINITIONS ------------------------------------------------- @@ -106,27 +101,9 @@ static const char SpinnyProgressChars[4] = { '|', '/', '-', '\\' }; FStartupScreen *FStartupScreen::CreateInstance(int max_progress) { - atterm(DeleteStartupScreen); return new FTTYStartupScreen(max_progress); } -//=========================================================================== -// -// DeleteStartupScreen -// -// Makes sure the startup screen has been deleted before quitting. -// -//=========================================================================== - -void DeleteStartupScreen() -{ - if (StartScreen != NULL) - { - delete StartScreen; - StartScreen = NULL; - } -} - //=========================================================================== // // FTTYStartupScreen Constructor @@ -349,6 +326,5 @@ bool FTTYStartupScreen::NetLoop(bool (*timer_callback)(void *), void *userdata) void ST_Endoom() { - I_ShutdownJoysticks(); throw CExitEvent(0); } diff --git a/src/rendering/r_utility.cpp b/src/rendering/r_utility.cpp index 4258b6278..3445c7ac3 100644 --- a/src/rendering/r_utility.cpp +++ b/src/rendering/r_utility.cpp @@ -64,7 +64,6 @@ #include "actorinlines.h" #include "g_game.h" #include "i_system.h" -#include "atterm.h" // EXTERNAL DATA DECLARATIONS ---------------------------------------------- @@ -154,7 +153,6 @@ DAngle viewpitch; DEFINE_GLOBAL(LocalViewPitch); // CODE -------------------------------------------------------------------- -static void R_Shutdown (); //========================================================================== // @@ -380,8 +378,6 @@ FRenderer *CreateSWRenderer(); void R_Init () { - atterm(R_Shutdown); - StartScreen->Progress(); R_InitTranslationTables (); R_SetViewSize (screenblocks); @@ -400,12 +396,10 @@ void R_Init () // //========================================================================== -static void R_Shutdown () +void R_Shutdown () { if (SWRenderer != nullptr) delete SWRenderer; SWRenderer = nullptr; - R_DeinitTranslationTables(); - R_DeinitColormaps (); } //========================================================================== diff --git a/src/rendering/swrenderer/r_swcolormaps.cpp b/src/rendering/swrenderer/r_swcolormaps.cpp index f22f67cc4..e312930a0 100644 --- a/src/rendering/swrenderer/r_swcolormaps.cpp +++ b/src/rendering/swrenderer/r_swcolormaps.cpp @@ -55,7 +55,6 @@ #include "templates.h" #include "r_utility.h" #include "swrenderer/r_renderer.h" -#include "atterm.h" #include FDynamicColormap NormalLight; @@ -452,7 +451,7 @@ static void InitBoomColormaps () // //========================================================================== -static void DeinitSWColorMaps() +void DeinitSWColorMaps() { FreeSpecialLights(); if (realcolormaps.Maps != nullptr) @@ -475,8 +474,6 @@ static void DeinitSWColorMaps() void InitSWColorMaps() { - DeinitSWColorMaps(); - atterm(DeinitSWColorMaps); InitBoomColormaps(); NormalLight.Color = PalEntry (255, 255, 255); NormalLight.Fade = 0; diff --git a/src/rendering/swrenderer/r_swcolormaps.h b/src/rendering/swrenderer/r_swcolormaps.h index b7d053d9b..73b484c9f 100644 --- a/src/rendering/swrenderer/r_swcolormaps.h +++ b/src/rendering/swrenderer/r_swcolormaps.h @@ -30,6 +30,7 @@ extern FDynamicColormap FullNormalLight; extern bool NormalLightHasFixedLights; extern TArray SpecialSWColormaps; +void DeinitSWColorMaps(); void InitSWColorMaps(); FDynamicColormap *GetSpecialLights (PalEntry lightcolor, PalEntry fadecolor, int desaturate); void SetDefaultColormap (const char *name); diff --git a/src/rendering/v_video.cpp b/src/rendering/v_video.cpp index 21993b46e..f5c9f3314 100644 --- a/src/rendering/v_video.cpp +++ b/src/rendering/v_video.cpp @@ -69,7 +69,6 @@ #include "version.h" #include "g_levellocals.h" #include "am_map.h" -#include "atterm.h" EXTERN_CVAR(Int, menu_resolution_custom_width) EXTERN_CVAR(Int, menu_resolution_custom_height) @@ -563,9 +562,6 @@ void V_InitScreenSize () const char *i; int width, height, bits; - atterm(V_Shutdown); - - width = height = bits = 0; if ( (i = Args->CheckValue ("-width")) ) @@ -632,17 +628,6 @@ void V_Init2() setsizeneeded = true; } -void V_Shutdown() -{ - if (screen) - { - DFrameBuffer *s = screen; - screen = NULL; - delete s; - } - V_ClearFonts(); -} - CUSTOM_CVAR (Int, vid_aspect, 0, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) { setsizeneeded = true; diff --git a/src/sound/s_advsound.cpp b/src/sound/s_advsound.cpp index 151875acb..19e55ef13 100644 --- a/src/sound/s_advsound.cpp +++ b/src/sound/s_advsound.cpp @@ -48,7 +48,6 @@ #include "r_data/sprites.h" #include "vm.h" #include "i_system.h" -#include "atterm.h" #include "s_music.h" #include "mididevices/mididevice.h" @@ -943,7 +942,7 @@ void FPlayerSoundHashTable::MarkUsed() // be cleared for each level //========================================================================== -static void S_ClearSoundData() +void S_ClearSoundData() { S_StopAllChannels(); S_UnloadAllSounds(); @@ -981,7 +980,6 @@ void S_ParseSndInfo (bool redefine) int lump; if (!redefine) SavedPlayerSounds.Clear(); // clear skin sounds only for initial parsing. - atterm(S_ClearSoundData); S_ClearSoundData(); // remove old sound data first! CurrentPitchMask = 0; diff --git a/src/sound/s_environment.cpp b/src/sound/s_environment.cpp index 64bb93bd7..affb68de2 100644 --- a/src/sound/s_environment.cpp +++ b/src/sound/s_environment.cpp @@ -46,7 +46,6 @@ #include "vm.h" #include "dobject.h" #include "menu/menu.h" -#include "atterm.h" @@ -643,9 +642,6 @@ void S_ParseReverbDef () { int lump, lastlump = 0; - atterm(S_UnloadReverbDef); - S_UnloadReverbDef (); - while ((lump = Wads.FindLump ("REVERBS", &lastlump)) != -1) { ReadReverbDef (lump); diff --git a/src/sound/s_music.cpp b/src/sound/s_music.cpp index 5245a880b..8cae82760 100644 --- a/src/sound/s_music.cpp +++ b/src/sound/s_music.cpp @@ -84,7 +84,6 @@ #include "g_levellocals.h" #include "vm.h" #include "g_game.h" -#include "atterm.h" #include "s_music.h" #include "filereadermusicinterface.h" #include "zmusic/musinfo.h" diff --git a/src/sound/s_sound.cpp b/src/sound/s_sound.cpp index 426d1602f..58e9d30e8 100644 --- a/src/sound/s_sound.cpp +++ b/src/sound/s_sound.cpp @@ -82,7 +82,6 @@ #include "g_levellocals.h" #include "vm.h" #include "g_game.h" -#include "atterm.h" #include "s_music.h" // MACROS ------------------------------------------------------------------ @@ -306,8 +305,6 @@ void S_Init () { int curvelump; - atterm(S_Shutdown); - // Heretic and Hexen have sound curve lookup tables. Doom does not. I_InitSound(); curvelump = Wads.CheckNumForName ("SNDCURVE"); diff --git a/src/sound/s_sound.h b/src/sound/s_sound.h index c6d130728..a4ef2a335 100644 --- a/src/sound/s_sound.h +++ b/src/sound/s_sound.h @@ -334,6 +334,7 @@ void S_UpdateSounds (AActor *listener); void S_RestoreEvictedChannels(); // [RH] S_sfx "maintenance" routines +void S_ClearSoundData(); void S_ParseSndInfo (bool redefine); void S_ParseReverbDef (); void S_UnloadReverbDef (); diff --git a/src/st_start.h b/src/st_start.h index 78399fccb..8e53b0e4f 100644 --- a/src/st_start.h +++ b/src/st_start.h @@ -130,6 +130,7 @@ protected: extern FStartupScreen *StartScreen; +void DeleteStartupScreen(); extern void ST_Endoom(); // The entire set of functions here uses native Windows types. These are recreations of those types so that the code doesn't need to be changed more than necessary diff --git a/src/utility/atterm.cpp b/src/utility/atterm.cpp deleted file mode 100644 index 51270ec03..000000000 --- a/src/utility/atterm.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* -** attern.cpp -** Termination handling -** -**--------------------------------------------------------------------------- -** Copyright 1998-2007 Randy Heit -** Copyright 2019 Christoph Oelckers -** All rights reserved. -** -** Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions -** are met: -** -** 1. Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** 2. Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in the -** documentation and/or other materials provided with the distribution. -** 3. The name of the author may not be used to endorse or promote products -** derived from this software without specific prior written permission. -** -** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -**--------------------------------------------------------------------------- -** -*/ - - -#include -#include "tarray.h" -#include "atterm.h" - -static TArray> TermFuncs; - - -//========================================================================== -// -// atterm -// -// Our own atexit because atexit can be problematic under Linux, though I -// forget the circumstances that cause trouble. -// -//========================================================================== - -void addterm(void (*func)(), const char *name) -{ - // Make sure this function wasn't already registered. - - for (auto &term : TermFuncs) - { - if (term.first == func) - { - return; - } - } - TermFuncs.Push(std::make_pair(func, name)); -} - -//========================================================================== -// -// call_terms -// -//========================================================================== - -void call_terms() -{ - for(int i = TermFuncs.Size()-1; i >= 0; i--) - { - TermFuncs[i].first(); - } - TermFuncs.Clear(); -} - -//========================================================================== -// -// popterm -// -// Removes the most recently register atterm function. -// -//========================================================================== - -void popterm() -{ - if (TermFuncs.Size() > 0) - { - TermFuncs.Pop(); - } -} - diff --git a/src/utility/atterm.h b/src/utility/atterm.h deleted file mode 100644 index 6c1a463c7..000000000 --- a/src/utility/atterm.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -void addterm (void (*func)(void), const char *name); -#define atterm(t) addterm (t, #t) -void popterm (); -void call_terms(); diff --git a/src/win32/hardware.cpp b/src/win32/hardware.cpp index c015c3a7a..afffaee93 100644 --- a/src/win32/hardware.cpp +++ b/src/win32/hardware.cpp @@ -49,7 +49,6 @@ #include "doomerrors.h" #include "i_system.h" #include "swrenderer/r_swrenderer.h" -#include "atterm.h" EXTERN_CVAR(Int, vid_enablevulkan) @@ -152,5 +151,4 @@ void I_InitGraphics () if (Video == NULL) I_FatalError ("Failed to initialize display"); - atterm(I_ShutdownGraphics); } diff --git a/src/win32/i_input.cpp b/src/win32/i_input.cpp index 99dc9f293..61d6c1880 100644 --- a/src/win32/i_input.cpp +++ b/src/win32/i_input.cpp @@ -88,7 +88,6 @@ #include "doomerrors.h" #include "i_system.h" #include "g_levellocals.h" -#include "atterm.h" // Compensate for w32api's lack @@ -613,7 +612,6 @@ bool I_InitInput (void *hwnd) HRESULT hr; Printf ("I_InitInput\n"); - atterm(I_ShutdownInput); noidle = !!Args->CheckParm ("-noidle"); g_pdi = NULL; diff --git a/src/win32/i_main.cpp b/src/win32/i_main.cpp index ef1e78caa..59ed03475 100644 --- a/src/win32/i_main.cpp +++ b/src/win32/i_main.cpp @@ -73,7 +73,6 @@ #include "vm.h" #include "i_system.h" #include "gstrings.h" -#include "atterm.h" #include "s_music.h" #include "stats.h" @@ -88,9 +87,6 @@ #define X64 "" #endif -// The maximum number of functions that can be registered with atterm. -#define MAX_TERMS 64 - // TYPES ------------------------------------------------------------------- // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- @@ -99,6 +95,7 @@ LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); void CreateCrashLog (const char *custominfo, DWORD customsize, HWND richedit); void DisplayCrashLog (); void I_FlushBufferedConsoleStuff(); +void DestroyCustomCursor(); // PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- @@ -149,7 +146,7 @@ static HMODULE hwtsapi32; // handle to wtsapi32.dll // // UnCOM // -// Called by atterm if CoInitialize() succeeded. +// Called by atexit if CoInitialize() succeeded. // //========================================================================== @@ -162,7 +159,7 @@ static void UnCOM (void) // // UnWTS // -// Called by atterm if RegisterSessionNotification() succeeded. +// Called by atexit if RegisterSessionNotification() succeeded. // //========================================================================== @@ -617,11 +614,7 @@ void RestoreConView() ShowWindow (GameTitleWindow, SW_SHOW); I_ShutdownInput (); // Make sure the mouse pointer is available. // Make sure the progress bar isn't visible. - if (StartScreen != NULL) - { - delete StartScreen; - StartScreen = NULL; - } + DeleteStartupScreen(); } //========================================================================== @@ -847,8 +840,6 @@ int DoMain (HINSTANCE hInstance) timeBeginPeriod (TimerPeriod); atexit(UnTbp); - atexit (call_terms); - // Figure out what directory the program resides in. WCHAR progbuff[1024]; if (GetModuleFileNameW(nullptr, progbuff, sizeof progbuff) == 0) @@ -960,10 +951,9 @@ int DoMain (HINSTANCE hInstance) atexit (UnCOM); int ret = D_DoomMain (); + DestroyCustomCursor(); if (ret == 1337) // special exit code for 'norun'. { - // The only way D_DoomMain can exit regularly is by executing a -norun startup, which was previously handled via exception. - I_ShutdownGraphics(); if (!batchrun) { if (FancyStdOut && !AttachedStdOut) diff --git a/src/win32/i_system.cpp b/src/win32/i_system.cpp index 4c9218cb9..6f8a4fd57 100644 --- a/src/win32/i_system.cpp +++ b/src/win32/i_system.cpp @@ -84,7 +84,6 @@ #include "doomstat.h" #include "i_system.h" #include "textures/bitmap.h" -#include "atterm.h" // MACROS ------------------------------------------------------------------ @@ -103,6 +102,8 @@ extern void LayoutMainWindow(HWND hWnd, HWND pane); // PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- +void DestroyCustomCursor(); + // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- static void CalculateCPUSpeed(); @@ -110,7 +111,6 @@ static void CalculateCPUSpeed(); static HCURSOR CreateCompatibleCursor(FBitmap &cursorpic, int leftofs, int topofs); static HCURSOR CreateAlphaCursor(FBitmap &cursorpic, int leftofs, int topofs); static HCURSOR CreateBitmapCursor(int xhot, int yhot, HBITMAP and_mask, HBITMAP color_mask); -static void DestroyCustomCursor(); // EXTERNAL DATA DECLARATIONS ---------------------------------------------- @@ -718,7 +718,6 @@ bool I_SetCursor(FTexture *cursorpic) // Replace the existing cursor with the new one. DestroyCustomCursor(); CustomCursor = cursor; - atterm(DestroyCustomCursor); } else { @@ -921,7 +920,7 @@ static HCURSOR CreateBitmapCursor(int xhot, int yhot, HBITMAP and_mask, HBITMAP // //========================================================================== -static void DestroyCustomCursor() +void DestroyCustomCursor() { if (CustomCursor != NULL) {