@@ -387,38 +387,38 @@ private void VisitNeighbour(int parentIndex, int nodeX, int nodeY, int nodeIndex
387
387
PathMinG = candidateMinG ,
388
388
Score = CalculateScore ( destPixG , candidateMinG , candidateLeeway , nodeIndex )
389
389
} ;
390
-
391
- if ( currentParentNode . Score >= Score . UnsafeImprove && altNode . Score == Score . JustBad ) // don't leave safe cells if it requires going through bad cells
390
+ ref var altnode = ref altNode ;
391
+ if ( ( currentParentNode . Score >= Score . Safe || currentParentNode . Score >= Score . UnsafeAsStart && altnode . PathLeeway < 0f ) && altnode . Score == Score . JustBad ) // don't leave safe cells if it requires going through bad cells
392
392
return ;
393
393
394
394
var grandParentIndex = currentParentNode . ParentIndex ;
395
-
396
- if ( grandParentIndex != nodeIndex && _nodes [ grandParentIndex ] . PathMinG >= currentParentNode . PathMinG )
395
+ ref var grandparentnode = ref _nodes [ grandParentIndex ] ;
396
+ if ( grandParentIndex != nodeIndex && grandparentnode . PathMinG >= currentParentNode . PathMinG )
397
397
{
398
398
var ( gx , gy ) = _map . IndexToGrid ( grandParentIndex ) ;
399
399
400
400
// Attempt to see if we can go directly from grandparent to (nodeX, nodeY)
401
- if ( LineOfSight ( gx , gy , nodeX , nodeY , _nodes [ grandParentIndex ] . GScore , out var losLeeway , out var losDist , out var losMinG ) )
401
+ if ( LineOfSight ( gx , gy , nodeX , nodeY , grandparentnode . GScore , out var losLeeway , out var losDist , out var losMinG ) )
402
402
{
403
403
var losScore = CalculateScore ( destPixG , losMinG , losLeeway , nodeIndex ) ;
404
- if ( losScore >= altNode . Score )
404
+ if ( losScore >= altnode . Score )
405
405
{
406
406
parentIndex = grandParentIndex ;
407
- altNode . GScore = _nodes [ parentIndex ] . GScore + _deltaGSide * losDist ;
408
- altNode . ParentIndex = grandParentIndex ;
409
- altNode . PathLeeway = losLeeway ;
410
- altNode . PathMinG = losMinG ;
411
- altNode . Score = losScore ;
407
+ altnode . GScore = _nodes [ parentIndex ] . GScore + _deltaGSide * losDist ;
408
+ altnode . ParentIndex = grandParentIndex ;
409
+ altnode . PathLeeway = losLeeway ;
410
+ altnode . PathMinG = losMinG ;
411
+ altnode . Score = losScore ;
412
412
}
413
413
}
414
414
}
415
415
416
- var visit = destNode . OpenHeapIndex == 0 || CompareNodeScores ( ref altNode , ref destNode ) < ( destNode . OpenHeapIndex < 0 ? - 1 : 0 ) ;
416
+ var visit = destNode . OpenHeapIndex == 0 || CompareNodeScores ( ref altnode , ref destNode ) < ( destNode . OpenHeapIndex < 0 ? - 1 : 0 ) ;
417
417
if ( visit )
418
418
{
419
419
if ( destNode . OpenHeapIndex < 0 )
420
420
++ NumReopens ;
421
- destNode = altNode ;
421
+ destNode = altnode ;
422
422
AddToOpen ( nodeIndex ) ;
423
423
}
424
424
}
0 commit comments