diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llcharacter/llkeyframemotionparam.cpp | 149 |
1 files changed, 69 insertions, 80 deletions
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 @@ | |||
48 | //----------------------------------------------------------------------------- | 48 | //----------------------------------------------------------------------------- |
49 | 49 | ||
50 | //----------------------------------------------------------------------------- | 50 | //----------------------------------------------------------------------------- |
51 | // sortFunc() | ||
52 | //----------------------------------------------------------------------------- | ||
53 | BOOL LLKeyframeMotionParam::sortFunc(ParameterizedMotion *new_motion, ParameterizedMotion *tested_motion) | ||
54 | { | ||
55 | return (new_motion->second < tested_motion->second); | ||
56 | } | ||
57 | |||
58 | //----------------------------------------------------------------------------- | ||
59 | // LLKeyframeMotionParam() | 51 | // LLKeyframeMotionParam() |
60 | // Class Constructor | 52 | // Class Constructor |
61 | //----------------------------------------------------------------------------- | 53 | //----------------------------------------------------------------------------- |
@@ -77,17 +69,18 @@ LLKeyframeMotionParam::LLKeyframeMotionParam( const LLUUID &id) : LLMotion(id) | |||
77 | //----------------------------------------------------------------------------- | 69 | //----------------------------------------------------------------------------- |
78 | LLKeyframeMotionParam::~LLKeyframeMotionParam() | 70 | LLKeyframeMotionParam::~LLKeyframeMotionParam() |
79 | { | 71 | { |
80 | for (U32 i = 0; i < mParameterizedMotions.length(); i++) | 72 | for (motion_map_t::iterator iter = mParameterizedMotions.begin(); |
73 | iter != mParameterizedMotions.end(); ++iter) | ||
81 | { | 74 | { |
82 | LLLinkedList< ParameterizedMotion > *motionList = *mParameterizedMotions.getValueAt(i); | 75 | motion_list_t& motionList = iter->second; |
83 | for (ParameterizedMotion* paramMotion = motionList->getFirstData(); paramMotion; paramMotion = motionList->getNextData()) | 76 | for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) |
84 | { | 77 | { |
85 | delete paramMotion->first; | 78 | const ParameterizedMotion& paramMotion = *iter2; |
79 | delete paramMotion.first; // note - deletes the structure; ParameterizedMotion pair remains intact | ||
86 | } | 80 | } |
87 | delete motionList; | 81 | motionList.clear(); |
88 | } | 82 | } |
89 | 83 | mParameterizedMotions.clear(); | |
90 | mParameterizedMotions.removeAll(); | ||
91 | } | 84 | } |
92 | 85 | ||
93 | //----------------------------------------------------------------------------- | 86 | //----------------------------------------------------------------------------- |
@@ -102,36 +95,39 @@ LLMotion::LLMotionInitStatus LLKeyframeMotionParam::onInitialize(LLCharacter *ch | |||
102 | return STATUS_FAILURE; | 95 | return STATUS_FAILURE; |
103 | } | 96 | } |
104 | 97 | ||
105 | for (U32 i = 0; i < mParameterizedMotions.length(); i++) | 98 | for (motion_map_t::iterator iter = mParameterizedMotions.begin(); |
99 | iter != mParameterizedMotions.end(); ++iter) | ||
106 | { | 100 | { |
107 | LLLinkedList< ParameterizedMotion > *motionList = *mParameterizedMotions.getValueAt(i); | 101 | motion_list_t& motionList = iter->second; |
108 | for (ParameterizedMotion* paramMotion = motionList->getFirstData(); paramMotion; paramMotion = motionList->getNextData()) | 102 | for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) |
109 | { | 103 | { |
110 | paramMotion->first->onInitialize(character); | 104 | const ParameterizedMotion& paramMotion = *iter2; |
111 | 105 | ||
112 | if (paramMotion->first->getDuration() > mEaseInDuration) | 106 | paramMotion.first->onInitialize(character); |
107 | |||
108 | if (paramMotion.first->getDuration() > mEaseInDuration) | ||
113 | { | 109 | { |
114 | mEaseInDuration = paramMotion->first->getEaseInDuration(); | 110 | mEaseInDuration = paramMotion.first->getEaseInDuration(); |
115 | } | 111 | } |
116 | 112 | ||
117 | if (paramMotion->first->getEaseOutDuration() > mEaseOutDuration) | 113 | if (paramMotion.first->getEaseOutDuration() > mEaseOutDuration) |
118 | { | 114 | { |
119 | mEaseOutDuration = paramMotion->first->getEaseOutDuration(); | 115 | mEaseOutDuration = paramMotion.first->getEaseOutDuration(); |
120 | } | 116 | } |
121 | 117 | ||
122 | if (paramMotion->first->getDuration() > mDuration) | 118 | if (paramMotion.first->getDuration() > mDuration) |
123 | { | 119 | { |
124 | mDuration = paramMotion->first->getDuration(); | 120 | mDuration = paramMotion.first->getDuration(); |
125 | } | 121 | } |
126 | 122 | ||
127 | if (paramMotion->first->getPriority() > mPriority) | 123 | if (paramMotion.first->getPriority() > mPriority) |
128 | { | 124 | { |
129 | mPriority = paramMotion->first->getPriority(); | 125 | mPriority = paramMotion.first->getPriority(); |
130 | } | 126 | } |
131 | 127 | ||
132 | LLPose *pose = paramMotion->first->getPose(); | 128 | LLPose *pose = paramMotion.first->getPose(); |
133 | 129 | ||
134 | mPoseBlender.addMotion(paramMotion->first); | 130 | mPoseBlender.addMotion(paramMotion.first); |
135 | for (LLJointState *jsp = pose->getFirstJointState(); jsp; jsp = pose->getNextJointState()) | 131 | for (LLJointState *jsp = pose->getFirstJointState(); jsp; jsp = pose->getNextJointState()) |
136 | { | 132 | { |
137 | LLPose *blendedPose = mPoseBlender.getBlendedPose(); | 133 | LLPose *blendedPose = mPoseBlender.getBlendedPose(); |
@@ -148,12 +144,14 @@ LLMotion::LLMotionInitStatus LLKeyframeMotionParam::onInitialize(LLCharacter *ch | |||
148 | //----------------------------------------------------------------------------- | 144 | //----------------------------------------------------------------------------- |
149 | BOOL LLKeyframeMotionParam::onActivate() | 145 | BOOL LLKeyframeMotionParam::onActivate() |
150 | { | 146 | { |
151 | for (U32 i = 0; i < mParameterizedMotions.length(); i++) | 147 | for (motion_map_t::iterator iter = mParameterizedMotions.begin(); |
148 | iter != mParameterizedMotions.end(); ++iter) | ||
152 | { | 149 | { |
153 | LLLinkedList< ParameterizedMotion > *motionList = *mParameterizedMotions.getValueAt(i); | 150 | motion_list_t& motionList = iter->second; |
154 | for (ParameterizedMotion* paramMotion = motionList->getFirstData(); paramMotion; paramMotion = motionList->getNextData()) | 151 | for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) |
155 | { | 152 | { |
156 | paramMotion->first->activate(); | 153 | const ParameterizedMotion& paramMotion = *iter2; |
154 | paramMotion.first->activate(); | ||
157 | } | 155 | } |
158 | } | 156 | } |
159 | return TRUE; | 157 | return TRUE; |
@@ -165,46 +163,48 @@ BOOL LLKeyframeMotionParam::onActivate() | |||
165 | //----------------------------------------------------------------------------- | 163 | //----------------------------------------------------------------------------- |
166 | BOOL LLKeyframeMotionParam::onUpdate(F32 time, U8* joint_mask) | 164 | BOOL LLKeyframeMotionParam::onUpdate(F32 time, U8* joint_mask) |
167 | { | 165 | { |
168 | F32 weightFactor = 1.f / (F32)mParameterizedMotions.length(); | 166 | F32 weightFactor = 1.f / (F32)mParameterizedMotions.size(); |
169 | U32 i; | ||
170 | 167 | ||
171 | // zero out all pose weights | 168 | // zero out all pose weights |
172 | for (i = 0; i < mParameterizedMotions.length(); i++) | 169 | for (motion_map_t::iterator iter = mParameterizedMotions.begin(); |
170 | iter != mParameterizedMotions.end(); ++iter) | ||
173 | { | 171 | { |
174 | LLLinkedList< ParameterizedMotion > *motionList = *mParameterizedMotions.getValueAt(i); | 172 | motion_list_t& motionList = iter->second; |
175 | 173 | for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) | |
176 | for (ParameterizedMotion* paramMotion = motionList->getFirstData(); paramMotion; paramMotion = motionList->getNextData()) | ||
177 | { | 174 | { |
178 | // llinfos << "Weight for pose " << paramMotion->first->getName() << " is " << paramMotion->first->getPose()->getWeight() << llendl; | 175 | const ParameterizedMotion& paramMotion = *iter2; |
179 | paramMotion->first->getPose()->setWeight(0.f); | 176 | // llinfos << "Weight for pose " << paramMotion.first->getName() << " is " << paramMotion.first->getPose()->getWeight() << llendl; |
177 | paramMotion.first->getPose()->setWeight(0.f); | ||
180 | } | 178 | } |
181 | } | 179 | } |
182 | 180 | ||
183 | 181 | ||
184 | for (i = 0; i < mParameterizedMotions.length(); i++) | 182 | for (motion_map_t::iterator iter = mParameterizedMotions.begin(); |
183 | iter != mParameterizedMotions.end(); ++iter) | ||
185 | { | 184 | { |
186 | LLLinkedList< ParameterizedMotion > *motionList = *mParameterizedMotions.getValueAt(i); | 185 | const std::string& paramName = iter->first; |
187 | std::string *paramName = mParameterizedMotions.getIndexAt(i); | 186 | F32* paramValue = (F32 *)mCharacter->getAnimationData(paramName); |
188 | F32* paramValue = (F32 *)mCharacter->getAnimationData(*paramName); | ||
189 | ParameterizedMotion* firstMotion = NULL; | ||
190 | ParameterizedMotion* secondMotion = NULL; | ||
191 | |||
192 | if (NULL == paramValue) // unexpected, but... | 187 | if (NULL == paramValue) // unexpected, but... |
193 | { | 188 | { |
194 | llwarns << "paramValue == NULL" << llendl; | 189 | llwarns << "paramValue == NULL" << llendl; |
195 | continue; | 190 | continue; |
196 | } | 191 | } |
197 | 192 | ||
198 | for (ParameterizedMotion* paramMotion = motionList->getFirstData(); paramMotion; paramMotion = motionList->getNextData()) | 193 | const ParameterizedMotion* firstMotion = NULL; |
194 | const ParameterizedMotion* secondMotion = NULL; | ||
195 | |||
196 | motion_list_t& motionList = iter->second; | ||
197 | for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) | ||
199 | { | 198 | { |
200 | paramMotion->first->onUpdate(time, joint_mask); | 199 | const ParameterizedMotion& paramMotion = *iter2; |
200 | paramMotion.first->onUpdate(time, joint_mask); | ||
201 | 201 | ||
202 | F32 distToParam = paramMotion->second - *paramValue; | 202 | F32 distToParam = paramMotion.second - *paramValue; |
203 | 203 | ||
204 | if ( distToParam <= 0.f) | 204 | if ( distToParam <= 0.f) |
205 | { | 205 | { |
206 | // keep track of the motion closest to the parameter value | 206 | // keep track of the motion closest to the parameter value |
207 | firstMotion = paramMotion; | 207 | firstMotion = ¶mMotion; |
208 | } | 208 | } |
209 | else | 209 | else |
210 | { | 210 | { |
@@ -212,13 +212,13 @@ BOOL LLKeyframeMotionParam::onUpdate(F32 time, U8* joint_mask) | |||
212 | // so store the first motion we find as the second one we want to blend... | 212 | // so store the first motion we find as the second one we want to blend... |
213 | if (firstMotion && !secondMotion ) | 213 | if (firstMotion && !secondMotion ) |
214 | { | 214 | { |
215 | secondMotion = paramMotion; | 215 | secondMotion = ¶mMotion; |
216 | } | 216 | } |
217 | //...or, if we've seen no other motion so far, make sure we blend to this only | 217 | //...or, if we've seen no other motion so far, make sure we blend to this only |
218 | else if (!firstMotion) | 218 | else if (!firstMotion) |
219 | { | 219 | { |
220 | firstMotion = paramMotion; | 220 | firstMotion = ¶mMotion; |
221 | secondMotion = paramMotion; | 221 | secondMotion = ¶mMotion; |
222 | } | 222 | } |
223 | } | 223 | } |
224 | } | 224 | } |
@@ -283,12 +283,14 @@ BOOL LLKeyframeMotionParam::onUpdate(F32 time, U8* joint_mask) | |||
283 | //----------------------------------------------------------------------------- | 283 | //----------------------------------------------------------------------------- |
284 | void LLKeyframeMotionParam::onDeactivate() | 284 | void LLKeyframeMotionParam::onDeactivate() |
285 | { | 285 | { |
286 | for (U32 i = 0; i < mParameterizedMotions.length(); i++) | 286 | for (motion_map_t::iterator iter = mParameterizedMotions.begin(); |
287 | iter != mParameterizedMotions.end(); ++iter) | ||
287 | { | 288 | { |
288 | LLLinkedList< ParameterizedMotion > *motionList = *mParameterizedMotions.getValueAt(i); | 289 | motion_list_t& motionList = iter->second; |
289 | for (ParameterizedMotion* paramMotion = motionList->getFirstData(); paramMotion; paramMotion = motionList->getNextData()) | 290 | for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) |
290 | { | 291 | { |
291 | paramMotion->first->onDeactivate(); | 292 | const ParameterizedMotion& paramMotion = *iter2; |
293 | paramMotion.first->onDeactivate(); | ||
292 | } | 294 | } |
293 | } | 295 | } |
294 | } | 296 | } |
@@ -307,23 +309,8 @@ BOOL LLKeyframeMotionParam::addKeyframeMotion(char *name, const LLUUID &id, char | |||
307 | 309 | ||
308 | newMotion->setName(name); | 310 | newMotion->setName(name); |
309 | 311 | ||
310 | // make sure a list of motions exists for this parameter | ||
311 | LLLinkedList< ParameterizedMotion > *motionList; | ||
312 | if (mParameterizedMotions.getValue(param)) | ||
313 | { | ||
314 | motionList = *mParameterizedMotions.getValue(param); | ||
315 | } | ||
316 | else | ||
317 | { | ||
318 | motionList = new LLLinkedList< ParameterizedMotion >; | ||
319 | motionList->setInsertBefore(sortFunc); | ||
320 | mParameterizedMotions.addToHead(param, motionList); | ||
321 | } | ||
322 | |||
323 | // now add motion to this list | 312 | // now add motion to this list |
324 | ParameterizedMotion *parameterizedMotion = new ParameterizedMotion(newMotion, value); | 313 | mParameterizedMotions[param].insert(ParameterizedMotion(newMotion, value)); |
325 | |||
326 | motionList->addDataSorted(parameterizedMotion); | ||
327 | 314 | ||
328 | return TRUE; | 315 | return TRUE; |
329 | } | 316 | } |
@@ -334,14 +321,16 @@ BOOL LLKeyframeMotionParam::addKeyframeMotion(char *name, const LLUUID &id, char | |||
334 | //----------------------------------------------------------------------------- | 321 | //----------------------------------------------------------------------------- |
335 | void LLKeyframeMotionParam::setDefaultKeyframeMotion(char *name) | 322 | void LLKeyframeMotionParam::setDefaultKeyframeMotion(char *name) |
336 | { | 323 | { |
337 | for (U32 i = 0; i < mParameterizedMotions.length(); i++) | 324 | for (motion_map_t::iterator iter = mParameterizedMotions.begin(); |
325 | iter != mParameterizedMotions.end(); ++iter) | ||
338 | { | 326 | { |
339 | LLLinkedList< ParameterizedMotion > *motionList = *mParameterizedMotions.getValueAt(i); | 327 | motion_list_t& motionList = iter->second; |
340 | for (ParameterizedMotion* paramMotion = motionList->getFirstData(); paramMotion; paramMotion = motionList->getNextData()) | 328 | for (motion_list_t::iterator iter2 = motionList.begin(); iter2 != motionList.end(); ++iter2) |
341 | { | 329 | { |
342 | if (paramMotion->first->getName() == name) | 330 | const ParameterizedMotion& paramMotion = *iter2; |
331 | if (paramMotion.first->getName() == name) | ||
343 | { | 332 | { |
344 | mDefaultKeyframeMotion = paramMotion->first; | 333 | mDefaultKeyframeMotion = paramMotion.first; |
345 | } | 334 | } |
346 | } | 335 | } |
347 | } | 336 | } |