bool Group::remove( const EntityPtr& entity ) { auto it = std::find(entities.begin(), entities.end(), entity); if( it == entities.end() ) return false; onEntityRemoved(entity); onEntityChanged(); entities.remove(it); return true; }
bool Group::remove( const EntityPtr& entity ) { std::vector<EntityPtr>::iterator it; it = std::find(entities.begin(), entities.end(), entity); if( it == entities.end() ) return false; onEntityRemoved(entity); onEntityChanged(); entities.erase(it); return true; }
void EntityEngine::updateFamilyMembership(shared_ptr<Entity> entity, bool removing) { for (auto entry : systems) { auto system = entry.first; auto& family = system->getComponentFamily(); auto familyEntities = entry.second; auto& familyBits = entity->getFamilyBits(); auto familyIndex = family.getIndex(); bool belongsToFamily = familyBits.test(familyIndex); bool matches = family.matches(entity) && !removing; if (belongsToFamily != matches) { if (matches) { familyEntities->push_back(entity); familyBits.set(familyIndex); system->onEntityAdded(entity); } else { familyEntities->erase(remove(familyEntities->begin(), familyEntities->end(), entity), familyEntities->end()); familyBits.reset(familyIndex); system->onEntityRemoved(entity); } } } for (auto entry : familyEntities) { auto& family = entry.first; auto familyEntities = entry.second; auto& familyBits = entity->getFamilyBits(); auto familyIndex = family.getIndex(); bool belongsToFamily = familyBits.test(familyIndex); bool matches = family.matches(entity) && !removing; if (belongsToFamily != matches) { if (matches) { familyEntities->push_back(entity); familyBits.set(familyIndex); } else { familyEntities->erase(remove(familyEntities->begin(), familyEntities->end(), entity), familyEntities->end()); familyBits.reset(familyIndex); } } } }
void BaseSystem::remove(anax::Entity &entity) { m_entities.erase(std::remove(m_entities.begin(), m_entities.end(), entity), m_entities.end()); onEntityRemoved(entity); }