Another-Game-Engine/AGE — pull request #249 by cesarl (2014-09-10 23:06:13+00:00)
Title: Threaded architecture

Engine is now threaded :

- Main thread for gameplay
- Prepare render thread to prepare render task (cull, sort, ...)
- Render thread (all opengl call have to be done in his context)

Communication between thread is easy but touchy, if you make mistake, you can dead lock easily :laughing:

To communication with render thread from another thread push safe message into :
`

AGE::Threads::Render *renderThread = getInstance();

// command will be executed at synchronization point.
renderThread->getCommandQueue().safeEmplace(args);

// command will be executed at synchronization point. Use .get on the future to get the result. Be careful you have to be sure that synchronization have been called before calling .get() (this is usefull when we want to get the result on the next frame
auto futur = renderThread->getCommandQueue().safeFutureEmplace(args);

// Will be execute ASAP, don't need to call synchronization function
renderThread->getCommandQueue().safePriorityEmplace(args);

// Will be execute ASAP, don't need to call synchronization function. You can call .get() directly after if you want
auto futurPriority = renderThread->getCommandQueue().safePriorityFutureEmplace(args);
`

Commands for the prepare thread `AGE::Threads::Prepare` are only called from the main thread for the moment. So you can use unsafe functions : `emplace, futureEmplace, priorityEmplace, priorityFutureEmplace`.

### Very important

Thread queue use an external library "TMQ". It's not yet in the vendors file because I'm still working actively on it. You can download it here : https://github.com/cesarl/ThreadsMessagePassing and copy /src content in /vendors/tmq . If in the future you see that there is problem with TMQ it's maybe because it have been updated.

Please try the PR before validate it and tell me if you have performance gain / lost (with and without physics) in comparison to master version.