Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(gameengine): -turbo fast-forwards a run that draws

Olcay Seyganec9780b49163
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index 531220ae1..727bfe25c 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -424,6 +424,7 @@ public:
Int m_autoSkirmishAIState; ///< SlotState the AI slots of an auto-started skirmish get (-aidiff)
Bool m_autoSkirmishObserver; ///< -observer: the local slot of an auto-started skirmish watches instead of playing
Bool m_headless; ///< -headless: never draw a frame, never pace the logic tick, quit when the match ends
+ Bool m_turbo; ///< -turbo: draw, but run one logic frame a pass instead of pacing it to the wall clock
Int m_autoSkirmishAIStateOdd; ///< -aidiff2 <name>: rung for the odd-numbered slots (0 = same as -aidiff)
Int m_autoSkirmishTeams; ///< -teams <n>: split the auto-skirmish slots into n allied teams (0 or 1 = free-for-all)
Int m_peaceTime; ///< -peacetime <n>: the lobby's peace time, in minutes, for an -autoskirmish run
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
index 5cdd64647..92009869c 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
@@ -1529,6 +1529,22 @@ Int parseWav(char *args[], int num)
return consumed;
}
+/* -turbo: a run that draws plays its match as fast as the machine draws it, one logic frame a pass,
+ the branch -headless and -video already take. A -screenshot at frame 3000 otherwise waits 100
+ seconds of wall clock at 30 logic frames a second for a picture that only needs frame 3000 to be
+ reached. The logic is identical frame for frame (same HEADLESS CRC), and a turbo shot repeats
+ itself, but it is not the paced shot: the cloud shadows scroll on the wall clock, and the two
+ differ on 7% of the pixels. Compare turbo with turbo. Ignored in a network game, whose clock
+ is the network's, and under -wav, which has to run at the speed a person hears. */
+Int parseTurbo(char *args[], int)
+{
+ if (TheWritableGlobalData)
+ {
+ TheWritableGlobalData->m_turbo = TRUE;
+ }
+ return 1;
+}
+
/* -autocamera [seconds]: every so often, put the camera wherever the fighting is.
*
* A soak run watches from a free camera that never moves, and a camera that never moves is the
@@ -2347,6 +2363,7 @@ static CommandLineParam params[] =
{ "-screenshot", parseScreenShot },
{ "-video", parseVideo },
{ "-wav", parseWav },
+ { "-turbo", parseTurbo },
{ "-msaa", parseMSAA },
{ "-d3d9", parseDirect3D9 },
{ "-language", parseTextLanguage },
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index d0a5514ab..87f0df385 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -2168,6 +2168,18 @@ void GameEngine::update( void )
of an unattended run. */
fastMode = fastMode || TheGlobalData->m_headless;
+ /* -turbo: the same for a run that draws, unless a network or a sound recording owns the clock.
+ The five seconds before a -screenshot run at the real rate. Taken straight out of
+ fast-forward, a shot differed from its own repeat on 5.6% of the pixels; settled first, on
+ 0.01%, where two paced runs differ on 0.1%. */
+ const Int TURBO_SETTLE_FRAMES = 150;
+ const Int turboFrame = (Int)TheGameLogic->getFrame();
+ const Bool turboSettling = TheGlobalData->m_screenShotFrame > 0
+ && turboFrame + TURBO_SETTLE_FRAMES >= TheGlobalData->m_screenShotFrame
+ && turboFrame <= TheGlobalData->m_screenShotFrame;
+ fastMode = fastMode || ( TheGlobalData->m_turbo && !turboSettling && TheNetwork == NULL
+ && TheGlobalData->m_wavEndFrame == 0 );
+
/* -video: one logic frame a pass across the range being recorded, so the draw in front of each
logic frame is the one picture of it. Paced by the wall clock, a pass that fell behind would
run two logic frames back to back and the video would jump over one. */
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index 22edaa720..4c10a85b3 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -706,6 +706,7 @@ GlobalData::GlobalData()
m_unitLimit = FALSE; // no unit limit unless -unitlimit asks for one
m_autoSkirmishObserver = FALSE;
m_headless = FALSE;
+ m_turbo = FALSE;
m_maxGameFrames = 0; // run until the match ends
m_screenShotFrame = 0; // take no picture unless -screenshot asks for one
m_videoStartFrame = 0;
diff --git a/ai-batch.ps1 b/ai-batch.ps1
index b353f4be1..bd7657911 100644
--- a/ai-batch.ps1
+++ b/ai-batch.ps1
@@ -124,6 +124,7 @@ for ($i = 0; $i -lt $Runs; $i++) {
Write-Host ("[{0,3}/{1}] seed {2} {3} ... " -f ($i + 1), $Runs, $seed, $where) -NoNewline
$sw = [Diagnostics.Stopwatch]::StartNew()
$proc = Start-Process -FilePath $exePath -ArgumentList $args -WorkingDirectory $RunDir -PassThru
+ $proc.PriorityClass = 'AboveNormal'
if (-not $proc.WaitForExit($TimeoutMinutes * 60 * 1000)) {
$proc.Kill()
Write-Host "KILLED (wedged past $TimeoutMinutes min)"
diff --git a/dx11-check.ps1 b/dx11-check.ps1
index 4497d27bc..fc14118cc 100644
--- a/dx11-check.ps1
+++ b/dx11-check.ps1
@@ -78,9 +78,10 @@ function Shoot($c, $tag, $extra) {
$arguments = @('-win','-xres','1280','-yres','720','-quickstart','-noshellmap','-multiInstance',
'-msaa','0','-dx11post','off','-map',"`"Maps\$($c.map)\$($c.map).map`"",'-autoskirmish','4','-aidiff','easy',
'-seed','5','-maxframes',($c.f+80),'-screenshot',$c.f,'-camera',$c.x,$c.y,
- '-logPrefix',"dx11chk_$tag`_") + $extra + $Extra
+ '-logPrefix',"dx11chk_$tag`_",'-turbo') + $extra + $Extra
try {
$process = Start-Process (Join-Path $run 'generals.exe') -ArgumentList $arguments -WorkingDirectory $run -PassThru
+ $process.PriorityClass = 'AboveNormal'
$null = $process.WaitForExit(900000)
}
finally {
diff --git a/replay-check.ps1 b/replay-check.ps1
index 34c61393c..f5e84f5bf 100644
--- a/replay-check.ps1
+++ b/replay-check.ps1
@@ -63,6 +63,7 @@ function Invoke-Run([string[]] $extra, [string] $prefix)
$args = @("-headless", "-quickstart", "-noshellmap", "-multiInstance", "-noFPSLimit",
"-maxframes", $MaxFrames, "-logPrefix", $prefix) + $extra + $ExtraArgs
$proc = Start-Process -FilePath $exePath -ArgumentList $args -WorkingDirectory $RunDir -PassThru
+ $proc.PriorityClass = 'AboveNormal'
$proc.WaitForExit()
$log = Join-Path $RunDir "$($prefix)DebugLogFile.txt"
if (-not (Test-Path $log)) { return $null }
diff --git a/shadow-check.ps1 b/shadow-check.ps1
index 46e27adf2..8902a002f 100644
--- a/shadow-check.ps1
+++ b/shadow-check.ps1
@@ -31,11 +31,12 @@ function Shoot($case, $tag, $extra) {
$arguments = @('-win','-xres','1280','-yres','720','-quickstart','-noshellmap','-multiInstance',
'-msaa','0','-dx11post','off','-map',"`"Maps\$($case.map)\$($case.map).map`"",
'-autoskirmish','4','-aidiff','easy','-seed','5','-maxframes',($case.f+80),
- '-screenshot',$case.f,'-camera',$case.x,$case.y,'-logPrefix',"shd_$tag`_")
+ '-screenshot',$case.f,'-camera',$case.x,$case.y,'-logPrefix',"shd_$tag`_",'-turbo')
if ($extra) { $arguments += $extra }
try {
$process = Start-Process (Join-Path $run "generals.exe") -ArgumentList $arguments `
-WorkingDirectory $run -PassThru
+ $process.PriorityClass = 'AboveNormal'
$null = $process.WaitForExit(900000)
}
finally {
diff --git a/tree-check.ps1 b/tree-check.ps1
index 2356b8c61..4ff30a930 100644
--- a/tree-check.ps1
+++ b/tree-check.ps1
@@ -18,6 +18,14 @@ $shots = "$env:USERPROFILE\Documents\Command and Conquer Generals Zero Hour Data
$tmp = Join-Path $env:TEMP "treecheck"
if (-not (Test-Path $tmp)) { $null = New-Item -ItemType Directory $tmp }
+# -turbo cuts a view from about 90 seconds to about 25, but the cloud shadows scroll on the wall
+# clock, so a turbo shot and a paced one of the same frame differ on 7% of the pixels. Both builds
+# have to run the same way: turbo when the reference build knows the switch, paced when it does not.
+$baseExe = Join-Path $run 'generals_base.exe'
+$pace = @()
+if (Select-String -Path $baseExe -Pattern '-turbo' -SimpleMatch -Quiet) { $pace = @('-turbo') }
+else { "generals_base.exe predates -turbo: both builds run paced, about 90 seconds a view" }
+
$cases = @(
@{map='Flash Effect'; x='1200'; y='945'; f=400},
@{map='Flash Effect'; x='1816'; y='1861'; f=1200},
@@ -46,9 +54,10 @@ function Shoot($exe, $c, $tag) {
Get-ChildItem "$shots\sshot*.bmp" -ErrorAction SilentlyContinue | Remove-Item -Force
$args = @('-win','-xres','1280','-yres','720','-quickstart','-noshellmap','-multiInstance','-msaa','0','-dx11post','off',
'-map',"`"Maps\$($c.map)\$($c.map).map`"",'-autoskirmish','4','-aidiff','easy','-seed','5',
- '-maxframes',($c.f+80),'-screenshot',$c.f,'-camera',$c.x,$c.y,'-logPrefix',"chk_$tag`_")
+ '-maxframes',($c.f+80),'-screenshot',$c.f,'-camera',$c.x,$c.y,'-logPrefix',"chk_$tag`_") + $pace
try {
$p = Start-Process (Join-Path $run $exe) -ArgumentList $args -WorkingDirectory $run -PassThru
+ $p.PriorityClass = 'AboveNormal'
$null = $p.WaitForExit(900000)
}
finally {