when an entity gets a physics flag set, set the same flag in any children

This commit is contained in:
Seth Alves 2015-10-23 09:46:57 -07:00
parent 7f6ac0207d
commit bf290c35be
2 changed files with 39 additions and 10 deletions

View file

@ -1309,17 +1309,40 @@ void EntityItem::computeShapeInfo(ShapeInfo& info) {
info.setParams(getShapeType(), 0.5f * getDimensions());
}
bool EntityItem::forSelfAndEachChildEntity(std::function<bool(EntityItemPointer)> actor) {
bool result = true;
QQueue<SpatiallyNestablePointer> toProcess;
toProcess.enqueue(shared_from_this());
while (!toProcess.empty()) {
EntityItemPointer entity = std::static_pointer_cast<EntityItem>(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;
});
}
}

View file

@ -396,6 +396,8 @@ protected:
const QByteArray getActionDataInternal() const;
void setActionDataInternal(QByteArray actionData);
bool forSelfAndEachChildEntity(std::function<bool(EntityItemPointer)> actor);
static bool _sendPhysicsUpdates;
EntityTypes::EntityType _type;
quint64 _lastSimulated; // last time this entity called simulate(), this includes velocity, angular velocity,