Reset ScoreProcessor from statistics replay frames

This commit is contained in:
Dan Balasescu
2022-01-31 18:54:23 +09:00
parent 39e1d65976
commit 4fb565e15f
5 changed files with 144 additions and 15 deletions

View File

@ -8,6 +8,7 @@ using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Replays;
namespace osu.Game.Rulesets.Scoring
{
@ -107,6 +108,17 @@ namespace osu.Game.Rulesets.Scoring
JudgedHits = 0;
}
public virtual void ResetFromReplayFrame(Ruleset ruleset, ReplayFrame frame)
{
if (frame.Header == null)
return;
JudgedHits = 0;
foreach ((_, int count) in frame.Header.Statistics)
JudgedHits += count;
}
/// <summary>
/// Creates the <see cref="JudgementResult"/> that represents the scoring result for a <see cref="HitObject"/>.
/// </summary>

View File

@ -7,9 +7,11 @@ using System.Diagnostics;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Utils;
using osu.Game.Extensions;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Replays;
using osu.Game.Scoring;
namespace osu.Game.Rulesets.Scoring
@ -18,6 +20,11 @@ namespace osu.Game.Rulesets.Scoring
{
private const double max_score = 1000000;
/// <summary>
/// Invoked when this <see cref="ScoreProcessor"/> was reset from a replay frame.
/// </summary>
public event Action OnResetFromReplayFrame;
/// <summary>
/// The current total score.
/// </summary>
@ -329,12 +336,6 @@ namespace osu.Game.Rulesets.Scoring
HighestCombo.Value = 0;
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
hitEvents.Clear();
}
/// <summary>
/// Retrieve a score populated with data for the current play this processor is responsible for.
/// </summary>
@ -351,6 +352,70 @@ namespace osu.Game.Rulesets.Scoring
score.HitEvents = hitEvents;
}
/// <summary>
/// Maximum <see cref="HitResult"/> for a normal hit (i.e. not tick/bonus) for this ruleset. Only populated via <see cref="ResetFromReplayFrame"/>.
/// </summary>
private HitResult? maxNormalResult;
public override void ResetFromReplayFrame(Ruleset ruleset, ReplayFrame frame)
{
base.ResetFromReplayFrame(ruleset, frame);
if (frame.Header == null)
return;
baseScore = 0;
rollingMaxBaseScore = 0;
HighestCombo.Value = frame.Header.MaxCombo;
foreach ((HitResult result, int count) in frame.Header.Statistics)
{
// Bonus scores are counted separately directly from the statistics dictionary later on.
if (!result.IsScorable() || result.IsBonus())
continue;
// The maximum result of this judgement if it wasn't a miss.
// E.g. For a GOOD judgement, the max result is either GREAT/PERFECT depending on which one the ruleset uses (osu!: GREAT, osu!mania: PERFECT).
HitResult maxResult;
switch (result)
{
case HitResult.LargeTickHit:
case HitResult.LargeTickMiss:
maxResult = HitResult.LargeTickHit;
break;
case HitResult.SmallTickHit:
case HitResult.SmallTickMiss:
maxResult = HitResult.SmallTickHit;
break;
default:
maxResult = maxNormalResult ??= ruleset.GetHitResults().OrderByDescending(kvp => Judgement.ToNumericResult(kvp.result)).First().result;
break;
}
for (int i = 0; i < count; i++)
{
baseScore += Judgement.ToNumericResult(result);
rollingMaxBaseScore += Judgement.ToNumericResult(maxResult);
}
}
scoreResultCounts.Clear();
scoreResultCounts.AddRange(frame.Header.Statistics);
updateScore();
OnResetFromReplayFrame?.Invoke();
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
hitEvents.Clear();
}
}
public enum ScoringMode