diff options
Diffstat (limited to 'indra/llcharacter/llkeyframemotionparam.cpp')
-rw-r--r-- | indra/llcharacter/llkeyframemotionparam.cpp | 122 |
1 files changed, 56 insertions, 66 deletions
diff --git a/indra/llcharacter/llkeyframemotionparam.cpp b/indra/llcharacter/llkeyframemotionparam.cpp index 30edc29c6e..82fe8971f5 100644 --- a/indra/llcharacter/llkeyframemotionparam.cpp +++ b/indra/llcharacter/llkeyframemotionparam.cpp @@ -2,30 +2,25 @@ * @file llkeyframemotionparam.cpp * @brief Implementation of LLKeyframeMotion class. * - * $LicenseInfo:firstyear=2001&license=viewergpl$ - * - * Copyright (c) 2001-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -76,7 +71,7 @@ LLKeyframeMotionParam::~LLKeyframeMotionParam() for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) { const ParameterizedMotion& paramMotion = *iter2; - delete paramMotion.first; // note - deletes the structure; ParameterizedMotion pair remains intact + delete paramMotion.mMotion; } motionList.clear(); } @@ -102,32 +97,32 @@ LLMotion::LLMotionInitStatus LLKeyframeMotionParam::onInitialize(LLCharacter *ch for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) { const ParameterizedMotion& paramMotion = *iter2; + LLMotion* motion = paramMotion.mMotion; + motion->onInitialize(character); - paramMotion.first->onInitialize(character); - - if (paramMotion.first->getDuration() > mEaseInDuration) + if (motion->getDuration() > mEaseInDuration) { - mEaseInDuration = paramMotion.first->getEaseInDuration(); + mEaseInDuration = motion->getEaseInDuration(); } - if (paramMotion.first->getEaseOutDuration() > mEaseOutDuration) + if (motion->getEaseOutDuration() > mEaseOutDuration) { - mEaseOutDuration = paramMotion.first->getEaseOutDuration(); + mEaseOutDuration = motion->getEaseOutDuration(); } - if (paramMotion.first->getDuration() > mDuration) + if (motion->getDuration() > mDuration) { - mDuration = paramMotion.first->getDuration(); + mDuration = motion->getDuration(); } - if (paramMotion.first->getPriority() > mPriority) + if (motion->getPriority() > mPriority) { - mPriority = paramMotion.first->getPriority(); + mPriority = motion->getPriority(); } - LLPose *pose = paramMotion.first->getPose(); + LLPose *pose = motion->getPose(); - mPoseBlender.addMotion(paramMotion.first); + mPoseBlender.addMotion(motion); for (LLJointState *jsp = pose->getFirstJointState(); jsp; jsp = pose->getNextJointState()) { LLPose *blendedPose = mPoseBlender.getBlendedPose(); @@ -151,7 +146,7 @@ BOOL LLKeyframeMotionParam::onActivate() for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) { const ParameterizedMotion& paramMotion = *iter2; - paramMotion.first->activate(); + paramMotion.mMotion->activate(mActivationTimestamp); } } return TRUE; @@ -173,8 +168,8 @@ BOOL LLKeyframeMotionParam::onUpdate(F32 time, U8* joint_mask) for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) { const ParameterizedMotion& paramMotion = *iter2; -// llinfos << "Weight for pose " << paramMotion.first->getName() << " is " << paramMotion.first->getPose()->getWeight() << llendl; - paramMotion.first->getPose()->setWeight(0.f); +// llinfos << "Weight for pose " << paramMotion.mMotion->getName() << " is " << paramMotion.mMotion->getPose()->getWeight() << llendl; + paramMotion.mMotion->getPose()->setWeight(0.f); } } @@ -190,6 +185,7 @@ BOOL LLKeyframeMotionParam::onUpdate(F32 time, U8* joint_mask) continue; } + // DANGER! Do not modify mParameterizedMotions while using these pointers! const ParameterizedMotion* firstMotion = NULL; const ParameterizedMotion* secondMotion = NULL; @@ -197,9 +193,9 @@ BOOL LLKeyframeMotionParam::onUpdate(F32 time, U8* joint_mask) for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) { const ParameterizedMotion& paramMotion = *iter2; - paramMotion.first->onUpdate(time, joint_mask); + paramMotion.mMotion->onUpdate(time, joint_mask); - F32 distToParam = paramMotion.second - *paramValue; + F32 distToParam = paramMotion.mParam - *paramValue; if ( distToParam <= 0.f) { @@ -227,12 +223,12 @@ BOOL LLKeyframeMotionParam::onUpdate(F32 time, U8* joint_mask) LLPose *secondPose; if (firstMotion) - firstPose = firstMotion->first->getPose(); + firstPose = firstMotion->mMotion->getPose(); else firstPose = NULL; if (secondMotion) - secondPose = secondMotion->first->getPose(); + secondPose = secondMotion->mMotion->getPose(); else secondPose = NULL; @@ -243,7 +239,7 @@ BOOL LLKeyframeMotionParam::onUpdate(F32 time, U8* joint_mask) { firstPose->setWeight(weightFactor); } - else if (firstMotion->second == secondMotion->second) + else if (firstMotion->mParam == secondMotion->mParam) { firstPose->setWeight(0.5f * weightFactor); secondPose->setWeight(0.5f * weightFactor); @@ -251,8 +247,8 @@ BOOL LLKeyframeMotionParam::onUpdate(F32 time, U8* joint_mask) else { F32 first_weight = 1.f - - ((llclamp(*paramValue - firstMotion->second, 0.f, (secondMotion->second - firstMotion->second))) / - (secondMotion->second - firstMotion->second)); + ((llclamp(*paramValue - firstMotion->mParam, 0.f, (secondMotion->mParam - firstMotion->mParam))) / + (secondMotion->mParam - firstMotion->mParam)); first_weight = llclamp(first_weight, 0.f, 1.f); F32 second_weight = 1.f - first_weight; @@ -290,7 +286,7 @@ void LLKeyframeMotionParam::onDeactivate() for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) { const ParameterizedMotion& paramMotion = *iter2; - paramMotion.first->onDeactivate(); + paramMotion.mMotion->onDeactivate(); } } } @@ -328,9 +324,9 @@ void LLKeyframeMotionParam::setDefaultKeyframeMotion(char *name) for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) { const ParameterizedMotion& paramMotion = *iter2; - if (paramMotion.first->getName() == name) + if (paramMotion.mMotion->getName() == name) { - mDefaultKeyframeMotion = paramMotion.first; + mDefaultKeyframeMotion = paramMotion.mMotion; } } } @@ -345,16 +341,19 @@ BOOL LLKeyframeMotionParam::loadMotions() // Load named file by concatenating the character prefix with the motion name. // Load data into a buffer to be parsed. //------------------------------------------------------------------------- - char path[LL_MAX_PATH]; /* Flawfinder: ignore */ - snprintf( path,sizeof(path), "%s_%s.llp", - gDirUtilp->getExpandedFilename(LL_PATH_MOTIONS,mCharacter->getAnimationPrefix()).c_str(), - getName().c_str() ); + //std::string path = gDirUtilp->getExpandedFilename(LL_PATH_MOTIONS,mCharacter->getAnimationPrefix()) + // + "_" + getName() + ".llp"; + //RN: deprecated unused reference to "motion" directory + std::string path; + //------------------------------------------------------------------------- // open the file //------------------------------------------------------------------------- S32 fileSize = 0; - apr_file_t* fp = ll_apr_file_open(path, LL_APR_R, &fileSize); + LLAPRFile infile ; + infile.open(path, LL_APR_R, NULL, &fileSize); + apr_file_t* fp = infile.getFileHandle() ; if (!fp || fileSize == 0) { llinfos << "ERROR: can't open: " << path << llendl; @@ -362,19 +361,13 @@ BOOL LLKeyframeMotionParam::loadMotions() } // allocate a text buffer - char *text = new char[ fileSize+1 ]; - if ( !text ) - { - llinfos << "ERROR: can't allocated keyframe text buffer." << llendl; - apr_file_close(fp); - return FALSE; - } + std::vector<char> text(fileSize+1); //------------------------------------------------------------------------- // load data from file into buffer //------------------------------------------------------------------------- bool error = false; - char *p = text; + char *p = &text[0]; while ( 1 ) { if (apr_file_eof(fp) == APR_EOF) @@ -393,17 +386,16 @@ BOOL LLKeyframeMotionParam::loadMotions() //------------------------------------------------------------------------- // close the file //------------------------------------------------------------------------- - apr_file_close( fp ); + infile.close(); //------------------------------------------------------------------------- // check for error //------------------------------------------------------------------------- - llassert( p <= (text+fileSize) ); + llassert( p <= (&text[0] + fileSize) ); if ( error ) { llinfos << "ERROR: error while reading from " << path << llendl; - delete [] text; return FALSE; } @@ -412,7 +404,7 @@ BOOL LLKeyframeMotionParam::loadMotions() //------------------------------------------------------------------------- // parse the text and build keyframe data structures //------------------------------------------------------------------------- - p = text; + p = &text[0]; S32 num; char strA[80]; /* Flawfinder: ignore */ char strB[80]; /* Flawfinder: ignore */ @@ -431,11 +423,10 @@ BOOL LLKeyframeMotionParam::loadMotions() if ((num != 3)) { llinfos << "WARNING: can't read parametric motion" << llendl; - delete [] text; return FALSE; } - addKeyframeMotion(strA, gAnimLibrary.stringToAnimState(strA), strB, floatA); + addKeyframeMotion(strA, gAnimLibrary.stringToAnimState(std::string(strA)), strB, floatA); if (isFirstMotion) { isFirstMotion = FALSE; @@ -452,7 +443,6 @@ BOOL LLKeyframeMotionParam::loadMotions() num = sscanf(p, "%79s %79s %f", strA, strB, &floatA); /* Flawfinder: ignore */ } - delete [] text; return TRUE; } |