improve final animation frame precision

This commit is contained in:
Felix Kratz 2023-08-23 15:02:21 +02:00
parent e5e24cb6b6
commit dba2cd2670

View file

@ -3,6 +3,7 @@
static CVReturn animation_frame_callback(CVDisplayLinkRef display_link, const CVTimeStamp* now, const CVTimeStamp* output_time, CVOptionFlags flags, CVOptionFlags* flags_out, void* context) { static CVReturn animation_frame_callback(CVDisplayLinkRef display_link, const CVTimeStamp* now, const CVTimeStamp* output_time, CVOptionFlags flags, CVOptionFlags* flags_out, void* context) {
double time_scale = 60. * CVDisplayLinkGetActualOutputVideoRefreshPeriod(display_link); double time_scale = 60. * CVDisplayLinkGetActualOutputVideoRefreshPeriod(display_link);
if (time_scale <= 0) time_scale = 1.;
struct event event = { *((void**)&time_scale), ANIMATOR_REFRESH }; struct event event = { *((void**)&time_scale), ANIMATOR_REFRESH };
event_post(&event); event_post(&event);
return kCVReturnSuccess; return kCVReturnSuccess;
@ -49,9 +50,7 @@ void animation_setup(struct animation* animation, void* target, animator_functio
} }
static bool animation_update(struct animation* animation, double time_scale) { static bool animation_update(struct animation* animation, double time_scale) {
if (!animation->target if (!animation->target || !animation->update_function) {
|| !animation->update_function
|| animation->counter > animation->duration) {
return false; return false;
} }
@ -60,7 +59,8 @@ static bool animation_update(struct animation* animation, double time_scale) {
return false; return false;
} }
double slider = animation->duration > 1 double slider = (animation->duration > 1
&& animation->counter < animation->duration)
? animation->interp_function(animation->counter ? animation->interp_function(animation->counter
/ animation->duration) / animation->duration)
: 1.0; : 1.0;