Skip to content

Commit

Permalink
Clamp max of movie->tick to item->time
Browse files Browse the repository at this point in the history
Fixes nesbox#1913.

animEffect seems to expect a value between 0 and 1, and nesbox#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.

nesbox#1913 could also be fixed by clamping the fadePalette() value between 0 and 256, though the lerp animation will eventually overflow.
  • Loading branch information
Madadog authored Mar 2, 2023
1 parent ecbcae5 commit fe6cc14
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/studio/studio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fe6cc14

Please sign in to comment.