diff --git a/osu.Desktop/OsuGameDesktop.cs b/osu.Desktop/OsuGameDesktop.cs index 4de1e84fbfcb..3aace34ab5c1 100644 --- a/osu.Desktop/OsuGameDesktop.cs +++ b/osu.Desktop/OsuGameDesktop.cs @@ -11,6 +11,7 @@ using Microsoft.Win32; using osu.Desktop.Security; using osu.Desktop.Overlays; +using osu.Desktop.Performance; using osu.Framework.Platform; using osu.Game; using osu.Desktop.Updater; @@ -112,6 +113,8 @@ protected override void LoadComplete() LoadComponentAsync(new DiscordRichPresence(), Add); + LoadComponentAsync(new HighPerformanceSession(), Add); + if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows) LoadComponentAsync(new GameplayWinKeyBlocker(), Add); diff --git a/osu.Desktop/Performance/Gamemode.cs b/osu.Desktop/Performance/Gamemode.cs new file mode 100644 index 000000000000..90a6effa24f1 --- /dev/null +++ b/osu.Desktop/Performance/Gamemode.cs @@ -0,0 +1,45 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Runtime.InteropServices; +using osu.Framework.Logging; + +namespace osu.Desktop.Performance +{ + public static class GamemodeRequest + { + [DllImport("libgamemode.so.0")] + private static extern int real_gamemode_request_start(); + + [DllImport("libgamemode.so.0")] + private static extern int real_gamemode_request_end(); + + public static void RequestStart() + { + try + { + int gamemodeOutput = real_gamemode_request_start(); + + Logger.Log(gamemodeOutput < 0 ? "Gamemode \"Start\" request failed" : "Gamemode \"Start\" request was successfull"); + } + catch + { + Logger.Log("Gamemode is not present on the system"); + } + } + + public static void RequestEnd() + { + try + { + int gamemodeOutput = real_gamemode_request_end(); + + Logger.Log(gamemodeOutput < 0 ? "Gamemode \"End\" request failed" : "Gamemode \"End\" request was successfull"); + } + catch + { + Logger.Log("Gamemode is not present on the system"); + } + } + } +} diff --git a/osu.Desktop/Performance/HighPerformanceSession.cs b/osu.Desktop/Performance/HighPerformanceSession.cs new file mode 100644 index 000000000000..4af165fd2a70 --- /dev/null +++ b/osu.Desktop/Performance/HighPerformanceSession.cs @@ -0,0 +1,41 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Game; +using osu.Game.Configuration; + +namespace osu.Desktop.Performance +{ + public class HighPerformanceSession : Component + { + private Bindable localUserPlaying; + + [BackgroundDependencyLoader] + private void load(OsuGame game, OsuConfigManager config) + { + localUserPlaying = game.LocalUserPlaying.GetBoundCopy(); + localUserPlaying.BindValueChanged(e => onPlayerStateChange(e.NewValue)); + } + + private void onPlayerStateChange(bool state) + { + if (state) + enableHighPerformanceSession(); + else + disableHighPerformanceSession(); + } + + private void enableHighPerformanceSession() + { + GamemodeRequest.RequestStart(); + } + + private void disableHighPerformanceSession() + { + GamemodeRequest.RequestEnd(); + } + } +}