refactor lua shenanigans in mainform, instead move frame based logic to lua console update hooks, control SupressScripts in lua itself not in mainform. Also, this breaks the logic that automatically stop countihng rerecords if loadstate happens from script, the logic appeared to be broken and can/should be managed by the script itself
This commit is contained in:
parent
4391c97a8e
commit
22ee71b0cf
|
@ -245,6 +245,8 @@ namespace BizHawk.Client.Common
|
|||
public RecentFiles RecentLua { get; set; } = new RecentFiles(8);
|
||||
public RecentFiles RecentLuaSession { get; set; } = new RecentFiles(8);
|
||||
public bool DisableLuaScriptsOnLoad { get; set; }
|
||||
|
||||
// luaconsole-refactor TODO: move this to LuaConsole settings
|
||||
public bool RunLuaDuringTurbo { get; set; } = true;
|
||||
|
||||
// Watch Settings
|
||||
|
|
|
@ -24,12 +24,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
LogCallback($"could not find file: {path}");
|
||||
return;
|
||||
}
|
||||
GlobalWin.MainForm.LoadState(path, Path.GetFileName(path), true, suppressOSD);
|
||||
|
||||
GlobalWin.MainForm.LoadState(path, Path.GetFileName(path), suppressOSD);
|
||||
}
|
||||
|
||||
public void LoadSlot(int slotNum, bool suppressOSD)
|
||||
{
|
||||
if (0.RangeTo(9).Contains(slotNum)) GlobalWin.MainForm.LoadQuickSave($"QuickSave{slotNum}", true, suppressOSD);
|
||||
if (0.RangeTo(9).Contains(slotNum)) GlobalWin.MainForm.LoadQuickSave($"QuickSave{slotNum}", suppressOSD);
|
||||
}
|
||||
|
||||
public void Save(string path, bool suppressOSD) => GlobalWin.MainForm.SaveState(path, path, true, suppressOSD);
|
||||
|
|
|
@ -582,7 +582,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
// autohold/autofire must not be affected by the following inputs
|
||||
Global.InputManager.ActiveController.Overrides(Global.InputManager.ButtonOverrideAdapter);
|
||||
|
||||
if (Tools.Has<LuaConsole>() && !SuppressLua)
|
||||
if (Tools.Has<LuaConsole>())
|
||||
{
|
||||
Tools.LuaConsole.ResumeScripts(false);
|
||||
}
|
||||
|
@ -704,9 +704,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
/// </summary>
|
||||
public bool InvisibleEmulation { get; set; }
|
||||
|
||||
// runloop won't exec lua
|
||||
public bool SuppressLua { get; set; }
|
||||
|
||||
public long MouseWheelTracker { get; private set; }
|
||||
|
||||
private int? _pauseOnFrame;
|
||||
|
@ -721,9 +718,8 @@ 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 = !(Config.TurboSeek && !Config.RunLuaDuringTurbo && !SuppressLua);
|
||||
Tools.UpdateToolsBefore(skipScripts);
|
||||
Tools.UpdateToolsAfter(skipScripts);
|
||||
Tools.UpdateToolsBefore();
|
||||
Tools.UpdateToolsAfter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1577,9 +1573,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
private void UpdateToolsAfter(bool fromLua = false)
|
||||
private void UpdateToolsAfter()
|
||||
{
|
||||
Tools.UpdateToolsAfter(fromLua);
|
||||
Tools.UpdateToolsAfter();
|
||||
HandleToggleLightAndLink();
|
||||
}
|
||||
|
||||
|
@ -2916,11 +2912,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
InputManager.ClickyVirtualPadController.FrameTick();
|
||||
Global.InputManager.ButtonOverrideAdapter.FrameTick();
|
||||
|
||||
if (Tools.Has<LuaConsole>() && !SuppressLua)
|
||||
{
|
||||
Tools.LuaConsole.LuaImp.CallFrameBeforeEvent();
|
||||
}
|
||||
|
||||
if (IsTurboing)
|
||||
{
|
||||
Tools.FastUpdateBefore();
|
||||
|
@ -3002,18 +2993,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
PressFrameAdvance = false;
|
||||
|
||||
if (Tools.Has<LuaConsole>() && !SuppressLua)
|
||||
{
|
||||
Tools.LuaConsole.LuaImp.CallFrameAfterEvent();
|
||||
}
|
||||
|
||||
if (IsTurboing)
|
||||
{
|
||||
Tools.FastUpdateAfter(SuppressLua);
|
||||
Tools.FastUpdateAfter();
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateToolsAfter(SuppressLua);
|
||||
UpdateToolsAfter();
|
||||
}
|
||||
|
||||
if (!PauseAvi && newFrame && !InvisibleEmulation)
|
||||
|
@ -4042,7 +4028,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return int.Parse(slot.Substring(slot.Length - 1, 1));
|
||||
}
|
||||
|
||||
public void LoadState(string path, string userFriendlyStateName, bool fromLua = false, bool suppressOSD = false) // Move to client.common
|
||||
public void LoadState(string path, string userFriendlyStateName, bool suppressOSD = false) // Move to client.common
|
||||
{
|
||||
if (!Emulator.HasSavestates())
|
||||
{
|
||||
|
@ -4055,14 +4041,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
return;
|
||||
}
|
||||
|
||||
// If from lua, disable counting rerecords
|
||||
bool wasCountingRerecords = MovieSession.Movie.IsCountingRerecords;
|
||||
|
||||
if (fromLua)
|
||||
{
|
||||
MovieSession.Movie.IsCountingRerecords = false;
|
||||
}
|
||||
|
||||
if (SavestateManager.LoadStateFile(Emulator, path))
|
||||
{
|
||||
GlobalWin.OSD.ClearGuiText();
|
||||
|
@ -4074,8 +4052,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
SetMainformMovieInfo();
|
||||
Tools.UpdateToolsBefore(fromLua);
|
||||
UpdateToolsAfter(fromLua);
|
||||
Tools.UpdateToolsBefore();
|
||||
UpdateToolsAfter();
|
||||
UpdateToolsLoadstate();
|
||||
InputManager.AutoFireController.ClearStarts();
|
||||
|
||||
|
@ -4093,11 +4071,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
AddOnScreenMessage("Loadstate error!");
|
||||
}
|
||||
|
||||
MovieSession.Movie.IsCountingRerecords = wasCountingRerecords;
|
||||
}
|
||||
|
||||
public void LoadQuickSave(string quickSlotName, bool fromLua = false, bool suppressOSD = false)
|
||||
public void LoadQuickSave(string quickSlotName, bool suppressOSD = false)
|
||||
{
|
||||
if (!Emulator.HasSavestates())
|
||||
{
|
||||
|
@ -4124,7 +4100,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return;
|
||||
}
|
||||
|
||||
LoadState(path, quickSlotName, fromLua, suppressOSD);
|
||||
LoadState(path, quickSlotName, suppressOSD);
|
||||
}
|
||||
|
||||
public void SaveState(string path, string userFriendlyStateName, bool fromLua = false, bool suppressOSD = false)
|
||||
|
|
|
@ -449,7 +449,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
StopBot();
|
||||
_replayMode = true;
|
||||
_doNotUpdateValues = true;
|
||||
MainForm.LoadQuickSave(SelectedSlot, false, true); // Triggers an UpdateValues call
|
||||
MainForm.LoadQuickSave(SelectedSlot, true); // Triggers an UpdateValues call
|
||||
_doNotUpdateValues = false;
|
||||
_startFrame = Emulator.Frame;
|
||||
SetNormalSpeed();
|
||||
|
@ -797,7 +797,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
_currentBotAttempt = new BotAttempt { Attempt = Attempts };
|
||||
MainForm.LoadQuickSave(SelectedSlot, false, true);
|
||||
MainForm.LoadQuickSave(SelectedSlot, true);
|
||||
}
|
||||
|
||||
// Before this would have 2 additional hits before the frame even advanced, making the amount of inputs greater than the number of frames to test.
|
||||
|
@ -936,7 +936,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
_doNotUpdateValues = true;
|
||||
MainForm.LoadQuickSave(SelectedSlot, false, true); // Triggers an UpdateValues call
|
||||
MainForm.LoadQuickSave(SelectedSlot, true); // Triggers an UpdateValues call
|
||||
_doNotUpdateValues = false;
|
||||
|
||||
_targetFrame = Emulator.Frame + (int)FrameLengthNumeric.Value;
|
||||
|
|
|
@ -136,13 +136,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
bool wasPaused = MainForm.EmulatorPaused;
|
||||
|
||||
// can't re-enter lua while doing this
|
||||
MainForm.SuppressLua = true;
|
||||
GlobalWin.Tools.LuaConsole.LuaImp.SuppressLua = true;
|
||||
while (Emulator.Frame != frame)
|
||||
{
|
||||
MainForm.SeekFrameAdvance();
|
||||
}
|
||||
|
||||
MainForm.SuppressLua = false;
|
||||
GlobalWin.Tools.LuaConsole.LuaImp.SuppressLua = false;
|
||||
|
||||
if (!wasPaused)
|
||||
{
|
||||
|
|
|
@ -17,12 +17,44 @@ namespace BizHawk.Client.EmuHawk
|
|||
public override string Name => "savestate";
|
||||
|
||||
[LuaMethodExample("savestate.load( \"C:\\state.bin\" );")]
|
||||
[LuaMethod("load", "Loads a savestate with the given path. If EmuHawk is deferring quicksaves, to TAStudio for example, that form will do what it likes (and the path is ignored).")]
|
||||
public void Load(string path, bool suppressOSD = false) => APIs.SaveState.Load(path, suppressOSD);
|
||||
[LuaMethod("load"
|
||||
, "Loads a savestate with the given path. If EmuHawk is deferring quicksaves, to TAStudio for example, that form will do what it likes (and the path is ignored).")]
|
||||
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;
|
||||
}
|
||||
|
||||
APIs.SaveState.Load(path, suppressOSD);
|
||||
|
||||
if (luaImp != null)
|
||||
{
|
||||
luaImp.SuppressLua = false;
|
||||
}
|
||||
}
|
||||
|
||||
[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) => APIs.SaveState.LoadSlot(slotNum, suppressOSD);
|
||||
[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;
|
||||
}
|
||||
|
||||
APIs.SaveState.LoadSlot(slotNum, suppressOSD);
|
||||
|
||||
if (luaImp != null)
|
||||
{
|
||||
luaImp.SuppressLua = false;
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("savestate.save( \"C:\\state.bin\" );")]
|
||||
[LuaMethod("save", "Saves a state at the given path. If EmuHawk is deferring quicksaves, to TAStudio for example, that form will do what it likes (and the path is ignored).")]
|
||||
|
|
|
@ -520,6 +520,45 @@ namespace BizHawk.Client.EmuHawk
|
|||
return result;
|
||||
}
|
||||
|
||||
protected override void UpdateBefore()
|
||||
{
|
||||
if (LuaImp.SuppressLua)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LuaImp.CallFrameBeforeEvent();
|
||||
LuaImp.StartLuaDrawing();
|
||||
}
|
||||
|
||||
protected override void UpdateAfter()
|
||||
{
|
||||
if (LuaImp.SuppressLua)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LuaImp.CallFrameAfterEvent();
|
||||
ResumeScripts(true);
|
||||
LuaImp.EndLuaDrawing();
|
||||
}
|
||||
|
||||
protected override void FastUpdateBefore()
|
||||
{
|
||||
if (Config.RunLuaDuringTurbo)
|
||||
{
|
||||
UpdateBefore();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void FastUpdateAfter()
|
||||
{
|
||||
if (Config.RunLuaDuringTurbo)
|
||||
{
|
||||
UpdateAfter();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// resumes suspended Co-routines
|
||||
/// </summary>
|
||||
|
@ -531,6 +570,16 @@ namespace BizHawk.Client.EmuHawk
|
|||
return;
|
||||
}
|
||||
|
||||
if (LuaImp.SuppressLua)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MainForm.IsTurboing && !Config.RunLuaDuringTurbo)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (LuaImp.GuiLibrary?.SurfaceIsNull == true)
|
||||
{
|
||||
LuaImp.GuiLibrary.DrawNew("emu");
|
||||
|
|
|
@ -18,6 +18,7 @@ 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 EventWaitHandle LuaWait { get; protected set; }
|
||||
|
||||
public abstract void CallExitEvent(LuaFile lf);
|
||||
|
|
|
@ -122,7 +122,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public override void StartLuaDrawing()
|
||||
{
|
||||
if (ScriptList.Count != 0 && GuiLibrary.SurfaceIsNull)
|
||||
if (ScriptList.Count != 0 && GuiLibrary.SurfaceIsNull && !SuppressLua)
|
||||
{
|
||||
GuiLibrary.DrawNew("emu");
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public override void EndLuaDrawing()
|
||||
{
|
||||
if (ScriptList.Count != 0)
|
||||
if (ScriptList.Count != 0 && !SuppressLua)
|
||||
{
|
||||
GuiLibrary.DrawFinish();
|
||||
}
|
||||
|
@ -157,12 +157,18 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public override void CallFrameBeforeEvent()
|
||||
{
|
||||
EventsLibrary.CallFrameBeforeEvent();
|
||||
if (!SuppressLua)
|
||||
{
|
||||
EventsLibrary.CallFrameBeforeEvent();
|
||||
}
|
||||
}
|
||||
|
||||
public override void CallFrameAfterEvent()
|
||||
{
|
||||
EventsLibrary.CallFrameAfterEvent();
|
||||
if (!SuppressLua)
|
||||
{
|
||||
EventsLibrary.CallFrameAfterEvent();
|
||||
}
|
||||
}
|
||||
|
||||
public override void CallExitEvent(LuaFile lf)
|
||||
|
|
|
@ -461,30 +461,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
.Where(t => typeof(IToolForm).IsAssignableFrom(t))
|
||||
.Where(t => !t.IsInterface)
|
||||
.Where(IsAvailable);
|
||||
|
||||
private void UpdateBefore()
|
||||
{
|
||||
foreach (var tool in _tools)
|
||||
{
|
||||
if (!tool.IsDisposed
|
||||
|| (tool is RamWatch && _config.DisplayRamWatch)) // RAM Watch hack, on screen display should run even if RAM Watch is closed
|
||||
{
|
||||
tool.UpdateValues(ToolFormUpdateType.PreFrame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateAfter()
|
||||
{
|
||||
foreach (var tool in _tools)
|
||||
{
|
||||
if (!tool.IsDisposed
|
||||
|| (tool is RamWatch && _config.DisplayRamWatch)) // RAM Watch hack, on screen display should run even if RAM Watch is closed
|
||||
{
|
||||
tool.UpdateValues(ToolFormUpdateType.PostFrame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls UpdateValues() on an instance of T, if it exists
|
||||
|
@ -665,33 +641,26 @@ namespace BizHawk.Client.EmuHawk
|
|||
return tool;
|
||||
}
|
||||
|
||||
public void UpdateToolsBefore(bool fromLua = false)
|
||||
public void UpdateToolsBefore()
|
||||
{
|
||||
if (Has<LuaConsole>())
|
||||
foreach (var tool in _tools)
|
||||
{
|
||||
if (!fromLua)
|
||||
if (!tool.IsDisposed
|
||||
|| (tool is RamWatch && _config.DisplayRamWatch)) // RAM Watch hack, on screen display should run even if RAM Watch is closed
|
||||
{
|
||||
LuaConsole.LuaImp.StartLuaDrawing();
|
||||
tool.UpdateValues(ToolFormUpdateType.PreFrame);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateBefore();
|
||||
}
|
||||
|
||||
public void UpdateToolsAfter(bool fromLua = false)
|
||||
public void UpdateToolsAfter()
|
||||
{
|
||||
if (!fromLua && Has<LuaConsole>())
|
||||
foreach (var tool in _tools)
|
||||
{
|
||||
LuaConsole.ResumeScripts(true);
|
||||
}
|
||||
|
||||
UpdateAfter();
|
||||
|
||||
if (Has<LuaConsole>())
|
||||
{
|
||||
if (!fromLua)
|
||||
if (!tool.IsDisposed
|
||||
|| (tool is RamWatch && _config.DisplayRamWatch)) // RAM Watch hack, on screen display should run even if RAM Watch is closed
|
||||
{
|
||||
LuaConsole.LuaImp.EndLuaDrawing();
|
||||
tool.UpdateValues(ToolFormUpdateType.PostFrame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -708,13 +677,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
public void FastUpdateAfter(bool fromLua = false)
|
||||
public void FastUpdateAfter()
|
||||
{
|
||||
if (!fromLua && _config.RunLuaDuringTurbo && Has<LuaConsole>())
|
||||
{
|
||||
LuaConsole.ResumeScripts(true);
|
||||
}
|
||||
|
||||
foreach (var tool in _tools)
|
||||
{
|
||||
if (!tool.IsDisposed
|
||||
|
@ -723,11 +687,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
tool.UpdateValues(ToolFormUpdateType.FastPostFrame);
|
||||
}
|
||||
}
|
||||
|
||||
if (_config.RunLuaDuringTurbo && Has<LuaConsole>())
|
||||
{
|
||||
LuaConsole.LuaImp.EndLuaDrawing();
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Lazy<List<string>> LazyAsmTypes = new Lazy<List<string>>(() =>
|
||||
|
|
Loading…
Reference in New Issue