Skip to content

Commit

Permalink
Marking entities about to be removed, avoiding multiple removal
Browse files Browse the repository at this point in the history
  • Loading branch information
Lusito committed Oct 28, 2014
1 parent ad99d23 commit 1c861a2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ashley/src/com/badlogic/ashley/core/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ public void addEntity(Entity entity){
*/
public void removeEntity(Entity entity){
if (updating || notifying) {
if(entity.scheduledForRemoval) {
return;
}
entity.scheduledForRemoval = true;
EntityOperation operation = entityOperationPool.obtain();
operation.entity = entity;
operation.type = EntityOperation.Type.Remove;
Expand Down Expand Up @@ -273,6 +277,7 @@ else if (belongsToFamily && !matches) {
}

protected void removeEntityInternal(Entity entity) {
entity.scheduledForRemoval = false;
entities.removeValue(entity, true);

if(!entity.getFamilyBits().isEmpty()){
Expand Down
8 changes: 8 additions & 0 deletions ashley/src/com/badlogic/ashley/core/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class Entity {
private Bits componentBits;
/** A Bits describing all the systems this entity was matched with. */
private Bits familyBits;
boolean scheduledForRemoval;

ComponentOperationHandler componentOperationHandler;

Expand Down Expand Up @@ -239,4 +240,11 @@ public boolean equals(Object obj) {
static long obtainId() {
return nextId++;
}

/**
* @return true if the entity is scheduled to be removed
*/
public boolean isScheduledForRemoval() {
return scheduledForRemoval;
}
}
1 change: 1 addition & 0 deletions ashley/src/com/badlogic/ashley/core/PooledEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public void reset() {
flags = 0;
componentAdded.removeAllListeners();
componentRemoved.removeAllListeners();
scheduledForRemoval = false;
}
}

Expand Down

0 comments on commit 1c861a2

Please sign in to comment.