From cd17687f01420952712a500107e0f93e7ab8d5f8 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Fri, 15 Aug 2008 23:45:34 -0500 Subject: Second Life viewer sources 1.19.1.0 --- linden/indra/llcharacter/llcharacter.cpp | 26 +- linden/indra/llcharacter/llcharacter.h | 5 +- linden/indra/llcharacter/llcharacter_vc8.vcproj | 838 ++++++++++---------- linden/indra/llcharacter/llcharacter_vc9.vcproj | 840 ++++++++++----------- linden/indra/llcharacter/llkeyframemotion.cpp | 295 +++----- linden/indra/llcharacter/llkeyframemotion.h | 11 +- linden/indra/llcharacter/llkeyframemotionparam.cpp | 149 ++-- linden/indra/llcharacter/llkeyframemotionparam.h | 16 +- linden/indra/llcharacter/llmotioncontroller.cpp | 9 +- linden/indra/llcharacter/llmotioncontroller.h | 2 + linden/indra/llcharacter/llpose.cpp | 23 +- linden/indra/llcharacter/llpose.h | 2 - linden/indra/llcharacter/llstatemachine.h | 1 - 13 files changed, 1073 insertions(+), 1144 deletions(-) (limited to 'linden/indra/llcharacter') diff --git a/linden/indra/llcharacter/llcharacter.cpp b/linden/indra/llcharacter/llcharacter.cpp index af4c5aa..0339cf0 100644 --- a/linden/indra/llcharacter/llcharacter.cpp +++ b/linden/indra/llcharacter/llcharacter.cpp @@ -241,33 +241,15 @@ void LLCharacter::dumpCharacter( LLJoint* joint ) //----------------------------------------------------------------------------- void LLCharacter::setAnimationData(std::string name, void *data) { - if(mAnimationData.getValue(name)) - { - *mAnimationData[name] = data; - } - else - { - mAnimationData.addToHead(name, data); - } + mAnimationData[name] = data; } //----------------------------------------------------------------------------- // getAnimationData() //----------------------------------------------------------------------------- -void * LLCharacter::getAnimationData(std::string name) +void* LLCharacter::getAnimationData(std::string name) { - void **result = mAnimationData.getValue(name); - void *return_value; // Necessary to suppress VC6 warning. JC - if (!result) - { - return_value = NULL; - } - else - { - return_value = *result; - } - - return return_value; + return get_if_there(mAnimationData, name, (void*)NULL); } //----------------------------------------------------------------------------- @@ -275,7 +257,7 @@ void * LLCharacter::getAnimationData(std::string name) //----------------------------------------------------------------------------- void LLCharacter::removeAnimationData(std::string name) { - mAnimationData.remove(name); + mAnimationData.erase(name); } //----------------------------------------------------------------------------- diff --git a/linden/indra/llcharacter/llcharacter.h b/linden/indra/llcharacter/llcharacter.h index 6699796..46faab1 100644 --- a/linden/indra/llcharacter/llcharacter.h +++ b/linden/indra/llcharacter/llcharacter.h @@ -39,9 +39,7 @@ #include "lljoint.h" #include "llmotioncontroller.h" -#include "llassoclist.h" #include "llvisualparam.h" -#include "linked_lists.h" #include "string_table.h" #include "llmemory.h" #include "llthread.h" @@ -255,7 +253,8 @@ public: protected: LLMotionController mMotionController; - LLAssocList mAnimationData; + typedef std::map animation_data_map_t; + animation_data_map_t mAnimationData; F32 mPreferredPelvisHeight; ESex mSex; diff --git a/linden/indra/llcharacter/llcharacter_vc8.vcproj b/linden/indra/llcharacter/llcharacter_vc8.vcproj index 00ceb88..fdad9c2 100644 --- a/linden/indra/llcharacter/llcharacter_vc8.vcproj +++ b/linden/indra/llcharacter/llcharacter_vc8.vcproj @@ -1,419 +1,419 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/linden/indra/llcharacter/llcharacter_vc9.vcproj b/linden/indra/llcharacter/llcharacter_vc9.vcproj index 13e3b14..837ec04 100644 --- a/linden/indra/llcharacter/llcharacter_vc9.vcproj +++ b/linden/indra/llcharacter/llcharacter_vc9.vcproj @@ -1,420 +1,420 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/linden/indra/llcharacter/llkeyframemotion.cpp b/linden/indra/llcharacter/llkeyframemotion.cpp index 4288b8d..0138860 100644 --- a/linden/indra/llcharacter/llkeyframemotion.cpp +++ b/linden/indra/llcharacter/llkeyframemotion.cpp @@ -122,6 +122,7 @@ U32 LLKeyframeMotion::JointMotionList::dumpDiagInfo() //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- + //----------------------------------------------------------------------------- // ScaleCurve::ScaleCurve() //----------------------------------------------------------------------------- @@ -136,7 +137,7 @@ LLKeyframeMotion::ScaleCurve::ScaleCurve() //----------------------------------------------------------------------------- LLKeyframeMotion::ScaleCurve::~ScaleCurve() { - mKeys.deleteAllData(); + mKeys.clear(); mNumKeys = 0; } @@ -146,43 +147,42 @@ LLKeyframeMotion::ScaleCurve::~ScaleCurve() LLVector3 LLKeyframeMotion::ScaleCurve::getValue(F32 time, F32 duration) { LLVector3 value; - F32 index_before, index_after; - ScaleKey* scale_before; - ScaleKey* scale_after; - mKeys.getInterval(time, index_before, index_after, scale_before, scale_after); - if (scale_before) + if (mKeys.empty()) { - if (!scale_after) - { - scale_after = &mLoopInKey; - index_after = duration; - } - - if (index_after == index_before) - { - value = scale_after->mScale; - } - else - { - F32 u = (time - index_before) / (index_after - index_before); - value = interp(u, *scale_before, *scale_after); - } + value.clearVec(); + return value; + } + + key_map_t::iterator right = mKeys.lower_bound(time); + if (right == mKeys.end()) + { + // Past last key + --right; + value = right->second.mScale; + } + else if (right == mKeys.begin() || right->first == time) + { + // Before first key or exactly on a key + value = right->second.mScale; } else { - // before first key - if (scale_after) - { - value = scale_after->mScale; - } - // no keys? - else + // Between two keys + key_map_t::iterator left = right; --left; + F32 index_before = left->first; + F32 index_after = right->first; + ScaleKey& scale_before = left->second; + ScaleKey& scale_after = right->second; + if (right == mKeys.end()) { - value.clearVec(); + scale_after = mLoopInKey; + index_after = duration; } - } + F32 u = (time - index_before) / (index_after - index_before); + value = interp(u, scale_before, scale_after); + } return value; } @@ -217,7 +217,7 @@ LLKeyframeMotion::RotationCurve::RotationCurve() //----------------------------------------------------------------------------- LLKeyframeMotion::RotationCurve::~RotationCurve() { - mKeys.deleteAllData(); + mKeys.clear(); mNumKeys = 0; } @@ -227,44 +227,42 @@ LLKeyframeMotion::RotationCurve::~RotationCurve() LLQuaternion LLKeyframeMotion::RotationCurve::getValue(F32 time, F32 duration) { LLQuaternion value; - F32 index_before, index_after; - RotationKey* rot_before; - RotationKey* rot_after; - mKeys.getInterval(time, index_before, index_after, rot_before, rot_after); - - if (rot_before) + if (mKeys.empty()) { - if (!rot_after) - { - rot_after = &mLoopInKey; - index_after = duration; - } - - if (index_after == index_before) - { - value = rot_after->mRotation; - } - else - { - F32 u = (time - index_before) / (index_after - index_before); - value = interp(u, *rot_before, *rot_after); - } + value = LLQuaternion::DEFAULT; + return value; + } + + key_map_t::iterator right = mKeys.lower_bound(time); + if (right == mKeys.end()) + { + // Past last key + --right; + value = right->second.mRotation; + } + else if (right == mKeys.begin() || right->first == time) + { + // Before first key or exactly on a key + value = right->second.mRotation; } else { - // before first key - if (rot_after) + // Between two keys + key_map_t::iterator left = right; --left; + F32 index_before = left->first; + F32 index_after = right->first; + RotationKey& rot_before = left->second; + RotationKey& rot_after = right->second; + if (right == mKeys.end()) { - value = rot_after->mRotation; - } - // no keys? - else - { - value = LLQuaternion::DEFAULT; + rot_after = mLoopInKey; + index_after = duration; } - } + F32 u = (time - index_before) / (index_after - index_before); + value = interp(u, rot_before, rot_after); + } return value; } @@ -300,7 +298,7 @@ LLKeyframeMotion::PositionCurve::PositionCurve() //----------------------------------------------------------------------------- LLKeyframeMotion::PositionCurve::~PositionCurve() { - mKeys.deleteAllData(); + mKeys.clear(); mNumKeys = 0; } @@ -310,46 +308,45 @@ LLKeyframeMotion::PositionCurve::~PositionCurve() LLVector3 LLKeyframeMotion::PositionCurve::getValue(F32 time, F32 duration) { LLVector3 value; - F32 index_before, index_after; - PositionKey* pos_before; - PositionKey* pos_after; - - mKeys.getInterval(time, index_before, index_after, pos_before, pos_after); - if (pos_before) + if (mKeys.empty()) { - if (!pos_after) - { - pos_after = &mLoopInKey; - index_after = duration; - } - - if (index_after == index_before) - { - value = pos_after->mPosition; - } - else - { - F32 u = (time - index_before) / (index_after - index_before); - value = interp(u, *pos_before, *pos_after); - } + value.clearVec(); + return value; + } + + key_map_t::iterator right = mKeys.lower_bound(time); + if (right == mKeys.end()) + { + // Past last key + --right; + value = right->second.mPosition; + } + else if (right == mKeys.begin() || right->first == time) + { + // Before first key or exactly on a key + value = right->second.mPosition; } else { - // before first key - if (pos_after) + // Between two keys + key_map_t::iterator left = right; --left; + F32 index_before = left->first; + F32 index_after = right->first; + PositionKey& pos_before = left->second; + PositionKey& pos_after = right->second; + if (right == mKeys.end()) { - value = pos_after->mPosition; - } - // no keys? - else - { - value.clearVec(); + pos_after = mLoopInKey; + index_after = duration; } + + F32 u = (time - index_before) / (index_after - index_before); + value = interp(u, pos_before, pos_after); } llassert(value.isFinite()); - + return value; } @@ -1404,8 +1401,8 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp) time = U16_to_F32(time_short, 0.f, mJointMotionList->mDuration); } - RotationKey *rot_key = new RotationKey; - rot_key->mTime = time; + RotationKey rot_key; + rot_key.mTime = time; LLVector3 rot_angles; U16 x, y, z; @@ -1416,7 +1413,7 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp) success = dp.unpackVector3(rot_angles, "rot_angles"); LLQuaternion::Order ro = StringToOrder("ZYX"); - rot_key->mRotation = mayaQ(rot_angles.mV[VX], rot_angles.mV[VY], rot_angles.mV[VZ], ro); + rot_key.mRotation = mayaQ(rot_angles.mV[VX], rot_angles.mV[VY], rot_angles.mV[VZ], ro); } else { @@ -1428,13 +1425,12 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp) rot_vec.mV[VX] = U16_to_F32(x, -1.f, 1.f); rot_vec.mV[VY] = U16_to_F32(y, -1.f, 1.f); rot_vec.mV[VZ] = U16_to_F32(z, -1.f, 1.f); - rot_key->mRotation.unpackFromVector3(rot_vec); + rot_key.mRotation.unpackFromVector3(rot_vec); } if (!success) { llwarns << "can't read rotation key (" << k << ")" << llendl; - delete rot_key; return FALSE; } @@ -1464,14 +1460,13 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp) for (S32 k = 0; k < joint_motion->mPositionCurve.mNumKeys; k++) { U16 time_short; - PositionKey* pos_key = new PositionKey; + PositionKey pos_key; if (old_version) { - if (!dp.unpackF32(pos_key->mTime, "time")) + if (!dp.unpackF32(pos_key.mTime, "time")) { llwarns << "can't read position key (" << k << ")" << llendl; - delete pos_key; return FALSE; } } @@ -1480,18 +1475,17 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp) if (!dp.unpackU16(time_short, "time")) { llwarns << "can't read position key (" << k << ")" << llendl; - delete pos_key; return FALSE; } - pos_key->mTime = U16_to_F32(time_short, 0.f, mJointMotionList->mDuration); + pos_key.mTime = U16_to_F32(time_short, 0.f, mJointMotionList->mDuration); } BOOL success = TRUE; if (old_version) { - success = dp.unpackVector3(pos_key->mPosition, "pos"); + success = dp.unpackVector3(pos_key.mPosition, "pos"); } else { @@ -1501,23 +1495,22 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp) success &= dp.unpackU16(y, "pos_y"); success &= dp.unpackU16(z, "pos_z"); - pos_key->mPosition.mV[VX] = U16_to_F32(x, -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET); - pos_key->mPosition.mV[VY] = U16_to_F32(y, -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET); - pos_key->mPosition.mV[VZ] = U16_to_F32(z, -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET); + pos_key.mPosition.mV[VX] = U16_to_F32(x, -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET); + pos_key.mPosition.mV[VY] = U16_to_F32(y, -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET); + pos_key.mPosition.mV[VZ] = U16_to_F32(z, -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET); } if (!success) { llwarns << "can't read position key (" << k << ")" << llendl; - delete pos_key; return FALSE; } - pCurve->mKeys[pos_key->mTime] = pos_key; + pCurve->mKeys[pos_key.mTime] = pos_key; if (is_pelvis) { - mJointMotionList->mPelvisBBox.addPoint(pos_key->mPosition); + mJointMotionList->mPelvisBBox.addPoint(pos_key.mPosition); } } @@ -1724,14 +1717,14 @@ BOOL LLKeyframeMotion::serialize(LLDataPacker& dp) const success &= dp.packS32(joint_motionp->mPriority, "joint_priority"); success &= dp.packS32(joint_motionp->mRotationCurve.mNumKeys, "num_rot_keys"); - for (RotationKey* rot_keyp = joint_motionp->mRotationCurve.mKeys.getFirstData(); - rot_keyp; - rot_keyp = joint_motionp->mRotationCurve.mKeys.getNextData()) + for (RotationCurve::key_map_t::iterator iter = joint_motionp->mRotationCurve.mKeys.begin(); + iter != joint_motionp->mRotationCurve.mKeys.end(); ++iter) { - U16 time_short = F32_to_U16(rot_keyp->mTime, 0.f, mJointMotionList->mDuration); + RotationKey& rot_key = iter->second; + U16 time_short = F32_to_U16(rot_key.mTime, 0.f, mJointMotionList->mDuration); success &= dp.packU16(time_short, "time"); - LLVector3 rot_angles = rot_keyp->mRotation.packToVector3(); + LLVector3 rot_angles = rot_key.mRotation.packToVector3(); U16 x, y, z; rot_angles.quantize16(-1.f, 1.f, -1.f, 1.f); @@ -1744,18 +1737,18 @@ BOOL LLKeyframeMotion::serialize(LLDataPacker& dp) const } success &= dp.packS32(joint_motionp->mPositionCurve.mNumKeys, "num_pos_keys"); - for (PositionKey* pos_keyp = joint_motionp->mPositionCurve.mKeys.getFirstData(); - pos_keyp; - pos_keyp = joint_motionp->mPositionCurve.mKeys.getNextData()) + for (PositionCurve::key_map_t::iterator iter = joint_motionp->mPositionCurve.mKeys.begin(); + iter != joint_motionp->mPositionCurve.mKeys.end(); ++iter) { - U16 time_short = F32_to_U16(pos_keyp->mTime, 0.f, mJointMotionList->mDuration); + PositionKey& pos_key = iter->second; + U16 time_short = F32_to_U16(pos_key.mTime, 0.f, mJointMotionList->mDuration); success &= dp.packU16(time_short, "time"); U16 x, y, z; - pos_keyp->mPosition.quantize16(-LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET, -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET); - x = F32_to_U16(pos_keyp->mPosition.mV[VX], -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET); - y = F32_to_U16(pos_keyp->mPosition.mV[VY], -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET); - z = F32_to_U16(pos_keyp->mPosition.mV[VZ], -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET); + pos_key.mPosition.quantize16(-LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET, -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET); + x = F32_to_U16(pos_key.mPosition.mV[VX], -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET); + y = F32_to_U16(pos_key.mPosition.mV[VY], -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET); + z = F32_to_U16(pos_key.mPosition.mV[VZ], -LL_MAX_PELVIS_OFFSET, LL_MAX_PELVIS_OFFSET); success &= dp.packU16(x, "pos_x"); success &= dp.packU16(y, "pos_y"); success &= dp.packU16(z, "pos_z"); @@ -2030,64 +2023,6 @@ void LLKeyframeMotion::onLoadComplete(LLVFS *vfs, } } - -//----------------------------------------------------------------------------- -// writeCAL3D() -//----------------------------------------------------------------------------- -void LLKeyframeMotion::writeCAL3D(apr_file_t* fp) -{ -// -// -// -// 0 0 48.8332 -// 0.0512905 0.05657 0.66973 0.738668 -// -// -// - - apr_file_printf(fp, "\n", getDuration(), mJointMotionList->getNumJointMotions()); - for (U32 joint_index = 0; joint_index < mJointMotionList->getNumJointMotions(); joint_index++) - { - JointMotion* joint_motionp = mJointMotionList->getJointMotion(joint_index); - LLJoint* animated_joint = mCharacter->getJoint(joint_motionp->mJointName); - S32 joint_num = animated_joint->mJointNum + 1; - - apr_file_printf(fp, " \n", joint_num, joint_motionp->mRotationCurve.mNumKeys ); - PositionKey* pos_keyp = joint_motionp->mPositionCurve.mKeys.getFirstData(); - for (RotationKey* rot_keyp = joint_motionp->mRotationCurve.mKeys.getFirstData(); - rot_keyp; - rot_keyp = joint_motionp->mRotationCurve.mKeys.getNextData()) - { - apr_file_printf(fp, " \n", rot_keyp->mTime); - LLVector3 nominal_pos = animated_joint->getPosition(); - if (animated_joint->getParent()) - { - nominal_pos.scaleVec(animated_joint->getParent()->getScale()); - } - nominal_pos = nominal_pos * 100.f; - - if (joint_motionp->mUsage & LLJointState::POS && pos_keyp) - { - LLVector3 pos_val = pos_keyp->mPosition; - pos_val = pos_val * 100.f; - pos_val += nominal_pos; - apr_file_printf(fp, " %0.4f %0.4f %0.4f\n", pos_val.mV[VX], pos_val.mV[VY], pos_val.mV[VZ]); - pos_keyp = joint_motionp->mPositionCurve.mKeys.getNextData(); - } - else - { - apr_file_printf(fp, " %0.4f %0.4f %0.4f\n", nominal_pos.mV[VX], nominal_pos.mV[VY], nominal_pos.mV[VZ]); - } - - LLQuaternion rot_val = ~rot_keyp->mRotation; - apr_file_printf(fp, " %0.4f %0.4f %0.4f %0.4f\n", rot_val.mQ[VX], rot_val.mQ[VY], rot_val.mQ[VZ], rot_val.mQ[VW]); - apr_file_printf(fp, " \n"); - } - apr_file_printf(fp, " \n"); - } - apr_file_printf(fp, "\n"); -} - //-------------------------------------------------------------------- // LLKeyframeDataCache::dumpDiagInfo() //-------------------------------------------------------------------- diff --git a/linden/indra/llcharacter/llkeyframemotion.h b/linden/indra/llcharacter/llkeyframemotion.h index 0ad0181..5f897cf 100644 --- a/linden/indra/llcharacter/llkeyframemotion.h +++ b/linden/indra/llcharacter/llkeyframemotion.h @@ -43,7 +43,6 @@ #include "llhandmotion.h" #include "lljointstate.h" #include "llmotion.h" -#include "llptrskipmap.h" #include "llquaternion.h" #include "v3dmath.h" #include "v3math.h" @@ -158,7 +157,6 @@ public: U32 getFileSize(); BOOL serialize(LLDataPacker& dp) const; BOOL deserialize(LLDataPacker& dp); - void writeCAL3D(apr_file_t* fp); BOOL isLoaded() { return mJointMotionList != NULL; } @@ -339,7 +337,8 @@ public: InterpolationType mInterpolationType; S32 mNumKeys; - LLPtrSkipMap mKeys; + typedef std::map key_map_t; + key_map_t mKeys; ScaleKey mLoopInKey; ScaleKey mLoopOutKey; }; @@ -357,7 +356,8 @@ public: InterpolationType mInterpolationType; S32 mNumKeys; - LLPtrSkipMap mKeys; + typedef std::map key_map_t; + key_map_t mKeys; RotationKey mLoopInKey; RotationKey mLoopOutKey; }; @@ -375,7 +375,8 @@ public: InterpolationType mInterpolationType; S32 mNumKeys; - LLPtrSkipMap mKeys; + typedef std::map key_map_t; + key_map_t mKeys; PositionKey mLoopInKey; PositionKey mLoopOutKey; }; diff --git a/linden/indra/llcharacter/llkeyframemotionparam.cpp b/linden/indra/llcharacter/llkeyframemotionparam.cpp index 2dd935c..106c02c 100644 --- a/linden/indra/llcharacter/llkeyframemotionparam.cpp +++ b/linden/indra/llcharacter/llkeyframemotionparam.cpp @@ -48,14 +48,6 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -// sortFunc() -//----------------------------------------------------------------------------- -BOOL LLKeyframeMotionParam::sortFunc(ParameterizedMotion *new_motion, ParameterizedMotion *tested_motion) -{ - return (new_motion->second < tested_motion->second); -} - -//----------------------------------------------------------------------------- // LLKeyframeMotionParam() // Class Constructor //----------------------------------------------------------------------------- @@ -77,17 +69,18 @@ LLKeyframeMotionParam::LLKeyframeMotionParam( const LLUUID &id) : LLMotion(id) //----------------------------------------------------------------------------- LLKeyframeMotionParam::~LLKeyframeMotionParam() { - for (U32 i = 0; i < mParameterizedMotions.length(); i++) + for (motion_map_t::iterator iter = mParameterizedMotions.begin(); + iter != mParameterizedMotions.end(); ++iter) { - LLLinkedList< ParameterizedMotion > *motionList = *mParameterizedMotions.getValueAt(i); - for (ParameterizedMotion* paramMotion = motionList->getFirstData(); paramMotion; paramMotion = motionList->getNextData()) + motion_list_t& motionList = iter->second; + for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) { - delete paramMotion->first; + const ParameterizedMotion& paramMotion = *iter2; + delete paramMotion.first; // note - deletes the structure; ParameterizedMotion pair remains intact } - delete motionList; + motionList.clear(); } - - mParameterizedMotions.removeAll(); + mParameterizedMotions.clear(); } //----------------------------------------------------------------------------- @@ -102,36 +95,39 @@ LLMotion::LLMotionInitStatus LLKeyframeMotionParam::onInitialize(LLCharacter *ch return STATUS_FAILURE; } - for (U32 i = 0; i < mParameterizedMotions.length(); i++) + for (motion_map_t::iterator iter = mParameterizedMotions.begin(); + iter != mParameterizedMotions.end(); ++iter) { - LLLinkedList< ParameterizedMotion > *motionList = *mParameterizedMotions.getValueAt(i); - for (ParameterizedMotion* paramMotion = motionList->getFirstData(); paramMotion; paramMotion = motionList->getNextData()) + motion_list_t& motionList = iter->second; + for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) { - paramMotion->first->onInitialize(character); + const ParameterizedMotion& paramMotion = *iter2; - if (paramMotion->first->getDuration() > mEaseInDuration) + paramMotion.first->onInitialize(character); + + if (paramMotion.first->getDuration() > mEaseInDuration) { - mEaseInDuration = paramMotion->first->getEaseInDuration(); + mEaseInDuration = paramMotion.first->getEaseInDuration(); } - if (paramMotion->first->getEaseOutDuration() > mEaseOutDuration) + if (paramMotion.first->getEaseOutDuration() > mEaseOutDuration) { - mEaseOutDuration = paramMotion->first->getEaseOutDuration(); + mEaseOutDuration = paramMotion.first->getEaseOutDuration(); } - if (paramMotion->first->getDuration() > mDuration) + if (paramMotion.first->getDuration() > mDuration) { - mDuration = paramMotion->first->getDuration(); + mDuration = paramMotion.first->getDuration(); } - if (paramMotion->first->getPriority() > mPriority) + if (paramMotion.first->getPriority() > mPriority) { - mPriority = paramMotion->first->getPriority(); + mPriority = paramMotion.first->getPriority(); } - LLPose *pose = paramMotion->first->getPose(); + LLPose *pose = paramMotion.first->getPose(); - mPoseBlender.addMotion(paramMotion->first); + mPoseBlender.addMotion(paramMotion.first); for (LLJointState *jsp = pose->getFirstJointState(); jsp; jsp = pose->getNextJointState()) { LLPose *blendedPose = mPoseBlender.getBlendedPose(); @@ -148,12 +144,14 @@ LLMotion::LLMotionInitStatus LLKeyframeMotionParam::onInitialize(LLCharacter *ch //----------------------------------------------------------------------------- BOOL LLKeyframeMotionParam::onActivate() { - for (U32 i = 0; i < mParameterizedMotions.length(); i++) + for (motion_map_t::iterator iter = mParameterizedMotions.begin(); + iter != mParameterizedMotions.end(); ++iter) { - LLLinkedList< ParameterizedMotion > *motionList = *mParameterizedMotions.getValueAt(i); - for (ParameterizedMotion* paramMotion = motionList->getFirstData(); paramMotion; paramMotion = motionList->getNextData()) + motion_list_t& motionList = iter->second; + for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) { - paramMotion->first->activate(); + const ParameterizedMotion& paramMotion = *iter2; + paramMotion.first->activate(); } } return TRUE; @@ -165,46 +163,48 @@ BOOL LLKeyframeMotionParam::onActivate() //----------------------------------------------------------------------------- BOOL LLKeyframeMotionParam::onUpdate(F32 time, U8* joint_mask) { - F32 weightFactor = 1.f / (F32)mParameterizedMotions.length(); - U32 i; + F32 weightFactor = 1.f / (F32)mParameterizedMotions.size(); // zero out all pose weights - for (i = 0; i < mParameterizedMotions.length(); i++) + for (motion_map_t::iterator iter = mParameterizedMotions.begin(); + iter != mParameterizedMotions.end(); ++iter) { - LLLinkedList< ParameterizedMotion > *motionList = *mParameterizedMotions.getValueAt(i); - - for (ParameterizedMotion* paramMotion = motionList->getFirstData(); paramMotion; paramMotion = motionList->getNextData()) + motion_list_t& motionList = iter->second; + for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) { -// llinfos << "Weight for pose " << paramMotion->first->getName() << " is " << paramMotion->first->getPose()->getWeight() << llendl; - paramMotion->first->getPose()->setWeight(0.f); + const ParameterizedMotion& paramMotion = *iter2; +// llinfos << "Weight for pose " << paramMotion.first->getName() << " is " << paramMotion.first->getPose()->getWeight() << llendl; + paramMotion.first->getPose()->setWeight(0.f); } } - for (i = 0; i < mParameterizedMotions.length(); i++) + for (motion_map_t::iterator iter = mParameterizedMotions.begin(); + iter != mParameterizedMotions.end(); ++iter) { - LLLinkedList< ParameterizedMotion > *motionList = *mParameterizedMotions.getValueAt(i); - std::string *paramName = mParameterizedMotions.getIndexAt(i); - F32* paramValue = (F32 *)mCharacter->getAnimationData(*paramName); - ParameterizedMotion* firstMotion = NULL; - ParameterizedMotion* secondMotion = NULL; - + const std::string& paramName = iter->first; + F32* paramValue = (F32 *)mCharacter->getAnimationData(paramName); if (NULL == paramValue) // unexpected, but... { llwarns << "paramValue == NULL" << llendl; continue; } - for (ParameterizedMotion* paramMotion = motionList->getFirstData(); paramMotion; paramMotion = motionList->getNextData()) + const ParameterizedMotion* firstMotion = NULL; + const ParameterizedMotion* secondMotion = NULL; + + motion_list_t& motionList = iter->second; + for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) { - paramMotion->first->onUpdate(time, joint_mask); + const ParameterizedMotion& paramMotion = *iter2; + paramMotion.first->onUpdate(time, joint_mask); - F32 distToParam = paramMotion->second - *paramValue; + F32 distToParam = paramMotion.second - *paramValue; if ( distToParam <= 0.f) { // keep track of the motion closest to the parameter value - firstMotion = paramMotion; + firstMotion = ¶mMotion; } else { @@ -212,13 +212,13 @@ BOOL LLKeyframeMotionParam::onUpdate(F32 time, U8* joint_mask) // so store the first motion we find as the second one we want to blend... if (firstMotion && !secondMotion ) { - secondMotion = paramMotion; + secondMotion = ¶mMotion; } //...or, if we've seen no other motion so far, make sure we blend to this only else if (!firstMotion) { - firstMotion = paramMotion; - secondMotion = paramMotion; + firstMotion = ¶mMotion; + secondMotion = ¶mMotion; } } } @@ -283,12 +283,14 @@ BOOL LLKeyframeMotionParam::onUpdate(F32 time, U8* joint_mask) //----------------------------------------------------------------------------- void LLKeyframeMotionParam::onDeactivate() { - for (U32 i = 0; i < mParameterizedMotions.length(); i++) + for (motion_map_t::iterator iter = mParameterizedMotions.begin(); + iter != mParameterizedMotions.end(); ++iter) { - LLLinkedList< ParameterizedMotion > *motionList = *mParameterizedMotions.getValueAt(i); - for (ParameterizedMotion* paramMotion = motionList->getFirstData(); paramMotion; paramMotion = motionList->getNextData()) + motion_list_t& motionList = iter->second; + for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) { - paramMotion->first->onDeactivate(); + const ParameterizedMotion& paramMotion = *iter2; + paramMotion.first->onDeactivate(); } } } @@ -307,23 +309,8 @@ BOOL LLKeyframeMotionParam::addKeyframeMotion(char *name, const LLUUID &id, char newMotion->setName(name); - // make sure a list of motions exists for this parameter - LLLinkedList< ParameterizedMotion > *motionList; - if (mParameterizedMotions.getValue(param)) - { - motionList = *mParameterizedMotions.getValue(param); - } - else - { - motionList = new LLLinkedList< ParameterizedMotion >; - motionList->setInsertBefore(sortFunc); - mParameterizedMotions.addToHead(param, motionList); - } - // now add motion to this list - ParameterizedMotion *parameterizedMotion = new ParameterizedMotion(newMotion, value); - - motionList->addDataSorted(parameterizedMotion); + mParameterizedMotions[param].insert(ParameterizedMotion(newMotion, value)); return TRUE; } @@ -334,14 +321,16 @@ BOOL LLKeyframeMotionParam::addKeyframeMotion(char *name, const LLUUID &id, char //----------------------------------------------------------------------------- void LLKeyframeMotionParam::setDefaultKeyframeMotion(char *name) { - for (U32 i = 0; i < mParameterizedMotions.length(); i++) + for (motion_map_t::iterator iter = mParameterizedMotions.begin(); + iter != mParameterizedMotions.end(); ++iter) { - LLLinkedList< ParameterizedMotion > *motionList = *mParameterizedMotions.getValueAt(i); - for (ParameterizedMotion* paramMotion = motionList->getFirstData(); paramMotion; paramMotion = motionList->getNextData()) + motion_list_t& motionList = iter->second; + for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) { - if (paramMotion->first->getName() == name) + const ParameterizedMotion& paramMotion = *iter2; + if (paramMotion.first->getName() == name) { - mDefaultKeyframeMotion = paramMotion->first; + mDefaultKeyframeMotion = paramMotion.first; } } } diff --git a/linden/indra/llcharacter/llkeyframemotionparam.h b/linden/indra/llcharacter/llkeyframemotionparam.h index a5bc2cb..f509e6a 100644 --- a/linden/indra/llcharacter/llkeyframemotionparam.h +++ b/linden/indra/llcharacter/llkeyframemotionparam.h @@ -143,8 +143,20 @@ protected: // Member Data //------------------------------------------------------------------------- - typedef LLLinkedList < ParameterizedMotion > motion_list_t; - LLAssocList mParameterizedMotions; + struct compare_motions + { + bool operator() (const ParameterizedMotion& a, const ParameterizedMotion& b) const + { + if (a.second != b.second) + return (a.second < b.second); + else + return a.first < b.first; + } + }; + + typedef std::set < ParameterizedMotion, compare_motions > motion_list_t; + typedef std::map motion_map_t; + motion_map_t mParameterizedMotions; LLMotion* mDefaultKeyframeMotion; LLCharacter* mCharacter; LLPoseBlender mPoseBlender; diff --git a/linden/indra/llcharacter/llmotioncontroller.cpp b/linden/indra/llcharacter/llmotioncontroller.cpp index d1a2a53..028cf22 100644 --- a/linden/indra/llcharacter/llmotioncontroller.cpp +++ b/linden/indra/llcharacter/llmotioncontroller.cpp @@ -746,7 +746,7 @@ void LLMotionController::updateMotion() // is calculating a new keyframe pose, make sure the last one gets applied mPoseBlender.interpolate(1.f); - mPoseBlender.clearBlenders(); + clearBlenders(); mTimeStepCount = quantum_count; mLastTime = mTime; @@ -824,6 +824,13 @@ void LLMotionController::updateMotion() //----------------------------------------------------------------------------- BOOL LLMotionController::activateMotionInstance(LLMotion *motion, F32 time) { + // It's not clear why the getWeight() line seems to be crashing this, but + // hopefully this fixes it. + if (motion == NULL || motion->getPose() == NULL) + { + return FALSE; + } + if (mLoadingMotions.find(motion) != mLoadingMotions.end()) { // we want to start this motion, but we can't yet, so flag it as started diff --git a/linden/indra/llcharacter/llmotioncontroller.h b/linden/indra/llcharacter/llmotioncontroller.h index e66edcb..48e184d 100644 --- a/linden/indra/llcharacter/llmotioncontroller.h +++ b/linden/indra/llcharacter/llmotioncontroller.h @@ -157,6 +157,8 @@ public: // deactivates terminated motions` void updateMotion(); + void clearBlenders() { mPoseBlender.clearBlenders(); } + // flush motions // releases all motion instances void flushAllMotions(); diff --git a/linden/indra/llcharacter/llpose.cpp b/linden/indra/llcharacter/llpose.cpp index 3a6a221..f496b7b 100644 --- a/linden/indra/llcharacter/llpose.cpp +++ b/linden/indra/llcharacter/llpose.cpp @@ -379,15 +379,20 @@ void LLJointStateBlender::blendJointStates(BOOL apply_now) } } - // apply blended transforms - target_joint->setPosition(blended_pos); - target_joint->setScale(blended_scale); - target_joint->setRotation(blended_rot); - - // apply additive transforms - target_joint->setPosition(target_joint->getPosition() + added_pos); - target_joint->setScale(target_joint->getScale() + added_scale); - target_joint->setRotation(added_rot * target_joint->getRotation()); + if (!added_scale.isFinite()) + { + added_scale.clearVec(); + } + + if (!blended_scale.isFinite()) + { + blended_scale.setVec(1,1,1); + } + + // apply transforms + target_joint->setPosition(blended_pos + added_pos); + target_joint->setScale(blended_scale + added_scale); + target_joint->setRotation(added_rot * blended_rot); if (apply_now) { diff --git a/linden/indra/llcharacter/llpose.h b/linden/indra/llcharacter/llpose.h index f67a26b..075a456 100644 --- a/linden/indra/llcharacter/llpose.h +++ b/linden/indra/llcharacter/llpose.h @@ -37,10 +37,8 @@ //----------------------------------------------------------------------------- #include -#include "linked_lists.h" #include "llmap.h" #include "lljointstate.h" -#include "llassoclist.h" #include "lljoint.h" #include diff --git a/linden/indra/llcharacter/llstatemachine.h b/linden/indra/llcharacter/llstatemachine.h index f46e4bf..12a71b7 100644 --- a/linden/indra/llcharacter/llstatemachine.h +++ b/linden/indra/llcharacter/llstatemachine.h @@ -34,7 +34,6 @@ #include -#include "llassoclist.h" #include "llerror.h" #include -- cgit v1.1