Archived

This topic is now archived and is closed to further replies.

kVandaele

Frames Per Second - odd

Recommended Posts

kVandaele    138
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?

Share this post


Link to post
Share on other sites
Bad Maniac    252
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!

Share this post


Link to post
Share on other sites
kVandaele    138
... 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?)

Share this post


Link to post
Share on other sites
kVandaele    138
!$%&*@# ... 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?

Share this post


Link to post
Share on other sites
kVandaele    138
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)

Share this post


Link to post
Share on other sites
Agony    3452
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]

Share this post


Link to post
Share on other sites
kVandaele    138
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)?

Share this post


Link to post
Share on other sites