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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
test(gameengine): time how long path requests wait in the queue
Olcay Seygan88846f557327
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cppindex 27a177f57..026488aeb 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp@@ -172,6 +172,19 @@ static Int thePFEscapes = 0; ///< backing-out manoeuvres startedstatic Int thePFCrowdRepaths = 0; ///< routes given up on because nothing on them could get paststatic Int thePFDithers = 0; ///< units caught driving a long way and gaining nothing+/* How long a request stood in the path queue before it was answered. The frame it went in is kept+ beside its slot for this count alone and nothing reads it back into a decision, so it is not+ saved and not in the CRC. */+static UnsignedInt theQueuedFrame[ PATHFIND_QUEUE_LEN ];+static Int thePFQServed = 0; ///< requests taken off the queue+static Int64 thePFQWaitSum = 0; ///< frames they waited, summed+static Int thePFQWaitMax = 0; ///< the longest one waited+static Int thePFQLate = 0; ///< answered more than a second after asking+static Int thePFQPeak = 0; ///< the deepest the queue got+static Int thePFQFull = 0; ///< refused because the queue was full+static Int thePFQCapFrames = 0; ///< frames the request cap stopped with requests left+static Int thePFQCellFrames = 0; ///< frames the cell budget stopped with requests left+inline void pfBump( Int slot ) { thePFCalls[ slot ]++; }class PathProfile@@ -5268,6 +5281,14 @@ void Pathfinder::resetMatchProfile( void )thePFEscapes = 0;thePFCrowdRepaths = 0;thePFDithers = 0;+ thePFQServed = 0;+ thePFQWaitSum = 0;+ thePFQWaitMax = 0;+ thePFQLate = 0;+ thePFQPeak = 0;+ thePFQFull = 0;+ thePFQCapFrames = 0;+ thePFQCellFrames = 0;}void Pathfinder::bumpNoPath( void )@@ -5334,6 +5355,12 @@ const char *Pathfinder::getMatchProfileReport( void )"| nopath %d outofcells %d blocked %d stuck %d wedge %d worst %d escape %d repath %d dither %d",thePFNoPath, thePFOutOfCells, thePFBlockedFrames, thePFStuckFrames,thePFWedgeFrames, thePFWedgeWorst, thePFEscapes, thePFCrowdRepaths, thePFDithers );+ len = strlen( thePFMatchReport );+ if( len < (Int)sizeof( thePFMatchReport ) - 160 )+ sprintf( thePFMatchReport + len,+ " | queued %d wait %.1f longest %d late %d peak %d full %d capped %d cellcapped %d",+ thePFQServed, thePFQServed ? (double)thePFQWaitSum / thePFQServed : 0.0, thePFQWaitMax,+ thePFQLate, thePFQPeak, thePFQFull, thePFQCapFrames, thePFQCellFrames );return thePFMatchReport;}@@ -7492,10 +7519,15 @@ Bool Pathfinder::queueForPath(ObjectID id)}if (nextSlot==m_queuePRHead) {DEBUG_LOG(("PATHFIND QUEUE FULL: object %d asks again shortly\n", id));+ thePFQFull++;return false;}m_queuedPathfindRequests[m_queuePRTail] = id;+ theQueuedFrame[m_queuePRTail] = TheGameLogic->getFrame();m_queuePRTail = nextSlot;+ const Int depth = (m_queuePRTail - m_queuePRHead + PATHFIND_QUEUE_LEN) % PATHFIND_QUEUE_LEN;+ if (depth > thePFQPeak)+ thePFQPeak = depth;if ((size_t)id >= m_isQueuedForPath.size()) {m_isQueuedForPath.resize( (size_t)id + 1024, false );}@@ -7763,11 +7795,19 @@ void Pathfinder::processPathfindQueue(void)frame half as long needs no less. */enum { PATHFIND_REQUESTS_PER_FRAME = 3 };Int requestsThisFrame = 0;+ const UnsignedInt now = TheGameLogic->getFrame();while (m_cumulativeCellsAllocated < PATHFIND_CELLS_PER_FRAME &&requestsThisFrame < PATHFIND_REQUESTS_PER_FRAME &&m_queuePRTail!=m_queuePRHead) {++requestsThisFrame;+ const Int waited = (Int)(now - theQueuedFrame[m_queuePRHead]);+ thePFQServed++;+ thePFQWaitSum += waited;+ if (waited > thePFQWaitMax)+ thePFQWaitMax = waited;+ if (waited > LOGICFRAMES_PER_SECOND)+ thePFQLate++;Object *obj = TheGameLogic->findObjectByID(m_queuedPathfindRequests[m_queuePRHead]);m_isQueuedForPath[m_queuedPathfindRequests[m_queuePRHead]] = false;m_queuedPathfindRequests[m_queuePRHead] = INVALID_ID;@@ -7785,6 +7825,12 @@ void Pathfinder::processPathfindQueue(void)m_queuePRHead = 0;}}+ if (m_queuePRTail != m_queuePRHead) {+ if (m_cumulativeCellsAllocated >= PATHFIND_CELLS_PER_FRAME)+ thePFQCellFrames++;+ else+ thePFQCapFrames++;+ }if (pathsFound>0) {#ifdef DEBUG_QPF#if defined _DEBUG || defined _INTERNALdiff --git a/ai-batch.ps1 b/ai-batch.ps1index da1ae0f03..369ef6b67 100644--- a/ai-batch.ps1+++ b/ai-batch.ps1@@ -204,7 +204,8 @@ foreach ($run in $started) {# blocked/stuck say whether the traffic jams it was aimed at actually got shorter$pf = [pscustomobject]@{ FindMs = 0.0; Finds = 0; Expands = 0; NoPath = 0; OutOfCells = 0; Blocked = 0; Stuck = 0Wedge = 0; WedgeWorst = 0; Escapes = 0; Repaths = 0- Dithers = 0; Orders = 0; Arrived = 0; Stalled = 0 }+ Dithers = 0; Orders = 0; Arrived = 0; Stalled = 0+ Queued = 0; QWait = 0.0; QLongest = 0; QLate = 0; QPeak = 0 }# THREADING-ROADMAP.md section 0: the per-scope frame cost, present only in a PERF_TIMERS# build (-Exe generals_perf.exe), and the job pool's own report, present in every build.$perf = @{}@@ -298,6 +299,12 @@ foreach ($run in $started) {if ($report -match "escape (\d+)") { $pf.Escapes = [int]$Matches[1] }if ($report -match "repath (\d+)") { $pf.Repaths = [int]$Matches[1] }if ($report -match "dither (\d+)") { $pf.Dithers = [int]$Matches[1] }+ # how long a request stood in the path queue: the late-game wait players see as a unit+ # that takes seconds to set off+ if ($report -match "queued (\d+) wait ([\d.]+) longest (\d+) late (\d+) peak (\d+)") {+ $pf.Queued = [int]$Matches[1]; $pf.QWait = [double]$Matches[2]; $pf.QLongest = [int]$Matches[3]+ $pf.QLate = [int]$Matches[4]; $pf.QPeak = [int]$Matches[5]+ }}elseif ($line -match "HEADLESS PLAYER (\d+) '(.*?)': (\w+) \| score (\d+) \| money (\d+) earned (\d+) spent \| units (\d+) built (\d+) lost (\d+) killed peak (\d+)(?:.*\| slot (-?\d+) team (-?\d+))?") {# the lobby team is -1 for a free-for-all seat, and absent from a log an older build wrote@@ -463,6 +470,19 @@ if ($pfRows.Count -gt 0) {(& $avg { param($p) $p.Escapes }),(& $avg { param($p) $p.Repaths }),(& $avg { param($p) $p.Dithers }))++ # the path queue: three requests a frame, so a late 4v4 backs it up and a unit stands waiting+ $totQueued = ($pfRows | ForEach-Object { $_.Pf.Queued } | Measure-Object -Sum).Sum+ if ($totQueued -gt 0) {+ $totLate = ($pfRows | ForEach-Object { $_.Pf.QLate } | Measure-Object -Sum).Sum+ Write-Host ("path queue per match: {0:n0} requests, mean wait {1:n1} frames, {2:n1}% waited over 1s | longest {3} frames ({4:n1}s), deepest {5}" -f+ (& $avg { param($p) $p.Queued }),+ (& $avg { param($p) $p.QWait }),+ (100.0 * $totLate / $totQueued),+ (($pfRows | ForEach-Object { $_.Pf.QLongest } | Measure-Object -Maximum).Maximum),+ ((($pfRows | ForEach-Object { $_.Pf.QLongest } | Measure-Object -Maximum).Maximum) / $LogicFps),+ (($pfRows | ForEach-Object { $_.Pf.QPeak } | Measure-Object -Maximum).Maximum))+ }}# Stability. A mean frame time is the statistic that hides a stutter, so this reports the tail: