From 117e22047c5752352342d64e3fb7ce00a4eb8113 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Fri, 15 Aug 2008 23:45:04 -0500 Subject: Second Life viewer sources 1.18.1.2 --- linden/indra/llcharacter/llmotioncontroller.cpp | 157 ++++++++++++++++-------- 1 file changed, 106 insertions(+), 51 deletions(-) (limited to 'linden/indra/llcharacter/llmotioncontroller.cpp') diff --git a/linden/indra/llcharacter/llmotioncontroller.cpp b/linden/indra/llcharacter/llmotioncontroller.cpp index 2427fd8..aebfaf6 100644 --- a/linden/indra/llcharacter/llmotioncontroller.cpp +++ b/linden/indra/llcharacter/llmotioncontroller.cpp @@ -194,34 +194,44 @@ void LLMotionController::deleteAllMotions() //----------------------------------------------------------------------------- void LLMotionController::addLoadedMotion(LLMotion* motionp) { + std::set motions_to_kill; + + // gather all inactive, loaded motions if (mLoadedMotions.size() > MAX_MOTION_INSTANCES) { // too many motions active this frame, kill all blenders mPoseBlender.clearBlenders(); - for (U32 i = 0; i < mLoadedMotions.size(); i++) + for (motion_list_t::iterator loaded_motion_it = mLoadedMotions.begin(); + loaded_motion_it != mLoadedMotions.end(); + ++loaded_motion_it) { - LLMotion* cur_motionp = mLoadedMotions.front(); - mLoadedMotions.pop_front(); + LLMotion* cur_motionp = *loaded_motion_it; // motion isn't playing, delete it if (!isMotionActive(cur_motionp)) { - mCharacter->requestStopMotion(cur_motionp); - mAllMotions.erase(cur_motionp->getID()); - delete cur_motionp; - if (mLoadedMotions.size() <= MAX_MOTION_INSTANCES) - { - break; - } - } - else - { - // put active motion on back - mLoadedMotions.push_back(cur_motionp); + motions_to_kill.insert(cur_motionp->getID()); } } } + + // clean up all inactive, loaded motions + for (std::set::iterator motion_it = motions_to_kill.begin(); + motion_it != motions_to_kill.end(); + ++motion_it) + { + // look up the motion again by ID to get canonical instance + // and kill it only if that one is inactive + LLUUID motion_id = *motion_it; + LLMotion* motionp = findMotion(motion_id); + if (motionp && !isMotionActive(motionp)) + { + removeMotion(motion_id); + } + } + + // add new motion to loaded list mLoadedMotions.push_back(motionp); } @@ -280,14 +290,24 @@ BOOL LLMotionController::addMotion( const LLUUID& id, LLMotionConstructor constr void LLMotionController::removeMotion( const LLUUID& id) { LLMotion* motionp = findMotion(id); + + removeMotionInstance(motionp); + + mAllMotions.erase(id); +} + +// removes instance of a motion from all runtime structures, but does +// not erase entry by ID, as this could be a duplicate instance +// use removeMotion(id) to remove all references to a given motion by id. +void LLMotionController::removeMotionInstance(LLMotion* motionp) +{ if (motionp) { - stopMotionLocally(id, TRUE); + stopMotionInstance(motionp, TRUE); mLoadingMotions.erase(motionp); mLoadedMotions.remove(motionp); mActiveMotions.remove(motionp); - mAllMotions.erase(id); delete motionp; } } @@ -348,28 +368,39 @@ LLMotion* LLMotionController::createMotion( const LLUUID &id ) //----------------------------------------------------------------------------- BOOL LLMotionController::startMotion(const LLUUID &id, F32 start_offset) { - // look for motion in our list of created motions - LLMotion *motion = createMotion(id); + // do we have an instance of this motion for this character? + LLMotion *motion = findMotion(id); + + // motion that is stopping will be allowed to stop but + // replaced by a new instance of that motion + if (motion + && motion->canDeprecate() + && motion->getFadeWeight() > 0.01f // not LOD-ed out + && (motion->isBlending() || motion->getStopTime() != 0.f)) + { + deprecateMotionInstance(motion); + // force creation of new instance + motion = NULL; + } + + // create new motion instance + if (!motion) + { + motion = createMotion(id); + } if (!motion) { return FALSE; } - //if the motion is already active, then we're done - else if (isMotionActive(motion)) // motion is playing and... + //if the motion is already active and allows deprecation, then let it keep playing + else if (motion->canDeprecate() && isMotionActive(motion)) { - if (motion->isStopped()) // motion has been stopped - { - deactivateMotion(motion, false); - } - else if (mTime < motion->mSendStopTimestamp) // motion is still active - { - return TRUE; - } + return TRUE; } // llinfos << "Starting motion " << name << llendl; - return activateMotion(motion, mTime - start_offset); + return activateMotionInstance(motion, mTime - start_offset); } @@ -380,6 +411,12 @@ BOOL LLMotionController::stopMotionLocally(const LLUUID &id, BOOL stop_immediate { // if already inactive, return false LLMotion *motion = findMotion(id); + + return stopMotionInstance(motion, stop_immediate); +} + +BOOL LLMotionController::stopMotionInstance(LLMotion* motion, BOOL stop_immediate) +{ if (!motion) { return FALSE; @@ -396,7 +433,7 @@ BOOL LLMotionController::stopMotionLocally(const LLUUID &id, BOOL stop_immediate if (stop_immediate) { - deactivateMotion(motion, false); + deactivateMotionInstance(motion); } return TRUE; } @@ -492,7 +529,7 @@ void LLMotionController::updateMotionsByType(LLMotion::LLMotionBlendType anim_ty { if (motionp->isStopped() && mTime > motionp->getStopTime() + motionp->getEaseOutDuration()) { - deactivateMotion(motionp, false); + deactivateMotionInstance(motionp); } else if (motionp->isStopped() && mTime > motionp->getStopTime()) { @@ -510,7 +547,7 @@ void LLMotionController::updateMotionsByType(LLMotion::LLMotionBlendType anim_ty if (mLastTime <= motionp->mSendStopTimestamp) { mCharacter->requestStopMotion( motionp ); - stopMotionLocally(motionp->getID(), FALSE); + stopMotionInstance(motionp, FALSE); } } else if (mTime >= motionp->mActivationTimestamp) @@ -538,7 +575,7 @@ void LLMotionController::updateMotionsByType(LLMotion::LLMotionBlendType anim_ty if (mLastTime <= motionp->mSendStopTimestamp) { mCharacter->requestStopMotion( motionp ); - stopMotionLocally(motionp->getID(), FALSE); + stopMotionInstance(motionp, FALSE); } } @@ -546,7 +583,8 @@ void LLMotionController::updateMotionsByType(LLMotion::LLMotionBlendType anim_ty { if (motionp->isStopped() && mTime > motionp->getStopTime() + motionp->getEaseOutDuration()) { - deactivateMotion(motionp, true); + posep->setWeight(0.f); + deactivateMotionInstance(motionp); } continue; } @@ -572,7 +610,8 @@ void LLMotionController::updateMotionsByType(LLMotion::LLMotionBlendType anim_ty } else { - deactivateMotion(motionp, true); + posep->setWeight(0.f); + deactivateMotionInstance(motionp); continue; } } @@ -617,7 +656,7 @@ void LLMotionController::updateMotionsByType(LLMotion::LLMotionBlendType anim_ty if (mLastTime <= motionp->mSendStopTimestamp) { mCharacter->requestStopMotion( motionp ); - stopMotionLocally(motionp->getID(), FALSE); + stopMotionInstance(motionp, FALSE); } } @@ -661,7 +700,7 @@ void LLMotionController::updateMotionsByType(LLMotion::LLMotionBlendType anim_ty // propagate this to the network // as not all viewers are guaranteed to have access to the same logic mCharacter->requestStopMotion( motionp ); - stopMotionLocally(motionp->getID(), FALSE); + stopMotionInstance(motionp, FALSE); } } @@ -733,7 +772,7 @@ void LLMotionController::updateMotion() // this motion should be playing if (!motionp->isStopped()) { - activateMotion(motionp, mTime); + activateMotionInstance(motionp, mTime); } } else if (status == LLMotion::STATUS_FAILURE) @@ -741,6 +780,7 @@ void LLMotionController::updateMotion() llinfos << "Motion " << motionp->getID() << " init failed." << llendl; sRegistry.markBad(motionp->getID()); mLoadingMotions.erase(curiter); + mAllMotions.erase(motionp->getID()); delete motionp; } @@ -773,9 +813,9 @@ void LLMotionController::updateMotion() //----------------------------------------------------------------------------- -// activateMotion() +// activateMotionInstance() //----------------------------------------------------------------------------- -BOOL LLMotionController::activateMotion(LLMotion *motion, F32 time) +BOOL LLMotionController::activateMotionInstance(LLMotion *motion, F32 time) { if (mLoadingMotions.find(motion) != mLoadingMotions.end()) { @@ -818,23 +858,38 @@ BOOL LLMotionController::activateMotion(LLMotion *motion, F32 time) } //----------------------------------------------------------------------------- -// deactivateMotion() +// deactivateMotionInstance() //----------------------------------------------------------------------------- -BOOL LLMotionController::deactivateMotion(LLMotion *motion, bool remove_weight) +BOOL LLMotionController::deactivateMotionInstance(LLMotion *motion) { - if( remove_weight ) + motion->deactivate(); + + motion_set_t::iterator found_it = mDeprecatedMotions.find(motion); + if (found_it != mDeprecatedMotions.end()) { - // immediately remove pose weighting instead of letting it time out - LLPose *posep = motion->getPose(); - posep->setWeight(0.f); + // deprecated motions need to be completely excised + removeMotionInstance(motion); + mDeprecatedMotions.erase(found_it); + } + else + { + // for motions that we are keeping, simply remove from active queue + mActiveMotions.remove(motion); } - - motion->deactivate(); - mActiveMotions.remove(motion); return TRUE; } +void LLMotionController::deprecateMotionInstance(LLMotion* motion) +{ + mDeprecatedMotions.insert(motion); + + //fade out deprecated motion + stopMotionInstance(motion, FALSE); + //no longer canonical + mAllMotions.erase(motion->getID()); +} + //----------------------------------------------------------------------------- // isMotionActive() //----------------------------------------------------------------------------- @@ -857,7 +912,7 @@ bool LLMotionController::isMotionLoading(LLMotion* motion) //----------------------------------------------------------------------------- LLMotion *LLMotionController::findMotion(const LLUUID& id) { - return mAllMotions[id]; + return get_if_there(mAllMotions, id, NULL); } //----------------------------------------------------------------------------- -- cgit v1.1