keep grabbed and worn entities from spamming entity-server

This commit is contained in:
Seth Alves 2017-10-12 11:33:42 -07:00
parent 2ab606a98b
commit f75e59c0a6
5 changed files with 98 additions and 75 deletions

View file

@ -43,7 +43,7 @@ int EntityItem::_maxActionsDataSize = 800;
quint64 EntityItem::_rememberDeletedActionTime = 20 * USECS_PER_SECOND; quint64 EntityItem::_rememberDeletedActionTime = 20 * USECS_PER_SECOND;
EntityItem::EntityItem(const EntityItemID& entityItemID) : EntityItem::EntityItem(const EntityItemID& entityItemID) :
SpatiallyNestable(NestableType::Entity, entityItemID) SpatiallyNestable(NestableType::Entity, entityItemID)
{ {
setLocalVelocity(ENTITY_ITEM_DEFAULT_VELOCITY); setLocalVelocity(ENTITY_ITEM_DEFAULT_VELOCITY);
setLocalAngularVelocity(ENTITY_ITEM_DEFAULT_ANGULAR_VELOCITY); setLocalAngularVelocity(ENTITY_ITEM_DEFAULT_ANGULAR_VELOCITY);
@ -719,7 +719,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
} }
{ // 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
// information to be idempotent, but if we applied new physics properties we'd resimulation // information to be idempotent, but if we applied new physics properties we'd resimulation
// with small differences in results. // with small differences in results.
@ -727,7 +727,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
// made these lambdas that can access other details about the previous updates to suppress // made these lambdas that can access other details about the previous updates to suppress
// any duplicates. // any duplicates.
// 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; auto lastEdited = lastEditedFromBufferAdjusted;
bool otherOverwrites = overwriteLocalData && !weOwnSimulation; bool otherOverwrites = overwriteLocalData && !weOwnSimulation;
@ -1659,7 +1659,7 @@ bool EntityItem::verifyStaticCertificateProperties() {
const auto hash = getStaticCertificateHash(); const auto hash = getStaticCertificateHash();
const auto text = reinterpret_cast<const unsigned char*>(hash.constData()); const auto text = reinterpret_cast<const unsigned char*>(hash.constData());
const unsigned int textLength = hash.length(); const unsigned int textLength = hash.length();
// After DEBUG_CERT ends, we will get/cache this once from the marketplace when needed, and it likely won't be RSA. // After DEBUG_CERT ends, we will get/cache this once from the marketplace when needed, and it likely won't be RSA.
const char publicKey[] = "-----BEGIN PUBLIC KEY-----\n\ const char publicKey[] = "-----BEGIN PUBLIC KEY-----\n\
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALCoBiDAZOClO26tC5pd7JikBL61WIgp\n\ MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALCoBiDAZOClO26tC5pd7JikBL61WIgp\n\
@ -2016,9 +2016,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
@ -2425,6 +2423,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 +2432,11 @@ bool EntityItem::shouldSuppressLocationEdits() const {
i++; i++;
} }
// if any of the ancestors are MyAvatar, suppress
if (isChildOfMyAvatar()) {
return true;
}
return false; return false;
} }
@ -2495,16 +2499,16 @@ void EntityItem::globalizeProperties(EntityItemProperties& properties, const QSt
bool EntityItem::matchesJSONFilters(const QJsonObject& jsonFilters) const { bool EntityItem::matchesJSONFilters(const QJsonObject& jsonFilters) const {
// The intention for the query JSON filter and this method is to be flexible to handle a variety of filters for // The intention for the query JSON filter and this method is to be flexible to handle a variety of filters for
// ALL entity properties. Some work will need to be done to the property system so that it can be more flexible // ALL entity properties. Some work will need to be done to the property system so that it can be more flexible
// (to grab the value and default value of a property given the string representation of that property, for example) // (to grab the value and default value of a property given the string representation of that property, for example)
// currently the only property filter we handle is '+' for serverScripts // currently the only property filter we handle is '+' for serverScripts
// which means that we only handle a filtered query asking for entities where the serverScripts property is non-default // which means that we only handle a filtered query asking for entities where the serverScripts property is non-default
static const QString SERVER_SCRIPTS_PROPERTY = "serverScripts"; static const QString SERVER_SCRIPTS_PROPERTY = "serverScripts";
foreach(const auto& property, jsonFilters.keys()) { foreach(const auto& property, jsonFilters.keys()) {
if (property == SERVER_SCRIPTS_PROPERTY && jsonFilters[property] == EntityQueryFilterSymbol::NonDefault) { if (property == SERVER_SCRIPTS_PROPERTY && jsonFilters[property] == EntityQueryFilterSymbol::NonDefault) {
// check if this entity has a non-default value for serverScripts // check if this entity has a non-default value for serverScripts
@ -2515,7 +2519,7 @@ bool EntityItem::matchesJSONFilters(const QJsonObject& jsonFilters) const {
} }
} }
} }
// the json filter syntax did not match what we expected, return a match // the json filter syntax did not match what we expected, return a match
return true; return true;
} }
@ -2528,7 +2532,7 @@ quint64 EntityItem::getLastSimulated() const {
return result; return result;
} }
void EntityItem::setLastSimulated(quint64 now) { void EntityItem::setLastSimulated(quint64 now) {
withWriteLock([&] { withWriteLock([&] {
_lastSimulated = now; _lastSimulated = now;
}); });
@ -2549,7 +2553,7 @@ void EntityItem::setLastEdited(quint64 lastEdited) {
}); });
} }
quint64 EntityItem::getLastBroadcast() const { quint64 EntityItem::getLastBroadcast() const {
quint64 result; quint64 result;
withReadLock([&] { withReadLock([&] {
result = _lastBroadcast; result = _lastBroadcast;
@ -2557,19 +2561,19 @@ quint64 EntityItem::getLastBroadcast() const {
return result; return result;
} }
void EntityItem::setLastBroadcast(quint64 lastBroadcast) { void EntityItem::setLastBroadcast(quint64 lastBroadcast) {
withWriteLock([&] { withWriteLock([&] {
_lastBroadcast = lastBroadcast; _lastBroadcast = lastBroadcast;
}); });
} }
void EntityItem::markAsChangedOnServer() { void EntityItem::markAsChangedOnServer() {
withWriteLock([&] { withWriteLock([&] {
_changedOnServer = usecTimestampNow(); _changedOnServer = usecTimestampNow();
}); });
} }
quint64 EntityItem::getLastChangedOnServer() const { quint64 EntityItem::getLastChangedOnServer() const {
quint64 result; quint64 result;
withReadLock([&] { withReadLock([&] {
result = _changedOnServer; result = _changedOnServer;
@ -2577,13 +2581,13 @@ quint64 EntityItem::getLastChangedOnServer() const {
return result; return result;
} }
void EntityItem::update(const quint64& now) { void EntityItem::update(const quint64& now) {
withWriteLock([&] { withWriteLock([&] {
_lastUpdated = now; _lastUpdated = now;
}); });
} }
quint64 EntityItem::getLastUpdated() const { quint64 EntityItem::getLastUpdated() const {
quint64 result; quint64 result;
withReadLock([&] { withReadLock([&] {
result = _lastUpdated; result = _lastUpdated;
@ -2591,10 +2595,10 @@ quint64 EntityItem::getLastUpdated() const {
return result; return result;
} }
void EntityItem::requiresRecalcBoxes() { void EntityItem::requiresRecalcBoxes() {
withWriteLock([&] { withWriteLock([&] {
_recalcAABox = true; _recalcAABox = true;
_recalcMinAACube = true; _recalcMinAACube = true;
_recalcMaxAACube = true; _recalcMaxAACube = true;
}); });
} }
@ -2607,7 +2611,7 @@ QString EntityItem::getHref() const {
return result; return result;
} }
QString EntityItem::getDescription() const { QString EntityItem::getDescription() const {
QString result; QString result;
withReadLock([&] { withReadLock([&] {
result = _description; result = _description;
@ -2629,54 +2633,54 @@ float EntityItem::getLocalRenderAlpha() const {
return result; return result;
} }
void EntityItem::setLocalRenderAlpha(float localRenderAlpha) { void EntityItem::setLocalRenderAlpha(float localRenderAlpha) {
withWriteLock([&] { withWriteLock([&] {
_localRenderAlpha = localRenderAlpha; _localRenderAlpha = localRenderAlpha;
}); });
} }
glm::vec3 EntityItem::getGravity() const { glm::vec3 EntityItem::getGravity() const {
glm::vec3 result; glm::vec3 result;
withReadLock([&] { withReadLock([&] {
result = _gravity; result = _gravity;
}); });
return result; return result;
} }
void EntityItem::setGravity(const glm::vec3& value) { void EntityItem::setGravity(const glm::vec3& value) {
withWriteLock([&] { withWriteLock([&] {
_gravity = value; _gravity = value;
}); });
} }
glm::vec3 EntityItem::getAcceleration() const { glm::vec3 EntityItem::getAcceleration() const {
glm::vec3 result; glm::vec3 result;
withReadLock([&] { withReadLock([&] {
result = _acceleration; result = _acceleration;
}); });
return result; return result;
} }
void EntityItem::setAcceleration(const glm::vec3& value) { void EntityItem::setAcceleration(const glm::vec3& value) {
withWriteLock([&] { withWriteLock([&] {
_acceleration = value; _acceleration = value;
}); });
} }
float EntityItem::getDamping() const { float EntityItem::getDamping() const {
float result; float result;
withReadLock([&] { withReadLock([&] {
result = _damping; result = _damping;
}); });
return result; return result;
} }
void EntityItem::setDamping(float value) { void EntityItem::setDamping(float value) {
withWriteLock([&] { withWriteLock([&] {
_damping = value; _damping = value;
}); });
} }
float EntityItem::getRestitution() const { float EntityItem::getRestitution() const {
float result; float result;
withReadLock([&] { withReadLock([&] {
result = _restitution; result = _restitution;
@ -2684,7 +2688,7 @@ float EntityItem::getRestitution() const {
return result; return result;
} }
float EntityItem::getFriction() const { float EntityItem::getFriction() const {
float result; float result;
withReadLock([&] { withReadLock([&] {
result = _friction; result = _friction;
@ -2693,35 +2697,35 @@ float EntityItem::getFriction() const {
} }
// lifetime related properties. // lifetime related properties.
float EntityItem::getLifetime() const { float EntityItem::getLifetime() const {
float result; float result;
withReadLock([&] { withReadLock([&] {
result = _lifetime; result = _lifetime;
}); });
return result; return result;
} }
void EntityItem::setLifetime(float value) { void EntityItem::setLifetime(float value) {
withWriteLock([&] { withWriteLock([&] {
_lifetime = value; _lifetime = value;
}); });
} }
quint64 EntityItem::getCreated() const { quint64 EntityItem::getCreated() const {
quint64 result; quint64 result;
withReadLock([&] { withReadLock([&] {
result = _created; result = _created;
}); });
return result; return result;
} }
void EntityItem::setCreated(quint64 value) { void EntityItem::setCreated(quint64 value) {
withWriteLock([&] { withWriteLock([&] {
_created = value; _created = value;
}); });
} }
QString EntityItem::getScript() const { QString EntityItem::getScript() const {
QString result; QString result;
withReadLock([&] { withReadLock([&] {
result = _script; result = _script;
@ -2729,13 +2733,13 @@ QString EntityItem::getScript() const {
return result; return result;
} }
void EntityItem::setScript(const QString& value) { void EntityItem::setScript(const QString& value) {
withWriteLock([&] { withWriteLock([&] {
_script = value; _script = value;
}); });
} }
quint64 EntityItem::getScriptTimestamp() const { quint64 EntityItem::getScriptTimestamp() const {
quint64 result; quint64 result;
withReadLock([&] { withReadLock([&] {
result = _scriptTimestamp; result = _scriptTimestamp;
@ -2743,13 +2747,13 @@ quint64 EntityItem::getScriptTimestamp() const {
return result; return result;
} }
void EntityItem::setScriptTimestamp(const quint64 value) { void EntityItem::setScriptTimestamp(const quint64 value) {
withWriteLock([&] { withWriteLock([&] {
_scriptTimestamp = value; _scriptTimestamp = value;
}); });
} }
QString EntityItem::getServerScripts() const { QString EntityItem::getServerScripts() const {
QString result; QString result;
withReadLock([&] { withReadLock([&] {
result = _serverScripts; result = _serverScripts;
@ -2759,12 +2763,12 @@ QString EntityItem::getServerScripts() const {
void EntityItem::setServerScripts(const QString& serverScripts) { void EntityItem::setServerScripts(const QString& serverScripts) {
withWriteLock([&] { withWriteLock([&] {
_serverScripts = serverScripts; _serverScripts = serverScripts;
_serverScriptsChangedTimestamp = usecTimestampNow(); _serverScriptsChangedTimestamp = usecTimestampNow();
}); });
} }
QString EntityItem::getCollisionSoundURL() const { QString EntityItem::getCollisionSoundURL() const {
QString result; QString result;
withReadLock([&] { withReadLock([&] {
result = _collisionSoundURL; result = _collisionSoundURL;
@ -2772,22 +2776,22 @@ QString EntityItem::getCollisionSoundURL() const {
return result; return result;
} }
glm::vec3 EntityItem::getRegistrationPoint() const { glm::vec3 EntityItem::getRegistrationPoint() const {
glm::vec3 result; glm::vec3 result;
withReadLock([&] { withReadLock([&] {
result = _registrationPoint; result = _registrationPoint;
}); });
return result; return result;
} }
void EntityItem::setRegistrationPoint(const glm::vec3& value) { void EntityItem::setRegistrationPoint(const glm::vec3& value) {
withWriteLock([&] { withWriteLock([&] {
_registrationPoint = glm::clamp(value, 0.0f, 1.0f); _registrationPoint = glm::clamp(value, 0.0f, 1.0f);
}); });
dimensionsChanged(); // Registration Point affects the bounding box dimensionsChanged(); // Registration Point affects the bounding box
} }
float EntityItem::getAngularDamping() const { float EntityItem::getAngularDamping() const {
float result; float result;
withReadLock([&] { withReadLock([&] {
result = _angularDamping; result = _angularDamping;
@ -2795,13 +2799,13 @@ float EntityItem::getAngularDamping() const {
return result; return result;
} }
void EntityItem::setAngularDamping(float value) { void EntityItem::setAngularDamping(float value) {
withWriteLock([&] { withWriteLock([&] {
_angularDamping = value; _angularDamping = value;
}); });
} }
QString EntityItem::getName() const { QString EntityItem::getName() const {
QString result; QString result;
withReadLock([&] { withReadLock([&] {
result = _name; result = _name;
@ -2809,13 +2813,13 @@ QString EntityItem::getName() const {
return result; return result;
} }
void EntityItem::setName(const QString& value) { void EntityItem::setName(const QString& value) {
withWriteLock([&] { withWriteLock([&] {
_name = value; _name = value;
}); });
} }
QString EntityItem::getDebugName() { QString EntityItem::getDebugName() {
QString result = getName(); QString result = getName();
if (result.isEmpty()) { if (result.isEmpty()) {
result = getID().toString(); result = getID().toString();
@ -2823,7 +2827,7 @@ QString EntityItem::getDebugName() {
return result; return result;
} }
bool EntityItem::getVisible() const { bool EntityItem::getVisible() const {
bool result; bool result;
withReadLock([&] { withReadLock([&] {
result = _visible; result = _visible;
@ -2831,13 +2835,18 @@ bool EntityItem::getVisible() const {
return result; return result;
} }
void EntityItem::setVisible(bool value) { void EntityItem::setVisible(bool value) {
withWriteLock([&] { withWriteLock([&] {
_visible = value; _visible = value;
}); });
} }
bool EntityItem::getCollisionless() const { bool EntityItem::isChildOfMyAvatar() const {
QUuid ancestorID = findAncestorOfType(NestableType::Avatar);
return !ancestorID.isNull() && (ancestorID == Physics::getSessionUUID() || ancestorID == AVATAR_SELF_ID);
}
bool EntityItem::getCollisionless() const {
bool result; bool result;
withReadLock([&] { withReadLock([&] {
result = _collisionless; result = _collisionless;
@ -2845,13 +2854,13 @@ bool EntityItem::getCollisionless() const {
return result; return result;
} }
void EntityItem::setCollisionless(bool value) { void EntityItem::setCollisionless(bool value) {
withWriteLock([&] { withWriteLock([&] {
_collisionless = value; _collisionless = value;
}); });
} }
uint8_t EntityItem::getCollisionMask() const { uint8_t EntityItem::getCollisionMask() const {
uint8_t result; uint8_t result;
withReadLock([&] { withReadLock([&] {
result = _collisionMask; result = _collisionMask;
@ -2859,13 +2868,13 @@ uint8_t EntityItem::getCollisionMask() const {
return result; return result;
} }
void EntityItem::setCollisionMask(uint8_t value) { void EntityItem::setCollisionMask(uint8_t value) {
withWriteLock([&] { withWriteLock([&] {
_collisionMask = value; _collisionMask = value;
}); });
} }
bool EntityItem::getDynamic() const { bool EntityItem::getDynamic() const {
if (SHAPE_TYPE_STATIC_MESH == getShapeType()) { if (SHAPE_TYPE_STATIC_MESH == getShapeType()) {
return false; return false;
} }
@ -2876,13 +2885,13 @@ bool EntityItem::getDynamic() const {
return result; return result;
} }
void EntityItem::setDynamic(bool value) { void EntityItem::setDynamic(bool value) {
withWriteLock([&] { withWriteLock([&] {
_dynamic = value; _dynamic = value;
}); });
} }
bool EntityItem::getLocked() const { bool EntityItem::getLocked() const {
bool result; bool result;
withReadLock([&] { withReadLock([&] {
result = _locked; result = _locked;
@ -2890,7 +2899,7 @@ bool EntityItem::getLocked() const {
return result; return result;
} }
void EntityItem::setLocked(bool value) { void EntityItem::setLocked(bool value) {
withWriteLock([&] { withWriteLock([&] {
_locked = value; _locked = value;
}); });
@ -2913,7 +2922,7 @@ void EntityItem::updateLocked(bool value) {
} }
} }
QString EntityItem::getUserData() const { QString EntityItem::getUserData() const {
QString result; QString result;
withReadLock([&] { withReadLock([&] {
result = _userData; result = _userData;
@ -2921,7 +2930,7 @@ QString EntityItem::getUserData() const {
return result; return result;
} }
void EntityItem::setUserData(const QString& value) { void EntityItem::setUserData(const QString& value) {
withWriteLock([&] { withWriteLock([&] {
_userData = value; _userData = value;
}); });
@ -2955,7 +2964,7 @@ DEFINE_PROPERTY_ACCESSOR(quint32, EditionNumber, editionNumber)
DEFINE_PROPERTY_ACCESSOR(quint32, EntityInstanceNumber, entityInstanceNumber) DEFINE_PROPERTY_ACCESSOR(quint32, EntityInstanceNumber, entityInstanceNumber)
DEFINE_PROPERTY_ACCESSOR(QString, CertificateID, certificateID) DEFINE_PROPERTY_ACCESSOR(QString, CertificateID, certificateID)
uint32_t EntityItem::getDirtyFlags() const { uint32_t EntityItem::getDirtyFlags() const {
uint32_t result; uint32_t result;
withReadLock([&] { withReadLock([&] {
result = _dirtyFlags; result = _dirtyFlags;
@ -2970,7 +2979,7 @@ void EntityItem::markDirtyFlags(uint32_t mask) {
}); });
} }
void EntityItem::clearDirtyFlags(uint32_t mask) { void EntityItem::clearDirtyFlags(uint32_t mask) {
withWriteLock([&] { withWriteLock([&] {
_dirtyFlags &= ~mask; _dirtyFlags &= ~mask;
}); });

View file

@ -273,6 +273,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);

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->checkAndMaybeUpdateQueryAACube(true)) {
// 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());
} }

View file

@ -963,19 +963,21 @@ 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::checkAndMaybeUpdateQueryAACube(bool forcePuffed) {
bool updated = false;
bool success = false; bool success = false;
AACube maxAACube = getMaximumAACube(success); AACube maxAACube = getMaximumAACube(success);
if (success) { if (success) {
// maybe update _queryAACube // maybe update _queryAACube
if (!_queryAACubeSet || (_parentID.isNull() && _children.size() == 0) || !_queryAACube.contains(maxAACube)) { if (!_queryAACubeSet || (_parentID.isNull() && _children.size() == 0) || !_queryAACube.contains(maxAACube)) {
if (_parentJointIndex != INVALID_JOINT_INDEX || _children.size() > 0 ) { if (forcePuffed || _parentJointIndex != INVALID_JOINT_INDEX || _children.size() > 0 ) {
// 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);
} else { } else {
_queryAACube = maxAACube; _queryAACube = maxAACube;
} }
updated = true;
forEachDescendant([&](const SpatiallyNestablePointer& descendant) { forEachDescendant([&](const SpatiallyNestablePointer& descendant) {
bool childSuccess; bool childSuccess;
@ -991,7 +993,7 @@ bool SpatiallyNestable::checkAndMaybeUpdateQueryAACube() {
_queryAACubeSet = true; _queryAACubeSet = true;
} }
} }
return success; return updated;
} }
void SpatiallyNestable::setQueryAACube(const AACube& queryAACube) { void SpatiallyNestable::setQueryAACube(const AACube& queryAACube) {
@ -1008,6 +1010,12 @@ bool SpatiallyNestable::queryAACubeNeedsUpdate() const {
return true; return true;
} }
bool success;
AACube maxAACube = getMaximumAACube(success);
if (success && !_queryAACube.contains(maxAACube)) {
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) {

View file

@ -106,7 +106,7 @@ 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(); bool checkAndMaybeUpdateQueryAACube(bool forcePuffed = false);
void updateQueryAACube(); void updateQueryAACube();
virtual void setQueryAACube(const AACube& queryAACube); virtual void setQueryAACube(const AACube& queryAACube);