Hi,
I have a game codebase from the late 90's that I updated to work with Direct3D9 and modern Windows operating systems.
What I did originally when updating the renderer was set D3D9's presentation parameters PresentationInterval to D3DPRESENT_INTERVAL_ONE, and this works great. I need to do this to limit the framerate as the game starts to act oddly at high framerate (bouncing items that should remain static, player movement becomes janky etc)
When I did this, I had 60hz refresh rates in mind, and this all worked fine. But of course, some users like to overwrite this value in their graphics card display adapters and/or we're now seeing 144hz refresh rates, so this isn't working so well anymore.
So what Ideally I'd like to do is cap the game updates to 60hz and let the game render as much as it needs. Should be ok?
I've seen the few "fix your timestamps" articles but unfortunately I didn't write this game, and tend not to go near the gameplay code, so modifying the underlying methods for how entities and whatnot update their velocities etc etc is beyond me.
Here's what I've been trying, to only update the game every 16ms and allow rendering as fast as possible - only clear the backbuffer and render a new frame every time the game updates, otherwise just redraw the previous frame:
uint32_t startTime = timeGetTime();
while (1)
{
CheckWindowsMessages();
bool doupdate = false;
if (currentTime - startTime >= 16)
{
D3D9_BeginFrame();
UpdateGame();
startTime = timeGetTime(); //currentTime;
doupdate = true;
}
if (doupdate)
{
D3D_EndFrame();
FrameCounterHandler();
/* FrameCounterHandler() is the games method for handling timer updates,
calculting how much time has passed since it was last called, and updating game
variables with this value. Lots of fixed point math stuff lurking in here...
*/
doupdate = false;
}
D3D9_FlipBuffers();
}
This doesn't actually work well in reality, as my 4 year old computer can run a frame of this game at about 3000fps when vsync is off. What happens is sorta like vsync tearing, but instead of a single shear in the middle, there are multiple shears all down the screen (evenly spaced apart)
I guess what I'm asking is there a better way to do what I want, without having to pass any sort of delta time changes to the underlying game code? I might have my logic wrong somewhere here..
I'm really clueless on this timer stuff... Thanks!