diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 46d5635fc5..7c9f3139df 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1309,17 +1309,40 @@ void EntityItem::computeShapeInfo(ShapeInfo& info) { info.setParams(getShapeType(), 0.5f * getDimensions()); } +bool EntityItem::forSelfAndEachChildEntity(std::function actor) { + bool result = true; + QQueue toProcess; + toProcess.enqueue(shared_from_this()); + + while (!toProcess.empty()) { + EntityItemPointer entity = std::static_pointer_cast(toProcess.dequeue()); + + result &= actor(entity); + + foreach (SpatiallyNestablePointer child, entity->getChildren()) { + if (child && child->getNestableType() == NestableTypes::Entity) { + toProcess.enqueue(child); + } + } + } + + return result; +} + void EntityItem::updatePosition(const glm::vec3& value) { if (shouldSuppressLocationEdits()) { return; } auto delta = glm::distance(getLocalPosition(), value); if (delta > IGNORE_POSITION_DELTA) { - _dirtyFlags |= Simulation::DIRTY_POSITION; setLocalPosition(value); - if (delta > ACTIVATION_POSITION_DELTA) { - _dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION; - } + forSelfAndEachChildEntity([&](EntityItemPointer entity) { + entity->_dirtyFlags |= Simulation::DIRTY_POSITION; + if (delta > ACTIVATION_POSITION_DELTA) { + entity->_dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION; + } + return true; + }); } } @@ -1342,12 +1365,16 @@ void EntityItem::updateRotation(const glm::quat& rotation) { setRotation(rotation); auto alignmentDot = glm::abs(glm::dot(getRotation(), rotation)); - if (alignmentDot < IGNORE_ALIGNMENT_DOT) { - _dirtyFlags |= Simulation::DIRTY_ROTATION; - } - if (alignmentDot < ACTIVATION_ALIGNMENT_DOT) { - _dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION; - } + + forSelfAndEachChildEntity([&](EntityItemPointer entity) { + if (alignmentDot < IGNORE_ALIGNMENT_DOT) { + entity->_dirtyFlags |= Simulation::DIRTY_ROTATION; + } + if (alignmentDot < ACTIVATION_ALIGNMENT_DOT) { + entity->_dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION; + } + return true; + }); } } diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 7d6de20a5c..6e03e52679 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -396,6 +396,8 @@ protected: const QByteArray getActionDataInternal() const; void setActionDataInternal(QByteArray actionData); + bool forSelfAndEachChildEntity(std::function actor); + static bool _sendPhysicsUpdates; EntityTypes::EntityType _type; quint64 _lastSimulated; // last time this entity called simulate(), this includes velocity, angular velocity,