Mail Archives: djgpp/1998/08/03/16:07:21
C.Rothwell wrote:
>
> cam and or nenette remove trailing 666 wrote:
>
> > On Sat, 01 Aug 1998 23:29:06 +0100, "C.Rothwell"
> > <enquiries AT aditfree DOT com> added to the entropy with:
> > >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?
> >
> > yeah - run it on the slowest machine you want it to run on, and then
> > use that as the standard for how fast the program is allowed to run on
> > faster machines.
>
> Well, my problem is that It works fin on a 386 and up to a P150 then it
> starts to get faster (more so on cyrix machines) and I suspect that on a
> P400 it would be unplayable.
>
> Although I don't have access to anything more than a P200.
> I could put a screen update on an interupt but it might cause problems on
> the slower machines with slow graphics cards. I have been used to using the
> Amiga and this is the first time I have had to deal with such variance in
> speed of CPU's.Try finding the speed of the machine by finding how much it can count up
to in a certain time, then delay it with a loop by that a proportional
amount of for the faster machines.
Sample untested code, which you will have to change '#define
time_for_386 1000' to the amount delaytime gets up to on a 386:
#include <time.h>
#include <stdio.h>
#define time_for_386 1000
int speed();
void delay();
int delaytime;
int main(){
speed();
/* Game goes here..*/
delay();
/*With the call to delay in it*/
}
int speed(){
struct tm value;
int start,start2;
do{
start2=start;
start=time(NULL);
}while (start2==start);
do{
delaytime++;
printf ("%d %d\n",start,time(NULL));
}while (start==time(NULL));
}
void delay(){
int n;
for (n=0 ;n < delaytime - time_for_386;n++ ){
}
}
- Raw text -