FLAMEGPU / FLAMEGPU2-visualiser

Cross platform real-time OpenGL visualiser for FLAMEGPU2 models.
1 stars 2 forks source link

Step sim when paused #129

Open Robadob opened 1 year ago

Robadob commented 1 year ago

Pressing o (I'm not tied to this key, its just next to p on the keyboard), now steps the simulation if the simulation is paused and the sim has processed it's next step.

This works with a double mutex, whereby render_buffer_mutex_pre is locked by the visualiser, prior to locking render_buffer_mutex (the normal pause mutex). After the lock of render_buffer_mutex is achieved, the lock on render_buffer_mutex_pre is released.

This allows us to quickly release the normal pause mutex, and lock render_buffer_mutex_pre, prior to re-locking the normal pause mutex.

This (albeit a race) should guarantee the simulation if waiting to lock the pause mutex, only has time to update the buffers and complete one step.

This approach works because, typically the simulation has completed it's next step and is waiting to update render buffers, where the pause mutex blocks it.

The downside of this approach is that it has no impact if the simulation is running slower than the time between your attempts to step the simulation (as the renderer can lock and release render_buffer_mutex_pre without any competition from the sim. This could be detected, by checking whether render_buffer_mutex_pre is already locked, and a message shared with the user.

Closes #124

First commit is a basic one, that adds alt camera controls with the arrow keys, i keep trying to use them with orthographic view.