Set visibilites

This commit is contained in:
Brychan Dempsey 2021-06-09 11:34:14 +12:00
parent 6ada4110e1
commit d021b7815b
3 changed files with 29 additions and 17 deletions

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>nz.ac.massey.javaecs</groupId> <groupId>nz.ac.massey.javaecs</groupId>
<artifactId>javaecs</artifactId> <artifactId>javaecs</artifactId>
<version>1.2-PRERELEASE</version> <version>1.2-PRERELEASE-v2</version>
<properties> <properties>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>

View File

@ -56,7 +56,7 @@ public class ECS {
* @return the index of the new entity * @return the index of the new entity
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
*/ */
Entity createEntity() throws IndexOutOfBoundsException{ public Entity createEntity() throws IndexOutOfBoundsException{
Entity newEntity = entityManager.addEntity(); Entity newEntity = entityManager.addEntity();
if (newEntity == null) throw new IndexOutOfBoundsException("Could not create a new entity"); if (newEntity == null) throw new IndexOutOfBoundsException("Could not create a new entity");
return newEntity; return newEntity;
@ -67,7 +67,7 @@ public class ECS {
* @param newSize the new maximum number of entities * @param newSize the new maximum number of entities
* @return true if the operation succeeded * @return true if the operation succeeded
*/ */
boolean resizeMaximum(int newSize){ public boolean resizeMaximum(int newSize){
return entityManager.resize(newSize, systemManager, componentManager); return entityManager.resize(newSize, systemManager, componentManager);
} }
@ -75,7 +75,7 @@ public class ECS {
* Signals each manager to remove the specified entity * Signals each manager to remove the specified entity
* @param entity the entity to destroy * @param entity the entity to destroy
*/ */
void destroyEntity(Entity entity){ public void destroyEntity(Entity entity){
entityManager.removeEntity(entity); entityManager.removeEntity(entity);
componentManager.entityDestroyed(entity); componentManager.entityDestroyed(entity);
systemManager.entityDestroyed(entity); systemManager.entityDestroyed(entity);
@ -85,11 +85,11 @@ public class ECS {
* Registers the specified name in the component manager * 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 name the name to register. Should be the component class name or a suitable name for primitive types
*/ */
boolean registerComponent(Type type){ public boolean registerComponent(Type type){
return componentManager.registerComponent(type); return componentManager.registerComponent(type);
} }
Integer getComponentIndex(Type type){ public Integer getComponentIndex(Type type){
return componentManager.getComponentIndex(type); return componentManager.getComponentIndex(type);
} }
@ -99,7 +99,7 @@ public class ECS {
* @param componentName the class name of the component to add * @param componentName the class name of the component to add
* @param component the actual component data * @param component the actual component data
*/ */
boolean addComponent(Entity entity, Type componentName, Object component){ public boolean addComponent(Entity entity, Type componentName, Object component){
if (entityManager.registerComponent(componentManager.getComponentIndex(componentName), entity)) if (entityManager.registerComponent(componentManager.getComponentIndex(componentName), entity))
{ {
systemManager.entityRegistrationsChanged(entity, entityManager.getRegistrations(entity)); systemManager.entityRegistrationsChanged(entity, entityManager.getRegistrations(entity));
@ -114,7 +114,7 @@ public class ECS {
* @param entity the entity to remove the component from * @param entity the entity to remove the component from
* @param componentName the class name of the component * @param componentName the class name of the component
*/ */
boolean removeComponent(Entity entity, Type componentType){ public boolean removeComponent(Entity entity, Type componentType){
if (entityManager.unregisterComponent(componentManager.getComponentIndex(componentType), entity)) if (entityManager.unregisterComponent(componentManager.getComponentIndex(componentType), entity))
{ {
componentManager.removeComponentFromEntity(componentType, entity); componentManager.removeComponentFromEntity(componentType, entity);
@ -131,7 +131,7 @@ public class ECS {
* @param componentType the class type of the component * @param componentType the class type of the component
* @return the component data Object associated with the entity * @return the component data Object associated with the entity
*/ */
Object getComponentData(Entity entity, Type componentType){ public Object getComponentData(Entity entity, Type componentType){
return componentManager.getComponent(componentType, entity); return componentManager.getComponent(componentType, entity);
} }
@ -140,7 +140,7 @@ public class ECS {
* @param systemName * @param systemName
* @param action * @param action
*/ */
boolean registerSystem(Type systemType, ECSSystem action){ public boolean registerSystem(Type systemType, ECSSystem action){
return systemManager.registerSystem(systemType, action); return systemManager.registerSystem(systemType, action);
} }
@ -149,10 +149,10 @@ public class ECS {
* @param system the class name of the system to set the signature of * @param system the class name of the system to set the signature of
* @param signature the new signature data * @param signature the new signature data
*/ */
void setSystemSignature(Type system, BitSet signature){ public void setSystemSignature(Type system, BitSet signature){
systemManager.setRegistrationSignature(system, signature); systemManager.setRegistrationSignature(system, signature);
} }
Integer getMaxEntities(){ public Integer getMaxEntities(){
return entityManager.getMaxSize(); return entityManager.getMaxSize();
} }
@ -182,7 +182,7 @@ public class ECS {
* Sets the error PrintStream to the provided PrintStream * Sets the error PrintStream to the provided PrintStream
* @param newErr the PrintStream to set as the write destination * @param newErr the PrintStream to set as the write destination
*/ */
static void setErr(PrintStream newErr){ public static void setErr(PrintStream newErr){
errorStream = newErr; errorStream = newErr;
} }
@ -190,7 +190,19 @@ public class ECS {
* Gets the current error PrintStream * Gets the current error PrintStream
* @return the current PrintStream that errors are written to * @return the current PrintStream that errors are written to
*/ */
static PrintStream getErr(){ public static PrintStream getErr(){
return errorStream; return errorStream;
} }
public ComponentManager getComponentManager() {
return componentManager;
}
public EntityManager getEntityManager() {
return entityManager;
}
public SystemManager getSystemManager() {
return systemManager;
}
} }

View File

@ -15,18 +15,18 @@ package nz.ac.massey.javaecs;
import java.util.Set; import java.util.Set;
import java.util.HashSet; import java.util.HashSet;
abstract class ECSSystem{ public abstract class ECSSystem{
Set<Entity> entities = new HashSet<>(); Set<Entity> entities = new HashSet<>();
/** /**
* Implement additional parameterised init() functions as required. * Implement additional parameterised init() functions as required.
* These should run once, when the system is first initialised. * These should run once, when the system is first initialised.
*/ */
abstract void init(); public abstract void init();
/** /**
* Implement additional parameterised update() functions as required. * Implement additional parameterised update() functions as required.
* These should be run each game loop or otherwise sensible regular interval * These should be run each game loop or otherwise sensible regular interval
*/ */
abstract void update(); public abstract void update();
} }