Skip to content

Commit 19ec2fc

Browse files
committed
[GEN] Backports redundant call reductions from ZH
1 parent 1597a1d commit 19ec2fc

File tree

13 files changed

+54
-36
lines changed

13 files changed

+54
-36
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class JetAIUpdate : public AIUpdateInterface
103103
virtual Bool isTemporarilyPreventingAimSuccess() const;
104104
virtual Bool isDoingGroundMovement() const;
105105
virtual void notifyVictimIsDead();
106+
virtual Bool isOutOfSpecialReloadAmmo() const;
106107

107108
const Coord3D* friend_getProducerLocation() const { return &m_producerLocation; }
108109
Real friend_getOutOfAmmoDamagePerSecond() const { return getJetAIUpdateModuleData()->m_outOfAmmoDamagePerSecond; }

Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ Bool BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos,
679679
MemoryPoolObjectHolder hold(iter);
680680
for( them = iter->first(); them; them = iter->next() )
681681
{
682+
Relationship rel = builderObject ? builderObject->getRelationship( them ) : NEUTRAL;
682683

683684
// ignore any kind of class of objects that we will "remove" for building
684685
if( isRemovableForConstruction( them ) == TRUE )
@@ -695,7 +696,7 @@ Bool BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos,
695696

696697
// an immobile object may obstruct our building depending on flags.
697698
if( them->isKindOf( KINDOF_IMMOBILE ) ) {
698-
if (onlyCheckEnemies && builderObject && builderObject->getRelationship( them ) != ENEMIES ) {
699+
if (onlyCheckEnemies && builderObject && rel != ENEMIES ) {
699700
continue;
700701
}
701702
TheTerrainVisual->addFactionBib(them, true);
@@ -706,7 +707,7 @@ Bool BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos,
706707
// if this is an enemy object of the builder object (and therefore the thing
707708
// that will be constructed) we can't build here
708709
//
709-
if( builderObject && builderObject->getRelationship( them ) == ENEMIES ) {
710+
if( builderObject && rel == ENEMIES ) {
710711
TheTerrainVisual->addFactionBib(them, true);
711712
return false;
712713
}

Generals/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -1028,11 +1028,12 @@ CommandAvailability ControlBar::getCommandAvailability( const CommandButton *com
10281028
{
10291029
case GUI_COMMAND_DOZER_CONSTRUCT:
10301030
{
1031+
const ThingTemplate * whatToBuild = command->getThingTemplate();
10311032
// if the command is a dozer construct task and the object dozer is building anything
10321033
// this command is not available
1033-
if(command->getThingTemplate())
1034+
if(whatToBuild)
10341035
{
1035-
BuildableStatus bStatus = command->getThingTemplate()->getBuildable();
1036+
BuildableStatus bStatus = whatToBuild->getBuildable();
10361037
if (bStatus == BSTATUS_NO || (bStatus == BSTATUS_ONLY_BY_AI && obj->getControllingPlayer()->getPlayerType() != PLAYER_COMPUTER))
10371038
return COMMAND_HIDDEN;
10381039
}
@@ -1057,10 +1058,10 @@ CommandAvailability ControlBar::getCommandAvailability( const CommandButton *com
10571058
return COMMAND_RESTRICTED;
10581059

10591060
// return whether or not the player can build this thing
1060-
if( player->canBuild( command->getThingTemplate() ) == FALSE )
1061+
if( player->canBuild( whatToBuild ) == FALSE )
10611062
return COMMAND_RESTRICTED;
10621063

1063-
if( !player->canAffordBuild( command->getThingTemplate() ) )
1064+
if( !player->canAffordBuild( whatToBuild ) )
10641065
{
10651066
return COMMAND_RESTRICTED;//COMMAND_CANT_AFFORD;
10661067
}

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,12 @@ UpdateSleepTime SlowDeathBehavior::update()
479479
//-------------------------------------------------------------------------------------------------
480480
void SlowDeathBehavior::onDie( const DamageInfo *damageInfo )
481481
{
482+
Object *obj = getObject();
483+
482484
if (!isDieApplicable(damageInfo))
483485
return;
484486

485-
AIUpdateInterface *ai = getObject()->getAIUpdateInterface();
487+
AIUpdateInterface *ai = obj->getAIUpdateInterface();
486488
if (ai)
487489
{
488490
// has another AI already handled us. (hopefully another SlowDeathBehavior)
@@ -492,10 +494,10 @@ void SlowDeathBehavior::onDie( const DamageInfo *damageInfo )
492494
}
493495

494496
// deselect this unit for all players.
495-
TheGameLogic->deselectObject(getObject(), PLAYERMASK_ALL, TRUE);
497+
TheGameLogic->deselectObject(obj, PLAYERMASK_ALL, TRUE);
496498

497499
Int total = 0;
498-
BehaviorModule** update = getObject()->getBehaviorModules();
500+
BehaviorModule** update = obj->getBehaviorModules();
499501
for (; *update; ++update)
500502
{
501503
SlowDeathBehaviorInterface* sdu = (*update)->getSlowDeathBehaviorInterface();
@@ -510,7 +512,7 @@ void SlowDeathBehavior::onDie( const DamageInfo *damageInfo )
510512
// this returns a value from 1...total, inclusive
511513
Int roll = GameLogicRandomValue(1, total);
512514

513-
for (/* UpdateModuleInterface** */ update = getObject()->getBehaviorModules(); *update; ++update)
515+
for (/* UpdateModuleInterface** */ update = obj->getBehaviorModules(); *update; ++update)
514516
{
515517
SlowDeathBehaviorInterface* sdu = (*update)->getSlowDeathBehaviorInterface();
516518
if (sdu != NULL && sdu->isDieApplicable(damageInfo))

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,9 @@ void OpenContain::orderAllPassengersToExit( CommandSourceType commandSource )
12741274
//-------------------------------------------------------------------------------------------------
12751275
void OpenContain::processDamageToContained()
12761276
{
1277+
const OpenContainModuleData *data = getOpenContainModuleData();
1278+
Real percentDamage = data->m_damagePercentageToUnits;
1279+
12771280
const ContainedItemsList* items = getContainedItemsList();
12781281
if( items )
12791282
{
@@ -1290,7 +1293,7 @@ void OpenContain::processDamageToContained()
12901293
++it;
12911294

12921295
//Calculate the damage to be inflicted on each unit.
1293-
Real damage = object->getBodyModule()->getMaxHealth() * getOpenContainModuleData()->m_damagePercentageToUnits;
1296+
Real damage = object->getBodyModule()->getMaxHealth() * percentDamage;
12941297

12951298
DamageInfo damageInfo;
12961299
damageInfo.in.m_damageType = DAMAGE_UNRESISTABLE;
@@ -1299,7 +1302,7 @@ void OpenContain::processDamageToContained()
12991302
damageInfo.in.m_amount = damage;
13001303
object->attemptDamage( &damageInfo );
13011304

1302-
if( !object->isEffectivelyDead() && getOpenContainModuleData()->m_damagePercentageToUnits == 1.0f )
1305+
if( !object->isEffectivelyDead() && percentDamage == 1.0f )
13031306
object->kill(); // in case we are carrying flame proof troops we have been asked to kill
13041307
}
13051308
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,13 @@ CreateObjectDie::~CreateObjectDie( void )
8383
//-------------------------------------------------------------------------------------------------
8484
void CreateObjectDie::onDie( const DamageInfo * damageInfo )
8585
{
86+
const CreateObjectDieModuleData *data = getCreateObjectDieModuleData();
8687
if (!isDieApplicable(damageInfo))
8788
return;
8889

8990
Object *damageDealer = TheGameLogic->findObjectByID( damageInfo->in.m_sourceID );
9091

91-
ObjectCreationList::create(getCreateObjectDieModuleData()->m_ocl, getObject(), damageDealer);
92+
ObjectCreationList::create( data->m_ocl, getObject(), damageDealer );
9293
} // end onDie
9394

9495
// ------------------------------------------------------------------------------------------------

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ DestroyDie::~DestroyDie( void )
5252
//-------------------------------------------------------------------------------------------------
5353
void DestroyDie::onDie( const DamageInfo *damageInfo )
5454
{
55+
Object *obj = getObject();
5556
if (!isDieApplicable(damageInfo))
5657
return;
57-
TheGameLogic->destroyObject(getObject());
58+
TheGameLogic->destroyObject( obj );
5859
}
5960

6061
// ------------------------------------------------------------------------------------------------

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Int FiringTracker::getNumConsecutiveShotsAtVictim( const Object *victim ) const
8484
void FiringTracker::shotFired(const Weapon* weaponFired, ObjectID victimID)
8585
{
8686
UnsignedInt now = TheGameLogic->getFrame();
87+
Object *me = getObject();
8788

8889
if( victimID == m_victimID )
8990
{
@@ -117,15 +118,15 @@ void FiringTracker::shotFired(const Weapon* weaponFired, ObjectID victimID)
117118
Int shotsNeededOne = weaponFired->getContinuousFireOneShotsNeeded();
118119
Int shotsNeededTwo = weaponFired->getContinuousFireTwoShotsNeeded();
119120

120-
if( getObject()->testWeaponBonusCondition( WEAPONBONUSCONDITION_CONTINUOUS_FIRE_MEAN ) )
121+
if( me->testWeaponBonusCondition( WEAPONBONUSCONDITION_CONTINUOUS_FIRE_MEAN ) )
121122
{
122123
// Can either go up or down from here.
123124
if( m_consecutiveShots < shotsNeededOne )
124125
coolDown();
125126
else if( m_consecutiveShots > shotsNeededTwo )
126127
speedUp();
127128
}
128-
else if( getObject()->testWeaponBonusCondition( WEAPONBONUSCONDITION_CONTINUOUS_FIRE_FAST ) )
129+
else if( me->testWeaponBonusCondition( WEAPONBONUSCONDITION_CONTINUOUS_FIRE_FAST ) )
129130
{
130131
// Only place I can go here from here is all the way down
131132
if( m_consecutiveShots < shotsNeededTwo )
@@ -161,7 +162,7 @@ void FiringTracker::shotFired(const Weapon* weaponFired, ObjectID victimID)
161162
}
162163

163164

164-
setWakeFrame(getObject(), calcTimeToSleep());
165+
setWakeFrame(me, calcTimeToSleep());
165166
}
166167

167168
//-------------------------------------------------------------------------------------------------

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -3945,12 +3945,14 @@ void AIUpdateInterface::privateHackInternet( CommandSourceType cmdSource )
39453945
/// if we are attacking "fromID", stop that and attack "toID" instead
39463946
void AIUpdateInterface::transferAttack(ObjectID fromID, ObjectID toID)
39473947
{
3948+
Object *newTarget = TheGameLogic->findObjectByID( toID );
3949+
39483950
if (m_currentVictimID == fromID)
39493951
m_currentVictimID = toID;
39503952

39513953
Object* goalObj = getStateMachine()->getGoalObject();
39523954
if (goalObj && goalObj->getID() == fromID)
3953-
getStateMachine()->setGoalObject(TheGameLogic->findObjectByID(toID));
3955+
getStateMachine()->setGoalObject( newTarget );
39543956
}
39553957

39563958
//----------------------------------------------------------------------------------------------------------

Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,17 @@ enum JetAIStateType CPP_11(: Int)
8686
};
8787

8888
//-------------------------------------------------------------------------------------------------
89-
static Bool isOutOfSpecialReloadAmmo(Object* jet)
89+
Bool JetAIUpdate::isOutOfSpecialReloadAmmo() const
9090
{
91+
const Object* jet = getObject();
9192
// if we have at least one special reload weapon,
9293
// AND all such weapons are out of ammo,
9394
// return true.
9495
Int specials = 0;
9596
Int out = 0;
9697
for( Int i = 0; i < WEAPONSLOT_COUNT; i++ )
9798
{
98-
Weapon* weapon = jet->getWeaponInWeaponSlot((WeaponSlotType)i);
99+
const Weapon* weapon = jet->getWeaponInWeaponSlot((WeaponSlotType)i);
99100
if (weapon == NULL || weapon->getReloadType() != RETURN_TO_BASE_TO_RELOAD)
100101
continue;
101102
++specials;
@@ -300,7 +301,7 @@ class JetOrHeliCirclingDeadAirfieldState : public State
300301
// it might not have an owning airfield, and it might be trying to return
301302
// simply due to being idle, not out of ammo. so check and don't die in that
302303
// case, but just punt back out to idle.
303-
if (!isOutOfSpecialReloadAmmo(jet) && jet->getProducerID() == INVALID_ID)
304+
if (!jetAI->isOutOfSpecialReloadAmmo() && jet->getProducerID() == INVALID_ID)
304305
{
305306
return STATE_FAILURE;
306307
}
@@ -1656,7 +1657,7 @@ UpdateSleepTime JetAIUpdate::update()
16561657
}
16571658

16581659
// note that we might still have weapons with ammo, but still be forced to return to reload.
1659-
if (isOutOfSpecialReloadAmmo(jet) && getFlag(ALLOW_AIR_LOCO))
1660+
if (isOutOfSpecialReloadAmmo() && getFlag(ALLOW_AIR_LOCO))
16601661
{
16611662
m_returnToBaseFrame = 0;
16621663

@@ -1682,7 +1683,7 @@ UpdateSleepTime JetAIUpdate::update()
16821683
else if (m_returnToBaseFrame != 0 && now >= m_returnToBaseFrame && getFlag(ALLOW_AIR_LOCO))
16831684
{
16841685
m_returnToBaseFrame = 0;
1685-
DEBUG_ASSERTCRASH(isOutOfSpecialReloadAmmo(jet) == false, ("Hmm, this seems unlikely -- isOutOfSpecialReloadAmmo(jet)==false"));
1686+
DEBUG_ASSERTCRASH(isOutOfSpecialReloadAmmo() == false, ("Hmm, this seems unlikely -- isOutOfSpecialReloadAmmo()==false"));
16861687
setFlag(USE_SPECIAL_RETURN_LOCO, false);
16871688
setLastCommandSource( CMD_FROM_AI );
16881689
getStateMachine()->setState(RETURNING_FOR_LANDING);
@@ -1700,7 +1701,7 @@ UpdateSleepTime JetAIUpdate::update()
17001701
}
17011702
m_returnToBaseFrame = 0;
17021703
if (getFlag(ALLOW_INTERRUPT_AND_RESUME_OF_CUR_STATE_FOR_RELOAD) &&
1703-
isOutOfSpecialReloadAmmo(jet) && getFlag(ALLOW_AIR_LOCO))
1704+
isOutOfSpecialReloadAmmo() && getFlag(ALLOW_AIR_LOCO))
17041705
{
17051706
setFlag(USE_SPECIAL_RETURN_LOCO, true);
17061707
setFlag(HAS_PENDING_COMMAND, true);
@@ -2101,7 +2102,7 @@ void JetAIUpdate::doLandingCommand(Object *airfield, CommandSourceType cmdSource
21012102
}
21022103

21032104
getObject()->setProducer(airfield);
2104-
DEBUG_ASSERTCRASH(isOutOfSpecialReloadAmmo(getObject()) == false, ("Hmm, this seems unlikely -- isOutOfSpecialReloadAmmo(jet)==false"));
2105+
DEBUG_ASSERTCRASH(isOutOfSpecialReloadAmmo() == false, ("Hmm, this seems unlikely -- isOutOfSpecialReloadAmmo()==false"));
21052106
setFlag(USE_SPECIAL_RETURN_LOCO, false);
21062107
setFlag(ALLOW_INTERRUPT_AND_RESUME_OF_CUR_STATE_FOR_RELOAD, false);
21072108
setLastCommandSource( cmdSource );

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

+10-7
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ void AutoDepositUpdate::awardInitialCaptureBonus( Player *player )
116116
//-------------------------------------------------------------------------------------------------
117117
UpdateSleepTime AutoDepositUpdate::update( void )
118118
{
119+
const AutoDepositUpdateModuleData *modData = getAutoDepositUpdateModuleData();
119120
/// @todo srj use SLEEPY_UPDATE here
120121
if( TheGameLogic->getFrame() >= m_depositOnFrame)
121122
{
@@ -125,23 +126,25 @@ UpdateSleepTime AutoDepositUpdate::update( void )
125126
m_awardInitialCaptureBonus = TRUE;
126127
m_initialized = TRUE;
127128
}
128-
m_depositOnFrame = TheGameLogic->getFrame() + getAutoDepositUpdateModuleData()->m_depositFrame;
129+
m_depositOnFrame = TheGameLogic->getFrame() + modData->m_depositFrame;
129130

130-
if(getObject()->isNeutralControlled() || getAutoDepositUpdateModuleData()->m_depositAmount <= 0 )
131+
if(getObject()->isNeutralControlled() || modData->m_depositAmount <= 0 )
131132
return UPDATE_SLEEP_NONE;
132133

133134
// makes sure that buildings under construction do not get a bonus CCB
134135
if( getObject()->getConstructionPercent() != CONSTRUCTION_COMPLETE )
135136
return UPDATE_SLEEP_NONE;
136137

137-
getObject()->getControllingPlayer()->getMoney()->deposit( getAutoDepositUpdateModuleData()->m_depositAmount);
138-
getObject()->getControllingPlayer()->getScoreKeeper()->addMoneyEarned( getAutoDepositUpdateModuleData()->m_depositAmount);
139-
138+
int moneyAmount = modData->m_depositAmount;
139+
140+
getObject()->getControllingPlayer()->getMoney()->deposit( moneyAmount );
141+
getObject()->getControllingPlayer()->getScoreKeeper()->addMoneyEarned( modData->m_depositAmount);
142+
140143
//Display cash income floating over the blacklotus
141-
if(getAutoDepositUpdateModuleData()->m_depositAmount > 0)
144+
if(moneyAmount > 0)
142145
{
143146
UnicodeString moneyString;
144-
moneyString.format( TheGameText->fetch( "GUI:AddCash" ), getAutoDepositUpdateModuleData()->m_depositAmount );
147+
moneyString.format( TheGameText->fetch( "GUI:AddCash" ), moneyAmount );
145148
Coord3D pos;
146149
pos.set( getObject()->getPosition() );
147150
pos.z += 10.0f; //add a little z to make it show up above the unit.

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ Coord3D DockUpdate::computeApproachPosition( Int positionIndex, Object *forWhom
491491
// ------------------------------------------------------------------------------------------------
492492
void DockUpdate::loadDockPositions()
493493
{
494-
Drawable *myDrawable = getObject()->getDrawable();
494+
Object *obj = getObject();
495+
Drawable *myDrawable = obj->getDrawable();
495496

496497
if (myDrawable)
497498
{

Generals/Code/GameEngine/Source/GameNetwork/GameSpy/StagingRoomGameInfo.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -669,17 +669,17 @@ AsciiString GameSpyStagingRoom::generateGameSpyGameResultsPacket( void )
669669
Int gsPlayerID = slot->getProfileID();
670670
Bool disconnected = slot->disconnected();
671671

672-
AsciiString result = "loss", side = "USA";
672+
AsciiString result = "loss";
673673
if (disconnected)
674674
result = "discon";
675675
else if (TheNetwork->sawCRCMismatch())
676676
result = "desync";
677677
else if (TheVictoryConditions->hasAchievedVictory(p))
678678
result = "win";
679679

680-
side = p->getPlayerTemplate()->getSide();
680+
AsciiString side = p->getPlayerTemplate()->getSide();
681681
if (side == "America")
682-
side = "USA";
682+
side = "USA"; //conform to GameSpy
683683

684684
AsciiString playerStr;
685685
playerStr.format("\\player_%d\\%s\\pid_%d\\%d\\team_%d\\%d\\result_%d\\%s\\side_%d\\%s",

0 commit comments

Comments
 (0)