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 2 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
34 changes: 34 additions & 0 deletions osu.Game/Gamemode/Gamemode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 {
Copy link
Contributor

@Game4all Game4all Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Platform-specific stuff like this shouldn't reside in osu.Game project but rather in osu.Desktop project and use a component that you insert into the drawable hierachy and which listens for value changes of Game.LocalUserPlaying field instead of calling it in PlayerLoader (see the following link for an example https://github.com/ppy/osu/blob/master/osu.Desktop/Windows/GameplayWinKeyBlocker.cs).

Also you may want to add platform checks to add this component only when the host runs linux and should add handling for cases where the DLL isn't locatable (as it'll cause a crash as it is right now when calling the PInvoke methods and the DLL isn't locatable).

(All what is said above assumes of course that support for gamemode is accepted.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will look into moving it to the osu.Desktop project.

It already checks whether the DLL is available on the system. Tried to run without gamemode on and it works without any issues.


[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;
}
}
}
}
6 changes: 6 additions & 0 deletions osu.Game/Screens/Play/PlayerLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()}");
DavidHusicka marked this conversation as resolved.
Show resolved Hide resolved

showMuteWarningIfNeeded();
}

Expand Down Expand Up @@ -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);
}

Expand Down