diff --git a/Ryujinx.Profiler/NPadDebug.cs b/Ryujinx.Profiler/NPadDebug.cs new file mode 100644 index 0000000000..02847c7402 --- /dev/null +++ b/Ryujinx.Profiler/NPadDebug.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Text; +using OpenTK.Input; + +namespace Ryujinx.Profiler +{ + public struct NpadDebugButtons + { + public Key ToggleProfiler; + } + + public class NpadDebug + { + public NpadDebugButtons Buttons; + + private KeyboardState _prevKeyboard; + + public NpadDebug(NpadDebugButtons buttons) + { + Buttons = buttons; + } + + public bool TogglePressed(KeyboardState keyboard) => !keyboard[Buttons.ToggleProfiler] && _prevKeyboard[Buttons.ToggleProfiler]; + + public void SetPrevKeyboardState(KeyboardState keyboard) + { + _prevKeyboard = keyboard; + } + } +} diff --git a/Ryujinx.Profiler/Profile.cs b/Ryujinx.Profiler/Profile.cs index ac980789c2..99a8b34af7 100644 --- a/Ryujinx.Profiler/Profile.cs +++ b/Ryujinx.Profiler/Profile.cs @@ -7,8 +7,9 @@ namespace Ryujinx.Profiler { public static class Profile { - public static float UpdateRate => _settings.UpdateRate; - public static long HistoryLength => _settings.History; + public static float UpdateRate => _settings.UpdateRate; + public static long HistoryLength => _settings.History; + public static NpadDebug Controls => _settings.Controls; private static InternalProfile _profileInstance; private static ProfilerSettings _settings; @@ -27,6 +28,7 @@ namespace Ryujinx.Profiler UpdateRate = (config.UpdateRate <= 0) ? -1 : 1.0f / config.UpdateRate, History = (long)(config.History * PerformanceCounter.TicksPerSecond), MaxLevel = config.MaxLevel, + Controls = config.Controls, }; } diff --git a/Ryujinx.Profiler/ProfilerConfig.jsonc b/Ryujinx.Profiler/ProfilerConfig.jsonc index e716aebd4b..50cf0fb647 100644 --- a/Ryujinx.Profiler/ProfilerConfig.jsonc +++ b/Ryujinx.Profiler/ProfilerConfig.jsonc @@ -1,6 +1,4 @@ { - "$schema": "./_schema.json", - // Enable profiling (Only available on a profiling enabled build) "enabled": true, @@ -8,11 +6,20 @@ "dump_path": "", // Update rate for profiler UI, in hertz. -1 updates every time a frame is issued - "update_rate": 4, + "update_rate": 4.0, // Set how long to keep profiling data in seconds, reduce if profiling is taking too much RAM - "history": 5, + "history": 5.0, // Set the maximum profiling level. Higher values may cause a heavy load on your system but will allow you to profile in more detail - "max_level": 0 + "max_level": 0, + + // Keyboard Controls + // https://github.com/opentk/opentk/blob/master/src/OpenTK/Input/Key.cs + "controls": { + "buttons": { + // Show/Hide the profiler + "toggle_profiler": "F2" + } + } } \ No newline at end of file diff --git a/Ryujinx.Profiler/ProfilerConfiguration.cs b/Ryujinx.Profiler/ProfilerConfiguration.cs index 411bcd3843..7185cfdf08 100644 --- a/Ryujinx.Profiler/ProfilerConfiguration.cs +++ b/Ryujinx.Profiler/ProfilerConfiguration.cs @@ -17,6 +17,8 @@ namespace Ryujinx.Profiler public int MaxLevel { get; private set; } public float History { get; private set; } + public NpadDebug Controls { get; private set; } + /// /// Loads a configuration file from disk /// diff --git a/Ryujinx.Profiler/Settings.cs b/Ryujinx.Profiler/Settings.cs index a3c677d81a..f8db5bb98d 100644 --- a/Ryujinx.Profiler/Settings.cs +++ b/Ryujinx.Profiler/Settings.cs @@ -15,5 +15,8 @@ namespace Ryujinx.Profiler // 19531225 = 5 seconds in ticks public long History { get; set; } = 19531225; + + // Controls + public NpadDebug Controls; } } diff --git a/Ryujinx.Profiler/UI/ProfileWindowManager.cs b/Ryujinx.Profiler/UI/ProfileWindowManager.cs index da6b94253a..3b10ccb582 100644 --- a/Ryujinx.Profiler/UI/ProfileWindowManager.cs +++ b/Ryujinx.Profiler/UI/ProfileWindowManager.cs @@ -1,6 +1,7 @@ using System.Diagnostics; using System.Threading; using OpenTK; +using OpenTK.Input; using Ryujinx.Common; namespace Ryujinx.Profiler.UI @@ -46,6 +47,16 @@ namespace Ryujinx.Profiler.UI _window = null; } + [Conditional("USE_PROFILING")] + public void UpdateKeyInput(KeyboardState keyboard) + { + if (Profile.Controls.TogglePressed(keyboard)) + { + ToggleVisible(); + } + Profile.Controls.SetPrevKeyboardState(keyboard); + } + private void ProfileLoop() { using (_window = new ProfileWindow()) diff --git a/Ryujinx/Ui/GLScreen.cs b/Ryujinx/Ui/GLScreen.cs index 9738d6db09..d07ad89578 100644 --- a/Ryujinx/Ui/GLScreen.cs +++ b/Ryujinx/Ui/GLScreen.cs @@ -152,15 +152,9 @@ namespace Ryujinx if (_keyboard.HasValue) { KeyboardState keyboard = _keyboard.Value; - - #if USE_PROFILING - // Debug - if (Config.NPadDebug.TogglePressed(keyboard)) - { - _profileWindow.ToggleVisible(); - } - Config.NPadDebug.SetPrevKeyboardState(keyboard); - #endif + + // Profiler input, lets the profiler get access to the main windows keyboard state + _profileWindow.UpdateKeyInput(keyboard); // Normal Input currentButton = Configuration.Instance.KeyboardControls.GetButtons(keyboard); diff --git a/Ryujinx/Ui/NPadDebug.cs b/Ryujinx/Ui/NPadDebug.cs deleted file mode 100644 index 415e5035cd..0000000000 --- a/Ryujinx/Ui/NPadDebug.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using OpenTK.Input; - -namespace Ryujinx.Ui -{ - public struct NPadDebugButtons - { - public int ToggleProfiler; - } - - public class NPadDebug - { - public NPadDebugButtons Buttons; - private KeyboardState prevKeyboard; - - public NPadDebug(NPadDebugButtons buttons) - { - Buttons = buttons; - } - - public bool TogglePressed(KeyboardState keyboard) => !keyboard[(Key) Buttons.ToggleProfiler] && prevKeyboard[(Key) Buttons.ToggleProfiler]; - - public void SetPrevKeyboardState(KeyboardState keyboard) - { - prevKeyboard = keyboard; - } - } -}