Jump to content
  • Advertisement
Sign in to follow this  
X Abstract X

SDL_Delay Question

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

Sup, I'm working on a game using SDL and OpenGL. I have my timing all sorted out to run the game logic at a fixed rate and render as fast as possible. With VSycnc enabled my FPS would cap to 60. That worked great but then I disabled VSync for testing purposes. The FPS would reach really high numbers obviously, but then when I would try to exit the window it would be too hung up to close. So, I tried adding SDL_Delay(x) at the end of my main loop and through trial and error I found out I needed to delay for atleast 2 ms to be able to have control over closing the application. My question is, what should I do? I'm not sure using SDL_Delay is a good idea. Should I cap the rendering speed myself? Even capping the rendering speed could lead to problems if a slower computer is struggling to render at the capped rate I'm guessing.

Share this post


Link to post
Share on other sites
Advertisement
Do you want a fix rate of 60fps even with VSync off ?

In this case just measure the time for your last frame and wait for the rest of the frame until atleast 1/60 s has been passed.

Pseudo code

while(...mainloop)
{
Time startTime = Clock::getTimeInMs();

.. handle events ..

.. run game logic, render scene ...

Time endTime = Clock::getTimeInMs();
Time frameDuration = endTime - startTime;

// compare to 60fps = 1/60 s = 1000/60 ms
if( frameDuration< (1000/60))
{
// wait for the rest of 1/60s
SDL_delay( (1000/60) - frameDuration);
}
}



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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!