Archived

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

Reliable frame timer in D3D....

This topic is 5150 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

Hello, I was wondering if anyone could help me. I''m currently using the sample framework in a game I am writing. My game uses the m_fFPS variable from the framework application class to calculate a frame multiplier ie so that the code is frame independant. My problem is that when starting the application and also when windows appear, ie the file menu dialogue, the frame rate appears to get `stuck` for a second and thus giving an incorrect frame rate to the game and the game goes a bit pear shaped momentarily. Does anyone know of how to 1) stop this happening or 2) how to get a reliable frame timer in D3D? Much appreciated. Jez. PS My game is downloadable at www.jeremypardon.com if anyone fancies a look http://www.jeremypardon.com/parp/pages/downloads.html http://www.jeremypardon.com/parp/pages/gallery.html

Share this post


Link to post
Share on other sites
holy moe, that's beautiful. now i'm jellous

a couple of quirks though:
1. if you fall down on level 3 (i think it is), from the stairs, you can go back up by moving backwars (under the stairs). it will pop back up.
2. in fullscreen mode, the game goes in different speed all the time. sometimes slow, and sometimes fast [EDIT: and i have a P4 2.5 Ghz and GF4 4200]. noticed it on the first stair level. impossible to control.

really cool game, care to share the code for me to learn?

i don't know how to fix your problem though. i havn't worked with the app framework.


[edited by - apanjocko on November 8, 2003 5:09:04 PM]

Share this post


Link to post
Share on other sites
Well your problem sounds like it stems from the fact that you''re using the CD3DApplication::m_fFPS variable and using that to estimate the amount of time elapsed on each frame, if I understand you correctly. If you look in d3dapp.cpp, you''ll see that the scene stats are only updated once per second, so your FPS counter is only a very rough estimate. How about you use the CD3DApplication::m_fElapsedTime variable instead - that''s what it''s there for!

Share this post


Link to post
Share on other sites
I would also recommend that you cap the upper amount of time that can logically elapse between frames, to something like 100 milliseconds.

Thus, you''d do something like:


forever {
process messages
time = ReadTime();
if( time-lastTime > 100 ) {
lastTime = time-100;
}
step physics( time-lastTime );
lastTime = time
render
}
[/code[

Share this post


Link to post
Share on other sites
From what I can tell look at your demo, the FPS inaccuracies are due to the WinMain message loop. When you click on a menu or move the window, for example, the message loop goes into a spin, waiting for the event to finish. This halts the rest of your program, the code outside the loop. Once the message loop is released, your FPS code tries to account for the long delay, and produces the strange speed effects.

The only solution I know of is to separate the WinMain message loop from the rest of the code, by using a separate thread. This is what I do, and the game is never halted by menus or windows.

Share this post


Link to post
Share on other sites
Excellent, cheers for all your answers. Much appreciated. Hinch, I think you''ve got it there. Think I''m using the wrong framework variable to calculate my timer as you suggested.
I post new versions all the time so if anyone is interested in following it''s progress pay us a visit every now and again.
Cheers again all!
Jez

Share this post


Link to post
Share on other sites
Just me I''m afraid. I do have a friend that contributes code `theory`, ie not specific code although he does give me code that explains the theory then I go off and use it in one form or another. Generally I try to understand what he tells me then write it myself.

Thanks for your comments. Well pleased!!!

By the way. You were having probs with level 3, Lava Lout? I''d be interested in some more detail. I am aware that the frame rate goes haywire when fiddling with windows but during gameplay I''ve not experienced any probs...More info would be greatly appreciated.

Cheers
Jez.

Share this post


Link to post
Share on other sites
Hi!, just wanna say that it''s an awesome game!!, very fun and kindda adictive!, good work!!

just a problem on my PC (P4, WinXp, GeForce2), the camera somethimes seem to loose itself specially in the scene 4 (theam scene with ice) when one of the characters climb the huge mountain, also I reached the top using nippa, is that OK? or shouldn´t he be able to do that?

already waiting for the next update!

Share this post


Link to post
Share on other sites
Sweet cheers, I''ve recently updated all the movement code and a few bugs crept in damn! Ah well. At least you got the idea that you weren''t meant to get him up there which is good! I''ll post an update with a few fixes in soon. Cheers for the feedback, it''s really appreciated.

Share this post


Link to post
Share on other sites
Hi all again! I was wondering I may call upon your help once again. I have uploaded a version with the new timer in place but I get a slight, very slight, judder on the character when moving. I have put this down to the fact that the frame timer is constantly changing ever so slightly but was wondering I you may look at it for me and see how bad or insignificant it is on your machines. apanjocko, you had particular probs with level three, I wonder if you might pop back there with in new version and see what happens for you?

I''ve put up an exe.zip so people dont have to download the data all the time. Bear in mind though that both change frequently so if you get any error''s is likely the data is old. Get the exe only here:

http://www.jeremypardon.com/downloads/exe.zip

There''s a debug build with loads of shit messages and crap but may be useful for viewing the frame rate to see whats happening.

Cheers for you help

Share this post


Link to post
Share on other sites