Mail Archives: djgpp/2000/04/06/18:09:44
Greetings, Yannick Benoit <yannick DOT benoit AT dr DOT cgocable DOT ca>! You wrote:
> hi,
> i made some part of a game and after testing it on few diferent pcs, i
found
> out that the speed is never the same, sometimes it lags and sometimes its
> too fast...
>
> is there a way to make it the same on every pcs?
I think it is better to begin code optimizations. btw, vsync() is slightly
unregular procedure when we are talking about run time.
Allegro FAQ about subj:
How can I make my game run at the same speed on any computer?
You need to make sure the game logic gets updated at a regular rate, but
skip the screen refresh every now and then if the computer is too slow to
keep up. This can be done by installing a timer handler that will increment
a global variable at your game logic speed, eg:
volatile int speed_counter = 0;
void increment_speed_counter()
{
speed_counter++;
}
END_OF_FUNCTION(increment_speed_counter);
void play_the_game()
{
LOCK_VARIABLE(speed_counter);
LOCK_FUNCTION(increment_speed_counter);
install_int_ex(increment_speed_counter, BPS_TO_TIMER(60));
while (!game_over) {
while (speed_counter > 0) {
update_game_logic();
speed_counter--;
}
update_display();
}
}
- Raw text -