• Advertisement

Archived

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

Is this about right for frame limiting?

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

This is based on the DirectX AppWizard template "teapot". Unmodified, it runs at 2,000 fps on my PC. Wow. Using this method from "Tricks of the Windows Game Programming Gurus", I''ve got it down to 21 fps (should have been 30 fps, but...) DWORD start_time = GetTickCount(); //Begin Game Loop { ... // Render scene ... while ((GetTickCount() - start_time) < 33); } // End Game Loop A few questions: Am I headed in the right direction for a good/reasonable frame limiter? I''ve noticed that this method uses 99% CPU time, which I guess is normal? I''m thinking that eventually I would be putting my non-rendering code inside the WHILE statment? And lastly, has anyone monitored their system temperature while running a graphic app at 2,000 fps? Things get a little hot. Thanks. I''m a beginner in case anyone hadn''t noticed. -me-

Share this post


Link to post
Share on other sites
Advertisement
don''t use GetTickCount(), it''s not accurate enough for games. Use QueryPerformanceCounter() instead.

I think it''s best to use vertical retrace to limit FPS.


My compiler generates one error message: "does not compile."

Share this post


Link to post
Share on other sites
quote:
Original post by icabob_crane
I've noticed that this method uses 99% CPU time, which I guess is normal?


not really, considering that those wasted cpu cycles could've been used for playing background music in winamp, downloading stuff from internet, or running seti@home.

if you want to limit framerate, at least use sleep() instead of that while loop.

time_to_sleep = start_time+frame_time-getcurrenttime();
if (time_to_sleep > 0) Sleep(time_to_sleep);

timeGetTime may be a good compromise between queryperformancecounter and gettickcount, but make sure to call timeBeginPeriod and timeEndPeriod to get 1 ms resolution on nt-based oses.

and you should really implement time-based motion. who would want to have your game run at 30 fps when it can be running at 2000 fps? people with the newest hardware bought it for a reason.

[edited by - niyaw on December 1, 2002 12:46:54 AM]

Share this post


Link to post
Share on other sites
Thanks for the responses.

If GetTickCount is not the way to go, I think it shouldn''t be in a book titled "...Game Programming Gurus". Maybe a different method is mentioned later in the book--I''m not too far along in reading it.

I''ll try out QueryPerformanceCounter and maybe Sleep() in the ways described.

Share this post


Link to post
Share on other sites
QueryPerformanceCounter is sometimes (usually) overkill...
i use timeGetTime myself...
btw, lamothe will teach you alot of bad habits in that book..
locking the frame rate is but one of them
(not a big lamothe fan myself.. others kiss the ground he walks on)

-eldee
;another space monkey;
[ Forced Evolution Studios ]


::evolve::

Do NOT let Dr. Mario touch your genitals. He is not a real doctor!

Share this post


Link to post
Share on other sites
Oh I see. Well, I purchased LaMothe''s book partially based on the book recommendations on this site. Hmmm...

It''s not locking the frame rate I''m after, it''s getting a consistent frame rate on various kinds of systems. Plus, as someone brought up earlier, consistent rates of object movement as well.

Share this post


Link to post
Share on other sites
use time based movement. That way, things will work well on faster systems without throwing away cycles.

In the real world, things move in mph, m/s, etc. Recreate *that* in your engine.

(rant: is the book where everyone is getting the idea to use frame based movement? Do many real games limit the framerate?)

Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces"

Share this post


Link to post
Share on other sites
quote:
Original post by CrazedGenius
Do many real games limit the framerate?


Sure they do. Most 2D games, for example. There''s little point running as fast as you can when the player isn''t gonna see much improvement in gameplay, your animations are fixed to a given number of frames per second, and things like collision detection code is made a lot more complex as a result. It''s a game, not a benchmark.

In answer to the original poster, perhaps you should write a little Wait() function that will perform a combination of a Sleep() and a busy-wait loop. I think Sleep has 10ms granularity, so you use that function to wait up to the nearest multiple of 10ms, and busy-wait the rest to keep it accurate.


[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Kylotan

In answer to the original poster, perhaps you should write a little Wait() function that will perform a combination of a Sleep() and a busy-wait loop. I think Sleep has 10ms granularity, so you use that function to wait up to the nearest multiple of 10ms, and busy-wait the rest to keep it accurate.



10ms is minimum granularity, It could be gone for much longer than the time specified, if anything else decides to load up the CPU.

Share this post


Link to post
Share on other sites

  • Advertisement