Load a map

This commit is contained in:
Magnus Norddahl 2025-01-07 11:30:49 +01:00
commit bddf1a2548
4 changed files with 90 additions and 43 deletions

View file

@ -2,9 +2,12 @@
#include "commandlet.h"
#include "lightmapcmd.h"
#include "version.h"
#include "v_draw.h"
#include "v_video.h"
#include <functional>
int D_DoomMain_Game();
void D_BeginDoomLoop();
static std::function<void()>* ToolCallback;
extern bool DisableLogging;
@ -17,8 +20,11 @@ int ToolMain()
void Commandlet::RunInGame(std::function<void()> action)
{
std::function<void()> callback = [=]() {
std::function<void()> callback = [&]() {
DisableLogging = false;
D_BeginDoomLoop();
twod->Begin(screen->GetWidth(), screen->GetHeight());
action();
};

View file

@ -1,5 +1,10 @@
#include "lightmapcmd.h"
#include "g_levellocals.h"
#include "d_event.h"
void G_SetMap(const char* mapname, int mode);
void D_SingleTick();
LightmapCmdletGroup::LightmapCmdletGroup()
{
@ -20,8 +25,24 @@ LightmapBuildCmdlet::LightmapBuildCmdlet()
void LightmapBuildCmdlet::OnCommand(FArgs args)
{
RunInGame([]() {
RunInGame([&]() {
FString mapname;
if (args.NumArgs() > 0 && args.GetArg(0)[0] != '-')
mapname = args.GetArg(0);
else
mapname = "map01";
G_SetMap(mapname.GetChars(), 0);
for (int i = 0; i < 100; i++)
{
D_SingleTick();
if (gameaction == ga_nothing)
break;
}
Printf("Baking LIGHTMAP lump!\n");
Printf("Current map is %s", level.LevelName.GetChars());
});
}

View file

@ -1216,6 +1216,33 @@ void D_ErrorCleanup ()
ClearGlobalVMStack();
}
void D_BeginDoomLoop()
{
// Clamp the timer to TICRATE until the playloop has been entered.
r_NoInterpolate = true;
Page.SetInvalid();
Subtitle = nullptr;
Advisory.SetInvalid();
}
void D_SingleTick()
{
I_StartTic();
D_ProcessEvents();
G_BuildTiccmd(&netcmds[consoleplayer][maketic % BACKUPTICS]);
if (advancedemo)
D_DoAdvanceDemo();
C_Ticker();
M_Ticker();
G_Ticker();
// [RH] Use the consoleplayer's camera to update sounds
S_UpdateSounds(players[consoleplayer].camera); // move positional sounds
gametic++;
maketic++;
GC::CheckGC();
Net_NewMakeTic();
}
//==========================================================================
//
// D_DoomLoop
@ -1227,16 +1254,11 @@ void D_ErrorCleanup ()
void D_DoomLoop ()
{
int lasttic = 0;
// Clamp the timer to TICRATE until the playloop has been entered.
r_NoInterpolate = true;
Page.SetInvalid();
Subtitle = nullptr;
Advisory.SetInvalid();
D_BeginDoomLoop();
vid_cursor->Callback();
int lasttic = 0;
for (;;)
{
try
@ -1254,20 +1276,7 @@ void D_DoomLoop ()
// process one or more tics
if (singletics)
{
I_StartTic ();
D_ProcessEvents ();
G_BuildTiccmd (&netcmds[consoleplayer][maketic%BACKUPTICS]);
if (advancedemo)
D_DoAdvanceDemo ();
C_Ticker ();
M_Ticker ();
G_Ticker ();
// [RH] Use the consoleplayer's camera to update sounds
S_UpdateSounds (players[consoleplayer].camera); // move positional sounds
gametic++;
maketic++;
GC::CheckGC ();
Net_NewMakeTic ();
D_SingleTick();
}
else
{

View file

@ -305,6 +305,30 @@ void G_DeferedInitNew (FNewGameStartup *gs)
//
//==========================================================================
void G_SetMap(const char* mapname, int mode)
{
if (!strcmp(mapname, "*")) mapname = primaryLevel->MapName.GetChars();
if (!P_CheckMapData(mapname))
{
Printf("No map %s\n", mapname);
}
else
{
if (mode == 1)
{
deathmatch = false;
multiplayernext = true;
}
else if (mode == 2)
{
deathmatch = true;
multiplayernext = true;
}
G_DeferedInitNew(mapname);
}
}
CCMD (map)
{
if (netgame)
@ -316,28 +340,15 @@ CCMD (map)
if (argv.argc() > 1)
{
const char *mapname = argv[1];
if (!strcmp(mapname, "*")) mapname = primaryLevel->MapName.GetChars();
try
{
if (!P_CheckMapData(mapname))
{
Printf ("No map %s\n", mapname);
}
else
{
if (argv.argc() > 2 && stricmp(argv[2], "coop") == 0)
{
deathmatch = false;
multiplayernext = true;
}
else if (argv.argc() > 2 && stricmp(argv[2], "dm") == 0)
{
deathmatch = true;
multiplayernext = true;
}
G_DeferedInitNew (mapname);
}
int mode = 0;
if (argv.argc() > 2 && stricmp(argv[2], "coop") == 0)
mode = 1;
else if (argv.argc() > 2 && stricmp(argv[2], "dm") == 0)
mode = 2;
G_SetMap(mapname, mode);
}
catch(CRecoverableError &error)
{