4
\$\begingroup\$

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.

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

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.)

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .