Skip to content

Adapt VPE's threading model with PinMAME 3.7#37

Merged
freezy merged 17 commits intomasterfrom
pinmame37
Apr 10, 2026
Merged

Adapt VPE's threading model with PinMAME 3.7#37
freezy merged 17 commits intomasterfrom
pinmame37

Conversation

@freezy
Copy link
Copy Markdown
Member

@freezy freezy commented Apr 10, 2026

This PR stabilizes the PinMAME Unity integration around play mode lifecycle, cross-thread event dispatch, and shared-state handoff with the simulation thread. It also updates the PinMAME .NET dependency to 1.0.2, which uses the lastest PinMAME 3.7 beta.

Lifecycle and shutdown safety

  • Added editor play mode lifecycle hook (PinMamePlayModeLifecycle) to coordinate deterministic PinMAME shutdown on play mode exit/editor quit.
  • Hardened PinMameGamelogicEngine init/stop flow with start/stop gating and defensive unsubscribe/cleanup paths.
  • Added StopForPlayModeExit() and improved OnDisable/OnDestroy/OnApplicationQuit handling to avoid stale callbacks and overlapping sessions.

Threading and performance instrumentation

  • Added simulation-thread-facing interfaces:
    • IGamelogicInputThreading
    • IGamelogicTimeFence
    • IGamelogicCoilOutputFeed
    • IGamelogicSharedStateWriter
    • IGamelogicSharedStateApplier
    • IGamelogicPerformanceStats
  • Added bounded/instrumented coil dispatch queue for simulation-thread consumption (TryDequeueCoilEvent), including backlog/drop warnings.
  • Added callback-rate sampling and TryGetPerformanceStats.

Shared state publication / application

  • Added shared state snapshots for coils/lamps/GI (WriteSharedState + ApplySharedState) with lock-protected state caches.
  • Added de-duplication when applying lamp/GI state to avoid redundant updates.

Display / output handling improvements

  • Reworked DMD frame copy path to direct byte copy and moved dispatch through main-thread queue wrapper.
  • Switched DMD frame format reporting to DisplayFrameFormat.Dmd8.
  • Added safer handling when display frames arrive before display buffers are registered.

Mech and misc fixes

  • Fixed mech registration to use 1-based IDs and improved mech slot/max diagnostics.
  • Cached mech name in PinMameMechComponent for clearer mapping error logs.
  • Reduced hot-path logging in callback-heavy code paths.

Testing

  • No automated test run was performed as part of this PR draft.
  • Recommended validation:
    • Enter/exit play mode repeatedly with domain reload on/off.
    • Verify ROM start/stop reliability across sessions.
    • Verify DMD/segment updates and lamp/GI behavior.
    • Verify mech registration and coil dispatch behavior under load.

freezy added 17 commits February 7, 2026 16:20
`PinMameGamelogicEngine.Update()` now copies `_dispatchQueue` callbacks into a reusable local list under the queue lock, then releases the lock before invoking them. This removes callback execution time from the producer-contention window while preserving callback order and exception handling.
`PinMameGamelogicEngine` warns on main-thread dispatch queue growth and simulation-coil queue overflow.
…cks.

The solenoid-delay timing check now uses a monotonic `Stopwatch`-based timestamp instead of `DateTimeOffset.Now`, and high-frequency coil callback logs were downgraded behind `Logger.IsDebugEnabled` so normal runtime no longer pays string-format/logging cost on every coil edge.
@freezy freezy merged commit d8a7969 into master Apr 10, 2026
13 checks passed
@freezy freezy deleted the pinmame37 branch April 10, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant