Jump to content
  • Advertisement
Sign in to follow this  
webjeff

a set FPS

This topic is 5176 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys: I have this code:
currTime = GetTickCount();
	if (currTime >= lastTime + MIN_FRAME_TIME)
	{
		numFrames++;
		if (numFrames > 11)
		{
			float currentUpdate = currTime;
			fps = numFrames / ((currentUpdate - lastUpdate)/1000);
			lastUpdate = currentUpdate;
			numFrames = 0;	
		}
		lastTime = currTime;
	}

I'm trying to get the frames per seconds maintained at 12. my MIN_FRAME_TIME is (1000/12). However, when I calculate the FPS, its averaging around 8fps, 7.994 or something. Any ideas? Thanks!! Jeff King

Share this post


Link to post
Share on other sites
Advertisement
frame/sec*sec=frame
I'm not so sure but you should have multipied not divide

currentTime=GetTickCount()*0.001f;//value in sec

if(currentTime-lastTime>1/NUMBER_OF_FRAMES_PER_SEC)
{

lastTime=currentTime;
...do smth.....

}

EDIT: This should work fine

Share this post


Link to post
Share on other sites
ok, with this:


currTime=GetTickCount()*0.001f;//value in sec
if(currTime-lastTime>1/12)
{
numFrames++;
if (numFrames > 11)
{
float currentUpdate = currTime;
fps = numFrames / ((currentUpdate - lastUpdate));
lastUpdate = currentUpdate;
numFrames = 0;
}
lastTime=currTime;
}



I'm getting 16 frames per second... any clues??

Share this post


Link to post
Share on other sites
What is the resolution of GetTickCount? If it only gives the time every 5 ms or so, after 10 ms (2 ticks), it would be to early so it would wait until the next tick, which would be too late.

Just out of curiosity, why do you want to limit the framerate to 12?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!