forked from chrisb88/php-ecs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEcs.php
More file actions
124 lines (105 loc) · 2.67 KB
/
Copy pathEcs.php
File metadata and controls
124 lines (105 loc) · 2.67 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
namespace ecs;
use ecs\events\EventManager;
use ecs\events\Receiver;
use ecs\systems\SystemInterface;
use Psr\Log\LoggerInterface;
class Ecs
{
/**
* @var LoggerInterface
*/
private $logger;
/**
* @var EntityManager
*/
private $entityManager;
/**
* @var EventManager
*/
private $eventManager;
/**
* @var SystemManager
*/
private $systemManager;
/**
* Constructor
* @param LoggerInterface $logger
*/
public function __construct(LoggerInterface $logger = null) {
$this->logger = $logger;
$this->eventManager = new EventManager();
$this->entityManager = new EntityManager($this->eventManager);
$this->systemManager = new SystemManager($this->eventManager, $this->entityManager, $this->logger);
}
/**
* Updates all systems.
*/
public function update() {
$this->systemManager->update();
$this->eventManager->deliverDeferredMessages();
}
/**
* @return Entity
*/
public function createEntity() {
return $this->entityManager->createEntity();
}
/**
* @param int $id Entity ID
* @return Entity
* @throws \Exception
*/
public function getEntity($id) {
return $this->entityManager->getEntity($id);
}
/**
* @param int $id Entity ID
*/
public function destroyEntity($id) {
$this->entityManager->destroyEntity($id);
}
/**
* @param Receiver $receiver
* @param string $messageClass
* @return $this
*/
public function subscribe(Receiver $receiver, $messageClass) {
$this->eventManager->subscribe($receiver, $messageClass);
return $this;
}
/**
* @param int $entityId Entity ID
* @param Component $component
* @return $this
*/
public function addComponent($entityId, Component $component) {
$this->getEntity($entityId)->addComponent($component);
return $this;
}
/**
* @param string $className
* @return SystemInterface
*/
public function createSystem($className) {
return $this->systemManager->createSystem($className);
}
/**
* @param SystemInterface $system
* @param int $priority
* @return $this
* @throws \Exception
*/
public function addSystem(SystemInterface $system, $priority = 0) {
$this->systemManager->addSystem($system, $priority);
return $this;
}
/**
* @param string $className
* @return SystemInterface
* @throws \Exception
*/
public function getSystem($className) {
return $this->systemManager->getSystem($className);
}
}