Added Frameadvance with threading. Can't test, because CueFromPath is broken.

This commit is contained in:
kylethomson 2012-01-22 23:44:53 +00:00
parent abf0698e43
commit 16ec704e41
3 changed files with 32 additions and 7 deletions

View File

@ -6,6 +6,8 @@ using System.IO;
using LuaInterface; using LuaInterface;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.MultiClient.tools; using BizHawk.MultiClient.tools;
using System.Threading;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
@ -14,10 +16,14 @@ namespace BizHawk.MultiClient
Lua lua = new Lua(); Lua lua = new Lua();
LuaConsole Caller; LuaConsole Caller;
public String LuaLibraryList = ""; public String LuaLibraryList = "";
public EventWaitHandle LuaWait;
public bool isRunning;
private Thread LuaThread;
private int CurrentMemoryDomain = 0; //Main memory by default private int CurrentMemoryDomain = 0; //Main memory by default
public LuaImplementation(LuaConsole passed) public LuaImplementation(LuaConsole passed)
{ {
EventWaitHandle LuaWait = new AutoResetEvent(false);
LuaLibraryList = ""; LuaLibraryList = "";
Caller = passed.get(); Caller = passed.get();
lua.RegisterFunction("print", this, this.GetType().GetMethod("print")); lua.RegisterFunction("print", this, this.GetType().GetMethod("print"));
@ -72,12 +78,22 @@ namespace BizHawk.MultiClient
LuaLibraryList += "client." + MultiClientFunctions[i] + "\n"; LuaLibraryList += "client." + MultiClientFunctions[i] + "\n";
} }
} }
private void LuaThreadFunction(object File)
{
string F = File.ToString();
isRunning = true;
lua.DoFile(F);
isRunning = false;
LuaWait.Set();
}
public void DoLuaFile(string File) public void DoLuaFile(string File)
{ {
lua.DoFile(File); LuaThread = new Thread(new ParameterizedThreadStart(LuaThreadFunction));
LuaThread.Start(File);
} }
public void print(string s) public void print(string s)
{ {
Caller.AddText(string.Format(s)); Caller.AddText(string.Format(s));
@ -180,8 +196,8 @@ namespace BizHawk.MultiClient
//---------------------------------------------------- //----------------------------------------------------
public void emu_frameadvance() public void emu_frameadvance()
{ {
//Global.MainForm.PressFrameAdvance = true; LuaWait.Set();
//Global.Emulator.FrameAdvance(true); Global.MainForm.MainWait.WaitOne();
} }
public void emu_pause() public void emu_pause()

View File

@ -37,6 +37,7 @@ namespace BizHawk.MultiClient
bool runloop_frameProgress; bool runloop_frameProgress;
DateTime FrameAdvanceTimestamp = DateTime.MinValue; DateTime FrameAdvanceTimestamp = DateTime.MinValue;
public bool EmulatorPaused; public bool EmulatorPaused;
public EventWaitHandle MainWait;
int runloop_fps; int runloop_fps;
int runloop_last_fps; int runloop_last_fps;
bool runloop_frameadvance; bool runloop_frameadvance;
@ -67,6 +68,7 @@ namespace BizHawk.MultiClient
{ {
Global.MovieSession = new MovieSession(); Global.MovieSession = new MovieSession();
Global.MovieSession.Movie = new Movie(); Global.MovieSession.Movie = new Movie();
MainWait = new AutoResetEvent(false)
Icon = BizHawk.MultiClient.Properties.Resources.logo; Icon = BizHawk.MultiClient.Properties.Resources.logo;
InitializeComponent(); InitializeComponent();
Global.Game = GameInfo.GetNullGame(); Global.Game = GameInfo.GetNullGame();
@ -331,6 +333,8 @@ namespace BizHawk.MultiClient
for (; ; ) for (; ; )
{ {
//client input-related duties //client input-related duties
Input.Instance.Update(); Input.Instance.Update();
//handle events and dispatch as a hotkey action, or a hotkey button, or an input button //handle events and dispatch as a hotkey action, or a hotkey button, or an input button
ProcessInput(); ProcessInput();
@ -339,14 +343,19 @@ namespace BizHawk.MultiClient
Global.ActiveController.OR_FromLogical(Global.ClickyVirtualPadController); Global.ActiveController.OR_FromLogical(Global.ClickyVirtualPadController);
Global.AutoFireController.LatchFromPhysical(Global.ControllerInputCoalescer); Global.AutoFireController.LatchFromPhysical(Global.ControllerInputCoalescer);
Global.ClickyVirtualPadController.FrameTick(); Global.ClickyVirtualPadController.FrameTick();
if (LuaConsole1.LuaImp.isRunning)
{
LuaConsole1.LuaImp.LuaWait.WaitOne();
}
StepRunLoop_Core(); StepRunLoop_Core();
//if(!IsNullEmulator()) //if(!IsNullEmulator())
StepRunLoop_Throttle(); StepRunLoop_Throttle();
Render(); Render();
if (LuaConsole1.LuaImp.isRunning)
{
MainForm.MainWait.Set();
}
CheckMessages(); CheckMessages();
if (exit) if (exit)
break; break;

View File

@ -162,7 +162,7 @@ namespace BizHawk.MultiClient
luaList.Add(l); luaList.Add(l);
LuaListView.ItemCount = luaList.Count; LuaListView.ItemCount = luaList.Count;
LuaListView.Refresh(); LuaListView.Refresh();
Global.Config.RecentLua.Add(path); Global.Config.RecentLua.Add(path);
LuaImp.DoLuaFile(path); LuaImp.DoLuaFile(path);
} }