Page 1 of 1

FPS limit

Posted: Wed Oct 03, 2007 7:14 pm
by konrad
Hi, i have problem. What i can make fps limit??
Please help me :)
PS. Sorry for my english ;p

Re: FPS limit

Posted: Wed Oct 03, 2007 7:37 pm
by kburkhart84
konrad wrote:Hi, i have problem. What i can make fps limit??
Please help me :)
PS. Sorry for my english ;p
Why do you want to limit the FPS?? If the reason is to control movement speed, then you probably want to switch your movement to be based on time passed instead of frames.

Posted: Wed Oct 03, 2007 8:25 pm
by hybrid
But for all possible reasons there are several threads available from the search button :idea:

Posted: Wed Oct 03, 2007 11:55 pm
by eMgz
i dont know how, but just for curiosity, its good to limit FPS so you dont waste time rendering useless frames (your monitor just show about 80 of them) and it prevents the graphics card from overheating.

Posted: Thu Oct 04, 2007 6:05 am
by hybrid
But that's a simply VSync. You can enable it with some parameter upon device creation. Check the Demo for making it configurable. Most people that ask for FPS limiting do this for synchronizing their animations and controls, though, just as kburkhart84 mentioned. And this is quite problematic, due to time glitches and the overall accuracy of timing. Even worse, some people tend to activate vsync and assume a fixed frame rate of 60 fps (which is damn wrong, first the FPS are varying depending on the screen settings and second it's not really exact, can be anything between 58 and 62 fps, or worse due to some high-priority process in the background).
Also note that activating VSync does not make your game run at 60 FPS, if the frame rate drops below screen refresh you will only get 30 FPS or even 15FPS, it's simply bound to integral multiples of the refresh cycle.

Posted: Thu Oct 04, 2007 6:07 am
by FriendlyWarlord
This may not be the best way, but I use a timer from Irrlicht. I set up a complex system where you can change the frames rendered per second and the number of times the game is updated per second (as the game is running). It was actually quite fun to make! From my testing I found that if you try to render as fast as the game updates, but it can't render fast enough, it tends to look choppy and bad - capping the framerate at a lower (but steadier) value looks MUCH smoother. But whatever you do, make sure you don't render frames faster than your game can update!

So, how did I do all this? Basically I used this:

Code: Select all

ITimer* timer = device->getTimer();
timer->setTime(0);

while (device->run())
{
	// Use timer->getTime() to get the time passed in milliseconds.
	// When needed, use timer->setTime() to change it.
	// As far as I know, the value returned from timer->getTime is only updated inside device->run().

	if (time to update the game)
	{
		//do stuff
	}
	else if (time to render a frame)
	{
		//render a frame
	}
}
My solution is a lot more complex than that (and gives better results), but that should be able to get you started (or finished). I may release my code later once it's cleaned up, but I really recommend building what you need yourself (both to learn, and to get what you want for your application). Hope this helps, sorry about the extra long post!

Oh, one more thing: device->getTimer() will always return a pointer to the SAME timer!

Posted: Thu Oct 04, 2007 1:14 pm
by kburkhart84
eMgz wrote:i dont know how, but just for curiosity, its good to limit FPS so you dont waste time rendering useless frames (your monitor just show about 80 of them) and it prevents the graphics card from overheating.
True, monitors have limitations on how fast they display. VSync has it's limitations that Hybrid mentioned as well. And Yes, it is good to give up the processor so the computer can do what it needs to as well. In windows, a simple Sleep() can do it though. Your game more likely than not would be with full attention from the user. Games aren't really used in multitasking situations constantly. Sure, they run along office apps that people leave open, but when the game is on, it's pretty much the only intensive thing going. Everything else has much lower priority and doesn't need much processor time. So a Sleep(1) lets Windows know to give a quick time slice to other processes, such as AntiSpywares and things like that, besides the Windows core processes. But you don't have to limit to 60FPS to do it.

Posted: Thu Oct 04, 2007 2:27 pm
by konrad
@FriendlyWarlord: I can't use this code ;p
EDIT: I have 100-200 FPS :(

Posted: Thu Oct 04, 2007 11:53 pm
by FriendlyWarlord
konrad wrote:@FriendlyWarlord: I can't use this code ;p
Of course not, it's mostly pseudo code! Maybe I shouldn't have put it in code tags then, sorry :oops: