Mail Archives: djgpp/1998/01/28/00:48:23
Hey! Thanks for answering! If you don't mind, I have two more
questions:
1.) I want to prevent the behavior that makes a program run too
fast on a fast computer (but I still want the program to run
slow on a slow computer).
I figure I can do that by timing the event loops so they
run a set number of times a second. My first question is:
What is the suggested minimum number of frames to blit to
the screen per second? (I use the allegro library.)
Is ten times per second too slow?
---------
2.) As for my second question, George Foot explained how to
create a fixed timer using the allegro library:
George Foot (mert0407 AT sable DOT ox DOT ac DOT uk) wrote:
: The simplest way to use Allegro's routines to do this is like so:
: volatile int global_ticks = 0;
: void my_timer_function () {
: global_ticks++;
: }
: END_OF_FUNCTION (my_timer_function);
: Then at initialisation:
: LOCK_VARIABLE (global_ticks);
: LOCK_FUNCTION (my_timer_function);
: install_timer();
: install_int_ex (my_timer_function, BPS_TO_TIMER (1000));
The above code increments global_ticks once every millisecond
(1000 times a second). My second question is: if I wanted to
display, say, a maximum of 10 frames to my screen every second,
would implementing the following code be suggested?
BITMAP *buffer;
while(1) /* Event loop */
{
/* code executed every event loop */
.
.
.
while (global_ticks < 100){} /* if one tenth of a second
hasn't elapsed yet, do
nothing until one tenth of
a second has elapsed. */
global_ticks = 0; /* reset the global_ticks for next time
through the event loop */
/* blit the buffer to the screen like so: */
blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
}
Basically, this code calculates everything up to the buffer.
If the computer happens to be too fast (resulting in global_ticks
less than 100), the program waits out the tenth of a second
allocated to that loop of the event loop, then moves on.
Is this an efficient way to prevent the speed-up of my game on
faster computers, or is there a better way?
Thanks in advance.
Jean-Luc Romano
- Raw text -