wildrj wrote:What are your personal experiences with threading an engine? There are not a lot of articles talking about this considering many believe it to be “Advanced”.
Any extra articles or explanations of various things I’d gladly take.
P.S: Sorry if this post jumps around randomly its 7:50am and I’m in class typing this.
It's not really 'advanced'... When I was in college, we had a course that spent a large section talking about threading issues and we had assignments to create little programs...
Jump forward several years later and libraries like
Boostmake cross-platform threading simple. Things like Signals/Conditions, mutexes, etc...
I use threading for asset loading (and level loading), decoding video/audio and in the last game some custom post processing (render a scene to sepia and cut into jigsaw pieces).
Really, the asset loading was the most important, and decoding video in a separate thread was a must. If I were going to do physics, I would kick off (resume) the physics thread at the beginning of my global update and wait on it to finish at the end of the global update. Probably to keep my physics from getting ahead of my game.
pseudo code:
- Code: Select all
OnGlobalUpdate()
Modify physics engine // (add impulses from user input)
ResumePhysicsThread // (ODE->Update(0.01)) in a thread
/// ... /// Non physics dependent code
WaitOnPhysicsThread() // JOIN
That Parallel engine article has some interesting ideas but I think that for my purposes I would probably simplify it a lot until really, all I had was the thread pool manager (in lock step mode). Many physics engines have their own internal set of data objects. ODE, Box2D, Chipmunk... so the whole Observer pattern is probably overkill. (although I can think of some improvements to the observer they're using with {Read, Read/Write} attributes to an observer, CopyOnWrite, and invalidating local copies.
Anyways, I suggest looking into Boost
Thread,
Signals2/Slots, Accumulators (Perf testing?), and the
testingstuff. The testing might be overkill for a second iteration of an engine. Probably just need to check all inputs into a method and all outputs from a function.