From fe6cc1491a6fedc7978da5478d87ca260994b9c7 Mon Sep 17 00:00:00 2001 From: Madadog <53168336+Madadog@users.noreply.github.com> Date: Thu, 2 Mar 2023 11:32:28 +1000 Subject: [PATCH] Clamp max of movie->tick to item->time Fixes https://github.com/nesbox/TIC-80/issues/1913. animEffect seems to expect a value between 0 and 1, and #1913 is caused by the surf coverFade animation lerping past 1, feeding values greater than 256 into fadePalette(), causing the flashing colors. This PR clamps movie ticks for each item ensuring animEffect won't receive values > 1. This could create issues if any animation items rely on playing past their end. I didn't notice any while visually checking the editor and surf menu animations, but I could easily have missed something. It might be better to move this clamp directly into animEffect(). Some of the AnimEffects already clamp x to a maximum of 1 (e.g. AnimEaseInElastic) but most don't. #1913 could also be fixed by clamping the fadePalette() value between 0 and 256, though the lerp animation will eventually overflow. --- src/studio/studio.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/studio/studio.c b/src/studio/studio.c index ec081e828..aa4df6014 100644 --- a/src/studio/studio.c +++ b/src/studio/studio.c @@ -914,7 +914,10 @@ static inline float animEffect(AnimEffect effect, float x) static void animTick(Movie* movie) { for(Anim* it = movie->items, *end = it + movie->count; it != end; ++it) - *it->value = lerp(it->start, it->end, animEffect(it->effect, (float)movie->tick / it->time)); + { + float tick = (float)(movie->tick < it->time ? movie->tick : it->time); + *it->value = lerp(it->start, it->end, animEffect(it->effect, tick / it->time)); + } } void processAnim(Movie* movie, void* data)