dont do work if not needed

This commit is contained in:
Dante Ruiz 2017-12-05 09:31:35 -08:00
parent 486cdf14d2
commit c58286d371

View file

@ -1606,23 +1606,42 @@ void EntityItem::setParentID(const QUuid& value) {
tree->removeFromChildrenOfAvatars(getThisPointer()); tree->removeFromChildrenOfAvatars(getThisPointer());
} }
bool enableNoBootStrapping = false; uint32_t oldParentNoBootstrapping = 0;
uint32_t newParentNoBootstrapping = 0;
if (!value.isNull() && tree) { if (!value.isNull() && tree) {
EntityItemPointer entity = tree->findEntityByEntityItemID(value); EntityItemPointer entity = tree->findEntityByEntityItemID(value);
if (entity) { if (entity) {
enableNoBootStrapping = (bool)(entity->getDirtyFlags() & Simulation::NO_BOOTSTRAPPING); newParentNoBootstrapping = entity->getDirtyFlags() & Simulation::NO_BOOTSTRAPPING;
} }
} }
enableNoBootStrapping ? markDirtyFlags(Simulation::NO_BOOTSTRAPPING) : clearDirtyFlags(Simulation::NO_BOOTSTRAPPING); if (!oldParentID.isNull() && tree) {
forEachDescendant([&](SpatiallyNestablePointer object) { EntityItemPointer entity = tree->findEntityByEntityItemID(oldParentID);
if (object->getNestableType() == NestableType::Entity) { if (entity) {
EntityItemPointer entity = std::static_pointer_cast<EntityItem>(object); oldParentNoBootstrapping = entity->getDirtyFlags() & Simulation::NO_BOOTSTRAPPING;
entity->markDirtyFlags(Simulation::DIRTY_COLLISION_GROUP);
enableNoBootStrapping ? entity->markDirtyFlags(Simulation::NO_BOOTSTRAPPING) :
entity->clearDirtyFlags(Simulation::NO_BOOTSTRAPPING);
} }
}); }
if ((bool)(oldParentNoBootstrapping ^ newParentNoBootstrapping)) {
if ((bool)(newParentNoBootstrapping & Simulation::NO_BOOTSTRAPPING)) {
markDirtyFlags(Simulation::NO_BOOTSTRAPPING);
forEachDescendant([&](SpatiallyNestablePointer object) {
if (object->getNestableType() == NestableType::Entity) {
EntityItemPointer entity = std::static_pointer_cast<EntityItem>(object);
entity->markDirtyFlags(Simulation::DIRTY_COLLISION_GROUP | Simulation::NO_BOOTSTRAPPING);
}
});
} else {
clearDirtyFlags(Simulation::NO_BOOTSTRAPPING);
forEachDescendant([&](SpatiallyNestablePointer object) {
if (object->getNestableType() == NestableType::Entity) {
EntityItemPointer entity = std::static_pointer_cast<EntityItem>(object);
entity->markDirtyFlags(Simulation::DIRTY_COLLISION_GROUP);
entity->clearDirtyFlags(Simulation::NO_BOOTSTRAPPING);
}
});
}
}
SpatiallyNestable::setParentID(value); SpatiallyNestable::setParentID(value);
// children are forced to be kinematic // children are forced to be kinematic