diff --git a/docs/component/component.md b/docs/component/component.md index b2d08b3..f56d953 100644 --- a/docs/component/component.md +++ b/docs/component/component.md @@ -1,4 +1,4 @@ -*| [JavaECS](../../README.md) | [docs](../overview.md) | component* +*| [JavaECS](../../README.md) | [docs](../overview.md) | [component](./dir.md) | component[]().md* # Component ### Contents diff --git a/docs/component/dir.md b/docs/component/dir.md new file mode 100644 index 0000000..aabceaa --- /dev/null +++ b/docs/component/dir.md @@ -0,0 +1,4 @@ +*| [JavaECS](../README.md) | [docs](../overview.md) | component* +# Overview +### In this folder +[component.md](./component.md) \ No newline at end of file diff --git a/docs/entity/dir.md b/docs/entity/dir.md new file mode 100644 index 0000000..63296e8 --- /dev/null +++ b/docs/entity/dir.md @@ -0,0 +1,4 @@ +*| [JavaECS](../README.md) | [docs](../overview.md) | entity* +# Overview +### In this folder +[entity.md](./entity.md) \ No newline at end of file diff --git a/docs/entity/entity.md b/docs/entity/entity.md index e2cb55a..595849b 100644 --- a/docs/entity/entity.md +++ b/docs/entity/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 ### Contents diff --git a/docs/implementation.md b/docs/implementation.md new file mode 100644 index 0000000..ceff74e --- /dev/null +++ b/docs/implementation.md @@ -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.class.getName()); + gameEngine.registerComponent(ridgidbody.class.getName()); + // Register the system to run on the component + gameEngine.registerSystem("ApplyGravitySystem", () -> { + List 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) diff --git a/docs/overview.md b/docs/overview.md index f108169..783ca38 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -1,7 +1,7 @@ *| [JavaECS](../README.md) | docs* -# Entity -### Contents -[About](#About) +# Overview +### In this folder +[Implementation](./implementation.md) *how to use JavaECS* [Usage](#Usage) @@ -14,3 +14,4 @@ [system](./system/system.md) + diff --git a/docs/system/dir.md b/docs/system/dir.md new file mode 100644 index 0000000..76eac34 --- /dev/null +++ b/docs/system/dir.md @@ -0,0 +1,4 @@ +*| [JavaECS](../README.md) | [docs](../overview.md) | system* +# Overview +### In this folder +[system.md](./system.md) \ No newline at end of file diff --git a/docs/system/system.md b/docs/system/system.md index dfab437..377729d 100644 --- a/docs/system/system.md +++ b/docs/system/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 -### Contents +### 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(){ @@ -44,4 +54,9 @@ class SystemManager{ ## 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 +