Frames Per Second - odd

Started by
6 comments, last by kVandaele 20 years, 2 months ago
My program (which, for once, is working right) has a frame limiter built into it (leftover from Programming RPG''s with DirectX), which supposedly limits it to 30 frames per second in the following manner: BOOL cApp::Frame(){ static DWORD UpdateTimer = timeGetTime(); // Limit all frame updates to 30 fps if(timeGetTime() < UpdateTimer + 33) return TRUE; UpdateTimer = timeGetTime(); m_Frames++; // do work... } I find nothing strange about the code (wait until at least 33 milliseconds passed since last frame -> +/-30 fps), but when i added the FPS counter, it was leveling off around 20 fps. Even more strange is that when i change the minimum delay from 33 to 16 milliseconds (theoretically getting 60fps if your PC can handle it) it leveled off around 40 fps. Why is that? Also, when i removed the frame limiter completely it floated around 60fps, but i think that''s just because of vsync (... which is the monitor''s rate of updating, right?). By the way, to make sure my PC isn''t topping off at 60 fps (and out of curiousity as to how high it''ll go), how do i ''uncap'' the vsync (if that IS the problem) to allow it to go up to it''s max fps?
Advertisement
Turn off waiting for vsync. that timing code might make you mis the vertical retrace and then you''ll have to wait a whole other retrace before flipping again.

What you can do is add some code to check for a retrace manually, and if it''s not in a retrace then waut, but when the retrace comes, flip the surface, then check and wait more if necessary. That way you''ll never miss a retrace.
I''ve never tried this myself though, so it might be a load of hogwash...

The more I think, the more confused I get.
The best 2D game developer site out there!
JRA GameDev Website//Bad Maniac
... freaky! I just tried it right now (without changing ANYTHING) and i got 30 fps with 33ms wait, and 60fps with 16ms wait. Despite probably being my fault in some way, i still blame my computer! :D

But how do i turn of vsync though? I searched all my files for the string "vsync" but couldn''t find anything. I looked it up on the DX docs, but the only reference was to the swap effect, which in my engine is:
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;

Does that mean vsync''s off? (... and if it is, that''s bad, isn''t it?)
!$%&*@# ... I ran it like 8 times now and over and over again i get 21.3something fps... If i put in a delay of 31ms though, i get 31.something fps (a quickfix, i suppose, but in no way ideal).

Anyone have a clue?
Slightly off-topic... but why are you limiting the frame rate? Maybe you could keep track of the time elapsed since the last frame and use that instead (time deltas)... ??

Regards,
Sharky

---
< Sharky''s Coding Corner >
< Coder @ Strangelite >
---
true... but this is already setup right now, and while not ideal it''s satisfactory. I could (and probably will later on) switch to full time-based simulations but that''ll get a bit complicated.

Even still, i''m just curious now as to the solutions... (and the problem as well)
In the D3DPRESENT_PARAMETERS structure, the member PresentationInterval should be set to D3DPRESENT_INTERVAL_IMMEDIATE. The default, D3DPRESENT_INTERVAL_DEFAULT, is nearly identical to D3DPRESENT_INTERVAL_ONE, which automatically waits for the next vertical retrace everytime you call pD3DDevice->Present(...). Here are MSDN's docs for D3DPRESENT_PARAMETERS (check near bottom), and for D3DPRESENT_INTERVAL_XXX values.

[Edit - had a messed up link]

[edited by - Agony on January 23, 2004 9:19:32 AM]

[edited by - Agony on January 23, 2004 9:21:12 AM]
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
great, thanks a bunch!

Anyone have a clue as to why sometimes it''s limited to 21.x frames and sometimes it''s limited to 30.x frames (using the same delay, just different runtimes)?

This topic is closed to new replies.

Advertisement