Store RawTime in JudgementResult

This commit is contained in:
ekrctb 2023-02-09 17:15:37 +09:00
parent 5f0636c330
commit 258de3b2d8
3 changed files with 33 additions and 14 deletions

View File

@ -3,6 +3,7 @@
#nullable disable #nullable disable
using System;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
@ -33,19 +34,30 @@ namespace osu.Game.Rulesets.Judgements
public readonly Judgement Judgement; public readonly Judgement Judgement;
/// <summary> /// <summary>
/// The offset of <see cref="TimeAbsolute"/> from the end time of <see cref="HitObject"/>, clamped by <see cref="HitObject.MaximumJudgementOffset"/>. /// The time at which this <see cref="JudgementResult"/> occurred.
/// Populated when this <see cref="JudgementResult"/> is applied via <see cref="DrawableHitObject.ApplyResult"/>.
/// </summary>
public double TimeOffset { get; internal set; }
/// <summary>
/// The absolute time at which this <see cref="JudgementResult"/> occurred.
/// Populated when this <see cref="JudgementResult"/> is applied via <see cref="DrawableHitObject.ApplyResult"/>. /// Populated when this <see cref="JudgementResult"/> is applied via <see cref="DrawableHitObject.ApplyResult"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// This is initially set to the end time of <see cref="HitObject"/>. /// This is used instead of <see cref="TimeAbsolute"/> to check whether this <see cref="JudgementResult"/> should be reverted.
/// </remarks> /// </remarks>
public double TimeAbsolute { get; internal set; } internal double? RawTime { get; set; }
/// <summary>
/// The offset of <see cref="TimeAbsolute"/> from the end time of <see cref="HitObject"/>, clamped by <see cref="osu.Game.Rulesets.Objects.HitObject.MaximumJudgementOffset"/>.
/// </summary>
public double TimeOffset
{
get => RawTime != null ? Math.Min(RawTime.Value - HitObject.GetEndTime(), HitObject.MaximumJudgementOffset) : 0;
internal set => RawTime = HitObject.GetEndTime() + value;
}
/// <summary>
/// The absolute time at which this <see cref="JudgementResult"/> occurred, clamped by the end time of <see cref="HitObject"/> plus <see cref="osu.Game.Rulesets.Objects.HitObject.MaximumJudgementOffset"/>.
/// </summary>
/// <remarks>
/// The end time of <see cref="HitObject"/> is returned if this result is not populated yet.
/// </remarks>
public double TimeAbsolute => RawTime != null ? Math.Min(RawTime.Value, HitObject.GetEndTime() + HitObject.MaximumJudgementOffset) : HitObject.GetEndTime();
/// <summary> /// <summary>
/// The combo prior to this <see cref="JudgementResult"/> occurring. /// The combo prior to this <see cref="JudgementResult"/> occurring.
@ -92,8 +104,7 @@ namespace osu.Game.Rulesets.Judgements
internal void Reset() internal void Reset()
{ {
Type = HitResult.None; Type = HitResult.None;
TimeOffset = 0; RawTime = null;
TimeAbsolute = HitObject.GetEndTime();
} }
public override string ToString() => $"{Type} (Score:{Judgement.NumericResultFor(this)} HP:{Judgement.HealthIncreaseFor(this)} {Judgement})"; public override string ToString() => $"{Type} (Score:{Judgement.NumericResultFor(this)} HP:{Judgement.HealthIncreaseFor(this)} {Judgement})";

View File

@ -661,7 +661,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
$"{GetType().ReadableName()} applied an invalid hit result (was: {Result.Type}, expected: [{Result.Judgement.MinResult} ... {Result.Judgement.MaxResult}])."); $"{GetType().ReadableName()} applied an invalid hit result (was: {Result.Type}, expected: [{Result.Judgement.MinResult} ... {Result.Judgement.MaxResult}]).");
} }
Result.TimeOffset = Math.Min(HitObject.MaximumJudgementOffset, Time.Current - HitObject.GetEndTime()); Result.RawTime = Time.Current;
if (Result.HasResult) if (Result.HasResult)
updateState(Result.IsHit ? ArmedState.Hit : ArmedState.Miss); updateState(Result.IsHit ? ArmedState.Hit : ArmedState.Miss);

View File

@ -258,9 +258,17 @@ namespace osu.Game.Rulesets.UI
} }
// When rewinding, revert future judgements in the reverse order. // When rewinding, revert future judgements in the reverse order.
while (judgedEntries.Count > 0 && Time.Current < judgedEntries.Peek().Result.AsNonNull().TimeAbsolute) while (judgedEntries.Count > 0)
{
var result = judgedEntries.Peek().Result;
Debug.Assert(result?.RawTime != null);
if (Time.Current >= result.RawTime.Value)
break;
revertResult(judgedEntries.Pop()); revertResult(judgedEntries.Pop());
} }
}
/// <summary> /// <summary>
/// Creates the container that will be used to contain the <see cref="DrawableHitObject"/>s. /// Creates the container that will be used to contain the <see cref="DrawableHitObject"/>s.
@ -453,7 +461,7 @@ namespace osu.Game.Rulesets.UI
private void onNewResult(DrawableHitObject drawable, JudgementResult result) private void onNewResult(DrawableHitObject drawable, JudgementResult result)
{ {
Debug.Assert(result != null && drawable.Entry?.Result == result); Debug.Assert(result != null && drawable.Entry?.Result == result && result.RawTime != null);
judgedEntries.Push(drawable.Entry.AsNonNull()); judgedEntries.Push(drawable.Entry.AsNonNull());
NewResult?.Invoke(drawable, result); NewResult?.Invoke(drawable, result);