Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

What is the best way to separate render and game logic threads?

I'd like to make logic-heavy game (ai, machine learning, and network) in which world updates 50-60 times per second.

I want to separate rendering so it will not waste logic's thread power.

I'm planning to use c++ with boost.

share|improve this question
add comment

1 Answer

Threading in games has pretty much the same issues you'll find in any other application. Think in terms of parallelization: you have some interrelated task that must be run concurrently without interfering with each other's work.

The drawing stage should not be affected by any other computation, so the gamestate must remain stable while drawing, i.e., these tasks must be synchronized. Drawing should not start until the whole gamestate step has finished. Gamesate-changing tasks must run sequentially with drawing code (update-draw-update-draw-...) while you can still concurrently run code that doesn't immediately change gamestate (e.g. pathfinding for the next frame.) You can also keep local copies of the whole gamestate (if it's not too big) or parts of it, computing them but only updating the gamestate upon synchronization with the drawing code (after the drawing for the current frame had ended.)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.