mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-28 20:06:41 +00:00
Do not store pointer to Pathgrid in PathFinder
This commit is contained in:
parent
3565d92e11
commit
ca3d0594b3
2 changed files with 10 additions and 16 deletions
|
@ -83,8 +83,7 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
|
|
||||||
PathFinder::PathFinder()
|
PathFinder::PathFinder()
|
||||||
: mPathgrid(nullptr)
|
: mCell(nullptr)
|
||||||
, mCell(nullptr)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,18 +133,14 @@ namespace MWMechanics
|
||||||
const MWWorld::CellStore* cell, const PathgridGraph& pathgridGraph)
|
const MWWorld::CellStore* cell, const PathgridGraph& pathgridGraph)
|
||||||
{
|
{
|
||||||
mPath.clear();
|
mPath.clear();
|
||||||
|
mCell = cell;
|
||||||
|
|
||||||
// TODO: consider removing mCell / mPathgrid in favor of mPathgridGraph
|
const auto pathgrid = pathgridGraph.getPathgrid();
|
||||||
if(mCell != cell || !mPathgrid)
|
|
||||||
{
|
|
||||||
mCell = cell;
|
|
||||||
mPathgrid = pathgridGraph.getPathgrid();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Refer to AiWander reseach topic on openmw forums for some background.
|
// Refer to AiWander reseach topic on openmw forums for some background.
|
||||||
// Maybe there is no pathgrid for this cell. Just go to destination and let
|
// Maybe there is no pathgrid for this cell. Just go to destination and let
|
||||||
// physics take care of any blockages.
|
// physics take care of any blockages.
|
||||||
if(!mPathgrid || mPathgrid->mPoints.empty())
|
if(!pathgrid || pathgrid->mPoints.empty())
|
||||||
{
|
{
|
||||||
mPath.push_back(endPoint);
|
mPath.push_back(endPoint);
|
||||||
return;
|
return;
|
||||||
|
@ -160,18 +155,18 @@ namespace MWMechanics
|
||||||
// point right behind the wall that is closer than any pathgrid
|
// point right behind the wall that is closer than any pathgrid
|
||||||
// point outside the wall
|
// point outside the wall
|
||||||
osg::Vec3f startPointInLocalCoords(converter.toLocalVec3(startPoint));
|
osg::Vec3f startPointInLocalCoords(converter.toLocalVec3(startPoint));
|
||||||
int startNode = getClosestPoint(mPathgrid, startPointInLocalCoords);
|
int startNode = getClosestPoint(pathgrid, startPointInLocalCoords);
|
||||||
|
|
||||||
osg::Vec3f endPointInLocalCoords(converter.toLocalVec3(endPoint));
|
osg::Vec3f endPointInLocalCoords(converter.toLocalVec3(endPoint));
|
||||||
std::pair<int, bool> endNode = getClosestReachablePoint(mPathgrid, &pathgridGraph,
|
std::pair<int, bool> endNode = getClosestReachablePoint(pathgrid, &pathgridGraph,
|
||||||
endPointInLocalCoords,
|
endPointInLocalCoords,
|
||||||
startNode);
|
startNode);
|
||||||
|
|
||||||
// if it's shorter for actor to travel from start to end, than to travel from either
|
// if it's shorter for actor to travel from start to end, than to travel from either
|
||||||
// start or end to nearest pathgrid point, just travel from start to end.
|
// start or end to nearest pathgrid point, just travel from start to end.
|
||||||
float startToEndLength2 = (endPointInLocalCoords - startPointInLocalCoords).length2();
|
float startToEndLength2 = (endPointInLocalCoords - startPointInLocalCoords).length2();
|
||||||
float endTolastNodeLength2 = distanceSquared(mPathgrid->mPoints[endNode.first], endPointInLocalCoords);
|
float endTolastNodeLength2 = distanceSquared(pathgrid->mPoints[endNode.first], endPointInLocalCoords);
|
||||||
float startTo1stNodeLength2 = distanceSquared(mPathgrid->mPoints[startNode], startPointInLocalCoords);
|
float startTo1stNodeLength2 = distanceSquared(pathgrid->mPoints[startNode], startPointInLocalCoords);
|
||||||
if ((startToEndLength2 < startTo1stNodeLength2) || (startToEndLength2 < endTolastNodeLength2))
|
if ((startToEndLength2 < startTo1stNodeLength2) || (startToEndLength2 < endTolastNodeLength2))
|
||||||
{
|
{
|
||||||
mPath.push_back(endPoint);
|
mPath.push_back(endPoint);
|
||||||
|
@ -185,7 +180,7 @@ namespace MWMechanics
|
||||||
// nodes are the same
|
// nodes are the same
|
||||||
if(startNode == endNode.first)
|
if(startNode == endNode.first)
|
||||||
{
|
{
|
||||||
ESM::Pathgrid::Point temp(mPathgrid->mPoints[startNode]);
|
ESM::Pathgrid::Point temp(pathgrid->mPoints[startNode]);
|
||||||
converter.toWorld(temp);
|
converter.toWorld(temp);
|
||||||
mPath.push_back(makeOsgVec3(temp));
|
mPath.push_back(makeOsgVec3(temp));
|
||||||
}
|
}
|
||||||
|
@ -198,7 +193,7 @@ namespace MWMechanics
|
||||||
if (path.size() > 1)
|
if (path.size() > 1)
|
||||||
{
|
{
|
||||||
ESM::Pathgrid::Point secondNode = *(++path.begin());
|
ESM::Pathgrid::Point secondNode = *(++path.begin());
|
||||||
osg::Vec3f firstNodeVec3f = makeOsgVec3(mPathgrid->mPoints[startNode]);
|
osg::Vec3f firstNodeVec3f = makeOsgVec3(pathgrid->mPoints[startNode]);
|
||||||
osg::Vec3f secondNodeVec3f = makeOsgVec3(secondNode);
|
osg::Vec3f secondNodeVec3f = makeOsgVec3(secondNode);
|
||||||
osg::Vec3f toSecondNodeVec3f = secondNodeVec3f - firstNodeVec3f;
|
osg::Vec3f toSecondNodeVec3f = secondNodeVec3f - firstNodeVec3f;
|
||||||
osg::Vec3f toStartPointVec3f = startPointInLocalCoords - firstNodeVec3f;
|
osg::Vec3f toStartPointVec3f = startPointInLocalCoords - firstNodeVec3f;
|
||||||
|
|
|
@ -163,7 +163,6 @@ namespace MWMechanics
|
||||||
private:
|
private:
|
||||||
std::deque<osg::Vec3f> mPath;
|
std::deque<osg::Vec3f> mPath;
|
||||||
|
|
||||||
const ESM::Pathgrid *mPathgrid;
|
|
||||||
const MWWorld::CellStore* mCell;
|
const MWWorld::CellStore* mCell;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue