From 355bc49a264c582f780710a09338ed30dbeb1475 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Thu, 11 Feb 2010 00:06:54 -0500 Subject: [PATCH] lbxgui: Implement frame dropping for animation. Currently, if it takes longer than 1/15th of a second to draw a frame, the next frame will be queued before it has a chance to finish, which then takes longer than 1/15th of a second to draw, so the next one gets queued, ad infinitum. We do two things to solve this problem. First, the timer runs at a low priority so that a redraw doesn't get queued while a redraw is in progress. Second, the timer skips queueing any frames that have missed their time. --- src/gui/lbxgui.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/gui/lbxgui.c b/src/gui/lbxgui.c index da03cfb..2c1235a 100644 --- a/src/gui/lbxgui.c +++ b/src/gui/lbxgui.c @@ -83,7 +83,7 @@ static void tick(void *p, double delta) struct lbx_imginfo info; GtkSpinButton *spin; GtkToggleButton *play; - unsigned frame; + unsigned frame, newframe; if (!image) return; @@ -97,20 +97,22 @@ static void tick(void *p, double delta) return; elapsed += delta; + newframe = frame; while (elapsed > seconds_per_frame) { elapsed -= seconds_per_frame; - if (++frame >= info.nframes) { + if (++newframe >= info.nframes) { if (!info.looping) { gtk_toggle_button_set_active(play, FALSE); break; } - frame = info.loopstart; + newframe = info.loopstart; } - - gtk_spin_button_set_value(spin, frame); } + + if (frame != newframe) + gtk_spin_button_set_value(spin, newframe); } static gboolean timeout(gpointer data) @@ -492,7 +494,7 @@ int main(int argc, char **argv) init_interface(); gtk_builder_connect_signals(builder, window); - g_timeout_add(10, timeout, NULL); + g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE, 10, timeout, NULL, NULL); gtk_widget_show_all(window); init_background(canvas->window); -- 2.43.2