Few method call avoid

This commit is contained in:
Daniel Maixner 2022-12-29 15:58:30 +01:00
parent 85224194d0
commit 4e72ee56df
5 changed files with 10 additions and 7 deletions

View File

@ -110,7 +110,7 @@ final class Backtrack
$states[] = $i; $states[] = $i;
} }
if ($states === []) { if ($states === []) {
$states[] = 0; return [0];
} }
return $states; return $states;
} }

View File

@ -8,7 +8,7 @@ class Bullet
{ {
private Point $origin; private Point $origin;
private Point $position; public Point $position;
private int $originPlayerId; private int $originPlayerId;
private bool $originPlayerIsAttacker; private bool $originPlayerIsAttacker;
private int $distanceTraveled; private int $distanceTraveled;

View File

@ -31,7 +31,10 @@ class Collision
public static function pointWithSphere(Point $point, Point $sphereCenter, int $sphereRadius): bool public static function pointWithSphere(Point $point, Point $sphereCenter, int $sphereRadius): bool
{ {
return Util::distanceSquared($point, $sphereCenter) <= $sphereRadius * $sphereRadius; $dx = $point->x - $sphereCenter->x;
$dy = $point->y - $sphereCenter->y;
$dz = $point->z - $sphereCenter->z;
return (($dx * $dx) + ($dy * $dy) + ($dz * $dz)) <= ($sphereRadius * $sphereRadius);
} }
public static function cylinderWithCylinder( public static function cylinderWithCylinder(

View File

@ -95,9 +95,9 @@ class HitBox implements Hittable
return $armorDamage; return $armorDamage;
} }
public function intersect(Bullet $bullet): bool public function intersect(Point $point): bool
{ {
return $this->geometry->intersect($this->player, $bullet->getPosition()); return $this->geometry->intersect($this->player, $point);
} }
public function getPlayer(): Player public function getPlayer(): Player

View File

@ -34,7 +34,7 @@ class PlayerCollider
public function tryHitPlayer(Bullet $bullet, Backtrack $backtrack): ?Hittable public function tryHitPlayer(Bullet $bullet, Backtrack $backtrack): ?Hittable
{ {
$bp = $bullet->getPosition(); $bp = $bullet->position;
foreach ($backtrack->getStates() as $state) { foreach ($backtrack->getStates() as $state) {
$backtrack->apply($state, $this->playerId); $backtrack->apply($state, $this->playerId);
@ -48,7 +48,7 @@ class PlayerCollider
} }
foreach ($this->hitBoxes as $hitBox) { foreach ($this->hitBoxes as $hitBox) {
if ($hitBox->intersect($bullet)) { if ($hitBox->intersect($bp)) {
$hitBox->registerHit($bullet); $hitBox->registerHit($bullet);
return $hitBox; return $hitBox;
} }