Re: [Dev-C++] Franerate limiter! Damn!
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <ste...@ge...> - 2001-06-21 19:43:11
|
Here's how I made my framerate limiter: (further explanation below)
#include <time.h> /* Contains the clock_t type definition, for the =
framerate-measure */
#include <conio.h> /* Contains the kbhit() function, which we'l use for =
the mainloop */
void Game(void)
{
int F; /* Frame counter */
const int FRAMERATE =3D 160; /* We need a framerate @ 160fps or =
less */
clock_t Fstart, Fend; /* Time variables */
F =3D 0;
Fstart =3D clock();
Fend =3D clock();
/* This is the main game loop */
while( !kbhit() )
{
/* Increase our framecounter with 1, each frame/gameloop */
F++;
/* Here we keep looping, until we have decreased
the framerate to FRAMERATE fps */
while( int( F / ( (1+Fend-Fstart) / CLK_TCK ) ) > int(FRAMERATE) =
)
{
Fend =3D clock();
}
}
}
Further explanation:
A framerate is the count, of frames that is displayed each seccond. So, =
if we want a framerate of 160 frames per second (160frames / 1second), =
we can calculate the time that is supposed to pass between each frame =
like this;
TimeBetweenEachFrame =3D 1second / 160frames =3D 0.00625seconds
Okay... The "( (1+Fend-Fstart) / CLK_TCK )" is the time that has passed =
since Fstart =3D clock(); ( The "/ CLK_TCK" is to convert the =
timemeasure into seconds). The "F++;" is to keep counting the frames =
each time we make one.
So the loop goes;
while ( FramesSoFar / TimeSoFar > FrameRateWeLike )
{
TimeSoFar +=3D TimeSinceLastLoop;
}
Bye:
So, I hope this is any good for you Ian. I'm glad to help :)
If there's anything else, just let me know.
- Stein Nyg=E5rd :)
----- Original Message -----
From: "Ian Weston" <lak...@ho...>
To: <dev...@li...>
Sent: Wednesday, June 20, 2001 8:55 PM
Subject: Re: [Dev-C++] Franerate limiter! Damn!
> hi there stein, i was just wondering if it would be possible for you =
to
send
> me the code that worked if thats ok. i would really apreciate it if =
you
> could.
>
> thanks ian.
>
>
> >From: Stein Nyg=E5rd <ste...@ge...>
> >Reply-To: dev...@li...
> >To: <dev...@li...>
> >Subject: [Dev-C++] Franerate limiter! Damn!
> >Date: Wed, 20 Jun 2001 11:42:25 +0200
> >
> >Just ignonore my last mail, I jsut got it working :)
> >
> >Tanks!
>
> =
_________________________________________________________________________=
> Get Your Private, Free E-mail from MSN Hotmail at =
http://www.hotmail.com.
>
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|