DirectX 9: Best Method To Limit FPS?

Started by
12 comments, last by TomKQT 10 years, 5 months ago


I just want the game engine to run at a constant 60 Frames Per Second on any computer.

If all you care about is 60FPS, then call Present() with the D3DPRESENT_INTERVAL_ONE flag. This will enable vsync, limiting your FPS to the monitor refresh rate.

This probably isn't the most reliable method if he intends on getting 60fps across the board. The number of 120hz monitors are increasing rapidly, so those individuals will be getting locked at twice the speed of others with 60hz displays.

Advertisement

You should decouple FPS from game logic so that the game behave the same way regardless of FPS. For each frame you find the fElapsedTime and pass it down to all your logic. Every parameter you want to move/rotate/scale/advance you multiply with fElapsedTime.


void Logic(float fElapsedTime){
.
.
.
.
.
PlayerPosition += PlayerVelocity*fElapsedTime;
.
.
.
.
.
}

I wrote a lenghty post about doing this: http://www.gamedev.net/topic/647960-extreme-framerates/#entry5096093 .

I don't think it's very clear form that post what I did, but if you need help understanding what I did, please let me know.

You still have to use the winmm timeBeginPeriod API for it, though - otherwise, the frames will not be rendered exactly at the 60 FPS mark - they'll be renderd at somewhere around the 60 FPS marks (+/-15ms, because 15ms is the default system-timer resolution), but this wouldn't cause the average framerate to go down - it will still be 60FPS.

Another remark - if you limit the FPS to 60 without VSync and a the game is played on a 60 Hz monitor (most monitors are 60 Hz), tearing can become extremely visible and annoying. Why? Because the tearing line will move very slowly on the screen or will be almost stationary (if you manage to get EXACTLY 60 Hz). Theoretically that's like if you were using VSync, but the pictures are synced in a random time/location, not at the monitor refresh.

This topic is closed to new replies.

Advertisement