mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-13 07:57:52 +00:00
- cleaned up the startup code a bit.
Mainly splitting up D_DoomMain_Internal to put all the actual initialization from game data into a subfunction
This commit is contained in:
parent
65a37856ec
commit
ac1cfa6027
1 changed files with 454 additions and 455 deletions
377
src/d_main.cpp
377
src/d_main.cpp
|
@ -309,7 +309,6 @@ CUSTOM_CVAR(Int, I_FriendlyWindowTitle, 1, CVAR_GLOBALCONFIG|CVAR_ARCHIVE|CVAR_N
|
|||
bool hud_toggled = false;
|
||||
bool wantToRestart;
|
||||
bool DrawFSHUD; // [RH] Draw fullscreen HUD?
|
||||
TArray<FString> allwads;
|
||||
bool devparm; // started game with -devparm
|
||||
const char *D_DrawIcon; // [RH] Patch name of icon to draw on next refresh
|
||||
int NoWipe; // [RH] Allow wipe? (Needs to be set each time)
|
||||
|
@ -1749,14 +1748,6 @@ static void GetCmdLineFiles(TArray<FString> &wadfiles)
|
|||
}
|
||||
}
|
||||
|
||||
static void CopyFiles(TArray<FString> &to, TArray<FString> &from)
|
||||
{
|
||||
unsigned int ndx = to.Reserve(from.Size());
|
||||
for(unsigned i=0;i<from.Size(); i++)
|
||||
{
|
||||
to[ndx+i] = from[i];
|
||||
}
|
||||
}
|
||||
|
||||
static FString ParseGameInfo(TArray<FString> &pwads, const char *fn, const char *data, int size)
|
||||
{
|
||||
|
@ -1967,7 +1958,7 @@ static void D_DoomInit()
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
static void AddAutoloadFiles(const char *autoname)
|
||||
static void AddAutoloadFiles(const char *autoname, TArray<FString> allwads)
|
||||
{
|
||||
LumpFilterIWAD.Format("%s.", autoname); // The '.' is appened to simplify parsing the string
|
||||
|
||||
|
@ -2965,184 +2956,22 @@ bool CheckSkipGameOptionBlock(const char* str);
|
|||
|
||||
//==========================================================================
|
||||
//
|
||||
// D_DoomMain
|
||||
// D_InitGame
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
static int D_DoomMain_Internal (void)
|
||||
static int D_InitGame(const FIWADInfo* iwad_info, TArray<FString> allwads)
|
||||
{
|
||||
int p;
|
||||
const char *v;
|
||||
const char *wad;
|
||||
TArray<FString> pwads;
|
||||
FString *args;
|
||||
int argcount;
|
||||
FIWadManager *iwad_man;
|
||||
|
||||
GC::AddMarkerFunc(GC_MarkGameRoots);
|
||||
VM_CastSpriteIDToString = Doom_CastSpriteIDToString;
|
||||
|
||||
// Set up the button list. Mlook and Klook need a bit of extra treatment.
|
||||
buttonMap.SetButtons(DoomButtons, countof(DoomButtons));
|
||||
buttonMap.GetButton(Button_Mlook)->ReleaseHandler = Mlook_ReleaseHandler;
|
||||
buttonMap.GetButton(Button_Mlook)->bReleaseLock = true;
|
||||
buttonMap.GetButton(Button_Klook)->bReleaseLock = true;
|
||||
|
||||
sysCallbacks = {
|
||||
System_WantGuiCapture,
|
||||
System_WantLeftButton,
|
||||
System_NetGame,
|
||||
System_WantNativeMouse,
|
||||
System_CaptureModeInGame,
|
||||
System_CrashInfo,
|
||||
System_PlayStartupSound,
|
||||
System_IsSpecialUI,
|
||||
System_DisableTextureFilter,
|
||||
System_OnScreenSizeChanged,
|
||||
System_GetSceneRect,
|
||||
System_GetLocationDescription,
|
||||
System_M_Dim,
|
||||
System_GetPlayerName,
|
||||
System_DispatchEvent,
|
||||
StrTable_ValidFilter,
|
||||
StrTable_GetGender,
|
||||
nullptr,
|
||||
CheckSkipGameOptionBlock,
|
||||
System_ConsoleToggled,
|
||||
nullptr,
|
||||
nullptr,
|
||||
System_ToggleFullConsole,
|
||||
System_StartCutscene,
|
||||
System_SetTransition,
|
||||
};
|
||||
|
||||
|
||||
std::set_new_handler(NewFailure);
|
||||
const char *batchout = Args->CheckValue("-errorlog");
|
||||
|
||||
C_InitConsole(80*8, 25*8, false);
|
||||
I_DetectOS();
|
||||
|
||||
// +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");
|
||||
if (logfile.IsNotEmpty())
|
||||
{
|
||||
execLogfile(logfile);
|
||||
}
|
||||
else if (batchout != NULL && *batchout != 0)
|
||||
{
|
||||
batchrun = true;
|
||||
nosound = true;
|
||||
execLogfile(batchout, true);
|
||||
Printf("Command line: ");
|
||||
for (int i = 0; i < Args->NumArgs(); i++)
|
||||
{
|
||||
Printf("%s ", Args->GetArg(i));
|
||||
}
|
||||
Printf("\n");
|
||||
}
|
||||
|
||||
if (Args->CheckParm("-hashfiles"))
|
||||
{
|
||||
const char *filename = "fileinfo.txt";
|
||||
Printf("Hashing loaded content to: %s\n", filename);
|
||||
hashfile = fopen(filename, "w");
|
||||
if (hashfile)
|
||||
{
|
||||
fprintf(hashfile, "%s version %s (%s)\n", GAMENAME, GetVersionString(), GetGitHash());
|
||||
#ifdef __VERSION__
|
||||
fprintf(hashfile, "Compiler version: %s\n", __VERSION__);
|
||||
#endif
|
||||
fprintf(hashfile, "Command line:");
|
||||
for (int i = 0; i < Args->NumArgs(); ++i)
|
||||
{
|
||||
fprintf(hashfile, " %s", Args->GetArg(i));
|
||||
}
|
||||
fprintf(hashfile, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (!batchrun) Printf(PRINT_LOG, "%s version %s\n", GAMENAME, GetVersionString());
|
||||
|
||||
D_DoomInit();
|
||||
|
||||
extern void D_ConfirmSendStats();
|
||||
D_ConfirmSendStats();
|
||||
|
||||
// [RH] Make sure zdoom.pk3 is always loaded,
|
||||
// as it contains magic stuff we need.
|
||||
wad = BaseFileSearch (BASEWAD, NULL, true, GameConfig);
|
||||
if (wad == NULL)
|
||||
{
|
||||
I_FatalError ("Cannot find " BASEWAD);
|
||||
}
|
||||
FString basewad = wad;
|
||||
|
||||
FString optionalwad = BaseFileSearch(OPTIONALWAD, NULL, true, GameConfig);
|
||||
|
||||
iwad_man = new FIWadManager(basewad, optionalwad);
|
||||
|
||||
// Now that we have the IWADINFO, initialize the autoload ini sections.
|
||||
GameConfig->DoAutoloadSetup(iwad_man);
|
||||
|
||||
// Prevent the game from starting if the savegame passed to -loadgame is invalid
|
||||
v = Args->CheckValue("-loadgame");
|
||||
if (v)
|
||||
{
|
||||
FString file(v);
|
||||
FixPathSeperator(file);
|
||||
DefaultExtension(file, "." SAVEGAME_EXT);
|
||||
if (!FileExists(file))
|
||||
{
|
||||
I_FatalError("Cannot find savegame %s", file.GetChars());
|
||||
}
|
||||
}
|
||||
|
||||
// reinit from here
|
||||
|
||||
do
|
||||
{
|
||||
PClass::StaticInit();
|
||||
PType::StaticInit();
|
||||
|
||||
if (restart)
|
||||
{
|
||||
C_InitConsole(SCREENWIDTH, SCREENHEIGHT, false);
|
||||
}
|
||||
nospriterename = false;
|
||||
|
||||
// Load zdoom.pk3 alone so that we can get access to the internal gameinfos before
|
||||
// the IWAD is known.
|
||||
|
||||
GetCmdLineFiles(pwads);
|
||||
FString iwad = CheckGameInfo(pwads);
|
||||
|
||||
// The IWAD selection dialogue does not show in fullscreen so if the
|
||||
// restart is initiated without a defined IWAD assume for now that it's not going to change.
|
||||
if (iwad.IsEmpty()) iwad = lastIWAD;
|
||||
|
||||
if (iwad_man == NULL)
|
||||
{
|
||||
iwad_man = new FIWadManager(basewad, optionalwad);
|
||||
}
|
||||
const FIWADInfo *iwad_info = iwad_man->FindIWAD(allwads, iwad, basewad, optionalwad);
|
||||
if (!iwad_info) return 0; // user exited the selection popup via cancel button.
|
||||
gameinfo.gametype = iwad_info->gametype;
|
||||
gameinfo.flags = iwad_info->flags;
|
||||
gameinfo.nokeyboardcheats = iwad_info->nokeyboardcheats;
|
||||
gameinfo.ConfigName = iwad_info->Configname;
|
||||
lastIWAD = iwad;
|
||||
|
||||
|
||||
if ((gameinfo.flags & GI_SHAREWARE) && pwads.Size() > 0)
|
||||
{
|
||||
I_FatalError ("You cannot -file with the shareware version. Register!");
|
||||
}
|
||||
|
||||
FBaseCVar::DisableCallbacks();
|
||||
GameConfig->DoGameSetup (gameinfo.ConfigName);
|
||||
|
||||
AddAutoloadFiles(iwad_info->Autoname);
|
||||
AddAutoloadFiles(iwad_info->Autoname, allwads);
|
||||
|
||||
// Process automatically executed files
|
||||
FExecList *exec;
|
||||
|
@ -3160,16 +2989,11 @@ static int D_DoomMain_Internal (void)
|
|||
// [RH] process all + commands on the command line
|
||||
exec = C_ParseCmdLineParams(exec);
|
||||
|
||||
CopyFiles(allwads, pwads);
|
||||
if (exec != NULL)
|
||||
{
|
||||
exec->AddPullins(allwads, GameConfig);
|
||||
}
|
||||
|
||||
// Since this function will never leave we must delete this array here manually.
|
||||
pwads.Clear();
|
||||
pwads.ShrinkToFit();
|
||||
|
||||
if (hashfile)
|
||||
{
|
||||
Printf("Notice: File hashing is incredibly verbose. Expect loading files to take much longer than usual.\n");
|
||||
|
@ -3413,8 +3237,10 @@ static int D_DoomMain_Internal (void)
|
|||
|
||||
//Added by MC:
|
||||
primaryLevel->BotInfo.getspawned.Clear();
|
||||
argcount = Args->CheckParmList("-bots", &args);
|
||||
for (p = 0; p < argcount; ++p)
|
||||
|
||||
FString *args;
|
||||
int argcount = Args->CheckParmList("-bots", &args);
|
||||
for (int p = 0; p < argcount; ++p)
|
||||
{
|
||||
primaryLevel->BotInfo.getspawned.Push(args[p]);
|
||||
}
|
||||
|
@ -3437,7 +3263,7 @@ static int D_DoomMain_Internal (void)
|
|||
static const char *startupString[5] = {
|
||||
"STARTUP1", "STARTUP2", "STARTUP3", "STARTUP4", "STARTUP5"
|
||||
};
|
||||
for (p = 0; p < 5; ++p)
|
||||
for (int p = 0; p < 5; ++p)
|
||||
{
|
||||
// At this point we cannot use the player's gender info yet so force 'male' here.
|
||||
const char *str = GStrings.GetString(startupString[p], nullptr, 0);
|
||||
|
@ -3465,9 +3291,6 @@ static int D_DoomMain_Internal (void)
|
|||
// about to begin the game.
|
||||
FBaseCVar::EnableNoSet ();
|
||||
|
||||
delete iwad_man; // now we won't need this anymore
|
||||
iwad_man = NULL;
|
||||
|
||||
// [RH] Run any saved commands from the command line or autoexec.cfg now.
|
||||
gamestate = GS_FULLCONSOLE;
|
||||
Net_NewMakeTic ();
|
||||
|
@ -3481,7 +3304,7 @@ static int D_DoomMain_Internal (void)
|
|||
if (!restart)
|
||||
{
|
||||
// start the apropriate game based on parms
|
||||
v = Args->CheckValue ("-record");
|
||||
auto v = Args->CheckValue ("-record");
|
||||
|
||||
if (v)
|
||||
{
|
||||
|
@ -3568,11 +3391,187 @@ static int D_DoomMain_Internal (void)
|
|||
D_StartTitle (); // start up intro loop
|
||||
setmodeneeded = false; // This may be set to true here, but isn't needed for a restart
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
//==========================================================================
|
||||
//
|
||||
// D_DoomMain
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
static int D_DoomMain_Internal (void)
|
||||
{
|
||||
const char *v;
|
||||
const char *wad;
|
||||
FIWadManager *iwad_man;
|
||||
|
||||
GC::AddMarkerFunc(GC_MarkGameRoots);
|
||||
VM_CastSpriteIDToString = Doom_CastSpriteIDToString;
|
||||
|
||||
// Set up the button list. Mlook and Klook need a bit of extra treatment.
|
||||
buttonMap.SetButtons(DoomButtons, countof(DoomButtons));
|
||||
buttonMap.GetButton(Button_Mlook)->ReleaseHandler = Mlook_ReleaseHandler;
|
||||
buttonMap.GetButton(Button_Mlook)->bReleaseLock = true;
|
||||
buttonMap.GetButton(Button_Klook)->bReleaseLock = true;
|
||||
|
||||
sysCallbacks = {
|
||||
System_WantGuiCapture,
|
||||
System_WantLeftButton,
|
||||
System_NetGame,
|
||||
System_WantNativeMouse,
|
||||
System_CaptureModeInGame,
|
||||
System_CrashInfo,
|
||||
System_PlayStartupSound,
|
||||
System_IsSpecialUI,
|
||||
System_DisableTextureFilter,
|
||||
System_OnScreenSizeChanged,
|
||||
System_GetSceneRect,
|
||||
System_GetLocationDescription,
|
||||
System_M_Dim,
|
||||
System_GetPlayerName,
|
||||
System_DispatchEvent,
|
||||
StrTable_ValidFilter,
|
||||
StrTable_GetGender,
|
||||
nullptr,
|
||||
CheckSkipGameOptionBlock,
|
||||
System_ConsoleToggled,
|
||||
nullptr,
|
||||
nullptr,
|
||||
System_ToggleFullConsole,
|
||||
System_StartCutscene,
|
||||
System_SetTransition,
|
||||
};
|
||||
|
||||
|
||||
std::set_new_handler(NewFailure);
|
||||
const char *batchout = Args->CheckValue("-errorlog");
|
||||
|
||||
C_InitConsole(80*8, 25*8, false);
|
||||
I_DetectOS();
|
||||
|
||||
// +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");
|
||||
if (logfile.IsNotEmpty())
|
||||
{
|
||||
execLogfile(logfile);
|
||||
}
|
||||
else if (batchout != NULL && *batchout != 0)
|
||||
{
|
||||
batchrun = true;
|
||||
nosound = true;
|
||||
execLogfile(batchout, true);
|
||||
Printf("Command line: ");
|
||||
for (int i = 0; i < Args->NumArgs(); i++)
|
||||
{
|
||||
Printf("%s ", Args->GetArg(i));
|
||||
}
|
||||
Printf("\n");
|
||||
}
|
||||
|
||||
if (Args->CheckParm("-hashfiles"))
|
||||
{
|
||||
const char *filename = "fileinfo.txt";
|
||||
Printf("Hashing loaded content to: %s\n", filename);
|
||||
hashfile = fopen(filename, "w");
|
||||
if (hashfile)
|
||||
{
|
||||
fprintf(hashfile, "%s version %s (%s)\n", GAMENAME, GetVersionString(), GetGitHash());
|
||||
#ifdef __VERSION__
|
||||
fprintf(hashfile, "Compiler version: %s\n", __VERSION__);
|
||||
#endif
|
||||
fprintf(hashfile, "Command line:");
|
||||
for (int i = 0; i < Args->NumArgs(); ++i)
|
||||
{
|
||||
fprintf(hashfile, " %s", Args->GetArg(i));
|
||||
}
|
||||
fprintf(hashfile, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (!batchrun) Printf(PRINT_LOG, "%s version %s\n", GAMENAME, GetVersionString());
|
||||
|
||||
D_DoomInit();
|
||||
|
||||
extern void D_ConfirmSendStats();
|
||||
D_ConfirmSendStats();
|
||||
|
||||
// [RH] Make sure zdoom.pk3 is always loaded,
|
||||
// as it contains magic stuff we need.
|
||||
wad = BaseFileSearch (BASEWAD, NULL, true, GameConfig);
|
||||
if (wad == NULL)
|
||||
{
|
||||
I_FatalError ("Cannot find " BASEWAD);
|
||||
}
|
||||
FString basewad = wad;
|
||||
|
||||
FString optionalwad = BaseFileSearch(OPTIONALWAD, NULL, true, GameConfig);
|
||||
|
||||
iwad_man = new FIWadManager(basewad, optionalwad);
|
||||
|
||||
// Now that we have the IWADINFO, initialize the autoload ini sections.
|
||||
GameConfig->DoAutoloadSetup(iwad_man);
|
||||
|
||||
// Prevent the game from starting if the savegame passed to -loadgame is invalid
|
||||
v = Args->CheckValue("-loadgame");
|
||||
if (v)
|
||||
{
|
||||
FString file(v);
|
||||
FixPathSeperator(file);
|
||||
DefaultExtension(file, "." SAVEGAME_EXT);
|
||||
if (!FileExists(file))
|
||||
{
|
||||
I_FatalError("Cannot find savegame %s", file.GetChars());
|
||||
}
|
||||
}
|
||||
|
||||
// reinit from here
|
||||
|
||||
do
|
||||
{
|
||||
PClass::StaticInit();
|
||||
PType::StaticInit();
|
||||
|
||||
if (restart)
|
||||
{
|
||||
C_InitConsole(SCREENWIDTH, SCREENHEIGHT, false);
|
||||
}
|
||||
nospriterename = false;
|
||||
|
||||
if (iwad_man == NULL)
|
||||
{
|
||||
iwad_man = new FIWadManager(basewad, optionalwad);
|
||||
}
|
||||
|
||||
// Load zdoom.pk3 alone so that we can get access to the internal gameinfos before
|
||||
// the IWAD is known.
|
||||
|
||||
TArray<FString> pwads;
|
||||
GetCmdLineFiles(pwads);
|
||||
FString iwad = CheckGameInfo(pwads);
|
||||
|
||||
// The IWAD selection dialogue does not show in fullscreen so if the
|
||||
// restart is initiated without a defined IWAD assume for now that it's not going to change.
|
||||
if (iwad.IsEmpty()) iwad = lastIWAD;
|
||||
|
||||
TArray<FString> allwads;
|
||||
|
||||
const FIWADInfo *iwad_info = iwad_man->FindIWAD(allwads, iwad, basewad, optionalwad);
|
||||
if (!iwad_info) return 0; // user exited the selection popup via cancel button.
|
||||
if ((iwad_info->flags & GI_SHAREWARE) && pwads.Size() > 0)
|
||||
{
|
||||
I_FatalError ("You cannot -file with the shareware version. Register!");
|
||||
}
|
||||
allwads.Append(std::move(pwads));
|
||||
lastIWAD = iwad;
|
||||
|
||||
int ret = D_InitGame(iwad_info, allwads);
|
||||
allwads.Reset();
|
||||
delete iwad_man; // now we won't need this anymore
|
||||
iwad_man = NULL;
|
||||
if (ret != 0) return ret;
|
||||
|
||||
D_DoAnonStats();
|
||||
|
||||
I_UpdateWindowTitle();
|
||||
|
||||
D_DoomLoop (); // this only returns if a 'restart' CCMD is given.
|
||||
//
|
||||
// Clean up after a restart
|
||||
|
|
Loading…
Reference in a new issue