Make autolocking of ApiHawk surface less aggressive when used via Lua

This commit is contained in:
YoshiRulz 2021-02-22 02:40:17 +10:00
parent d929891c97
commit a8b1e06e44
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 15 additions and 11 deletions

View File

@ -47,6 +47,8 @@ namespace BizHawk.Client.Common
private DisplaySurfaceID? _usingSurfaceID = null;
public bool EnableLuaAutolockHack = false;
public bool HasGUISurface => _GUISurface != null;
public GuiApi(Action<string> logCallback, IDisplayManagerForApi displayManager)
@ -79,12 +81,19 @@ namespace BizHawk.Client.Common
public void SetAttributes(ImageAttributes a) => _attributes = a;
private DisplaySurface GetRelevantSurface(DisplaySurfaceID? surfaceID) => (surfaceID ?? _usingSurfaceID) switch
private DisplaySurface GetRelevantSurface(DisplaySurfaceID? surfaceID)
{
DisplaySurfaceID.EmuCore => _GUISurface,
DisplaySurfaceID.Client => _clientSurface,
_ => throw new Exception()
};
switch (surfaceID ?? _usingSurfaceID)
{
case DisplaySurfaceID.EmuCore:
if (_GUISurface == null && EnableLuaAutolockHack) LockEmuSurfaceLua();
return _GUISurface;
case DisplaySurfaceID.Client:
return _clientSurface;
default:
throw new Exception();
}
}
private void LockSurface(DisplaySurfaceID surfaceID)
{

View File

@ -98,6 +98,7 @@ namespace BizHawk.Client.EmuHawk
{
_luaContainer?.Dispose();
_luaContainer = Register(serviceProvider, logCallback, mainForm, displayManager, inputManager, movieSession, toolManager, config, emulator, game);
((GuiApi) _luaContainer.Gui).EnableLuaAutolockHack = true;
return _luaContainer;
}
}

View File

@ -165,7 +165,6 @@ namespace BizHawk.Client.EmuHawk
{
try
{
GuiAPI.LockEmuSurfaceLua();
foreach (var lf in RegisteredFunctions.Where(l => l.Event == "OnSavestateSave"))
{
lf.Call(name);
@ -183,7 +182,6 @@ namespace BizHawk.Client.EmuHawk
{
try
{
GuiAPI.LockEmuSurfaceLua();
foreach (var lf in RegisteredFunctions.Where(l => l.Event == "OnSavestateLoad"))
{
lf.Call(name);
@ -202,7 +200,6 @@ namespace BizHawk.Client.EmuHawk
if (IsUpdateSupressed) return;
try
{
GuiAPI.LockEmuSurfaceLua();
foreach (var lf in RegisteredFunctions.Where(l => l.Event == "OnFrameStart"))
{
lf.Call();
@ -221,7 +218,6 @@ namespace BizHawk.Client.EmuHawk
if (IsUpdateSupressed) return;
try
{
GuiAPI.LockEmuSurfaceLua();
foreach (var lf in RegisteredFunctions.Where(l => l.Event == "OnFrameEnd"))
{
lf.Call();
@ -237,7 +233,6 @@ namespace BizHawk.Client.EmuHawk
public void CallExitEvent(LuaFile lf)
{
GuiAPI.LockEmuSurfaceLua();
foreach (var exitCallback in RegisteredFunctions.ForFile(lf).ForEvent("OnExit"))
{
exitCallback.Call();
@ -306,7 +301,6 @@ namespace BizHawk.Client.EmuHawk
{
LuaLibraryBase.SetCurrentThread(lf);
GuiAPI.LockEmuSurfaceLua();
var execResult = _currThread.Resume(0);
GuiAPI.UnlockEmuSurfaceLua();