Changed component data handling
Adding empty (null) component data defaults to false Also added getNumEntities() function Added a test for getRegistrationsOutOfRange
This commit is contained in:
parent
0571986059
commit
86ef1e30e3
@ -17,14 +17,22 @@ class ComponentManager{
|
||||
private Map<Type, ComponentArray> componentArrays = new HashMap<>();
|
||||
private Map<Type, Integer> componentPosIndex = new HashMap<>();
|
||||
private Map<Integer, Type> indexComponentType = new HashMap<>();
|
||||
private BitSet ignoreEmpty = new BitSet(); // Ignore empty values when deleting data of the index type.
|
||||
|
||||
/**
|
||||
* Adds the specified component to the provided entity
|
||||
* Adds the specified component to the provided entity.
|
||||
* <p>
|
||||
* Providing a null Object defaults the value to boolean false
|
||||
* @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){
|
||||
if (componentData == null){
|
||||
// In the case of null component data, insert the boolean false
|
||||
// (preserves structure by associating data with a null component)
|
||||
return componentArrays.get(componentType).insertData(entity, false);
|
||||
}
|
||||
return componentArrays.get(componentType).insertData(entity, componentData);
|
||||
}
|
||||
|
||||
|
@ -208,4 +208,8 @@ public class Engine {
|
||||
public SystemManager getSystemManager() {
|
||||
return systemManager;
|
||||
}
|
||||
|
||||
public int getNumEntities(){
|
||||
return entityManager.getNumEntities();
|
||||
}
|
||||
}
|
@ -210,4 +210,8 @@ class EntityManager{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected int getNumEntities(){
|
||||
return maxSize - unusedEntities.size();
|
||||
}
|
||||
}
|
@ -229,6 +229,12 @@ class AppTest {
|
||||
assertFalse(gameEngine.registerSystem(TestSystem.class, new TestSystem()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetRegistrationsOutOfRange(){
|
||||
Entity entity = Entity.asEntity(25);
|
||||
assertEquals(new BitSet(), gameEngine.entityManager.getRegistrations(entity));
|
||||
}
|
||||
|
||||
/**
|
||||
* Establish a simple ECS, with a single system and component
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user