Lua - tastudio library - supress lua console updates when invoking tastudio methods that cause tool udpates, fixes #2172

This commit is contained in:
adelikat 2020-09-27 12:59:09 -05:00
parent b5cf9cb241
commit e4d4c3a9d8
6 changed files with 41 additions and 28 deletions

View File

@ -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)
{

View File

@ -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\" );")]

View File

@ -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();
}
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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();
}