Hi,
How can i lock the irrlicht frame rate to a chosen value ?
Frame Rate Lock
Search for it, this question was posted many times. And it's not really a great idea to lock the framerate as some computers may run slower than the framerate you try to lock it.
But if you really need to lock it than in the update loop you should get delta time of the frame using irrlicht timer and yield it until the time you want another frame to begin.
But if you really need to lock it than in the update loop you should get delta time of the frame using irrlicht timer and yield it until the time you want another frame to begin.
Working on game: Marrbles (Currently stopped).
I suggest you use framerate-independent movement.
http://www.gamedev.net/reference/articl ... le1382.asp
http://www.gamedev.net/reference/articl ... le1382.asp
-
- Posts: 34
- Joined: Thu Feb 18, 2010 5:24 pm
I realize that using frame rate independent movement would be good.
But i am working on a networked game. So i want to make sure that all clients are running at same frame rates. Thats why i want to lock it.
I will try the yield function technique above. Any other suggestions would be welcome.
Thanx.
But i am working on a networked game. So i want to make sure that all clients are running at same frame rates. Thats why i want to lock it.
I will try the yield function technique above. Any other suggestions would be welcome.
Thanx.
-
- Posts: 26
- Joined: Fri Aug 20, 2010 11:07 am
- Location: Bulgaria
what I do is...
and in the main loop
it may take several seconds to adjust to the desired FPS, but it pretty much does what it's supposed to.
also, by changing '1.15' and '0.85' to numbers, closer to 1, will make it more accurate.
yet this is not something you should rely on.
for example, I use it to lower the CPU usage.
Code: Select all
unsigned int FPS=0;
wchar_t* FPSwc = (wchar_t*) calloc(10, sizeof(wchar_t));
unsigned short int time=0;
unsigned short int dividor=2;
Code: Select all
if (driver->getFPS()!=FPS){
FPS = driver->getFPS();
if((double)FPS/(double)desiredfps > 1.5 &&dividor>=4) dividor-=2;
else if((double)FPS/(double)desiredfps > 1.15 &&dividor>2) dividor--;
else if((double)FPS/(double)desiredfps < 0.5) dividor+=2;
else if((double)FPS/(double)desiredfps < 0.85) dividor++;
/* display the fps
_itow(FPS, FPSwc, 10);
fpsdisp->setText(FPSwc);
*/
}
time++;
if(!(time%dividor)){ // on every dividor-1 frames, one Sleep will be called
Sleep(10); //maintaining set FPS
time=0;}
also, by changing '1.15' and '0.85' to numbers, closer to 1, will make it more accurate.
yet this is not something you should rely on.
for example, I use it to lower the CPU usage.
-
- Posts: 34
- Joined: Thu Feb 18, 2010 5:24 pm
False... Sleep actually frees up the CPU cycles that would normally be used by the current thread to other threads on the system.julescoder wrote:I will experiment with your code as well. But as u said the sleep function can waste CPU cylces.
If I were to lock the frame rate, I'd check the clock at the beginning of the frame and the end of the frame. If the difference between the two was smaller than the time per frame I was aiming for, I'd call sleep with the time the frame took to render subtracted from the time per frame you want.