Ignore:
Timestamp:
Aug 15, 2010, 4:29:11 PM (10 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/test-map.cpp

    r112 r116  
    1818#include "ticker.h"
    1919#include "video.h"
     20
     21static int const FPS = 30.0f;
    2022
    2123int main(int argc, char **argv)
     
    4042    SDL_WM_GrabInput(SDL_GRAB_ON);
    4143
    42     /* Initialise timer */
    43     Uint32 ticks = SDL_GetTicks();
    44 
    4544    /* Initialise OpenGL */
    4645    Video::Setup(video->w, video->h);
     
    5554    while (!game->Finished())
    5655    {
    57         /* Compute delta time */
    58         Uint32 newticks = SDL_GetTicks();
    59         float delta_time = (float)(newticks - ticks);
    60         ticks = newticks;
    61 
    6256        /* Tick the game */
    63         Ticker::TickGame(delta_time);
     57        Ticker::TickGame();
    6458
    6559        /* Clear the screen, tick the renderer, and show the frame */
    6660        Video::Clear();
    67         Ticker::TickRender(delta_time);
     61        Ticker::TickRender();
    6862        SDL_GL_SwapBuffers();
    6963
    7064        /* Clamp to desired framerate */
    71         while (SDL_GetTicks() < ticks + (33.33333f - 0.5f))
    72             SDL_Delay(1);
     65        Ticker::ClampFps(FPS);
    7366    }
    7467
Note: See TracChangeset for help on using the changeset viewer.