| 278 | } |
| 279 | |
| 280 | static void PostEvents(HRigInstance instance, RigPlayer* player, const dmRigDDF::RigAnimation* animation, float dt, float prev_cursor, float duration, bool completed, float blend_weight) |
| 281 | { |
| 282 | float cursor = player->m_Cursor; |
| 283 | // Since the intervals are defined as t0 <= t < t1, make sure we include the end of the animation, i.e. when t1 == duration |
| 284 | if (completed) |
| 285 | cursor += dt; |
| 286 | // If the start cursor is greater than the end cursor, we have looped and handle that as two distinct intervals: [0,end_cursor) and [start_cursor,duration) |
| 287 | // Note that for looping ping pong, one event can be triggered twice during the same frame by appearing in both intervals |
| 288 | if (prev_cursor > cursor) |
| 289 | { |
| 290 | bool prev_backwards = player->m_Backwards; |
| 291 | // Handle the flipping nature of ping pong |
| 292 | if (player->m_Playback == dmRig::PLAYBACK_LOOP_PINGPONG) |
| 293 | { |
| 294 | prev_backwards = !player->m_Backwards; |
| 295 | } |
| 296 | PostEventsInterval(instance, animation, prev_cursor, duration, duration, prev_backwards, blend_weight); |
| 297 | PostEventsInterval(instance, animation, 0.0f, cursor, duration, player->m_Backwards, blend_weight); |
| 298 | } |
| 299 | else |
| 300 | { |
| 301 | // Special handling when we reach the way back of once ping pong playback |
| 302 | float half_duration = duration * 0.5f; |
| 303 | if (player->m_Playback == dmRig::PLAYBACK_ONCE_PINGPONG && cursor > half_duration) |
| 304 | { |
| 305 | // If the previous cursor was still in the forward direction, treat it as two distinct intervals: [start_cursor,half_duration) and [half_duration, end_cursor) |
| 306 | if (prev_cursor < half_duration) |
| 307 | { |
| 308 | PostEventsInterval(instance, animation, prev_cursor, half_duration, duration, false, blend_weight); |
| 309 | PostEventsInterval(instance, animation, half_duration, cursor, duration, true, blend_weight); |
| 310 | } |
| 311 | else |
| 312 | { |
| 313 | PostEventsInterval(instance, animation, prev_cursor, cursor, duration, true, blend_weight); |
| 314 | } |
| 315 | } |
| 316 | else |
| 317 | { |
| 318 | PostEventsInterval(instance, animation, prev_cursor, cursor, duration, player->m_Backwards, blend_weight); |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | static void UpdatePlayer(RigInstance* instance, RigPlayer* player, float dt, float blend_weight) |
| 324 | { |
no test coverage detected