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
perf(gamelogic): walk the pathfinder zone passes down the columns
Olcay Seyganbe3f5293496b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5da1f821d..a85076f64 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -201,7 +201,7 @@ found and fixed — EA's own, not port damage.**- Crowded battles run a good deal faster. At 1080p, thirty Inferno Cannons against twenty Crusaders went from 153 to 227 frames a second, and six Brutal computer players on one map from 146 to 240. The slowest one frame in twenty got 22 to 34% shorter, and the slowest one in a hundred 16 to 29%. The game stopped re-sending lights, materials, textures and card settings that had not changed, stopped relighting the terrain when no light had moved, stopped adding up the glow of every fire particle twice, and widened low-colour textures with a lookup instead of arithmetic on each pixel. The new renderer keeps the old one's settings back until something actually reads them, re-sends only the half of each draw's settings that changed, and remembers each patch of ground's colours, its blend coordinates and its tread marks between frames. Units whose shadow cannot reach the screen are no longer drawn into the shadow map, except on maps with reflecting water. The command bar and the console replay what they drew last frame when nothing under them moved, and the HUD checks for changes without rebuilding its text. The rules side runs 4% quicker too: locking, the lists of nearby units, the sleeping-unit schedule and text strings all got cheaper. The picture matches the old build in all eight test views on both renderers, and a recorded match plays back to the same checksum.- A long match costs less late in the game. Four Hard computer players on Twilight Flame, well into the match, went from 111.6 to 136.2 frames a second, and the step that works out the battle from 5.59ms to 4.78ms. The computer left every group it had made and never filled in a list the game went through on every step until the match ended, and that list is cleared now. A unit looking for something to shoot passes over ground that holds nobody it could shoot at, sight is worked out with fewer lookups, and the smoke and fire are gone through once per step instead of once for every picture. Eight views over five maps came out the same as before.- Every moving unit's skeleton was worked out three times a picture, once for its shadow, once for the scene and once more for the outline drawn when it stands behind a building. It is worked out once now, and late in the same match the animation costs 60% less. With the rules step finding the next unit due for an update a little faster, minutes 24 to 26 went from 119.8 to 123.7 frames a second, and the match still ends on the same checksum.-- Late in a match the picture caught less often. Every ten seconds each computer player looked over its economy, its spending and the enemy army all in one step, 8 to 10ms of work landing on a single picture. Those three now run a fifth of a second apart. With four Hard computer players on Twilight Flame at minutes 24 and 25, pictures slower than 16.7ms went from 29 a minute to 22, and the slowest one in a hundred from 14.7ms to 14.0ms.+- Late in a match the picture caught less often. Every ten seconds each computer player looked over its economy, its spending and the enemy army all in one step, 8 to 10ms of work landing on a single picture. Those three now run a fifth of a second apart. With four Hard computer players on Twilight Flame at minutes 24 and 25, pictures slower than 16.7ms went from 29 a minute to 22, and the slowest one in a hundred from 14.7ms to 14.0ms. Two more hitches got smaller in the same match. The map of where units can drive is rebuilt whenever a building goes up or comes down, and that rebuild went from 9.9ms to 7.4ms, with the ones over 8ms halved (90 to 43). A Hard computer steering its Particle Cannon beam now weighs the ground around it in 0.9ms instead of 2.6ms. Neither changes a single move: the match ends on the same checksum.- Every animation runs on a clock instead of counting frames.- Tanks and trucks move the same at any frame rate. Their treads scrolled a fixed step every picture, so at 120 frames a second they ran four times too fast, and a tank turning on the spot rolled both treads forward as if it were driving. Each tread now covers exactly the ground under it. In a tight turn the two run against each other, and backing up runs them backwards. Wheels spin with the distance driven the same way. The hull's springs used to settle four times too fast as well, and every start or stop threw the chassis to its full tilt in a single picture. Now a tank squats as it pulls away and dips its nose when it brakes, easing in over a tenth of a second and settling within half a second. In a corner it leans out, a Crusader up to two and a half degrees. The Humvee, which never moved on its springs at all, rocks too. A run drawing one picture per game tick and one drawing fourteen put every tank in the same pose, to the last digit, for as long as neither skipped a tick.- A scroll that starts after the camera has stood still no longer lurches. The first frame of the move was timed from the last time the camera moved, so after a few seconds of looking at one spot it was worth three frames of scrolling at once. The clock runs while the camera is still now, and the first frame moves one frame's worth.diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cppindex 0c6b25897..f00479772 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp@@ -2714,8 +2714,10 @@ void ZoneBlock::blockCalculateZones(PathfindCell **map, PathfindLayer layers[],UnsignedInt minZone = map[bounds.lo.x][bounds.lo.y].getZone();UnsignedInt maxZone = minZone;- for( j=bounds.lo.y; j<=bounds.hi.y; j++ ) {- for( i=bounds.lo.x; i<=bounds.hi.x; i++ ) {+ // both walks go down the columns, as the cells lie in memory; a merge keeps the smaller id+ // whichever pair comes first, so the tables are the same as a walk along the rows gave+ for( i=bounds.lo.x; i<=bounds.hi.x; i++ ) {+ for( j=bounds.lo.y; j<=bounds.hi.y; j++ ) {PathfindCell *cell = &map[i][j];zoneStorageType zone = cell->getZone();if (minZone>zone) minZone=zone;@@ -2737,8 +2739,8 @@ void ZoneBlock::blockCalculateZones(PathfindCell **map, PathfindLayer layers[],m_crusherZones[i] = i+m_firstZone;}- for( j=bounds.lo.y; j<=bounds.hi.y; j++ ) {- for( i=bounds.lo.x; i<=bounds.hi.x; i++ ) {+ for( i=bounds.lo.x; i<=bounds.hi.x; i++ ) {+ for( j=bounds.lo.y; j<=bounds.hi.y; j++ ) {if (i>bounds.lo.x && map[i][j].getZone()!=map[i-1][j].getZone()) {if (waterGround(map[i][j], map[i-1][j])) {@@ -3151,23 +3153,16 @@ void PathfindZoneManager::calculateZones( PathfindCell **map, PathfindLayer laye- // Now map the zones in the map back into the collapsed zones.- j=globalBounds.lo.y;- while( j<=globalBounds.hi.y )- {- i=globalBounds.lo.x;- while( i<=globalBounds.hi.x )- {- PathfindCell &cell = map[i][j];- cell.setZone(collapsedZones[cell.getZone()]);-- //if (cell.getZone()==0)- //{- // DEBUG_CRASH(("Zone not set cell %d, %d", i, j));- //}- ++i;- }- ++j;+ // Now map the zones in the map back into the collapsed zones. Each cell is mapped on its own, so+ // the walk goes down a column, the way the cells lie in memory: across a row every cell was a+ // cache line of its own, and a building put down late in a match stalled a frame for 7-10ms on it.+ i=globalBounds.lo.x;+ while( i<=globalBounds.hi.x )+ {+ PathfindCell *column = map[i];+ for( j=globalBounds.lo.y; j<=globalBounds.hi.y; ++j )+ column[j].setZone(collapsedZones[column[j].getZone()]);+ ++i;}// for( j=globalBounds.lo.y; j<=globalBounds.hi.y; j++ ) {@@ -3364,11 +3359,14 @@ void PathfindZoneManager::calculateZones( PathfindCell **map, PathfindLayer laye// }// }UnsignedInt maxZone = m_maxZone;- j=globalBounds.lo.y;- while( j <= globalBounds.hi.y )+ /* Down each column, as the cells lie in memory, rather than across the rows. Every pair this looks+ at is the same either way, and a merge keeps the smaller id of the two sets whichever comes+ first, so the flattened tables come out the same. */+ i=globalBounds.lo.x;+ while( i <= globalBounds.hi.x ){- i=globalBounds.lo.x;- while( i <= globalBounds.hi.x )+ j=globalBounds.lo.y;+ while( j <= globalBounds.hi.y ){PathfindCell &r_thisCell = map[i][j];@@ -3450,10 +3448,10 @@ void PathfindZoneManager::calculateZones( PathfindCell **map, PathfindLayer laye// DEBUG_ASSERTCRASH(r_thisCell.getZone() != 0, ("Cleared the zone."));- ++i;+ ++j;}- ++j;+ ++i;}