| 258 | |
| 259 | |
| 260 | void update_position(animation_position &p_animation_position, animation const &p_animation, unsigned int const p_increase) |
| 261 | { |
| 262 | p_animation_position.m_frame_nr_in_part += p_increase; |
| 263 | if (p_animation_position.m_part_nr >= p_animation.get_num_parts()) |
| 264 | p_animation_position.m_part_nr = p_animation.get_num_parts() - 1; |
| 265 | |
| 266 | // After m_frame_nr_in_part was incremented by p_increase, its value |
| 267 | // may lie outside of the bounds of the part. This means the new position |
| 268 | // is actually beyond the current part, so try moving to the next part, |
| 269 | // and see if the m_frame_nr_in_part value there is inside the bounds. If |
| 270 | // not, move to the next part again etc. until m_frame_nr_in_part fits in |
| 271 | // the part's bounds, or until the last part is reached. |
| 272 | while (true) |
| 273 | { |
| 274 | animation::part const &part = *(p_animation.get_part(p_animation_position.m_part_nr)); |
| 275 | |
| 276 | // If m_frame_nr_in_part lies within the bounds of the current part, |
| 277 | // exit, since we are done. |
| 278 | if (p_animation_position.m_frame_nr_in_part < part.m_frames.size()) |
| 279 | break; |
| 280 | |
| 281 | // If the current part is the last one, simply do a modulo on |
| 282 | // m_frame_nr_in_part, thereby looping inside the last part. |
| 283 | if (p_animation_position.m_part_nr == (p_animation.get_num_parts() - 1)) |
| 284 | { |
| 285 | p_animation_position.m_frame_nr_in_part = p_animation_position.m_frame_nr_in_part % part.m_frames.size(); |
| 286 | break; |
| 287 | } |
| 288 | |
| 289 | // If this point is reached, it means that (1) the current part is not |
| 290 | // the last part in the animation and (2) m_frame_nr_in_part still lies |
| 291 | // outside of the part's bounds. Increase the part's loop count, and |
| 292 | // if the maximum number of loops is reached, advance to the next part. |
| 293 | p_animation_position.m_part_loop_nr++; |
| 294 | p_animation_position.m_frame_nr_in_part -= part.m_frames.size(); |
| 295 | if (p_animation_position.m_part_loop_nr >= part.m_num_times_to_play) |
| 296 | { |
| 297 | p_animation_position.m_part_loop_nr = 0; |
| 298 | p_animation_position.m_part_nr++; |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | |
| 304 | } // namespace easysplash end |
no test coverage detected