This commit is contained in:
GameHerobrine 2022-12-31 21:59:40 +03:00
parent 0f72601891
commit 2573e4f90d
14 changed files with 65 additions and 57 deletions

View file

@ -2,6 +2,6 @@
interface ITileNavigator
{
public function navigate(PathTile $from, PathTile $to);
public function navigate(PathTile $from, PathTile $to, $maxDist);
}

View file

@ -24,6 +24,10 @@ class PathTileXYZ extends PathTile
return new Vector3($this->x, $this->y, $this->z);
}
public function asArray(){
return ["x" => $this->x, "y" => $this->y, "z" => $this->z];
}
public function addOffset($offset){
$this->x += $offset[0];
$this->y += $offset[1];

View file

@ -23,7 +23,7 @@ class TileNavigator implements ITileNavigator
return array_reverse($totalPath);
}
public function navigate(PathTile $from, PathTile $to)
public function navigate(PathTile $from, PathTile $to, $maxDist) //TODO optimizations, no arraylist
{
$closed = new ArrayList();
$open = new ArrayList();
@ -54,14 +54,20 @@ class TileNavigator implements ITileNavigator
$closed->add($current);
foreach($this->neighborProvider->getNeighbors($current) as $neighbor)
{
if(in_array($neighbor, $visited)){
continue;
}
$visited[] = $neighbor;
if ($closed->has($neighbor) || $this->blockedProvider->isBlocked($neighbor))
{
continue;
}
if(in_array($neighbor, $visited)){
if(!Utils::in_range(Utils::distance($neighbor->asArray(), $from->asArray()), -$maxDist, $maxDist)){
continue;
}
$visited[] = $neighbor;
$tentativeG = $gScore[(string) $current] + $this->distanceAlgorithm->calculate($current, $neighbor);
if (!$open->has($neighbor))