]> git.draconx.ca Git - liblbx.git/commitdiff
lbxgui: Implement frame dropping for animation.
authorNick Bowler <nbowler@draconx.ca>
Thu, 11 Feb 2010 05:06:54 +0000 (00:06 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 11 Feb 2010 05:06:54 +0000 (00:06 -0500)
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

index da03cfbcfc823ecd3754b57d346e442f39f83db4..2c1235aab0d3924c76a04955a586202f96dd8c39 100644 (file)
@@ -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);