mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 16:27:26 +08:00
Revert "Abstractify PP counter logic from the "Triangles" implementation"
This reverts commit daf4a03fd0
.
This commit is contained in:
parent
58a830fc5b
commit
a23dfbeab5
@ -1,186 +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.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Difficulty;
|
||||
using osu.Game.Rulesets.Judgements;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Skinning;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
public abstract partial class GameplayPerformancePointsCounter : RollingCounter<int>
|
||||
{
|
||||
protected override bool IsRollingProportional => true;
|
||||
|
||||
protected override double RollingDuration => 1000;
|
||||
|
||||
private const float alpha_when_invalid = 0.3f;
|
||||
|
||||
[Resolved]
|
||||
private ScoreProcessor scoreProcessor { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private GameplayState gameplayState { get; set; }
|
||||
|
||||
[CanBeNull]
|
||||
private List<TimedDifficultyAttributes> timedAttributes;
|
||||
|
||||
private readonly CancellationTokenSource loadCancellationSource = new CancellationTokenSource();
|
||||
|
||||
private JudgementResult lastJudgement;
|
||||
private PerformanceCalculator performanceCalculator;
|
||||
private ScoreInfo scoreInfo;
|
||||
|
||||
protected GameplayPerformancePointsCounter()
|
||||
{
|
||||
Current.Value = DisplayedCount = 0;
|
||||
}
|
||||
|
||||
private Mod[] clonedMods;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(BeatmapDifficultyCache difficultyCache)
|
||||
{
|
||||
DrawableCount.Alpha = alpha_when_invalid;
|
||||
|
||||
if (gameplayState != null)
|
||||
{
|
||||
performanceCalculator = gameplayState.Ruleset.CreatePerformanceCalculator();
|
||||
clonedMods = gameplayState.Mods.Select(m => m.DeepClone()).ToArray();
|
||||
|
||||
scoreInfo = new ScoreInfo(gameplayState.Score.ScoreInfo.BeatmapInfo, gameplayState.Score.ScoreInfo.Ruleset) { Mods = clonedMods };
|
||||
|
||||
var gameplayWorkingBeatmap = new GameplayWorkingBeatmap(gameplayState.Beatmap);
|
||||
difficultyCache.GetTimedDifficultyAttributesAsync(gameplayWorkingBeatmap, gameplayState.Ruleset, clonedMods, loadCancellationSource.Token)
|
||||
.ContinueWith(task => Schedule(() =>
|
||||
{
|
||||
timedAttributes = task.GetResultSafely();
|
||||
|
||||
IsValid = true;
|
||||
|
||||
if (lastJudgement != null)
|
||||
onJudgementChanged(lastJudgement);
|
||||
}), TaskContinuationOptions.OnlyOnRanToCompletion);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
if (scoreProcessor != null)
|
||||
{
|
||||
scoreProcessor.NewJudgement += onJudgementChanged;
|
||||
scoreProcessor.JudgementReverted += onJudgementChanged;
|
||||
}
|
||||
|
||||
if (gameplayState?.LastJudgementResult.Value != null)
|
||||
onJudgementChanged(gameplayState.LastJudgementResult.Value);
|
||||
}
|
||||
|
||||
private bool isValid;
|
||||
|
||||
protected bool IsValid
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value == isValid)
|
||||
return;
|
||||
|
||||
isValid = value;
|
||||
DrawableCount.FadeTo(isValid ? 1 : alpha_when_invalid, 1000, Easing.OutQuint);
|
||||
}
|
||||
}
|
||||
|
||||
private void onJudgementChanged(JudgementResult judgement)
|
||||
{
|
||||
lastJudgement = judgement;
|
||||
|
||||
var attrib = getAttributeAtTime(judgement);
|
||||
|
||||
if (gameplayState == null || attrib == null || scoreProcessor == null)
|
||||
{
|
||||
IsValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
scoreProcessor.PopulateScore(scoreInfo);
|
||||
Current.Value = (int)Math.Round(performanceCalculator?.Calculate(scoreInfo, attrib).Total ?? 0, MidpointRounding.AwayFromZero);
|
||||
IsValid = true;
|
||||
}
|
||||
|
||||
[CanBeNull]
|
||||
private DifficultyAttributes getAttributeAtTime(JudgementResult judgement)
|
||||
{
|
||||
if (timedAttributes == null || timedAttributes.Count == 0)
|
||||
return null;
|
||||
|
||||
int attribIndex = timedAttributes.BinarySearch(new TimedDifficultyAttributes(judgement.HitObject.GetEndTime(), null));
|
||||
if (attribIndex < 0)
|
||||
attribIndex = ~attribIndex - 1;
|
||||
|
||||
return timedAttributes[Math.Clamp(attribIndex, 0, timedAttributes.Count - 1)].Attributes;
|
||||
}
|
||||
|
||||
protected override LocalisableString FormatCount(int count) => count.ToString(@"D");
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (scoreProcessor != null)
|
||||
{
|
||||
scoreProcessor.NewJudgement -= onJudgementChanged;
|
||||
scoreProcessor.JudgementReverted -= onJudgementChanged;
|
||||
}
|
||||
|
||||
loadCancellationSource?.Cancel();
|
||||
}
|
||||
|
||||
// TODO: This class shouldn't exist, but requires breaking changes to allow DifficultyCalculator to receive an IBeatmap.
|
||||
private class GameplayWorkingBeatmap : WorkingBeatmap
|
||||
{
|
||||
private readonly IBeatmap gameplayBeatmap;
|
||||
|
||||
public GameplayWorkingBeatmap(IBeatmap gameplayBeatmap)
|
||||
: base(gameplayBeatmap.BeatmapInfo, null)
|
||||
{
|
||||
this.gameplayBeatmap = gameplayBeatmap;
|
||||
}
|
||||
|
||||
public override IBeatmap GetPlayableBeatmap(IRulesetInfo ruleset, IReadOnlyList<Mod> mods, CancellationToken cancellationToken)
|
||||
=> gameplayBeatmap;
|
||||
|
||||
protected override IBeatmap GetBeatmap() => gameplayBeatmap;
|
||||
|
||||
public override Texture GetBackground() => throw new NotImplementedException();
|
||||
|
||||
protected override Track GetBeatmapTrack() => throw new NotImplementedException();
|
||||
|
||||
protected internal override ISkin GetSkin() => throw new NotImplementedException();
|
||||
|
||||
public override Stream GetStream(string storagePath) => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +1,175 @@
|
||||
// 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.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Resources.Localisation.Web;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Difficulty;
|
||||
using osu.Game.Rulesets.Judgements;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Skinning;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
// todo: this should be renamed to DefaultPerformancePointsCounter, or probably even TrianglesPerformancePointsCounter once all other triangles components are renamed accordingly.
|
||||
public partial class PerformancePointsCounter : GameplayPerformancePointsCounter, ISerialisableDrawable
|
||||
public partial class PerformancePointsCounter : RollingCounter<int>, ISerialisableDrawable
|
||||
{
|
||||
public bool UsesFixedAnchor { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
protected override bool IsRollingProportional => true;
|
||||
|
||||
protected override double RollingDuration => 1000;
|
||||
|
||||
private const float alpha_when_invalid = 0.3f;
|
||||
|
||||
[Resolved]
|
||||
private ScoreProcessor scoreProcessor { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private GameplayState gameplayState { get; set; }
|
||||
|
||||
[CanBeNull]
|
||||
private List<TimedDifficultyAttributes> timedAttributes;
|
||||
|
||||
private readonly CancellationTokenSource loadCancellationSource = new CancellationTokenSource();
|
||||
|
||||
private JudgementResult lastJudgement;
|
||||
private PerformanceCalculator performanceCalculator;
|
||||
private ScoreInfo scoreInfo;
|
||||
|
||||
public PerformancePointsCounter()
|
||||
{
|
||||
Colour = colours.BlueLighter;
|
||||
Current.Value = DisplayedCount = 0;
|
||||
}
|
||||
|
||||
protected override IHasText CreateText() => new TextComponent();
|
||||
private Mod[] clonedMods;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours, BeatmapDifficultyCache difficultyCache)
|
||||
{
|
||||
Colour = colours.BlueLighter;
|
||||
|
||||
if (gameplayState != null)
|
||||
{
|
||||
performanceCalculator = gameplayState.Ruleset.CreatePerformanceCalculator();
|
||||
clonedMods = gameplayState.Mods.Select(m => m.DeepClone()).ToArray();
|
||||
|
||||
scoreInfo = new ScoreInfo(gameplayState.Score.ScoreInfo.BeatmapInfo, gameplayState.Score.ScoreInfo.Ruleset) { Mods = clonedMods };
|
||||
|
||||
var gameplayWorkingBeatmap = new GameplayWorkingBeatmap(gameplayState.Beatmap);
|
||||
difficultyCache.GetTimedDifficultyAttributesAsync(gameplayWorkingBeatmap, gameplayState.Ruleset, clonedMods, loadCancellationSource.Token)
|
||||
.ContinueWith(task => Schedule(() =>
|
||||
{
|
||||
timedAttributes = task.GetResultSafely();
|
||||
|
||||
IsValid = true;
|
||||
|
||||
if (lastJudgement != null)
|
||||
onJudgementChanged(lastJudgement);
|
||||
}), TaskContinuationOptions.OnlyOnRanToCompletion);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
if (scoreProcessor != null)
|
||||
{
|
||||
scoreProcessor.NewJudgement += onJudgementChanged;
|
||||
scoreProcessor.JudgementReverted += onJudgementChanged;
|
||||
}
|
||||
|
||||
if (gameplayState?.LastJudgementResult.Value != null)
|
||||
onJudgementChanged(gameplayState.LastJudgementResult.Value);
|
||||
}
|
||||
|
||||
private bool isValid;
|
||||
|
||||
protected bool IsValid
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value == isValid)
|
||||
return;
|
||||
|
||||
isValid = value;
|
||||
DrawableCount.FadeTo(isValid ? 1 : alpha_when_invalid, 1000, Easing.OutQuint);
|
||||
}
|
||||
}
|
||||
|
||||
private void onJudgementChanged(JudgementResult judgement)
|
||||
{
|
||||
lastJudgement = judgement;
|
||||
|
||||
var attrib = getAttributeAtTime(judgement);
|
||||
|
||||
if (gameplayState == null || attrib == null || scoreProcessor == null)
|
||||
{
|
||||
IsValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
scoreProcessor.PopulateScore(scoreInfo);
|
||||
Current.Value = (int)Math.Round(performanceCalculator?.Calculate(scoreInfo, attrib).Total ?? 0, MidpointRounding.AwayFromZero);
|
||||
IsValid = true;
|
||||
}
|
||||
|
||||
[CanBeNull]
|
||||
private DifficultyAttributes getAttributeAtTime(JudgementResult judgement)
|
||||
{
|
||||
if (timedAttributes == null || timedAttributes.Count == 0)
|
||||
return null;
|
||||
|
||||
int attribIndex = timedAttributes.BinarySearch(new TimedDifficultyAttributes(judgement.HitObject.GetEndTime(), null));
|
||||
if (attribIndex < 0)
|
||||
attribIndex = ~attribIndex - 1;
|
||||
|
||||
return timedAttributes[Math.Clamp(attribIndex, 0, timedAttributes.Count - 1)].Attributes;
|
||||
}
|
||||
|
||||
protected override LocalisableString FormatCount(int count) => count.ToString(@"D");
|
||||
|
||||
protected override IHasText CreateText() => new TextComponent
|
||||
{
|
||||
Alpha = alpha_when_invalid
|
||||
};
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (scoreProcessor != null)
|
||||
{
|
||||
scoreProcessor.NewJudgement -= onJudgementChanged;
|
||||
scoreProcessor.JudgementReverted -= onJudgementChanged;
|
||||
}
|
||||
|
||||
loadCancellationSource?.Cancel();
|
||||
}
|
||||
|
||||
private partial class TextComponent : CompositeDrawable, IHasText
|
||||
{
|
||||
@ -65,5 +209,30 @@ namespace osu.Game.Screens.Play.HUD
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: This class shouldn't exist, but requires breaking changes to allow DifficultyCalculator to receive an IBeatmap.
|
||||
private class GameplayWorkingBeatmap : WorkingBeatmap
|
||||
{
|
||||
private readonly IBeatmap gameplayBeatmap;
|
||||
|
||||
public GameplayWorkingBeatmap(IBeatmap gameplayBeatmap)
|
||||
: base(gameplayBeatmap.BeatmapInfo, null)
|
||||
{
|
||||
this.gameplayBeatmap = gameplayBeatmap;
|
||||
}
|
||||
|
||||
public override IBeatmap GetPlayableBeatmap(IRulesetInfo ruleset, IReadOnlyList<Mod> mods, CancellationToken cancellationToken)
|
||||
=> gameplayBeatmap;
|
||||
|
||||
protected override IBeatmap GetBeatmap() => gameplayBeatmap;
|
||||
|
||||
public override Texture GetBackground() => throw new NotImplementedException();
|
||||
|
||||
protected override Track GetBeatmapTrack() => throw new NotImplementedException();
|
||||
|
||||
protected internal override ISkin GetSkin() => throw new NotImplementedException();
|
||||
|
||||
public override Stream GetStream(string storagePath) => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user