From 9b3756f8bc3ab131ab4a627c13feee032930b97c Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 18 Aug 2018 13:40:04 +0300 Subject: [PATCH] Store path points in deque --- apps/openmw/mwmechanics/aipackage.cpp | 3 +-- apps/openmw/mwmechanics/pathfinding.cpp | 3 +-- apps/openmw/mwmechanics/pathfinding.hpp | 6 +++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwmechanics/aipackage.cpp b/apps/openmw/mwmechanics/aipackage.cpp index a781eb1fff..9bc3ed103e 100644 --- a/apps/openmw/mwmechanics/aipackage.cpp +++ b/apps/openmw/mwmechanics/aipackage.cpp @@ -148,8 +148,7 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, const osg::Vec3f& if (destInLOS && mPathFinder.getPath().size() > 1) { // get point just before dest - auto pPointBeforeDest = mPathFinder.getPath().rbegin(); - ++pPointBeforeDest; + auto pPointBeforeDest = mPathFinder.getPath().rbegin() + 1; // 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)) diff --git a/apps/openmw/mwmechanics/pathfinding.cpp b/apps/openmw/mwmechanics/pathfinding.cpp index 38ddec4dc8..952c92ad57 100644 --- a/apps/openmw/mwmechanics/pathfinding.cpp +++ b/apps/openmw/mwmechanics/pathfinding.cpp @@ -298,8 +298,7 @@ namespace MWMechanics { // if 2nd waypoint of new path == 1st waypoint of old, // delete 1st waypoint of new path. - const auto iter = ++mPath.begin(); - if (*iter == oldStart) + if (mPath[1] == oldStart) { mPath.pop_front(); } diff --git a/apps/openmw/mwmechanics/pathfinding.hpp b/apps/openmw/mwmechanics/pathfinding.hpp index 9cb418b406..0d3b6bdff2 100644 --- a/apps/openmw/mwmechanics/pathfinding.hpp +++ b/apps/openmw/mwmechanics/pathfinding.hpp @@ -1,7 +1,7 @@ #ifndef GAME_MWMECHANICS_PATHFINDING_H #define GAME_MWMECHANICS_PATHFINDING_H -#include +#include #include #include @@ -95,7 +95,7 @@ namespace MWMechanics return mPath.size(); } - const std::list& getPath() const + const std::deque& getPath() const { return mPath; } @@ -172,7 +172,7 @@ namespace MWMechanics } private: - std::list mPath; + std::deque mPath; const ESM::Pathgrid *mPathgrid; const MWWorld::CellStore* mCell;