Merge pull request #4227 from huffman/internal-delete-fix

Add force delete to internal EntityTree deletes
This commit is contained in:
Brad Hefta-Gaub 2015-02-04 14:02:34 -08:00
commit 97f888b340
2 changed files with 7 additions and 7 deletions

View file

@ -228,7 +228,7 @@ void EntityTree::setSimulation(EntitySimulation* simulation) {
_simulation = simulation; _simulation = simulation;
} }
void EntityTree::deleteEntity(const EntityItemID& entityID) { void EntityTree::deleteEntity(const EntityItemID& entityID, bool force) {
EntityTreeElement* containingElement = getContainingElement(entityID); EntityTreeElement* containingElement = getContainingElement(entityID);
if (!containingElement) { if (!containingElement) {
qDebug() << "UNEXPECTED!!!! EntityTree::deleteEntity() entityID doesn't exist!!! entityID=" << entityID; qDebug() << "UNEXPECTED!!!! EntityTree::deleteEntity() entityID doesn't exist!!! entityID=" << entityID;
@ -241,7 +241,7 @@ void EntityTree::deleteEntity(const EntityItemID& entityID) {
return; return;
} }
if (existingEntity->getLocked()) { if (existingEntity->getLocked() && !force) {
qDebug() << "ERROR! EntityTree::deleteEntity() trying to delete locked entity. entityID=" << entityID; qDebug() << "ERROR! EntityTree::deleteEntity() trying to delete locked entity. entityID=" << entityID;
return; return;
} }
@ -255,7 +255,7 @@ void EntityTree::deleteEntity(const EntityItemID& entityID) {
_isDirty = true; _isDirty = true;
} }
void EntityTree::deleteEntities(QSet<EntityItemID> entityIDs) { void EntityTree::deleteEntities(QSet<EntityItemID> entityIDs, bool force) {
// NOTE: callers must lock the tree before using this method // NOTE: callers must lock the tree before using this method
DeleteEntityOperator theOperator(this); DeleteEntityOperator theOperator(this);
foreach(const EntityItemID& entityID, entityIDs) { foreach(const EntityItemID& entityID, entityIDs) {
@ -271,7 +271,7 @@ void EntityTree::deleteEntities(QSet<EntityItemID> entityIDs) {
continue; continue;
} }
if (existingEntity->getLocked()) { if (existingEntity->getLocked() && !force) {
qDebug() << "ERROR! EntityTree::deleteEntities() trying to delete locked entity. entityID=" << entityID; qDebug() << "ERROR! EntityTree::deleteEntities() trying to delete locked entity. entityID=" << entityID;
continue; continue;
} }
@ -667,7 +667,7 @@ void EntityTree::update() {
foreach (EntityItem* entity, entitiesToDelete) { foreach (EntityItem* entity, entitiesToDelete) {
idsToDelete.insert(entity->getEntityItemID()); idsToDelete.insert(entity->getEntityItemID());
} }
deleteEntities(idsToDelete); deleteEntities(idsToDelete, true);
} }
unlock(); unlock();
} }

View file

@ -91,8 +91,8 @@ public:
// use this method if you have a pointer to the entity (avoid an extra entity lookup) // use this method if you have a pointer to the entity (avoid an extra entity lookup)
bool updateEntity(EntityItem* entity, const EntityItemProperties& properties); bool updateEntity(EntityItem* entity, const EntityItemProperties& properties);
void deleteEntity(const EntityItemID& entityID); void deleteEntity(const EntityItemID& entityID, bool force = false);
void deleteEntities(QSet<EntityItemID> entityIDs); void deleteEntities(QSet<EntityItemID> entityIDs, bool force = false);
void removeEntityFromSimulation(EntityItem* entity); void removeEntityFromSimulation(EntityItem* entity);
const EntityItem* findClosestEntity(glm::vec3 position, float targetRadius); const EntityItem* findClosestEntity(glm::vec3 position, float targetRadius);