Adjust API of HighPerformanceSession + rename

This commit is contained in:
Dan Balasescu 2024-02-26 22:12:04 +09:00
parent 09b420a083
commit 3e9425fdf2
No known key found for this signature in database
3 changed files with 36 additions and 44 deletions

View File

@ -792,7 +792,7 @@ public override Task Import(ImportTask[] imports, ImportParameters parameters =
protected virtual UpdateManager CreateUpdateManager() => new UpdateManager();
protected virtual HighPerformanceSession CreateHighPerformanceSession() => new HighPerformanceSession();
protected virtual HighPerformanceSessionManager CreateHighPerformanceSessionManager() => new HighPerformanceSessionManager();
protected override Container CreateScalingContainer() => new ScalingContainer(ScalingMode.Everything);
@ -1088,7 +1088,7 @@ protected override void LoadComplete()
loadComponentSingleFile(new AccountCreationOverlay(), topMostOverlayContent.Add, true);
loadComponentSingleFile<IDialogOverlay>(new DialogOverlay(), topMostOverlayContent.Add, true);
loadComponentSingleFile(CreateHighPerformanceSession(), Add);
loadComponentSingleFile(CreateHighPerformanceSessionManager(), Add, true);
loadComponentSingleFile(new BackgroundDataStoreProcessor(), Add);

View File

@ -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()
{
}
}
}

View File

@ -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;
using System.Runtime;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
namespace osu.Game.Performance
{
public partial class HighPerformanceSessionManager : Component
{
private GCLatencyMode originalGCMode;
public IDisposable BeginSession()
{
EnableHighPerformanceSession();
return new InvokeOnDisposal<HighPerformanceSessionManager>(this, static m => m.DisableHighPerformanceSession());
}
protected virtual void EnableHighPerformanceSession()
{
originalGCMode = GCSettings.LatencyMode;
GCSettings.LatencyMode = GCLatencyMode.LowLatency;
GC.Collect(0);
}
protected virtual void DisableHighPerformanceSession()
{
if (GCSettings.LatencyMode == GCLatencyMode.LowLatency)
GCSettings.LatencyMode = originalGCMode;
}
}
}