-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVoxelSystem.php
More file actions
75 lines (65 loc) · 2.02 KB
/
Copy pathVoxelSystem.php
File metadata and controls
75 lines (65 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace App\System;
use App\Voxel\ChunkAllocator;
use GL\Math\{GLM, Quat, Vec2, Vec3};
use VISU\ECS\EntitiesInterface;
use VISU\ECS\SystemInterface;
use VISU\Graphics\Camera;
use VISU\Graphics\GLState;
use VISU\Graphics\Rendering\RenderContext;
class VoxelSystem implements SystemInterface
{
private ChunkAllocator $chunkAllocator;
public function __construct(
private GLState $gl,
)
{
$this->chunkAllocator = new ChunkAllocator($gl);
}
/**
* Registers the system, this is where you should register all required components.
*
* @return void
*/
public function register(EntitiesInterface $entities) : void
{
$entities->setSingleton($this->chunkAllocator);
// load the first 2k chunks
// $this->chunkAllocator->renderDistance = 8;
// $this->chunkAllocator->ensureChunksLoaded(0, 0, 0, 4096);
// $this->chunkAllocator->renderDistance = 8;
$this->chunkAllocator->renderDistance = 4;
$this->chunkAllocator->ensureChunksLoaded(0, 0, 0, 4096);
}
/**
* Unregisters the system, this is where you can handle any cleanup.
*
* @return void
*/
public function unregister(EntitiesInterface $entities) : void
{
}
/**
* Updates handler, this is where the game state should be updated.
*
* @return void
*/
public function update(EntitiesInterface $entities) : void
{
$cameraEntity = $entities->first(Camera::class);
$this->chunkAllocator->ensureChunksLoaded(
$cameraEntity->transform->position->x,
$cameraEntity->transform->position->y,
$cameraEntity->transform->position->z
);
}
/**
* Handles rendering of the scene, here you can attach additional render passes,
* modify the render pipeline or customize rendering related data.
*
* @param RenderContext $context
*/
public function render(EntitiesInterface $entities, RenderContext $context) : void
{
}
}