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): script searches skip a type nobody on the map holds
Olcay Seyganfe050ef17c14
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5e10c6e4b..1ec6a69cd 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -484,6 +484,7 @@ found and fixed, EA's own, not port damage.**- 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.- Counting a player's units costs less. The computer's scripts and the build menu keep asking how many of some unit or building a player owns, and every answer went through every unit on every one of that player's teams. Each player now keeps its units grouped by type, so an answer looks only at the types it was asked about. Over an hour of eight Hard computer players on Twilight Flame, the step that works out the battle went from 6.15ms to 6.01ms on average and from 13.75ms to 13.25ms at the slowest one in a hundred, and pictures slower than 16.7ms fell from 1,279 to 1,072. The match ends on the same checksum.- Every armed unit stopped asking its model to show its loaded missiles. Each one asked on every step of the battle, and only the Tomahawk, the Scud Launcher, the Scorpion and the Scud Storm carry missiles you can see on the model; for the hundreds of others the answer was nothing, and it still had to be queued and read back. Those four keep asking, so their racks still empty and refill as they fire and reload. Over an hour of eight Hard computer players on Twilight Flame the battle step went from 7.15ms to 6.81ms on average, pictures slower than 16.7ms fell from 7,065 to 5,826, and minute 50 ran at 8.6ms a picture instead of 10.7. The match ends on the same checksum.+- Computer players' scripts stopped searching the whole map for units that are not on it. The Stealth General's GPS Scrambler script looks for its own Quad Cannon on every step, and with none left the search still walked the map square by square to be sure; it now first asks whether anyone holds one, and a search that reaches past the edge of the map stops at the last square that is on it. Over 114,000 steps of eight Hard computer players on Twilight Flame the battle step went from 5.63ms to 5.37ms on average and from 14.5ms to 14.0ms at the slowest one in a thousand, and the match took 733 seconds instead of 763. The match ends on the same checksum.- The game no longer freezes for seconds when your hard drive is busy. It writes a log of the match as it plays, and once a second the battle itself stopped to push that log to disk. On a drive already busy with something else, Windows can hold such a write back for seconds, and the whole game stood still behind it: a 2v2 against the computer froze for 7.8 seconds on a single step. The log is written on the side now and the battle never waits for it. Three matches played while another program kept the drive busy froze for 6.2 seconds in two of them before; with the change, the slowest step in all three took 48ms.- The game's log no longer grows without limit. Players sent us logs of half a gigabyte up to 19 GB, enough to fill a disk, and the launcher could not open them to report a crash. Most of it was the network code writing a line for every order and every frame, which only a developer's build writes now: a 100-second two-player network match went from 10.9 MB of log to 175 KB, and a skirmish from 600 KB to 166 KB. Past 64 MB the log keeps its first 8 MB, which say how the game started and on what machine, and its most recent lines, so it stays under 64 MB however long you play.- The replay no longer stops the battle either. Every order given in a match went to the replay file on disk the moment it was recorded, and on a busy hard drive Windows held each of those writes back. Two long matches against the computer, played while another program kept the drive busy, stalled 115 times for over a tenth of a second, the worst for 0.63 seconds. The replay is written on the side now, about once a second. The same two matches never stalled past 35ms and finished 40% sooner. The file itself has not changed: a replay recorded by the old game and the new one from the same match is identical byte for byte, the clock times aside. A game that crashes still saves its replay up to the crash; one killed from Task Manager can lose its last second.diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Player.h b/GeneralsMD/Code/GameEngine/Include/Common/Player.hindex 8c0954d14..e8f506ae0 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/Player.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/Player.h@@ -668,6 +668,9 @@ public:void addTemplateCountMember(Object *obj);void removeTemplateCountMember(Object *obj);+ /// whether any member of our teams, dead or alive, has a template equivalent to tmpl+ Bool hasTemplateMember(const ThingTemplate *tmpl) const;+/**simply returns the number of buildings owned by this player*/diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cppindex cf8d7e8bd..3e41fa4c0 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp@@ -2014,6 +2014,17 @@ void Player::removeTemplateCountMember(Object *obj)DEBUG_CRASH(("Player %d leaves object %d '%s' it never counted\n", getPlayerIndex(), obj->getID(), tmpl->getName().str()));}+//=============================================================================+Bool Player::hasTemplateMember(const ThingTemplate *tmpl) const+{+ for (std::vector<TemplateCountMembers>::const_iterator it = m_templateCountMembers.begin(); it != m_templateCountMembers.end(); ++it)+ {+ if (!it->m_objects.empty() && it->m_template->isEquivalentTo(tmpl))+ return true;+ }+ return false;+}+//=============================================================================void Player::countObjectsByThingTemplate(Int numTmplates, const ThingTemplate* const * things, Bool ignoreDead, Int *counts, Bool ignoreUnderConstruction ) const{diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cppindex a3aac3b03..2f2568016 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp@@ -3547,6 +3547,17 @@ Object *PartitionManager::getClosestObjects(maxRadiusLimit = -1; // nothing left for the ring walk to find}+ /* Every offset past the on-map cell farthest from the centre lands off the map, where getCellAt+ returns NULL, yet a REALLY_FAR search that found nothing stepped through all of them. A ring's+ radius never shrinks as the offset grows on either axis, so the farthest corner cell bounds+ every on-map one. Its radius is at least its longer side less one, so a nearer limit, which is+ every small search, skips the lookup. */+ ICoord2D farthestOnMap;+ farthestOnMap.x = maxInt(cellCenterX, m_cellCountX - 1 - cellCenterX);+ farthestOnMap.y = maxInt(cellCenterY, m_cellCountY - 1 - cellCenterY);+ if (maxRadiusLimit >= maxInt(farthestOnMap.x, farthestOnMap.y))+ maxRadiusLimit = minInt(maxRadiusLimit, calcMinRadius(farthestOnMap));+/*m_radiusVec[curRadius] contains a list of the cells (foo) that couldcontain objects that are <= (curRadius * cellSize) distance away from cell (0,0).diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cppindex 945a44729..8bf0f6da5 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp@@ -5841,6 +5841,29 @@ void ScriptActions::doTeamUseCommandButtonOnNearestBuildingClass( const AsciiStrtheGroup->groupDoCommandButtonAtObject(commandButton, obj, CMD_FROM_SCRIPT);}+//-------------------------------------------------------------------------------------------------+/** Whether anyone PartitionFilterPlayerAffiliation(me, ALLOW_ENEMIES | ALLOW_NEUTRAL, true) lets+ through holds a member equivalent to type: an enemy, a neutral, or me, whose own objects pass that+ filter as well. Every Object in the partition sits on some player's team, so with no such holder+ a REALLY_FAR search for the type finds nothing, after walking the whole map to be sure. */+//-------------------------------------------------------------------------------------------------+static Bool enemyNeutralOrSelfHolds( const Player *me, const ThingTemplate *type )+{+ // with no team-keyed override a relationship to a team depends only on the team's player, and+ // that player's default team answers for all of its teams (Team::getEnemyPlayerMask)+ const Bool perTeam = me->hasTeamRelationships();+ for (Int i = 0; i < ThePlayerList->getPlayerCount(); ++i)+ {+ const Player *holder = ThePlayerList->getNthPlayer(i);+ if (!holder->hasTemplateMember(type))+ continue;+ if (perTeam || holder == me || holder->getDefaultTeam()->getControllingPlayer() != holder+ || me->getRelationship(holder->getDefaultTeam()) != ALLIES)+ return true;+ }+ return false;+}+//-------------------------------------------------------------------------------------------------/** doTeamUseCommandButtonOnNearestObjectType *///-------------------------------------------------------------------------------------------------@@ -5874,8 +5897,13 @@ void ScriptActions::doTeamUseCommandButtonOnNearestObjectType( const AsciiString//First look for a specific object type (object lists will fail)const ThingTemplate *thingTemplate = TheThingFactory->findTemplate( objectType, FALSE );- if( thingTemplate )+ if( thingTemplate ){+ // The Stealth General's GPS Scrambler script asks this for its own Quad Cannon every frame, and+ // with none on the map the search walked every ring offset of it to come back empty+ if (!enemyNeutralOrSelfHolds(team->getControllingPlayer(), thingTemplate))+ return;+PartitionFilterPlayerAffiliation f1(team->getControllingPlayer(), ALLOW_ENEMIES | ALLOW_NEUTRAL, true);PartitionFilterThing f2(thingTemplate, true);PartitionFilterValidCommandButtonTarget f3(srcObj, commandButton, true, CMD_FROM_SCRIPT);@@ -5914,6 +5942,10 @@ void ScriptActions::doTeamUseCommandButtonOnNearestObjectType( const AsciiStringPartitionFilterThing f2( thisType, true );PartitionFilter *filters[] = { &f1, &f2, &f3, &f4, 0 };+ // the search walks every ring offset of the map before it gives up on a type+ if (!enemyNeutralOrSelfHolds(team->getControllingPlayer(), thisType))+ continue;+Object *obj = ThePartitionManager->getClosestObject(&pos, REALLY_FAR, FROM_CENTER_2D, filters, &dist );if( obj ){