Package nz.ac.massey.javaecs
Class ComponentManager
- java.lang.Object
-
- nz.ac.massey.javaecs.ComponentManager
-
public class ComponentManager extends Object
Manages the addition, sorting and retrieving of components and component data
-
-
Constructor Summary
Constructors Constructor Description ComponentManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
addComponentToEntity(Type componentType, Object componentData, Entity entity)
Adds the specified component to the provided entity.void
entityDestroyed(Entity entity, BitSet entityRegistrations)
Signals to the ComponentManager the entity was destroyed.boolean
entityHasComponentData(Entity entity, Type componentType)
Checks if the entity contains data for the provided componentObject
getComponent(Type componentType, Entity entity)
Gets the component data associated with the entityInteger
getComponentIndex(Type type)
Gets the registration index of the component typeType
getComponentType(Integer index)
Gets the type of the component at the provided indexvoid
moveAllComponentData(Entity sourceEntity, Entity destinationEntity, BitSet sourceRegistrations)
Moves all component data from one entity to anotherboolean
moveComponentData(Entity sourceEntity, Entity destinationEntity, Type component)
Moves a single component data from one entity to anotherboolean
registerComponent(Type type)
Registers the component typeboolean
registerComponent(Type type, int arraySize)
Registers the component typeboolean
removeComponentFromEntity(Type componentType, Entity entity)
Removes the specified component from the entity.
-
-
-
Method Detail
-
addComponentToEntity
protected boolean addComponentToEntity(Type componentType, Object componentData, Entity entity)
Adds the specified component to the provided entity.Providing a null Object defaults the value to boolean false
- Parameters:
componentType
- the class type of the component to addcomponentData
- the component data to associateentity
- the entity to associate data to
-
entityDestroyed
public void entityDestroyed(Entity entity, BitSet entityRegistrations)
Signals to the ComponentManager the entity was destroyed. All component data references should be removed.- Parameters:
entity
- the entity that was destroyed.
-
getComponent
public Object getComponent(Type componentType, Entity entity)
Gets the component data associated with the entity- Parameters:
componentType
- the class type of data to look forentity
- the entity to find data for- Returns:
- the Object data found, or null if it was not found
-
getComponentIndex
public Integer getComponentIndex(Type type)
Gets the registration index of the component type- Parameters:
type
- the class type of the component- Returns:
- the index of the component type, or -1 if it isn't found
-
getComponentType
public Type getComponentType(Integer index)
Gets the type of the component at the provided index- Parameters:
index
- the index of the component- Returns:
- the class type of the index. `null` if not found
-
moveComponentData
public boolean moveComponentData(Entity sourceEntity, Entity destinationEntity, Type component)
Moves a single component data from one entity to another- Parameters:
sourceEntity
- the entity to move data fromdestinationEntity
- the entity to move data tocomponent
- the component class type to consider- Returns:
- true if the component was moved successfully, else false
-
moveAllComponentData
public void moveAllComponentData(Entity sourceEntity, Entity destinationEntity, BitSet sourceRegistrations)
Moves all component data from one entity to another- Parameters:
sourceEntity
- the entity to move data fromdestinationEntity
- the entity to move data tosourceRegistrations
- the component registrations of the source entity
-
registerComponent
public boolean registerComponent(Type type)
Registers the component type- Parameters:
type
- the class type to register- Returns:
- true if the component was registered successfully, else false
-
registerComponent
public boolean registerComponent(Type type, int arraySize)
Registers the component type- Parameters:
type
- the class type to registerarraySize
- the number of elements to prereserve space for.- Returns:
- true if the component was registered successfully, else false
-
removeComponentFromEntity
public boolean removeComponentFromEntity(Type componentType, Entity entity)
Removes the specified component from the entity.Be sure to call SystemManager.entityRegistrationsChanged after calling this function
- Parameters:
componentType
- the class type of the component to removeentity
- the entity to remove the component from
-
-