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.
Terry
Posts: 55 Joined: Wed Jan 27, 2010 6:16 am
Location: Peking/China
Post
by Terry » Thu Jun 10, 2010 10:52 am
hello folks,
Maybe it's a easy problem,i'd like to compute fps by my own.but it displays error.
Right code:
Code: Select all
fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Collision detection example - Irrlicht Engine [";
str += driver->getName();
str += "] FPS:";
str += (int)fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
but if i change first sentence to:
Code: Select all
now = device->getTimer()->getTime();
fps = (int)(1000.0f/(now-last));
"last"has been computed before,it could not display the fps infor,
what's wrong?
Thank you very much!
CuteAlien
Admin
Posts: 9716 Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:
Post
by CuteAlien » Thu Jun 10, 2010 11:23 am
Maybe now-last is zero? Then you would try dividing by that.
Terry
Posts: 55 Joined: Wed Jan 27, 2010 6:16 am
Location: Peking/China
Post
by Terry » Thu Jun 10, 2010 11:24 am
CuteAlien wrote: Maybe now-last is zero? Then you would try dividing by that.
No i've traced the code step by step,it's not zero.and fps is 19.
Valmond
Posts: 308 Joined: Thu Apr 12, 2007 3:26 pm
Post
by Valmond » Thu Jun 10, 2010 6:01 pm
If you want 'perfect' fps you need to save off the reminder of that division (so this frame when fps=19.5 and shows 19, the 0.5 should go to the next frames calculation).
Otherwise, what's the problem with the code (crashes, slightly wrong fps, not at all correct etc.)?
Terry
Posts: 55 Joined: Wed Jan 27, 2010 6:16 am
Location: Peking/China
Post
by Terry » Fri Jun 11, 2010 12:35 am
wow,i mean it displays like "…………FPS:@#!"
19 could not be displayed.
greenya
Posts: 1012 Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:
Post
by greenya » Fri Jun 11, 2010 12:55 am
I see "now" assignment, but "last" -- i don't.
So, after this:
Code: Select all
now = device->getTimer()->getTime();
fps = (int)(1000.0f/(now-last));
you have to do also
But to make sure never have devision by zero, i would wrote: last = now - 1;
Maybe that is a problem.
DtD
Posts: 264 Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:
Post
by DtD » Fri Jun 11, 2010 5:04 am
Since you said it is displaing random characters, my guess is it is because you are adding the FPS in like it is text, do this instead:
str += irr::core::stringw(fps);
Edit: However, the divide by zero is an important issue as well. I output the time since the last frame along with the FPS in my game and I notice it is very common it is 0 on my machine.