From 2c96e92a6a32d937bd17b06d93ff555a92ca5555 Mon Sep 17 00:00:00 2001 From: Brychan Dempsey Date: Tue, 15 Jun 2021 17:59:03 +1200 Subject: [PATCH] Changed access modifiers to public Changed access so data may be manually changed, if needed --- .../ac/massey/javaecs/ComponentManager.java | 11 ++++---- .../java/nz/ac/massey/javaecs/ECSSystem.java | 4 +-- .../nz/ac/massey/javaecs/EntityManager.java | 28 +++++++++++-------- .../nz/ac/massey/javaecs/SystemManager.java | 6 ++-- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/javaecs/src/main/java/nz/ac/massey/javaecs/ComponentManager.java b/javaecs/src/main/java/nz/ac/massey/javaecs/ComponentManager.java index 1f06aa1..fcb72f8 100644 --- a/javaecs/src/main/java/nz/ac/massey/javaecs/ComponentManager.java +++ b/javaecs/src/main/java/nz/ac/massey/javaecs/ComponentManager.java @@ -17,21 +17,20 @@ import java.util.HashMap; * Manages the addition, sorting and retrieving of components and component data */ public class ComponentManager{ - private Map> componentArrays = new HashMap<>(); + public Map> componentArrays = new HashMap<>(); // Need to be able to map bit indices and component types - private Map indexComponentType = new HashMap<>(); - private Map componentTypeIndex = new HashMap<>(); + public Map indexComponentType = new HashMap<>(); + public Map componentTypeIndex = new HashMap<>(); // /** * Adds the specified component to the provided entity. - *

- * Providing a null Object defaults the value to boolean false + * Does not ensure synchronisation with the other managers; ensure this is done! * @param componentType the class type of the component to add * @param componentData the component data to associate * @param entity the entity to associate data to */ - protected boolean addComponentToEntity(Type componentType, Object componentData, Entity entity){ + public boolean addComponentToEntity(Type componentType, Object componentData, Entity entity){ componentArrays.get(componentType).put(entity, componentData); return true; } diff --git a/javaecs/src/main/java/nz/ac/massey/javaecs/ECSSystem.java b/javaecs/src/main/java/nz/ac/massey/javaecs/ECSSystem.java index 29e0e7f..1279020 100644 --- a/javaecs/src/main/java/nz/ac/massey/javaecs/ECSSystem.java +++ b/javaecs/src/main/java/nz/ac/massey/javaecs/ECSSystem.java @@ -29,8 +29,8 @@ import java.util.HashSet; * Additional functions can be implemented as required. */ public abstract class ECSSystem{ - protected Set entities = new HashSet<>(); - protected BitSet registrationSet; + public Set entities = new HashSet<>(); + public BitSet registrationSet; public ECSSystem(){ registrationSet = new BitSet(); diff --git a/javaecs/src/main/java/nz/ac/massey/javaecs/EntityManager.java b/javaecs/src/main/java/nz/ac/massey/javaecs/EntityManager.java index b3d5789..8a1d4cd 100644 --- a/javaecs/src/main/java/nz/ac/massey/javaecs/EntityManager.java +++ b/javaecs/src/main/java/nz/ac/massey/javaecs/EntityManager.java @@ -19,15 +19,17 @@ import java.util.ArrayList; * Manages data from the perspective of the entity. *

* I.e. Controls adding and removing entities, and registration and deregistration of components. + *

+ * Do not update values in this class unless you have reviewed the JavaECS source! */ public class EntityManager{ // According to https://stackoverflow.com/questions/12524826/why-should-i-use-deque-over-stack // ArrayDeque is likely faster than a LinkedList, when used in place of one. // We can also supply a size to the constructor of ArrayDeque, which avoids resizing the collection // at initialisation time (took 1.4s vs 1.8s for 1M) - private Deque unusedEntities; - private List entityRegistrations; - private int maxSize = 1024; + public Deque unusedEntities; + public List entityRegistrations; + public int maxSize = 1024; /** * Initialise the EntityManager with the default max size of 1024 @@ -63,7 +65,7 @@ public class EntityManager{ * @return the index of the new entity * @throws NoSuchElementException an exception if there are no more unused entities */ - protected Entity addEntity() throws NoSuchElementException{ + public Entity addEntity() throws NoSuchElementException{ Entity result = unusedEntities.remove(); entityRegistrations.set(result.getValue(), new BitSet()); return result; @@ -105,7 +107,7 @@ public class EntityManager{ * @param entity the entity to register * @return true if the operation was successful */ - protected boolean registerComponent(int component, Entity entity){ + public boolean registerComponent(int component, Entity entity){ if (entity.getValue() >= maxSize){ Engine.writeErr("Attempted to assign a component to non-existent entity: " + entity.getValue()); return false; @@ -124,32 +126,36 @@ public class EntityManager{ /** * Adds the entity index back into unusedEntities, and sets the registrations to null *

- * Does not handle associated data Use the method in ECS to remove entities cleanly + * Does not handle associated data Use the method in ECS to remove entities cleanly, + * or otherwise ensure the component data and systems are updated! * @param entity the entity to remove */ - protected void removeEntity(Entity entity){ + public void removeEntity(Entity entity){ unusedEntities.add(entity); entityRegistrations.set(entity.getValue(), null); } /** - * Sets the entity's registrations to the provided BitSet + * Sets the entity's registrations to the provided BitSet. + *

+ * Does not ensure the systems registrations are updated. * @param entity the entity to set * @param registrations the preset registrations */ - protected void setRegistrations(Entity entity, BitSet registrations){ + public void setRegistrations(Entity entity, BitSet registrations){ entityRegistrations.set(entity.getValue(), registrations); } /** * Unregisters the specified component from the entity *

- * Does not handle component data Use the method in ECS to remove components cleanly + * Does not handle component data Use the method in ECS to remove components cleanly, + * or otherwise ensure the component data and systems are updated! * @param component the component index to remove * @param entity the entity to remove * @return true if successful */ - protected boolean unregisterComponent(int component, Entity entity){ + public boolean unregisterComponent(int component, Entity entity){ try{ entityRegistrations.get(entity.getValue()).clear(component); return true; diff --git a/javaecs/src/main/java/nz/ac/massey/javaecs/SystemManager.java b/javaecs/src/main/java/nz/ac/massey/javaecs/SystemManager.java index cb7ccb4..f3b97a5 100644 --- a/javaecs/src/main/java/nz/ac/massey/javaecs/SystemManager.java +++ b/javaecs/src/main/java/nz/ac/massey/javaecs/SystemManager.java @@ -17,16 +17,18 @@ import java.util.HashMap; /** * Manages system-focused aspects, such as ensuring a system has the correct list of current entities. * Manages registration of new systems + *

+ * Do not update data in this class unless you have reviewed the JavaECS source. */ public class SystemManager{ - private Map systems = new HashMap<>(); + public Map systems = new HashMap<>(); /** * Signals the SystemManager that an entity was destroyed. * Removes the entity from each system's tracked entities * @param entity the destroyed entity */ - protected void entityDestroyed(Entity entity){ + public void entityDestroyed(Entity entity){ // Unlike components, this isn't simply indexed. for (Type key : systems.keySet()) { systems.get(key).entities.remove(entity);