Constantly Changing FPS
I got a question about the FPS.
I am working on an engine rigt now and i just made an FPS counter using QueryPerformanceCounter() and QueryPerformanceFrequency() to do it..
and i slowed down the rate at which the FPS was written to the screen so i could actually seee waht i am getting, not just a blury numbers, and it was jumping from 100, 99, 121, 200, 100 and kinda at the same cycle each time. and i wasnt changing anything in the scene either.
what is going on.
i am using time based animation so it wont affect anything i just want to know why it is jumping in such huge gapes..
thanks alot
"What we do in life, echos in eternity" -- Gladiator
Most likely, either ths OS scheduled a disk write in that period, or your thread timeslice expired between the timing calls.
Try taking a 5 second average or something; that should make it much steadier
Try taking a 5 second average or something; that should make it much steadier
I narrowed down the problem to Sleep(1) which was in my main loop,
i took that out, and the FPS went way down, but if i did Sleep(2) then the FPS stays constant at a high rate.
what is going on, i would think if i didnt make a pause in the loop, it would go faster..
thanks alot
i took that out, and the FPS went way down, but if i did Sleep(2) then the FPS stays constant at a high rate.
what is going on, i would think if i didnt make a pause in the loop, it would go faster..
thanks alot
"What we do in life, echos in eternity" -- Gladiator
It depend how you measure your FPS - if you use 1/(frame render stop - frame render start), your sleep may not be measured. Also, it depends on the resolution of the timer - try printing the ticks out - eg. difference between 200fps and 100fps may be the difference between 1 tick and 2 - which in turn is random depending when you start timing.
Here is some code that measures FPS quite literally, ie frames rendered in last second (call once per refresh). Change the 1000 to 5000 to get longer averages etc.
[edited by - ChookMaster on February 17, 2003 10:07:20 PM]
[edited by - ChookMaster on February 17, 2003 10:07:59 PM]
Here is some code that measures FPS quite literally, ie frames rendered in last second (call once per refresh). Change the 1000 to 5000 to get longer averages etc.
class FPS { public: FPS() { }; void Render(GLFont *font) { char buf[100]; int ms = GetTickCount(); times.push_back(ms); while( *(times.begin()) < ms-1000 ) times.pop_front(); sprintf(buf,"FPS:%d",times.size()); glColor3ub(255,255,255); font->Print(10,30,buf); } private: std::deque<int> times; };
[edited by - ChookMaster on February 17, 2003 10:07:20 PM]
[edited by - ChookMaster on February 17, 2003 10:07:59 PM]
I obviously don't know how to post code - the std::deque should have "int" in angle brackets after it. Ok - sorry - I went back and edited it.
[edited by - ChookMaster on February 17, 2003 10:08:30 PM]
[edited by - ChookMaster on February 17, 2003 10:08:30 PM]
off my head, this should work..
| - Project-X - my mega project.. yup, still cracking along
- | - adDeath - an ad blocker I made - | - email me - |
static int tick=GetTickCount();static int frame=0;static int fps=0;frame++;if (tick+1000<GetTickCount()){ fps=frame; frame=0; tick=GetTickCount();}
| - Project-X - my mega project.. yup, still cracking along

um, right...
here is how to find the frames per second:
where
nothing hard realy.
frame
shuld be the realtime frames per second then.here is how to find the frames per second:
frame = ( 1.0f / fDelay );
where
fDelay
is the time in milliseconds that it take for your main loop to iterate one time (that means render/do one game frame).nothing hard realy.
Rate me up.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement