2021-09-30 16:00:15 +08:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2021-09-30 16:00:15 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
2021-10-05 10:26:13 +08:00
|
|
|
using System.Threading;
|
2022-05-28 20:25:59 +08:00
|
|
|
using System.Threading.Tasks;
|
2021-09-30 16:54:56 +08:00
|
|
|
using JetBrains.Annotations;
|
2021-09-30 16:00:15 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Audio.Track;
|
2022-01-03 16:31:12 +08:00
|
|
|
using osu.Framework.Extensions;
|
2021-09-30 16:00:15 +08:00
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
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;
|
2022-03-14 14:51:10 +08:00
|
|
|
using osu.Game.Scoring;
|
2021-09-30 16:00:15 +08:00
|
|
|
using osu.Game.Skinning;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
|
|
|
{
|
2024-03-05 09:34:41 +08:00
|
|
|
public abstract partial class PerformancePointsCounter : RollingCounter<int>, ISerialisableDrawable
|
2021-09-30 16:00:15 +08:00
|
|
|
{
|
|
|
|
public bool UsesFixedAnchor { get; set; }
|
|
|
|
|
2022-03-15 21:55:47 +08:00
|
|
|
[Resolved]
|
2021-09-30 16:00:15 +08:00
|
|
|
private ScoreProcessor scoreProcessor { get; set; }
|
|
|
|
|
2022-03-15 21:55:47 +08:00
|
|
|
[Resolved]
|
2021-10-04 19:33:54 +08:00
|
|
|
private GameplayState gameplayState { get; set; }
|
2021-09-30 16:00:15 +08:00
|
|
|
|
2021-10-05 10:26:13 +08:00
|
|
|
[CanBeNull]
|
2021-10-05 15:59:54 +08:00
|
|
|
private List<TimedDifficultyAttributes> timedAttributes;
|
2021-10-05 10:26:13 +08:00
|
|
|
|
2021-10-05 11:07:41 +08:00
|
|
|
private readonly CancellationTokenSource loadCancellationSource = new CancellationTokenSource();
|
|
|
|
|
2021-10-05 16:10:32 +08:00
|
|
|
private JudgementResult lastJudgement;
|
2022-03-14 13:44:04 +08:00
|
|
|
private PerformanceCalculator performanceCalculator;
|
2022-03-14 14:51:10 +08:00
|
|
|
private ScoreInfo scoreInfo;
|
2021-10-05 16:10:32 +08:00
|
|
|
|
2021-10-06 20:26:30 +08:00
|
|
|
private Mod[] clonedMods;
|
|
|
|
|
2021-09-30 16:00:15 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2024-03-05 08:01:01 +08:00
|
|
|
private void load(BeatmapDifficultyCache difficultyCache)
|
2021-09-30 16:00:15 +08:00
|
|
|
{
|
2021-10-04 19:33:54 +08:00
|
|
|
if (gameplayState != null)
|
2021-09-30 16:54:56 +08:00
|
|
|
{
|
2022-03-14 13:44:04 +08:00
|
|
|
performanceCalculator = gameplayState.Ruleset.CreatePerformanceCalculator();
|
2021-10-06 20:26:30 +08:00
|
|
|
clonedMods = gameplayState.Mods.Select(m => m.DeepClone()).ToArray();
|
|
|
|
|
2022-03-14 16:10:37 +08:00
|
|
|
scoreInfo = new ScoreInfo(gameplayState.Score.ScoreInfo.BeatmapInfo, gameplayState.Score.ScoreInfo.Ruleset) { Mods = clonedMods };
|
2022-03-14 14:51:10 +08:00
|
|
|
|
2021-10-05 14:10:56 +08:00
|
|
|
var gameplayWorkingBeatmap = new GameplayWorkingBeatmap(gameplayState.Beatmap);
|
2021-10-06 20:30:30 +08:00
|
|
|
difficultyCache.GetTimedDifficultyAttributesAsync(gameplayWorkingBeatmap, gameplayState.Ruleset, clonedMods, loadCancellationSource.Token)
|
2022-01-03 16:31:12 +08:00
|
|
|
.ContinueWith(task => Schedule(() =>
|
2021-10-05 16:10:32 +08:00
|
|
|
{
|
2022-01-06 21:54:43 +08:00
|
|
|
timedAttributes = task.GetResultSafely();
|
2022-01-03 16:31:12 +08:00
|
|
|
|
2021-10-05 16:24:36 +08:00
|
|
|
IsValid = true;
|
2022-01-03 16:31:12 +08:00
|
|
|
|
2021-10-05 16:10:32 +08:00
|
|
|
if (lastJudgement != null)
|
2021-10-05 18:08:30 +08:00
|
|
|
onJudgementChanged(lastJudgement);
|
2022-05-28 20:25:59 +08:00
|
|
|
}), TaskContinuationOptions.OnlyOnRanToCompletion);
|
2021-09-30 16:54:56 +08:00
|
|
|
}
|
2021-09-30 16:00:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2021-09-30 16:54:56 +08:00
|
|
|
|
|
|
|
if (scoreProcessor != null)
|
2021-10-05 14:39:29 +08:00
|
|
|
{
|
2021-10-05 18:08:30 +08:00
|
|
|
scoreProcessor.NewJudgement += onJudgementChanged;
|
|
|
|
scoreProcessor.JudgementReverted += onJudgementChanged;
|
2021-10-05 14:39:29 +08:00
|
|
|
}
|
2021-11-11 23:23:37 +08:00
|
|
|
|
|
|
|
if (gameplayState?.LastJudgementResult.Value != null)
|
|
|
|
onJudgementChanged(gameplayState.LastJudgementResult.Value);
|
2021-10-05 14:39:29 +08:00
|
|
|
}
|
|
|
|
|
2024-03-05 08:01:01 +08:00
|
|
|
public virtual bool IsValid { get; set; }
|
2021-09-30 16:00:15 +08:00
|
|
|
|
2021-10-05 18:08:30 +08:00
|
|
|
private void onJudgementChanged(JudgementResult judgement)
|
2021-09-30 16:00:15 +08:00
|
|
|
{
|
2021-10-05 16:10:32 +08:00
|
|
|
lastJudgement = judgement;
|
|
|
|
|
2021-10-05 15:40:07 +08:00
|
|
|
var attrib = getAttributeAtTime(judgement);
|
2021-09-30 16:54:56 +08:00
|
|
|
|
2022-03-14 14:51:10 +08:00
|
|
|
if (gameplayState == null || attrib == null || scoreProcessor == null)
|
2021-10-05 18:08:30 +08:00
|
|
|
{
|
|
|
|
IsValid = false;
|
2021-10-05 15:40:07 +08:00
|
|
|
return;
|
2021-10-05 18:08:30 +08:00
|
|
|
}
|
2021-09-30 16:00:15 +08:00
|
|
|
|
2022-03-14 14:51:10 +08:00
|
|
|
scoreProcessor.PopulateScore(scoreInfo);
|
2022-03-14 13:44:04 +08:00
|
|
|
Current.Value = (int)Math.Round(performanceCalculator?.Calculate(scoreInfo, attrib).Total ?? 0, MidpointRounding.AwayFromZero);
|
2021-10-05 14:39:29 +08:00
|
|
|
IsValid = true;
|
|
|
|
}
|
|
|
|
|
2021-10-05 15:40:07 +08:00
|
|
|
[CanBeNull]
|
|
|
|
private DifficultyAttributes getAttributeAtTime(JudgementResult judgement)
|
2021-10-05 14:39:29 +08:00
|
|
|
{
|
2021-10-05 15:59:54 +08:00
|
|
|
if (timedAttributes == null || timedAttributes.Count == 0)
|
2021-10-05 15:40:07 +08:00
|
|
|
return null;
|
|
|
|
|
2021-10-05 15:59:54 +08:00
|
|
|
int attribIndex = timedAttributes.BinarySearch(new TimedDifficultyAttributes(judgement.HitObject.GetEndTime(), null));
|
2021-10-05 15:40:07 +08:00
|
|
|
if (attribIndex < 0)
|
|
|
|
attribIndex = ~attribIndex - 1;
|
|
|
|
|
2021-10-05 15:59:54 +08:00
|
|
|
return timedAttributes[Math.Clamp(attribIndex, 0, timedAttributes.Count - 1)].Attributes;
|
2021-09-30 16:00:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
if (scoreProcessor != null)
|
2021-11-12 01:11:18 +08:00
|
|
|
{
|
2021-10-05 18:08:30 +08:00
|
|
|
scoreProcessor.NewJudgement -= onJudgementChanged;
|
2021-11-12 01:11:18 +08:00
|
|
|
scoreProcessor.JudgementReverted -= onJudgementChanged;
|
|
|
|
}
|
2021-10-05 11:07:41 +08:00
|
|
|
|
|
|
|
loadCancellationSource?.Cancel();
|
2021-09-30 16:00:15 +08:00
|
|
|
}
|
|
|
|
|
2021-10-05 14:10:56 +08:00
|
|
|
// TODO: This class shouldn't exist, but requires breaking changes to allow DifficultyCalculator to receive an IBeatmap.
|
2021-09-30 16:00:15 +08:00
|
|
|
private class GameplayWorkingBeatmap : WorkingBeatmap
|
|
|
|
{
|
2021-10-04 19:33:54 +08:00
|
|
|
private readonly IBeatmap gameplayBeatmap;
|
2021-09-30 16:00:15 +08:00
|
|
|
|
2021-10-04 19:33:54 +08:00
|
|
|
public GameplayWorkingBeatmap(IBeatmap gameplayBeatmap)
|
2021-09-30 16:00:15 +08:00
|
|
|
: base(gameplayBeatmap.BeatmapInfo, null)
|
|
|
|
{
|
|
|
|
this.gameplayBeatmap = gameplayBeatmap;
|
|
|
|
}
|
|
|
|
|
2021-11-21 00:23:55 +08:00
|
|
|
public override IBeatmap GetPlayableBeatmap(IRulesetInfo ruleset, IReadOnlyList<Mod> mods, CancellationToken cancellationToken)
|
2021-10-04 19:33:54 +08:00
|
|
|
=> gameplayBeatmap;
|
2021-09-30 16:00:15 +08:00
|
|
|
|
2021-10-04 19:33:54 +08:00
|
|
|
protected override IBeatmap GetBeatmap() => gameplayBeatmap;
|
2021-09-30 16:00:15 +08:00
|
|
|
|
2023-06-08 15:17:44 +08:00
|
|
|
public override Texture GetBackground() => throw new NotImplementedException();
|
2021-09-30 16:00:15 +08:00
|
|
|
|
|
|
|
protected override Track GetBeatmapTrack() => throw new NotImplementedException();
|
|
|
|
|
|
|
|
protected internal override ISkin GetSkin() => throw new NotImplementedException();
|
|
|
|
|
|
|
|
public override Stream GetStream(string storagePath) => throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|