From d833fb08d74f365323822f5e0dd8553c42c70b90 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 15 Oct 2015 10:03:32 -0700 Subject: [PATCH] further unmangle branch split --- interface/src/avatar/AvatarActionHold.cpp | 95 +++++++++++++---------- 1 file changed, 53 insertions(+), 42 deletions(-) diff --git a/interface/src/avatar/AvatarActionHold.cpp b/interface/src/avatar/AvatarActionHold.cpp index 22585d962a..1529805e1e 100644 --- a/interface/src/avatar/AvatarActionHold.cpp +++ b/interface/src/avatar/AvatarActionHold.cpp @@ -36,10 +36,12 @@ AvatarActionHold::~AvatarActionHold() { } void AvatarActionHold::updateActionWorker(float deltaTimeStep) { + bool gotLock = false; glm::quat rotation; glm::vec3 position; glm::vec3 offset; - bool gotLock = withTryReadLock([&]{ + + gotLock = withTryReadLock([&]{ auto myAvatar = DependencyManager::get()->getMyAvatar(); glm::vec3 palmPosition; glm::quat palmRotation; @@ -58,17 +60,10 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) { if (gotLock) { gotLock = withTryWriteLock([&]{ - if (_positionalTarget != position || _rotationalTarget != rotation) { - auto ownerEntity = _ownerEntity.lock(); - if (ownerEntity) { - ownerEntity->setActionDataDirty(true); - } _positionalTarget = position; _rotationalTarget = rotation; - } - }); + }); } - if (gotLock) { ObjectActionSpring::updateActionWorker(deltaTimeStep); } @@ -76,57 +71,73 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) { bool AvatarActionHold::updateArguments(QVariantMap arguments) { - if (!ObjectAction::updateArguments(arguments)) { - return false; - } - bool ok = true; - glm::vec3 relativePosition = - EntityActionInterface::extractVec3Argument("hold", arguments, "relativePosition", ok, false); - if (!ok) { - relativePosition = _relativePosition; - } + glm::vec3 relativePosition; + glm::quat relativeRotation; + float timeScale; + QString hand; + QUuid holderID; + bool needUpdate = false; - ok = true; - glm::quat relativeRotation = - EntityActionInterface::extractQuatArgument("hold", arguments, "relativeRotation", ok, false); - if (!ok) { - relativeRotation = _relativeRotation; - } - - ok = true; - float timeScale = - EntityActionInterface::extractFloatArgument("hold", arguments, "timeScale", ok, false); - if (!ok) { - timeScale = _linearTimeScale; - } + bool somethingChanged = ObjectAction::updateArguments(arguments); + withReadLock([&]{ + bool ok = true; + relativePosition = EntityActionInterface::extractVec3Argument("hold", arguments, "relativePosition", ok, false); + if (!ok) { + relativePosition = _relativePosition; + } - ok = true; - QString hand = - EntityActionInterface::extractStringArgument("hold", arguments, "hand", ok, false); - if (!ok || !(hand == "left" || hand == "right")) { - hand = _hand; - } + ok = true; + relativeRotation = EntityActionInterface::extractQuatArgument("hold", arguments, "relativeRotation", ok, false); + if (!ok) { + relativeRotation = _relativeRotation; + } - if (relativePosition != _relativePosition + ok = true; + timeScale = EntityActionInterface::extractFloatArgument("hold", arguments, "timeScale", ok, false); + if (!ok) { + timeScale = _linearTimeScale; + } + + ok = true; + hand = EntityActionInterface::extractStringArgument("hold", arguments, "hand", ok, false); + if (!ok || !(hand == "left" || hand == "right")) { + hand = _hand; + } + + ok = true; + auto myAvatar = DependencyManager::get()->getMyAvatar(); + holderID = myAvatar->getSessionUUID(); + + if (somethingChanged || + relativePosition != _relativePosition || relativeRotation != _relativeRotation || timeScale != _linearTimeScale || hand != _hand) { + needUpdate = true; + } + }); + + if (needUpdate) { withWriteLock([&] { _relativePosition = relativePosition; _relativeRotation = relativeRotation; const float MIN_TIMESCALE = 0.1f; - _linearTimeScale = glm::min(MIN_TIMESCALE, timeScale); + _linearTimeScale = glm::max(MIN_TIMESCALE, timeScale); _angularTimeScale = _linearTimeScale; _hand = hand; - _active = true; - activateBody(); + + auto ownerEntity = _ownerEntity.lock(); + if (ownerEntity) { + ownerEntity->setActionDataDirty(true); + } }); + activateBody(); } + return true; } - QVariantMap AvatarActionHold::getArguments() { QVariantMap arguments = ObjectAction::getArguments(); withReadLock([&]{