From a47aaea37a17790aa1bfad21e7c5314cb8d87ac0 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 12 Jan 2017 10:12:45 -0800 Subject: [PATCH] don't bootstrap self with an avatar hold action --- libraries/entities/src/EntityItem.cpp | 33 ++++++++++++++++++++------ libraries/entities/src/EntityItem.h | 2 +- libraries/physics/src/ObjectAction.cpp | 1 + 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 27b3507f31..917f7f3de1 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1794,12 +1794,27 @@ void EntityItem::computeCollisionGroupAndFinalMask(int16_t& group, int16_t& mask } uint8_t userMask = getCollisionMask(); - // 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()) { - userMask &= ~USER_COLLISION_GROUP_MY_AVATAR; + if (userMask & USER_COLLISION_GROUP_MY_AVATAR) { + // 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()) { + userMask &= ~USER_COLLISION_GROUP_MY_AVATAR; + } + } + if (userMask & USER_COLLISION_GROUP_MY_AVATAR) { + // also, don't bootstrap our own avatar with a hold action + QList holdActions = getActionsOfType(ACTION_TYPE_HOLD); + QList::const_iterator i = holdActions.begin(); + while (i != holdActions.end()) { + EntityActionPointer action = *i; + if (action->isMine()) { + userMask &= ~USER_COLLISION_GROUP_MY_AVATAR; + break; + } + i++; + } } if ((bool)(userMask & USER_COLLISION_GROUP_MY_AVATAR) != @@ -1904,6 +1919,7 @@ bool EntityItem::addActionInternal(EntitySimulationPointer simulation, EntityAct if (success) { _allActionsDataCache = newDataCache; _dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION; + _dirtyFlags |= Simulation::DIRTY_COLLISION_GROUP; // may need to not collide with own avatar } else { qCDebug(entities) << "EntityItem::addActionInternal -- serializeActions failed"; } @@ -1926,6 +1942,7 @@ bool EntityItem::updateAction(EntitySimulationPointer simulation, const QUuid& a action->setIsMine(true); serializeActions(success, _allActionsDataCache); _dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION; + _dirtyFlags |= Simulation::DIRTY_COLLISION_GROUP; // may need to not collide with own avatar } else { qCDebug(entities) << "EntityItem::updateAction failed"; } @@ -1963,6 +1980,7 @@ bool EntityItem::removeActionInternal(const QUuid& actionID, EntitySimulationPoi bool success = true; serializeActions(success, _allActionsDataCache); _dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION; + _dirtyFlags |= Simulation::DIRTY_COLLISION_GROUP; // may need to not collide with own avatar setActionDataNeedsTransmit(true); return success; } @@ -1983,6 +2001,7 @@ bool EntityItem::clearActions(EntitySimulationPointer simulation) { _actionsToRemove.clear(); _allActionsDataCache.clear(); _dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION; + _dirtyFlags |= Simulation::DIRTY_COLLISION_GROUP; // may need to not collide with own avatar }); return true; } @@ -2189,7 +2208,7 @@ bool EntityItem::shouldSuppressLocationEdits() const { return false; } -QList EntityItem::getActionsOfType(EntityActionType typeToGet) { +QList EntityItem::getActionsOfType(EntityActionType typeToGet) const { QList result; QHash::const_iterator i = _objectActions.begin(); diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 7be81391f3..3e1f32ffdb 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -416,7 +416,7 @@ public: const QUuid& getSourceUUID() const { return _sourceUUID; } bool matchesSourceUUID(const QUuid& sourceUUID) const { return _sourceUUID == sourceUUID; } - QList getActionsOfType(EntityActionType typeToGet); + QList getActionsOfType(EntityActionType typeToGet) const; // these are in the frame of this object virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override { return glm::quat(); } diff --git a/libraries/physics/src/ObjectAction.cpp b/libraries/physics/src/ObjectAction.cpp index 140de3a972..95448ad029 100644 --- a/libraries/physics/src/ObjectAction.cpp +++ b/libraries/physics/src/ObjectAction.cpp @@ -133,6 +133,7 @@ QVariantMap ObjectAction::getArguments() { arguments["::no-motion-state"] = true; } } + arguments["isMine"] = isMine(); }); return arguments; }