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:
zeromus 2012-03-23 23:03:39 +00:00
parent 216a44e3f0
commit 5f39ba5bbd
4 changed files with 40 additions and 8 deletions

View File

@ -20,7 +20,7 @@ namespace BizHawk.MultiClient
public EventWaitHandle LuaWait; public EventWaitHandle LuaWait;
public bool isRunning; public bool isRunning;
private int CurrentMemoryDomain = 0; //Main memory by default private int CurrentMemoryDomain = 0; //Main memory by default
//List<Lua> runningThreads = new List<Lua>(); public bool FrameAdvanceRequested;
Lua currThread; Lua currThread;
public LuaImplementation(LuaConsole passed) public LuaImplementation(LuaConsole passed)
@ -141,11 +141,20 @@ namespace BizHawk.MultiClient
return lua_result; return lua_result;
} }
public void ResumeScript(Lua script) public class ResumeResult
{
public bool WaitForFrame;
}
public ResumeResult ResumeScript(Lua script)
{ {
currThread = script; currThread = script;
script.Resume(0); script.Resume(0);
currThread = null; currThread = null;
var result = new ResumeResult();
result.WaitForFrame = FrameAdvanceRequested;
FrameAdvanceRequested = false;
return result;
} }
public void print(string s) public void print(string s)
@ -173,6 +182,7 @@ namespace BizHawk.MultiClient
public static string[] EmuFunctions = new string[] public static string[] EmuFunctions = new string[]
{ {
"frameadvance", "frameadvance",
"yield",
"pause", "pause",
"unpause", "unpause",
"togglepause", "togglepause",
@ -339,6 +349,12 @@ namespace BizHawk.MultiClient
//Emu library //Emu library
//---------------------------------------------------- //----------------------------------------------------
public void emu_frameadvance() public void emu_frameadvance()
{
FrameAdvanceRequested = true;
currThread.Yield(0);
}
public void emu_yield()
{ {
currThread.Yield(0); currThread.Yield(0);
} }

View File

@ -372,6 +372,10 @@ namespace BizHawk.MultiClient
Global.AutoFireController.LatchFromPhysical(Global.ControllerInputCoalescer); Global.AutoFireController.LatchFromPhysical(Global.ControllerInputCoalescer);
Global.ClickyVirtualPadController.FrameTick(); Global.ClickyVirtualPadController.FrameTick();
#if WINDOWS
LuaConsole1.ResumeScripts(false);
#endif
StepRunLoop_Core(); StepRunLoop_Core();
//if(!IsNullEmulator()) //if(!IsNullEmulator())
StepRunLoop_Throttle(); StepRunLoop_Throttle();
@ -1682,11 +1686,9 @@ namespace BizHawk.MultiClient
{ {
Global.RenderPanel.ClearGUIText(); Global.RenderPanel.ClearGUIText();
//client input-related duties //client input-related duties
#if WINDOWS #if WINDOWS
//if (LuaConsole1.IsRunning()) LuaConsole1.ResumeScripts(true);
{
LuaConsole1.ResumeScripts();
}
#endif #endif
runloop_fps++; runloop_fps++;

View File

@ -725,12 +725,24 @@ namespace BizHawk.MultiClient
OpenLuaSession(); 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) foreach (var s in luaList)
{ {
if (s.Enabled && s.Thread != null) 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;
}
} }
} }

View File

@ -12,12 +12,14 @@ namespace BizHawk.MultiClient
public bool Enabled; public bool Enabled;
public bool IsSeparator; public bool IsSeparator;
public LuaInterface.Lua Thread; public LuaInterface.Lua Thread;
public bool FrameWaiting;
public LuaFile(string path) public LuaFile(string path)
{ {
Name = ""; Name = "";
Path = path; Path = path;
Enabled = true; Enabled = true;
FrameWaiting = false;
} }
public void Stop() public void Stop()