Skip to content

Commit

Permalink
Lua - tastudio library - supress lua console updates when invoking ta…
Browse files Browse the repository at this point in the history
…studio methods that cause tool udpates, fixes #2172
  • Loading branch information
adelikat committed Sep 27, 2020
1 parent b5cf9cb commit e4d4c3a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ public void SeekFrame(int frame)
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,23 @@ public SaveStateLuaLibrary(Lua lua, Action<string> logOutputCallback)
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 );")]
[LuaMethod("loadslot", "Loads the savestate at the given slot number (must be an integer between 0 and 9). If EmuHawk is deferring quicksaves, to TAStudio for example, that form will do what it likes with the slot number.")]
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\" );")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ public void SetPlayback(object frame)
{
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)
{
Expand All @@ -157,6 +160,8 @@ public void SetPlayback(object frame)
{
Tastudio.GoToFrame(f, true);
}

GlobalWin.Tools.LuaConsole?.LuaImp.EnableUpdate();
}
}

Expand Down Expand Up @@ -289,6 +294,9 @@ public void ApplyInputChanges()
{
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;
Expand Down Expand Up @@ -324,6 +332,8 @@ public void ApplyInputChanges()
Tastudio.JumpToGreenzone();
Tastudio.DoAutoRestore();
}

GlobalWin.Tools.LuaConsole?.LuaImp.EnableUpdate();
}
}

Expand Down Expand Up @@ -418,7 +428,12 @@ public void LoadBranch(int index)
{
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();
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ public bool LoadLuaSession(string path)

protected override void UpdateBefore()
{
if (LuaImp.SuppressLua)
if (LuaImp.IsUpdateSupressed)
{
return;
}
Expand All @@ -570,7 +570,7 @@ protected override void UpdateBefore()

protected override void UpdateAfter()
{
if (LuaImp.SuppressLua)
if (LuaImp.IsUpdateSupressed)
{
return;
}
Expand Down Expand Up @@ -607,7 +607,7 @@ public void ResumeScripts(bool includeFrameWaiters)
return;
}

if (LuaImp.SuppressLua)
if (LuaImp.IsUpdateSupressed)
{
return;
}
Expand Down
14 changes: 13 additions & 1 deletion src/BizHawk.Client.EmuHawk/tools/Lua/LuaLibraries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@ public abstract class LuaLibraries
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);
Expand Down
8 changes: 4 additions & 4 deletions src/BizHawk.Client.EmuHawk/tools/Lua/Win32LuaLibraries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ public override void Restart(IEmulatorServiceProvider newServiceProvider)

public override void StartLuaDrawing()
{
if (ScriptList.Count != 0 && GuiLibrary.SurfaceIsNull && !SuppressLua)
if (ScriptList.Count != 0 && GuiLibrary.SurfaceIsNull && !IsUpdateSupressed)
{
GuiLibrary.DrawNew("emu");
}
}

public override void EndLuaDrawing()
{
if (ScriptList.Count != 0 && !SuppressLua)
if (ScriptList.Count != 0 && !IsUpdateSupressed)
{
GuiLibrary.DrawFinish();
}
Expand All @@ -142,15 +142,15 @@ public override void CallLoadStateEvent(string name)

public override void CallFrameBeforeEvent()
{
if (!SuppressLua)
if (!IsUpdateSupressed)
{
EventsLibrary.CallFrameBeforeEvent();
}
}

public override void CallFrameAfterEvent()
{
if (!SuppressLua)
if (!IsUpdateSupressed)
{
EventsLibrary.CallFrameAfterEvent();
}
Expand Down

0 comments on commit e4d4c3a

Please sign in to comment.