FPS limit

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
konrad
Posts: 15
Joined: Wed Oct 03, 2007 7:07 pm
Location: Poland

FPS limit

Post by konrad »

Hi, i have problem. What i can make fps limit??
Please help me :)
PS. Sorry for my english ;p
kburkhart84
Posts: 277
Joined: Thu Dec 15, 2005 6:11 pm

Re: FPS limit

Post 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.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

But for all possible reasons there are several threads available from the search button :idea:
eMgz
Posts: 10
Joined: Sat Sep 29, 2007 2:54 am
Contact:

Post 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.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post 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.
FriendlyWarlord
Posts: 58
Joined: Thu Apr 06, 2006 11:54 pm

Post 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!
=D
kburkhart84
Posts: 277
Joined: Thu Dec 15, 2005 6:11 pm

Post 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.
konrad
Posts: 15
Joined: Wed Oct 03, 2007 7:07 pm
Location: Poland

Post by konrad »

@FriendlyWarlord: I can't use this code ;p
EDIT: I have 100-200 FPS :(
FriendlyWarlord
Posts: 58
Joined: Thu Apr 06, 2006 11:54 pm

Post 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:
=D
Post Reply