Jump to content
  • Advertisement
Sign in to follow this  
all_names_taken

Game speed and framerate questions

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

I'm making a framerate handling module of my game engine. I've heard timeGetTime() has unacceptable accuracy, so I'm wondering what to use instead (also which libraries I might need to include to get access to those functions). Also a few other questions: 1. if variable framerate is used, and the time the next frame will take is predicted to take as long as the last frame took, then with great fluctuations in framerate the game animations will behave strangely. A better result might be achieved by using a more fixed framerate, timed by busy-waiting loops, but where the fixed framerate setting changes but not as fast as every frame, or with smoothening functions. Does anyone know if using smoothening mechanisms for framerate is needed, or if predicting next frame time with last frame time works well? In any case, predicting the next frame with the last would even up all prediction errors over time, so if framerate is reasonably high and/or varying little, the effects might not be noticeable. What are your experiences with a framerate varying in this way? 2. some games offer a "synch every frame" option. This, I assume, means activating vsync mode. One problem I see with vsync on, is that if the time between vsyncs is x, and about half of the frames take less than x, and half are too slow to fit in x milliseconds, frame execution time will switch between x and 2x. This is a pretty large fluctuation, and would probably be very noticeable I think. For such cases, it is perhaps necessary to slow down all frames to fit within the 2x time, for a smoother appearance. But I don't know how to achieve this slow-down - does anyone have an idea on how to achieve it? Because there are plenty of difficulties to come around: a. vsync frequency varies between monitors (85 Hz might be 85.1 or 84.9), b. if your game without extra busy-waiting delays fit within a certain number of vsyncs, how can you know if it's within 1 vsync interval, 2 vsync intervals or 3? If it's within 1 vsync interval, the desired time is 2x, if it's within 2 vsync intervals, the desired time is 3x/2 etc, c. the only way to find out what to set the framerate too is by letting the game run and find out when it exceeds the previous number of vsync intervals. But how do I detect when that happens? If the frame takes "sufficiently much more time" than the previous, it can be assumed to be a case of that. But what is "sufficiently much more time"? Finally there's an issue with setting the actual delay buys-waiting loop time. I assume since we might have a framerate x of 1, 2 or 3 or more vsync intervals, setting the delay so we wait just above x+e, where e is a very small number, is a good way of making sure we don't increase the frame execution time to more than 1 vsync interval over the current when such a thing happens. But how do we set e? If we don't know the exact vsync time, and vsync time also varies slightly between frames for most monitors, then e might not be large enough and doesn't give us the longer frame execution time. Conversely, a too high e might slow down the game too much. 3. are there any other framerate and game speed smoothening systems I should know about? The purpose is simply to make animations smooth and the game to look acceptable when moving it between different platforms

Share this post


Link to post
Share on other sites
Advertisement
timeGetTime may have acceptable accuracy if you set the precision to 1 ms. Otherwise, you can use QueryPerformanceCounter (aka QPC).

Varying frame rates are generally handled one of these three ways:
  1. Update the state of the game at specific intervals, but render every frame.
  2. Compute the amount of time that passed since the last frame and use that to update the state of the world. Render every frame.
  3. Try to lock the frame rate to a specific rate using Sleep().
People generally use #2, though #1 is better if you are doing physics. #3 is difficult to do successfully.

Share this post


Link to post
Share on other sites
I have read in some game programming book that there is a timer that is a part of DirectX. It is extremely precise but I cant remember where Ive read about it. Only problem was that you can have only one at a time but you could simulate them. If I find more about it I will let you know.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!