// TODO: optimization - Only interested in the new family void EntityEngine::updateFamilyMembershipAll() { for (auto entity : entities) { updateFamilyMembership(entity); } }
void EntityEngine::processPendingEntityOperations() { for (auto entityOperation : entityOperations) { auto entity = entityOperation->entity; switch (entityOperation->type) { case EntityOperation::ADD: addEntityInternal(entity); updateFamilyMembership(entity); break; case EntityOperation::REMOVE: removeEntityInternal(entity); updateFamilyMembership(entity, true); break; } } entityOperations.clear(); }
ashley::Entity *ashley::Engine::addEntity(std::unique_ptr<Entity> &&ptr) { entities.emplace_back(std::move(ptr)); auto &added = entities.back(); updateFamilyMembership(*added); added->componentAdded.add((Listener<Entity>*) componentAddedListener.get()); added->componentRemoved.add((Listener<Entity>*) componentRemovedListener.get()); added->operationHandler = operationHandler.get(); notifying = true; for (auto &listener : listeners) { listener->entityAdded(*added); } notifying = false; removePendingListeners(); return added.get(); }
void EntityEngine::processPendingComponentOperations() { for (auto componentOperation : componentOperations) { auto entity = componentOperation->entity; auto component = componentOperation->component; auto componentId = componentOperation->componentId; switch (componentOperation->type) { case ComponentOperation::ADD: entity->addInternal(component, componentId); break; case ComponentOperation::REMOVE: entity->removeInternal(componentId); break; } updateFamilyMembership(entity); } componentOperations.clear(); }