Skip to content

Commit af4ef6e

Browse files
committed
small fixes
1 parent c9ebe3f commit af4ef6e

12 files changed

Lines changed: 44 additions & 40 deletions

File tree

cli/generateNavmesh.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/////
1313

1414
$game = new Game();
15-
$game->loadMap($map);
15+
$planeCount = $game->loadMap($map);
1616
$tileSize = $game->getWorld()::GRENADE_NAVIGATION_MESH_TILE_SIZE;
1717
$colliderHeight = $game->getWorld()::GRENADE_NAVIGATION_MESH_OBJECT_HEIGHT;
1818

@@ -37,7 +37,8 @@
3737
$path = $map->getNavigationMeshPath($map->generateNavigationMeshKey($tileSize, $colliderHeight));
3838
file_put_contents($path, $pathFinder->getNavigationMesh()->serialize());
3939
printf(
40-
"Navmesh (Nodes: %d; Edges: %d) generated to '%s'%s",
40+
"Navmesh (Planes: %d, Nodes: %d; Edges: %d) generated to '%s'%s",
41+
$planeCount,
4142
$pathFinder->getGraph()->getNodesCount(),
4243
$pathFinder->getGraph()->getEdgeCount(),
4344
$path,

cli/server.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
$debug = in_array('--debug', $argv);
1616
$bindAddress = "udp://0.0.0.0:$port";
1717
$map = Maps\DefaultMap::class;
18+
ini_set('memory_limit', '1G');
1819
/////
1920

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

2526
$game = ($debug ? GameFactory::createDebug() : GameFactory::createDefaultCompetitive());
2627
$game->loadMap(new $map);
28+
$game->getWorld()->regenerateNavigationMeshes();
2729

2830
$logger->info("Starting server on '{$bindAddress}', waiting maximum of '{$settings->warmupWaitSec}' sec for '{$playersMax}' player" . ($playersMax > 1 ? 's' : '') . " to connect.");
2931
$net = new ClueSocket($bindAddress);

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"scripts": {
3-
"post-install-cmd": "@php -d memory_limit=200M cli/generateNavmesh.php",
3+
"post-install-cmd": "@php -d memory_limit=300M cli/generateNavmesh.php",
44
"stan": "@php vendor/bin/phpstan --memory-limit=300M analyze",
55
"unit": "@php vendor/bin/phpunit -d memory_limit=200M",
66
"infection": "@php -d memory_limit=300M vendor/bin/infection --show-mutations --threads=max --min-covered-msi=100",
7-
"dev": "php cli/server.php 1 8080 --debug & php cli/udp-ws-bridge.php",
8-
"dev2": "php cli/server.php 2 8080 --debug & php cli/udp-ws-bridge.php & php cli/udp-ws-bridge.php 8082",
9-
"dev2c": "php cli/server.php 2 8080 --debug & php cli/udp-ws-bridge.php & sleep 2 && php cli/client.php acode 8080",
10-
"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",
7+
"dev": "php cli/server.php 1 8080 --debug & sleep 1 && php cli/udp-ws-bridge.php",
8+
"dev2": "php cli/server.php 2 8080 --debug & sleep 1 && php cli/udp-ws-bridge.php & php cli/udp-ws-bridge.php 8082",
9+
"dev2c": "php cli/server.php 2 8080 --debug & sleep 1 && php cli/udp-ws-bridge.php & php cli/client.php acode 8080",
10+
"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",
1111
"coverage": [
1212
"@putenv XDEBUG_MODE=coverage",
1313
"@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",

server/src/Core/Game.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ public function playersCanBuy(): bool
215215
return ($this->isPaused() || $this->tick <= $this->roundStartTickId + $this->buyTimeTickCount);
216216
}
217217

218-
public function loadMap(Map $map): void
218+
public function loadMap(Map $map): int
219219
{
220220
$this->bomb->setMaxBlastDistance($map->getBombMaxBlastDistance());
221-
$this->world->loadMap($map);
221+
return $this->world->loadMap($map);
222222
}
223223

224224
public function getWorld(): World

server/src/Core/PathFinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function buildNavigationMesh(Point $start, int $objectHeight, int $maxNod
172172
$startPoint = $start->clone();
173173
$this->convertToNavMeshNode($startPoint);
174174
if (!$this->world->findFloorSquare($startPoint, 1)) {
175-
throw new GameException('No floor on start point'); // @codeCoverageIgnore
175+
throw new GameException('No floor on start: ' . $start); // @codeCoverageIgnore
176176
}
177177

178178
/** @var SplQueue<Point> $queue */

server/src/Core/PlaneBuilder.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function create(Point $a, Point $b, Point $c, ?Point $d = null, ?float $j
2222
/** @return list<Plane> */
2323
public function fromTriangle(Point $a, Point $b, Point $c, float $voxelSizeDotThreshold): array
2424
{
25+
$this->voxels = [];
2526
$voxelSize = (int)$voxelSizeDotThreshold;
2627
$voxelThreshold = max(1, intval(str_replace('0.', '', abs($voxelSizeDotThreshold - $voxelSize)))); // @phpstan-ignore argument.type
2728
if ($voxelSize > 0) {
@@ -39,6 +40,7 @@ public function fromTriangle(Point $a, Point $b, Point $c, float $voxelSizeDotTh
3940
$planes[] = (new Wall($voxelPoint->clone()->addX($voxelSize), false, $voxelSize, $voxelSize))->setNormal($this->voxelNormal[0], $this->voxelNormal[1]);
4041
$planes[] = (new Floor($voxelPoint->clone()->addY($voxelSize), $voxelSize, $voxelSize))->setNormal($this->voxelNormal[0], $this->voxelNormal[1]);
4142
}
43+
$this->voxels = [];
4244
return $planes;
4345
}
4446

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

303-
$this->voxels = [];
304305
$this->voxelizeLine($a, $b);
305306
$this->voxelizeLine($b, $c);
306307
$this->voxelizeLine($c, $a);
@@ -333,27 +334,24 @@ private function voxelizeTriangle(Point $a, Point $b, Point $c, int $voxelSize,
333334
);
334335

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

343-
$key = implode(',', [
344-
(int)ceil(($x - $bbMin->x) / $voxelSize),
345-
(int)ceil(($y - $bbMin->y) / $voxelSize),
346-
(int)ceil(($z - $bbMin->z) / $voxelSize),
347-
]);
348-
if (!isset($data[$key])) {
349-
$data[$key] = 0;
350-
}
351-
$data[$key]++;
352-
}
342+
$key = implode(',', [
343+
(int) ceil(($voxel->x - $bbMin->x) / $voxelSize),
344+
(int) ceil(($voxel->y - $bbMin->y) / $voxelSize),
345+
(int) ceil(($voxel->z - $bbMin->z) / $voxelSize),
346+
]);
347+
if (!isset($data[$key])) {
348+
$data[$key] = 0;
353349
}
350+
$data[$key]++;
354351
}
355352

356353
$startPoints = [];
354+
$halfHeight = (int)round($voxelSize / 2);
357355
foreach ($data as $key => $hits) {
358356
if ($hits < $voxelThreshold) {
359357
continue;
@@ -362,7 +360,7 @@ private function voxelizeTriangle(Point $a, Point $b, Point $c, int $voxelSize,
362360
$sizeIncrements = explode(',', $key);
363361
$startPoints[] = $bbMin->clone()->addPart(
364362
$voxelSize * (int)$sizeIncrements[0],
365-
$voxelSize * (int)$sizeIncrements[1],
363+
$voxelSize * (int)$sizeIncrements[1] - $halfHeight,
366364
$voxelSize * (int)$sizeIncrements[2],
367365
);
368366
}

server/src/Core/World.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,24 @@ public function roundReset(): void
6666
}
6767
}
6868

69-
public function loadMap(Map $map): void
69+
public function loadMap(Map $map): int
7070
{
71+
$planeCount = 0;
7172
$this->roundReset();
7273
$this->map = $map;
7374

7475
$this->walls = [];
7576
foreach ($map->getWalls() as $wall) {
7677
$this->addWall($wall);
78+
$planeCount++;
7779
}
7880

7981
$this->floors = [];
8082
foreach ($map->getFloors() as $floor) {
8183
$this->addFloor($floor);
84+
$planeCount++;
8285
}
86+
return $planeCount;
8387
}
8488

8589
public function regenerateNavigationMeshes(): void

test/og/Unit/PlaneBuilderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ public function testTriangleBoundary(): void
119119
max($boundaryMax->z, $plane->getEnd()->z),
120120
);
121121
}
122-
$this->assertPositionSame(new Point(2, 1, 0), $boundaryMin);
123-
$this->assertPositionSame(new Point(12, 11, 22), $boundaryMax);
122+
$this->assertPositionSame(new Point(2, 1 - 1, 0), $boundaryMin);
123+
$this->assertPositionSame(new Point(12, 11 - 1, 22), $boundaryMax);
124124
}
125125

126126
public function testTriangleBoundaryNegative(): void
@@ -149,8 +149,8 @@ public function testTriangleBoundaryNegative(): void
149149
max($boundaryMax->z, $plane->getEnd()->z),
150150
);
151151
}
152-
$this->assertPositionSame(new Point(2, 1, -1), $boundaryMin);
153-
$this->assertPositionSame(new Point(13, 12, 23), $boundaryMax);
152+
$this->assertPositionSame(new Point(2, 1 - 1, -1), $boundaryMin);
153+
$this->assertPositionSame(new Point(13, 12 - 1, 23), $boundaryMax);
154154
}
155155

156156
public function testAABBWallX(): void

www/assets/js/Game.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ export class Game {
673673
this.#world.getCamera().getObjectByName('pov-item').visible = isNotScopedIn
674674
this.#world.updateCameraZoom(Utils.scopeLevelToZoom(scopeLevel))
675675
if (this.meIsAlive()) {
676-
this.#pointer.pointerSpeed = (isNotScopedIn ? this.#setting.getSensitivity() : this.#setting.getInScopeSensitivity())
676+
this.#pointer.pointerSpeed = (isNotScopedIn ? this.#setting.getSensitivity() : this.#setting.getInScopeSensitivity() / scopeLevel)
677677
}
678678
}
679679
}

www/assets/js/ModelRepository.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ export class ModelRepository {
121121
return model.clone()
122122
}
123123

124-
init(mapName, renderer, scene) {
124+
init(scene, renderer, mapName = null) {
125125
const ktx2Loader = new KTX2Loader()
126126
ktx2Loader.setTranscoderPath('assets/threejs/libs/basis/')
127127
ktx2Loader.detectSupport(renderer)
128128
this.#gltfLoader.setKTX2Loader(ktx2Loader)
129129

130130
const self = this
131131
const promises = []
132-
promises.push(this.#loadMap(mapName).then((model) => scene.add(model)))
132+
mapName && promises.push(this.#loadMap(mapName).then((model) => scene.add(model)))
133133

134134
promises.push(this.#loadModel('./resources/model/player.glb').then((model) => {
135135
model.scene.traverse(function (object) {
@@ -254,7 +254,6 @@ export class ModelRepository {
254254
this.#materials.smoke = new THREE.MeshStandardMaterial({ // todo better material with cool displacement map etc.
255255
color: 0x798aa0,
256256
map: texture,
257-
blending: THREE.AdditiveBlending,
258257
side: THREE.FrontSide,
259258
})
260259

0 commit comments

Comments
 (0)