Skip to content

Commit

Permalink
Clean up Mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Gustafsson committed Jul 6, 2016
1 parent 549be60 commit d3d2eda
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ void applyComponentChanges() {
@SuppressWarnings("unchecked")
Mapper<Component> mapper = (Mapper<Component>) array[i];
Bag<Component> components = mapper.components;
Mask mask = mapper.removeMask;
Mask mask = mapper.remove;
for (int ii = mask.nextSetBit(0); ii != -1; ii = mask.nextSetBit(ii + 1)) {
components.set(ii, null);
}
mapper.componentsMask.andNot(mapper.removeMask);
mapper.componentsMask.andNot(mapper.remove);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ private void flush() {
entityManager.removeQueue.clear();

for (Mapper<?> mapper : componentManager.array) {
mapper.removeMask.set(mapper.removeQueueMask);
mapper.removeMask.or(entityManager.remove);
mapper.removeQueueMask.clear();
mapper.remove.set(mapper.removeQueue);
mapper.remove.or(entityManager.remove);
mapper.removeQueue.clear();
}

familyManager.updateFamilyMembership();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ void updateFamilyMembership() {
for (int component : components) {
Mapper<?> mapper = mappers[component];
tmpMask.set(mapper.componentsMask);
tmpMask.andNot(mapper.removeMask);
tmpMask.andNot(mapper.remove);
matchedEntities.and(tmpMask);
}

int[] excludedComponents = family.excludedComponents;
for (int excludedComponent : excludedComponents) {
Mapper<?> mapper = mappers[excludedComponent];
tmpMask.set(mapper.componentsMask);
tmpMask.andNot(mapper.removeMask);
tmpMask.andNot(mapper.remove);
matchedEntities.andNot(tmpMask);
}

Expand Down
12 changes: 4 additions & 8 deletions retinazer/src/main/java/com/github/antag99/retinazer/Mapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.lang.reflect.InvocationTargetException;

import com.github.antag99.retinazer.util.Bag;
import com.github.antag99.retinazer.util.IntBag;
import com.github.antag99.retinazer.util.Mask;

/**
Expand All @@ -50,12 +49,9 @@ public final class Mapper<T extends Component> {
Mask componentsMask = new Mask();

/** Mask of components that will be removed */
Mask removeMask = new Mask();
Mask remove = new Mask();
/** Mask of components to be removed later */
Mask removeQueueMask = new Mask();

/** Temporary buffer that stores the set bits of removeMask */
IntBag tmpRemove = new IntBag();
Mask removeQueue = new Mask();

Mapper(Engine engine, Class<T> type, int typeIndex) {
this.engine = engine;
Expand Down Expand Up @@ -156,11 +152,11 @@ public void remove(int entity) {
return;
}

if (removeQueueMask.get(entity)) {
if (removeQueue.get(entity)) {
return;
}

engine.dirty = true;
removeQueueMask.set(entity);
removeQueue.set(entity);
}
}

0 comments on commit d3d2eda

Please sign in to comment.