mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 17:43:05 +08:00
Make loading asynchronous
This commit is contained in:
parent
a1cf67be62
commit
167e3a3377
@ -1,8 +1,10 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Threading;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Caching;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Replays;
|
using osu.Game.Replays;
|
||||||
@ -19,9 +21,9 @@ namespace osu.Game.Rulesets.Osu.UI
|
|||||||
private BindableBool showCursorPath { get; } = new BindableBool();
|
private BindableBool showCursorPath { get; } = new BindableBool();
|
||||||
private BindableInt displayLength { get; } = new BindableInt();
|
private BindableInt displayLength { get; } = new BindableInt();
|
||||||
|
|
||||||
protected ClickMarkerContainer ClickMarkers = null!;
|
protected ClickMarkerContainer? ClickMarkers;
|
||||||
protected FrameMarkerContainer FrameMarkers = null!;
|
protected FrameMarkerContainer? FrameMarkers;
|
||||||
protected CursorPathContainer CursorPath = null!;
|
protected CursorPathContainer? CursorPath;
|
||||||
|
|
||||||
private readonly Replay replay;
|
private readonly Replay replay;
|
||||||
|
|
||||||
@ -47,42 +49,43 @@ namespace osu.Game.Rulesets.Osu.UI
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
showClickMarkers.BindValueChanged(enabled =>
|
|
||||||
{
|
|
||||||
initialise();
|
|
||||||
ClickMarkers.FadeTo(enabled.NewValue ? 1 : 0);
|
|
||||||
}, true);
|
|
||||||
showFrameMarkers.BindValueChanged(enabled =>
|
|
||||||
{
|
|
||||||
initialise();
|
|
||||||
FrameMarkers.FadeTo(enabled.NewValue ? 1 : 0);
|
|
||||||
}, true);
|
|
||||||
showCursorPath.BindValueChanged(enabled =>
|
|
||||||
{
|
|
||||||
initialise();
|
|
||||||
CursorPath.FadeTo(enabled.NewValue ? 1 : 0);
|
|
||||||
}, true);
|
|
||||||
displayLength.BindValueChanged(_ =>
|
displayLength.BindValueChanged(_ =>
|
||||||
{
|
{
|
||||||
isLoaded = false;
|
// Need to fully reload to make this work.
|
||||||
initialise();
|
loaded.Invalidate();
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool isLoaded;
|
private readonly Cached loaded = new Cached();
|
||||||
|
|
||||||
|
private CancellationTokenSource? generationCancellationSource;
|
||||||
|
|
||||||
|
protected override void Update()
|
||||||
|
{
|
||||||
|
base.Update();
|
||||||
|
|
||||||
|
if (requireDisplay)
|
||||||
|
{
|
||||||
|
initialise();
|
||||||
|
|
||||||
|
if (ClickMarkers != null) ClickMarkers.Alpha = showClickMarkers.Value ? 1 : 0;
|
||||||
|
if (FrameMarkers != null) FrameMarkers.Alpha = showFrameMarkers.Value ? 1 : 0;
|
||||||
|
if (CursorPath != null) CursorPath.Alpha = showCursorPath.Value ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void initialise()
|
private void initialise()
|
||||||
{
|
{
|
||||||
if (!requireDisplay)
|
if (loaded.IsValid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (isLoaded)
|
loaded.Validate();
|
||||||
return;
|
|
||||||
|
|
||||||
isLoaded = true;
|
generationCancellationSource?.Cancel();
|
||||||
|
generationCancellationSource = new CancellationTokenSource();
|
||||||
|
|
||||||
// It's faster to reinitialise the whole drawable stack than use `Clear` on `PooledDrawableWithLifetimeContainer`
|
// It's faster to reinitialise the whole drawable stack than use `Clear` on `PooledDrawableWithLifetimeContainer`
|
||||||
InternalChildren = new Drawable[]
|
var newDrawables = new Drawable[]
|
||||||
{
|
{
|
||||||
CursorPath = new CursorPathContainer(),
|
CursorPath = new CursorPathContainer(),
|
||||||
ClickMarkers = new ClickMarkerContainer(),
|
ClickMarkers = new ClickMarkerContainer(),
|
||||||
@ -92,6 +95,8 @@ namespace osu.Game.Rulesets.Osu.UI
|
|||||||
bool leftHeld = false;
|
bool leftHeld = false;
|
||||||
bool rightHeld = false;
|
bool rightHeld = false;
|
||||||
|
|
||||||
|
// This should probably be async as well, but it's a bit of a pain to debounce and everything.
|
||||||
|
// Let's address concerns when they are raised.
|
||||||
foreach (var frame in replay.Frames)
|
foreach (var frame in replay.Frames)
|
||||||
{
|
{
|
||||||
var osuFrame = (OsuReplayFrame)frame;
|
var osuFrame = (OsuReplayFrame)frame;
|
||||||
@ -118,6 +123,8 @@ namespace osu.Game.Rulesets.Osu.UI
|
|||||||
FrameMarkers.Add(new AnalysisFrameEntry(osuFrame.Time, displayLength.Value, osuFrame.Position, osuFrame.Actions.ToArray()));
|
FrameMarkers.Add(new AnalysisFrameEntry(osuFrame.Time, displayLength.Value, osuFrame.Position, osuFrame.Actions.ToArray()));
|
||||||
CursorPath.Add(new AnalysisFrameEntry(osuFrame.Time, displayLength.Value, osuFrame.Position));
|
CursorPath.Add(new AnalysisFrameEntry(osuFrame.Time, displayLength.Value, osuFrame.Position));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LoadComponentsAsync(newDrawables, drawables => InternalChildrenEnumerable = drawables, generationCancellationSource.Token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,10 +28,10 @@ namespace osu.Game.Rulesets.Osu.UI
|
|||||||
[SettingSource("Display length", SettingControlType = typeof(PlayerSliderBar<int>))]
|
[SettingSource("Display length", SettingControlType = typeof(PlayerSliderBar<int>))]
|
||||||
public BindableInt DisplayLength { get; } = new BindableInt
|
public BindableInt DisplayLength { get; } = new BindableInt
|
||||||
{
|
{
|
||||||
MinValue = 100,
|
MinValue = 200,
|
||||||
Default = 800,
|
|
||||||
MaxValue = 2000,
|
MaxValue = 2000,
|
||||||
Precision = 100,
|
Default = 800,
|
||||||
|
Precision = 200,
|
||||||
};
|
};
|
||||||
|
|
||||||
public ReplayAnalysisSettings(OsuRulesetConfigManager config)
|
public ReplayAnalysisSettings(OsuRulesetConfigManager config)
|
||||||
|
Loading…
Reference in New Issue
Block a user