63 lines
1.6 KiB
Markdown
63 lines
1.6 KiB
Markdown
*| [JavaECS](../../README.md) | [docs](../overview.md) | [system](./dir.md) | system[]().md*
|
|
# System
|
|
|
|
### In this section
|
|
[About](#about)
|
|
|
|
[Implementation](#implementation)
|
|
|
|
[Examples](#examples)
|
|
|
|
[Notes](#notes)
|
|
|
|
|
|
## About
|
|
The system runs operations that must be performed on its assoiciated components.
|
|
|
|
Typically, this is expected to be run every frame, though this is not a strict requirement.
|
|
|
|
A system must implement the Runnable interface (this is a limited case of inheritence in this library)
|
|
|
|
This allows a simpler implementation of any system, and also allows concurrency to be implemented with relative ease.
|
|
|
|
|
|
|
|
|
|
Examples of the `system` include the `health_system`; which reads the value of the entitie's `health` component and ensures h > 0.
|
|
``` java
|
|
void health_system(){
|
|
for (i = 0; i < registeredComponents.size(); i++){
|
|
if (registeredComponents[i].health <= 0){
|
|
registeredComponents[i].dead = true;
|
|
if (registeredComponents[i].isPlayer){
|
|
GameOver();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
```
|
|
## Implementation
|
|
|
|
The systems are managed by the following code:
|
|
|
|
``` java
|
|
class SystemManager{
|
|
ECS baseECS;
|
|
int systemIndex;
|
|
|
|
public SystemManager(ECS baseECS){
|
|
this.baseECS = baseECS;
|
|
systemIndex = 0;
|
|
}
|
|
}
|
|
```
|
|
|
|
## Examples
|
|
|
|
## Notes
|
|
* Each system is represented by a name-index pair, and the action that gets executed every time the system is performed.
|
|
* This is implicitly sequential, but a custom system that performs concurrent actions can be implemented.
|
|
* Care must be taken to ensure all threads are synchronised before the concurrent system finishes its execution
|
|
|
|
|