Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cli/generateNavmesh.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/////

$game = new Game();
$game->loadMap($map);
$planeCount = $game->loadMap($map);
$tileSize = $game->getWorld()::GRENADE_NAVIGATION_MESH_TILE_SIZE;
$colliderHeight = $game->getWorld()::GRENADE_NAVIGATION_MESH_OBJECT_HEIGHT;

Expand All @@ -37,7 +37,8 @@
$path = $map->getNavigationMeshPath($map->generateNavigationMeshKey($tileSize, $colliderHeight));
file_put_contents($path, $pathFinder->getNavigationMesh()->serialize());
printf(
"Navmesh (Nodes: %d; Edges: %d) generated to '%s'%s",
"Navmesh (Planes: %d, Nodes: %d; Edges: %d) generated to '%s'%s",
$planeCount,
$pathFinder->getGraph()->getNodesCount(),
$pathFinder->getGraph()->getEdgeCount(),
$path,
Expand Down
2 changes: 2 additions & 0 deletions cli/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
$debug = in_array('--debug', $argv);
$bindAddress = "udp://0.0.0.0:$port";
$map = Maps\DefaultMap::class;
ini_set('memory_limit', '1G');
/////

$settings = new ServerSetting($playersMax); // must be first for correctly setting the global tickRate (Util::$TICK_RATE)
Expand All @@ -24,6 +25,7 @@

$game = ($debug ? GameFactory::createDebug() : GameFactory::createDefaultCompetitive());
$game->loadMap(new $map);
$game->getWorld()->regenerateNavigationMeshes();

$logger->info("Starting server on '{$bindAddress}', waiting maximum of '{$settings->warmupWaitSec}' sec for '{$playersMax}' player" . ($playersMax > 1 ? 's' : '') . " to connect.");
$net = new ClueSocket($bindAddress);
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"scripts": {
"post-install-cmd": "@php -d memory_limit=200M cli/generateNavmesh.php",
"post-install-cmd": "@php -d memory_limit=300M cli/generateNavmesh.php",
"stan": "@php vendor/bin/phpstan --memory-limit=300M analyze",
"unit": "@php vendor/bin/phpunit -d memory_limit=200M",
"infection": "@php -d memory_limit=300M vendor/bin/infection --show-mutations --threads=max --min-covered-msi=100",
"dev": "php cli/server.php 1 8080 --debug & php cli/udp-ws-bridge.php",
"dev2": "php cli/server.php 2 8080 --debug & php cli/udp-ws-bridge.php & php cli/udp-ws-bridge.php 8082",
"dev2c": "php cli/server.php 2 8080 --debug & php cli/udp-ws-bridge.php & sleep 2 && php cli/client.php acode 8080",
"dev3c": "php cli/server.php 3 8080 --debug & php cli/udp-ws-bridge.php & sleep 1 ; php cli/client.php acode 8080 & php cli/client.php acode 8080",
"dev": "php cli/server.php 1 8080 --debug & sleep 1 && php cli/udp-ws-bridge.php",
"dev2": "php cli/server.php 2 8080 --debug & sleep 1 && php cli/udp-ws-bridge.php & php cli/udp-ws-bridge.php 8082",
"dev2c": "php cli/server.php 2 8080 --debug & sleep 1 && php cli/udp-ws-bridge.php & php cli/client.php acode 8080",
"dev3c": "php cli/server.php 3 8080 --debug & sleep 1 && php cli/udp-ws-bridge.php & php cli/client.php acode 8080 & php cli/client.php acode 8080",
"coverage": [
"@putenv XDEBUG_MODE=coverage",
"@unit --coverage-text=www/coverage/coverage.txt --only-summary-for-coverage-text --coverage-html www/coverage --coverage-xml=www/coverage/coverage-xml --log-junit=www/coverage/junit.xml",
Expand Down
4 changes: 2 additions & 2 deletions server/src/Core/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ public function playersCanBuy(): bool
return ($this->isPaused() || $this->tick <= $this->roundStartTickId + $this->buyTimeTickCount);
}

public function loadMap(Map $map): void
public function loadMap(Map $map): int
{
$this->bomb->setMaxBlastDistance($map->getBombMaxBlastDistance());
$this->world->loadMap($map);
return $this->world->loadMap($map);
}

public function getWorld(): World
Expand Down
2 changes: 1 addition & 1 deletion server/src/Core/PathFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function buildNavigationMesh(Point $start, int $objectHeight, int $maxNod
$startPoint = $start->clone();
$this->convertToNavMeshNode($startPoint);
if (!$this->world->findFloorSquare($startPoint, 1)) {
throw new GameException('No floor on start point'); // @codeCoverageIgnore
throw new GameException('No floor on start: ' . $start); // @codeCoverageIgnore
}

/** @var SplQueue<Point> $queue */
Expand Down
34 changes: 16 additions & 18 deletions server/src/Core/PlaneBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function create(Point $a, Point $b, Point $c, ?Point $d = null, ?float $j
/** @return list<Plane> */
public function fromTriangle(Point $a, Point $b, Point $c, float $voxelSizeDotThreshold): array
{
$this->voxels = [];
$voxelSize = (int)$voxelSizeDotThreshold;
$voxelThreshold = max(1, intval(str_replace('0.', '', abs($voxelSizeDotThreshold - $voxelSize)))); // @phpstan-ignore argument.type
if ($voxelSize > 0) {
Expand All @@ -39,6 +40,7 @@ public function fromTriangle(Point $a, Point $b, Point $c, float $voxelSizeDotTh
$planes[] = (new Wall($voxelPoint->clone()->addX($voxelSize), false, $voxelSize, $voxelSize))->setNormal($this->voxelNormal[0], $this->voxelNormal[1]);
$planes[] = (new Floor($voxelPoint->clone()->addY($voxelSize), $voxelSize, $voxelSize))->setNormal($this->voxelNormal[0], $this->voxelNormal[1]);
}
$this->voxels = [];
return $planes;
}

Expand Down Expand Up @@ -300,7 +302,6 @@ private function voxelizeTriangle(Point $a, Point $b, Point $c, int $voxelSize,
($u[0] * $v[1]) - ($u[1] * $v[0]),
));

$this->voxels = [];
$this->voxelizeLine($a, $b);
$this->voxelizeLine($b, $c);
$this->voxelizeLine($c, $a);
Expand Down Expand Up @@ -333,27 +334,24 @@ private function voxelizeTriangle(Point $a, Point $b, Point $c, int $voxelSize,
);

$data = [];
for ($y = $bbMin->y; $y <= $bbMax->y; $y++) {
for ($x = $bbMin->x; $x <= $bbMax->x; $x++) {
for ($z = $bbMin->z; $z <= $bbMax->z; $z++) {
if (!isset($this->voxels["$x,$y,$z"])) {
continue;
}
foreach ($this->voxels as $voxel) {
if ($matchTriangleSize && ($voxel->x > $bbMax->x || $voxel->y > $bbMax->y || $voxel->z > $bbMax->z)) {
continue;
}

$key = implode(',', [
(int)ceil(($x - $bbMin->x) / $voxelSize),
(int)ceil(($y - $bbMin->y) / $voxelSize),
(int)ceil(($z - $bbMin->z) / $voxelSize),
]);
if (!isset($data[$key])) {
$data[$key] = 0;
}
$data[$key]++;
}
$key = implode(',', [
(int) ceil(($voxel->x - $bbMin->x) / $voxelSize),
(int) ceil(($voxel->y - $bbMin->y) / $voxelSize),
(int) ceil(($voxel->z - $bbMin->z) / $voxelSize),
]);
if (!isset($data[$key])) {
$data[$key] = 0;
}
$data[$key]++;
}

$startPoints = [];
$halfHeight = (int)round($voxelSize / 2);
foreach ($data as $key => $hits) {
if ($hits < $voxelThreshold) {
continue;
Expand All @@ -362,7 +360,7 @@ private function voxelizeTriangle(Point $a, Point $b, Point $c, int $voxelSize,
$sizeIncrements = explode(',', $key);
$startPoints[] = $bbMin->clone()->addPart(
$voxelSize * (int)$sizeIncrements[0],
$voxelSize * (int)$sizeIncrements[1],
$voxelSize * (int)$sizeIncrements[1] - $halfHeight,
$voxelSize * (int)$sizeIncrements[2],
);
}
Expand Down
6 changes: 5 additions & 1 deletion server/src/Core/World.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,24 @@ public function roundReset(): void
}
}

public function loadMap(Map $map): void
public function loadMap(Map $map): int
{
$planeCount = 0;
$this->roundReset();
$this->map = $map;

$this->walls = [];
foreach ($map->getWalls() as $wall) {
$this->addWall($wall);
$planeCount++;
}

$this->floors = [];
foreach ($map->getFloors() as $floor) {
$this->addFloor($floor);
$planeCount++;
}
return $planeCount;
}

public function regenerateNavigationMeshes(): void
Expand Down
Loading