diff --git a/source/main.cpp b/source/main.cpp index 0847317a10..b68c64b8d7 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2023 Wildfire Games. +/* Copyright (C) 2024 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -654,7 +654,7 @@ static void RunGameOrAtlas(const PS::span argv) if (!Init(args, flags)) { flags &= ~INIT_MODS; - Shutdown(SHUTDOWN_FROM_CONFIG); + ShutdownConfigAndSubsequent(); continue; } @@ -708,7 +708,8 @@ static void RunGameOrAtlas(const PS::span argv) // Do not install mods again in case of restart (typically from the mod selector) modsToInstall.clear(); - Shutdown(0); + ShutdownNetworkAndUI(); + ShutdownConfigAndSubsequent(); MainControllerShutdown(); flags &= ~INIT_MODS; diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index 2895bbebc9..320f97e440 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -333,13 +333,10 @@ void EndGame() } } -void Shutdown(int flags) +void ShutdownNetworkAndUI() { const bool hasRenderer = CRenderer::IsInitialised(); - if ((flags & SHUTDOWN_FROM_CONFIG)) - goto from_config; - EndGame(); SAFE_DELETE(g_XmppClient); @@ -374,8 +371,10 @@ void Shutdown(int flags) curl_global_cleanup(); delete &g_L10n; +} -from_config: +void ShutdownConfigAndSubsequent() +{ TIMER_BEGIN(L"shutdown ConfigDB"); CConfigDB::Shutdown(); TIMER_END(L"shutdown ConfigDB"); diff --git a/source/ps/GameSetup/GameSetup.h b/source/ps/GameSetup/GameSetup.h index 57ea33942e..4fb6aecc0b 100644 --- a/source/ps/GameSetup/GameSetup.h +++ b/source/ps/GameSetup/GameSetup.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2023 Wildfire Games. +/* Copyright (C) 2024 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -52,14 +52,6 @@ enum InitFlags INIT_MODS_PUBLIC = 16 }; -enum ShutdownFlags -{ - // start shutdown from config down - // needed for loading mods as specified in the config - // without having to go through a full init-shutdown cycle - SHUTDOWN_FROM_CONFIG = 1 -}; - extern const std::vector& GetMods(const CmdLineArgs& args, int flags); /** @@ -73,13 +65,27 @@ void InitVfs(const CmdLineArgs& args); /** * Returns true if successful, false if Init is aborted early (for instance if * mods changed, or if we are using -dumpSchema). - * If false is returned, the caller should call Shutdown() with SHUTDOWN_FROM_CONFIG. + * `ShutdownConfigAndSubsequent` has to be called later. */ extern bool Init(const CmdLineArgs& args, int flags); extern void InitInput(); + +/** + * `ShutdownNetworkAndUI` has to be called later. + */ extern void InitGraphics(const CmdLineArgs& args, int flags, const std::vector& installedMods = std::vector()); + +/** + * `ShutdownNetworkAndUI` has to be called later. + */ extern bool InitNonVisual(const CmdLineArgs& args); -extern void Shutdown(int flags); + +/** + * Has to be called before `ShutdownConfigAndSubsequent`. + */ +void ShutdownNetworkAndUI(); +void ShutdownConfigAndSubsequent(); + extern void CancelLoad(const CStrW& message); extern bool InDevelopmentCopy(); diff --git a/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp index a2aff2f151..42ec7dee30 100644 --- a/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2023 Wildfire Games. +/* Copyright (C) 2024 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -81,7 +81,7 @@ MESSAGEHANDLER(Init) { // There are no mods specified on the command line, // but there are in the config file, so mount those. - Shutdown(SHUTDOWN_FROM_CONFIG); + ShutdownConfigAndSubsequent(); ENSURE(Init(g_AtlasGameLoop->args, g_InitFlags)); } @@ -146,8 +146,8 @@ MESSAGEHANDLER(Shutdown) AtlasView::DestroyViews(); g_AtlasGameLoop->view = AtlasView::GetView_None(); - int flags = 0; - Shutdown(flags); + ShutdownNetworkAndUI(); + ShutdownConfigAndSubsequent(); g_FileLogger.reset(); }