afritz1 / OpenTESArena

Open-source re-implementation of The Elder Scrolls: Arena.
MIT License
915 stars 68 forks source link

Job system #245

Open afritz1 opened 1 year ago

afritz1 commented 1 year ago

The engine is lacking a good way of utilizing several threads. After the software rendering is optimized for single-threaded execution in part 3, it will switch to this job system so pixel shading, etc. can run 5-20x faster.

Off the top of my head, the job system needs a private thread pool and some kind of addJob(), isRunning(), and wait() functions. Maybe it could have a queue of std::function<void()> and worker threads would check if the queue is not empty. Later, wait() could take a category tag so it only waits for certain jobs to finish. Basically the job system exists so we don't have to use condition variables directly.

I am a bit shy of threading due to how easily bugs can show up, but the gains in the renderer and elsewhere would be massive.