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

Proper delta time computation in both the game and the editor.

File:
1 edited

Legend:

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

    r111 r112  
    2020#include "game.h"
    2121
    22 volatile int quit = 0;
     22static volatile int quit = 0;
     23
     24static GTimer *timer;
     25static float delta_time;
     26static int ticking = 0;
    2327
    2428static gint main_quit(GtkWidget *widget, GdkEventExpose *event)
     
    3438static gboolean tick(void *widget)
    3539{
    36     float const delta_time = 33.33333f;
    37 
    3840    // 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);
    3943
    4044    // FIXME: only quit if all assets have been cleaned
    4145    if (quit)
    4246        return FALSE;
     47
     48    ticking = 1;
    4349
    4450    /* Tick the game */
     
    7177
    7278    /* OpenGL functions can be called only if make_current returns true */
    73     if (gtk_gl_area_make_current(GTK_GL_AREA(widget)))
     79    if (ticking && gtk_gl_area_make_current(GTK_GL_AREA(widget)))
    7480    {
    75         // FIXME: do not do anything if the game tick wasn't called?
    76         float const delta_time = 33.33333f;
     81        ticking = 0;
    7782
    7883        /* Clear the screen, tick the renderer, and show the frame */
     
    8893{
    8994    /* Initialize GTK */
     95    g_thread_init(NULL);
    9096    gtk_init(&argc, &argv);
    9197
     
    152158    //gtk_idle_add(tick, glarea);
    153159    gtk_timeout_add(33, tick, glarea);
     160
     161    timer = g_timer_new();
    154162    gtk_main();
    155163
Note: See TracChangeset for help on using the changeset viewer.