Lua - move threading code into the frame loops, now emu.frameadvance works per frame not per emulator loop
This commit is contained in:
parent
33ca14a344
commit
41708a8579
|
@ -13,25 +13,25 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
public class LuaImplementation
|
||||
{
|
||||
Lua lua = new Lua();
|
||||
Lua lua = new Lua();
|
||||
LuaConsole Caller;
|
||||
public String LuaLibraryList = "";
|
||||
public EventWaitHandle LuaWait;
|
||||
public bool isRunning;
|
||||
private Thread LuaThread;
|
||||
public EventWaitHandle LuaWait;
|
||||
public bool isRunning;
|
||||
private Thread LuaThread;
|
||||
private int CurrentMemoryDomain = 0; //Main memory by default
|
||||
|
||||
public LuaImplementation(LuaConsole passed)
|
||||
{
|
||||
LuaWait = new AutoResetEvent(false);
|
||||
LuaWait = new AutoResetEvent(false);
|
||||
LuaLibraryList = "";
|
||||
Caller = passed.get();
|
||||
LuaRegister(lua);
|
||||
}
|
||||
public void LuaRegister(Lua lua)
|
||||
{
|
||||
LuaRegister(lua);
|
||||
}
|
||||
public void LuaRegister(Lua lua)
|
||||
{
|
||||
lua.RegisterFunction("print", this, this.GetType().GetMethod("print"));
|
||||
|
||||
|
||||
//Register libraries
|
||||
lua.NewTable("console");
|
||||
for (int i = 0; i < ConsoleFunctions.Length; i++)
|
||||
|
@ -82,29 +82,29 @@ namespace BizHawk.MultiClient
|
|||
LuaLibraryList += "client." + MultiClientFunctions[i] + "\n";
|
||||
}
|
||||
}
|
||||
private void LuaThreadFunction(object File)
|
||||
{
|
||||
string F = File.ToString();
|
||||
isRunning = true;
|
||||
try
|
||||
{
|
||||
lua.DoFile(F);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageBox.Show("Exception caught. " + e.ToString());
|
||||
}
|
||||
isRunning = false;
|
||||
LuaWait.Set();
|
||||
}
|
||||
private void LuaThreadFunction(object File)
|
||||
{
|
||||
string F = File.ToString();
|
||||
isRunning = true;
|
||||
try
|
||||
{
|
||||
lua.DoFile(F);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageBox.Show("Exception caught. " + e.ToString());
|
||||
}
|
||||
isRunning = false;
|
||||
LuaWait.Set();
|
||||
}
|
||||
|
||||
public void DoLuaFile(string File)
|
||||
{
|
||||
LuaThread = new Thread(new ParameterizedThreadStart(LuaThreadFunction));
|
||||
LuaThread.Start(File);
|
||||
LuaThread = new Thread(new ParameterizedThreadStart(LuaThreadFunction));
|
||||
LuaThread.Start(File);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void print(string s)
|
||||
{
|
||||
Caller.AddText(string.Format(s));
|
||||
|
@ -207,8 +207,8 @@ namespace BizHawk.MultiClient
|
|||
//----------------------------------------------------
|
||||
public void emu_frameadvance()
|
||||
{
|
||||
LuaWait.Set();
|
||||
Global.MainForm.MainWait.WaitOne();
|
||||
LuaWait.Set();
|
||||
Global.MainForm.MainWait.WaitOne();
|
||||
}
|
||||
|
||||
public void emu_pause()
|
||||
|
@ -249,7 +249,7 @@ namespace BizHawk.MultiClient
|
|||
//----------------------------------------------------
|
||||
//Memory library
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
public string memory_readbyte(object lua_input)
|
||||
{
|
||||
|
||||
|
@ -319,7 +319,7 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
return Global.GetOutputControllersAsMnemonic();
|
||||
}
|
||||
|
||||
|
||||
public void joypad_set(object lua_input)
|
||||
{
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace BizHawk.MultiClient
|
|||
bool runloop_frameProgress;
|
||||
DateTime FrameAdvanceTimestamp = DateTime.MinValue;
|
||||
public bool EmulatorPaused;
|
||||
public EventWaitHandle MainWait;
|
||||
public EventWaitHandle MainWait;
|
||||
int runloop_fps;
|
||||
int runloop_last_fps;
|
||||
bool runloop_frameadvance;
|
||||
|
@ -68,7 +68,7 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
Global.MovieSession = new MovieSession();
|
||||
Global.MovieSession.Movie = new Movie();
|
||||
MainWait = new AutoResetEvent(false);
|
||||
MainWait = new AutoResetEvent(false);
|
||||
Icon = BizHawk.MultiClient.Properties.Resources.logo;
|
||||
InitializeComponent();
|
||||
Global.Game = GameInfo.GetNullGame();
|
||||
|
@ -332,11 +332,7 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
for (; ; )
|
||||
{
|
||||
//client input-related duties
|
||||
if (LuaConsole1.LuaImp.isRunning)
|
||||
{
|
||||
LuaConsole1.LuaImp.LuaWait.WaitOne();
|
||||
}
|
||||
|
||||
|
||||
Input.Instance.Update();
|
||||
//handle events and dispatch as a hotkey action, or a hotkey button, or an input button
|
||||
|
@ -346,16 +342,13 @@ namespace BizHawk.MultiClient
|
|||
Global.ActiveController.OR_FromLogical(Global.ClickyVirtualPadController);
|
||||
Global.AutoFireController.LatchFromPhysical(Global.ControllerInputCoalescer);
|
||||
Global.ClickyVirtualPadController.FrameTick();
|
||||
|
||||
|
||||
StepRunLoop_Core();
|
||||
//if(!IsNullEmulator())
|
||||
StepRunLoop_Throttle();
|
||||
|
||||
Render();
|
||||
if (LuaConsole1.LuaImp.isRunning)
|
||||
{
|
||||
Global.MainForm.MainWait.Set();
|
||||
}
|
||||
|
||||
CheckMessages();
|
||||
if (exit)
|
||||
break;
|
||||
|
@ -656,8 +649,8 @@ namespace BizHawk.MultiClient
|
|||
genControls.BindMulti("P1 Start", Global.Config.GenesisController[0].Start);
|
||||
Global.GenControls = genControls;
|
||||
|
||||
var agenControls = new AutofireController(Genesis.GenesisController);
|
||||
agbControls.Autofire = true;
|
||||
var agenControls = new AutofireController(Genesis.GenesisController);
|
||||
agbControls.Autofire = true;
|
||||
genControls.BindMulti("P1 Up", Global.Config.GenesisAutoController[0].Up);
|
||||
genControls.BindMulti("P1 Left", Global.Config.GenesisAutoController[0].Left);
|
||||
genControls.BindMulti("P1 Right", Global.Config.GenesisAutoController[0].Right);
|
||||
|
@ -666,8 +659,8 @@ namespace BizHawk.MultiClient
|
|||
genControls.BindMulti("P1 B", Global.Config.GenesisAutoController[0].B);
|
||||
genControls.BindMulti("P1 C", Global.Config.GenesisAutoController[0].C);
|
||||
genControls.BindMulti("P1 Start", Global.Config.GenesisAutoController[0].Start);
|
||||
Global.AutofireGenControls = agenControls;
|
||||
|
||||
Global.AutofireGenControls = agenControls;
|
||||
|
||||
var TI83Controls = new Controller(TI83.TI83Controller);
|
||||
TI83Controls.BindMulti("0", Global.Config.TI83Controller[0]._0);
|
||||
TI83Controls.BindMulti("1", Global.Config.TI83Controller[0]._1);
|
||||
|
@ -1226,9 +1219,9 @@ namespace BizHawk.MultiClient
|
|||
|
||||
private void CloseGame()
|
||||
{
|
||||
if (Global.Config.AutoSavestates && Global.Emulator is NullEmulator == false)
|
||||
SaveState("Auto");
|
||||
if (Global.Emulator.SaveRamModified)
|
||||
if (Global.Config.AutoSavestates && Global.Emulator is NullEmulator == false)
|
||||
SaveState("Auto");
|
||||
if (Global.Emulator.SaveRamModified)
|
||||
SaveRam();
|
||||
Global.Emulator.Dispose();
|
||||
Global.Emulator = new NullEmulator();
|
||||
|
@ -1381,14 +1374,14 @@ namespace BizHawk.MultiClient
|
|||
Global.RenderPanel.AddMessage("Unthrottled: " + unthrottled);
|
||||
break;
|
||||
|
||||
case "Hard Reset":
|
||||
{
|
||||
bool autoSaveState = Global.Config.AutoSavestates;
|
||||
Global.Config.AutoSavestates = false;
|
||||
LoadRom(CurrentlyOpenRom);
|
||||
Global.Config.AutoSavestates = autoSaveState;
|
||||
break;
|
||||
}
|
||||
case "Hard Reset":
|
||||
{
|
||||
bool autoSaveState = Global.Config.AutoSavestates;
|
||||
Global.Config.AutoSavestates = false;
|
||||
LoadRom(CurrentlyOpenRom);
|
||||
Global.Config.AutoSavestates = autoSaveState;
|
||||
break;
|
||||
}
|
||||
|
||||
case "Screenshot":
|
||||
TakeScreenshot();
|
||||
|
@ -1626,6 +1619,17 @@ namespace BizHawk.MultiClient
|
|||
bool genSound = false;
|
||||
if (runFrame)
|
||||
{
|
||||
//client input-related duties
|
||||
if (LuaConsole1.LuaImp.isRunning)
|
||||
{
|
||||
LuaConsole1.LuaImp.LuaWait.WaitOne();
|
||||
}
|
||||
|
||||
if (LuaConsole1.LuaImp.isRunning)
|
||||
{
|
||||
Global.MainForm.MainWait.Set();
|
||||
}
|
||||
|
||||
runloop_fps++;
|
||||
bool ff = Global.ClientControls["Fast Forward"];
|
||||
bool updateFpsString = (runloop_last_ff != ff);
|
||||
|
|
Loading…
Reference in New Issue