add emu.yield, which when used allows a script to run while emulation is paused and interact with the gui/main window in realtime
This commit is contained in:
parent
216a44e3f0
commit
5f39ba5bbd
|
@ -20,7 +20,7 @@ namespace BizHawk.MultiClient
|
|||
public EventWaitHandle LuaWait;
|
||||
public bool isRunning;
|
||||
private int CurrentMemoryDomain = 0; //Main memory by default
|
||||
//List<Lua> runningThreads = new List<Lua>();
|
||||
public bool FrameAdvanceRequested;
|
||||
Lua currThread;
|
||||
|
||||
public LuaImplementation(LuaConsole passed)
|
||||
|
@ -141,11 +141,20 @@ namespace BizHawk.MultiClient
|
|||
return lua_result;
|
||||
}
|
||||
|
||||
public void ResumeScript(Lua script)
|
||||
public class ResumeResult
|
||||
{
|
||||
public bool WaitForFrame;
|
||||
}
|
||||
|
||||
public ResumeResult ResumeScript(Lua script)
|
||||
{
|
||||
currThread = script;
|
||||
script.Resume(0);
|
||||
currThread = null;
|
||||
var result = new ResumeResult();
|
||||
result.WaitForFrame = FrameAdvanceRequested;
|
||||
FrameAdvanceRequested = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
public void print(string s)
|
||||
|
@ -173,6 +182,7 @@ namespace BizHawk.MultiClient
|
|||
public static string[] EmuFunctions = new string[]
|
||||
{
|
||||
"frameadvance",
|
||||
"yield",
|
||||
"pause",
|
||||
"unpause",
|
||||
"togglepause",
|
||||
|
@ -339,6 +349,12 @@ namespace BizHawk.MultiClient
|
|||
//Emu library
|
||||
//----------------------------------------------------
|
||||
public void emu_frameadvance()
|
||||
{
|
||||
FrameAdvanceRequested = true;
|
||||
currThread.Yield(0);
|
||||
}
|
||||
|
||||
public void emu_yield()
|
||||
{
|
||||
currThread.Yield(0);
|
||||
}
|
||||
|
|
|
@ -372,6 +372,10 @@ namespace BizHawk.MultiClient
|
|||
Global.AutoFireController.LatchFromPhysical(Global.ControllerInputCoalescer);
|
||||
Global.ClickyVirtualPadController.FrameTick();
|
||||
|
||||
#if WINDOWS
|
||||
LuaConsole1.ResumeScripts(false);
|
||||
#endif
|
||||
|
||||
StepRunLoop_Core();
|
||||
//if(!IsNullEmulator())
|
||||
StepRunLoop_Throttle();
|
||||
|
@ -1682,11 +1686,9 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
Global.RenderPanel.ClearGUIText();
|
||||
//client input-related duties
|
||||
|
||||
#if WINDOWS
|
||||
//if (LuaConsole1.IsRunning())
|
||||
{
|
||||
LuaConsole1.ResumeScripts();
|
||||
}
|
||||
LuaConsole1.ResumeScripts(true);
|
||||
#endif
|
||||
|
||||
runloop_fps++;
|
||||
|
|
|
@ -725,12 +725,24 @@ namespace BizHawk.MultiClient
|
|||
OpenLuaSession();
|
||||
}
|
||||
|
||||
public void ResumeScripts()
|
||||
/// <summary>
|
||||
/// resumes suspended coroutines
|
||||
/// </summary>
|
||||
/// <param name="includeFrameWaiters">should frame waiters be waken up? only use this immediately before a frame of emulation</param>
|
||||
public void ResumeScripts(bool includeFrameWaiters)
|
||||
{
|
||||
foreach (var s in luaList)
|
||||
{
|
||||
if (s.Enabled && s.Thread != null)
|
||||
LuaImp.ResumeScript(s.Thread);
|
||||
{
|
||||
bool prohibit = false;
|
||||
if (s.FrameWaiting && !includeFrameWaiters)
|
||||
prohibit = true;
|
||||
|
||||
if (prohibit) continue;
|
||||
var result = LuaImp.ResumeScript(s.Thread);
|
||||
s.FrameWaiting = result.WaitForFrame;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,12 +12,14 @@ namespace BizHawk.MultiClient
|
|||
public bool Enabled;
|
||||
public bool IsSeparator;
|
||||
public LuaInterface.Lua Thread;
|
||||
public bool FrameWaiting;
|
||||
|
||||
public LuaFile(string path)
|
||||
{
|
||||
Name = "";
|
||||
Path = path;
|
||||
Enabled = true;
|
||||
FrameWaiting = false;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
|
|
Loading…
Reference in New Issue