From 900fe04515450dad6d052726f62f4056959d77a8 Mon Sep 17 00:00:00 2001 From: freezy Date: Tue, 1 Dec 2026 08:55:27 +0100 Subject: [PATCH] simulation: keep polling the real-time outputs while the table is paused A game without a time fence keeps running during a pause, and so do its lamps. Nobody polled its real-time feed until the resume, so it overflowed and DOF switched off for the rest of the game. The paused loop now polls every 10 ms without moving the time fence. --- .../VisualPinball.Unity/Plugins/RealtimeOutputPoll.cs | 8 ++++++-- .../VisualPinball.Unity/Plugins/UnityPluginContracts.cs | 4 +++- .../VisualPinball.Unity/Simulation/SimulationThread.cs | 3 +++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/VisualPinball.Unity/VisualPinball.Unity/Plugins/RealtimeOutputPoll.cs b/VisualPinball.Unity/VisualPinball.Unity/Plugins/RealtimeOutputPoll.cs index 730318129b..3a47ab6aeb 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Plugins/RealtimeOutputPoll.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/Plugins/RealtimeOutputPoll.cs @@ -14,7 +14,8 @@ namespace VisualPinball.Unity { /// /// Decides who calls an engine's : the simulation thread - /// on every tick while it runs, the player's frame update otherwise, and nobody while no listener is set. + /// on every tick while it runs and every 10 ms while it is paused, the player's frame update otherwise, and nobody + /// while no listener is set. /// /// /// There is one instance per engine, shared by (which sets the listener), @@ -69,7 +70,10 @@ internal void SetListener(IRealtimeOutputListener listener) /// The simulation thread's loop ended, normally or not (called from its finally); the frame update polls again. internal void SimulationThreadStopped() => Interlocked.Decrement(ref _simulationThreads); - /// Called by the simulation thread on every tick, between the time fence and the shared state. + /// + /// Called by the simulation thread on every tick, between the time fence and the shared state, and every 10 ms + /// while it is paused. + /// internal void PollFromSimulationThread() { if (Volatile.Read(ref _listening) != 0) { diff --git a/VisualPinball.Unity/VisualPinball.Unity/Plugins/UnityPluginContracts.cs b/VisualPinball.Unity/VisualPinball.Unity/Plugins/UnityPluginContracts.cs index 1d42643aa2..8d922e048b 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Plugins/UnityPluginContracts.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/Plugins/UnityPluginContracts.cs @@ -256,7 +256,9 @@ public interface IRealtimeOutputListener /// resource (<controller>/outputs/realtime) and sets a /// listener while that resource has subscribers. VPE then calls on every tick of /// the simulation thread, after the time fence and before the shared state is written, or once per frame from - /// when the game runs without the simulation thread. + /// when the game runs without the simulation thread. While the table is paused, the simulation + /// thread keeps calling it about every 10 ms without moving the time fence, so what an engine that runs on during a + /// pause reports does not pile up until the resume. /// /// Unlike , which reports from the engine's frame update, the feed carries /// switches, delivers the current state to each new receiver first, and keeps the order of modulated values. The diff --git a/VisualPinball.Unity/VisualPinball.Unity/Simulation/SimulationThread.cs b/VisualPinball.Unity/VisualPinball.Unity/Simulation/SimulationThread.cs index 855f1f0627..8cdb6a8b79 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Simulation/SimulationThread.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/Simulation/SimulationThread.cs @@ -557,6 +557,9 @@ private void SimulationThreadFunc() { if (_paused) { + // A game without a time fence keeps running while the table is paused, and so do its + // lamps. Keep taking its real-time outputs, or they pile up until the resume and overflow. + _realtimeOutputs?.PollFromSimulationThread(); Thread.Sleep(10); // Unity time stands still while paused (the menu sets timeScale to // zero); hold the timetable so no backlog accumulates to replay.