Improved entity destruction handling
This commit is contained in:
parent
edd8a3faa7
commit
4f4e1bec7b
@ -39,10 +39,20 @@ class ComponentManager{
|
||||
* Signals to the ComponentManager the entity was destroyed. All component data references should be removed.
|
||||
* @param entity the entity that was destroyed.
|
||||
*/
|
||||
public void entityDestroyed(Entity entity){
|
||||
for (Type key : componentArrays.keySet()) {
|
||||
componentArrays.get(key).removeData(entity);
|
||||
public void entityDestroyed(Entity entity, BitSet entityRegistrations){
|
||||
// HashMap lookups take time, use the known bitstates
|
||||
int index = entityRegistrations.nextSetBit(0);
|
||||
while(index != -1){
|
||||
if (!componentArrays.get(indexComponentType.get(index)).removeData(entity)){
|
||||
Engine.writeErr(indexComponentType.get(index).getTypeName());
|
||||
}
|
||||
index = entityRegistrations.nextSetBit(index+1);
|
||||
}
|
||||
/*for (Type key : componentArrays.keySet()) {
|
||||
if (!componentArrays.get(key).removeData(entity)){
|
||||
Engine.writeErr(key.getTypeName());
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,8 +76,8 @@ public class Engine {
|
||||
* @param entity the entity to destroy
|
||||
*/
|
||||
public void destroyEntity(Entity entity){
|
||||
componentManager.entityDestroyed(entity, entityManager.getRegistrations(entity));
|
||||
entityManager.removeEntity(entity);
|
||||
componentManager.entityDestroyed(entity);
|
||||
systemManager.entityDestroyed(entity);
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,14 @@ public class Entity {
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (obj instanceof Entity){
|
||||
return (this.getValue() == ((Entity)obj).getValue());
|
||||
}
|
||||
else if (obj instanceof Integer){
|
||||
return (this.value == (Integer)obj);
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode(){
|
||||
|
@ -24,6 +24,7 @@ class SystemManager{
|
||||
* @param entity the destroyed entity
|
||||
*/
|
||||
protected void entityDestroyed(Entity entity){
|
||||
// Unlike components, this isn't simply indexed; makes more sense just to search the systems
|
||||
for (Type key : systems.keySet()) {
|
||||
systems.get(key).entities.remove(entity);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user