// Console commands of the simulation core (DESIGN_UE.md section 9.2): fast-forward, pause, and the intent override. #include "Core/DescentIntent.h" #include "Core/DescentSimSubsystem.h" #include "Debug/DescentCommandUtil.h" #include "TheDescent.h" #include "HAL/IConsoleManager.h" namespace { void CmdSimFastForward(const TArray& Args, UWorld* World) { TArray N; UDescentSimSubsystem* Sim = UDescentSimSubsystem::Get(World); if (!Sim || !Descent::Cmd::ParseNumbers(Args, 0, 1, N)) { Descent::Cmd::Fail(World, TEXT("Descent.Sim.FastForward"), TEXT("usage: Descent.Sim.FastForward [dt] (needs a running game)")); return; } double Dt = Descent::Tune::Sim::DefaultFastForwardDt; if (Args.Num() > 1) { TArray D; if (!Descent::Cmd::ParseNumbers(Args, 1, 1, D) || D[0] <= 0.0) { Descent::Cmd::Fail(World, TEXT("Descent.Sim.FastForward"), TEXT("dt must be a positive number of seconds")); return; } Dt = D[0]; } const double T0 = Sim->SimTime(); const int64 Steps = Sim->FastForward(N[0], Dt); if (Steps == 0 && N[0] > 0.0) { Descent::Cmd::Fail(World, TEXT("Descent.Sim.FastForward"), TEXT("refused or nothing to do (see the log)")); return; } UE_LOG(LogDescent, Display, TEXT("Sim.FastForward: %lld steps, sim time %.3f -> %.3f s"), Steps, T0, Sim->SimTime()); } void CmdSimPause(const TArray& Args, UWorld* World) { UDescentSimSubsystem* Sim = UDescentSimSubsystem::Get(World); bool bValid = false; const bool bPause = Args.Num() > 0 ? Descent::Cmd::ParseBool(Args[0], bValid) : false; if (!Sim || !bValid) { Descent::Cmd::Fail(World, TEXT("Descent.Sim.Pause"), TEXT("usage: Descent.Sim.Pause <0 or 1> (needs a running game)")); return; } Sim->SetPaused(bPause); UE_LOG(LogDescent, Display, TEXT("Sim.Pause: sim is now %s"), bPause ? TEXT("paused") : TEXT("running")); } FAutoConsoleCommandWithWorldAndArgs GSimCmdFastForward( TEXT("Descent.Sim.FastForward"), TEXT("Descent.Sim.FastForward [dt] - run the sim that long in one frame (no rendering, no character movement)"), FConsoleCommandWithWorldAndArgsDelegate::CreateStatic(&CmdSimFastForward)); FAutoConsoleCommandWithWorldAndArgs GSimCmdPause( TEXT("Descent.Sim.Pause"), TEXT("Descent.Sim.Pause <0 or 1> - stop or resume the sim tick (the late steps and the HUD keep running)"), FConsoleCommandWithWorldAndArgsDelegate::CreateStatic(&CmdSimPause)); }