Added better navigation, some information
This commit is contained in:
parent
42edfc5c96
commit
bbd5b32368
@ -1,4 +1,4 @@
|
|||||||
*| [JavaECS](../../README.md) | [docs](../overview.md) | component*
|
*| [JavaECS](../../README.md) | [docs](../overview.md) | [component](./dir.md) | component[]().md*
|
||||||
# Component
|
# Component
|
||||||
|
|
||||||
### Contents
|
### Contents
|
||||||
|
4
docs/component/dir.md
Normal file
4
docs/component/dir.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
*| [JavaECS](../README.md) | [docs](../overview.md) | component*
|
||||||
|
# Overview
|
||||||
|
### In this folder
|
||||||
|
[component.md](./component.md)
|
4
docs/entity/dir.md
Normal file
4
docs/entity/dir.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
*| [JavaECS](../README.md) | [docs](../overview.md) | entity*
|
||||||
|
# Overview
|
||||||
|
### In this folder
|
||||||
|
[entity.md](./entity.md)
|
@ -1,4 +1,4 @@
|
|||||||
*| [JavaECS](../../README.md) | [docs](../overview.md) | entity*
|
*| [JavaECS](../../README.md) | [docs](../overview.md) | [entity](./dir.md) | entity[]().md*
|
||||||
# Entity
|
# Entity
|
||||||
|
|
||||||
### Contents
|
### Contents
|
||||||
|
61
docs/implementation.md
Normal file
61
docs/implementation.md
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
*| [JavaECS](../README.md) | [docs](./overview.md) | implementation[]().md*
|
||||||
|
# Implementation
|
||||||
|
### Contents
|
||||||
|
[Steps](#Steps)
|
||||||
|
|
||||||
|
[Example](#example)
|
||||||
|
|
||||||
|
## Steps
|
||||||
|
1. In the application's setup function, create an instance of `ECS`, with a specified maximum number of entity entries.
|
||||||
|
2. Define the component classes, (or associate the primitive types) and register the components.
|
||||||
|
3. Define the systems that interact with the components and register them
|
||||||
|
4. Run the game.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
``` java
|
||||||
|
public static void main(){
|
||||||
|
ECS gameEngine = new ECS(100);
|
||||||
|
// Register the components, with a parameterised type
|
||||||
|
gameEngine.registerComponent<coord>(coord.class.getName());
|
||||||
|
gameEngine.registerComponent<ridgidBody>(ridgidbody.class.getName());
|
||||||
|
// Register the system to run on the component
|
||||||
|
gameEngine.registerSystem("ApplyGravitySystem", () -> {
|
||||||
|
List<Integer> relevantEntities = gameEngine.getEntitiesWithComponent(ridgidBody.class.getName());
|
||||||
|
for (Integer entity : relevantEntities) {
|
||||||
|
coord c = (coord)gameEngine.getComponent(entity, coord.class.getName());
|
||||||
|
ridgidBody r = (ridgidBody)gameEngine.getComponent(entity, ridgidBody.class.getName());
|
||||||
|
c.y -= r.gravity;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Create an acutal game object
|
||||||
|
int someEntity = gameEngine.createEntity();
|
||||||
|
// Assign components to the new game object
|
||||||
|
gameEngine.addComponent(someEntity, coord.class.getName(), new coord());
|
||||||
|
gameEngine.addComponent(someEntity, ridgidBody.class.getName(), new ridgidBody());
|
||||||
|
// Finally, enter into the game loop
|
||||||
|
gameEngine.loop();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class coord{
|
||||||
|
double x = 0.0;
|
||||||
|
double y = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ridgidBody{
|
||||||
|
double gravity = -9.81; // has a default value, unless overridden in the constructor
|
||||||
|
ridgidBody(){}
|
||||||
|
ridgidBody(double gravity){
|
||||||
|
this.gravity = gravity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### See also:
|
||||||
|
[entity](./entity/entity.md)
|
||||||
|
|
||||||
|
[component](./component/component.md)
|
||||||
|
|
||||||
|
[system](./system/system.md)
|
@ -1,7 +1,7 @@
|
|||||||
*| [JavaECS](../README.md) | docs*
|
*| [JavaECS](../README.md) | docs*
|
||||||
# Entity
|
# Overview
|
||||||
### Contents
|
### In this folder
|
||||||
[About](#About)
|
[Implementation](./implementation.md) *how to use JavaECS*
|
||||||
|
|
||||||
[Usage](#Usage)
|
[Usage](#Usage)
|
||||||
|
|
||||||
@ -14,3 +14,4 @@
|
|||||||
|
|
||||||
[system](./system/system.md)
|
[system](./system/system.md)
|
||||||
|
|
||||||
|
|
||||||
|
4
docs/system/dir.md
Normal file
4
docs/system/dir.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
*| [JavaECS](../README.md) | [docs](../overview.md) | system*
|
||||||
|
# Overview
|
||||||
|
### In this folder
|
||||||
|
[system.md](./system.md)
|
@ -1,18 +1,28 @@
|
|||||||
*| [JavaECS](../../README.md) | [docs](../overview.md) | system*
|
*| [JavaECS](../../README.md) | [docs](../overview.md) | [system](./dir.md) | system[]().md*
|
||||||
# System
|
# System
|
||||||
|
|
||||||
### Contents
|
### In this section
|
||||||
[About](#About)
|
[About](#About)
|
||||||
|
|
||||||
[Implementation](#Implementation)
|
[Implementation](#Implementation)
|
||||||
|
|
||||||
[Examples](#Examples)
|
[Examples](#Examples)
|
||||||
|
|
||||||
|
[Notes](#Notes)
|
||||||
|
|
||||||
|
|
||||||
## About
|
## About
|
||||||
The system runs operations that must be performed on its assoiciated components.
|
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.
|
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.
|
Examples of the `system` include the `health_system`; which reads the value of the entitie's `health` component and ensures h > 0.
|
||||||
``` java
|
``` java
|
||||||
void health_system(){
|
void health_system(){
|
||||||
@ -44,4 +54,9 @@ class SystemManager{
|
|||||||
|
|
||||||
## Examples
|
## 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
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user