From 0c9a1d64c047a4eb232d6e1473dfb8c5274981af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Husi=C4=8Dka?= Date: Wed, 10 Mar 2021 16:27:39 +0100 Subject: [PATCH 1/4] Implemented support for Gamemode --- osu.Game/Gamemode/Gamemode.cs | 34 +++++++++++++++++++++++++++ osu.Game/Screens/Play/PlayerLoader.cs | 6 +++++ 2 files changed, 40 insertions(+) create mode 100644 osu.Game/Gamemode/Gamemode.cs diff --git a/osu.Game/Gamemode/Gamemode.cs b/osu.Game/Gamemode/Gamemode.cs new file mode 100644 index 000000000000..43a7c7d18ce8 --- /dev/null +++ b/osu.Game/Gamemode/Gamemode.cs @@ -0,0 +1,34 @@ +// 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; + +namespace Gamemode +{ + public static class GamemodeRequest { + + [DllImport("libgamemode.so.0")] + public static extern int real_gamemode_request_start(); + + [DllImport("libgamemode.so.0")] + public static extern int real_gamemode_request_end(); + + public static int RequestStart() + { + try { + return real_gamemode_request_start(); + } catch { + return -1; + } + } + + public static int RequestEnd() + { + try { + return real_gamemode_request_end(); + } catch { + return -1; + } + } + } +} diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 7d906cdc5b81..89f154a8dea6 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -4,10 +4,12 @@ using System; using System.Diagnostics; using System.Threading.Tasks; +using Gamemode; using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Bindables; +using osu.Framework.Logging; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; @@ -195,6 +197,8 @@ public override void OnEntering(IScreen last) // this will continue to execute even after resuming back on restart. Scheduler.Add(new ScheduledDelegate(pushWhenLoaded, Clock.CurrentTime + 1800, 0)); + Logger.Log($"Gamemode \"Start\" request exited with code {GamemodeRequest.RequestStart()}"); + showMuteWarningIfNeeded(); } @@ -234,6 +238,8 @@ public override bool OnExiting(IScreen next) BackgroundBrightnessReduction = false; Beatmap.Value.Track.RemoveAdjustment(AdjustableProperty.Volume, volumeAdjustment); + Logger.Log($"Gamemode \"End\" request exited with code {GamemodeRequest.RequestEnd()}"); + return base.OnExiting(next); } From d429333db89acc3fbc3c2a26233bd2689ec2fe94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Husi=C4=8Dka?= Date: Wed, 10 Mar 2021 16:32:11 +0100 Subject: [PATCH 2/4] Made internal functions private --- osu.Game/Gamemode/Gamemode.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Gamemode/Gamemode.cs b/osu.Game/Gamemode/Gamemode.cs index 43a7c7d18ce8..cb422fc2d584 100644 --- a/osu.Game/Gamemode/Gamemode.cs +++ b/osu.Game/Gamemode/Gamemode.cs @@ -8,10 +8,10 @@ namespace Gamemode public static class GamemodeRequest { [DllImport("libgamemode.so.0")] - public static extern int real_gamemode_request_start(); + private static extern int real_gamemode_request_start(); [DllImport("libgamemode.so.0")] - public static extern int real_gamemode_request_end(); + private static extern int real_gamemode_request_end(); public static int RequestStart() { From c319b71e84ef934a4b645576e3a9ca2f04131f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Husi=C4=8Dka?= Date: Thu, 11 Mar 2021 17:26:34 +0100 Subject: [PATCH 3/4] Made gamemode a component --- .../HighPerformanceSession}/Gamemode.cs | 17 +++++-- .../HighPerformanceSession.cs | 46 +++++++++++++++++++ osu.Desktop/OsuGameDesktop.cs | 2 + osu.Game/Screens/Play/PlayerLoader.cs | 6 --- 4 files changed, 60 insertions(+), 11 deletions(-) rename {osu.Game/Gamemode => osu.Desktop/HighPerformanceSession}/Gamemode.cs (78%) create mode 100644 osu.Desktop/HighPerformanceSession/HighPerformanceSession.cs diff --git a/osu.Game/Gamemode/Gamemode.cs b/osu.Desktop/HighPerformanceSession/Gamemode.cs similarity index 78% rename from osu.Game/Gamemode/Gamemode.cs rename to osu.Desktop/HighPerformanceSession/Gamemode.cs index cb422fc2d584..8020bf10de43 100644 --- a/osu.Game/Gamemode/Gamemode.cs +++ b/osu.Desktop/HighPerformanceSession/Gamemode.cs @@ -5,7 +5,8 @@ namespace Gamemode { - public static class GamemodeRequest { + public static class GamemodeRequest + { [DllImport("libgamemode.so.0")] private static extern int real_gamemode_request_start(); @@ -15,18 +16,24 @@ public static class GamemodeRequest { public static int RequestStart() { - try { + try + { return real_gamemode_request_start(); - } catch { + } + catch + { return -1; } } public static int RequestEnd() { - try { + try + { return real_gamemode_request_end(); - } catch { + } + catch + { return -1; } } diff --git a/osu.Desktop/HighPerformanceSession/HighPerformanceSession.cs b/osu.Desktop/HighPerformanceSession/HighPerformanceSession.cs new file mode 100644 index 000000000000..8bf26792a512 --- /dev/null +++ b/osu.Desktop/HighPerformanceSession/HighPerformanceSession.cs @@ -0,0 +1,46 @@ +// 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.Framework.Logging; +using osu.Game; +using osu.Game.Configuration; +using Gamemode; + +namespace osu.Desktop +{ + 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() + { + int gamemodeRequestResult = GamemodeRequest.RequestStart(); + Logger.Log($"Gamemode \"Start\" request exited with code {gamemodeRequestResult}"); + } + + private void disableHighPerformanceSession() + { + int gamemodeRequestResult = GamemodeRequest.RequestEnd(); + Logger.Log($"Gamemode \"End\" request exited with code {gamemodeRequestResult}"); + } + } +} \ No newline at end of file diff --git a/osu.Desktop/OsuGameDesktop.cs b/osu.Desktop/OsuGameDesktop.cs index 5909b82c8f66..2b8fe1e603df 100644 --- a/osu.Desktop/OsuGameDesktop.cs +++ b/osu.Desktop/OsuGameDesktop.cs @@ -109,6 +109,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.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 89f154a8dea6..7d906cdc5b81 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -4,12 +4,10 @@ using System; using System.Diagnostics; using System.Threading.Tasks; -using Gamemode; using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Bindables; -using osu.Framework.Logging; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; @@ -197,8 +195,6 @@ public override void OnEntering(IScreen last) // this will continue to execute even after resuming back on restart. Scheduler.Add(new ScheduledDelegate(pushWhenLoaded, Clock.CurrentTime + 1800, 0)); - Logger.Log($"Gamemode \"Start\" request exited with code {GamemodeRequest.RequestStart()}"); - showMuteWarningIfNeeded(); } @@ -238,8 +234,6 @@ public override bool OnExiting(IScreen next) BackgroundBrightnessReduction = false; Beatmap.Value.Track.RemoveAdjustment(AdjustableProperty.Volume, volumeAdjustment); - Logger.Log($"Gamemode \"End\" request exited with code {GamemodeRequest.RequestEnd()}"); - return base.OnExiting(next); } From ae713251abfc6a07a8e488f7bbc1d0f360a279c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Husi=C4=8Dka?= Date: Tue, 16 Mar 2021 09:53:26 +0100 Subject: [PATCH 4/4] Improved code quality --- .../HighPerformanceSession/Gamemode.cs | 41 ----------------- osu.Desktop/OsuGameDesktop.cs | 1 + osu.Desktop/Performance/Gamemode.cs | 45 +++++++++++++++++++ .../HighPerformanceSession.cs | 13 ++---- 4 files changed, 50 insertions(+), 50 deletions(-) delete mode 100644 osu.Desktop/HighPerformanceSession/Gamemode.cs create mode 100644 osu.Desktop/Performance/Gamemode.cs rename osu.Desktop/{HighPerformanceSession => Performance}/HighPerformanceSession.cs (72%) diff --git a/osu.Desktop/HighPerformanceSession/Gamemode.cs b/osu.Desktop/HighPerformanceSession/Gamemode.cs deleted file mode 100644 index 8020bf10de43..000000000000 --- a/osu.Desktop/HighPerformanceSession/Gamemode.cs +++ /dev/null @@ -1,41 +0,0 @@ -// 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; - -namespace Gamemode -{ - 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 int RequestStart() - { - try - { - return real_gamemode_request_start(); - } - catch - { - return -1; - } - } - - public static int RequestEnd() - { - try - { - return real_gamemode_request_end(); - } - catch - { - return -1; - } - } - } -} diff --git a/osu.Desktop/OsuGameDesktop.cs b/osu.Desktop/OsuGameDesktop.cs index 2b8fe1e603df..12fc779ffb3c 100644 --- a/osu.Desktop/OsuGameDesktop.cs +++ b/osu.Desktop/OsuGameDesktop.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Microsoft.Win32; using osu.Desktop.Overlays; +using osu.Desktop.Performance; using osu.Framework.Platform; using osu.Game; using osu.Desktop.Updater; 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/HighPerformanceSession/HighPerformanceSession.cs b/osu.Desktop/Performance/HighPerformanceSession.cs similarity index 72% rename from osu.Desktop/HighPerformanceSession/HighPerformanceSession.cs rename to osu.Desktop/Performance/HighPerformanceSession.cs index 8bf26792a512..4af165fd2a70 100644 --- a/osu.Desktop/HighPerformanceSession/HighPerformanceSession.cs +++ b/osu.Desktop/Performance/HighPerformanceSession.cs @@ -4,16 +4,13 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; -using osu.Framework.Logging; using osu.Game; using osu.Game.Configuration; -using Gamemode; -namespace osu.Desktop +namespace osu.Desktop.Performance { public class HighPerformanceSession : Component { - private Bindable localUserPlaying; [BackgroundDependencyLoader] @@ -33,14 +30,12 @@ private void onPlayerStateChange(bool state) private void enableHighPerformanceSession() { - int gamemodeRequestResult = GamemodeRequest.RequestStart(); - Logger.Log($"Gamemode \"Start\" request exited with code {gamemodeRequestResult}"); + GamemodeRequest.RequestStart(); } private void disableHighPerformanceSession() { - int gamemodeRequestResult = GamemodeRequest.RequestEnd(); - Logger.Log($"Gamemode \"End\" request exited with code {gamemodeRequestResult}"); + GamemodeRequest.RequestEnd(); } } -} \ No newline at end of file +}