1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-21 09:53:50 +00:00

Store path points in deque

This commit is contained in:
elsid 2018-08-18 13:40:04 +03:00
parent 925d909fea
commit 9b3756f8bc
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
3 changed files with 5 additions and 7 deletions

View file

@ -148,8 +148,7 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, const osg::Vec3f&
if (destInLOS && mPathFinder.getPath().size() > 1) if (destInLOS && mPathFinder.getPath().size() > 1)
{ {
// get point just before dest // get point just before dest
auto pPointBeforeDest = mPathFinder.getPath().rbegin(); auto pPointBeforeDest = mPathFinder.getPath().rbegin() + 1;
++pPointBeforeDest;
// if start point is closer to the target then last point of path (excluding target itself) then go straight on the target // if start point is closer to the target then last point of path (excluding target itself) then go straight on the target
if (distance(start, dest) <= distance(dest, *pPointBeforeDest)) if (distance(start, dest) <= distance(dest, *pPointBeforeDest))

View file

@ -298,8 +298,7 @@ namespace MWMechanics
{ {
// if 2nd waypoint of new path == 1st waypoint of old, // if 2nd waypoint of new path == 1st waypoint of old,
// delete 1st waypoint of new path. // delete 1st waypoint of new path.
const auto iter = ++mPath.begin(); if (mPath[1] == oldStart)
if (*iter == oldStart)
{ {
mPath.pop_front(); mPath.pop_front();
} }

View file

@ -1,7 +1,7 @@
#ifndef GAME_MWMECHANICS_PATHFINDING_H #ifndef GAME_MWMECHANICS_PATHFINDING_H
#define GAME_MWMECHANICS_PATHFINDING_H #define GAME_MWMECHANICS_PATHFINDING_H
#include <list> #include <deque>
#include <cassert> #include <cassert>
#include <components/esm/defs.hpp> #include <components/esm/defs.hpp>
@ -95,7 +95,7 @@ namespace MWMechanics
return mPath.size(); return mPath.size();
} }
const std::list<osg::Vec3f>& getPath() const const std::deque<osg::Vec3f>& getPath() const
{ {
return mPath; return mPath;
} }
@ -172,7 +172,7 @@ namespace MWMechanics
} }
private: private:
std::list<osg::Vec3f> mPath; std::deque<osg::Vec3f> mPath;
const ESM::Pathgrid *mPathgrid; const ESM::Pathgrid *mPathgrid;
const MWWorld::CellStore* mCell; const MWWorld::CellStore* mCell;