-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
PH-Neutre escribi?:
hello,
I’ve read and re-read the chapter of SDL documentation that deals
with timing but I’m not really sure about what i can do with them.
My purpose is to make a game, (that uses openGL) programmed with
SDL, runs at the same speed on different PCs (a well-known problem
I believe timing fonctions of SDL can help me in doing this but i’m
not sure about how to use them (SDL’s documentation is poor on this
subject). I probably need to get the time between each frame drawn
and to adjust the moves. I saw that SDL_GetTicks() can do this but
do I need to have a “callback” ? Do I need to call SDL_SetTimer,
and with which “interval” ?
thanks in advance, and thanks a lot to Gautier Portet and to
Mattias Engdeg?rd for their answers to my previous question.
PH.
What I do to keep my game running at a constant speed in on
different machines is to set a callback. For instance, if I want my
game to run at 20 cicles per second , I use two global int variables:
real_cicles and done_cicles , and this calback function:
Uint32 cicle(Uint32 time){
real_cicles++;
return time; //the function must return the same value it received
to keep the same timing
}
Then I set the callback calling:
SDL_SetTimer(50,cicle); //the callback will be called every 50
miliseconds. That’s twenty times a minute.
I have also two functions (update() and frame(), for example). The
first one updates all data for the next game frame but does nothing
with graphics. The second one blits images, updates surfaces, etc
(shows the next frame). update() also does done_cicles++. Finally,
the code for the main game loop is similar to this:
do{
int lastcicles;
lastcicles=done_cicles;
while(done_cicles<real_cicles) update();
if(lastcicles!=done_cicles);frame();
}while(exit==0);
This way the games runs at up to 20fps, and even if it is not able
to show all frames, the game speed will be the same (of course, on a
slow machine the game will look very ugly, cause it will skip may
frames). You could also supress the last if (and the first two
sentences) to avoid setting a limit to the frame rate.
I don't know if this is the usual way, but it seems to work.
Un saludo.
P.S. I think SDL also has a new timer callback system able to
maintain several callbacks running at the same time. I use the old
one because I don’t need more than one callback, and this system is
simpler.
Jes?s Carrete Monta?a ----> KUANTIKO___________________________________________
| .~. |
| /V\ jrcarmon(arroba)teleline.es |
| // \ Linux Registered |
| /( )\ User #158442 |
| ^`~’^ |
|___________________________________________|
Clave p?blica PGP disponible por e-mail.
-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.1i for non-commercial use http://www.pgpi.com/
iQA+AwUBOWcH61XBzV6UX+HYEQJV+wCXaMtPoxCTtsL2stK81J1dGo0o+wCgwlbh
2NAg+l+kmyvuBrNR+P50oFw=
=pknN
-----END PGP SIGNATURE-----