diff options
author | Jacek Antonelli | 2008-08-15 23:45:57 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:57 -0500 |
commit | 7e3007b63521c4b0c5bbad1c3964a557fc526ce2 (patch) | |
tree | ab231ed574db618873d6ebb25293cf7c0cb6d26e /linden/indra/llcharacter/llmotioncontroller.cpp | |
parent | Second Life viewer sources 1.20.10 (diff) | |
download | meta-impy-7e3007b63521c4b0c5bbad1c3964a557fc526ce2.zip meta-impy-7e3007b63521c4b0c5bbad1c3964a557fc526ce2.tar.gz meta-impy-7e3007b63521c4b0c5bbad1c3964a557fc526ce2.tar.bz2 meta-impy-7e3007b63521c4b0c5bbad1c3964a557fc526ce2.tar.xz |
Second Life viewer sources 1.20.11
Diffstat (limited to 'linden/indra/llcharacter/llmotioncontroller.cpp')
-rw-r--r-- | linden/indra/llcharacter/llmotioncontroller.cpp | 461 |
1 files changed, 276 insertions, 185 deletions
diff --git a/linden/indra/llcharacter/llmotioncontroller.cpp b/linden/indra/llcharacter/llmotioncontroller.cpp index 028cf22..90a3d74 100644 --- a/linden/indra/llcharacter/llmotioncontroller.cpp +++ b/linden/indra/llcharacter/llmotioncontroller.cpp | |||
@@ -34,6 +34,8 @@ | |||
34 | //----------------------------------------------------------------------------- | 34 | //----------------------------------------------------------------------------- |
35 | #include "linden_common.h" | 35 | #include "linden_common.h" |
36 | 36 | ||
37 | #include "llmemtype.h" | ||
38 | |||
37 | #include "llmotioncontroller.h" | 39 | #include "llmotioncontroller.h" |
38 | #include "llkeyframemotion.h" | 40 | #include "llkeyframemotion.h" |
39 | #include "llmath.h" | 41 | #include "llmath.h" |
@@ -50,32 +52,6 @@ const U32 MAX_MOTION_INSTANCES = 32; | |||
50 | LLMotionRegistry LLMotionController::sRegistry; | 52 | LLMotionRegistry LLMotionController::sRegistry; |
51 | 53 | ||
52 | //----------------------------------------------------------------------------- | 54 | //----------------------------------------------------------------------------- |
53 | // LLMotionTableEntry() | ||
54 | //----------------------------------------------------------------------------- | ||
55 | LLMotionTableEntry::LLMotionTableEntry() | ||
56 | { | ||
57 | mConstructor = NULL; | ||
58 | mID.setNull(); | ||
59 | } | ||
60 | |||
61 | LLMotionTableEntry::LLMotionTableEntry(LLMotionConstructor constructor, const LLUUID& id) | ||
62 | : mConstructor(constructor), mID(id) | ||
63 | { | ||
64 | |||
65 | } | ||
66 | |||
67 | //----------------------------------------------------------------------------- | ||
68 | // create() | ||
69 | //----------------------------------------------------------------------------- | ||
70 | LLMotion* LLMotionTableEntry::create(const LLUUID &id) | ||
71 | { | ||
72 | LLMotion* motionp = mConstructor(id); | ||
73 | |||
74 | return motionp; | ||
75 | } | ||
76 | |||
77 | |||
78 | //----------------------------------------------------------------------------- | ||
79 | //----------------------------------------------------------------------------- | 55 | //----------------------------------------------------------------------------- |
80 | // LLMotionRegistry class | 56 | // LLMotionRegistry class |
81 | //----------------------------------------------------------------------------- | 57 | //----------------------------------------------------------------------------- |
@@ -85,7 +61,7 @@ LLMotion* LLMotionTableEntry::create(const LLUUID &id) | |||
85 | // LLMotionRegistry() | 61 | // LLMotionRegistry() |
86 | // Class Constructor | 62 | // Class Constructor |
87 | //----------------------------------------------------------------------------- | 63 | //----------------------------------------------------------------------------- |
88 | LLMotionRegistry::LLMotionRegistry() : mMotionTable(LLMotionTableEntry::uuidEq, LLMotionTableEntry()) | 64 | LLMotionRegistry::LLMotionRegistry() |
89 | { | 65 | { |
90 | 66 | ||
91 | } | 67 | } |
@@ -97,19 +73,19 @@ LLMotionRegistry::LLMotionRegistry() : mMotionTable(LLMotionTableEntry::uuidEq, | |||
97 | //----------------------------------------------------------------------------- | 73 | //----------------------------------------------------------------------------- |
98 | LLMotionRegistry::~LLMotionRegistry() | 74 | LLMotionRegistry::~LLMotionRegistry() |
99 | { | 75 | { |
100 | mMotionTable.removeAll(); | 76 | mMotionTable.clear(); |
101 | } | 77 | } |
102 | 78 | ||
103 | 79 | ||
104 | //----------------------------------------------------------------------------- | 80 | //----------------------------------------------------------------------------- |
105 | // addMotion() | 81 | // addMotion() |
106 | //----------------------------------------------------------------------------- | 82 | //----------------------------------------------------------------------------- |
107 | BOOL LLMotionRegistry::addMotion( const LLUUID& id, LLMotionConstructor constructor ) | 83 | BOOL LLMotionRegistry::registerMotion( const LLUUID& id, LLMotionConstructor constructor ) |
108 | { | 84 | { |
109 | // llinfos << "Registering motion: " << name << llendl; | 85 | // llinfos << "Registering motion: " << name << llendl; |
110 | if (!mMotionTable.check(id)) | 86 | if (!is_in_map(mMotionTable, id)) |
111 | { | 87 | { |
112 | mMotionTable.set(id, LLMotionTableEntry(constructor, id)); | 88 | mMotionTable[id] = constructor; |
113 | return TRUE; | 89 | return TRUE; |
114 | } | 90 | } |
115 | 91 | ||
@@ -121,7 +97,7 @@ BOOL LLMotionRegistry::addMotion( const LLUUID& id, LLMotionConstructor construc | |||
121 | //----------------------------------------------------------------------------- | 97 | //----------------------------------------------------------------------------- |
122 | void LLMotionRegistry::markBad( const LLUUID& id ) | 98 | void LLMotionRegistry::markBad( const LLUUID& id ) |
123 | { | 99 | { |
124 | mMotionTable.set(id, LLMotionTableEntry()); | 100 | mMotionTable[id] = LLMotionConstructor(NULL); |
125 | } | 101 | } |
126 | 102 | ||
127 | //----------------------------------------------------------------------------- | 103 | //----------------------------------------------------------------------------- |
@@ -129,17 +105,17 @@ void LLMotionRegistry::markBad( const LLUUID& id ) | |||
129 | //----------------------------------------------------------------------------- | 105 | //----------------------------------------------------------------------------- |
130 | LLMotion *LLMotionRegistry::createMotion( const LLUUID &id ) | 106 | LLMotion *LLMotionRegistry::createMotion( const LLUUID &id ) |
131 | { | 107 | { |
132 | LLMotionTableEntry motion_entry = mMotionTable.get(id); | 108 | LLMotionConstructor constructor = get_if_there(mMotionTable, id, LLMotionConstructor(NULL)); |
133 | LLMotion* motion = NULL; | 109 | LLMotion* motion = NULL; |
134 | 110 | ||
135 | if ( motion_entry.getID().isNull() ) | 111 | if ( constructor == NULL ) |
136 | { | 112 | { |
137 | // *FIX: need to replace with a better default scheme. RN | 113 | // *FIX: need to replace with a better default scheme. RN |
138 | motion = LLKeyframeMotion::create(id); | 114 | motion = LLKeyframeMotion::create(id); |
139 | } | 115 | } |
140 | else | 116 | else |
141 | { | 117 | { |
142 | motion = motion_entry.create(id); | 118 | motion = constructor(id); |
143 | } | 119 | } |
144 | 120 | ||
145 | return motion; | 121 | return motion; |
@@ -155,18 +131,19 @@ LLMotion *LLMotionRegistry::createMotion( const LLUUID &id ) | |||
155 | // LLMotionController() | 131 | // LLMotionController() |
156 | // Class Constructor | 132 | // Class Constructor |
157 | //----------------------------------------------------------------------------- | 133 | //----------------------------------------------------------------------------- |
158 | LLMotionController::LLMotionController( ) | 134 | LLMotionController::LLMotionController() |
135 | : mTimeFactor(1.f), | ||
136 | mCharacter(NULL), | ||
137 | mAnimTime(0.f), | ||
138 | mPrevTimerElapsed(0.f), | ||
139 | mLastTime(0.0f), | ||
140 | mHasRunOnce(FALSE), | ||
141 | mPaused(FALSE), | ||
142 | mPauseTime(0.f), | ||
143 | mTimeStep(0.f), | ||
144 | mTimeStepCount(0), | ||
145 | mLastInterp(0.f) | ||
159 | { | 146 | { |
160 | mTime = 0.f; | ||
161 | mTimeOffset = 0.f; | ||
162 | mLastTime = 0.0f; | ||
163 | mHasRunOnce = FALSE; | ||
164 | mPaused = FALSE; | ||
165 | mPauseTime = 0.f; | ||
166 | mTimeStep = 0.f; | ||
167 | mTimeStepCount = 0; | ||
168 | mLastInterp = 0.f; | ||
169 | mTimeFactor = 1.f; | ||
170 | } | 147 | } |
171 | 148 | ||
172 | 149 | ||
@@ -179,6 +156,15 @@ LLMotionController::~LLMotionController() | |||
179 | deleteAllMotions(); | 156 | deleteAllMotions(); |
180 | } | 157 | } |
181 | 158 | ||
159 | void LLMotionController::incMotionCounts(S32& num_motions, S32& num_loading_motions, S32& num_loaded_motions, S32& num_active_motions, S32& num_deprecated_motions) | ||
160 | { | ||
161 | num_motions += mAllMotions.size(); | ||
162 | num_loading_motions += mLoadingMotions.size(); | ||
163 | num_loaded_motions += mLoadedMotions.size(); | ||
164 | num_active_motions += mActiveMotions.size(); | ||
165 | num_deprecated_motions += mDeprecatedMotions.size(); | ||
166 | } | ||
167 | |||
182 | //----------------------------------------------------------------------------- | 168 | //----------------------------------------------------------------------------- |
183 | // deleteAllMotions() | 169 | // deleteAllMotions() |
184 | //----------------------------------------------------------------------------- | 170 | //----------------------------------------------------------------------------- |
@@ -193,24 +179,38 @@ void LLMotionController::deleteAllMotions() | |||
193 | } | 179 | } |
194 | 180 | ||
195 | //----------------------------------------------------------------------------- | 181 | //----------------------------------------------------------------------------- |
196 | // addLoadedMotion() | 182 | // purgeExcessMotion() |
197 | //----------------------------------------------------------------------------- | 183 | //----------------------------------------------------------------------------- |
198 | void LLMotionController::addLoadedMotion(LLMotion* motionp) | 184 | void LLMotionController::purgeExcessMotions() |
199 | { | 185 | { |
200 | std::set<LLUUID> motions_to_kill; | 186 | if (mLoadedMotions.size() > MAX_MOTION_INSTANCES) |
187 | { | ||
188 | // clean up deprecated motions | ||
189 | for (motion_set_t::iterator deprecated_motion_it = mDeprecatedMotions.begin(); | ||
190 | deprecated_motion_it != mDeprecatedMotions.end(); ) | ||
191 | { | ||
192 | motion_set_t::iterator cur_iter = deprecated_motion_it++; | ||
193 | LLMotion* cur_motionp = *cur_iter; | ||
194 | if (!isMotionActive(cur_motionp)) | ||
195 | { | ||
196 | // Motion is deprecated so we know it's not cannonical, | ||
197 | // we can safely remove the instance | ||
198 | removeMotionInstance(cur_motionp); // modifies mDeprecatedMotions | ||
199 | mDeprecatedMotions.erase(cur_iter); | ||
200 | } | ||
201 | } | ||
202 | } | ||
201 | 203 | ||
202 | // gather all inactive, loaded motions | 204 | std::set<LLUUID> motions_to_kill; |
203 | if (mLoadedMotions.size() > MAX_MOTION_INSTANCES) | 205 | if (mLoadedMotions.size() > MAX_MOTION_INSTANCES) |
204 | { | 206 | { |
205 | // too many motions active this frame, kill all blenders | 207 | // too many motions active this frame, kill all blenders |
206 | mPoseBlender.clearBlenders(); | 208 | mPoseBlender.clearBlenders(); |
207 | 209 | for (motion_set_t::iterator loaded_motion_it = mLoadedMotions.begin(); | |
208 | for (motion_list_t::iterator loaded_motion_it = mLoadedMotions.begin(); | 210 | loaded_motion_it != mLoadedMotions.end(); |
209 | loaded_motion_it != mLoadedMotions.end(); | 211 | ++loaded_motion_it) |
210 | ++loaded_motion_it) | ||
211 | { | 212 | { |
212 | LLMotion* cur_motionp = *loaded_motion_it; | 213 | LLMotion* cur_motionp = *loaded_motion_it; |
213 | |||
214 | // motion isn't playing, delete it | 214 | // motion isn't playing, delete it |
215 | if (!isMotionActive(cur_motionp)) | 215 | if (!isMotionActive(cur_motionp)) |
216 | { | 216 | { |
@@ -218,7 +218,7 @@ void LLMotionController::addLoadedMotion(LLMotion* motionp) | |||
218 | } | 218 | } |
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||
222 | // clean up all inactive, loaded motions | 222 | // clean up all inactive, loaded motions |
223 | for (std::set<LLUUID>::iterator motion_it = motions_to_kill.begin(); | 223 | for (std::set<LLUUID>::iterator motion_it = motions_to_kill.begin(); |
224 | motion_it != motions_to_kill.end(); | 224 | motion_it != motions_to_kill.end(); |
@@ -234,8 +234,28 @@ void LLMotionController::addLoadedMotion(LLMotion* motionp) | |||
234 | } | 234 | } |
235 | } | 235 | } |
236 | 236 | ||
237 | // add new motion to loaded list | 237 | if (mLoadedMotions.size() > 2*MAX_MOTION_INSTANCES) |
238 | mLoadedMotions.push_back(motionp); | 238 | { |
239 | LL_WARNS_ONCE("Animation") << "> " << 2*MAX_MOTION_INSTANCES << " Loaded Motions" << llendl; | ||
240 | } | ||
241 | } | ||
242 | |||
243 | //----------------------------------------------------------------------------- | ||
244 | // deactivateStoppedMotions() | ||
245 | //----------------------------------------------------------------------------- | ||
246 | void LLMotionController::deactivateStoppedMotions() | ||
247 | { | ||
248 | // Since we're hidden, deactivate any stopped motions. | ||
249 | for (motion_list_t::iterator iter = mActiveMotions.begin(); | ||
250 | iter != mActiveMotions.end(); ) | ||
251 | { | ||
252 | motion_list_t::iterator curiter = iter++; | ||
253 | LLMotion* motionp = *curiter; | ||
254 | if (motionp->isStopped()) | ||
255 | { | ||
256 | deactivateMotionInstance(motionp); | ||
257 | } | ||
258 | } | ||
239 | } | 259 | } |
240 | 260 | ||
241 | //----------------------------------------------------------------------------- | 261 | //----------------------------------------------------------------------------- |
@@ -252,9 +272,10 @@ void LLMotionController::setTimeStep(F32 step) | |||
252 | iter != mActiveMotions.end(); ++iter) | 272 | iter != mActiveMotions.end(); ++iter) |
253 | { | 273 | { |
254 | LLMotion* motionp = *iter; | 274 | LLMotion* motionp = *iter; |
255 | motionp->mActivationTimestamp = (F32)llfloor(motionp->mActivationTimestamp / step) * step; | 275 | F32 activation_time = motionp->mActivationTimestamp; |
276 | motionp->mActivationTimestamp = (F32)(llfloor(activation_time / step)) * step; | ||
256 | BOOL stopped = motionp->isStopped(); | 277 | BOOL stopped = motionp->isStopped(); |
257 | motionp->setStopTime((F32)llfloor(motionp->getStopTime() / step) * step); | 278 | motionp->setStopTime((F32)(llfloor(motionp->getStopTime() / step)) * step); |
258 | motionp->setStopped(stopped); | 279 | motionp->setStopped(stopped); |
259 | motionp->mSendStopTimestamp = (F32)llfloor(motionp->mSendStopTimestamp / step) * step; | 280 | motionp->mSendStopTimestamp = (F32)llfloor(motionp->mSendStopTimestamp / step) * step; |
260 | } | 281 | } |
@@ -266,7 +287,6 @@ void LLMotionController::setTimeStep(F32 step) | |||
266 | //----------------------------------------------------------------------------- | 287 | //----------------------------------------------------------------------------- |
267 | void LLMotionController::setTimeFactor(F32 time_factor) | 288 | void LLMotionController::setTimeFactor(F32 time_factor) |
268 | { | 289 | { |
269 | mTimeOffset += mTimer.getElapsedTimeAndResetF32() * mTimeFactor; | ||
270 | mTimeFactor = time_factor; | 290 | mTimeFactor = time_factor; |
271 | } | 291 | } |
272 | 292 | ||
@@ -280,11 +300,11 @@ void LLMotionController::setCharacter(LLCharacter *character) | |||
280 | 300 | ||
281 | 301 | ||
282 | //----------------------------------------------------------------------------- | 302 | //----------------------------------------------------------------------------- |
283 | // addMotion() | 303 | // registerMotion() |
284 | //----------------------------------------------------------------------------- | 304 | //----------------------------------------------------------------------------- |
285 | BOOL LLMotionController::addMotion( const LLUUID& id, LLMotionConstructor constructor ) | 305 | BOOL LLMotionController::registerMotion( const LLUUID& id, LLMotionConstructor constructor ) |
286 | { | 306 | { |
287 | return sRegistry.addMotion(id, constructor); | 307 | return sRegistry.registerMotion(id, constructor); |
288 | } | 308 | } |
289 | 309 | ||
290 | //----------------------------------------------------------------------------- | 310 | //----------------------------------------------------------------------------- |
@@ -293,10 +313,8 @@ BOOL LLMotionController::addMotion( const LLUUID& id, LLMotionConstructor constr | |||
293 | void LLMotionController::removeMotion( const LLUUID& id) | 313 | void LLMotionController::removeMotion( const LLUUID& id) |
294 | { | 314 | { |
295 | LLMotion* motionp = findMotion(id); | 315 | LLMotion* motionp = findMotion(id); |
296 | |||
297 | removeMotionInstance(motionp); | ||
298 | |||
299 | mAllMotions.erase(id); | 316 | mAllMotions.erase(id); |
317 | removeMotionInstance(motionp); | ||
300 | } | 318 | } |
301 | 319 | ||
302 | // removes instance of a motion from all runtime structures, but does | 320 | // removes instance of a motion from all runtime structures, but does |
@@ -306,10 +324,11 @@ void LLMotionController::removeMotionInstance(LLMotion* motionp) | |||
306 | { | 324 | { |
307 | if (motionp) | 325 | if (motionp) |
308 | { | 326 | { |
309 | stopMotionInstance(motionp, TRUE); | 327 | llassert(findMotion(motionp->getID()) != motionp); |
310 | 328 | if (motionp->isActive()) | |
329 | motionp->deactivate(); | ||
311 | mLoadingMotions.erase(motionp); | 330 | mLoadingMotions.erase(motionp); |
312 | mLoadedMotions.remove(motionp); | 331 | mLoadedMotions.erase(motionp); |
313 | mActiveMotions.remove(motionp); | 332 | mActiveMotions.remove(motionp); |
314 | delete motionp; | 333 | delete motionp; |
315 | } | 334 | } |
@@ -320,6 +339,7 @@ void LLMotionController::removeMotionInstance(LLMotion* motionp) | |||
320 | //----------------------------------------------------------------------------- | 339 | //----------------------------------------------------------------------------- |
321 | LLMotion* LLMotionController::createMotion( const LLUUID &id ) | 340 | LLMotion* LLMotionController::createMotion( const LLUUID &id ) |
322 | { | 341 | { |
342 | LLMemType mt(LLMemType::MTYPE_ANIMATION); | ||
323 | // do we have an instance of this motion for this character? | 343 | // do we have an instance of this motion for this character? |
324 | LLMotion *motion = findMotion(id); | 344 | LLMotion *motion = findMotion(id); |
325 | 345 | ||
@@ -353,8 +373,8 @@ LLMotion* LLMotionController::createMotion( const LLUUID &id ) | |||
353 | mLoadingMotions.insert(motion); | 373 | mLoadingMotions.insert(motion); |
354 | break; | 374 | break; |
355 | case LLMotion::STATUS_SUCCESS: | 375 | case LLMotion::STATUS_SUCCESS: |
356 | // add motion to our list | 376 | // add motion to our list |
357 | addLoadedMotion(motion); | 377 | mLoadedMotions.insert(motion); |
358 | break; | 378 | break; |
359 | default: | 379 | default: |
360 | llerrs << "Invalid initialization status" << llendl; | 380 | llerrs << "Invalid initialization status" << llendl; |
@@ -377,6 +397,7 @@ BOOL LLMotionController::startMotion(const LLUUID &id, F32 start_offset) | |||
377 | // motion that is stopping will be allowed to stop but | 397 | // motion that is stopping will be allowed to stop but |
378 | // replaced by a new instance of that motion | 398 | // replaced by a new instance of that motion |
379 | if (motion | 399 | if (motion |
400 | && !mPaused | ||
380 | && motion->canDeprecate() | 401 | && motion->canDeprecate() |
381 | && motion->getFadeWeight() > 0.01f // not LOD-ed out | 402 | && motion->getFadeWeight() > 0.01f // not LOD-ed out |
382 | && (motion->isBlending() || motion->getStopTime() != 0.f)) | 403 | && (motion->isBlending() || motion->getStopTime() != 0.f)) |
@@ -403,7 +424,7 @@ BOOL LLMotionController::startMotion(const LLUUID &id, F32 start_offset) | |||
403 | } | 424 | } |
404 | 425 | ||
405 | // llinfos << "Starting motion " << name << llendl; | 426 | // llinfos << "Starting motion " << name << llendl; |
406 | return activateMotionInstance(motion, mTime - start_offset); | 427 | return activateMotionInstance(motion, mAnimTime - start_offset); |
407 | } | 428 | } |
408 | 429 | ||
409 | 430 | ||
@@ -414,7 +435,6 @@ BOOL LLMotionController::stopMotionLocally(const LLUUID &id, BOOL stop_immediate | |||
414 | { | 435 | { |
415 | // if already inactive, return false | 436 | // if already inactive, return false |
416 | LLMotion *motion = findMotion(id); | 437 | LLMotion *motion = findMotion(id); |
417 | |||
418 | return stopMotionInstance(motion, stop_immediate); | 438 | return stopMotionInstance(motion, stop_immediate); |
419 | } | 439 | } |
420 | 440 | ||
@@ -428,12 +448,7 @@ BOOL LLMotionController::stopMotionInstance(LLMotion* motion, BOOL stop_immediat | |||
428 | // If on active list, stop it | 448 | // If on active list, stop it |
429 | if (isMotionActive(motion) && !motion->isStopped()) | 449 | if (isMotionActive(motion) && !motion->isStopped()) |
430 | { | 450 | { |
431 | // when using timesteps, set stop time to last frame's time, otherwise grab current timer value | 451 | motion->setStopTime(mAnimTime); |
432 | // *FIX: should investigate this inconsistency...hints of obscure bugs | ||
433 | |||
434 | F32 stop_time = (mTimeStep != 0.f || mPaused) ? (mTime) : mTimeOffset + (mTimer.getElapsedTimeF32() * mTimeFactor); | ||
435 | motion->setStopTime(stop_time); | ||
436 | |||
437 | if (stop_immediate) | 452 | if (stop_immediate) |
438 | { | 453 | { |
439 | deactivateMotionInstance(motion); | 454 | deactivateMotionInstance(motion); |
@@ -449,7 +464,6 @@ BOOL LLMotionController::stopMotionInstance(LLMotion* motion, BOOL stop_immediat | |||
449 | return FALSE; | 464 | return FALSE; |
450 | } | 465 | } |
451 | 466 | ||
452 | |||
453 | //----------------------------------------------------------------------------- | 467 | //----------------------------------------------------------------------------- |
454 | // updateRegularMotions() | 468 | // updateRegularMotions() |
455 | //----------------------------------------------------------------------------- | 469 | //----------------------------------------------------------------------------- |
@@ -476,6 +490,59 @@ void LLMotionController::resetJointSignatures() | |||
476 | } | 490 | } |
477 | 491 | ||
478 | //----------------------------------------------------------------------------- | 492 | //----------------------------------------------------------------------------- |
493 | // updateIdleMotion() | ||
494 | // minimal updates for active motions | ||
495 | //----------------------------------------------------------------------------- | ||
496 | void LLMotionController::updateIdleMotion(LLMotion* motionp) | ||
497 | { | ||
498 | if (motionp->isStopped() && mAnimTime > motionp->getStopTime() + motionp->getEaseOutDuration()) | ||
499 | { | ||
500 | deactivateMotionInstance(motionp); | ||
501 | } | ||
502 | else if (motionp->isStopped() && mAnimTime > motionp->getStopTime()) | ||
503 | { | ||
504 | // is this the first iteration in the ease out phase? | ||
505 | if (mLastTime <= motionp->getStopTime()) | ||
506 | { | ||
507 | // store residual weight for this motion | ||
508 | motionp->mResidualWeight = motionp->getPose()->getWeight(); | ||
509 | } | ||
510 | } | ||
511 | else if (mAnimTime > motionp->mSendStopTimestamp) | ||
512 | { | ||
513 | // notify character of timed stop event on first iteration past sendstoptimestamp | ||
514 | // this will only be called when an animation stops itself (runs out of time) | ||
515 | if (mLastTime <= motionp->mSendStopTimestamp) | ||
516 | { | ||
517 | mCharacter->requestStopMotion( motionp ); | ||
518 | stopMotionInstance(motionp, FALSE); | ||
519 | } | ||
520 | } | ||
521 | else if (mAnimTime >= motionp->mActivationTimestamp) | ||
522 | { | ||
523 | if (mLastTime < motionp->mActivationTimestamp) | ||
524 | { | ||
525 | motionp->mResidualWeight = motionp->getPose()->getWeight(); | ||
526 | } | ||
527 | } | ||
528 | } | ||
529 | |||
530 | //----------------------------------------------------------------------------- | ||
531 | // updateIdleActiveMotions() | ||
532 | // Call this instead of updateMotionsByType for hidden avatars | ||
533 | //----------------------------------------------------------------------------- | ||
534 | void LLMotionController::updateIdleActiveMotions() | ||
535 | { | ||
536 | for (motion_list_t::iterator iter = mActiveMotions.begin(); | ||
537 | iter != mActiveMotions.end(); ) | ||
538 | { | ||
539 | motion_list_t::iterator curiter = iter++; | ||
540 | LLMotion* motionp = *curiter; | ||
541 | updateIdleMotion(motionp); | ||
542 | } | ||
543 | } | ||
544 | |||
545 | //----------------------------------------------------------------------------- | ||
479 | // updateMotionsByType() | 546 | // updateMotionsByType() |
480 | //----------------------------------------------------------------------------- | 547 | //----------------------------------------------------------------------------- |
481 | void LLMotionController::updateMotionsByType(LLMotion::LLMotionBlendType anim_type) | 548 | void LLMotionController::updateMotionsByType(LLMotion::LLMotionBlendType anim_type) |
@@ -530,36 +597,7 @@ void LLMotionController::updateMotionsByType(LLMotion::LLMotionBlendType anim_ty | |||
530 | 597 | ||
531 | if (!update_motion) | 598 | if (!update_motion) |
532 | { | 599 | { |
533 | if (motionp->isStopped() && mTime > motionp->getStopTime() + motionp->getEaseOutDuration()) | 600 | updateIdleMotion(motionp); |
534 | { | ||
535 | deactivateMotionInstance(motionp); | ||
536 | } | ||
537 | else if (motionp->isStopped() && mTime > motionp->getStopTime()) | ||
538 | { | ||
539 | // is this the first iteration in the ease out phase? | ||
540 | if (mLastTime <= motionp->getStopTime()) | ||
541 | { | ||
542 | // store residual weight for this motion | ||
543 | motionp->mResidualWeight = motionp->getPose()->getWeight(); | ||
544 | } | ||
545 | } | ||
546 | else if (mTime > motionp->mSendStopTimestamp) | ||
547 | { | ||
548 | // notify character of timed stop event on first iteration past sendstoptimestamp | ||
549 | // this will only be called when an animation stops itself (runs out of time) | ||
550 | if (mLastTime <= motionp->mSendStopTimestamp) | ||
551 | { | ||
552 | mCharacter->requestStopMotion( motionp ); | ||
553 | stopMotionInstance(motionp, FALSE); | ||
554 | } | ||
555 | } | ||
556 | else if (mTime >= motionp->mActivationTimestamp) | ||
557 | { | ||
558 | if (mLastTime < motionp->mActivationTimestamp) | ||
559 | { | ||
560 | motionp->mResidualWeight = motionp->getPose()->getWeight(); | ||
561 | } | ||
562 | } | ||
563 | continue; | 601 | continue; |
564 | } | 602 | } |
565 | 603 | ||
@@ -571,7 +609,7 @@ void LLMotionController::updateMotionsByType(LLMotion::LLMotionBlendType anim_ty | |||
571 | motionp->fadeOut(); | 609 | motionp->fadeOut(); |
572 | 610 | ||
573 | //should we notify the simulator that this motion should be stopped (check even if skipped by LOD logic) | 611 | //should we notify the simulator that this motion should be stopped (check even if skipped by LOD logic) |
574 | if (mTime > motionp->mSendStopTimestamp) | 612 | if (mAnimTime > motionp->mSendStopTimestamp) |
575 | { | 613 | { |
576 | // notify character of timed stop event on first iteration past sendstoptimestamp | 614 | // notify character of timed stop event on first iteration past sendstoptimestamp |
577 | // this will only be called when an animation stops itself (runs out of time) | 615 | // this will only be called when an animation stops itself (runs out of time) |
@@ -584,7 +622,7 @@ void LLMotionController::updateMotionsByType(LLMotion::LLMotionBlendType anim_ty | |||
584 | 622 | ||
585 | if (motionp->getFadeWeight() < 0.01f) | 623 | if (motionp->getFadeWeight() < 0.01f) |
586 | { | 624 | { |
587 | if (motionp->isStopped() && mTime > motionp->getStopTime() + motionp->getEaseOutDuration()) | 625 | if (motionp->isStopped() && mAnimTime > motionp->getStopTime() + motionp->getEaseOutDuration()) |
588 | { | 626 | { |
589 | posep->setWeight(0.f); | 627 | posep->setWeight(0.f); |
590 | deactivateMotionInstance(motionp); | 628 | deactivateMotionInstance(motionp); |
@@ -600,7 +638,7 @@ void LLMotionController::updateMotionsByType(LLMotion::LLMotionBlendType anim_ty | |||
600 | //********************** | 638 | //********************** |
601 | // MOTION INACTIVE | 639 | // MOTION INACTIVE |
602 | //********************** | 640 | //********************** |
603 | if (motionp->isStopped() && mTime > motionp->getStopTime() + motionp->getEaseOutDuration()) | 641 | if (motionp->isStopped() && mAnimTime > motionp->getStopTime() + motionp->getEaseOutDuration()) |
604 | { | 642 | { |
605 | // this motion has gone on too long, deactivate it | 643 | // this motion has gone on too long, deactivate it |
606 | // did we have a chance to stop it? | 644 | // did we have a chance to stop it? |
@@ -622,7 +660,7 @@ void LLMotionController::updateMotionsByType(LLMotion::LLMotionBlendType anim_ty | |||
622 | //********************** | 660 | //********************** |
623 | // MOTION EASE OUT | 661 | // MOTION EASE OUT |
624 | //********************** | 662 | //********************** |
625 | else if (motionp->isStopped() && mTime > motionp->getStopTime()) | 663 | else if (motionp->isStopped() && mAnimTime > motionp->getStopTime()) |
626 | { | 664 | { |
627 | // is this the first iteration in the ease out phase? | 665 | // is this the first iteration in the ease out phase? |
628 | if (mLastTime <= motionp->getStopTime()) | 666 | if (mLastTime <= motionp->getStopTime()) |
@@ -637,22 +675,22 @@ void LLMotionController::updateMotionsByType(LLMotion::LLMotionBlendType anim_ty | |||
637 | } | 675 | } |
638 | else | 676 | else |
639 | { | 677 | { |
640 | posep->setWeight(motionp->getFadeWeight() * motionp->mResidualWeight * cubic_step(1.f - ((mTime - motionp->getStopTime()) / motionp->getEaseOutDuration()))); | 678 | posep->setWeight(motionp->getFadeWeight() * motionp->mResidualWeight * cubic_step(1.f - ((mAnimTime - motionp->getStopTime()) / motionp->getEaseOutDuration()))); |
641 | } | 679 | } |
642 | 680 | ||
643 | // perform motion update | 681 | // perform motion update |
644 | update_result = motionp->onUpdate(mTime - motionp->mActivationTimestamp, last_joint_signature); | 682 | update_result = motionp->onUpdate(mAnimTime - motionp->mActivationTimestamp, last_joint_signature); |
645 | } | 683 | } |
646 | 684 | ||
647 | //********************** | 685 | //********************** |
648 | // MOTION ACTIVE | 686 | // MOTION ACTIVE |
649 | //********************** | 687 | //********************** |
650 | else if (mTime > motionp->mActivationTimestamp + motionp->getEaseInDuration()) | 688 | else if (mAnimTime > motionp->mActivationTimestamp + motionp->getEaseInDuration()) |
651 | { | 689 | { |
652 | posep->setWeight(motionp->getFadeWeight()); | 690 | posep->setWeight(motionp->getFadeWeight()); |
653 | 691 | ||
654 | //should we notify the simulator that this motion should be stopped? | 692 | //should we notify the simulator that this motion should be stopped? |
655 | if (mTime > motionp->mSendStopTimestamp) | 693 | if (mAnimTime > motionp->mSendStopTimestamp) |
656 | { | 694 | { |
657 | // notify character of timed stop event on first iteration past sendstoptimestamp | 695 | // notify character of timed stop event on first iteration past sendstoptimestamp |
658 | // this will only be called when an animation stops itself (runs out of time) | 696 | // this will only be called when an animation stops itself (runs out of time) |
@@ -664,13 +702,13 @@ void LLMotionController::updateMotionsByType(LLMotion::LLMotionBlendType anim_ty | |||
664 | } | 702 | } |
665 | 703 | ||
666 | // perform motion update | 704 | // perform motion update |
667 | update_result = motionp->onUpdate(mTime - motionp->mActivationTimestamp, last_joint_signature); | 705 | update_result = motionp->onUpdate(mAnimTime - motionp->mActivationTimestamp, last_joint_signature); |
668 | } | 706 | } |
669 | 707 | ||
670 | //********************** | 708 | //********************** |
671 | // MOTION EASE IN | 709 | // MOTION EASE IN |
672 | //********************** | 710 | //********************** |
673 | else if (mTime >= motionp->mActivationTimestamp) | 711 | else if (mAnimTime >= motionp->mActivationTimestamp) |
674 | { | 712 | { |
675 | if (mLastTime < motionp->mActivationTimestamp) | 713 | if (mLastTime < motionp->mActivationTimestamp) |
676 | { | 714 | { |
@@ -683,10 +721,10 @@ void LLMotionController::updateMotionsByType(LLMotion::LLMotionBlendType anim_ty | |||
683 | else | 721 | else |
684 | { | 722 | { |
685 | // perform motion update | 723 | // perform motion update |
686 | posep->setWeight(motionp->getFadeWeight() * motionp->mResidualWeight + (1.f - motionp->mResidualWeight) * cubic_step((mTime - motionp->mActivationTimestamp) / motionp->getEaseInDuration())); | 724 | posep->setWeight(motionp->getFadeWeight() * motionp->mResidualWeight + (1.f - motionp->mResidualWeight) * cubic_step((mAnimTime - motionp->mActivationTimestamp) / motionp->getEaseInDuration())); |
687 | } | 725 | } |
688 | // perform motion update | 726 | // perform motion update |
689 | update_result = motionp->onUpdate(mTime - motionp->mActivationTimestamp, last_joint_signature); | 727 | update_result = motionp->onUpdate(mAnimTime - motionp->mActivationTimestamp, last_joint_signature); |
690 | } | 728 | } |
691 | else | 729 | else |
692 | { | 730 | { |
@@ -697,7 +735,7 @@ void LLMotionController::updateMotionsByType(LLMotion::LLMotionBlendType anim_ty | |||
697 | // allow motions to deactivate themselves | 735 | // allow motions to deactivate themselves |
698 | if (!update_result) | 736 | if (!update_result) |
699 | { | 737 | { |
700 | if (!motionp->isStopped() || motionp->getStopTime() > mTime) | 738 | if (!motionp->isStopped() || motionp->getStopTime() > mAnimTime) |
701 | { | 739 | { |
702 | // animation has stopped itself due to internal logic | 740 | // animation has stopped itself due to internal logic |
703 | // propagate this to the network | 741 | // propagate this to the network |
@@ -713,18 +751,68 @@ void LLMotionController::updateMotionsByType(LLMotion::LLMotionBlendType anim_ty | |||
713 | } | 751 | } |
714 | } | 752 | } |
715 | 753 | ||
754 | //----------------------------------------------------------------------------- | ||
755 | // updateLoadingMotions() | ||
756 | //----------------------------------------------------------------------------- | ||
757 | void LLMotionController::updateLoadingMotions() | ||
758 | { | ||
759 | // query pending motions for completion | ||
760 | for (motion_set_t::iterator iter = mLoadingMotions.begin(); | ||
761 | iter != mLoadingMotions.end(); ) | ||
762 | { | ||
763 | motion_set_t::iterator curiter = iter++; | ||
764 | LLMotion* motionp = *curiter; | ||
765 | if( !motionp) | ||
766 | { | ||
767 | continue; // maybe shouldn't happen but i've seen it -MG | ||
768 | } | ||
769 | LLMotion::LLMotionInitStatus status = motionp->onInitialize(mCharacter); | ||
770 | if (status == LLMotion::STATUS_SUCCESS) | ||
771 | { | ||
772 | mLoadingMotions.erase(curiter); | ||
773 | // add motion to our loaded motion list | ||
774 | mLoadedMotions.insert(motionp); | ||
775 | // this motion should be playing | ||
776 | if (!motionp->isStopped()) | ||
777 | { | ||
778 | activateMotionInstance(motionp, mAnimTime); | ||
779 | } | ||
780 | } | ||
781 | else if (status == LLMotion::STATUS_FAILURE) | ||
782 | { | ||
783 | llinfos << "Motion " << motionp->getID() << " init failed." << llendl; | ||
784 | sRegistry.markBad(motionp->getID()); | ||
785 | mLoadingMotions.erase(curiter); | ||
786 | mAllMotions.erase(motionp->getID()); | ||
787 | delete motionp; | ||
788 | } | ||
789 | } | ||
790 | } | ||
791 | |||
792 | //----------------------------------------------------------------------------- | ||
793 | // call updateMotion() or updateMotionsMinimal() every frame | ||
794 | //----------------------------------------------------------------------------- | ||
716 | 795 | ||
717 | //----------------------------------------------------------------------------- | 796 | //----------------------------------------------------------------------------- |
718 | // updateMotion() | 797 | // updateMotion() |
719 | //----------------------------------------------------------------------------- | 798 | //----------------------------------------------------------------------------- |
720 | void LLMotionController::updateMotion() | 799 | void LLMotionController::updateMotions(bool force_update) |
721 | { | 800 | { |
722 | BOOL use_quantum = (mTimeStep != 0.f); | 801 | BOOL use_quantum = (mTimeStep != 0.f); |
723 | 802 | ||
803 | // Always update mPrevTimerElapsed | ||
804 | F32 cur_time = mTimer.getElapsedTimeF32(); | ||
805 | F32 delta_time = cur_time - mPrevTimerElapsed; | ||
806 | mPrevTimerElapsed = cur_time; | ||
807 | mLastTime = mAnimTime; | ||
808 | |||
809 | // Always cap the number of loaded motions | ||
810 | purgeExcessMotions(); | ||
811 | |||
724 | // Update timing info for this time step. | 812 | // Update timing info for this time step. |
725 | if (!mPaused) | 813 | if (!mPaused) |
726 | { | 814 | { |
727 | F32 update_time = mTimeOffset + (mTimer.getElapsedTimeF32() * mTimeFactor); | 815 | F32 update_time = mAnimTime + delta_time * mTimeFactor; |
728 | if (use_quantum) | 816 | if (use_quantum) |
729 | { | 817 | { |
730 | F32 time_interval = fmodf(update_time, mTimeStep); | 818 | F32 time_interval = fmodf(update_time, mTimeStep); |
@@ -740,7 +828,8 @@ void LLMotionController::updateMotion() | |||
740 | mPoseBlender.interpolate(interp - mLastInterp); | 828 | mPoseBlender.interpolate(interp - mLastInterp); |
741 | mLastInterp = interp; | 829 | mLastInterp = interp; |
742 | } | 830 | } |
743 | 831 | ||
832 | updateLoadingMotions(); | ||
744 | return; | 833 | return; |
745 | } | 834 | } |
746 | 835 | ||
@@ -749,53 +838,24 @@ void LLMotionController::updateMotion() | |||
749 | clearBlenders(); | 838 | clearBlenders(); |
750 | 839 | ||
751 | mTimeStepCount = quantum_count; | 840 | mTimeStepCount = quantum_count; |
752 | mLastTime = mTime; | 841 | mAnimTime = (F32)quantum_count * mTimeStep; |
753 | mTime = (F32)quantum_count * mTimeStep; | ||
754 | mLastInterp = 0.f; | 842 | mLastInterp = 0.f; |
755 | } | 843 | } |
756 | else | 844 | else |
757 | { | 845 | { |
758 | mLastTime = mTime; | 846 | mAnimTime = update_time; |
759 | mTime = update_time; | ||
760 | } | 847 | } |
761 | } | 848 | } |
762 | 849 | ||
763 | // query pending motions for completion | 850 | updateLoadingMotions(); |
764 | for (motion_set_t::iterator iter = mLoadingMotions.begin(); | ||
765 | iter != mLoadingMotions.end(); ) | ||
766 | { | ||
767 | motion_set_t::iterator curiter = iter++; | ||
768 | LLMotion* motionp = *curiter; | ||
769 | if( !motionp) | ||
770 | { | ||
771 | continue; // maybe shouldn't happen but i've seen it -MG | ||
772 | } | ||
773 | LLMotion::LLMotionInitStatus status = motionp->onInitialize(mCharacter); | ||
774 | if (status == LLMotion::STATUS_SUCCESS) | ||
775 | { | ||
776 | mLoadingMotions.erase(curiter); | ||
777 | // add motion to our loaded motion list | ||
778 | addLoadedMotion(motionp); | ||
779 | // this motion should be playing | ||
780 | if (!motionp->isStopped()) | ||
781 | { | ||
782 | activateMotionInstance(motionp, mTime); | ||
783 | } | ||
784 | } | ||
785 | else if (status == LLMotion::STATUS_FAILURE) | ||
786 | { | ||
787 | llinfos << "Motion " << motionp->getID() << " init failed." << llendl; | ||
788 | sRegistry.markBad(motionp->getID()); | ||
789 | mLoadingMotions.erase(curiter); | ||
790 | |||
791 | mAllMotions.erase(motionp->getID()); | ||
792 | delete motionp; | ||
793 | } | ||
794 | } | ||
795 | 851 | ||
796 | resetJointSignatures(); | 852 | resetJointSignatures(); |
797 | 853 | ||
798 | if (!mPaused) | 854 | if (mPaused && !force_update) |
855 | { | ||
856 | updateIdleActiveMotions(); | ||
857 | } | ||
858 | else | ||
799 | { | 859 | { |
800 | // update additive motions | 860 | // update additive motions |
801 | updateAdditiveMotions(); | 861 | updateAdditiveMotions(); |
@@ -818,6 +878,23 @@ void LLMotionController::updateMotion() | |||
818 | // llinfos << "Motion controller time " << motionTimer.getElapsedTimeF32() << llendl; | 878 | // llinfos << "Motion controller time " << motionTimer.getElapsedTimeF32() << llendl; |
819 | } | 879 | } |
820 | 880 | ||
881 | //----------------------------------------------------------------------------- | ||
882 | // updateMotionsMinimal() | ||
883 | // minimal update (e.g. while hidden) | ||
884 | //----------------------------------------------------------------------------- | ||
885 | void LLMotionController::updateMotionsMinimal() | ||
886 | { | ||
887 | // Always update mPrevTimerElapsed | ||
888 | mPrevTimerElapsed = mTimer.getElapsedTimeF32(); | ||
889 | |||
890 | purgeExcessMotions(); | ||
891 | updateLoadingMotions(); | ||
892 | resetJointSignatures(); | ||
893 | |||
894 | deactivateStoppedMotions(); | ||
895 | |||
896 | mHasRunOnce = TRUE; | ||
897 | } | ||
821 | 898 | ||
822 | //----------------------------------------------------------------------------- | 899 | //----------------------------------------------------------------------------- |
823 | // activateMotionInstance() | 900 | // activateMotionInstance() |
@@ -840,7 +917,6 @@ BOOL LLMotionController::activateMotionInstance(LLMotion *motion, F32 time) | |||
840 | } | 917 | } |
841 | 918 | ||
842 | motion->mResidualWeight = motion->getPose()->getWeight(); | 919 | motion->mResidualWeight = motion->getPose()->getWeight(); |
843 | motion->mActivationTimestamp = time; | ||
844 | 920 | ||
845 | // set stop time based on given duration and ease out time | 921 | // set stop time based on given duration and ease out time |
846 | if (motion->getDuration() != 0.f && !motion->getLoop()) | 922 | if (motion->getDuration() != 0.f && !motion->getLoop()) |
@@ -861,13 +937,26 @@ BOOL LLMotionController::activateMotionInstance(LLMotion *motion, F32 time) | |||
861 | { | 937 | { |
862 | motion->mSendStopTimestamp = F32_MAX; | 938 | motion->mSendStopTimestamp = F32_MAX; |
863 | } | 939 | } |
864 | 940 | ||
865 | mActiveMotions.remove(motion); // in case it is already in the active list | 941 | if (motion->isActive()) |
942 | { | ||
943 | mActiveMotions.remove(motion); | ||
944 | } | ||
866 | mActiveMotions.push_front(motion); | 945 | mActiveMotions.push_front(motion); |
867 | 946 | ||
868 | motion->activate(); | 947 | motion->activate(time); |
869 | motion->onUpdate(0.f, mJointSignature[1]); | 948 | motion->onUpdate(0.f, mJointSignature[1]); |
870 | 949 | ||
950 | if (mAnimTime >= motion->mSendStopTimestamp) | ||
951 | { | ||
952 | motion->setStopTime(motion->mSendStopTimestamp); | ||
953 | if (motion->mResidualWeight == 0.0f) | ||
954 | { | ||
955 | // bit of a hack; if newly activating a motion while easing out, weight should = 1 | ||
956 | motion->mResidualWeight = 1.f; | ||
957 | } | ||
958 | } | ||
959 | |||
871 | return TRUE; | 960 | return TRUE; |
872 | } | 961 | } |
873 | 962 | ||
@@ -924,9 +1013,17 @@ bool LLMotionController::isMotionLoading(LLMotion* motion) | |||
924 | //----------------------------------------------------------------------------- | 1013 | //----------------------------------------------------------------------------- |
925 | // findMotion() | 1014 | // findMotion() |
926 | //----------------------------------------------------------------------------- | 1015 | //----------------------------------------------------------------------------- |
927 | LLMotion *LLMotionController::findMotion(const LLUUID& id) | 1016 | LLMotion* LLMotionController::findMotion(const LLUUID& id) |
928 | { | 1017 | { |
929 | return get_if_there<LLUUID, LLMotion*>(mAllMotions, id, NULL); | 1018 | motion_map_t::iterator iter = mAllMotions.find(id); |
1019 | if(iter == mAllMotions.end()) | ||
1020 | { | ||
1021 | return NULL; | ||
1022 | } | ||
1023 | else | ||
1024 | { | ||
1025 | return iter->second; | ||
1026 | } | ||
930 | } | 1027 | } |
931 | 1028 | ||
932 | //----------------------------------------------------------------------------- | 1029 | //----------------------------------------------------------------------------- |
@@ -934,16 +1031,12 @@ LLMotion *LLMotionController::findMotion(const LLUUID& id) | |||
934 | //----------------------------------------------------------------------------- | 1031 | //----------------------------------------------------------------------------- |
935 | void LLMotionController::deactivateAllMotions() | 1032 | void LLMotionController::deactivateAllMotions() |
936 | { | 1033 | { |
937 | //They must all die, precious. | 1034 | for (motion_map_t::iterator iter = mAllMotions.begin(); |
938 | for (std::map<LLUUID, LLMotion*>::iterator iter = mAllMotions.begin(); | ||
939 | iter != mAllMotions.end(); iter++) | 1035 | iter != mAllMotions.end(); iter++) |
940 | { | 1036 | { |
941 | LLMotion* motionp = iter->second; | 1037 | LLMotion* motionp = iter->second; |
942 | if (motionp) motionp->deactivate(); | 1038 | deactivateMotionInstance(motionp); |
943 | } | 1039 | } |
944 | |||
945 | // delete all motion instances | ||
946 | deleteAllMotions(); | ||
947 | } | 1040 | } |
948 | 1041 | ||
949 | 1042 | ||
@@ -959,11 +1052,12 @@ void LLMotionController::flushAllMotions() | |||
959 | { | 1052 | { |
960 | motion_list_t::iterator curiter = iter++; | 1053 | motion_list_t::iterator curiter = iter++; |
961 | LLMotion* motionp = *curiter; | 1054 | LLMotion* motionp = *curiter; |
962 | F32 dtime = mTime - motionp->mActivationTimestamp; | 1055 | F32 dtime = mAnimTime - motionp->mActivationTimestamp; |
963 | active_motions.push_back(std::make_pair(motionp->getID(),dtime)); | 1056 | active_motions.push_back(std::make_pair(motionp->getID(),dtime)); |
964 | motionp->deactivate(); | 1057 | motionp->deactivate(); // don't call deactivateMotionInstance() because we are going to reactivate it |
965 | } | 1058 | } |
966 | 1059 | mActiveMotions.clear(); | |
1060 | |||
967 | // delete all motion instances | 1061 | // delete all motion instances |
968 | deleteAllMotions(); | 1062 | deleteAllMotions(); |
969 | 1063 | ||
@@ -982,12 +1076,11 @@ void LLMotionController::flushAllMotions() | |||
982 | //----------------------------------------------------------------------------- | 1076 | //----------------------------------------------------------------------------- |
983 | // pause() | 1077 | // pause() |
984 | //----------------------------------------------------------------------------- | 1078 | //----------------------------------------------------------------------------- |
985 | void LLMotionController::pause() | 1079 | void LLMotionController::pauseAllMotions() |
986 | { | 1080 | { |
987 | if (!mPaused) | 1081 | if (!mPaused) |
988 | { | 1082 | { |
989 | //llinfos << "Pausing animations..." << llendl; | 1083 | //llinfos << "Pausing animations..." << llendl; |
990 | mPauseTime = mTimer.getElapsedTimeF32(); | ||
991 | mPaused = TRUE; | 1084 | mPaused = TRUE; |
992 | } | 1085 | } |
993 | 1086 | ||
@@ -996,13 +1089,11 @@ void LLMotionController::pause() | |||
996 | //----------------------------------------------------------------------------- | 1089 | //----------------------------------------------------------------------------- |
997 | // unpause() | 1090 | // unpause() |
998 | //----------------------------------------------------------------------------- | 1091 | //----------------------------------------------------------------------------- |
999 | void LLMotionController::unpause() | 1092 | void LLMotionController::unpauseAllMotions() |
1000 | { | 1093 | { |
1001 | if (mPaused) | 1094 | if (mPaused) |
1002 | { | 1095 | { |
1003 | //llinfos << "Unpausing animations..." << llendl; | 1096 | //llinfos << "Unpausing animations..." << llendl; |
1004 | mTimer.reset(); | ||
1005 | mTimer.setAge(mPauseTime); | ||
1006 | mPaused = FALSE; | 1097 | mPaused = FALSE; |
1007 | } | 1098 | } |
1008 | } | 1099 | } |