void Group::add( const EntityPtr& entity ) { if( !entity ) return; entity->setParent( this ); entities.push_back( entity ); onEntityAdded(entity); onEntityChanged(); }
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::add(anax::Entity &entity) { m_entities.push_back(entity); onEntityAdded(entity); }