Skip to content

Commit bcbf169

Browse files
committed
build: wrap isHero optimization behind RETAIL_COMPATIBLE_CRC flag
1 parent 9e9ecdc commit bcbf169

File tree

6 files changed

+68
-0
lines changed

6 files changed

+68
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,11 @@ class OpenContain : public UpdateModule,
164164
virtual const Object *friend_getRider() const{return NULL;} ///< Damn. The draw order dependency bug for riders means that our draw module needs to cheat to get around it.
165165
virtual Real getContainedItemsMass() const;
166166
virtual UnsignedInt getStealthUnitsContained() const { return m_stealthUnitsContained; }
167+
#if !RETAIL_COMPATIBLE_CRC
167168
virtual UnsignedInt getHeroUnitsContained() const { return m_heroUnitsContained; }
169+
#else
170+
virtual UnsignedInt getHeroUnitsContained() const { return 0; }
171+
#endif
168172

169173
virtual PlayerMaskType getPlayerWhoEntered(void) const { return m_playerEnteredMask; }
170174

@@ -239,7 +243,9 @@ class OpenContain : public UpdateModule,
239243

240244
ObjectEnterExitMap m_objectEnterExitInfo;
241245
UnsignedInt m_stealthUnitsContained; ///< number of stealth units that can't be seen by enemy players.
246+
#if !RETAIL_COMPATIBLE_CRC
242247
UnsignedInt m_heroUnitsContained; ///< cached hero count
248+
#endif
243249
Int m_whichExitPath; ///< Cycles from 1 to n and is used only in modules whose data has numberOfExitPaths > 1.
244250
UnsignedInt m_doorCloseCountdown; ///< When should I shut my door.
245251

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ OpenContain::OpenContain( Thing *thing, const ModuleData* moduleData ) : UpdateM
125125
m_lastLoadSoundFrame = 0;
126126
m_containListSize = 0;
127127
m_stealthUnitsContained = 0;
128+
#if !RETAIL_COMPATIBLE_CRC
128129
m_heroUnitsContained = 0;
130+
#endif
129131
m_doorCloseCountdown = 0;
130132

131133
//Added By Sadullah Nader
@@ -635,10 +637,12 @@ void OpenContain::onContaining( Object *rider )
635637
}
636638

637639
// TheSuperHackers @performance bobtista 13/11/2025 Cache hero count to avoid O(n) iteration in Object::isHero().
640+
#if !RETAIL_COMPATIBLE_CRC
638641
if( rider && rider->isKindOf( KINDOF_HERO ) )
639642
{
640643
m_heroUnitsContained++;
641644
}
645+
#endif
642646
}
643647

644648
//-------------------------------------------------------------------------------------------------
@@ -655,10 +659,12 @@ void OpenContain::onRemoving( Object *rider)
655659
fallingSound.setObjectID(rider->getID());
656660
TheAudio->addAudioEvent(&fallingSound);
657661

662+
#if !RETAIL_COMPATIBLE_CRC
658663
if( rider->isKindOf( KINDOF_HERO ) && m_heroUnitsContained > 0 )
659664
{
660665
m_heroUnitsContained--;
661666
}
667+
#endif
662668
}
663669
}
664670

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,17 +595,39 @@ Object::~Object()
595595
}
596596

597597
//-------------------------------------------------------------------------------------------------
598+
//-------------------------------------------------------------------------------------------------
599+
#if RETAIL_COMPATIBLE_CRC
600+
void localIsHero( Object *obj, void* userData )
601+
{
602+
Bool *hero = (Bool*)userData;
603+
604+
if( obj && obj->isKindOf( KINDOF_HERO ) )
605+
{
606+
*hero = TRUE;
607+
}
608+
}
609+
#endif
610+
598611
//-------------------------------------------------------------------------------------------------
599612
// TheSuperHackers @performance bobtista 13/11/2025 Use cached hero count for O(1) lookup instead of O(n) iteration.
600613
Bool Object::isHero() const
601614
{
602615
ContainModuleInterface *contain = getContain();
603616
if( contain )
604617
{
618+
#if !RETAIL_COMPATIBLE_CRC
605619
if( contain->getHeroUnitsContained() > 0 )
606620
{
607621
return TRUE;
608622
}
623+
#else
624+
Bool heroInside = FALSE;
625+
contain->iterateContained( localIsHero, (void*)(&heroInside), FALSE );
626+
if( heroInside )
627+
{
628+
return TRUE;
629+
}
630+
#endif
609631
}
610632
return isKindOf( KINDOF_HERO );
611633
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ class OpenContain : public UpdateModule,
174174
virtual const Object *friend_getRider() const{return NULL;} ///< Damn. The draw order dependency bug for riders means that our draw module needs to cheat to get around it.
175175
virtual Real getContainedItemsMass() const;
176176
virtual UnsignedInt getStealthUnitsContained() const { return m_stealthUnitsContained; }
177+
#if !RETAIL_COMPATIBLE_CRC
177178
virtual UnsignedInt getHeroUnitsContained() const { return m_heroUnitsContained; }
179+
#else
180+
virtual UnsignedInt getHeroUnitsContained() const { return 0; }
181+
#endif
178182

179183
virtual PlayerMaskType getPlayerWhoEntered(void) const { return m_playerEnteredMask; }
180184

@@ -260,7 +264,9 @@ class OpenContain : public UpdateModule,
260264

261265
ObjectEnterExitMap m_objectEnterExitInfo;
262266
UnsignedInt m_stealthUnitsContained; ///< number of stealth units that can't be seen by enemy players.
267+
#if !RETAIL_COMPATIBLE_CRC
263268
UnsignedInt m_heroUnitsContained; ///< cached hero count
269+
#endif
264270
Int m_whichExitPath; ///< Cycles from 1 to n and is used only in modules whose data has numberOfExitPaths > 1.
265271
UnsignedInt m_doorCloseCountdown; ///< When should I shut my door.
266272

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ OpenContain::OpenContain( Thing *thing, const ModuleData* moduleData ) : UpdateM
129129
m_lastLoadSoundFrame = 0;
130130
m_containListSize = 0;
131131
m_stealthUnitsContained = 0;
132+
#if !RETAIL_COMPATIBLE_CRC
132133
m_heroUnitsContained = 0;
134+
#endif
133135
m_doorCloseCountdown = 0;
134136

135137
//Added By Sadullah Nader
@@ -755,10 +757,12 @@ void OpenContain::onContaining( Object *rider, Bool wasSelected )
755757
}
756758

757759
// TheSuperHackers @performance bobtista 13/11/2025 Cache hero count to avoid O(n) iteration in Object::isHero().
760+
#if !RETAIL_COMPATIBLE_CRC
758761
if( rider && rider->isKindOf( KINDOF_HERO ) )
759762
{
760763
m_heroUnitsContained++;
761764
}
765+
#endif
762766
}
763767

764768
//-------------------------------------------------------------------------------------------------
@@ -775,10 +779,12 @@ void OpenContain::onRemoving( Object *rider)
775779
fallingSound.setObjectID(rider->getID());
776780
TheAudio->addAudioEvent(&fallingSound);
777781

782+
#if !RETAIL_COMPATIBLE_CRC
778783
if( rider->isKindOf( KINDOF_HERO ) && m_heroUnitsContained > 0 )
779784
{
780785
m_heroUnitsContained--;
781786
}
787+
#endif
782788
}
783789
}
784790

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

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

2031+
//-------------------------------------------------------------------------------------------------
2032+
#if RETAIL_COMPATIBLE_CRC
2033+
void localIsHero( Object *obj, void* userData )
2034+
{
2035+
Bool *hero = (Bool*)userData;
2036+
2037+
if( obj && obj->isKindOf( KINDOF_HERO ) )
2038+
{
2039+
*hero = TRUE;
2040+
}
2041+
}
2042+
#endif
2043+
20312044
//-------------------------------------------------------------------------------------------------
20322045
// TheSuperHackers @performance bobtista 13/11/2025 Use cached hero count for O(1) lookup instead of O(n) iteration.
20332046
Bool Object::isHero(void) const
20342047
{
20352048
ContainModuleInterface *contain = getContain();
20362049
if( contain )
20372050
{
2051+
#if !RETAIL_COMPATIBLE_CRC
20382052
if( contain->getHeroUnitsContained() > 0 )
20392053
{
20402054
return TRUE;
20412055
}
2056+
#else
2057+
Bool heroInside = FALSE;
2058+
contain->iterateContained( localIsHero, (void*)(&heroInside), FALSE );
2059+
if( heroInside )
2060+
{
2061+
return TRUE;
2062+
}
2063+
#endif
20422064
}
20432065
return isKindOf( KINDOF_HERO );
20442066
}

0 commit comments

Comments
 (0)