From ea2188dc46aa842a43c6046063dc80b424ca0fbb Mon Sep 17 00:00:00 2001 From: zeromus Date: Tue, 7 Feb 2017 00:01:14 -0600 Subject: [PATCH] make tastudio.setplayback correctly restore the recording flag after it finishes seeking from the greenzone to the target frame --- BizHawk.Client.EmuHawk/MainForm.cs | 20 ++++++++--- .../Lua/Libraries/EmuLuaLibrary.Tastudio.cs | 1 - .../tools/TAStudio/TAStudio.cs | 34 +++++++++++++++---- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 5fa310d8cb..3164289677 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -518,7 +518,7 @@ namespace BizHawk.Client.EmuHawk // autohold/autofire must not be affected by the following inputs Global.ActiveController.Overrides(Global.LuaAndAdaptor); - if (GlobalWin.Tools.Has()) + if (GlobalWin.Tools.Has() && !SuppressLua) { GlobalWin.Tools.LuaConsole.ResumeScripts(false); } @@ -626,6 +626,9 @@ namespace BizHawk.Client.EmuHawk public bool TurboFastForward = false; public bool RestoreReadWriteOnStop = false; + //runloop won't exec lua + public bool SuppressLua; + public long MouseWheelTracker; private int? _pauseOnFrame; @@ -639,7 +642,7 @@ namespace BizHawk.Client.EmuHawk if (value == null) // TODO: make an Event handler instead, but the logic here is that after turbo seeking, tools will want to do a real update when the emulator finally pauses { - bool skipScripts = !(Global.Config.TurboSeek && !Global.Config.RunLuaDuringTurbo); + bool skipScripts = !(Global.Config.TurboSeek && !Global.Config.RunLuaDuringTurbo && !SuppressLua); GlobalWin.Tools.UpdateToolsBefore(skipScripts); GlobalWin.Tools.UpdateToolsAfter(skipScripts); } @@ -2694,6 +2697,13 @@ namespace BizHawk.Client.EmuHawk StepRunLoop_Core(true); } + public void SeekFrameAdvance() + { + PressFrameAdvance = true; + StepRunLoop_Core(true); + PressFrameAdvance = false; + } + public bool IsLagFrame { get @@ -2784,7 +2794,7 @@ namespace BizHawk.Client.EmuHawk Global.ClickyVirtualPadController.FrameTick(); Global.LuaAndAdaptor.FrameTick(); - if (GlobalWin.Tools.Has()) + if (GlobalWin.Tools.Has() && !SuppressLua) { GlobalWin.Tools.LuaConsole.LuaImp.CallFrameBeforeEvent(); } @@ -2852,7 +2862,7 @@ namespace BizHawk.Client.EmuHawk PressFrameAdvance = false; - if (GlobalWin.Tools.Has()) + if (GlobalWin.Tools.Has() && !SuppressLua) { GlobalWin.Tools.LuaConsole.LuaImp.CallFrameAfterEvent(); } @@ -2863,7 +2873,7 @@ namespace BizHawk.Client.EmuHawk } else { - UpdateToolsAfter(); + UpdateToolsAfter(SuppressLua); } if (GlobalWin.Tools.IsLoaded() && diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Tastudio.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Tastudio.cs index ce305978fb..e12b4671e0 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Tastudio.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Tastudio.cs @@ -167,7 +167,6 @@ namespace BizHawk.Client.EmuHawk if (frame is double) f = (int)(double)frame; else { - //r marker = Tastudio.CurrentTasMovie.Markers.Get(frame); f = Tastudio.CurrentTasMovie.Markers.FindIndex((string)frame); if (f == -1) return; f = Tastudio.CurrentTasMovie.Markers[f].Frame; diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 8a276b338a..46c7465974 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -819,6 +819,31 @@ namespace BizHawk.Client.EmuHawk LoadState(closestState); } + if (fromLua) + { + bool wasPaused = Mainform.EmulatorPaused; + + //why not use this? because I'm not letting the form freely run. it all has to be under this loop. + //i could use this and then poll StepRunLoop_Core() repeatedly, but.. that's basically what I'm doing + //PauseOnFrame = frame; + + //can't re-enter lua while doing this + Mainform.SuppressLua = true; + while (Emulator.Frame != frame) + Mainform.SeekFrameAdvance(); + Mainform.SuppressLua = false; + + if(!wasPaused) Mainform.UnpauseEmulator(); + + //lua botting users will want to re-activate record mode automatically -- it should be like nothing ever happened + if (_wasRecording) + { + TastudioRecordMode(); + } + + //now the next section won't happen since we're at the right spot + } + // frame == Emualtor.Frame when frame == 0 if (frame > Emulator.Frame) { @@ -828,13 +853,8 @@ namespace BizHawk.Client.EmuHawk } else { - if (_wasRecording) - { - //lua botting users will want to re-activate record mode automatically -- it should be like nothing ever happened - //GUI users on the other hand need to be protected from clobbering their video when skipping around - if(fromLua) - TastudioRecordMode(); - } + //GUI users hand need to be protected from clobbering their video when skipping around + //so we don't re-enable recording } } }