perfomances optimisations (pathfinding is computed less often, max 4 times per sec)

This commit is contained in:
gus 2013-10-30 20:52:23 +01:00
parent 650a112e2e
commit 2a927f65d3
2 changed files with 9 additions and 3 deletions

View file

@ -25,7 +25,7 @@ namespace MWMechanics
{ {
AiCombat::AiCombat(const std::string &targetId) AiCombat::AiCombat(const std::string &targetId)
:mTargetId(targetId),mTimer(0) :mTargetId(targetId),mTimer(0),mTimer2(0)
{ {
} }
@ -66,15 +66,20 @@ namespace MWMechanics
start.mY = pos.pos[1]; start.mY = pos.pos[1];
start.mZ = pos.pos[2]; start.mZ = pos.pos[2];
mTimer2 = mTimer2 + duration;
if(!mPathFinder.isPathConstructed()) if(!mPathFinder.isPathConstructed())
mPathFinder.buildPath(start, dest, pathgrid, xCell, yCell, true); mPathFinder.buildPath(start, dest, pathgrid, xCell, yCell, true);
else else
{ {
mPathFinder2.buildPath(start, dest, pathgrid, xCell, yCell, true); mPathFinder2.buildPath(start, dest, pathgrid, xCell, yCell, true);
ESM::Pathgrid::Point lastPt = mPathFinder.getPath().back(); ESM::Pathgrid::Point lastPt = mPathFinder.getPath().back();
if(mPathFinder2.getPathSize() < mPathFinder.getPathSize() || if((mTimer2 > 0.25)&&(mPathFinder2.getPathSize() < mPathFinder.getPathSize() ||
(dest.mX - lastPt.mX)*(dest.mX - lastPt.mX)+(dest.mY - lastPt.mY)*(dest.mY - lastPt.mY)+(dest.mZ - lastPt.mZ)*(dest.mZ - lastPt.mZ) > 200*200) (dest.mX - lastPt.mX)*(dest.mX - lastPt.mX)+(dest.mY - lastPt.mY)*(dest.mY - lastPt.mY)+(dest.mZ - lastPt.mZ)*(dest.mZ - lastPt.mZ) > 200*200))
{
mTimer2 = 0;
mPathFinder = mPathFinder2; mPathFinder = mPathFinder2;
}
} }
mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1],pos.pos[2]); mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1],pos.pos[2]);

View file

@ -35,6 +35,7 @@ namespace MWMechanics
PathFinder mPathFinder; PathFinder mPathFinder;
PathFinder mPathFinder2; PathFinder mPathFinder2;
float mTimer; float mTimer;
float mTimer2;
}; };
} }