Process commandlets without always initializing the entire engine
This commit is contained in:
parent
5491aecd5f
commit
794cfd78c8
12 changed files with 110 additions and 25 deletions
|
|
@ -2,6 +2,45 @@
|
|||
#include "commandlet.h"
|
||||
#include "lightmapcmd.h"
|
||||
#include "version.h"
|
||||
#include <functional>
|
||||
|
||||
int D_DoomMain_Game();
|
||||
static std::function<void()>* ToolCallback;
|
||||
extern bool DisableLogging;
|
||||
|
||||
int ToolMain()
|
||||
{
|
||||
RootCommandlet commands;
|
||||
commands.RunCommand();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Commandlet::RunInGame(std::function<void()> action)
|
||||
{
|
||||
std::function<void()> callback = [=]() {
|
||||
DisableLogging = false;
|
||||
action();
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
bool verbose = Args->CheckParm("-verbose") != 0;
|
||||
if (!verbose)
|
||||
DisableLogging = true;
|
||||
ToolCallback = &callback;
|
||||
D_DoomMain_Game();
|
||||
ToolCallback = nullptr;
|
||||
DisableLogging = false;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ToolCallback = nullptr;
|
||||
DisableLogging = false;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CommandletGroup::AddGroup(std::unique_ptr<CommandletGroup> group)
|
||||
{
|
||||
|
|
@ -20,6 +59,12 @@ RootCommandlet::RootCommandlet()
|
|||
AddGroup<LightmapCmdletGroup>();
|
||||
}
|
||||
|
||||
void RootCommandlet::RunEngineCommand()
|
||||
{
|
||||
if (ToolCallback)
|
||||
(*ToolCallback)();
|
||||
}
|
||||
|
||||
void RootCommandlet::RunCommand()
|
||||
{
|
||||
FArgs args = *Args;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include "templates.h"
|
||||
#include "zstring.h"
|
||||
#include "printf.h"
|
||||
|
|
@ -15,6 +16,8 @@ public:
|
|||
virtual void OnCommand(FArgs args) = 0;
|
||||
virtual void OnPrintHelp() = 0;
|
||||
|
||||
void RunInGame(std::function<void()> action);
|
||||
|
||||
const FString& GetLongFormName() const { return LongFormName; }
|
||||
const FString& GetShortDescription() const { return ShortDescription; }
|
||||
|
||||
|
|
@ -60,7 +63,9 @@ class RootCommandlet : public CommandletGroup
|
|||
{
|
||||
public:
|
||||
RootCommandlet();
|
||||
|
||||
void RunCommand();
|
||||
static void RunEngineCommand();
|
||||
|
||||
private:
|
||||
void RunCommand(CommandletGroup* group, FArgs args, const FString prefix);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,9 @@ LightmapBuildCmdlet::LightmapBuildCmdlet()
|
|||
|
||||
void LightmapBuildCmdlet::OnCommand(FArgs args)
|
||||
{
|
||||
Printf("Baking LIGHTMAP lump!\n");
|
||||
RunInGame([]() {
|
||||
Printf("Baking LIGHTMAP lump!\n");
|
||||
});
|
||||
}
|
||||
|
||||
void LightmapBuildCmdlet::OnPrintHelp()
|
||||
|
|
@ -38,7 +40,9 @@ LightmapDeleteCmdlet::LightmapDeleteCmdlet()
|
|||
|
||||
void LightmapDeleteCmdlet::OnCommand(FArgs args)
|
||||
{
|
||||
Printf("Deleting LIGHTMAP lump!\n");
|
||||
RunInGame([]() {
|
||||
Printf("Deleting LIGHTMAP lump!\n");
|
||||
});
|
||||
}
|
||||
|
||||
void LightmapDeleteCmdlet::OnPrintHelp()
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@
|
|||
#include "oalsound.h"
|
||||
|
||||
#include "i_module.h"
|
||||
#include "i_interface.h"
|
||||
#include "cmdlib.h"
|
||||
|
||||
#include "c_dispatch.h"
|
||||
|
|
@ -253,6 +254,9 @@ void I_InitSound ()
|
|||
nosound = !!Args->CheckParm ("-nosound");
|
||||
nosfx = !!Args->CheckParm ("-nosfx");
|
||||
|
||||
if (RunningAsTool)
|
||||
nosound = true;
|
||||
|
||||
GSnd = NULL;
|
||||
if (nosound)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -408,11 +408,12 @@ void WriteLineToLog(FILE *LogFile, const char *outline)
|
|||
fflush(LogFile);
|
||||
}
|
||||
|
||||
bool DisableLogging;
|
||||
extern bool gameisdead;
|
||||
|
||||
int PrintString (int iprintlevel, const char *outline)
|
||||
{
|
||||
if (gameisdead)
|
||||
if ((!RunningAsTool && gameisdead) || DisableLogging)
|
||||
return 0;
|
||||
|
||||
if (!conbuffer) return 0; // when called too early
|
||||
|
|
|
|||
|
|
@ -520,7 +520,8 @@ bool I_InitInput (void *hwnd)
|
|||
{
|
||||
HRESULT hr;
|
||||
|
||||
Printf ("I_InitInput\n");
|
||||
if (!RunningAsTool)
|
||||
Printf ("I_InitInput\n");
|
||||
|
||||
noidle = !!Args->CheckParm ("-noidle");
|
||||
g_pdi = NULL;
|
||||
|
|
@ -532,19 +533,24 @@ bool I_InitInput (void *hwnd)
|
|||
g_pdi = NULL; // Just to be sure DirectInput8Create didn't change it
|
||||
}
|
||||
|
||||
Printf ("I_StartupMouse\n");
|
||||
if (!RunningAsTool)
|
||||
Printf ("I_StartupMouse\n");
|
||||
I_StartupMouse();
|
||||
|
||||
Printf ("I_StartupKeyboard\n");
|
||||
if (!RunningAsTool)
|
||||
Printf ("I_StartupKeyboard\n");
|
||||
I_StartupKeyboard();
|
||||
|
||||
Printf ("I_StartupXInput\n");
|
||||
if (!RunningAsTool)
|
||||
Printf ("I_StartupXInput\n");
|
||||
I_StartupXInput();
|
||||
|
||||
Printf ("I_StartupRawPS2\n");
|
||||
if (!RunningAsTool)
|
||||
Printf ("I_StartupRawPS2\n");
|
||||
I_StartupRawPS2();
|
||||
|
||||
Printf ("I_StartupDirectInputJoystick\n");
|
||||
if (!RunningAsTool)
|
||||
Printf ("I_StartupDirectInputJoystick\n");
|
||||
I_StartupDirectInputJoystick();
|
||||
|
||||
return TRUE;
|
||||
|
|
|
|||
|
|
@ -337,7 +337,8 @@ int DoMain (HINSTANCE hInstance)
|
|||
void I_ShowFatalError(const char *msg)
|
||||
{
|
||||
I_ShutdownGraphics ();
|
||||
mainwindow.RestoreConView();
|
||||
if (!RunningAsTool)
|
||||
mainwindow.RestoreConView();
|
||||
S_StopMusic(true);
|
||||
|
||||
if (CVMAbortException::stacktrace.IsNotEmpty())
|
||||
|
|
|
|||
|
|
@ -365,7 +365,8 @@ void V_Init2()
|
|||
I_InitGraphics();
|
||||
|
||||
Video->SetResolution(); // this only fails via exceptions.
|
||||
Printf ("Resolution: %d x %d\n", SCREENWIDTH, SCREENHEIGHT);
|
||||
if (!RunningAsTool)
|
||||
Printf("Resolution: %d x %d\n", SCREENWIDTH, SCREENHEIGHT);
|
||||
|
||||
// init these for the scaling menu
|
||||
menu_resolution_custom_width = SCREENWIDTH;
|
||||
|
|
|
|||
|
|
@ -586,9 +586,9 @@ void VulkanRenderDevice::PrintStartupLog()
|
|||
Printf(PRINT_LOG, "\n");
|
||||
|
||||
const auto &limits = props.limits;
|
||||
Printf("Max. texture size: %d\n", limits.maxImageDimension2D);
|
||||
Printf("Max. uniform buffer range: %d\n", limits.maxUniformBufferRange);
|
||||
Printf("Min. uniform buffer offset alignment: %" PRIu64 "\n", limits.minUniformBufferOffsetAlignment);
|
||||
Printf(PRINT_LOG, "Max. texture size: %d\n", limits.maxImageDimension2D);
|
||||
Printf(PRINT_LOG, "Max. uniform buffer range: %d\n", limits.maxUniformBufferRange);
|
||||
Printf(PRINT_LOG, "Min. uniform buffer offset alignment: %" PRIu64 "\n", limits.minUniformBufferOffsetAlignment);
|
||||
}
|
||||
|
||||
void VulkanRenderDevice::SetLevelMesh(LevelMesh* mesh)
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "x86.h"
|
||||
#include "printf.h"
|
||||
|
||||
CPUInfo CPU;
|
||||
|
||||
|
|
@ -194,7 +195,7 @@ FString DumpCPUInfo(const CPUInfo *cpu, bool brief)
|
|||
out.Format("CPU Vendor ID: %s\n", cpu->VendorID);
|
||||
if (cpustring[0])
|
||||
{
|
||||
out.AppendFormat(" Name: %s\n", cpustring);
|
||||
out.AppendFormat(" Name: " TEXTCOLOR_ORANGE "%s" TEXTCOLOR_NORMAL "\n", cpustring);
|
||||
}
|
||||
if (cpu->bIsAMD)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -759,7 +759,7 @@ int FIWadManager::IdentifyVersion (std::vector<std::string>&wadfiles, const char
|
|||
{
|
||||
if (RunningAsTool)
|
||||
{
|
||||
Printf("Please specify which iwad to use with -iwad\n");
|
||||
I_FatalError("Please specify which iwad to use with -iwad\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -141,6 +141,7 @@ void D_DoAnonStats();
|
|||
void I_DetectOS();
|
||||
void UpdateGenericUI(bool cvar);
|
||||
void Local_Job_Init();
|
||||
int ToolMain();
|
||||
|
||||
// MACROS ------------------------------------------------------------------
|
||||
|
||||
|
|
@ -3646,11 +3647,16 @@ static int D_InitGame(const FIWADInfo* iwad_info, std::vector<std::string>& allw
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
static int D_DoomMain_Internal (void)
|
||||
namespace
|
||||
{
|
||||
const char *wad;
|
||||
FIWadManager *iwad_man;
|
||||
const char* wad;
|
||||
const char* batchout;
|
||||
}
|
||||
|
||||
int D_DoomMain_Game();
|
||||
|
||||
int GameMain_Internal()
|
||||
{
|
||||
NetworkEntityManager::NetIDStart = MAXPLAYERS + 1;
|
||||
GC::AddMarkerFunc(GC_MarkGameRoots);
|
||||
VM_CastSpriteIDToString = Doom_CastSpriteIDToString;
|
||||
|
|
@ -3700,7 +3706,7 @@ static int D_DoomMain_Internal (void)
|
|||
|
||||
|
||||
std::set_new_handler(NewFailure);
|
||||
const char *batchout = Args->CheckValue("-errorlog");
|
||||
batchout = Args->CheckValue("-errorlog");
|
||||
|
||||
D_DoomInit();
|
||||
|
||||
|
|
@ -3764,6 +3770,19 @@ static int D_DoomMain_Internal (void)
|
|||
}
|
||||
|
||||
C_InitConsole(80*8, 25*8, false);
|
||||
|
||||
if (RunningAsTool)
|
||||
{
|
||||
return ToolMain();
|
||||
}
|
||||
else
|
||||
{
|
||||
return D_DoomMain_Game();
|
||||
}
|
||||
}
|
||||
|
||||
int D_DoomMain_Game()
|
||||
{
|
||||
I_DetectOS();
|
||||
|
||||
// +logfile gets checked too late to catch the full startup log in the logfile so do some extra check for it here.
|
||||
|
|
@ -3794,7 +3813,7 @@ static int D_DoomMain_Internal (void)
|
|||
|
||||
FString optionalwad = BaseFileSearch(OPTIONALWAD, NULL, true, GameConfig);
|
||||
|
||||
iwad_man = new FIWadManager(basewad.GetChars(), optionalwad.GetChars());
|
||||
FIWadManager* iwad_man = new FIWadManager(basewad.GetChars(), optionalwad.GetChars());
|
||||
|
||||
// Now that we have the IWADINFO, initialize the autoload ini sections.
|
||||
GameConfig->DoAutoloadSetup(iwad_man);
|
||||
|
|
@ -3852,9 +3871,7 @@ static int D_DoomMain_Internal (void)
|
|||
|
||||
if (RunningAsTool)
|
||||
{
|
||||
Printf("\n");
|
||||
RootCommandlet commands;
|
||||
commands.RunCommand();
|
||||
RootCommandlet::RunEngineCommand();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -3891,7 +3908,7 @@ int GameMain()
|
|||
|
||||
try
|
||||
{
|
||||
ret = D_DoomMain_Internal();
|
||||
ret = GameMain_Internal();
|
||||
}
|
||||
catch (const CExitEvent &exit) // This is a regular exit initiated from deeply nested code.
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue