diff --git a/src/commandlets/commandlet.cpp b/src/commandlets/commandlet.cpp index cfd236edf..ff167fac5 100644 --- a/src/commandlets/commandlet.cpp +++ b/src/commandlets/commandlet.cpp @@ -2,9 +2,12 @@ #include "commandlet.h" #include "lightmapcmd.h" #include "version.h" +#include "v_draw.h" +#include "v_video.h" #include int D_DoomMain_Game(); +void D_BeginDoomLoop(); static std::function* ToolCallback; extern bool DisableLogging; @@ -17,8 +20,11 @@ int ToolMain() void Commandlet::RunInGame(std::function action) { - std::function callback = [=]() { + std::function callback = [&]() { DisableLogging = false; + + D_BeginDoomLoop(); + twod->Begin(screen->GetWidth(), screen->GetHeight()); action(); }; diff --git a/src/commandlets/lightmapcmd.cpp b/src/commandlets/lightmapcmd.cpp index 318f5b82c..4cc9d4483 100644 --- a/src/commandlets/lightmapcmd.cpp +++ b/src/commandlets/lightmapcmd.cpp @@ -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()); }); } diff --git a/src/d_main.cpp b/src/d_main.cpp index 38522ad31..e6484ff2b 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -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 { diff --git a/src/g_level.cpp b/src/g_level.cpp index fbd500008..b8ed812dc 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -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) {