Multi- Threading
In build 105 and previous, track sections where rendered as follows:
When a track sections comes into view:
- Measure the length of the track section and calculate the size of DirectX vertex buffer required.
- Create the vertex buffer
- Fill the vertex buffer by “extruding” the track symbol along the line of the track section
once the vertex buffer has been created, it is stored (until no longer required) and can be re-used as often as required for rendering.
Similar processes are required for tree blocks and terrain blocks.
The problem with this approach is that step 3 - filling the vertex buffer - can be quite long, particularly with highly detailed track models and so the simulation would pause breifly while the vertex buffer fill operation took place.
This pause would be even more significant when entering an area with a lot of track - ie a major station or goods yard. In this case the pause(s) while track buffers where generated could be quite significant.
So, in #106, we now use a multiple thread approach to generate the track buffers:
In the main thread, When a track section comes into view:
- add the track section to the queue of track sections that need to be generated
This means that the main thread (which does the main rendering) doesn’t need to pause while the track is setup, but can carry on rendering frames as usual.
The job of creating and filling the track vertex buffer is handed to the secondary thread running in the background:
- Take the track section out of the queue
- Measure the length of the track section and calculate the size of DirectX vertex buffer required.
- Create the vertex buffer
- Fill the vertex buffer by “extruding” the track symbol along the line of the track section
- Mark the section as ready to render
and similarly for tree and terrain blocks.
V106
import