Split the Shutdown function

Comments By: @vladislavbelov
Differential Revision: https://code.wildfiregames.com/D5148
This was SVN commit r28056.
This commit is contained in:
phosit 2024-03-24 12:45:27 +00:00
parent 942e4548b0
commit 7cf230341a
4 changed files with 29 additions and 23 deletions

View File

@ -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<const char* const> argv)
if (!Init(args, flags))
{
flags &= ~INIT_MODS;
Shutdown(SHUTDOWN_FROM_CONFIG);
ShutdownConfigAndSubsequent();
continue;
}
@ -708,7 +708,8 @@ static void RunGameOrAtlas(const PS::span<const char* const> 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;

View File

@ -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");

View File

@ -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<CStr>& 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<CStr>& installedMods = std::vector<CStr>());
/**
* `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();

View File

@ -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();
}