Jump to content
  • Advertisement
Sign in to follow this  
yzq89

Game Loop

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

Hi, I have a question on my game loop. I'm developing a game with SDL+OpenGL, and am currently rendering at a fixed interval, leaving spare time for AI processing. How would this interfere with the v-sync? If the monitor refresh rate is higher than what my frame interval allows, what would happen? I'm concerned because I'm getting tearing occasionally, even though v-sync is enabled. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
I've never used SDL, and I haven't done much OpenGL either. But, generally it is a bad idea to fix your framerate like that. At best, your application will appear choppy on monitors that have a refresh rate different than your framerate, because some frames will be seen longer than other frames, and some frames may never be seen at all. I don't know why you would see any tearing if you have v-sync enabled. But, it might be better if you change your code to rely on v-sync to control your framerate and see if that doesn't fix your problem. In the end, that is a better solution anyway.

Share this post


Link to post
Share on other sites
Thanks for the quick response:D. In that case, how would I go about doing AI processing?
Since I'm expecting to spread out the processing over multiple frames, I would like to know how much time my idle processing function has left before the next frame.

Share this post


Link to post
Share on other sites
Well you could allocate a fixed interval say 10ms for a single frame, then you'd time how long it takes to do the rendering and anything else you want to do in a frame and use the remaining time to do your AI processing. Though this is effectively fixing your frame rate.

Using threads would be a better solution, you'd have one thread doing the AI and another doing everything else. SDL has thread support that you can use.

Share this post


Link to post
Share on other sites
Thanks for the suggestions. I'm going to go with a separate AI thread (Monder) and not fixing the framerate (nimrand).

Share this post


Link to post
Share on other sites
Quote:
Original post by yzq89
I'm concerned because I'm getting tearing occasionally, even though v-sync is enabled.


Use double buffering. If you allready are, it's probably a problem outside of your program - not all API+OS+Driver+Hardware combinations are set up to allow for tear-free animation. Unless waiting for the vertical retrace is done with via interrupt or by the card itself, if another thread is running during the vertical retrace period, you can end up missing the period and be forced to either never display the frame or tear.

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!