From 63ef0c0832f14c8b256bc47e5007b37b2e59023b Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 2 Sep 2012 16:23:42 +0000 Subject: [PATCH] Lua - implement emu.registerbefore and emu.registerafter. Note that all lua work is done on the beginning of the frame (before) by default. also note that Registerbefore will run before normal lua processing. --- BizHawk.MultiClient/LuaImplementation.cs | 50 +++++++++++++++++++++++- BizHawk.MultiClient/MainForm.cs | 10 +++-- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/BizHawk.MultiClient/LuaImplementation.cs b/BizHawk.MultiClient/LuaImplementation.cs index 41f7b9a582..bd9c82a3d6 100644 --- a/BizHawk.MultiClient/LuaImplementation.cs +++ b/BizHawk.MultiClient/LuaImplementation.cs @@ -25,6 +25,8 @@ namespace BizHawk.MultiClient private Lua currThread; private LuaFunction savestate_registersavefunc; private LuaFunction savestate_registerloadfunc; + private LuaFunction frame_registerbeforefunc; + private LuaFunction frame_registerafterfunc; public void SavestateRegisterSave(string name) { @@ -60,6 +62,40 @@ namespace BizHawk.MultiClient } } + public void FrameRegisterBefore() + { + if (frame_registerbeforefunc != null) + { + try + { + frame_registerbeforefunc.Call(); + } + catch (SystemException e) + { + Global.MainForm.LuaConsole1.WriteToOutputWindow( + "error running function attached by lua function emu.registerbefore" + + "\nError message: " + e.Message); + } + } + } + + public void FrameRegisterAfter() + { + if (frame_registerafterfunc != null) + { + try + { + frame_registerafterfunc.Call(); + } + catch (SystemException e) + { + Global.MainForm.LuaConsole1.WriteToOutputWindow( + "error running function attached by lua function emu.registerafter" + + "\nError message: " + e.Message); + } + } + } + public LuaImplementation(LuaConsole passed) { LuaWait = new AutoResetEvent(false); @@ -312,7 +348,9 @@ namespace BizHawk.MultiClient "minimizeframeskip", "limitframerate", "displayvsync", - "enablerewind" + "enablerewind", + "registerbefore", + "registerafter", }; public static string[] MemoryFunctions = new string[] @@ -1069,6 +1107,16 @@ namespace BizHawk.MultiClient } } + public void emu_registerbefore(LuaFunction luaf) + { + frame_registerbeforefunc = luaf; + } + + public void emu_registerafter(LuaFunction luaf) + { + frame_registerafterfunc = luaf; + } + //---------------------------------------------------- //Memory library //---------------------------------------------------- diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index 9f809f2df3..dbd3e96e54 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -1898,10 +1898,6 @@ namespace BizHawk.MultiClient if (!fff) { UpdateToolsBefore(); -#if WINDOWS - LuaConsole1.ResumeScripts(true); - Global.DisplayManager.PreFrameUpdateLuaSource(); -#endif } if ((DateTime.Now - runloop_second).TotalSeconds > 1) @@ -2011,6 +2007,11 @@ namespace BizHawk.MultiClient /// public void UpdateToolsBefore() { + LuaConsole1.LuaImp.FrameRegisterBefore(); +#if WINDOWS + LuaConsole1.ResumeScripts(true); + Global.DisplayManager.PreFrameUpdateLuaSource(); +#endif RamWatch1.UpdateValues(); RamSearch1.UpdateValues(); HexEditor1.UpdateValues(); @@ -2027,6 +2028,7 @@ namespace BizHawk.MultiClient { //The other tool updates are earlier, TAStudio needs to be later so it can display the latest //frame of execution in its list view. + LuaConsole1.LuaImp.FrameRegisterAfter(); TAStudio1.UpdateValues(); }