For instance, I've been working on third person over the shoulder archery which requires me to stop head tracking updates for the player only when i'm in third person ranged aiming.
The code before I touched it:
The code after I touched it:for (PtrActorMap::iterator it(mActors.begin()); it != mActors.end(); ++it)
{
if (it->first == iter->first)
continue;
updateHeadTracking(iter->first, it->first, headTrackTarget, sqrHeadTrackDistance);
}
iter->second->getCharacterController()->setHeadTrackTarget(headTrackTarget);
Essentially for every actor on screen, I will constantly check the third person ranged flag and if my current iteration of actors is the player. This one check may not cost much depending on the frequency of update of head tracking, actor count, etc., but I see if(ptr == player) checks sprinkled across both actors.cpp and character.cpp many of which are loops where under various conditions, the player is ignored or perhaps does something extra.if (!((iter->first == player) && MWBase::Environment::get().getWorld()->getPlayer().getThirdPersonOverShoulderRanged()))
{
for (PtrActorMap::iterator it(mActors.begin()); it != mActors.end(); ++it)
{
if (it->first == iter->first)
continue;
updateHeadTracking(iter->first, it->first, headTrackTarget, sqrHeadTrackDistance);
}
}
iter->second->getCharacterController()->setHeadTrackTarget(headTrackTarget);
For the example above, adding general accessors to the map from outside and removing the player from the map would save the check altogether. For if checks where the player does something extra we may need to see if we can gather the work and amortize the check once.
Also, i'm not sure if vectors were looked into for all of these loop lists. Might improve on cache locality as well but again, need to profile first