From 98ee0d446f046fc2361ea20c7041310acec2d353 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sun, 19 Sep 2021 01:50:03 +1000 Subject: [PATCH] Add IEmuClientApi method (+Lua) for getting approximate framerate --- src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs | 2 ++ src/BizHawk.Client.Common/Api/Interfaces/IEmuClientApi.cs | 3 +++ src/BizHawk.Client.Common/IMainFormForApi.cs | 3 +++ src/BizHawk.Client.Common/lua/CommonLibs/ClientLuaLibrary.cs | 4 ++++ src/BizHawk.Client.EmuHawk/MainForm.cs | 2 ++ 5 files changed, 14 insertions(+) diff --git a/src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs b/src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs index f0f55349b9..15ce16cdc7 100644 --- a/src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs +++ b/src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs @@ -89,6 +89,8 @@ namespace BizHawk.Client.Common _mainForm.FrameSkipMessage(); } + public int GetApproxFramerate() => _mainForm.GetApproxFramerate(); + public bool GetSoundOn() => _config.SoundEnabled; public int GetTargetScanlineIntensity() => _config.TargetScanlineFilterIntensity; diff --git a/src/BizHawk.Client.Common/Api/Interfaces/IEmuClientApi.cs b/src/BizHawk.Client.Common/Api/Interfaces/IEmuClientApi.cs index e6eed73a14..91c6466299 100644 --- a/src/BizHawk.Client.Common/Api/Interfaces/IEmuClientApi.cs +++ b/src/BizHawk.Client.Common/Api/Interfaces/IEmuClientApi.cs @@ -63,6 +63,9 @@ namespace BizHawk.Client.Common void FrameSkip(int numFrames); + /// the (host) framerate, approximated from frame durations + int GetApproxFramerate(); + bool GetSoundOn(); int GetTargetScanlineIntensity(); diff --git a/src/BizHawk.Client.Common/IMainFormForApi.cs b/src/BizHawk.Client.Common/IMainFormForApi.cs index bd364742d8..366058543a 100644 --- a/src/BizHawk.Client.Common/IMainFormForApi.cs +++ b/src/BizHawk.Client.Common/IMainFormForApi.cs @@ -59,6 +59,9 @@ namespace BizHawk.Client.Common void FrameSkipMessage(); + /// only referenced from + int GetApproxFramerate(); + /// only referenced from void LoadQuickSave(string quickSlotName, bool suppressOSD = false); diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/ClientLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/ClientLuaLibrary.cs index 50d737100d..dc08909f8e 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/ClientLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/ClientLuaLibrary.cs @@ -112,6 +112,10 @@ namespace BizHawk.Client.Common } } + [LuaMethodExample("local sounds_terrible = client.get_approx_framerate() < 55;")] + [LuaMethod("get_approx_framerate", "Gets the (host) framerate, approximated from frame durations.")] + public int GetApproxFramerate() => APIs.EmuClient.GetApproxFramerate(); + [LuaMethodExample("local incliget = client.gettargetscanlineintensity( );")] [LuaMethod("gettargetscanlineintensity", "Gets the current scanline intensity setting, used for the scanline display filter")] public int GetTargetScanlineIntensity() => APIs.EmuClient.GetTargetScanlineIntensity(); diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index a8a2636145..f2db538178 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -1608,6 +1608,8 @@ namespace BizHawk.Client.EmuHawk private int _framesSinceLastFpsUpdate; private long _timestampLastFpsUpdate; + public int GetApproxFramerate() => _lastFpsRounded; + private readonly Throttle _throttle; private bool _unthrottled;