tweaks to pathfinder and pathfollower(basically nothing)

This commit is contained in:
GameHerobrine 2024-04-14 03:41:24 +03:00
parent da28b3b0ff
commit cb0fa06e12
5 changed files with 94 additions and 25 deletions

View file

@ -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])

View file

@ -3,9 +3,10 @@
class MCDiagonalProvider implements INeighborProvider
{
private static $neighbors = array(
[ -1, 0, -1 ], [-1, 0, 0], [-1, 0, 1],
[0, 0, -1], [0, 0, 1],
[1, 0, -1], [1, 0, 0], [1, 0, -1]
[-1, 0, 0],
[0, 0, -1],
[1, 0, 0],
[0, 0, 1],
);
private static $jumpOffset = [0, 1, 0];
private static $moveDownOffset = [0, -1, 0];
@ -15,17 +16,26 @@ class MCDiagonalProvider implements INeighborProvider
$pnts = [];
foreach(MCDiagonalProvider::$neighbors as $offset){
$pnt = $tile->addOffset($offset);
if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y, $pnt->z))){
if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y - 1, $pnt->z))){
--$pnt->y;
}
$pnts[] = $pnt;
}else{
if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y + 1, $pnt->z))){
++$pnt->y;
$pnts[] = $pnt;
}
}
//if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y, $pnt->z))){
//
//}
//if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y, $pnt->z))){
// if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y - 1, $pnt->z))){
// --$pnt->y;
// }
// $pnts[] = $pnt;
//}else{
// if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y + 1, $pnt->z))){
// ++$pnt->y;
// $pnts[] = $pnt;
// }
//}
}
return $pnts;
}