Improved root data types
This commit is contained in:
parent
0c12f8d38b
commit
1e9fc8d180
@ -3,17 +3,41 @@
|
|||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Brychan Dempsey - brychand@hotmail.com
|
* 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.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class ECS {
|
public class ECS {
|
||||||
// Entities in an ECS are just a unique integer
|
// As mentioned by Austin Morlan, a queue is a better choice of data structure for the entity list
|
||||||
List<Integer> entities = new ArrayList<>();
|
// - it allows the first element to be efficiently popped from the list
|
||||||
|
Queue<Integer> 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<BitSet> 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:
|
||||||
|
// (<datatype>)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<List<Object>> componentDataArrays = new ArrayList<>();
|
||||||
|
|
||||||
// Components are either primitive types or class/struct definitions, with an additional list associating
|
// Components are either primitive types or class/struct definitions, with an additional list associating
|
||||||
// the entities the component is assigned to
|
// the entities the component is assigned to
|
||||||
List<Object> components = new ArrayList<>();
|
List<Object> components = new ArrayList<>();
|
||||||
List<List<Object>> componentAssociations = new ArrayList<>();
|
|
||||||
// Systems are user-defined functions that are called by the game engine, usually at a regular interval such
|
// 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
|
// 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
|
// to update/read its data. A component
|
||||||
|
Loading…
x
Reference in New Issue
Block a user