Jump to content
  • Advertisement
Sign in to follow this  
xorjesus

fps problem

This topic is 5140 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I've been messing around trying to get an accurate fps counter. I've been using fixed time which works great, but the fps I'm getting just don't feel right. So I forced my computer to get 30 fps by using one of those while loops that supposedly locks your computer to about 30 frames a sec. Well the following code says I'm getting only about 22 frames a sec. Is this because of the cost of calling GetTickCount? Or is their some other problem I'm not noticing. I'm also getting the same frame count on several other computers.
float lastUpdate        = 0;
float fpsUpdateInterval = 0.5f;
int   numFrames         = 0;
float fps               = 0;
__int64	fps_ticks       = 0;


while (bGameRun == true)
{
    DWORD start_time = GetTickCount();
    // game code
    // ....
    
    sys.print("fps: %d", fps, 0xDh, 0xAh);
    Render();
    numFrames++;
    QueryPerformanceCounter((LARGE_INTEGER *) &fps_ticks);
    float currentUpdate =          (float)((__int64)fps_ticks/(__int64)ApplicationShell->frequency);
    if( currentUpdate - lastUpdate > fpsUpdateInterval )
    {
        fps = numFrames / (currentUpdate - lastUpdate);
        lastUpdate = currentUpdate;
        numFrames = 0;
    }
    while (GetTickCount() - start_time < 33);

}
[Edited by - xorjesus on October 24, 2004 10:33:20 PM]

Share this post


Link to post
Share on other sites
Advertisement
Maybe I misunderstand, but I think that code will only limit the framerate to no more than 30 fps. It won't raise the framerate to 30, but if the frame rate is over 30 it will lower it to 30. If the framerate is less than 30, (22 in your case) it will stay the same.

If you want to raise it to 30, you're going to have to optimize your render function.

Share this post


Link to post
Share on other sites
I didn't make it clear sorry. This program normally gets over 100 fps a sec, I can tell by the smooth animation. By adding the function it has limited it to 22, when it should limit it to 30. I was wondering what I was doing wrong.

Share this post


Link to post
Share on other sites
When you say, "I can tell by the smooth animation," what do you mean? Are you saying that you didn't actually test the previous frame rate? Is it possible that it wasn't as high as you thought?

Also, what's happening during the Render? Is it the same every time, or does it vary? If it's variable, it's possible that some calls to Render() are taking longer than others, and as a result, some frames may be taking more than 33ms to execute. That would throw off your FPS count. Your algorithm limits the frame rate to no more than 30, but it can certainly be less than 30fps.


Ryan

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by xorjesus
This program normally gets over 100 fps a sec, I can tell by the smooth animation.



Ha, Ha, Ha

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Quote:
Original post by xorjesus
This program normally gets over 100 fps a sec, I can tell by the smooth animation.



Ha, Ha, Ha


Ha ha ha, wait, I don't get it... Are you laughing at the fps/sec? It isn't very funny...

What does that while(...) do at the end of the code block? It is the middle of nowhere and it doesn't have any statements in it (or a set of brackets)...

Share this post


Link to post
Share on other sites
The point of the while loop is to lock the program to 30 fps a sec.
My frame rate counter without the restriction of the while loop says 100+, and it's obvious that it's pretty accurate as the animation is very nice.

The while loop locks the program to 30 fps by making sure the whole game loop takes at least 33 milliseconds. 1000/33 is about 30 frames a second. I'm just curious to why I might only be getting 22
fps a second with that while loop there, I should be getting 30 fps.

It's either the fact that GetTickCount is messed up, or my fps counter is messed up. I'm just wondering if anyone can see off that bat what is wrong with it.

//emphasize
The program normally is well over 30 fps, so that while loop shouldn't lower under 30 fps. At least I dont think so.

Share this post


Link to post
Share on other sites
That'll just wait until 33 ms have passed since the last update. Try and get rid of it to see what it does.
Also, to get a better general idea then "I've got over 100 fps, because it's smooth", try just counting the no. of frames, and time a minute or so, to see where the problem lies.
Come back with results!

Share this post


Link to post
Share on other sites
Quote:
Original post by tjoink
Come back with results!


as its only 6min later ill assume you were writing this before he posted. anyway, his point isnt to get rid of the loop (for now.. i really hope he will later on) but to know why its locking the fps to 22 instead of 30fps.

of course if one already suspects gettickcount im not quite sure why he doesnt just throw it away, especially if he's using the performance counter already. or just trying timegettime to see if its making any difference.

Share this post


Link to post
Share on other sites
a couple of things:

* try FRAPS to measure fps and compare against yours

* when I want to kill time I say something like:
endtime = GetTickCount() + 33;
// do stuff
while (GetTickCount() < endtime);
loop

* what OS? (I know that the old 98 & 95 clock resolution was about 18 ms, so double that and you are at about 27 frames per second...close to 22 <shrugs>)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!