Open ohlidalp opened 8 years ago
Triggers (IIRC main thread, should be sim)
Triggers are definitely updated on the sim thread: https://github.com/RigsOfRods/rigs-of-rods/blob/master/source/main/physics/BeamForcesEuler.cpp#L1217
Hooks - locking (IIRC main thread, should be sim)
Hooks as well: https://github.com/RigsOfRods/rigs-of-rods/blob/master/source/main/physics/BeamForcesEuler.cpp#L1135
This turned out to be impossible because existing implementation works closely together with brakes/gearbox/etc on main thread, without syncing.
The engine updates in the main thread happen while the sim thread is paused.
The sim thread is paused here: https://github.com/RigsOfRods/rigs-of-rods/blob/master/source/main/gameplay/RoRFrameListener.cpp#L1478
And the engine updates happen here (inside of the input event handling): https://github.com/RigsOfRods/rigs-of-rods/blob/master/source/main/gameplay/RoRFrameListener.cpp#L1718
This is a tech proposal document.
At the moment, RoR's multithreading is flawed. Read description of milestone future-proper-mt for details and general design goals.
General design goals (recap)
Overview and TODO list
Direct ray-queries to OGRE terrainOptimized by porting height-lookup code from OGRE. TODO: fix support for multi-page terrains!To research
History and previous implementation attempts
Act1: At the beginning, I tried to replace vehicle engine code (the BeamEngine part, updated on sim-thread) with Lua script. This turned out to be impossible because existing implementation works closely together with brakes/gearbox/etc on main thread, without syncing.
Act2: I tried to create properly threaded powertrain: all simulation on BeamFactory-thread, all GUI updates and input buffering on main-thread. This project got pretty far, the code is here. However, as I progressed, I realized it doesn't make sense to refactor just the powertrain when there are many other elements (hooks, ties, triggers, etc...) suffering from exactly the same issue.
Act3: This project. I want to apply the knowledge from Act2 to entire simulation code.