Note that there are some explanatory texts on larger screens.

plurals
  1. POI can't figure out why this fps counter is inaccurate
    primarykey
    data
    text
    <p>I'm trying to track frames per second in my game. I don't want the fps to show as an average. I want to see how the frame rate is affected when I push keys and add models etc. So I am using a variable to store the current time and previous time, and when they differ by 1 second, then I update the fps.</p> <p>My problem is that it is showing around 33fps but when I move the mouse around really fast, the fps jumps up to 49fps. Other times, if I change a simple line of code elsewhere not related to the frame counter, or close the project and open it later, the fps will be around 60. Vsync is on so I can't tell if the mouse is still effecting the fps.</p> <p>Here is my code which is in an update function that happens every frame:</p> <pre><code>FrameCount++; currentTime = timeGetTime (); static unsigned long prevTime = currentTime; TimeDelta = (currentTime - prevTime) / 1000; if (TimeDelta &gt; 1.0f) { fps = FrameCount / TimeDelta; prevTime = currentTime; FrameCount = 0; TimeDelta = 0; } </code></pre> <p>Here are the variable declarations:</p> <pre><code>int FrameCount; double fps, currentTime, prevTime, TimeDelta, TimeElapsed; </code></pre> <p>Please let me know what is wrong here and how to fix it, or if you have a better way to count fps. Thanks!!!!!!</p> <p>I am using DirectX 9 btw but I doubt that is relevant, and I am using PeekMessage. Should I be using an if else statement instead? Here is my message processing loop:</p> <pre><code>MSG msg; ZeroMemory (&amp;msg, sizeof (MSG)); while (msg.message != WM_QUIT) { if (PeekMessage(&amp;msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage (&amp;msg); DispatchMessage (&amp;msg); } Update (); RenderFrame (); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload