Example #1
0
  private void removeEntityInternal(Entity entity) {
    entities.removeValue(entity, true);

    if (!entity.getFamilyBits().isEmpty()) {
      for (Entry<Family, Array<Entity>> entry : families.entries()) {
        Family family = entry.key;
        Array<Entity> entities = entry.value;

        if (family.matches(entity)) {
          entities.removeValue(entity, true);
          entity.getFamilyBits().clear(family.getIndex());
          notifyFamilyListenersRemove(family, entity);
        }
      }
    }

    entity.componentAdded.remove(componentAdded);
    entity.componentRemoved.remove(componentRemoved);

    Object[] items = listeners.begin();
    for (int i = 0, n = listeners.size; i < n; i++) {
      EntityListener listener = (EntityListener) items[i];
      listener.entityRemoved(entity);
    }
    listeners.end();
  }
Example #2
0
  private void updateFamilyMembership(Entity entity) {
    for (Entry<Family, Array<Entity>> entry : families.entries()) {
      Family family = entry.key;
      Array<Entity> entities = entry.value;
      int familyIndex = family.getIndex();

      boolean belongsToFamily = entity.getFamilyBits().get(familyIndex);
      boolean matches = family.matches(entity);

      if (!belongsToFamily && matches) {
        entities.add(entity);
        entity.getFamilyBits().set(familyIndex);

        notifyFamilyListenersAdd(family, entity);
      } else if (belongsToFamily && !matches) {
        entities.removeValue(entity, true);
        entity.getFamilyBits().clear(familyIndex);

        notifyFamilyListenersRemove(family, entity);
      }
    }
  }
Example #3
0
  private Array<Entity> registerFamily(Family family) {
    Array<Entity> entities = families.get(family);

    if (entities == null) {
      entities = new Array<Entity>(false, 16);
      families.put(family, entities);
      immutableFamilies.put(family, new ImmutableArray<Entity>(entities));

      for (Entity e : this.entities) {
        if (family.matches(e)) {
          entities.add(e);
          e.getFamilyBits().set(family.getIndex());
        }
      }
    }

    return entities;
  }