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

@ -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
// "bootstrapping" problem where you can shoot yourself across the room by grabbing something
// and holding it against your own avatar.
QUuid ancestorID = findAncestorOfType(NestableType::Avatar);
if (!ancestorID.isNull() &&
(ancestorID == Physics::getSessionUUID() || ancestorID == AVATAR_SELF_ID)) {
if (isChildOfMyAvatar()) {
iAmHoldingThis = true;
}
// 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 {
// if any of the actions indicate they'd like suppression, suppress
QHash<QUuid, EntityDynamicPointer>::const_iterator i = _objectActions.begin();
while (i != _objectActions.end()) {
if (i.value()->shouldSuppressLocationEdits()) {
@ -2433,6 +2432,11 @@ bool EntityItem::shouldSuppressLocationEdits() const {
i++;
}
// if any of the ancestors are MyAvatar, suppress
if (isChildOfMyAvatar()) {
return true;
}
return false;
}
@ -2837,6 +2841,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 result;
withReadLock([&] {

View file

@ -273,6 +273,8 @@ public:
inline bool isVisible() const { return getVisible(); }
inline bool isInvisible() const { return !getVisible(); }
bool isChildOfMyAvatar() const;
bool getCollisionless() const;
void setCollisionless(bool value);

View file

@ -491,6 +491,10 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep) {
return true;
}
if (_entity->shouldSuppressLocationEdits()) {
return false;
}
if (!isLocallyOwned()) {
// we don't own the simulation
@ -577,7 +581,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
}
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.
properties.setQueryAACube(_entity->getQueryAACube());
}

View file

@ -963,19 +963,21 @@ AACube SpatiallyNestable::getMaximumAACube(bool& success) const {
const float PARENTED_EXPANSION_FACTOR = 3.0f;
bool SpatiallyNestable::checkAndMaybeUpdateQueryAACube() {
bool SpatiallyNestable::checkAndMaybeUpdateQueryAACube(bool forcePuffed) {
bool updated = false;
bool success = false;
AACube maxAACube = getMaximumAACube(success);
if (success) {
// maybe update _queryAACube
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
float scale = PARENTED_EXPANSION_FACTOR * maxAACube.getScale();
_queryAACube = AACube(maxAACube.calcCenter() - glm::vec3(0.5f * scale), scale);
} else {
_queryAACube = maxAACube;
}
updated = true;
forEachDescendant([&](const SpatiallyNestablePointer& descendant) {
bool childSuccess;
@ -991,7 +993,7 @@ bool SpatiallyNestable::checkAndMaybeUpdateQueryAACube() {
_queryAACubeSet = true;
}
}
return success;
return updated;
}
void SpatiallyNestable::setQueryAACube(const AACube& queryAACube) {
@ -1008,6 +1010,12 @@ bool SpatiallyNestable::queryAACubeNeedsUpdate() const {
return true;
}
bool success;
AACube maxAACube = getMaximumAACube(success);
if (success && !_queryAACube.contains(maxAACube)) {
return true;
}
// make sure children are still in their boxes, also.
bool childNeedsUpdate = false;
forEachDescendantTest([&](const SpatiallyNestablePointer& descendant) {

View file

@ -106,7 +106,7 @@ public:
virtual glm::vec3 getParentAngularVelocity(bool& success) const;
virtual AACube getMaximumAACube(bool& success) const;
bool checkAndMaybeUpdateQueryAACube();
bool checkAndMaybeUpdateQueryAACube(bool forcePuffed = false);
void updateQueryAACube();
virtual void setQueryAACube(const AACube& queryAACube);