// wait until time to display next frame
while(nextFrameTime_ms > millis());
// calculate time to display next frame
nextFrameTime_ms = millis() + (10 * frameDelay);
if(updateScreenCallback)
(*updateScreenCallback)();
Ideally we want nextFrameTime_ms to be exactly equal to millis() when we calculate the time for next frame. If however it's taken longer, and now nextFrameTime_ms is less than millis(), we update the frame late, and extend that delay into the nextFrameTime_ms calculation, so a late frame makes the next frame even later, instead of trying to make up the delay. The nextFrameTime_ms calculation should take this into account.
Potentially if keeping the pacing of the GIF is important and we get behind we may want to skip frames
Ideally we want
nextFrameTime_ms
to be exactly equal tomillis()
when we calculate the time for next frame. If however it's taken longer, and nownextFrameTime_ms
is less thanmillis()
, we update the frame late, and extend that delay into thenextFrameTime_ms
calculation, so a late frame makes the next frame even later, instead of trying to make up the delay. ThenextFrameTime_ms
calculation should take this into account.Potentially if keeping the pacing of the GIF is important and we get behind we may want to skip frames