From 1e9fc8d180faaa5289394da89b248d80c732e2c9 Mon Sep 17 00:00:00 2001 From: Brychan Dempsey Date: Thu, 1 Apr 2021 11:19:03 +1300 Subject: [PATCH] Improved root data types --- .../ECS.java | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/javaecs/src/main/java/nz/ac/massey/programming_project_159333_s1_2021/ECS.java b/javaecs/src/main/java/nz/ac/massey/programming_project_159333_s1_2021/ECS.java index fe275d9..b63f839 100644 --- a/javaecs/src/main/java/nz/ac/massey/programming_project_159333_s1_2021/ECS.java +++ b/javaecs/src/main/java/nz/ac/massey/programming_project_159333_s1_2021/ECS.java @@ -3,17 +3,41 @@ * * Contributors: * Brychan Dempsey - brychand@hotmail.com + * + * References: + * https://code.austinmorlan.com/austin/ecs - 'A simple C++ Entity Component System' - released under MIT licence + * */ import java.util.*; public class ECS { - // Entities in an ECS are just a unique integer - List entities = new ArrayList<>(); + // As mentioned by Austin Morlan, a queue is a better choice of data structure for the entity list + // - it allows the first element to be efficiently popped from the list + Queue unusedEntities = new ArrayList<>(); + + // As the entity subscribes (or does not) to a component, we can use a boolean state to represent the subscription + // If we instead store the list of indicies the component is subscribed to, we would use significantly more + // memory space due to the components being defined as a 32-bit integer. + // In a BitSet, each bit is a flag. Therefore we can represent subscription to the first 32 components in the + // same space as one as a 32-bit int. + // + // This list therefore uses the index of the BitSet as its reference to the entity. + List entityRegistrations = new ArrayList<>(); + + // Each component can be assigned to every possible entity. There is a reasonably unlimited number of possible components; + // so therefore we get an array of arrays containing all of a component's data allocations. + // Access is in [componentType][entityNumber] format; getting the data from a subscribed entity is performed like so: + // ()componentDataArrays.get(ComponentIndex).get(Entity); + // Unfortunately, given Java's constraints on dynamic typing (run-time type determination), the returned data must be + // explicitly cast. Therefore, all components must implement the IComponent interface - which mandates the getType() + // function + List> componentDataArrays = new ArrayList<>(); + // Components are either primitive types or class/struct definitions, with an additional list associating // the entities the component is assigned to List components = new ArrayList<>(); - List> componentAssociations = new ArrayList<>(); + // Systems are user-defined functions that are called by the game engine, usually at a regular interval such // as between every render frame. It must be able to find all instances of a specific component, in order // to update/read its data. A component