Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add libgamemode support #11996

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions osu.Desktop/HighPerformanceSession/Gamemode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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;
}
}
DavidHusicka marked this conversation as resolved.
Show resolved Hide resolved

public static int RequestEnd()
{
try
{
return real_gamemode_request_end();
}
catch
{
return -1;
}
}
}
}
46 changes: 46 additions & 0 deletions osu.Desktop/HighPerformanceSession/HighPerformanceSession.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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<bool> 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}");
}
}
}
2 changes: 2 additions & 0 deletions osu.Desktop/OsuGameDesktop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down