Jump to content
  • Advertisement
Sign in to follow this  
jujumbura

main game loop implementation?

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

Good evening folks, I have a question today about how to implement the main loop for a game. It seems pretty clear that this should be separated from the rendering loop. Ideally, the game loop would cycled at regular timed intervals, and not be affected by how frequently frames were getting rendered at all. I remember seeing a post a while ago about multi-threaded games. This makes sense to me, as you could have your game thread execute, sleep for a while, and repeat while your graphics loop just gets frames in whenever it can. Is this standard practice? Is there a different way to get a regularly timed call to execute game logic that won't wait for the rendering proccess to return? If multi-threaded IS the way to go, are there some good C++ tutorials out there? What is a good amount of time to sleep between executions? Any other sage advice? Thanks very much for any help, Mike

Share this post


Link to post
Share on other sites
Advertisement
My two cents: avoid multithreading as much as possible. Multi-threaded games are an order of magnitude harder to debug and two orders of magnitude harder to write properly without actually decreasing performance. The combination of the two means that you'll be spending a lot of time going "What the heck is wrong with it this time?"

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
My two cents: avoid multithreading as much as possible. Multi-threaded games are an order of magnitude harder to debug and two orders of magnitude harder to write properly without actually decreasing performance. The combination of the two means that you'll be spending a lot of time going "What the heck is wrong with it this time?"



Couldn't have said it better myself. Multithreading might sound good, but the difficulties of its implementation make it a horrid mess. How ironic, since next-gen game processor designers are looking to exploit parallelism in games (ie, IBM and the Cell architecture). I was at ISPASS this year and Kunle Olukotun of Stanford gave a great little talk during the panel discussion about the future of multithreaded programming. He suggested that there should be "something better" than the current multithreaded programming model. In fact, here's a link to his presentation (only 6 slides, you can handle it): Presentation Slides.


Now if <bhe doesn't convince you that multi-threading is the work of the digital devil, then you're hopeless. [wink]

Share this post


Link to post
Share on other sites
Quote:
Original post by Roots
Now if <bhe doesn't convince you that multi-threading is the work of the digital devil, then you're hopeless. [wink]
It’s not "the work of the digital devil" Its just not appropriate for every type of application. Can you imagine A GUI OS with out multithreading?

Share this post


Link to post
Share on other sites
Hmm. So if multithreading is more hassle than it's worth, what do you use for a regularly-timed loop? I mean you need some sort of deal:


while game playing
{

gather input;
make state changes;

}


Then how does the rendering loop figure in to that? How do you prevent the rendering proccess from slowing down the input and game logic?

Mike

Share this post


Link to post
Share on other sites
This quite recent thread addresses that question, albeit from a slightly different standpoint:
Game Timing

I only mention this because I made a fairly significant contribution, of course ;)

-Twilight Dragon

Share this post


Link to post
Share on other sites
its not so much the language that matters as keeping all the data straight when dealing with multiple execution paths, trying to debug things when different threads can change the data can be a right nitemare, making it work properly for a game loop just compounds the problem [smile]

Not saying its impossible, just not something most people want to try, certainly not until you've played with simple MTing and maybe not if you have to ask how a game loop should be structured, a bit of experiance with a simple single thread system will stand you in good stead.

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!