mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
tweaks to pathfinder and pathfollower(basically nothing)
This commit is contained in:
parent
da28b3b0ff
commit
cb0fa06e12
5 changed files with 94 additions and 25 deletions
|
|
@ -26,8 +26,9 @@ class TileNavigator implements ITileNavigator
|
|||
|
||||
public function navigate(PathTile $from, PathTile $to, $maxDist)
|
||||
{
|
||||
$open = [0 => $from];
|
||||
$open = new SplPriorityQueue();
|
||||
//$open->insert(, 0);
|
||||
$open->insert($from, 0);
|
||||
$path = [];
|
||||
$gScore = [];
|
||||
$gScore[(string) $from] = 0;
|
||||
|
|
@ -37,9 +38,10 @@ class TileNavigator implements ITileNavigator
|
|||
}
|
||||
$visited = [];
|
||||
$maxDist*=$maxDist; //no square root
|
||||
while(count($open) > 0)
|
||||
while(!$open->isEmpty())
|
||||
{
|
||||
$current = array_pop($open);
|
||||
$current = $open->top();
|
||||
$open->next();
|
||||
if ($current == $to){
|
||||
return $this->reconstructPath($path, $current);
|
||||
}
|
||||
|
|
@ -58,7 +60,9 @@ class TileNavigator implements ITileNavigator
|
|||
$tentativeG = $gScore[(string) $current] + $distbetweenCost;
|
||||
if (!isset($has[(string)$neighbor]))
|
||||
{
|
||||
$open[-$tentativeG] = $neighbor;
|
||||
//if(isset($open[-$tentativeG])) console("overwriting $tentativeG");
|
||||
//$open[-$tentativeG] = $neighbor;
|
||||
$open->insert($neighbor, -$tentativeG);
|
||||
$has[(string)$neighbor] = true;
|
||||
}
|
||||
elseif ($tentativeG >= $gScore[(string) $neighbor])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue