for (iI = 0; iI < MAX_PLAYERS; iI++)
{
if (GET_PLAYER((PlayerTypes)iI).isAlive())
{
if ((GET_PLAYER((PlayerTypes)iI).getTeam() == getID()) || (GET_PLAYER((PlayerTypes)iI).getTeam() == eTeam))
{
GET_PLAYER((PlayerTypes)iI).updateWarWearinessPercentAnger();
}
}
}
for (iI = 0; iI < MAX_PLAYERS; iI++)
{
if (GET_PLAYER((PlayerTypes)iI).isAlive())
{
if ((GET_PLAYER((PlayerTypes)iI).getTeam() == getID()) || (GET_PLAYER((PlayerTypes)iI).getTeam() == eTeam))
{
GET_PLAYER((PlayerTypes)iI).updatePlotGroups();
}
}
}
for (iI = 0; iI < MAX_PLAYERS; iI++)
{
if (GET_PLAYER((PlayerTypes)iI).isAlive())
{
if ((GET_PLAYER((PlayerTypes)iI).getTeam() == getID()) || (GET_PLAYER((PlayerTypes)iI).getTeam() == eTeam))
{
GET_PLAYER((PlayerTypes)iI).updateTradeRoutes();
}
}
}
for (iI = 0; iI < MAX_PLAYERS; iI++)
{
if (GET_PLAYER((PlayerTypes)iI).isAlive())
{
if ((GET_PLAYER((PlayerTypes)iI).getTeam() == getID()) || (GET_PLAYER((PlayerTypes)iI).getTeam() == eTeam))
{
GET_PLAYER((PlayerTypes)iI).updateWarWearinessPercentAnger();
GET_PLAYER((PlayerTypes)iI).updatePlotGroups();
GET_PLAYER((PlayerTypes)iI).updateTradeRoutes();
}
}
}
for (iI = 0; iI < MAX_PLAYERS; iI++)
{
if (GET_PLAYER((PlayerTypes)iI).isAlive())
{
if (GET_PLAYER((PlayerTypes)iI).getTeam() == getID())
{
for (std::vector<PlayerTypes>::const_iterator iter = m_aePlayerMembers.begin(); iter != m_aePlayerMembers.end(); ++iter)
{
You'd have to check what each function does. If they did 3 separate loops, you must assume that each loop depends on the results of the previous one. War Weariness doesn't completely make sense to have influence on your plotgroups, unless during the war weariness update you can have a city go into revolt. But PlotGroups would influence available traderoutes, so they must ALL be updated before you update ANY traderoutes.
for (std::vector<PlayerTypes>::const_iterator iter = m_aePlayerMembers.begin(); iter != m_aePlayerMembers.end(); ++iter)
{
GET_PLAYER(*iter).updateWarWearinessPercentAnger();
}
for (std::vector<PlayerTypes>::const_iterator iter = m_aePlayerMembers.begin(); iter != m_aePlayerMembers.end(); ++iter)
{
GET_PLAYER(*iter).updateWarWearinessPercentAnger();
}
for (std::vector<PlayerTypes>::const_iterator iter = m_aePlayerMembers.begin(); iter != m_aePlayerMembers.end(); ++iter)
{
GET_PLAYER(*iter).updateWarWearinessPercentAnger();
}
Keep in mind that the code that does the looping itself (iI++, iI < MAX_PLAYERS, getTeam(), getID(), etc) probably takes 0.00001% of the time that those other functions being called take. Shaving that down to 0.000003% is not saving you all that much time (microseconds at the most).
This is why profiling is the most important first step to performance tuning. You want to measure the parts that take the largest amounts of time and focus your efforts there.
And as xienwolf points out, when you do you have to analyze your changes to ensure you aren't changing the logic of the code.
As for iterating over the members iterator versus looping over all players and checking for which are members, yes that will be faster and should be functionally identical. I suspect that the function that checks if a player is a member of a team iterates over the members array looking for a matching ID itself. Again, however, you're saving a tiny amount of time. You won't notice it unless it's run thousands of times per turn.
Doesn't the beginning of this thread describe how to turn it on?
[882186.438] DBG: Total Frame MS: 698.0 FPS: 001 Min:143 Max:000 Avg:001 SampleFilter:1.010000
Time : Ave : Min% : Max% : Num : Profile Name
-----------------------------------------------------
697.0 : 000.0 : 000.0 : 000.0 : 001 : CvGame::doTurn()
003.0 : 000.0 : 000.0 : 000.0 : 006 : CvTeam::doTurn()
009.0 : 000.0 : 000.0 : 000.0 : 001 : CvMap::doTurn()
009.0 : 000.0 : 000.0 : 000.0 : 1024 : CvPlot::doTurn
007.0 : 000.0 : 000.0 : 000.0 : 1024 : CvPlot::doFeature()
663.0 : 000.0 : 000.0 : 000.0 : 001 : CvPlayer::doTurnUnits
277.0 : 000.0 : 000.0 : 000.0 : 001 : CvPlayerAI::AI_doTurnUnitsPre
277.0 : 039.7 : 000.6 : 039.7 : 001 : CvPlayerAI::AI_updateFoundValues
236.0 : 033.8 : 005.8 : 033.8 : 488 : CvPlayerAI::AI_baseBonusVal
236.0 : 033.8 : 005.8 : 033.8 : 012 : CvPlayerAI::AI_baseBonusVal::recalculate
013.0 : 001.9 : 000.1 : 001.9 : 2528 : CvPlayer::canTrain
13595.0 : 000.0 : 000.0 : 000.0 : 2463 : CvCity::canTrain
385.0 : 000.0 : 000.0 : 000.0 : 001 : CvPlayerAI::AI_doTurnUnitsPost
008.0 : 000.0 : 000.0 : 000.0 : 006 : CvUnitAI::AI_upgrade
002.0 : 000.0 : 000.0 : 000.0 : 1275 : CvPlayer::calculateScore
--------------------------------------------------
Why not just set the callback in the XML to 0? No need to comment out the code. Or is that callback non-optional?
Please take a look on the revdcm forum. Phungus420 is in the middle of changing inquisitors to be soft-coded, ie controlled by xml flags + sdk. This would remove the inquisitor parts of the cvgameutil.py including canTrain.
It's already done, and the code is posted.
Please take a look on the revdcm forum. Phungus420 is in the middle of changing inquisitors to be soft-coded, ie controlled by xml flags + sdk. This would remove the inquisitor parts of the cvgameutil.py including canTrain.