Process commandlets without always initializing the entire engine

This commit is contained in:
Magnus Norddahl 2025-01-07 10:55:48 +01:00
commit 794cfd78c8
12 changed files with 110 additions and 25 deletions

View file

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