Skip to content

Commit df4e579

Browse files
committed
perf(fps): move hero counter updates to match stealth counter pattern"
1 parent bf1c4bb commit df4e579

File tree

6 files changed

+16
-69
lines changed

6 files changed

+16
-69
lines changed

Generals/Code/GameEngine/Include/GameLogic/Module/ContainModule.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ class ContainModuleInterface
155155
virtual const Object *friend_getRider() const = 0; ///< Damn. The draw order dependency bug for riders means that our draw module needs to cheat to get around it.
156156
virtual Real getContainedItemsMass() const = 0;
157157
virtual UnsignedInt getStealthUnitsContained() const = 0;
158-
#if !RETAIL_COMPATIBLE_CRC
159158
virtual UnsignedInt getHeroUnitsContained() const = 0;
160-
#endif
161159

162160
virtual Bool calcBestGarrisonPosition( Coord3D *sourcePos, const Coord3D *targetPos ) = 0;
163161
virtual Bool attemptBestFirePointPosition( Object *source, Weapon *weapon, Object *victim ) = 0;

Generals/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ void OpenContain::addToContainList( Object *rider )
353353
{
354354
m_stealthUnitsContained++;
355355
}
356+
if( rider->isKindOf( KINDOF_HERO ) )
357+
{
358+
m_heroUnitsContained++;
359+
}
356360
}
357361

358362
//-------------------------------------------------------------------------------------------------
@@ -543,6 +547,10 @@ void OpenContain::removeFromContainViaIterator( ContainedItemsList::iterator it,
543547
}
544548
}
545549
}
550+
if( rider->isKindOf( KINDOF_HERO ) && m_heroUnitsContained > 0 )
551+
{
552+
m_heroUnitsContained--;
553+
}
546554

547555

548556
if (isEnclosingContainerFor( rider ))
@@ -630,11 +638,6 @@ void OpenContain::onContaining( Object *rider )
630638
enterSound.setObjectID(getObject()->getID());
631639
TheAudio->addAudioEvent(&enterSound);
632640
}
633-
634-
if( rider && rider->isKindOf( KINDOF_HERO ) )
635-
{
636-
m_heroUnitsContained++;
637-
}
638641
}
639642

640643
//-------------------------------------------------------------------------------------------------
@@ -650,11 +653,6 @@ void OpenContain::onRemoving( Object *rider)
650653
AudioEventRTS fallingSound = *rider->getTemplate()->getSoundFalling();
651654
fallingSound.setObjectID(rider->getID());
652655
TheAudio->addAudioEvent(&fallingSound);
653-
654-
if( rider->isKindOf( KINDOF_HERO ) && m_heroUnitsContained > 0 )
655-
{
656-
m_heroUnitsContained--;
657-
}
658656
}
659657
}
660658

Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -592,40 +592,17 @@ Object::~Object()
592592
TheScriptEngine->notifyOfObjectDestruction(this);
593593
}
594594

595-
//-------------------------------------------------------------------------------------------------
596-
//-------------------------------------------------------------------------------------------------
597-
#if RETAIL_COMPATIBLE_CRC
598-
void localIsHero( Object *obj, void* userData )
599-
{
600-
Bool *hero = (Bool*)userData;
601-
602-
if( obj && obj->isKindOf( KINDOF_HERO ) )
603-
{
604-
*hero = TRUE;
605-
}
606-
}
607-
#endif
608-
609595
//-------------------------------------------------------------------------------------------------
610596
// TheSuperHackers @performance bobtista 13/11/2025 Use cached hero count for O(1) lookup instead of O(n) iteration.
611597
Bool Object::isHero() const
612598
{
613599
ContainModuleInterface *contain = getContain();
614600
if( contain )
615601
{
616-
#if !RETAIL_COMPATIBLE_CRC
617602
if( contain->getHeroUnitsContained() > 0 )
618603
{
619604
return TRUE;
620605
}
621-
#else
622-
Bool heroInside = FALSE;
623-
contain->iterateContained( localIsHero, (void*)(&heroInside), FALSE );
624-
if( heroInside )
625-
{
626-
return TRUE;
627-
}
628-
#endif
629606
}
630607
return isKindOf( KINDOF_HERO );
631608
}

GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ContainModule.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ class ContainModuleInterface
175175
virtual const Object *friend_getRider() const = 0; ///< Damn. The draw order dependency bug for riders means that our draw module needs to cheat to get around it.
176176
virtual Real getContainedItemsMass() const = 0;
177177
virtual UnsignedInt getStealthUnitsContained() const = 0;
178-
#if !RETAIL_COMPATIBLE_CRC
179178
virtual UnsignedInt getHeroUnitsContained() const = 0;
180-
#endif
181179

182180
virtual Bool calcBestGarrisonPosition( Coord3D *sourcePos, const Coord3D *targetPos ) = 0;
183181
virtual Bool attemptBestFirePointPosition( Object *source, Weapon *weapon, Object *victim ) = 0;

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,10 @@ void OpenContain::addToContainList( Object *rider )
375375
{
376376
m_stealthUnitsContained++;
377377
}
378+
if( rider->isKindOf( KINDOF_HERO ) )
379+
{
380+
m_heroUnitsContained++;
381+
}
378382
}
379383

380384
//-------------------------------------------------------------------------------------------------
@@ -661,6 +665,10 @@ void OpenContain::removeFromContainViaIterator( ContainedItemsList::iterator it,
661665
}
662666
}
663667
}
668+
if( rider->isKindOf( KINDOF_HERO ) && m_heroUnitsContained > 0 )
669+
{
670+
m_heroUnitsContained--;
671+
}
664672

665673

666674
if (isEnclosingContainerFor( rider ))
@@ -750,11 +758,6 @@ void OpenContain::onContaining( Object *rider, Bool wasSelected )
750758
enterSound.setObjectID(getObject()->getID());
751759
TheAudio->addAudioEvent(&enterSound);
752760
}
753-
754-
if( rider && rider->isKindOf( KINDOF_HERO ) )
755-
{
756-
m_heroUnitsContained++;
757-
}
758761
}
759762

760763
//-------------------------------------------------------------------------------------------------
@@ -770,11 +773,6 @@ void OpenContain::onRemoving( Object *rider)
770773
AudioEventRTS fallingSound = *rider->getTemplate()->getSoundFalling();
771774
fallingSound.setObjectID(rider->getID());
772775
TheAudio->addAudioEvent(&fallingSound);
773-
774-
if( rider->isKindOf( KINDOF_HERO ) && m_heroUnitsContained > 0 )
775-
{
776-
m_heroUnitsContained--;
777-
}
778776
}
779777
}
780778

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,39 +2042,17 @@ Bool Object::isNonFactionStructure(void) const
20422042
return isStructure() && !isFactionStructure();
20432043
}
20442044

2045-
//-------------------------------------------------------------------------------------------------
2046-
#if RETAIL_COMPATIBLE_CRC
2047-
void localIsHero( Object *obj, void* userData )
2048-
{
2049-
Bool *hero = (Bool*)userData;
2050-
2051-
if( obj && obj->isKindOf( KINDOF_HERO ) )
2052-
{
2053-
*hero = TRUE;
2054-
}
2055-
}
2056-
#endif
2057-
20582045
//-------------------------------------------------------------------------------------------------
20592046
// TheSuperHackers @performance bobtista 13/11/2025 Use cached hero count for O(1) lookup instead of O(n) iteration.
20602047
Bool Object::isHero(void) const
20612048
{
20622049
ContainModuleInterface *contain = getContain();
20632050
if( contain )
20642051
{
2065-
#if !RETAIL_COMPATIBLE_CRC
20662052
if( contain->getHeroUnitsContained() > 0 )
20672053
{
20682054
return TRUE;
20692055
}
2070-
#else
2071-
Bool heroInside = FALSE;
2072-
contain->iterateContained( localIsHero, (void*)(&heroInside), FALSE );
2073-
if( heroInside )
2074-
{
2075-
return TRUE;
2076-
}
2077-
#endif
20782056
}
20792057
return isKindOf( KINDOF_HERO );
20802058
}

0 commit comments

Comments
 (0)