From 58bf7624becac34486eb6018c301de9d9f27ef04 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 13 May 2014 21:52:05 -0400 Subject: [PATCH] Made code a bit more efficient --- apps/openmw/mwmechanics/aiactivate.cpp | 2 +- apps/openmw/mwmechanics/aiavoiddoor.hpp | 2 +- apps/openmw/mwmechanics/aipackage.cpp | 2 +- apps/openmw/mwworld/worldimp.cpp | 8 ++------ 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwmechanics/aiactivate.cpp b/apps/openmw/mwmechanics/aiactivate.cpp index 1463dff7e..56c155ded 100644 --- a/apps/openmw/mwmechanics/aiactivate.cpp +++ b/apps/openmw/mwmechanics/aiactivate.cpp @@ -29,7 +29,7 @@ bool MWMechanics::AiActivate::execute (const MWWorld::Ptr& actor,float duration) //Set the target desition from the actor ESM::Pathgrid::Point dest = target.getRefData().getPosition().pos; - if(distance(dest, pos.pos[0], pos.pos[1], pos.pos[2]) < 200 || mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1], pos.pos[2])) { //Stop when you get close + if(distance(dest, pos.pos[0], pos.pos[1], pos.pos[2]) < 200) { //Stop when you get close actor.getClass().getMovementSettings(actor).mPosition[1] = 0; MWWorld::Ptr target = MWBase::Environment::get().getWorld()->getPtr(mObjectId,false); MWWorld::Class::get(target).activate(target,actor).get()->execute(actor); //Arrest player diff --git a/apps/openmw/mwmechanics/aiavoiddoor.hpp b/apps/openmw/mwmechanics/aiavoiddoor.hpp index 6e9a1bdf5..8d225655a 100644 --- a/apps/openmw/mwmechanics/aiavoiddoor.hpp +++ b/apps/openmw/mwmechanics/aiavoiddoor.hpp @@ -29,7 +29,7 @@ namespace MWMechanics private: float mDuration; - MWWorld::Ptr mDoorPtr; + const MWWorld::Ptr& mDoorPtr; }; } #endif diff --git a/apps/openmw/mwmechanics/aipackage.cpp b/apps/openmw/mwmechanics/aipackage.cpp index 1bc350383..5ccd2c8d8 100644 --- a/apps/openmw/mwmechanics/aipackage.cpp +++ b/apps/openmw/mwmechanics/aipackage.cpp @@ -96,7 +96,7 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, ESM::Pathgrid::Po if(door != NULL) // NOTE: checks interior cells only { if(door->mRef.mTrap.empty() && mLastDoorChecked != door) { //Open the door if untrapped - door->mClass->activate(MWBase::Environment::get().getWorld()->getPtr(door->mRef.mRefID,false), actor).get()->execute(actor); + door->mClass->activate(MWWorld::Ptr(door, actor.getCell()), actor).get()->execute(actor); mLastDoorChecked = door; } } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 82489adac..96dd91f82 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1863,12 +1863,8 @@ namespace MWWorld bool World::getIsMovingDoor(const Ptr& door) { - //This more expensive comparison is needed for some reason - // TODO (tluppi#1#): Figure out why comparing Ptr isn't working - for(std::map::iterator it = mDoorStates.begin(); it != mDoorStates.end(); it++) - if(it->first.getCellRef().mRefID == door.getCellRef().mRefID) - return true; - return false; + bool result = mDoorStates.find(door) != mDoorStates.end(); + return result; } bool World::getPlayerStandingOn (const MWWorld::Ptr& object)