From: George Foot Newsgroups: comp.os.msdos.djgpp Subject: Re: Frames per second question Date: 28 Jan 1998 09:05:51 GMT Organization: Oxford University, England Lines: 70 Message-ID: <6amsdf$aap$1@news.ox.ac.uk> References: <6ae2u5$ls2$1 AT herald DOT Mines DOT EDU> <6aeqlq$qjq$2 AT news DOT ox DOT ac DOT uk> <6am4g7$dtk$1 AT herald DOT Mines DOT EDU> NNTP-Posting-Host: sable.ox.ac.uk Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk On 28 Jan 1998 02:17:43 GMT in comp.os.msdos.djgpp Jean-Luc Romano wrote: : 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? It'll look a little jerky. Try it and see -- and see whether or not different computers can handle it for your game. [snip] : 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); : } That would work for what you want, yes. I'd avoid resetting a variable called `global_*' though -- the idea was that it would be a count of how many ticks the game had been running for. Such variables can be quite useful, if for example you need to schedule something to happen later on, or know when something happened exactly. How about using a second variable, last_frame_time, which you set to global_ticks just before blitting (and zero initially), and change the while loop condition to (global_ticks - last_frame_time < 100)? In general I prefer a game to run at the same speed even on slow computers that can't handle the frame rate, in which case you need to rearrange the while loop a bit and add 100 to last_frame_time instead of setting it to exactly global_ticks; but you said you wanted it to run slowly on slower computers. : Is this an efficient way to prevent the speed-up of my game on : faster computers, or is there a better way? I don't think `efficient' is really the right term to use for a delay loop ;). You might consider calling __dpmi_yield in the loop, which would let background tasks the OS is performing continue, but this is probably undesirable in a game. -- george DOT foot AT merton DOT oxford DOT ac DOT uk