From 4f4c6e4c5e729c90bee24c813efbc1e76bdca470 Mon Sep 17 00:00:00 2001 From: Brychan Dempsey Date: Thu, 3 Jun 2021 13:25:17 +1200 Subject: [PATCH] Added ECS docs --- docs/component/component.md | 49 +++++++++++++++++++++++++++++++++++++ docs/entity/entity.md | 37 ++++++++++++++++++++++++++++ docs/system/system.md | 24 ++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 docs/component/component.md create mode 100644 docs/entity/entity.md create mode 100644 docs/system/system.md diff --git a/docs/component/component.md b/docs/component/component.md new file mode 100644 index 0000000..d74d33d --- /dev/null +++ b/docs/component/component.md @@ -0,0 +1,49 @@ +# Component +### Contents +[About](#About) + +## About +Components are raw data that gets associated with an entity. + +For an Object-Oriented language like Java, they are objects. + +Each component is an array of objects, containing the data that should be associated with the entity. + +E.g.: A position component is defined such as: +``` java +class position{ + double x = 0.0; + double y = 0.0; +} +``` + +
+ +As the component is simply an object, the associated data can be anything, including scripts: +``` java +class script{ + String statement = ""; + Function foo = () -> { + statement += "boo"; + }; +} +``` + +
+
+ +Two different usages of this data can then be applied: +1. System-less data usage - which stores data but does not have a system that interacts with it every frame + +and + +2. System-based interaction - which utilises the current data (of one or more components) to check if certain conditions have been met. + +I.e.: + +The `position` component might not have a `position_system`, but may be utilised by the `collision_system`, which may use `position.x` and `position.y` to determine the location of the entity. + +See [System](./system/system.md) for more information. + + + diff --git a/docs/entity/entity.md b/docs/entity/entity.md new file mode 100644 index 0000000..bd4afda --- /dev/null +++ b/docs/entity/entity.md @@ -0,0 +1,37 @@ +# Entity +### Contents +[About](#About) + +[Usage](#Usage) + +[Notes](#Notes) + +## About +An 'entity' is a unique ID. + +For most implementations, it makes sense to use a simple integer value - usually in a packed array (*reuses the most minimal value it can*) + +E.g.: The ID 101 would be the next selected value for a new entity. + +>100 | 101 | 102| 103| 104| ...| +>:----:|:-----:|:----:|:----:|:----:|:----| +>used|unused|used|used| unused| .... +
+ +**This ID represents a specific instance of a game object** + +e.g. character, vehicle, effect etc. + +___An entity contains no further data.___ + +In order to be useful, its identifier must be registered to one or more [components](./component/component.md). + +## Usage +*some specific usage info here* +``` java +void todo(); +``` + +## Notes +* The only requirement for a Entity is that it has a unique ID. An [entity manager](./manager/entity_manager.md) could implement a more complex ID system such as using a packed array for only a small region of IDs, or using named IDs by use of a dictionary or ordered hash-map +* The maximum number of entities is limited by the size of the container used to store it. E.g., for a 32-bit unsigned integer, there are ~4.3 billion ID's available. But keep in mind that such a large amount of IDs will take significant time for each system to consider. diff --git a/docs/system/system.md b/docs/system/system.md new file mode 100644 index 0000000..7ef9fe1 --- /dev/null +++ b/docs/system/system.md @@ -0,0 +1,24 @@ +# System +### Contents +[About](#About) + +## 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. + +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(); + } + } + } +} +``` + +