Ignore:
Timestamp:
Aug 15, 2010, 4:29:11 PM (11 years ago)
Author:
sam
Message:

Implement a better timing mechanism for fixed framerate. Accuracy is
sub-millisecond but can be improved if we get rid of SDL timers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gtk/editor.cpp

    r114 r116  
    2222static volatile int quit = 0;
    2323
    24 static GTimer *timer;
    25 static float delta_time;
    2624static int ticking = 0;
     25static float const FPS = 30.0f;
    2726
    2827static gint main_quit(GtkWidget *widget, GdkEventExpose *event)
     
    3938{
    4039    // FIXME: do not do anything if the previous tick was too recent?
    41     delta_time = 1000.0f * g_timer_elapsed(timer, NULL);
    42     g_timer_start(timer);
    4340
    4441    // FIXME: only quit if all assets have been cleaned
     
    4946
    5047    /* Tick the game */
    51     Ticker::TickGame(delta_time);
     48    Ticker::TickGame();
    5249
    5350    gtk_widget_draw(GTK_WIDGET(widget), NULL);
     
    8380        /* Clear the screen, tick the renderer, and show the frame */
    8481        Video::Clear();
    85         Ticker::TickRender(delta_time);
     82        Ticker::TickRender();
    8683        gtk_gl_area_swapbuffers(GTK_GL_AREA(widget));
     84        Ticker::ClampFps(FPS);
    8785    }
    8886
     
    159157
    160158    //gtk_idle_add(tick, glarea);
    161     gtk_timeout_add(33, tick, glarea);
     159    gtk_timeout_add(1000 / FPS, tick, glarea);
    162160
    163     timer = g_timer_new();
    164161    gtk_main();
    165162
Note: See TracChangeset for help on using the changeset viewer.