Math: Kill BlockIterator, added a VoxelRayTrace class with level-independent generator functions (#1885)

This is a rather larger commit than I'm happy with, but oh well.

This kills off the enormously overcomplicated BlockIterator and replaces it with a VoxelRayTrace class containing ray tracing generator functions. These functions are independent of any Level. They yield Vector3 objects with current ray trace positions to allow implementations to handle the intercepted blocks in their own ways.

Living->getLineOfSight() now uses VoxelRayTrace instead of BlockIterator.
This commit is contained in:
Dylan K. Taylor
2018-01-10 20:14:36 +00:00
committed by GitHub
parent 24116ba846
commit 71d11c73f0
4 changed files with 141 additions and 382 deletions

View File

@ -1245,78 +1245,6 @@ class Level implements ChunkManager, Metadatable{
return $collides;
}
/*
public function rayTraceBlocks(Vector3 $pos1, Vector3 $pos2, $flag = false, $flag1 = false, $flag2 = false){
if(!is_nan($pos1->x) and !is_nan($pos1->y) and !is_nan($pos1->z)){
if(!is_nan($pos2->x) and !is_nan($pos2->y) and !is_nan($pos2->z)){
$x1 = (int) $pos1->x;
$y1 = (int) $pos1->y;
$z1 = (int) $pos1->z;
$x2 = (int) $pos2->x;
$y2 = (int) $pos2->y;
$z2 = (int) $pos2->z;
$block = $this->getBlock(Vector3::createVector($x1, $y1, $z1));
if(!$flag1 or $block->getBoundingBox() !== null){
$ob = $block->calculateIntercept($pos1, $pos2);
if($ob !== null){
return $ob;
}
}
$movingObjectPosition = null;
$k = 200;
while($k-- >= 0){
if(is_nan($pos1->x) or is_nan($pos1->y) or is_nan($pos1->z)){
return null;
}
if($x1 === $x2 and $y1 === $y2 and $z1 === $z2){
return $flag2 ? $movingObjectPosition : null;
}
$flag3 = true;
$flag4 = true;
$flag5 = true;
$i = 999;
$j = 999;
$k = 999;
if($x1 > $x2){
$i = $x2 + 1;
}elseif($x1 < $x2){
$i = $x2;
}else{
$flag3 = false;
}
if($y1 > $y2){
$j = $y2 + 1;
}elseif($y1 < $y2){
$j = $y2;
}else{
$flag4 = false;
}
if($z1 > $z2){
$k = $z2 + 1;
}elseif($z1 < $z2){
$k = $z2;
}else{
$flag5 = false;
}
//TODO
}
}
}
}
*/
public function getFullLight(Vector3 $pos) : int{
return $this->getFullLightAt($pos->x, $pos->y, $pos->z);
}