* Maximum 1024 enitites default */ - public ECS(){ + public Engine(){ entityManager = new EntityManager(); componentManager = new ComponentManager(); systemManager = new SystemManager(); @@ -44,7 +44,7 @@ public class ECS { * Initialises the ECS with the specified value * @param maxEntities the maximum number of entities to allow */ - public ECS(int maxEntities){ + public Engine(int maxEntities){ entityManager = new EntityManager(maxEntities); componentManager = new ComponentManager(); systemManager = new SystemManager(); @@ -54,7 +54,7 @@ public class ECS { * /** * Creates a new entity * @return the index of the new entity - * @throws IndexOutOfBoundsException + * @throws IndexOutOfBoundsException if there are no more entities available */ public Entity createEntity() throws IndexOutOfBoundsException{ Entity newEntity = entityManager.addEntity(); @@ -83,7 +83,8 @@ public class ECS { /** * Registers the specified name in the component manager - * @param name the name to register. Should be the component class name or a suitable name for primitive types + * @param type the name to register. Should be the component class name or a suitable name for primitive types + * @return true if the component type was registered successfully */ public boolean registerComponent(Type type){ return componentManager.registerComponent(type); @@ -98,6 +99,7 @@ public class ECS { * @param entity the entity to add the component to * @param componentName the class name of the component to add * @param component the actual component data + * @return true if the compnent was added to the entity */ public boolean addComponent(Entity entity, Type componentName, Object component){ if (entityManager.registerComponent(componentManager.getComponentIndex(componentName), entity)) @@ -112,7 +114,8 @@ public class ECS { /** * Removes the component from the specified entity * @param entity the entity to remove the component from - * @param componentName the class name of the component + * @param componentType the class type of the component + * @return true if the component was removed */ public boolean removeComponent(Entity entity, Type componentType){ if (entityManager.unregisterComponent(componentManager.getComponentIndex(componentType), entity)) @@ -136,8 +139,8 @@ public class ECS { } /** - * - * @param systemName + * Registers the system to + * @param systemType * @param action */ public boolean registerSystem(Type systemType, ECSSystem action){ @@ -197,7 +200,7 @@ public class ECS { public ComponentManager getComponentManager() { return componentManager; } - + public EntityManager getEntityManager() { return entityManager; } 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 1140d4c..93cfd95 100644 --- a/javaecs/src/main/java/nz/ac/massey/javaecs/EntityManager.java +++ b/javaecs/src/main/java/nz/ac/massey/javaecs/EntityManager.java @@ -59,7 +59,7 @@ class EntityManager{ */ protected Entity addEntity(){ if (unusedEntities.size() == 0){ - ECS.writeErr("No available space to create a new entity"); + Engine.writeErr("No available space to create a new entity"); return null; } Entity result = unusedEntities.remove(); @@ -85,7 +85,7 @@ class EntityManager{ return entityRegistrations.get(entity.getValue()); } catch (IndexOutOfBoundsException e){ - ECS.writeErr("Index out of bounds error getting registrations for " + entity.getValue() + ";\nThe entity might not exist"); + Engine.writeErr("Index out of bounds error getting registrations for " + entity.getValue() + ";\nThe entity might not exist"); return new BitSet(); // Using a blank BitSet will retain data safety (that is, no data will be modified) } } @@ -98,12 +98,12 @@ class EntityManager{ */ protected boolean registerComponent(int component, Entity entity){ if (entity.getValue() >= maxSize){ - ECS.writeErr("Attempted to assign a component to non-existent entity: " + entity.getValue()); + Engine.writeErr("Attempted to assign a component to non-existent entity: " + entity.getValue()); return false; } else if (entityRegistrations.get(entity.getValue()).get(component)) { - ECS.writeErr("Entity is already assigned to the component"); + Engine.writeErr("Entity is already assigned to the component"); return false; } else{ @@ -146,7 +146,7 @@ class EntityManager{ return true; } catch (NullPointerException e){ - ECS.writeErr("Entity not initialised"); + Engine.writeErr("Entity not initialised"); return false; } catch (IndexOutOfBoundsException e) @@ -164,11 +164,11 @@ class EntityManager{ */ protected boolean resize(int newSize, SystemManager systemManager, ComponentManager componentManager){ if (newSize < maxSize - unusedEntities.size()){ - ECS.writeErr("Attempted to resize the maximum entity count to a number smaller than the current assigned entity count."); + Engine.writeErr("Attempted to resize the maximum entity count to a number smaller than the current assigned entity count."); return false; } else if (newSize == maxSize){ - ECS.writeErr("Attempted to set the newSize to the current size"); + Engine.writeErr("Attempted to set the newSize to the current size"); return true; } else{ 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 9edd3ce..0b00a35 100644 --- a/javaecs/src/main/java/nz/ac/massey/javaecs/SystemManager.java +++ b/javaecs/src/main/java/nz/ac/massey/javaecs/SystemManager.java @@ -59,7 +59,7 @@ class SystemManager{ */ protected boolean registerSystem(Type systemType, ECSSystem system){ if (systems.containsKey(systemType)){ - ECS.writeErr("System already registered"); + Engine.writeErr("System already registered"); return false; } systems.put(systemType, system); diff --git a/javaecs/src/test/java/nz/ac/massey/javaecs/AppTest.java b/javaecs/src/test/java/nz/ac/massey/javaecs/AppTest.java index 2028840..53ec351 100644 --- a/javaecs/src/test/java/nz/ac/massey/javaecs/AppTest.java +++ b/javaecs/src/test/java/nz/ac/massey/javaecs/AppTest.java @@ -19,7 +19,7 @@ import org.junit.jupiter.api.BeforeEach; */ class AppTest { - ECS gameEngine; + Engine gameEngine; TestSystem system; class TestObject{ @@ -169,7 +169,7 @@ class AppTest { @Test void testEntityManagerConstructor(){ - gameEngine = new ECS(5); + gameEngine = new Engine(5); assertEquals(5, gameEngine.getMaxEntities()); } @@ -189,15 +189,15 @@ class AppTest { @Test void testEqualResize(){ ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - PrintStream orig = ECS.getErr(); + PrintStream orig = Engine.getErr(); PrintStream newErr = new PrintStream(bytes); - ECS.setErr(newErr); + Engine.setErr(newErr); assertTrue(gameEngine.resizeMaximum(1024)); - ECS.setErr(orig); + Engine.setErr(orig); newErr.flush(); // ensure the bytes are recieved byte[] errBytes = bytes.toByteArray(); String result = new String(errBytes); - ECS.writeErr("Captured in redirect: " + result); + Engine.writeErr("Captured in redirect: " + result); assertTrue(result.trim().equals("Attempted to set the newSize to the current size")); } @@ -234,7 +234,7 @@ class AppTest { */ @BeforeEach void testSetup(){ - gameEngine = new ECS(); + gameEngine = new Engine(); gameEngine.registerComponent(TestObject.class); system = new TestSystem();