// protected void EntitySimulation::sortEntitiesThatMoved() { // NOTE: this is only for entities that have been moved by THIS EntitySimulation. // External changes to entity position/shape are expected to be sorted outside of the EntitySimulation. PerformanceTimer perfTimer("sortingEntities"); MovingEntitiesOperator moveOperator(_entityTree); AACube domainBounds(glm::vec3(0.0f,0.0f,0.0f), (float)TREE_SCALE); SetOfEntities::iterator itemItr = _entitiesToSort.begin(); while (itemItr != _entitiesToSort.end()) { EntityItemPointer entity = *itemItr; // check to see if this movement has sent the entity outside of the domain. AACube newCube = entity->getMaximumAACube(); if (!domainBounds.touches(newCube)) { qCDebug(entities) << "Entity " << entity->getEntityItemID() << " moved out of domain bounds."; _entitiesToDelete.insert(entity); _mortalEntities.remove(entity); _entitiesToUpdate.remove(entity); _simpleKinematicEntities.remove(entity); removeEntityInternal(entity); _allEntities.remove(entity); entity->_simulated = false; itemItr = _entitiesToSort.erase(itemItr); } else { moveOperator.addEntityToMoveList(entity, newCube); ++itemItr; } } if (moveOperator.hasMovingEntities()) { PerformanceTimer perfTimer("recurseTreeWithOperator"); _entityTree->recurseTreeWithOperator(&moveOperator); } _entitiesToSort.clear(); }
// protected void EntitySimulation::expireMortalEntities(const quint64& now) { if (now > _nextExpiry) { // only search for expired entities if we expect to find one _nextExpiry = quint64(-1); SetOfEntities::iterator itemItr = _mortalEntities.begin(); while (itemItr != _mortalEntities.end()) { EntityItemPointer entity = *itemItr; quint64 expiry = entity->getExpiry(); if (expiry < now) { _entitiesToDelete.insert(entity); itemItr = _mortalEntities.erase(itemItr); _entitiesToUpdate.remove(entity); _entitiesToSort.remove(entity); _simpleKinematicEntities.remove(entity); removeEntityInternal(entity); _allEntities.remove(entity); entity->_simulated = false; } else { if (expiry < _nextExpiry) { // remeber the smallest _nextExpiry so we know when to start the next search _nextExpiry = expiry; } ++itemItr; } } } }
void ashley::Engine::removeEntity(Entity * const ptr) { if (updating) { pendingRemovalEntities.push_back(ptr); } else { removeEntityInternal(ptr); } }
void EntitySimulation::removeEntity(EntityItem* entity) { assert(entity); _updateableEntities.remove(entity); _mortalEntities.remove(entity); _entitiesToBeSorted.remove(entity); _entitiesToDelete.remove(entity); removeEntityInternal(entity); }
void ashley::Engine::removePendingEntities() { const auto numPending = pendingRemovalEntities.size(); for (size_t i = 0u; i < numPending; i++) { removeEntityInternal(pendingRemovalEntities[i]); } pendingRemovalEntities.clear(); }
void EntitySimulation::prepareEntityForDelete(EntityItemPointer entity) { assert(entity); assert(entity->isDead()); if (entity->isSimulated()) { QMutexLocker lock(&_mutex); entity->clearActions(getThisPointer()); removeEntityInternal(entity); _entitiesToDelete.insert(entity); } }
void EntitySimulation::removeEntity(EntityItemPointer entity) { assert(entity); _entitiesToUpdate.remove(entity); _mortalEntities.remove(entity); _entitiesToSort.remove(entity); _simpleKinematicEntities.remove(entity); _entitiesToDelete.remove(entity); removeEntityInternal(entity); _allEntities.remove(entity); entity->_simulated = false; }
void EntitySimulation::changeEntity(EntityItemPointer entity) { assert(entity); if (!entity->_simulated) { // This entity was either never added to the simulation or has been removed // (probably for pending delete), so we don't want to keep a pointer to it // on any internal lists. return; } // Although it is not the responsibility of the EntitySimulation to sort the tree for EXTERNAL changes // it IS responsibile for triggering deletes for entities that leave the bounds of the domain, hence // we must check for that case here, however we rely on the change event to have set DIRTY_POSITION flag. bool wasRemoved = false; uint32_t dirtyFlags = entity->getDirtyFlags(); if (dirtyFlags & EntityItem::DIRTY_POSITION) { AACube domainBounds(glm::vec3(0.0f,0.0f,0.0f), (float)TREE_SCALE); AACube newCube = entity->getMaximumAACube(); if (!domainBounds.touches(newCube)) { qCDebug(entities) << "Entity " << entity->getEntityItemID() << " moved out of domain bounds."; _entitiesToDelete.insert(entity); _mortalEntities.remove(entity); _entitiesToUpdate.remove(entity); _entitiesToSort.remove(entity); _simpleKinematicEntities.remove(entity); removeEntityInternal(entity); entity->_simulated = false; wasRemoved = true; } } if (!wasRemoved) { if (dirtyFlags & EntityItem::DIRTY_LIFETIME) { if (entity->isMortal()) { _mortalEntities.insert(entity); quint64 expiry = entity->getExpiry(); if (expiry < _nextExpiry) { _nextExpiry = expiry; } } else { _mortalEntities.remove(entity); } entity->clearDirtyFlags(EntityItem::DIRTY_LIFETIME); } if (entity->needsToCallUpdate()) { _entitiesToUpdate.insert(entity); } else { _entitiesToUpdate.remove(entity); } changeEntityInternal(entity); } }
void EntitySimulation::entityChanged(EntityItem* entity) { assert(entity); // Although it is not the responsibility of the EntitySimulation to sort the tree for EXTERNAL changes // it IS responsibile for triggering deletes for entities that leave the bounds of the domain, hence // we must check for that case here, however we rely on the change event to have set DIRTY_POSITION flag. bool wasRemoved = false; uint32_t dirtyFlags = entity->getDirtyFlags(); if (dirtyFlags & EntityItem::DIRTY_POSITION) { AACube domainBounds(glm::vec3(0.0f,0.0f,0.0f), (float)TREE_SCALE); AACube newCube = entity->getMaximumAACube(); if (!domainBounds.touches(newCube)) { qCDebug(entities) << "Entity " << entity->getEntityItemID() << " moved out of domain bounds."; _entitiesToDelete.insert(entity); _mortalEntities.remove(entity); _updateableEntities.remove(entity); removeEntityInternal(entity); wasRemoved = true; } } if (!wasRemoved) { if (dirtyFlags & EntityItem::DIRTY_LIFETIME) { if (entity->isMortal()) { _mortalEntities.insert(entity); quint64 expiry = entity->getExpiry(); if (expiry < _nextExpiry) { _nextExpiry = expiry; } } else { _mortalEntities.remove(entity); } entity->clearDirtyFlags(EntityItem::DIRTY_LIFETIME); } if (entity->needsToCallUpdate()) { _updateableEntities.insert(entity); } else { _updateableEntities.remove(entity); } entityChangedInternal(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(); }
// private void EntitySimulation::expireMortalEntities(const quint64& now) { if (now > _nextExpiry) { // only search for expired entities if we expect to find one _nextExpiry = quint64(-1); QSet<EntityItem*>::iterator itemItr = _mortalEntities.begin(); while (itemItr != _mortalEntities.end()) { EntityItem* entity = *itemItr; quint64 expiry = entity->getExpiry(); if (expiry < now) { _entitiesToDelete.insert(entity); itemItr = _mortalEntities.erase(itemItr); _updateableEntities.remove(entity); _entitiesToBeSorted.remove(entity); removeEntityInternal(entity); } else { if (expiry < _nextExpiry) { // remeber the smallest _nextExpiry so we know when to start the next search _nextExpiry = expiry; } ++itemItr; } } } }
// virtual void PhysicalEntitySimulation::prepareEntityForDelete(EntityItemPointer entity) { assert(entity); assert(entity->isDead()); entity->clearActions(this); removeEntityInternal(entity); }