#include <animated.hpp>
Classes | |
| struct | frame |
Public Types | |
| typedef std::pair< std::chrono::milliseconds, T > | frame_description |
| typedef std::vector< frame_description > | anim_description |
Public Member Functions | |
| animated (const std::chrono::milliseconds &start_time=std::chrono::milliseconds{0}) | |
| Creates an animation with no frames; add_frame() populates it afterward. More... | |
| animated (const anim_description &cfg, const std::chrono::milliseconds &start_time=std::chrono::milliseconds{0}, bool force_change=false) | |
| Creates an animation with its frame list already built from cfg. More... | |
| virtual | ~animated ()=default |
| void | add_frame (const std::chrono::milliseconds &duration, const T &value, bool force_change=false) |
| Appends a frame, starting where the previous one ends (or at start_time, if first). More... | |
| void | start_animation (const std::chrono::milliseconds &start_time_offset, bool cycles=false) |
| Anchors the timeline to the current tick, then begins playback. More... | |
| void | pause_animation () |
| Freezes the timeline in place. More... | |
| void | resume_animation () |
| Shifts the timeline forward by the time spent paused, then continues playback. More... | |
| void | advance_to_current_frame () |
| Moves current_frame_index_ forward to match the current tick, one frame at a time (or in whole cycles, if far enough behind). More... | |
| bool | need_update () const |
| True once the current tick has reached the current frame's end, meaning advance_to_current_frame() has a new frame to move to. More... | |
| bool | animation_finished () const |
| True if playback has run past the last frame, is not yet started, or has no frames. More... | |
| bool | cycles () const |
| True if the animation loops back to the first frame instead of stopping at the last. More... | |
| std::chrono::milliseconds | get_elapsed_time () const |
| Time since playback began, per get_playback_tick(). More... | |
| void | apply_time_offset (const std::chrono::milliseconds &time) |
| Shifts the timeline so the current tick corresponds to the given animation time, then restarts frame tracking from the beginning to resync. More... | |
| void | set_duration_limit (const std::chrono::milliseconds &time) |
| std::chrono::milliseconds | get_animation_duration () const |
| get_end_time() minus get_begin_time(): how long one pass through all frames takes. More... | |
| std::chrono::milliseconds | get_begin_time () const |
| Animation-time offset of the first frame's start. More... | |
| std::chrono::milliseconds | get_end_time () const |
| Animation-time offset where the last frame ends. More... | |
| void | set_begin_time (const std::chrono::milliseconds &new_begin_time) |
| Rebases the timeline onto a new begin time, offsetting every frame's start_time_ by the difference so their durations and order are unchanged. More... | |
| std::chrono::milliseconds | get_current_frame_begin_time () const |
| Animation-time offset where the current frame starts. More... | |
| std::chrono::milliseconds | get_current_frame_end_time () const |
| Animation-time offset where the current frame ends. More... | |
| std::chrono::milliseconds | get_time_in_current_frame () const |
| How far into its own duration the current frame is, clamped to [0, duration]. More... | |
| const T & | get_current_frame () const |
| const T & | get_first_frame () const |
| const T & | get_frame (std::size_t n) const |
| const T & | get_last_frame () const |
| std::size_t | get_frames_count () const |
| void | force_change () |
| Clears the flag returned by is_static(). More... | |
| bool | is_static () const |
| True when the single-unchanging-frame optimization is enabled: need_update() will always report false, since there is never a different frame to advance to. More... | |
| void | set_uses_acceleration (bool uses_accel) |
| Selects which of the two global timelines get_current_animation_tick() reads for this animation: accelerated if true, normal if false. More... | |
| bool | uses_acceleration () const |
| Which timeline this animation currently reads; see set_uses_acceleration(). More... | |
Static Public Attributes | |
| static const T | void_value_ |
Protected Member Functions | |
| void | remove_frames_until (const std::chrono::milliseconds &starting_time) |
| Drops whole frames from the front while their end time is still before starting_time, then advances the begin time by their durations. More... | |
| void | set_end_time (const std::chrono::milliseconds &ending_time) |
| Reduces or extends the frame list so get_end_time() becomes ending_time: drops frames after the cut and shortens the one it falls in, extends the last frame if ending_time is later, or (if ending_time is before the current begin time) collapses to a zero-length first frame. More... | |
Private Member Functions | |
| std::chrono::steady_clock::time_point | get_playback_tick () const |
| The tick get_elapsed_time() and get_time_in_current_frame() treat as "now": frozen at pause_tick_ while paused_, otherwise the live tick from get_current_animation_tick(). More... | |
Private Attributes | |
| std::chrono::milliseconds | starting_frame_time_ |
| std::chrono::milliseconds | max_animation_time_ |
| std::vector< frame > | frames_ |
| std::size_t | current_frame_index_ |
| bool | started_ |
| bool | paused_ |
| bool | finished_ |
| bool | cycles_ |
| bool | uses_acceleration_ |
| std::chrono::steady_clock::time_point | animation_start_tick_ |
| std::chrono::steady_clock::time_point | next_frame_tick_ |
| std::chrono::steady_clock::time_point | pause_tick_ |
| bool | is_static_ |
Friends | |
| class | unit_animation |
Definition at line 48 of file animated.hpp.
| typedef std::vector<frame_description> animated< T >::anim_description |
Definition at line 52 of file animated.hpp.
| typedef std::pair<std::chrono::milliseconds, T> animated< T >::frame_description |
Definition at line 51 of file animated.hpp.
| animated< T >::animated | ( | const std::chrono::milliseconds & | start_time = std::chrono::milliseconds{0} | ) |
Creates an animation with no frames; add_frame() populates it afterward.
| start_time | Logical start time of the animation timeline (default 0ms) |
|
explicit |
Creates an animation with its frame list already built from cfg.
| cfg | Sequence of (duration, value) pairs to build the frame list from |
| start_time | Logical start time of the animation timeline |
| force_change | See add_frame(). Applies to the whole sequence built from cfg. |
| void animated< T >::add_frame | ( | const std::chrono::milliseconds & | duration, |
| const T & | value, | ||
| bool | force_change = false |
||
| ) |
Appends a frame, starting where the previous one ends (or at start_time, if first).
| duration | How long this frame should be displayed |
| value | The data/state for this frame |
| force_change | Forces is_static() false even if this is the only frame added so far; use when the frame's own value can change over time despite the frame count. |
Referenced by unit_animation::add_frame(), terrain_builder::load_images(), terrain_builder::rebuild_terrain(), display::reinit_flags_for_team(), and unit_animation::start_animation().
| void animated< T >::advance_to_current_frame | ( | ) |
Moves current_frame_index_ forward to match the current tick, one frame at a time (or in whole cycles, if far enough behind).
Marks the animation finished() if it runs out of frames without cycles().
Referenced by unit_animation::try_advance_to_current_frame(), and terrain_builder::update_animation().
| bool animated< T >::animation_finished | ( | ) | const |
True if playback has run past the last frame, is not yet started, or has no frames.
Always true for a cycling animation, since it never runs out.
Referenced by unit_animation::animation_finished().
| void animated< T >::apply_time_offset | ( | const std::chrono::milliseconds & | time | ) |
Shifts the timeline so the current tick corresponds to the given animation time, then restarts frame tracking from the beginning to resync.
Used to desynchronize otherwise-identical animations for visual variety.
| time | e.g. 300ms starts the animation as if it had been playing for 300ms already |
|
inline |
True if the animation loops back to the first frame instead of stopping at the last.
Definition at line 112 of file animated.hpp.
References animated< T >::cycles_.
|
inline |
Clears the flag returned by is_static().
Needed because is_static_ is set purely from frame count: a single frame can still change visually over time through means this class doesn't track (e.g. unit_frame's interpolated offset/alpha/image parameters), in which case the owner must call this to keep need_update() reporting true.
Definition at line 174 of file animated.hpp.
References animated< T >::is_static_.
| std::chrono::milliseconds animated< T >::get_animation_duration | ( | ) | const |
get_end_time() minus get_begin_time(): how long one pass through all frames takes.
Referenced by terrain_builder::tile::rebuild_cache().
| std::chrono::milliseconds animated< T >::get_begin_time | ( | ) | const |
Animation-time offset of the first frame's start.
Default 0ms; see set_begin_time().
Referenced by unit_animation::get_begin_time().
| const T& animated< T >::get_current_frame | ( | ) | const |
| std::chrono::milliseconds animated< T >::get_current_frame_begin_time | ( | ) | const |
Animation-time offset where the current frame starts.
Referenced by unit_animation::get_current_frame_begin_time().
| std::chrono::milliseconds animated< T >::get_current_frame_end_time | ( | ) | const |
Animation-time offset where the current frame ends.
| std::chrono::milliseconds animated< T >::get_elapsed_time | ( | ) | const |
Time since playback began, per get_playback_tick().
0 if not started. Capped at the limit set by set_duration_limit(), if any.
Referenced by unit_animation::get_elapsed_time().
| std::chrono::milliseconds animated< T >::get_end_time | ( | ) | const |
Animation-time offset where the last frame ends.
For 3 seconds of frames starting at 500ms (see get_begin_time()), this returns 3500ms.
Referenced by unit_animation::get_end_time().
| const T& animated< T >::get_first_frame | ( | ) | const |
| const T& animated< T >::get_frame | ( | std::size_t | n | ) | const |
Referenced by terrain_builder::tile::rebuild_cache().
| std::size_t animated< T >::get_frames_count | ( | ) | const |
Referenced by terrain_builder::load_images(), and terrain_builder::tile::rebuild_cache().
| const T& animated< T >::get_last_frame | ( | ) | const |
Referenced by unit_animation::get_last_frame().
|
private |
The tick get_elapsed_time() and get_time_in_current_frame() treat as "now": frozen at pause_tick_ while paused_, otherwise the live tick from get_current_animation_tick().
Playback bookkeeping (start/pause/resume/advance) reads get_current_animation_tick() directly instead, since it needs the live clock even while paused_.
| std::chrono::milliseconds animated< T >::get_time_in_current_frame | ( | ) | const |
How far into its own duration the current frame is, clamped to [0, duration].
|
inline |
True when the single-unchanging-frame optimization is enabled: need_update() will always report false, since there is never a different frame to advance to.
Set from add_frame()/the constructor when the animation has exactly one frame, unless force_change requests otherwise; cleared permanently by add_frame() past the first frame, or by force_change().
Definition at line 181 of file animated.hpp.
References animated< T >::is_static_.
| bool animated< T >::need_update | ( | ) | const |
True once the current tick has reached the current frame's end, meaning advance_to_current_frame() has a new frame to move to.
Referenced by terrain_builder::update_animation().
| void animated< T >::pause_animation | ( | ) |
Freezes the timeline in place.
Playback continues from the same point via resume_animation().
Referenced by unit_animation::pause_animation().
|
protected |
Drops whole frames from the front while their end time is still before starting_time, then advances the begin time by their durations.
May overshoot starting_time if it falls inside a remaining frame, rather than split that frame.
| starting_time | Animation time the new begin time should reach |
| void animated< T >::resume_animation | ( | ) |
Shifts the timeline forward by the time spent paused, then continues playback.
Referenced by unit_animation::resume_animation().
| void animated< T >::set_begin_time | ( | const std::chrono::milliseconds & | new_begin_time | ) |
Rebases the timeline onto a new begin time, offsetting every frame's start_time_ by the difference so their durations and order are unchanged.
| void animated< T >::set_duration_limit | ( | const std::chrono::milliseconds & | time | ) |
| time | Elapsed time past which animation_finished() reports true regardless of actual progress (0 = no limit). Does not affect frame playback, only that query. |
Referenced by unit_animation::set_duration_limit().
|
protected |
Reduces or extends the frame list so get_end_time() becomes ending_time: drops frames after the cut and shortens the one it falls in, extends the last frame if ending_time is later, or (if ending_time is before the current begin time) collapses to a zero-length first frame.
| ending_time | Animation time the new end time should reach |
|
inline |
Selects which of the two global timelines get_current_animation_tick() reads for this animation: accelerated if true, normal if false.
Definition at line 185 of file animated.hpp.
References animated< T >::uses_acceleration_.
Referenced by unit_animation::start_animation().
| void animated< T >::start_animation | ( | const std::chrono::milliseconds & | start_time_offset, |
| bool | cycles = false |
||
| ) |
Anchors the timeline to the current tick, then begins playback.
| start_time_offset | How far into the animation to start (0 = from beginning) |
| cycles | If true, loop back to the first frame on reaching the end; if false, stop there |
Referenced by halo::halo_impl::effect::effect(), terrain_builder::load_images(), terrain_builder::rebuild_terrain(), and unit_animation::particle::start_animation().
|
inline |
Which timeline this animation currently reads; see set_uses_acceleration().
Definition at line 188 of file animated.hpp.
References animated< T >::uses_acceleration_.
|
friend |
Definition at line 193 of file animated.hpp.
|
private |
Definition at line 240 of file animated.hpp.
|
private |
Definition at line 229 of file animated.hpp.
|
private |
Definition at line 235 of file animated.hpp.
Referenced by animated< T >::cycles().
|
private |
Definition at line 234 of file animated.hpp.
Definition at line 228 of file animated.hpp.
|
private |
Definition at line 245 of file animated.hpp.
Referenced by animated< T >::force_change(), and animated< T >::is_static().
|
private |
Definition at line 225 of file animated.hpp.
|
private |
Definition at line 241 of file animated.hpp.
|
private |
Definition at line 242 of file animated.hpp.
|
private |
Definition at line 233 of file animated.hpp.
|
private |
Definition at line 232 of file animated.hpp.
|
private |
Definition at line 224 of file animated.hpp.
|
private |
Definition at line 236 of file animated.hpp.
Referenced by animated< T >::set_uses_acceleration(), and animated< T >::uses_acceleration().
|
static |
Definition at line 190 of file animated.hpp.