a set FPS

Started by
3 comments, last by Sr_Guapo 19 years, 7 months ago
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
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
its in milliseconds, so don't I need to divide 1000 milliseconds/ fps? to get how many milliseconds per frame
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??
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?
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute

This topic is closed to new replies.

Advertisement