Use high performance session during gameplay

This commit is contained in:
Dan Balasescu 2024-02-26 22:13:15 +09:00
parent 3e9425fdf2
commit bfb5098238
No known key found for this signature in database
2 changed files with 20 additions and 0 deletions

View File

@ -22,6 +22,8 @@ namespace osu.Game.Performance
{
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);
}
@ -29,6 +31,8 @@ namespace osu.Game.Performance
{
if (GCSettings.LatencyMode == GCLatencyMode.LowLatency)
GCSettings.LatencyMode = originalGCMode;
// No GC.Collect() as we were already collecting at a higher frequency in the old mode.
}
}
}

View File

@ -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 HighPerformanceSessionManager? highPerformanceSessionManager { get; set; }
public PlayerLoader(Func<Player> createPlayer)
{
this.createPlayer = createPlayer;
@ -264,6 +270,9 @@ namespace osu.Game.Screens.Play
Debug.Assert(CurrentPlayer != null);
highPerformanceSession?.Dispose();
highPerformanceSession = null;
// prepare for a retry.
CurrentPlayer = null;
playerConsumed = false;
@ -304,6 +313,9 @@ namespace osu.Game.Screens.Play
BackgroundBrightnessReduction = false;
Beatmap.Value.Track.RemoveAdjustment(AdjustableProperty.Volume, volumeAdjustment);
highPerformanceSession?.Dispose();
highPerformanceSession = null;
return base.OnExiting(e);
}
@ -463,6 +475,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).