mirror of
https://github.com/ppy/osu
synced 2024-12-26 00:32:52 +00:00
Merge pull request #27391 from smoogipoo/high-performance-session-redux
Use high performance session during gameplay
This commit is contained in:
commit
2889cf39d7
@ -7,6 +7,7 @@ using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Versioning;
|
||||
using Microsoft.Win32;
|
||||
using osu.Desktop.Performance;
|
||||
using osu.Desktop.Security;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game;
|
||||
@ -15,9 +16,11 @@ using osu.Framework;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Game.Updater;
|
||||
using osu.Desktop.Windows;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.IO;
|
||||
using osu.Game.IPC;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Performance;
|
||||
using osu.Game.Utils;
|
||||
using SDL2;
|
||||
|
||||
@ -28,6 +31,9 @@ namespace osu.Desktop
|
||||
private OsuSchemeLinkIPCChannel? osuSchemeLinkIPCChannel;
|
||||
private ArchiveImportIPCChannel? archiveImportIPCChannel;
|
||||
|
||||
[Cached(typeof(IHighPerformanceSessionManager))]
|
||||
private readonly HighPerformanceSessionManager highPerformanceSessionManager = new HighPerformanceSessionManager();
|
||||
|
||||
public OsuGameDesktop(string[]? args = null)
|
||||
: base(args)
|
||||
{
|
||||
|
43
osu.Desktop/Performance/HighPerformanceSessionManager.cs
Normal file
43
osu.Desktop/Performance/HighPerformanceSessionManager.cs
Normal file
@ -0,0 +1,43 @@
|
||||
// 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;
|
||||
using System.Runtime;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Game.Performance;
|
||||
|
||||
namespace osu.Desktop.Performance
|
||||
{
|
||||
public class HighPerformanceSessionManager : IHighPerformanceSessionManager
|
||||
{
|
||||
private GCLatencyMode originalGCMode;
|
||||
|
||||
public IDisposable BeginSession()
|
||||
{
|
||||
enableHighPerformanceSession();
|
||||
return new InvokeOnDisposal<HighPerformanceSessionManager>(this, static m => m.disableHighPerformanceSession());
|
||||
}
|
||||
|
||||
private void enableHighPerformanceSession()
|
||||
{
|
||||
Logger.Log("Starting high performance session");
|
||||
|
||||
originalGCMode = GCSettings.LatencyMode;
|
||||
GCSettings.LatencyMode = GCLatencyMode.LowLatency;
|
||||
|
||||
// Without doing this, the new GC mode won't kick in until the next GC, which could be at a more noticeable point in time.
|
||||
GC.Collect(0);
|
||||
}
|
||||
|
||||
private void disableHighPerformanceSession()
|
||||
{
|
||||
Logger.Log("Ending high performance session");
|
||||
|
||||
if (GCSettings.LatencyMode == GCLatencyMode.LowLatency)
|
||||
GCSettings.LatencyMode = originalGCMode;
|
||||
|
||||
// No GC.Collect() as we were already collecting at a higher frequency in the old mode.
|
||||
}
|
||||
}
|
||||
}
|
@ -55,7 +55,6 @@ using osu.Game.Overlays.Notifications;
|
||||
using osu.Game.Overlays.SkinEditor;
|
||||
using osu.Game.Overlays.Toolbar;
|
||||
using osu.Game.Overlays.Volume;
|
||||
using osu.Game.Performance;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Screens;
|
||||
@ -792,8 +791,6 @@ namespace osu.Game
|
||||
|
||||
protected virtual UpdateManager CreateUpdateManager() => new UpdateManager();
|
||||
|
||||
protected virtual HighPerformanceSession CreateHighPerformanceSession() => new HighPerformanceSession();
|
||||
|
||||
protected override Container CreateScalingContainer() => new ScalingContainer(ScalingMode.Everything);
|
||||
|
||||
#region Beatmap progression
|
||||
@ -1088,8 +1085,6 @@ namespace osu.Game
|
||||
loadComponentSingleFile(new AccountCreationOverlay(), topMostOverlayContent.Add, true);
|
||||
loadComponentSingleFile<IDialogOverlay>(new DialogOverlay(), topMostOverlayContent.Add, true);
|
||||
|
||||
loadComponentSingleFile(CreateHighPerformanceSession(), Add);
|
||||
|
||||
loadComponentSingleFile(new BackgroundDataStoreProcessor(), Add);
|
||||
|
||||
Add(difficultyRecommender);
|
||||
|
@ -1,42 +0,0 @@
|
||||
// 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.Game.Screens.Play;
|
||||
|
||||
namespace osu.Game.Performance
|
||||
{
|
||||
public partial class HighPerformanceSession : Component
|
||||
{
|
||||
private readonly IBindable<bool> localUserPlaying = new Bindable<bool>();
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(ILocalUserPlayInfo localUserInfo)
|
||||
{
|
||||
localUserPlaying.BindTo(localUserInfo.IsPlaying);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
localUserPlaying.BindValueChanged(playing =>
|
||||
{
|
||||
if (playing.NewValue)
|
||||
EnableHighPerformanceSession();
|
||||
else
|
||||
DisableHighPerformanceSession();
|
||||
}, true);
|
||||
}
|
||||
|
||||
protected virtual void EnableHighPerformanceSession()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void DisableHighPerformanceSession()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
23
osu.Game/Performance/IHighPerformanceSessionManager.cs
Normal file
23
osu.Game/Performance/IHighPerformanceSessionManager.cs
Normal file
@ -0,0 +1,23 @@
|
||||
// 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;
|
||||
|
||||
namespace osu.Game.Performance
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows creating a temporary "high performance" session, with the goal of optimising runtime
|
||||
/// performance for gameplay purposes.
|
||||
///
|
||||
/// On desktop platforms, this will set a low latency GC mode which collects more frequently to avoid
|
||||
/// GC spikes.
|
||||
/// </summary>
|
||||
public interface IHighPerformanceSessionManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Start a new high performance session.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="IDisposable"/> which will end the session when disposed.</returns>
|
||||
IDisposable BeginSession();
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@ using osu.Game.Input;
|
||||
using osu.Game.Localisation;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using osu.Game.Performance;
|
||||
using osu.Game.Screens.Menu;
|
||||
using osu.Game.Screens.Play.PlayerSettings;
|
||||
using osu.Game.Skinning;
|
||||
@ -140,6 +141,8 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
private bool quickRestart;
|
||||
|
||||
private IDisposable? highPerformanceSession;
|
||||
|
||||
[Resolved]
|
||||
private INotificationOverlay? notificationOverlay { get; set; }
|
||||
|
||||
@ -152,6 +155,9 @@ namespace osu.Game.Screens.Play
|
||||
[Resolved]
|
||||
private BatteryInfo? batteryInfo { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private IHighPerformanceSessionManager? highPerformanceSessionManager { get; set; }
|
||||
|
||||
public PlayerLoader(Func<Player> createPlayer)
|
||||
{
|
||||
this.createPlayer = createPlayer;
|
||||
@ -262,6 +268,9 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
Debug.Assert(CurrentPlayer != null);
|
||||
|
||||
highPerformanceSession?.Dispose();
|
||||
highPerformanceSession = null;
|
||||
|
||||
// prepare for a retry.
|
||||
CurrentPlayer = null;
|
||||
playerConsumed = false;
|
||||
@ -303,6 +312,9 @@ namespace osu.Game.Screens.Play
|
||||
BackgroundBrightnessReduction = false;
|
||||
Beatmap.Value.Track.RemoveAdjustment(AdjustableProperty.Volume, volumeAdjustment);
|
||||
|
||||
highPerformanceSession?.Dispose();
|
||||
highPerformanceSession = null;
|
||||
|
||||
return base.OnExiting(e);
|
||||
}
|
||||
|
||||
@ -478,6 +490,10 @@ namespace osu.Game.Screens.Play
|
||||
if (scheduledPushPlayer != null)
|
||||
return;
|
||||
|
||||
// Now that everything's been loaded, we can safely switch to a higher performance session without incurring too much overhead.
|
||||
// Doing this prior to the game being pushed gives us a bit of time to stabilise into the high performance mode before gameplay starts.
|
||||
highPerformanceSession ??= highPerformanceSessionManager?.BeginSession();
|
||||
|
||||
scheduledPushPlayer = Scheduler.AddDelayed(() =>
|
||||
{
|
||||
// ensure that once we have reached this "point of no return", readyForPush will be false for all future checks (until a new player instance is prepared).
|
||||
|
Loading…
Reference in New Issue
Block a user