Assign world to local variable once per function

pull/1633/head
elsid 6 years ago
parent 27a74725f1
commit ab090108cb
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -102,11 +102,11 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, const osg::Vec3f&
mTimer += duration; //Update timer mTimer += duration; //Update timer
const auto position = actor.getRefData().getPosition().asVec3(); //position of the actor const auto position = actor.getRefData().getPosition().asVec3(); //position of the actor
const auto world = MWBase::Environment::get().getWorld();
{ {
const auto halfExtents = MWBase::Environment::get().getWorld()->getHalfExtents(actor); const auto halfExtents = world->getHalfExtents(actor);
MWBase::Environment::get().getWorld()->updateActorPath(actor, mPathFinder.getPath(), halfExtents, world->updateActorPath(actor, mPathFinder.getPath(), halfExtents, position, dest);
position, dest);
} }
/// Stops the actor when it gets too close to a unloaded cell /// Stops the actor when it gets too close to a unloaded cell
@ -131,10 +131,9 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, const osg::Vec3f&
bool destInLOS = false; bool destInLOS = false;
const MWWorld::Class& actorClass = actor.getClass(); const MWWorld::Class& actorClass = actor.getClass();
MWBase::World* world = MWBase::Environment::get().getWorld();
// check if actor can move along z-axis // check if actor can move along z-axis
bool actorCanMoveByZ = (actorClass.canSwim(actor) && MWBase::Environment::get().getWorld()->isSwimming(actor)) bool actorCanMoveByZ = (actorClass.canSwim(actor) && world->isSwimming(actor))
|| world->isFlying(actor); || world->isFlying(actor);
// Prohibit shortcuts for AiWander, if the actor can not move in 3 dimensions. // Prohibit shortcuts for AiWander, if the actor can not move in 3 dimensions.
@ -227,7 +226,8 @@ void MWMechanics::AiPackage::evadeObstacles(const MWWorld::Ptr& actor)
void MWMechanics::AiPackage::openDoors(const MWWorld::Ptr& actor) void MWMechanics::AiPackage::openDoors(const MWWorld::Ptr& actor)
{ {
static float distance = MWBase::Environment::get().getWorld()->getMaxActivationDistance(); const auto world = MWBase::Environment::get().getWorld();
static float distance = world->getMaxActivationDistance();
const MWWorld::Ptr door = getNearbyDoor(actor, distance); const MWWorld::Ptr door = getNearbyDoor(actor, distance);
if (door == MWWorld::Ptr()) if (door == MWWorld::Ptr())
@ -238,7 +238,7 @@ void MWMechanics::AiPackage::openDoors(const MWWorld::Ptr& actor)
{ {
if ((door.getCellRef().getTrap().empty() && door.getCellRef().getLockLevel() <= 0 )) if ((door.getCellRef().getTrap().empty() && door.getCellRef().getLockLevel() <= 0 ))
{ {
MWBase::Environment::get().getWorld()->activate(door, actor); world->activate(door, actor);
return; return;
} }
@ -250,7 +250,7 @@ void MWMechanics::AiPackage::openDoors(const MWWorld::Ptr& actor)
MWWorld::Ptr keyPtr = invStore.search(keyId); MWWorld::Ptr keyPtr = invStore.search(keyId);
if (!keyPtr.isEmpty()) if (!keyPtr.isEmpty())
MWBase::Environment::get().getWorld()->activate(door, actor); world->activate(door, actor);
} }
} }
@ -299,8 +299,9 @@ bool MWMechanics::AiPackage::shortcutPath(const osg::Vec3f& startPoint, const os
bool MWMechanics::AiPackage::checkWayIsClearForActor(const osg::Vec3f& startPoint, const osg::Vec3f& endPoint, const MWWorld::Ptr& actor) bool MWMechanics::AiPackage::checkWayIsClearForActor(const osg::Vec3f& startPoint, const osg::Vec3f& endPoint, const MWWorld::Ptr& actor)
{ {
const bool actorCanMoveByZ = (actor.getClass().canSwim(actor) && MWBase::Environment::get().getWorld()->isSwimming(actor)) const auto world = MWBase::Environment::get().getWorld();
|| MWBase::Environment::get().getWorld()->isFlying(actor); const bool actorCanMoveByZ = (actor.getClass().canSwim(actor) && world->isSwimming(actor))
|| world->isFlying(actor);
if (actorCanMoveByZ) if (actorCanMoveByZ)
return true; return true;

Loading…
Cancel
Save