Original Post
I'm trying to design my game with multithreading in mind. It's going to be quite a simple system, consisting of only 2 main threads: "Simulation" and "Render". One of the key goals of the system is to completely detach the renderer and simulation. That is, the simulation runs at a speed independent of the renderer. I chose a fixed timestep of 10hz (100ms) for the simulation, and the renderer will just push out frames as fast as it can. Because of the low update rate of the simulation thread, the renderer needs to interpolate data between timesteps. Since the renderer could potentially be running at upwards of 30-60fps, there would need to be 3-6 interpolated frame for each timestep of 100ms. To achieve this, I'm thinking of a buffering system. The simulation thread does its calculations and writes to a buffer, while the renderer reads from two buffers containing the data from the past 2 timesteps and interpolates between them. This is what I'm envisioning:
There are a few problems with it. One is latency. Since my timestep is 100ms, the time between input and render is 200ms at a minimum. If the rendering or simulation takes longer than expected, the latency will be even higher. Since my game is a space sim, latency isn't a *huge* issue, but 200ms (or more) seems a bit much. The other problem is the potential for data starvation. If the simulation thread takes longer to process a timestep than expected, then the render thread will finish the interpolation through its two buffers and then have to sit waiting for the next timestep to complete. If this happened every timestep, it would result in extremely jerky motion. Can anyone give any suggestions to improve my design?
There are a few problems with it. One is latency. Since my timestep is 100ms, the time between input and render is 200ms at a minimum. If the rendering or simulation takes longer than expected, the latency will be even higher. Since my game is a space sim, latency isn't a *huge* issue, but 200ms (or more) seems a bit much. The other problem is the potential for data starvation. If the simulation thread takes longer to process a timestep than expected, then the render thread will finish the interpolation through its two buffers and then have to sit waiting for the next timestep to complete. If this happened every timestep, it would result in extremely jerky motion. Can anyone give any suggestions to improve my design?