diff options
| author | Fred Sundvik <fsundvik@gmail.com> | 2016-04-24 15:45:52 +0300 |
|---|---|---|
| committer | Fred Sundvik <fsundvik@gmail.com> | 2016-04-24 15:45:52 +0300 |
| commit | 444132edd056cd52a60e3551d1f6c1a07909c040 (patch) | |
| tree | 92f6a79294d104053b7709a4d424d90f45afb10b | |
| parent | 0e0488623e8d8820a909a48a6c847866a65bf845 (diff) | |
| download | qmk_firmware-444132edd056cd52a60e3551d1f6c1a07909c040.tar.gz qmk_firmware-444132edd056cd52a60e3551d1f6c1a07909c040.zip | |
Add last and first update of frame for anims
| -rw-r--r-- | visualizer.c | 9 | ||||
| -rw-r--r-- | visualizer.h | 2 |
2 files changed, 11 insertions, 0 deletions
diff --git a/visualizer.c b/visualizer.c index ed5c9fa2c..219d44cd3 100644 --- a/visualizer.c +++ b/visualizer.c | |||
| @@ -103,6 +103,8 @@ void stop_keyframe_animation(keyframe_animation_t* animation) { | |||
| 103 | animation->current_frame = animation->num_frames; | 103 | animation->current_frame = animation->num_frames; |
| 104 | animation->time_left_in_frame = 0; | 104 | animation->time_left_in_frame = 0; |
| 105 | animation->need_update = true; | 105 | animation->need_update = true; |
| 106 | animation->first_update_of_frame = false; | ||
| 107 | animation->last_update_of_frame = false; | ||
| 106 | for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) { | 108 | for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) { |
| 107 | if (animations[i] == animation) { | 109 | if (animations[i] == animation) { |
| 108 | animations[i] = NULL; | 110 | animations[i] = NULL; |
| @@ -117,6 +119,8 @@ void stop_all_keyframe_animations(void) { | |||
| 117 | animations[i]->current_frame = animations[i]->num_frames; | 119 | animations[i]->current_frame = animations[i]->num_frames; |
| 118 | animations[i]->time_left_in_frame = 0; | 120 | animations[i]->time_left_in_frame = 0; |
| 119 | animations[i]->need_update = true; | 121 | animations[i]->need_update = true; |
| 122 | animations[i]->first_update_of_frame = false; | ||
| 123 | animations[i]->last_update_of_frame = false; | ||
| 120 | animations[i] = NULL; | 124 | animations[i] = NULL; |
| 121 | } | 125 | } |
| 122 | } | 126 | } |
| @@ -133,16 +137,20 @@ static bool update_keyframe_animation(keyframe_animation_t* animation, visualize | |||
| 133 | animation->current_frame = 0; | 137 | animation->current_frame = 0; |
| 134 | animation->time_left_in_frame = animation->frame_lengths[0]; | 138 | animation->time_left_in_frame = animation->frame_lengths[0]; |
| 135 | animation->need_update = true; | 139 | animation->need_update = true; |
| 140 | animation->first_update_of_frame = true; | ||
| 136 | } else { | 141 | } else { |
| 137 | animation->time_left_in_frame -= delta; | 142 | animation->time_left_in_frame -= delta; |
| 138 | while (animation->time_left_in_frame <= 0) { | 143 | while (animation->time_left_in_frame <= 0) { |
| 139 | int left = animation->time_left_in_frame; | 144 | int left = animation->time_left_in_frame; |
| 140 | if (animation->need_update) { | 145 | if (animation->need_update) { |
| 141 | animation->time_left_in_frame = 0; | 146 | animation->time_left_in_frame = 0; |
| 147 | animation->last_update_of_frame = true; | ||
| 142 | (*animation->frame_functions[animation->current_frame])(animation, state); | 148 | (*animation->frame_functions[animation->current_frame])(animation, state); |
| 149 | animation->last_update_of_frame = false; | ||
| 143 | } | 150 | } |
| 144 | animation->current_frame++; | 151 | animation->current_frame++; |
| 145 | animation->need_update = true; | 152 | animation->need_update = true; |
| 153 | animation->first_update_of_frame = true; | ||
| 146 | if (animation->current_frame == animation->num_frames) { | 154 | if (animation->current_frame == animation->num_frames) { |
| 147 | if (animation->loop) { | 155 | if (animation->loop) { |
| 148 | animation->current_frame = 0; | 156 | animation->current_frame = 0; |
| @@ -159,6 +167,7 @@ static bool update_keyframe_animation(keyframe_animation_t* animation, visualize | |||
| 159 | } | 167 | } |
| 160 | if (animation->need_update) { | 168 | if (animation->need_update) { |
| 161 | animation->need_update = (*animation->frame_functions[animation->current_frame])(animation, state); | 169 | animation->need_update = (*animation->frame_functions[animation->current_frame])(animation, state); |
| 170 | animation->first_update_of_frame = false; | ||
| 162 | } | 171 | } |
| 163 | 172 | ||
| 164 | int wanted_sleep = animation->need_update ? 10 : animation->time_left_in_frame; | 173 | int wanted_sleep = animation->need_update ? 10 : animation->time_left_in_frame; |
diff --git a/visualizer.h b/visualizer.h index 6a72fde1f..82d7a71d3 100644 --- a/visualizer.h +++ b/visualizer.h | |||
| @@ -95,6 +95,8 @@ typedef struct keyframe_animation_t { | |||
| 95 | // keyframe update functions | 95 | // keyframe update functions |
| 96 | int current_frame; | 96 | int current_frame; |
| 97 | int time_left_in_frame; | 97 | int time_left_in_frame; |
| 98 | bool first_update_of_frame; | ||
| 99 | bool last_update_of_frame; | ||
| 98 | bool need_update; | 100 | bool need_update; |
| 99 | 101 | ||
| 100 | } keyframe_animation_t; | 102 | } keyframe_animation_t; |
