BLADERUNNER: Better fix for bug in pathfinding
Basically just more robust (but slower) fix to the intermittent assert in pathfinding code when polygons were touching only by a single corner.
This commit is contained in:
parent
664dd4a8aa
commit
1630cf0e6c
1 changed files with 6 additions and 9 deletions
|
@ -191,7 +191,6 @@ bool Obstacles::mergePolygons(Polygon &polyA, Polygon &polyB) {
|
||||||
bool flagAddVertexToVertexList = true;
|
bool flagAddVertexToVertexList = true;
|
||||||
bool flagDidFindIntersection = false;
|
bool flagDidFindIntersection = false;
|
||||||
int vertIndex = 0;
|
int vertIndex = 0;
|
||||||
int lastIntersectionIndex = -1;
|
|
||||||
|
|
||||||
Polygon *startingPolygon = polyPrimary;
|
Polygon *startingPolygon = polyPrimary;
|
||||||
int flagDone = false;
|
int flagDone = false;
|
||||||
|
@ -205,7 +204,12 @@ bool Obstacles::mergePolygons(Polygon &polyA, Polygon &polyB) {
|
||||||
polyPrimaryType = polyPrimary->vertexType[vertIndex];
|
polyPrimaryType = polyPrimary->vertexType[vertIndex];
|
||||||
|
|
||||||
if (flagAddVertexToVertexList) {
|
if (flagAddVertexToVertexList) {
|
||||||
assert(polyMerged.verticeCount < kPolygonVertexCount);
|
// In some cases polygons will have only one intersection (touching corners) and because of that second SWAP never occure,
|
||||||
|
// algorithm will stop only when the merged polygon is full.
|
||||||
|
if (polyMerged.verticeCount >= kPolygonVertexCount) {
|
||||||
|
flagDidMergePolygons = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
polyMerged.vertices[polyMerged.verticeCount] = polyLine.start;
|
polyMerged.vertices[polyMerged.verticeCount] = polyLine.start;
|
||||||
polyMerged.vertexType[polyMerged.verticeCount] = polyPrimaryType;
|
polyMerged.vertexType[polyMerged.verticeCount] = polyPrimaryType;
|
||||||
polyMerged.verticeCount++;
|
polyMerged.verticeCount++;
|
||||||
|
@ -227,15 +231,8 @@ bool Obstacles::mergePolygons(Polygon &polyA, Polygon &polyB) {
|
||||||
SWAP(polyPrimary, polySecondary);
|
SWAP(polyPrimary, polySecondary);
|
||||||
|
|
||||||
flagDidMergePolygons = true;
|
flagDidMergePolygons = true;
|
||||||
lastIntersectionIndex = polySecondaryIntersectionIndex;
|
|
||||||
} else {
|
} else {
|
||||||
vertIndex = (vertIndex + 1) % polyPrimary->verticeCount;
|
vertIndex = (vertIndex + 1) % polyPrimary->verticeCount;
|
||||||
// In some cases polygons will have only one intersection (touching corners) and because of that second SWAP never occure and algorithm will never stop.
|
|
||||||
// This can be avoided by stopping the algorithm after looping over whole polygon. Such polygons will not merge.
|
|
||||||
if (vertIndex == lastIntersectionIndex) {
|
|
||||||
flagDidMergePolygons = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
flagDidFindIntersection = false;
|
flagDidFindIntersection = false;
|
||||||
}
|
}
|
||||||
if (polyPrimary->vertices[vertIndex] == startingPolygon->vertices[0]) {
|
if (polyPrimary->vertices[vertIndex] == startingPolygon->vertices[0]) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue