You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* wip #19
* types and tests working again 🏷️ ✅
* types and tests working again 🏷️ ✅
* feat(queues): engine working with queues
* feat(queues): engine working with queues
* feat(queues): engine working with queues
* feat(queues): tests working again ✅
* feat(queues): get next loop with idealTick
* feat(queues): Updated onTick function
* feat(queues): fix types and change README.md
---------
Co-authored-by: pagoru <pagoru@gmail.com>
@@ -28,54 +28,114 @@ Install the package with npm:
28
28
npm install darker-engine
29
29
```
30
30
31
-
### Code Example
31
+
## Concepts
32
+
33
+
### Action Queue System
34
+
35
+
This engine implements an action queue with three levels of priority: `Priority.HIGH`, `Priority.MEDIUM`, `Priority.LOW`.
36
+
Actions are added to the queue and processed based on their priority.
37
+
38
+
#### Config
39
+
With `Engine.load` config we can specify how many ticks we want per second. By default, is 60
40
+
41
+
```ts
42
+
awaitEngine.load({
43
+
ticksPerSecond: 40,
44
+
})
45
+
```
46
+
47
+
With `Engine.onTick` we can sets a callback function that is run on each iteration of the loop.
48
+
The callback function receives an object with the result of the last processed action, the time (`ms`) the iteration took, and the % usage of the tick.
49
+
50
+
```ts
51
+
Engine.onTick(({usage, ms, status}) => {
52
+
console.log({ms, usage, actionId: status?.id})
53
+
})
54
+
// -> { ms: 2, usage: 0.02, actionId: 1 }
55
+
```
56
+
57
+
#### Add Actions To Queue
58
+
When we use `addEntity`, `removeEntity`, `entity.updateComponent` and `entity.removeComponent` we can specify if we want to perform the action immediately or assign it a priority.
59
+
60
+
By default, they are added to the queue and assigned a medium priority (`Priority.MEDIUM`)
61
+
62
+
```ts
63
+
// Action added to HIGH priority queue
64
+
awaitEngine.addEntity({
65
+
priority: Priority.HIGH,
66
+
entities: [exampleEntity()]
67
+
})
68
+
69
+
// Action that is executed immediately without depending on the queue
0 commit comments