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(gameclient): cache per-frame interface work
Olcay Seygance9f92e0c349
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d86fff95c..8012cc291 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -457,6 +457,7 @@ found and fixed, EA's own, not port damage.**- Shadows in a big battle cost about a third of what they did. With some 560 tanks, soldiers and buildings throwing a shadow on Twilight Flame, the sun's shadows took 0.90 ms of every picture and now take 0.36, never more than half a millisecond in any second of the fight. Every copy of the same model now goes to the graphics card in one batch, so the shadows that took 916 separate draws take 121, and the card itself spends half as long on them. The shadows land on the same pixels they did.- Faster drawing in big battles on the Direct3D 11 renderer: each unit and building draw costs about a quarter less CPU, smoke, fire and tracers go out in about half the draw calls with the translucent pass a third cheaper, and shadows and aura rings laid on the ground take less than half the CPU they did. The picture is identical to the bit.- Late in big matches each frame does less busywork: the mouse-over check and the visibility sweep look only at what is on screen.+- Late in a match the interface costs less: clocks and readouts reuse their text textures instead of making new ones every frame, leader aura rings and guard shields are worked out once a game frame, and health bars, rank insignia and supply readouts over a crowded screen cost about a quarter less to draw.- 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.- 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.diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.hindex f7418478e..e2a8115a2 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h@@ -970,7 +970,19 @@ private:void drawBattlePlans( const IRegion2D* healthBarRegion ); ///< Icons rendering for active battle plan statiiBool drawsAnyUIText( void );-++ /// the modules the icon pass looks for on the object; its modules are made with it and never change+ enum IconModule+ {+ ICON_MODULE_DOCK = 1 << 0,+ ICON_MODULE_STICKY_BOMB = 1 << 1,+ ICON_MODULE_PRODUCTION = 1 << 2,+ ICON_MODULE_SPECIAL_POWER = 1 << 3,+ ICON_MODULES_KNOWN = 1 << 7+ };+ UnsignedByte m_iconModules = 0; ///< IconModule bits, found the first time the icon pass asks+ Bool hasIconModule( IconModule module );+static Bool s_staticImagesInited;static const Image* s_veterancyImage[LEVEL_COUNT];static const Image* s_fullAmmo;diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.hindex b98b824bf..670b6ebc5 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h@@ -1266,6 +1266,8 @@ protected:void handleBuildPlacements( void ); ///< handle updating of placement icons based on mouse posvoid handleRadiusCursor(); ///< handle updating of "radius cursors" that follow the mouse posvoid updateAuraRings(); ///< the ground ring of each aura every visible leader gives+ /// frozen time runs the scripts with no new logic frame, so an overlay laid once a frame is laid every pass+ Bool isTimeFrozenWithoutTick( void ) const;void incrementSelectCount( void ) { ++m_selectCount; } ///< Increase by one the running total of "selected" drawablesvoid decrementSelectCount( void ) { --m_selectCount; } ///< Decrease by one the running total of "selected" drawables@@ -1563,6 +1565,9 @@ protected:RadiusDecal decal;};AuraRing m_auraRings[AURA_RING_MAX];+ UnsignedInt m_auraRingsFrame = ~0u; ///< the logic frame the rings were last laid for+ const Player *m_auraRingsPlayer = NULL; ///< and the local player they were laid for+ Int m_auraRingsShroudIndex = -1; ///< and the player whose fog the screen showed//Floating Text DataFloatingTextList m_floatingTextList; ///< Our list of floating textdiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cppindex 65cacc7ee..8f82b5253 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp@@ -3457,6 +3457,39 @@ static Bool showsOwnerDetail( const Object *obj )} // end showsOwnerDetail+//-------------------------------------------------------------------------------------------------+static NameKeyType stickyBombUpdateKey( void )+{+ static const NameKeyType key = NAMEKEY( "StickyBombUpdate" );+ return key;+}++//-------------------------------------------------------------------------------------------------+/** Whether the object carries a module the icon pass asks for. Each ask walked every module of+ * every drawable in view on every pass, and the supply cash, the sticky bomb, the production bar+ * and the charge bar asked for one each: most of what the post draw cost late in a match. The+ * object's modules are made with it, so one walk answers for its whole life. */+//-------------------------------------------------------------------------------------------------+Bool Drawable::hasIconModule( IconModule module )+{+ if( m_iconModules == 0 )+ {+ m_iconModules = ICON_MODULES_KNOWN;+ for( BehaviorModule **m = getObject()->getBehaviorModules(); *m; ++m )+ {+ if( (*m)->getDockUpdateInterface() )+ m_iconModules |= ICON_MODULE_DOCK;+ if( (*m)->getModuleNameKey() == stickyBombUpdateKey() )+ m_iconModules |= ICON_MODULE_STICKY_BOMB;+ if( (*m)->getProductionUpdateInterface() )+ m_iconModules |= ICON_MODULE_PRODUCTION;+ if( (*m)->getSpecialPower() )+ m_iconModules |= ICON_MODULE_SPECIAL_POWER;+ }+ }+ return ( m_iconModules & module ) != 0;+}+// ------------------------------------------------------------------------------------------------@@ -4303,8 +4336,8 @@ void Drawable::drawBombed(const IRegion2D* healthBarRegion)//// Bombed?//- static NameKeyType key_StickyBombUpdate = NAMEKEY( "StickyBombUpdate" );- StickyBombUpdate *update = (StickyBombUpdate*)obj->findUpdateModule( key_StickyBombUpdate );+ StickyBombUpdate *update = hasIconModule( ICON_MODULE_STICKY_BOMB )+ ? (StickyBombUpdate*)obj->findUpdateModule( stickyBombUpdateKey() ) : NULL;if( update ){//This case is tricky. The object that is bombed doesn't know it... but the bomb itself does.@@ -4562,7 +4595,7 @@ void Drawable::drawConstructPercent( const IRegion2D *healthBarRegion )void Drawable::drawSupplyCash( const IRegion2D *healthBarRegion ){Object *obj = getObject();- DockUpdateInterface *dock = obj ? obj->getDockUpdateInterface() : NULL;+ DockUpdateInterface *dock = obj && hasIconModule( ICON_MODULE_DOCK ) ? obj->getDockUpdateInterface() : NULL;Int cash = dock ? dock->getSupplyCashValue() : -1;if( cash <= 0 )@@ -4686,7 +4719,6 @@ void Drawable::drawVeterancy( const IRegion2D *healthBarRegion )// a unit on a rank ladder wears its grade's insignia, a grade with no insignia nothing; anyone else// EA's chevron for the levelconst RankLadder *ladder = TheGlobalData->getRankLadder( obj->getTemplate() );- const Int insignia = ladder ? ladder->insigniaIndex( obj->getRankGrade(), obj->isKindOf( KINDOF_HERO ) ) : 0;VeterancyLevel level = obj->getVeterancyLevel();const Image* image = ladder ? getRankInsignia( obj ) : s_veterancyImage[level];if (!image)@@ -4731,9 +4763,11 @@ void Drawable::drawVeterancy( const IRegion2D *healthBarRegion )left = healthBarRegion->hi.x + 2;middle = ( healthBarRegion->lo.y + healthBarRegion->hi.y ) / 2;}+ // image is the grade's insignia already (getRankInsignia), so it is drawn as drawRankInsignia wouldInt width, height;rankInsigniaSize( image, 1.0f, &width, &height );- drawRankInsignia( obj->getTemplate(), insignia, left, middle - height / 2, FALSE, 1.0f, GameMakeColor( 255, 255, 255, 255 ) );+ const Int top = middle - height / 2;+ TheDisplay->drawImage( image, left, top, left + width, top + height, GameMakeColor( 255, 255, 255, 255 ) );return;}@@ -5167,7 +5201,8 @@ void Drawable::drawHealthBar(const IRegion2D* healthBarRegion)Int stackY = healthBarRegion->lo.y - 3;// own producers show a white production-progress bar above the health bar, with seconds left at its top-left- ProductionUpdateInterface *pu = showsOwnerDetail( obj ) ? obj->getProductionUpdateInterface() : NULL;+ ProductionUpdateInterface *pu = hasIconModule( ICON_MODULE_PRODUCTION ) && showsOwnerDetail( obj )+ ? obj->getProductionUpdateInterface() : NULL;const ProductionEntry *pe = pu ? pu->firstProduction() : NULL;if( pe ){@@ -5235,7 +5270,7 @@ void Drawable::drawHealthBar(const IRegion2D* healthBarRegion)// not own is skipped, and so is one that has finished charging: a full bar that never// empties is the same clutter in a different colour.//- if( showsOwnerDetail( obj ) &&+ if( hasIconModule( ICON_MODULE_SPECIAL_POWER ) && showsOwnerDetail( obj ) &&!obj->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) &&!obj->getStatusBits().test( OBJECT_STATUS_SOLD ) ){@@ -5761,8 +5796,8 @@ DrawableID Drawable::getID( void ) const//-------------------------------------------------------------------------------------------------void Drawable::friend_bindToObject( Object *obj ) ///< bind this drawable to an object ID-{- m_object = obj;+{+ m_object = obj;if (getObject()){if (TheGlobalData->m_timeOfDay == TIME_OF_DAY_NIGHT)diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cppindex 35bc8eb64..1c130ee82 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp@@ -94,6 +94,7 @@#include "GameLogic/GameLogic.h"#include "GameLogic/GhostObject.h"#include "GameLogic/Object.h"+#include "GameLogic/PartitionManager.h"#include "GameLogic/ScriptEngine.h" // For TheScriptEngine - jkmcd#ifdef _INTERNAL// for occasional debugging...@@ -872,10 +873,14 @@ void GameClient::update( void )Object *object=draw->getObject();if (object){- if (numNonLocalPlayers > 0)+ // keep the other players' view of this object current too, so their fog memory is+ // right the moment you become one of them. Fog memory is the ghost's snapshot, and+ // only an immobile object has a ghost (PartitionData::attachToObject); asking for a+ // unit kept nothing and cost an observer a status call per player for every unit on+ // the map every pass. Whoever asks about a unit later works its answer out then.+ const PartitionData *partition = object->friend_getPartitionData();+ if (numNonLocalPlayers > 0 && partition != NULL && partition->getGhostObject() != NULL){- // keep the other players' view of this object current too, so their fog- // memory is right the moment you become one of themInt *playerIndex=nonLocalPlayerIndices;for (Int p=0; p<numNonLocalPlayers; p++, playerIndex++)object->getShroudedStatus(*playerIndex);diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex d24bfddde..8fd296a74 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -134,7 +134,7 @@#include "GameLogic/Module/MobMemberSlavedUpdate.h"//ML#include "GameLogic/Module/SpawnBehavior.h"-#include "Common/UnitTimings.h" //Contains the DO_UNIT_TIMINGS define jba.+#include "Common/UnitTimings.h" //Contains the DO_UNIT_TIMINGS define jba.#ifdef _INTERNAL// for occasional debugging...@@ -1503,6 +1503,17 @@ void InGameUI::setRadiusCursor(RadiusCursorType cursorType, const SpecialPowerTehandleRadiusCursor();}+//-------------------------------------------------------------------------------------------------+/** GameLogic::update's freeze, where the scripts run and the frame stays: a camera move freezes+ * nothing in a multiplayer session. */+//-------------------------------------------------------------------------------------------------+Bool InGameUI::isTimeFrozenWithoutTick( void ) const+{+ return ( !TheGameEngine->isMultiplayerSession() && TheTacticalView->isTimeFrozen()+ && !TheTacticalView->isCameraMovementFinished() )+ || TheScriptEngine->isTimeFrozenDebug() || TheScriptEngine->isTimeFrozenScript();+}+//-------------------------------------------------------------------------------------------------/** A leader's auras on the ground: one ring for each kind it gives, under every leader on the map,* selected or not, friend or enemy, while the player at this machine can see it: out of the fog and@@ -1513,24 +1524,50 @@ void InGameUI::setRadiusCursor(RadiusCursorType cursorType, const SpecialPowerTe//-------------------------------------------------------------------------------------------------void InGameUI::updateAuraRings(){+ // Who leads, where and through which fog moves with a tick, so the walk over every drawable runs+ // once a logic frame and again when the fog on the screen changes hands; on every pass it was 1.8%+ // of the main thread late in a match. Frozen time runs scripts with no new frame, and one may move+ // or hide a leader, so then it walks every pass. A ring's opacity follows the icon switch and+ // -cinema, which change between ticks, so every live ring is updated every pass.+ Player *local = ThePlayerList->getLocalPlayer();+ const UnsignedInt frame = TheGameLogic->getFrame();+ const Int shroudIndex = local != NULL ? TheObserverCamera.getShroudPlayerIndex() : -1;+ if( frame == m_auraRingsFrame && local == m_auraRingsPlayer && shroudIndex == m_auraRingsShroudIndex+ && !isTimeFrozenWithoutTick() )+ {+ for( Int slot = 0; slot < AURA_RING_MAX; ++slot )+ if( m_auraRings[ slot ].id != INVALID_ID )+ m_auraRings[ slot ].decal.update();+ return;+ }+ m_auraRingsFrame = frame;+ m_auraRingsPlayer = local;+ m_auraRingsShroudIndex = shroudIndex;+struct Wanted { ObjectID id; Int kind; Real radius; Coord3D pos; };Wanted wanted[ AURA_RING_MAX ];Int wantedCount = 0;- Player *local = ThePlayerList->getLocalPlayer();for( Drawable *draw = TheGameClient->firstDrawable(); draw != NULL && local != NULL; draw = draw->getNextDrawable() ){const Object *obj = draw->getObject();const RankLadder *ladder = obj ? TheGlobalData->getRankLadder( obj->getTemplate() ) : NULL;- if( ladder == NULL || obj->isEffectivelyDead() || obj->getContainedBy()+ if( ladder == NULL )+ continue;+ // the grade first: few units lead, and the fog asks the partition+ const Int grade = obj->getRankGrade();+ Int kinds[ RANK_AURA_COUNT ];+ Int kindCount = 0;+ for( Int kind = 0; kind < RANK_AURA_COUNT; ++kind )+ if( ladder->aura( grade, (RankAura)kind ) > 0.0f && TheGlobalData->m_rankAuraRing[ kind ].valid() )+ kinds[ kindCount++ ] = kind;+ if( kindCount == 0 || obj->isEffectivelyDead() || obj->getContainedBy()|| draw->isDrawableEffectivelyHidden() || draw->getFullyObscuredByShroud()|| obj->getShroudedStatus( local->getPlayerIndex() ) != OBJECTSHROUD_CLEAR )continue;- const Int grade = obj->getRankGrade();- for( Int kind = 0; kind < RANK_AURA_COUNT && wantedCount < AURA_RING_MAX; ++kind )+ for( Int k = 0; k < kindCount && wantedCount < AURA_RING_MAX; ++k ){- if( ladder->aura( grade, (RankAura)kind ) <= 0.0f || !TheGlobalData->m_rankAuraRing[ kind ].valid() )- continue;+ const Int kind = kinds[ k ];wanted[ wantedCount ].id = obj->getID();wanted[ wantedCount ].kind = kind;wanted[ wantedCount ].radius = ladder->auraRadius( grade, (RankAura)kind );@@ -2802,6 +2839,8 @@ void InGameUI::reset( void )m_auraRings[ i ].id = INVALID_ID;m_auraRings[ i ].decal.clear();}+ m_auraRingsFrame = ~0u;+ m_auraRingsPlayer = NULL;m_isQuitMenuVisible = FALSE;TheObserverCamera.reset();diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.hindex 460260644..0e6d1c470 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h@@ -85,6 +85,9 @@ protected:virtual void drawFormationLine( void ); ///< the line an armed left drag is spreading the selection alongvirtual void drawAttackCircle( void ); ///< the circle a left drag is sweeping targets out ofvoid drawGuardMarkers( void ); ///< the shield over each of the local player's guarding units+ std::vector< Coord3D > m_guardMarkerTops; ///< the guarding units' tops, taken once a logic frame+ UnsignedInt m_guardMarkersFrame = ~0u; ///< the logic frame they were taken on+ const Player *m_guardMarkersPlayer = NULL; ///< and the local player they were taken forRenderObjClass *m_buildingPlacementAnchor;RenderObjClass *m_buildingPlacementArrow;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cppindex b833f6a73..cfa43b411 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp@@ -73,23 +73,40 @@// Every sentence build by the text it was built for, for the report at shutdown. A build makes a// new texture, and on the Direct3D 11 frame a new copy of that texture too, so a string rebuilt-// every frame is a texture made and thrown away every frame.+// every frame is a texture made and thrown away every frame. A text that is new every time, the+// corner readout's frame number or a clock, adds a string a build, so at the limit the strings+// built least are dropped: the report wants the ones built over and over.static std::map<std::string, Int> theSentenceBuilds;+static Int theSentenceBuildTotal = 0;static const size_t SENTENCE_BUILD_REPORT_LINES = 12;+static const size_t SENTENCE_BUILD_STRING_LIMIT = 1024;++static void countSentenceBuild( const AsciiString &text )+{+ ++theSentenceBuildTotal;+ ++theSentenceBuilds[ text.str() ];+ for( Int fewest = 1; theSentenceBuilds.size() >= SENTENCE_BUILD_STRING_LIMIT; ++fewest )+ {+ std::map<std::string, Int>::iterator entry = theSentenceBuilds.begin();+ while( entry != theSentenceBuilds.end() )+ {+ if( entry->second <= fewest )+ theSentenceBuilds.erase( entry++ );+ else+ ++entry;+ }+ }+}void W3DDisplayString_logSentenceBuilds( void ){std::vector< std::pair<Int, std::string> > ranked;- Int total = 0;for( std::map<std::string, Int>::const_iterator entry = theSentenceBuilds.begin();entry != theSentenceBuilds.end(); ++entry )- {ranked.push_back( std::make_pair( entry->second, entry->first ) );- total += entry->second;- }std::sort( ranked.rbegin(), ranked.rend() );- DEBUG_LOG(( "SENTENCE BUILDS: %d builds of %d distinct strings\n", total, (Int)ranked.size() ));+ DEBUG_LOG(( "SENTENCE BUILDS: %d builds, %d strings kept\n", theSentenceBuildTotal, (Int)ranked.size() ));for( size_t index = 0; index < ranked.size() && index < SENTENCE_BUILD_REPORT_LINES; ++index )DEBUG_LOG(( "SENTENCE BUILDS: %d '%s'\n", ranked[ index ].first, ranked[ index ].second.c_str() ));}@@ -159,8 +176,9 @@ void W3DDisplayString::notifyTextChanged( void )//m_textChanged = TRUE;- // reset data for our text renderer- m_textRenderer.Reset();+ // reset data for our text renderer; its textures are filled again by the next build, which for a+ // clock or the corner readout's frame number is every second or every logic frame+ m_textRenderer.Reset_Keeping_Textures();} // end notifyTextChanged@@ -216,7 +234,7 @@ void W3DDisplayString::draw( Int x, Int y, Color color, Color dropColor, Int xDrAsciiString builtText;builtText.translate( getText() );- ++theSentenceBuilds[ builtText.str() ];+ countSentenceBuild( builtText );} // end ifdiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cppindex d741a64d6..b38fa9c68 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp@@ -78,7 +78,7 @@#include "WW3D2/vertmaterial.h"#include "WW3D2/shader.h"-#include "Common/UnitTimings.h" //Contains the DO_UNIT_TIMINGS define jba.+#include "Common/UnitTimings.h" //Contains the DO_UNIT_TIMINGS define jba.#ifdef _INTERNAL// for occasional debugging...@@ -412,6 +412,8 @@ void W3DInGameUI::reset( void )m_dragBoxDraw.clear();m_postDrawCalls.clear();m_hudOverlayDraw.clear();+ m_guardMarkersFrame = ~0u;+ m_guardMarkerTops.clear();} // end reset@@ -1340,20 +1342,37 @@ void W3DInGameUI::drawGuardMarkers( void )const Int lift = height / 2; // clear of the health bar's line over the model's topconst Real rim = max( 1.0f, height / 10.0f );- // ponytail: walks every object each frame; share one walk with another per-object overlay if it shows- for( Object *obj = TheGameLogic->getFirstObject(); obj; obj = obj->getNextObject() )+ // Who stands guard, and where, moves only with a tick, so the walk over every object runs once a+ // logic frame; it ran on every pass and was most of what this method cost. Only the camera is+ // this pass's, except under frozen time, whose scripts move units with no new frame.+ // ponytail: walks every object once a logic frame; share one walk with another per-object overlay if it shows+ const UnsignedInt frame = TheGameLogic->getFrame();+ const Player *local = ThePlayerList->getLocalPlayer();+ if( frame != m_guardMarkersFrame || local != m_guardMarkersPlayer || isTimeFrozenWithoutTick() ){- if( !obj->isLocallyControlled() || obj->isEffectivelyDead() || obj->getContainedBy() )- continue;- const AIUpdateInterface *ai = obj->getAI();- if( ai == NULL || ai->getCurrentStateID() != AI_GUARD )- continue;- const Drawable *draw = obj->getDrawable();- if( draw == NULL || draw->isDrawableEffectivelyHidden() )- continue;+ m_guardMarkersFrame = frame;+ m_guardMarkersPlayer = local;+ m_guardMarkerTops.clear();+ for( Object *obj = TheGameLogic->getFirstObject(); obj; obj = obj->getNextObject() )+ {+ if( !obj->isLocallyControlled() || obj->isEffectivelyDead() || obj->getContainedBy() )+ continue;+ const AIUpdateInterface *ai = obj->getAI();+ if( ai == NULL || ai->getCurrentStateID() != AI_GUARD )+ continue;+ const Drawable *draw = obj->getDrawable();+ if( draw == NULL || draw->isDrawableEffectivelyHidden() )+ continue;- Coord3D top = *obj->getPosition();- top.z += obj->getGeometryInfo().getMaxHeightAbovePosition();+ Coord3D top = *obj->getPosition();+ top.z += obj->getGeometryInfo().getMaxHeightAbovePosition();+ m_guardMarkerTops.push_back( top );+ }+ }++ for( size_t i = 0; i < m_guardMarkerTops.size(); ++i )+ {+ Coord3D top = m_guardMarkerTops[ i ];ICoord2D spot;if( !TheTacticalView->worldToScreen( &top, &spot ) )continue;