| 183 | |
| 184 | template <class Key, class KeyList, class KeyValue> |
| 185 | int Tr2CurveBase<Key, KeyList, KeyValue>::AddKey( float time, const KeyValue& value ) |
| 186 | { |
| 187 | // This function should return the index of the key where it was added to m_keys |
| 188 | // If the time is already in a key and thus the key's value is updated for that time |
| 189 | // return the index of the updated key. |
| 190 | // Otherwise, if no key was added, it returns -1. |
| 191 | int keyIndex = -1; |
| 192 | |
| 193 | // Key at zero is the start point |
| 194 | if( time == 0.0f ) |
| 195 | { |
| 196 | m_startValue = value; |
| 197 | return keyIndex; |
| 198 | } |
| 199 | |
| 200 | // time at the end point is the end key |
| 201 | if( time == m_length ) |
| 202 | { |
| 203 | m_endValue = value; |
| 204 | return keyIndex; |
| 205 | } |
| 206 | |
| 207 | // If there are no keys, the sorting will not fix the curve |
| 208 | // Therefor, we have to create a new key at current endpoint and then move the endpoint |
| 209 | // to the new value. |
| 210 | if( m_keys.empty() ) |
| 211 | { |
| 212 | if( time > m_length ) |
| 213 | { |
| 214 | if( m_length > 0.0f ) |
| 215 | { |
| 216 | // Need to create a new key here using the current endpoint value |
| 217 | AddKey_( m_length, m_endValue ); |
| 218 | |
| 219 | // We know that we have 1 and only 1 key in m_keys. |
| 220 | keyIndex = 0; |
| 221 | } |
| 222 | |
| 223 | // Update end value |
| 224 | m_length = time; |
| 225 | m_endValue = value; |
| 226 | |
| 227 | // If keyIndex == -1 => |
| 228 | // We got a time value > 0 for a curve of zero length |
| 229 | // Thus, we have shifted the length to that time value |
| 230 | // and updated the end value accordingly. |
| 231 | if( keyIndex == -1 ) |
| 232 | { |
| 233 | return keyIndex; |
| 234 | } |
| 235 | } |
| 236 | else |
| 237 | { |
| 238 | // If we are between the begin and end. |
| 239 | AddKey_( time, value ); |
| 240 | return 0; |
| 241 | } |
| 242 | } |
no test coverage detected