From e4d4c3a9d83599aff3d4d7a85637fab860d1bd84 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 27 Sep 2020 12:59:09 -0500 Subject: [PATCH] Lua - tastudio library - supress lua console updates when invoking tastudio methods that cause tool udpates, fixes #2172 --- .../tools/Lua/Libraries/ClientLuaLibrary.cs | 4 ++-- .../Lua/Libraries/SaveStateLuaLibrary.cs | 22 ++++--------------- .../tools/Lua/Libraries/TAStudioLuaLibrary.cs | 15 +++++++++++++ .../tools/Lua/LuaConsole.cs | 6 ++--- .../tools/Lua/LuaLibraries.cs | 14 +++++++++++- .../tools/Lua/Win32LuaLibraries.cs | 8 +++---- 6 files changed, 41 insertions(+), 28 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/ClientLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/ClientLuaLibrary.cs index 7c241630d0..c89d83247e 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/ClientLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/ClientLuaLibrary.cs @@ -104,13 +104,13 @@ namespace BizHawk.Client.EmuHawk bool wasPaused = MainForm.EmulatorPaused; // can't re-enter lua while doing this - GlobalWin.Tools.LuaConsole.LuaImp.SuppressLua = true; + GlobalWin.Tools.LuaConsole?.LuaImp.SupressUpdate(); while (Emulator.Frame != frame) { MainForm.SeekFrameAdvance(); } - GlobalWin.Tools.LuaConsole.LuaImp.SuppressLua = false; + GlobalWin.Tools.LuaConsole?.LuaImp.EnableUpdate(); if (!wasPaused) { diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/SaveStateLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/SaveStateLuaLibrary.cs index 02936e8098..f9ce88a6af 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/SaveStateLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/SaveStateLuaLibrary.cs @@ -21,18 +21,11 @@ namespace BizHawk.Client.EmuHawk public void Load(string path, bool suppressOSD = false) { // TODO: find a non-global way to access LuaImp from Lua libraries! - var luaImp = GlobalWin.Tools.LuaConsole?.LuaImp; - if (luaImp != null) - { - luaImp.SuppressLua = true; - } + GlobalWin.Tools.LuaConsole?.LuaImp.SupressUpdate(); APIs.SaveState.Load(path, suppressOSD); - if (luaImp != null) - { - luaImp.SuppressLua = false; - } + GlobalWin.Tools.LuaConsole?.LuaImp.EnableUpdate(); } [LuaMethodExample("savestate.loadslot( 7 );")] @@ -40,18 +33,11 @@ namespace BizHawk.Client.EmuHawk public void LoadSlot(int slotNum, bool suppressOSD = false) { // TODO: find a non-global way to access LuaImp from Lua libraries! - var luaImp = GlobalWin.Tools.LuaConsole?.LuaImp; - if (luaImp != null) - { - luaImp.SuppressLua = true; - } + GlobalWin.Tools.LuaConsole?.LuaImp.SupressUpdate(); APIs.SaveState.LoadSlot(slotNum, suppressOSD); - if (luaImp != null) - { - luaImp.SuppressLua = false; - } + GlobalWin.Tools.LuaConsole?.LuaImp.EnableUpdate(); } [LuaMethodExample("savestate.save( \"C:\\state.bin\" );")] diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs index 2da3913dcc..5eb34d334d 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs @@ -137,6 +137,9 @@ namespace BizHawk.Client.EmuHawk { if (Engaged()) { + // TODO: find a non-global way to access LuaImp from Lua libraries! + GlobalWin.Tools.LuaConsole?.LuaImp.SupressUpdate(); + int f; if (frame is double frameNumber) { @@ -157,6 +160,8 @@ namespace BizHawk.Client.EmuHawk { Tastudio.GoToFrame(f, true); } + + GlobalWin.Tools.LuaConsole?.LuaImp.EnableUpdate(); } } @@ -289,6 +294,9 @@ namespace BizHawk.Client.EmuHawk { if (Engaged()) { + // TODO: find a non-global way to access LuaImp from Lua libraries! + GlobalWin.Tools.LuaConsole?.LuaImp.SupressUpdate(); + if (_changeList.Count > 0) { int size = _changeList.Count; @@ -324,6 +332,8 @@ namespace BizHawk.Client.EmuHawk Tastudio.JumpToGreenzone(); Tastudio.DoAutoRestore(); } + + GlobalWin.Tools.LuaConsole?.LuaImp.EnableUpdate(); } } @@ -418,7 +428,12 @@ namespace BizHawk.Client.EmuHawk { if (Engaged()) { + // TODO: find a non-global way to access LuaImp from Lua libraries! + GlobalWin.Tools.LuaConsole?.LuaImp.SupressUpdate(); + Tastudio.LoadBranchByIndex(index); + + GlobalWin.Tools.LuaConsole?.LuaImp.EnableUpdate(); } } diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index 69b87fd58c..7135d6fe91 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -559,7 +559,7 @@ namespace BizHawk.Client.EmuHawk protected override void UpdateBefore() { - if (LuaImp.SuppressLua) + if (LuaImp.IsUpdateSupressed) { return; } @@ -570,7 +570,7 @@ namespace BizHawk.Client.EmuHawk protected override void UpdateAfter() { - if (LuaImp.SuppressLua) + if (LuaImp.IsUpdateSupressed) { return; } @@ -607,7 +607,7 @@ namespace BizHawk.Client.EmuHawk return; } - if (LuaImp.SuppressLua) + if (LuaImp.IsUpdateSupressed) { return; } diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaLibraries.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaLibraries.cs index 03c79b7fd4..ba0d100e9d 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaLibraries.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaLibraries.cs @@ -18,7 +18,19 @@ namespace BizHawk.Client.EmuHawk public readonly LuaFileList ScriptList = new LuaFileList(); public bool IsRebootingCore { get; set; } // pretty hacky.. we don't want a lua script to be able to restart itself by rebooting the core - public bool SuppressLua { get; set; } + + public bool IsUpdateSupressed { get; private set;} + + public void SupressUpdate() + { + IsUpdateSupressed = true; + } + + public void EnableUpdate() + { + IsUpdateSupressed = false; + } + public EventWaitHandle LuaWait { get; protected set; } public abstract void CallExitEvent(LuaFile lf); diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Win32LuaLibraries.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Win32LuaLibraries.cs index 5e1f037bf3..98ac33d148 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Win32LuaLibraries.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Win32LuaLibraries.cs @@ -107,7 +107,7 @@ namespace BizHawk.Client.EmuHawk public override void StartLuaDrawing() { - if (ScriptList.Count != 0 && GuiLibrary.SurfaceIsNull && !SuppressLua) + if (ScriptList.Count != 0 && GuiLibrary.SurfaceIsNull && !IsUpdateSupressed) { GuiLibrary.DrawNew("emu"); } @@ -115,7 +115,7 @@ namespace BizHawk.Client.EmuHawk public override void EndLuaDrawing() { - if (ScriptList.Count != 0 && !SuppressLua) + if (ScriptList.Count != 0 && !IsUpdateSupressed) { GuiLibrary.DrawFinish(); } @@ -142,7 +142,7 @@ namespace BizHawk.Client.EmuHawk public override void CallFrameBeforeEvent() { - if (!SuppressLua) + if (!IsUpdateSupressed) { EventsLibrary.CallFrameBeforeEvent(); } @@ -150,7 +150,7 @@ namespace BizHawk.Client.EmuHawk public override void CallFrameAfterEvent() { - if (!SuppressLua) + if (!IsUpdateSupressed) { EventsLibrary.CallFrameAfterEvent(); }