Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ namespace VisualPinball.Unity
{
/// <summary>
/// Decides who calls an engine's <see cref="IGamelogicRealtimeOutputs.PollRealtimeOutputs"/>: 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.
/// </summary>
/// <remarks>
/// There is one instance per engine, shared by <see cref="GamelogicPluginResources"/> (which sets the listener),
Expand Down Expand Up @@ -69,7 +70,10 @@ internal void SetListener(IRealtimeOutputListener listener)
/// <summary>The simulation thread's loop ended, normally or not (called from its <c>finally</c>); the frame update polls again.</summary>
internal void SimulationThreadStopped() => Interlocked.Decrement(ref _simulationThreads);

/// <summary>Called by the simulation thread on every tick, between the time fence and the shared state.</summary>
/// <summary>
/// Called by the simulation thread on every tick, between the time fence and the shared state, and every 10 ms
/// while it is paused.
/// </summary>
internal void PollFromSimulationThread()
{
if (Volatile.Read(ref _listening) != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ public interface IRealtimeOutputListener
/// <see cref="ResourceKind.RealtimeOutputs"/> resource (<c>&lt;controller&gt;/outputs/realtime</c>) and sets a
/// listener while that resource has subscribers. VPE then calls <see cref="PollRealtimeOutputs"/> on every tick of
/// the simulation thread, after the time fence and before the shared state is written, or once per frame from
/// <see cref="Player"/> when the game runs without the simulation thread.
/// <see cref="Player"/> 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.
/// <para>
/// Unlike <see cref="IGamelogicNativeOutputs"/>, 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Paused polling lacks test coverage

The new paused-loop poll has no regression test. TheSimulationThreadTakesOverThePollFromTheFrame calls the poll helper directly, so it would still pass if this line were removed. Add a test that pauses the simulation, checks that outputs keep arriving, and checks that the time fence stays fixed.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not adding one here. Testing this line means running the real simulation thread, and its loop only starts after a fully initialized physics engine (it waits for PhysicsEngine.IsInitialized, then gives up after 5 s). No test in the suite starts the thread; the existing ones call its methods directly. A test that pauses the running thread would need that harness first, which is out of scope for this fix.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s fair. A regression test for this line would require bringing up the initialized physics engine and running the simulation thread, and the existing tests don’t provide that harness. I’ll withdraw the test-coverage comment for this change; the direct helper test is not a substitute for exercising the paused loop, but adding that infrastructure is out of scope here.

Thread.Sleep(10);
// Unity time stands still while paused (the menu sets timeScale to
// zero); hold the timetable so no backlog accumulates to replay.
Expand Down
Loading