Merge pull request #11633 from sethalves/pr-11581-for-rc-57

Pr 11581 for rc 57
This commit is contained in:
Seth Alves 2017-10-20 09:00:08 -07:00 committed by GitHub
commit f8a01dffb0
10 changed files with 176 additions and 182 deletions

View file

@ -587,7 +587,7 @@ void MyAvatar::simulate(float deltaTime) {
MovingEntitiesOperator moveOperator; MovingEntitiesOperator moveOperator;
forEachDescendant([&](SpatiallyNestablePointer object) { forEachDescendant([&](SpatiallyNestablePointer object) {
// if the queryBox has changed, tell the entity-server // if the queryBox has changed, tell the entity-server
if (object->getNestableType() == NestableType::Entity && object->checkAndMaybeUpdateQueryAACube()) { if (object->getNestableType() == NestableType::Entity && object->updateQueryAACube()) {
EntityItemPointer entity = std::static_pointer_cast<EntityItem>(object); EntityItemPointer entity = std::static_pointer_cast<EntityItem>(object);
bool success; bool success;
AACube newCube = entity->getQueryAACube(success); AACube newCube = entity->getQueryAACube(success);

View file

@ -69,7 +69,7 @@ ParticleEffectEntityRenderer::ParticleEffectEntityRenderer(const EntityItemPoint
} }
bool ParticleEffectEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const { bool ParticleEffectEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const {
entity->checkAndMaybeUpdateQueryAACube(); entity->updateQueryAACube();
if (_emitting != entity->getIsEmitting()) { if (_emitting != entity->getIsEmitting()) {
return true; return true;

View file

@ -717,6 +717,14 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
weOwnSimulation = _simulationOwner.matchesValidID(myNodeID); weOwnSimulation = _simulationOwner.matchesValidID(myNodeID);
} }
} }
auto lastEdited = lastEditedFromBufferAdjusted;
bool otherOverwrites = overwriteLocalData && !weOwnSimulation;
auto shouldUpdate = [lastEdited, otherOverwrites, filterRejection](quint64 updatedTimestamp, bool valueChanged) {
bool simulationChanged = lastEdited > updatedTimestamp;
return otherOverwrites && simulationChanged && (valueChanged || filterRejection);
};
{ // When we own the simulation we don't accept updates to the entity's transform/velocities { // When we own the simulation we don't accept updates to the entity's transform/velocities
// we also want to ignore any duplicate packets that have the same "recently updated" values // we also want to ignore any duplicate packets that have the same "recently updated" values
// as a packet we've already recieved. This is because we want multiple edits of the same // as a packet we've already recieved. This is because we want multiple edits of the same
@ -729,15 +737,9 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
// Note: duplicate packets are expected and not wrong. They may be sent for any number of // Note: duplicate packets are expected and not wrong. They may be sent for any number of
// reasons and the contract is that the client handles them in an idempotent manner. // reasons and the contract is that the client handles them in an idempotent manner.
auto lastEdited = lastEditedFromBufferAdjusted;
bool otherOverwrites = overwriteLocalData && !weOwnSimulation;
auto shouldUpdate = [lastEdited, otherOverwrites, filterRejection](quint64 updatedTimestamp, bool valueChanged) {
bool simulationChanged = lastEdited > updatedTimestamp;
return otherOverwrites && simulationChanged && (valueChanged || filterRejection);
};
auto customUpdatePositionFromNetwork = [this, shouldUpdate, lastEdited](glm::vec3 value){ auto customUpdatePositionFromNetwork = [this, shouldUpdate, lastEdited](glm::vec3 value){
if (shouldUpdate(_lastUpdatedPositionTimestamp, value != _lastUpdatedPositionValue)) { if (shouldUpdate(_lastUpdatedPositionTimestamp, value != _lastUpdatedPositionValue)) {
updatePositionFromNetwork(value); updatePosition(value);
_lastUpdatedPositionTimestamp = lastEdited; _lastUpdatedPositionTimestamp = lastEdited;
_lastUpdatedPositionValue = value; _lastUpdatedPositionValue = value;
} }
@ -745,7 +747,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
auto customUpdateRotationFromNetwork = [this, shouldUpdate, lastEdited](glm::quat value){ auto customUpdateRotationFromNetwork = [this, shouldUpdate, lastEdited](glm::quat value){
if (shouldUpdate(_lastUpdatedRotationTimestamp, value != _lastUpdatedRotationValue)) { if (shouldUpdate(_lastUpdatedRotationTimestamp, value != _lastUpdatedRotationValue)) {
updateRotationFromNetwork(value); updateRotation(value);
_lastUpdatedRotationTimestamp = lastEdited; _lastUpdatedRotationTimestamp = lastEdited;
_lastUpdatedRotationValue = value; _lastUpdatedRotationValue = value;
} }
@ -753,7 +755,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
auto customUpdateVelocityFromNetwork = [this, shouldUpdate, lastEdited](glm::vec3 value){ auto customUpdateVelocityFromNetwork = [this, shouldUpdate, lastEdited](glm::vec3 value){
if (shouldUpdate(_lastUpdatedVelocityTimestamp, value != _lastUpdatedVelocityValue)) { if (shouldUpdate(_lastUpdatedVelocityTimestamp, value != _lastUpdatedVelocityValue)) {
updateVelocityFromNetwork(value); updateVelocity(value);
_lastUpdatedVelocityTimestamp = lastEdited; _lastUpdatedVelocityTimestamp = lastEdited;
_lastUpdatedVelocityValue = value; _lastUpdatedVelocityValue = value;
} }
@ -761,7 +763,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
auto customUpdateAngularVelocityFromNetwork = [this, shouldUpdate, lastEdited](glm::vec3 value){ auto customUpdateAngularVelocityFromNetwork = [this, shouldUpdate, lastEdited](glm::vec3 value){
if (shouldUpdate(_lastUpdatedAngularVelocityTimestamp, value != _lastUpdatedAngularVelocityValue)) { if (shouldUpdate(_lastUpdatedAngularVelocityTimestamp, value != _lastUpdatedAngularVelocityValue)) {
updateAngularVelocityFromNetwork(value); updateAngularVelocity(value);
_lastUpdatedAngularVelocityTimestamp = lastEdited; _lastUpdatedAngularVelocityTimestamp = lastEdited;
_lastUpdatedAngularVelocityValue = value; _lastUpdatedAngularVelocityValue = value;
} }
@ -780,8 +782,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
READ_ENTITY_PROPERTY(PROP_VELOCITY, glm::vec3, customUpdateVelocityFromNetwork); READ_ENTITY_PROPERTY(PROP_VELOCITY, glm::vec3, customUpdateVelocityFromNetwork);
READ_ENTITY_PROPERTY(PROP_ANGULAR_VELOCITY, glm::vec3, customUpdateAngularVelocityFromNetwork); READ_ENTITY_PROPERTY(PROP_ANGULAR_VELOCITY, glm::vec3, customUpdateAngularVelocityFromNetwork);
READ_ENTITY_PROPERTY(PROP_ACCELERATION, glm::vec3, customSetAcceleration); READ_ENTITY_PROPERTY(PROP_ACCELERATION, glm::vec3, customSetAcceleration);
} }
READ_ENTITY_PROPERTY(PROP_DIMENSIONS, glm::vec3, updateDimensions); READ_ENTITY_PROPERTY(PROP_DIMENSIONS, glm::vec3, updateDimensions);
@ -846,7 +846,18 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
overwriteLocalData = oldOverwrite; overwriteLocalData = oldOverwrite;
} }
READ_ENTITY_PROPERTY(PROP_QUERY_AA_CUBE, AACube, setQueryAACube);
{
auto customUpdateQueryAACubeFromNetwork = [this, shouldUpdate, lastEdited](AACube value){
if (shouldUpdate(_lastUpdatedQueryAACubeTimestamp, value != _lastUpdatedQueryAACubeValue)) {
setQueryAACube(value);
_lastUpdatedQueryAACubeTimestamp = lastEdited;
_lastUpdatedQueryAACubeValue = value;
}
};
READ_ENTITY_PROPERTY(PROP_QUERY_AA_CUBE, AACube, customUpdateQueryAACubeFromNetwork);
}
READ_ENTITY_PROPERTY(PROP_LAST_EDITED_BY, QUuid, setLastEditedBy); READ_ENTITY_PROPERTY(PROP_LAST_EDITED_BY, QUuid, setLastEditedBy);
bytesRead += readEntitySubclassDataFromBuffer(dataAt, (bytesLeftToRead - bytesRead), args, bytesRead += readEntitySubclassDataFromBuffer(dataAt, (bytesLeftToRead - bytesRead), args,
@ -1381,8 +1392,7 @@ bool EntityItem::setProperties(const EntityItemProperties& properties) {
SET_ENTITY_PROPERTY_FROM_PROPERTIES(lastEditedBy, setLastEditedBy); SET_ENTITY_PROPERTY_FROM_PROPERTIES(lastEditedBy, setLastEditedBy);
AACube saveQueryAACube = _queryAACube; if (updateQueryAACube()) {
if (checkAndMaybeUpdateQueryAACube() && saveQueryAACube != _queryAACube) {
somethingChanged = true; somethingChanged = true;
} }
@ -1546,6 +1556,9 @@ AACube EntityItem::getQueryAACube(bool& success) const {
return result; return result;
} }
bool EntityItem::shouldPuffQueryAACube() const {
return hasActions() || isChildOfMyAvatar() || isMovingRelativeToParent();
}
// NOTE: This should only be used in cases of old bitstreams which only contain radius data // NOTE: This should only be used in cases of old bitstreams which only contain radius data
// 0,0,0 --> maxDimension,maxDimension,maxDimension // 0,0,0 --> maxDimension,maxDimension,maxDimension
@ -1750,16 +1763,10 @@ void EntityItem::updateParentID(const QUuid& value) {
if (tree) { if (tree) {
tree->addToNeedsParentFixupList(getThisPointer()); tree->addToNeedsParentFixupList(getThisPointer());
} }
updateQueryAACube();
} }
} }
void EntityItem::updatePositionFromNetwork(const glm::vec3& value) {
if (shouldSuppressLocationEdits()) {
return;
}
updatePosition(value);
}
void EntityItem::updateDimensions(const glm::vec3& value) { void EntityItem::updateDimensions(const glm::vec3& value) {
if (getDimensions() != value) { if (getDimensions() != value) {
setDimensions(value); setDimensions(value);
@ -1782,13 +1789,6 @@ void EntityItem::updateRotation(const glm::quat& rotation) {
} }
} }
void EntityItem::updateRotationFromNetwork(const glm::quat& rotation) {
if (shouldSuppressLocationEdits()) {
return;
}
updateRotation(rotation);
}
void EntityItem::updateMass(float mass) { void EntityItem::updateMass(float mass) {
// Setting the mass actually changes the _density (at fixed volume), however // Setting the mass actually changes the _density (at fixed volume), however
// we must protect the density range to help maintain stability of physics simulation // we must protect the density range to help maintain stability of physics simulation
@ -1839,13 +1839,6 @@ void EntityItem::updateVelocity(const glm::vec3& value) {
} }
} }
void EntityItem::updateVelocityFromNetwork(const glm::vec3& value) {
if (shouldSuppressLocationEdits()) {
return;
}
updateVelocity(value);
}
void EntityItem::updateDamping(float value) { void EntityItem::updateDamping(float value) {
auto clampedDamping = glm::clamp(value, 0.0f, 1.0f); auto clampedDamping = glm::clamp(value, 0.0f, 1.0f);
if (_damping != clampedDamping) { if (_damping != clampedDamping) {
@ -1897,13 +1890,6 @@ void EntityItem::updateAngularVelocity(const glm::vec3& value) {
} }
} }
void EntityItem::updateAngularVelocityFromNetwork(const glm::vec3& value) {
if (shouldSuppressLocationEdits()) {
return;
}
updateAngularVelocity(value);
}
void EntityItem::updateAngularDamping(float value) { void EntityItem::updateAngularDamping(float value) {
auto clampedDamping = glm::clamp(value, 0.0f, 1.0f); auto clampedDamping = glm::clamp(value, 0.0f, 1.0f);
if (_angularDamping != clampedDamping) { if (_angularDamping != clampedDamping) {
@ -2016,9 +2002,7 @@ void EntityItem::computeCollisionGroupAndFinalMask(int16_t& group, int16_t& mask
// if this entity is a descendant of MyAvatar, don't collide with MyAvatar. This avoids the // if this entity is a descendant of MyAvatar, don't collide with MyAvatar. This avoids the
// "bootstrapping" problem where you can shoot yourself across the room by grabbing something // "bootstrapping" problem where you can shoot yourself across the room by grabbing something
// and holding it against your own avatar. // and holding it against your own avatar.
QUuid ancestorID = findAncestorOfType(NestableType::Avatar); if (isChildOfMyAvatar()) {
if (!ancestorID.isNull() &&
(ancestorID == Physics::getSessionUUID() || ancestorID == AVATAR_SELF_ID)) {
iAmHoldingThis = true; iAmHoldingThis = true;
} }
// also, don't bootstrap our own avatar with a hold action // also, don't bootstrap our own avatar with a hold action
@ -2210,6 +2194,7 @@ bool EntityItem::removeActionInternal(const QUuid& actionID, EntitySimulationPoi
_dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION; _dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
_dirtyFlags |= Simulation::DIRTY_COLLISION_GROUP; // may need to not collide with own avatar _dirtyFlags |= Simulation::DIRTY_COLLISION_GROUP; // may need to not collide with own avatar
setDynamicDataNeedsTransmit(true); setDynamicDataNeedsTransmit(true);
updateQueryAACube();
return success; return success;
} }
return false; return false;
@ -2425,6 +2410,7 @@ QVariantMap EntityItem::getActionArguments(const QUuid& actionID) const {
} }
bool EntityItem::shouldSuppressLocationEdits() const { bool EntityItem::shouldSuppressLocationEdits() const {
// if any of the actions indicate they'd like suppression, suppress
QHash<QUuid, EntityDynamicPointer>::const_iterator i = _objectActions.begin(); QHash<QUuid, EntityDynamicPointer>::const_iterator i = _objectActions.begin();
while (i != _objectActions.end()) { while (i != _objectActions.end()) {
if (i.value()->shouldSuppressLocationEdits()) { if (i.value()->shouldSuppressLocationEdits()) {
@ -2433,6 +2419,11 @@ bool EntityItem::shouldSuppressLocationEdits() const {
i++; i++;
} }
// if any of the ancestors are MyAvatar, suppress
if (isChildOfMyAvatar()) {
return true;
}
return false; return false;
} }
@ -2837,6 +2828,11 @@ void EntityItem::setVisible(bool value) {
}); });
} }
bool EntityItem::isChildOfMyAvatar() const {
QUuid ancestorID = findAncestorOfType(NestableType::Avatar);
return !ancestorID.isNull() && (ancestorID == Physics::getSessionUUID() || ancestorID == AVATAR_SELF_ID);
}
bool EntityItem::getCollisionless() const { bool EntityItem::getCollisionless() const {
bool result; bool result;
withReadLock([&] { withReadLock([&] {

View file

@ -240,6 +240,7 @@ public:
using SpatiallyNestable::getQueryAACube; using SpatiallyNestable::getQueryAACube;
virtual AACube getQueryAACube(bool& success) const override; virtual AACube getQueryAACube(bool& success) const override;
virtual bool shouldPuffQueryAACube() const override;
QString getScript() const; QString getScript() const;
void setScript(const QString& value); void setScript(const QString& value);
@ -273,6 +274,8 @@ public:
inline bool isVisible() const { return getVisible(); } inline bool isVisible() const { return getVisible(); }
inline bool isInvisible() const { return !getVisible(); } inline bool isInvisible() const { return !getVisible(); }
bool isChildOfMyAvatar() const;
bool getCollisionless() const; bool getCollisionless() const;
void setCollisionless(bool value); void setCollisionless(bool value);
@ -354,20 +357,16 @@ public:
virtual void updateRegistrationPoint(const glm::vec3& value); virtual void updateRegistrationPoint(const glm::vec3& value);
void updatePosition(const glm::vec3& value); void updatePosition(const glm::vec3& value);
void updateParentID(const QUuid& value); void updateParentID(const QUuid& value);
void updatePositionFromNetwork(const glm::vec3& value);
void updateDimensions(const glm::vec3& value); void updateDimensions(const glm::vec3& value);
void updateRotation(const glm::quat& rotation); void updateRotation(const glm::quat& rotation);
void updateRotationFromNetwork(const glm::quat& rotation);
void updateDensity(float value); void updateDensity(float value);
void updateMass(float value); void updateMass(float value);
void updateVelocity(const glm::vec3& value); void updateVelocity(const glm::vec3& value);
void updateVelocityFromNetwork(const glm::vec3& value);
void updateDamping(float value); void updateDamping(float value);
void updateRestitution(float value); void updateRestitution(float value);
void updateFriction(float value); void updateFriction(float value);
void updateGravity(const glm::vec3& value); void updateGravity(const glm::vec3& value);
void updateAngularVelocity(const glm::vec3& value); void updateAngularVelocity(const glm::vec3& value);
void updateAngularVelocityFromNetwork(const glm::vec3& value);
void updateAngularDamping(float value); void updateAngularDamping(float value);
void updateCollisionless(bool value); void updateCollisionless(bool value);
void updateCollisionMask(uint8_t value); void updateCollisionMask(uint8_t value);
@ -629,12 +628,14 @@ protected:
glm::vec3 _lastUpdatedVelocityValue; glm::vec3 _lastUpdatedVelocityValue;
glm::vec3 _lastUpdatedAngularVelocityValue; glm::vec3 _lastUpdatedAngularVelocityValue;
glm::vec3 _lastUpdatedAccelerationValue; glm::vec3 _lastUpdatedAccelerationValue;
AACube _lastUpdatedQueryAACubeValue;
quint64 _lastUpdatedPositionTimestamp { 0 }; quint64 _lastUpdatedPositionTimestamp { 0 };
quint64 _lastUpdatedRotationTimestamp { 0 }; quint64 _lastUpdatedRotationTimestamp { 0 };
quint64 _lastUpdatedVelocityTimestamp { 0 }; quint64 _lastUpdatedVelocityTimestamp { 0 };
quint64 _lastUpdatedAngularVelocityTimestamp { 0 }; quint64 _lastUpdatedAngularVelocityTimestamp { 0 };
quint64 _lastUpdatedAccelerationTimestamp { 0 }; quint64 _lastUpdatedAccelerationTimestamp { 0 };
quint64 _lastUpdatedQueryAACubeTimestamp { 0 };
}; };

View file

@ -457,7 +457,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties&
// if they've changed. // if they've changed.
entity->forEachDescendant([&](SpatiallyNestablePointer descendant) { entity->forEachDescendant([&](SpatiallyNestablePointer descendant) {
if (descendant->getNestableType() == NestableType::Entity) { if (descendant->getNestableType() == NestableType::Entity) {
if (descendant->checkAndMaybeUpdateQueryAACube()) { if (descendant->updateQueryAACube()) {
EntityItemPointer entityDescendant = std::static_pointer_cast<EntityItem>(descendant); EntityItemPointer entityDescendant = std::static_pointer_cast<EntityItem>(descendant);
EntityItemProperties newQueryCubeProperties; EntityItemProperties newQueryCubeProperties;
newQueryCubeProperties.setQueryAACube(descendant->getQueryAACube()); newQueryCubeProperties.setQueryAACube(descendant->getQueryAACube());

View file

@ -1028,7 +1028,8 @@ void EntityTree::fixupTerseEditLogging(EntityItemProperties& properties, QList<Q
changedProperties[index] = QString("queryAACube:") + changedProperties[index] = QString("queryAACube:") +
QString::number((int)center.x) + "," + QString::number((int)center.x) + "," +
QString::number((int)center.y) + "," + QString::number((int)center.y) + "," +
QString::number((int)center.z); QString::number((int)center.z) + "/" +
QString::number(properties.getQueryAACube().getDimensions().x);
} }
if (properties.positionChanged()) { if (properties.positionChanged()) {
int index = changedProperties.indexOf("position"); int index = changedProperties.indexOf("position");
@ -1804,7 +1805,7 @@ QVector<EntityItemID> EntityTree::sendEntities(EntityEditPacketSender* packetSen
addToNeedsParentFixupList(entity); addToNeedsParentFixupList(entity);
} }
entity->forceQueryAACubeUpdate(); entity->forceQueryAACubeUpdate();
entity->checkAndMaybeUpdateQueryAACube(); entity->updateQueryAACube();
moveOperator.addEntityToMoveList(entity, entity->getQueryAACube()); moveOperator.addEntityToMoveList(entity, entity->getQueryAACube());
i++; i++;
} else { } else {

View file

@ -136,7 +136,7 @@ void SimpleEntitySimulation::sortEntitiesThatMoved() {
SetOfEntities::iterator itemItr = _entitiesToSort.begin(); SetOfEntities::iterator itemItr = _entitiesToSort.begin();
while (itemItr != _entitiesToSort.end()) { while (itemItr != _entitiesToSort.end()) {
EntityItemPointer entity = *itemItr; EntityItemPointer entity = *itemItr;
entity->checkAndMaybeUpdateQueryAACube(); entity->updateQueryAACube();
++itemItr; ++itemItr;
} }
EntitySimulation::sortEntitiesThatMoved(); EntitySimulation::sortEntitiesThatMoved();

View file

@ -491,6 +491,10 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep) {
return true; return true;
} }
if (_entity->shouldSuppressLocationEdits()) {
return false;
}
if (!isLocallyOwned()) { if (!isLocallyOwned()) {
// we don't own the simulation // we don't own the simulation
@ -577,7 +581,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
} }
if (properties.transformChanged()) { if (properties.transformChanged()) {
if (_entity->checkAndMaybeUpdateQueryAACube()) { if (_entity->updateQueryAACube()) {
// due to parenting, the server may not know where something is in world-space, so include the bounding cube. // due to parenting, the server may not know where something is in world-space, so include the bounding cube.
properties.setQueryAACube(_entity->getQueryAACube()); properties.setQueryAACube(_entity->getQueryAACube());
} }
@ -644,7 +648,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
_entity->forEachDescendant([&](SpatiallyNestablePointer descendant) { _entity->forEachDescendant([&](SpatiallyNestablePointer descendant) {
if (descendant->getNestableType() == NestableType::Entity) { if (descendant->getNestableType() == NestableType::Entity) {
EntityItemPointer entityDescendant = std::static_pointer_cast<EntityItem>(descendant); EntityItemPointer entityDescendant = std::static_pointer_cast<EntityItem>(descendant);
if (descendant->checkAndMaybeUpdateQueryAACube()) { if (descendant->updateQueryAACube()) {
EntityItemProperties newQueryCubeProperties; EntityItemProperties newQueryCubeProperties;
newQueryCubeProperties.setQueryAACube(descendant->getQueryAACube()); newQueryCubeProperties.setQueryAACube(descendant->getQueryAACube());
newQueryCubeProperties.setLastEdited(properties.getLastEdited()); newQueryCubeProperties.setLastEdited(properties.getLastEdited());

View file

@ -963,18 +963,25 @@ AACube SpatiallyNestable::getMaximumAACube(bool& success) const {
const float PARENTED_EXPANSION_FACTOR = 3.0f; const float PARENTED_EXPANSION_FACTOR = 3.0f;
bool SpatiallyNestable::checkAndMaybeUpdateQueryAACube() { bool SpatiallyNestable::updateQueryAACube() {
bool success = false; if (!queryAACubeNeedsUpdate()) {
return false;
}
bool success;
AACube maxAACube = getMaximumAACube(success); AACube maxAACube = getMaximumAACube(success);
if (success) { if (!success) {
// maybe update _queryAACube return false;
if (!_queryAACubeSet || (_parentID.isNull() && _children.size() == 0) || !_queryAACube.contains(maxAACube)) { }
if (_parentJointIndex != INVALID_JOINT_INDEX || _children.size() > 0 ) {
if (shouldPuffQueryAACube()) {
// make an expanded AACube centered on the object // make an expanded AACube centered on the object
float scale = PARENTED_EXPANSION_FACTOR * maxAACube.getScale(); float scale = PARENTED_EXPANSION_FACTOR * maxAACube.getScale();
_queryAACube = AACube(maxAACube.calcCenter() - glm::vec3(0.5f * scale), scale); _queryAACube = AACube(maxAACube.calcCenter() - glm::vec3(0.5f * scale), scale);
_queryAACubeIsPuffed = true;
} else { } else {
_queryAACube = maxAACube; _queryAACube = maxAACube;
_queryAACubeIsPuffed = false;
} }
forEachDescendant([&](const SpatiallyNestablePointer& descendant) { forEachDescendant([&](const SpatiallyNestablePointer& descendant) {
@ -982,16 +989,15 @@ bool SpatiallyNestable::checkAndMaybeUpdateQueryAACube() {
AACube descendantAACube = descendant->getQueryAACube(childSuccess); AACube descendantAACube = descendant->getQueryAACube(childSuccess);
if (childSuccess) { if (childSuccess) {
if (_queryAACube.contains(descendantAACube)) { if (_queryAACube.contains(descendantAACube)) {
return ; return; // from lambda
} }
_queryAACube += descendantAACube.getMinimumPoint(); _queryAACube += descendantAACube.getMinimumPoint();
_queryAACube += descendantAACube.getMaximumPoint(); _queryAACube += descendantAACube.getMaximumPoint();
} }
}); });
_queryAACubeSet = true; _queryAACubeSet = true;
} return true;
}
return success;
} }
void SpatiallyNestable::setQueryAACube(const AACube& queryAACube) { void SpatiallyNestable::setQueryAACube(const AACube& queryAACube) {
@ -1008,6 +1014,16 @@ bool SpatiallyNestable::queryAACubeNeedsUpdate() const {
return true; return true;
} }
bool success;
AACube maxAACube = getMaximumAACube(success);
if (success && !_queryAACube.contains(maxAACube)) {
return true;
}
if (shouldPuffQueryAACube() != _queryAACubeIsPuffed) {
return true;
}
// make sure children are still in their boxes, also. // make sure children are still in their boxes, also.
bool childNeedsUpdate = false; bool childNeedsUpdate = false;
forEachDescendantTest([&](const SpatiallyNestablePointer& descendant) { forEachDescendantTest([&](const SpatiallyNestablePointer& descendant) {
@ -1021,31 +1037,6 @@ bool SpatiallyNestable::queryAACubeNeedsUpdate() const {
return childNeedsUpdate; return childNeedsUpdate;
} }
void SpatiallyNestable::updateQueryAACube() {
bool success;
AACube maxAACube = getMaximumAACube(success);
if (_parentJointIndex != INVALID_JOINT_INDEX || _children.size() > 0 ) {
// make an expanded AACube centered on the object
float scale = PARENTED_EXPANSION_FACTOR * maxAACube.getScale();
_queryAACube = AACube(maxAACube.calcCenter() - glm::vec3(0.5f * scale), scale);
} else {
_queryAACube = maxAACube;
}
forEachDescendant([&](const SpatiallyNestablePointer& descendant) {
bool success;
AACube descendantAACube = descendant->getQueryAACube(success);
if (success) {
if (_queryAACube.contains(descendantAACube)) {
return;
}
_queryAACube += descendantAACube.getMinimumPoint();
_queryAACube += descendantAACube.getMaximumPoint();
}
});
_queryAACubeSet = true;
}
AACube SpatiallyNestable::getQueryAACube(bool& success) const { AACube SpatiallyNestable::getQueryAACube(bool& success) const {
if (_queryAACubeSet) { if (_queryAACubeSet) {
success = true; success = true;

View file

@ -106,11 +106,11 @@ public:
virtual glm::vec3 getParentAngularVelocity(bool& success) const; virtual glm::vec3 getParentAngularVelocity(bool& success) const;
virtual AACube getMaximumAACube(bool& success) const; virtual AACube getMaximumAACube(bool& success) const;
bool checkAndMaybeUpdateQueryAACube();
void updateQueryAACube();
virtual void setQueryAACube(const AACube& queryAACube); virtual void setQueryAACube(const AACube& queryAACube);
virtual bool queryAACubeNeedsUpdate() const; virtual bool queryAACubeNeedsUpdate() const;
virtual bool shouldPuffQueryAACube() const { return false; }
bool updateQueryAACube();
void forceQueryAACubeUpdate() { _queryAACubeSet = false; } void forceQueryAACubeUpdate() { _queryAACubeSet = false; }
virtual AACube getQueryAACube(bool& success) const; virtual AACube getQueryAACube(bool& success) const;
virtual AACube getQueryAACube() const; virtual AACube getQueryAACube() const;
@ -234,6 +234,7 @@ private:
glm::vec3 _angularVelocity; glm::vec3 _angularVelocity;
mutable bool _parentKnowsMe { false }; mutable bool _parentKnowsMe { false };
bool _isDead { false }; bool _isDead { false };
bool _queryAACubeIsPuffed { false };
}; };