@@ -39,7 +39,7 @@ namespace VisualPinball.Engine.PinMAME
3939 [ DisallowMultipleComponent ]
4040 [ RequireComponent ( typeof ( AudioSource ) ) ]
4141 [ AddComponentMenu ( "Pinball/Gamelogic Engine/PinMAME" ) ]
42- public class PinMameGamelogicEngine : MonoBehaviour , IGamelogicEngine , IGamelogicInputThreading
42+ public class PinMameGamelogicEngine : MonoBehaviour , IGamelogicEngine , IGamelogicInputThreading , IGamelogicTimeFence
4343 {
4444 public string Name { get ; } = "PinMAME Gamelogic Engine" ;
4545 public GamelogicInputDispatchMode SwitchDispatchMode => GamelogicInputDispatchMode . SimulationThread ;
@@ -97,10 +97,24 @@ public GamelogicEngineLamp[] RequestedLamps {
9797 public event EventHandler < LampsEventArgs > OnLampsChanged ;
9898 public event EventHandler < RequestedDisplays > OnDisplaysRequested ;
9999 public event EventHandler < string > OnDisplayClear ;
100- public event EventHandler < DisplayFrameData > OnDisplayUpdateFrame ;
101- public event EventHandler < EventArgs > OnStarted ;
102-
103- #endregion
100+ public event EventHandler < DisplayFrameData > OnDisplayUpdateFrame ;
101+ public event EventHandler < EventArgs > OnStarted ;
102+
103+ public void SetTimeFence ( double timeInSeconds )
104+ {
105+ if ( ! _isRunning || _pinMame == null ) {
106+ return ;
107+ }
108+
109+ try {
110+ PinMame . PinMame . SetTimeFence ( timeInSeconds ) ;
111+ }
112+ catch ( Exception e ) {
113+ Logger . Warn ( e , "[PinMAME] SetTimeFence call failed." ) ;
114+ }
115+ }
116+
117+ #endregion
104118
105119 #region Internals
106120
@@ -284,6 +298,7 @@ public void StopForPlayModeExit()
284298 // Do not call into native Stop() here (it blocks); the editor hook will stop PinMAME
285299 // after we unsubscribe managed callbacks.
286300 Interlocked . Exchange ( ref _stopRequested , 1 ) ;
301+ SetTimeFence ( 0.0 ) ;
287302 // Stop polling outputs immediately to avoid concurrent calls into pinmame.dll
288303 // while a stop is in progress (pinmame APIs are not guaranteed thread-safe).
289304 _isRunning = false ;
@@ -317,6 +332,8 @@ private void RequestStopGame(string reason)
317332 #endif
318333
319334 try {
335+ SetTimeFence ( 0.0 ) ;
336+
320337 if ( Interlocked . Exchange ( ref _stopRequested , 1 ) != 0 ) {
321338 return ;
322339 }
@@ -1062,8 +1079,8 @@ private void SendMechs()
10621079 }
10631080 }
10641081
1065- #endregion
1066-
1082+ #endregion
1083+
10671084 private int IsKeyPressed ( PinMameKeycode keycode )
10681085 {
10691086 if ( keycode == PinMameKeycode . F10 ) {
0 commit comments