Showing the changes to libraries/physics/src/ObjectActionSpring.cpp (1 of 5 files). Show all
Unified · Split
| @@ -107,43 +107,52 @@ void ObjectActionSpring::updateActionWorker(btScalar deltaTimeStep) { · 106 unmodified lines | |||
| 107 | 107 | ||
| 108 | const float MIN_TIMESCALE = 0.1f; | 108 | const float MIN_TIMESCALE = 0.1f; |
| 109 | 109 | ||
| 110 | |||
| 110 | bool ObjectActionSpring::updateArguments(QVariantMap arguments) { | 111 | bool ObjectActionSpring::updateArguments(QVariantMap arguments) { |
| 111 | if (!ObjectAction::updateArguments(arguments)) { | 112 | glm::vec3 positionalTarget; |
| 112 | return false; | 113 | float linearTimeScale; |
| 113 | } | 114 | glm::quat rotationalTarget; |
| 114 | // targets are required, spring-constants are optional | 115 | float angularTimeScale; |
| 115 | bool ok = true; | 116 | |
| 116 | glm::vec3 positionalTarget = | 117 | bool needUpdate = false; |
| 117 | EntityActionInterface::extractVec3Argument("spring action", arguments, "targetPosition", ok, false); | 118 | bool somethingChanged = ObjectAction::updateArguments(arguments); |
| 118 | if (!ok) { | 119 | withReadLock([&]{ |
| 119 | positionalTarget = _positionalTarget; | 120 | // targets are required, spring-constants are optional |
| 120 | } | 121 | bool ok = true; |
| 121 | ok = true; | 122 | positionalTarget = EntityActionInterface::extractVec3Argument("spring action", arguments, "targetPosition", ok, false); |
| 122 | float linearTimeScale = | 123 | if (!ok) { |
| 123 | EntityActionInterface::extractFloatArgument("spring action", arguments, "linearTimeScale", ok, false); | 124 | positionalTarget = _positionalTarget; |
| 124 | if (!ok || linearTimeScale <= 0.0f) { | 125 | } |
| 125 | linearTimeScale = _linearTimeScale; | 126 | ok = true; |
| 126 | } | 127 | linearTimeScale = EntityActionInterface::extractFloatArgument("spring action", arguments, "linearTimeScale", ok, false); |
| 128 | if (!ok || linearTimeScale <= 0.0f) { | ||
| 129 | linearTimeScale = _linearTimeScale; | ||
| 130 | } | ||
| 127 | 131 | ||
| 128 | ok = true; | 132 | ok = true; |
| 129 | glm::quat rotationalTarget = | 133 | rotationalTarget = EntityActionInterface::extractQuatArgument("spring action", arguments, "targetRotation", ok, false); |
| 130 | EntityActionInterface::extractQuatArgument("spring action", arguments, "targetRotation", ok, false); | 134 | if (!ok) { |
| 131 | if (!ok) { | 135 | rotationalTarget = _rotationalTarget; |
| 132 | rotationalTarget = _rotationalTarget; | 136 | } |
| 133 | } | ||
| 134 | 137 | ||
| 135 | ok = true; | 138 | ok = true; |
| 136 | float angularTimeScale = | 139 | angularTimeScale = |
| 137 | EntityActionInterface::extractFloatArgument("spring action", arguments, "angularTimeScale", ok, false); | 140 | EntityActionInterface::extractFloatArgument("spring action", arguments, "angularTimeScale", ok, false); |
| 138 | if (!ok) { | 141 | if (!ok) { |
| 139 | angularTimeScale = _angularTimeScale; | 142 | angularTimeScale = _angularTimeScale; |
| 140 | } | 143 | } |
| 144 | |||
| 145 | if (somethingChanged || | ||
| 146 | positionalTarget != _positionalTarget || | ||
| 147 | linearTimeScale != _linearTimeScale || | ||
| 148 | rotationalTarget != _rotationalTarget || | ||
| 149 | angularTimeScale != _angularTimeScale) { | ||
| 150 | // something changed | ||
| 151 | needUpdate = true; | ||
| 152 | } | ||
| 153 | }); | ||
| 141 | 154 | ||
| 142 | if (positionalTarget != _positionalTarget | 155 | if (needUpdate) { |
| 143 | || linearTimeScale != _linearTimeScale | ||
| 144 | || rotationalTarget != _rotationalTarget | ||
| 145 | || angularTimeScale != _angularTimeScale) { | ||
| 146 | // something changed | ||
| 147 | withWriteLock([&] { | 156 | withWriteLock([&] { |
| 148 | _positionalTarget = positionalTarget; | 157 | _positionalTarget = positionalTarget; |
| 149 | _linearTimeScale = glm::max(MIN_TIMESCALE, glm::abs(linearTimeScale)); | 158 | _linearTimeScale = glm::max(MIN_TIMESCALE, glm::abs(linearTimeScale)); |
| @@ -151,8 +160,15 @@ bool ObjectActionSpring::updateArguments(QVariantMap arguments) { · 1 unmodified line | |||
| 151 | _angularTimeScale = glm::max(MIN_TIMESCALE, glm::abs(angularTimeScale)); | 160 | _angularTimeScale = glm::max(MIN_TIMESCALE, glm::abs(angularTimeScale)); |
| 152 | _active = true; | 161 | _active = true; |
| 153 | activateBody(); | 162 | activateBody(); |
| 163 | |||
| 164 | auto ownerEntity = _ownerEntity.lock(); | ||
| 165 | if (ownerEntity) { | ||
| 166 | ownerEntity->setActionDataDirty(true); | ||
| 167 | } | ||
| 168 | |||
| 154 | }); | 169 | }); |
| 155 | } | 170 | } |
| 171 | |||
| 156 | return true; | 172 | return true; |
| 157 | } | 173 | } |
| 158 | 174 | ||