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