Advertisement

Controlling the frame rate

Started by August 25, 2000 08:28 AM
3 comments, last by Ut 24 years, 4 months ago
Can someone tell me some techniques for keeping a consistent frame rate. Currently I''m just waiting for the vertical blank, but I thought I read about some other technique that kept animation and framerate consistent across a variety of computer speeds. I can''t remember it too well, what it was called or what it did (go figure). Ut
LOL, I just answered this question!! But I'll do it again. To control framerate, use a WIN32 function GetTickCount(), which quiries the system clock. This is all you have to do:

    // enter main game loopwhile(TRUE){  // get a starting point  DWORD start_time = GetTickCount();  //////////////////////////////////  // do main game processing here //  //////////////////////////////////  // now wait for 33ms (approx. 30fps)  while((GetTickCount() - start_time) < 33);} // end game loop    


Simple! Now your entire game loop will be locked at 30fps, you can play around with the millisecond counter, of course, to get what you like. Peace.


******************************
"I do not fear computers, I fear the lack of them"

- Isaac Asimov

Drew Sikora
Napali Networks, Inc.

Edited by - WebSpyder on August 25, 2000 9:48:07 AM
******************************"I do not fear computers, I fear the lack of them" - Isaac AsimovDrew SikoraNapali Networks, Inc.
Advertisement
btw, just include windows.h (you should anyway....)

******************************
"I do not fear computers, I fear the lack of them"

- Isaac Asimov

Drew Sikora
Napali Networks, Inc.
******************************"I do not fear computers, I fear the lack of them" - Isaac AsimovDrew SikoraNapali Networks, Inc.
Yeah, I''m pretty much doing that with the Wait_For_Vertical_Blank which gives me a 60fps refresh. I guess the method I''m thinking of keeps all animations in check. I think it''s based off the clock, and says something like if one clock tick has passed, move the object the default amount, but if two clock ticks have passed move it twice as far. That way the game moves at the same speed on a 486 as a pentium III. I think this is the general idea, but was hoping someone would explain it better to me. I remember a post about it here about a month or two ago, but can''t remember the details of it. I might be able to put it together from what I remember.

Ut
Locking to vertical blank only works if you''re running your video card at 60hz. My home system is currently running at 85hz refresh rate, and the video card is capable of running as high as 115hz, which is almost twice the speed of 60hz (unfortunately my monitor maxes out at 85hz at 1280x1024). Games locked to vertical blank will run almost 50% faster on my system then on a system running at 60hz.

This topic is closed to new replies.

Advertisement