Reliable frame timer in D3D....

Started by
9 comments, last by jpardon 20 years, 5 months ago
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
www.JeremyPardon.com
Advertisement
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]
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!
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[   
enum Bool { True, False, FileNotFound };
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.
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
www.JeremyPardon.com
how many are developing this sweet game? a team or you alone? just curious
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.

www.JeremyPardon.com
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!
My site Jvitel.com
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.

www.JeremyPardon.com

This topic is closed to new replies.

Advertisement