Timing question

Hello all

I’ve got the old problem of trying to make a
framerate-independent game loop. The problem is the
resolution of SDL_GetTicks(). 1ms isn’t fine enough!

What I want to do is have the graphics subsystem
separate from the game loop, probably with each
running in their own thread. I want the game loop to
cycle as fast as it can and the graphics should
(although not necessarily) cycle a little slower. The
thing is that I need sub-millisecond accuracy because
one iteration of the main loop can take less than a
millisecond (especially when I don’t draw any
graphical output) and then errors start to creep in to
the physics engine.

Last time I did any serious game development was under
DOS where you have access to a more precise timer. How
do you get around the problem of a low-resolution
timer?

Thanks

–jaa__________________________________________________
Do You Yahoo!?
Everything you’ll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

Had the same problem some time ago, but the solution is quite simple and
does not requires hi res clock:
Simply do not measure the length of a single frame, instead count the
number of frames per second:

Int time = clock();
Int fps=0;
While(1)
{
fps++;
if(clock()-time < 1000)
{
if(fps!=0)dt= 1.0 / fps;
fps=0;
time=clock();
}
}

Sure, you have some delay in adaption of fps, but you may shorten the
measuring time to 500 ms or 250 ms.

-----Urspr?ngliche Nachricht-----Von: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] Im Auftrag von
James Arthur
Gesendet: Sonntag, 4. August 2002 18:47
An: sdl at libsdl.org
Betreff: [SDL] Timing question

Hello all

I’ve got the old problem of trying to make a framerate-independent game
loop. The problem is the resolution of SDL_GetTicks(). 1ms isn’t fine
enough!

What I want to do is have the graphics subsystem
separate from the game loop, probably with each
running in their own thread. I want the game loop to
cycle as fast as it can and the graphics should
(although not necessarily) cycle a little slower. The
thing is that I need sub-millisecond accuracy because
one iteration of the main loop can take less than a
millisecond (especially when I don’t draw any
graphical output) and then errors start to creep in to
the physics engine.

Last time I did any serious game development was under
DOS where you have access to a more precise timer. How
do you get around the problem of a low-resolution
timer?

Thanks

–jaa


Do You Yahoo!?
Everything you’ll ever need on one web page
from News and Sport to Email and Music Charts http://uk.my.yahoo.com


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

-----Urspr?ngliche Nachricht-----
Von: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] Im Auftrag von
James Arthur
Gesendet: Sonntag, 4. August 2002 18:47
An: sdl at libsdl.org
Betreff: [SDL] Timing question

Hello all

I’ve got the old problem of trying to make a framerate-independent game
loop. The problem is the resolution of SDL_GetTicks(). 1ms isn’t fine
enough!

What I want to do is have the graphics subsystem
separate from the game loop, probably with each
running in their own thread. I want the game loop to
cycle as fast as it can and the graphics should
(although not necessarily) cycle a little slower. The
thing is that I need sub-millisecond accuracy because
one iteration of the main loop can take less than a
millisecond (especially when I don’t draw any
graphical output) and then errors start to creep in to
the physics engine.

Last time I did any serious game development was under
DOS where you have access to a more precise timer. How
do you get around the problem of a low-resolution
timer?

Thanks

–jaa


Do You Yahoo!?
Everything you’ll ever need on one web page
from News and Sport to Email and Music Charts http://uk.my.yahoo.com


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Thanks Andre, that’s exactly what I’m after. Seems so
obvious now, but a little weird since I’m used to
programming non-real-time simulations :slight_smile:

–jaa

— Andre Krause wrote: > Had
the same problem some time ago, but the solution> is quite simple and

does not requires hi res clock:
Simply do not measure the length of a single frame,
instead count the
number of frames per second:

Int time = clock();
Int fps=0;
While(1)
{
fps++;
if(clock()-time < 1000)
{
if(fps!=0)dt= 1.0 / fps;
fps=0;
time=clock();
}
}

Sure, you have some delay in adaption of fps, but
you may shorten the
measuring time to 500 ms or 250 ms.


Do You Yahoo!?
Everything you’ll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

Simply count not the length of a single frame, instead count the number
of frames per second:

Int time = clock();
Int fps=0;
While(1)
{
fps++;
if(clock()-time < 1000)
{
if(fps!=0)dt= 1.0 / fps;
fps=0;
time=clock();
}
}

-----Urspr?ngliche Nachricht-----Von: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] Im Auftrag von
James Arthur
Gesendet: Sonntag, 4. August 2002 18:47
An: sdl at libsdl.org
Betreff: [SDL] Timing question

Hello all

I’ve got the old problem of trying to make a framerate-independent game
loop. The problem is the resolution of SDL_GetTicks(). 1ms isn’t fine
enough!

What I want to do is have the graphics subsystem
separate from the game loop, probably with each
running in their own thread. I want the game loop to
cycle as fast as it can and the graphics should
(although not necessarily) cycle a little slower. The
thing is that I need sub-millisecond accuracy because
one iteration of the main loop can take less than a
millisecond (especially when I don’t draw any
graphical output) and then errors start to creep in to
the physics engine.

Last time I did any serious game development was under
DOS where you have access to a more precise timer. How
do you get around the problem of a low-resolution
timer?

Thanks

–jaa


Do You Yahoo!?
Everything you’ll ever need on one web page
from News and Sport to Email and Music Charts http://uk.my.yahoo.com


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl