Mail Archives: djgpp/1998/02/06/00:31:08
From: | jromano AT teton DOT Mines DOT EDU (Jean-Luc Romano)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Keeping speed with slow CPUs
|
Date: | 6 Feb 1998 05:13:46 GMT
|
Organization: | Colorado School of Mines
|
Lines: | 47
|
Message-ID: | <6be66a$e7i$1@herald.Mines.EDU>
|
NNTP-Posting-Host: | teton.mines.edu
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Hi, again.
About a week ago I posted a message about the problem of having
fast computers run my game too fast. I wanted faster CPUs to
run my program at a normal speed while slower CPUs run my program
slower, since I do not want my game to not run at all. I proposed
the following code for regulating my event loop:
while (!quitflag) /* event loop */
{
/* Event loop stuff */
prepare_buffer();
regulate();
blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
}
And my regulate function is:
void regulate() /* uses the timer to make sure a min amount
of time is spent each event loop */
{
while (timer < 100_milliseconds) /* has .1 secs passed yet? */
{
/* Do nothing -- just wait out the timer */
}
timer = 0; /* once done waiting, reset the timer */
}
George Foot told me this was a working way to prevent faster
machines from running my game too fast, but slower computers
would run it too slow (and George, if you are reading this, you may
want to answer). He briefly mentioned that there was another way
to regulate the event loop, one that would not be slower for slower
computers.
Would anyone know how I would go about accomplishing this?
George, you have any suggestions?
Thanks.
Jean-Luc Romano
- Raw text -