From: "Alberto Chessa" Newsgroups: comp.os.msdos.djgpp Subject: Re: Same speed on every machine Date: 4 Aug 1998 07:43:18 GMT Organization: TIN Lines: 36 Message-ID: <01bdbf7b$f10ebf00$92c809c0@chessa> References: <35C396B2 DOT C31C29EA AT aditfree DOT com> NNTP-Posting-Host: a-mi19-63.tin.it To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk C.Rothwell wrote in article <35C396B2 DOT C31C29EA AT aditfree DOT com>... > Is there a fool proof way of getting somethng to run at the same speed > on any PC without it slowing down the older machines? > > You must use a time tick that do not depend on the CPU, that is the timer (look at Allegro\demo\demo.c), to enstablish a time base First install a timer handler at the required tick (install_int(handler, time_base /* ms */)), then use the handler to count the number of tick since the last refresh (the handler must be very fast). Then create a main loop that check your tick, perform related operation (elapsed time = ticks * time_base) and redraw the screen only if required. On fast machine: Your game will be idle waiting for ticks. Do not care of frame rate. Tipically the time base is higher than the maximum frame rate (that is the veritical synch frequency - on my machine at 800x600x256 => 61Hz => 61 frames/s) On slow machine: More than one tick will occur between two complete game loop. The player position will be updated at the right velocity (using elapsed time), while the display will miss some frame. Very slow machine: the machine is not able to handle all the interrupt generated by the timer at the required tick ? Use time_base*2 or time_base*N as required and calculate elapsed time as ticks*time_base*N. Of course, the game "interaction" quality will be very low. Note that the average elapsed time (or the idle time) give you an idea of the machine speed (CPU+Video Car). You could automatically change the graphic quality (by removing some features) to obtain good playable game even of slow machine.