# UNDF: UNDF-2026-000000964 --- a/apps/openmw/mwmechanics/pathgrid.cpp +++ b/apps/openmw/mwmechanics/pathgrid.cpp @@ -1,6 +1,7 @@ #include "pathgrid.hpp" #include +#include #include #include @@ -250,6 +251,7 @@ std::list openset; std::set closedset; + std::unordered_set opensetMembership; openset.push_back(start); + opensetMembership.insert(start); size_t current = start; @@ -260,6 +262,7 @@ current = openset.front(); // front has the lowest cost openset.pop_front(); + opensetMembership.erase(current); if (current == goal) break; @@ -274,7 +277,7 @@ size_t dest = edge.index; float tentativeG = gScore[current] + edge.cost; - bool isInOpenSet = std::find(openset.begin(), openset.end(), dest) != openset.end(); + bool isInOpenSet = opensetMembership.count(dest) > 0; if (!isInOpenSet || tentativeG < gScore[dest]) { graphParent[dest] = current; @@ -282,6 +285,7 @@ fScore[dest] = tentativeG + costAStar(mPathgrid->mPoints[dest], mPathgrid->mPoints[goal]); if (!isInOpenSet) { + opensetMembership.insert(dest); // add this edge to openset, lowest cost goes to the front // TODO: if this causes performance problems a hash table may help auto it = openset.begin();