Package nz.ac.massey.javaecs
Class Engine
- java.lang.Object
-
- nz.ac.massey.javaecs.Engine
-
public class Engine extends Object
The ECS management engine. Supplemented by the EntityManager, ComponentManager, and System Manager These four classes provide the actual functionality of the ecsSee https://git.software.kauripeak.co.nz/BrychanD/JavaECS for documentation and more information.
-
-
Field Summary
Fields Modifier and Type Field Description protected nz.ac.massey.javaecs.ComponentManager
componentManager
protected nz.ac.massey.javaecs.EntityManager
entityManager
protected static PrintStream
errorStream
protected nz.ac.massey.javaecs.SystemManager
systemManager
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addComponent(Entity entity, Type componentType, Object component)
Adds an exisiting component to an exisiting entityEntity
createEntity()
Create a new Entity (dequeues the first element from unusedEntities)void
destroyEntity(Entity entity)
Signals each manager to remove the specified entityboolean
entityHasComponent(Entity entity, Type componentType)
Checks if the entity is subscribed to the provided typeObject
getComponentData(Entity entity, Type componentType)
Gets the actual data of the component associated to the entity.Integer
getComponentIndex(Type type)
Gets the component index of the provided typenz.ac.massey.javaecs.ComponentManager
getComponentManager()
Gets a the current component managernz.ac.massey.javaecs.EntityManager
getEntityManager()
Gets a the current enitity managerstatic PrintStream
getErr()
Gets the current error PrintStreamInteger
getMaxEntities()
Gets the set maximum number of entitiesint
getNumEntities()
Gets the current number of entitiesnz.ac.massey.javaecs.SystemManager
getSystemManager()
Gets a the current systems managerboolean
registerComponent(Type type)
Registers the specified name in the component managerboolean
registerSystem(Type systemType, ECSSystem instance)
Registers the system to the SystemManagerboolean
removeComponent(Entity entity, Type componentType)
Removes the component from the specified entityboolean
resizeMaximum(int newSize)
Attempts to resize the maximum number of entitiesstatic void
setErr(PrintStream newErr)
Sets the error PrintStream to the provided PrintStreamvoid
setSystemSignature(Type system, BitSet signature)
Sets the specified system's signature to the provided signature
-
-
-
Field Detail
-
errorStream
protected static PrintStream errorStream
-
entityManager
protected nz.ac.massey.javaecs.EntityManager entityManager
-
componentManager
protected nz.ac.massey.javaecs.ComponentManager componentManager
-
systemManager
protected nz.ac.massey.javaecs.SystemManager systemManager
-
-
Method Detail
-
resizeMaximum
public boolean resizeMaximum(int newSize)
Attempts to resize the maximum number of entities- Parameters:
newSize
- the new maximum number of entities- Returns:
- true if the operation succeeded
-
createEntity
public Entity createEntity() throws NoSuchElementException
Create a new Entity (dequeues the first element from unusedEntities)- Returns:
- the next unused Entity, now set to used
- Throws:
NoSuchElementException
- if there are no more entities available
-
destroyEntity
public void destroyEntity(Entity entity)
Signals each manager to remove the specified entity- Parameters:
entity
- the entity to destroy
-
getMaxEntities
public Integer getMaxEntities()
Gets the set maximum number of entities- Returns:
- an integer of the maximum number of entities
-
getNumEntities
public int getNumEntities()
Gets the current number of entities- Returns:
- the number of currently active entities
-
entityHasComponent
public boolean entityHasComponent(Entity entity, Type componentType)
Checks if the entity is subscribed to the provided type- Parameters:
entity
- the entity to searchcomponentType
- the class type of the component to search- Returns:
- true if the entity is subscribed
-
registerComponent
public boolean registerComponent(Type type)
Registers the specified name in the component manager- Parameters:
type
- the name to register. Should be the component class name or a suitable name for primitive types- Returns:
- true if the component type was registered successfully
-
addComponent
public boolean addComponent(Entity entity, Type componentType, Object component)
Adds an exisiting component to an exisiting entity- Parameters:
entity
- the entity to add the component tocomponentType
- the class name of the component to addcomponent
- the actual component data- Returns:
- true if the compnent was added to the entity
-
removeComponent
public boolean removeComponent(Entity entity, Type componentType)
Removes the component from the specified entity- Parameters:
entity
- the entity to remove the component fromcomponentType
- the class type of the component- Returns:
- true if the component was removed
-
getComponentData
public Object getComponentData(Entity entity, Type componentType)
Gets the actual data of the component associated to the entity. Requires casting from Object to the known data type- Parameters:
entity
- the entity to retrieve the data forcomponentType
- the class type of the component- Returns:
- the component data Object associated with the entity
-
getComponentIndex
public Integer getComponentIndex(Type type)
Gets the component index of the provided type- Parameters:
type
- the type to get the index of- Returns:
- the index of the component
-
registerSystem
public boolean registerSystem(Type systemType, ECSSystem instance)
Registers the system to the SystemManager- Parameters:
systemType
- the type of the systeminstance
- the instance of the system- Returns:
- true if successful
-
setSystemSignature
public void setSystemSignature(Type system, BitSet signature)
Sets the specified system's signature to the provided signature- Parameters:
system
- the class name of the system to set the signature ofsignature
- the new signature data
-
setErr
public static void setErr(PrintStream newErr)
Sets the error PrintStream to the provided PrintStream- Parameters:
newErr
- the PrintStream to set as the write destination
-
getErr
public static PrintStream getErr()
Gets the current error PrintStream- Returns:
- the current PrintStream that errors are written to
-
getComponentManager
public nz.ac.massey.javaecs.ComponentManager getComponentManager()
Gets a the current component manager- Returns:
- the current active component manager
-
getEntityManager
public nz.ac.massey.javaecs.EntityManager getEntityManager()
Gets a the current enitity manager- Returns:
- the current active enitity manager
-
getSystemManager
public nz.ac.massey.javaecs.SystemManager getSystemManager()
Gets a the current systems manager- Returns:
- the current active systems manager
-
-