1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-27 00:23:01 +08:00

Initial structure for new hitobject judgement system

This commit is contained in:
smoogipoo 2018-08-01 21:04:03 +09:00
parent 41512667a8
commit d51d0e8547
3 changed files with 44 additions and 28 deletions

View File

@ -28,19 +28,19 @@ namespace osu.Game.Rulesets.Judgements
/// </summary>
public int HighestComboAtJudgement;
/// <summary>
/// Whether this <see cref="Judgement"/> has a result.
/// </summary>
public bool HasResult => Result > HitResult.None;
/// <summary>
/// Whether a successful hit occurred.
/// </summary>
public bool IsHit => Result > HitResult.Miss;
/// <summary>
/// Whether this judgement is the final judgement for the hit object.
/// </summary>
public bool Final = true;
/// <summary>
/// The offset from a perfect hit at which this judgement occurred.
/// Populated when added via <see cref="DrawableHitObject{TObject}.AddJudgement"/>.
/// Populated when added via <see cref="DrawableHitObject.ApplyJudgement"/>.
/// </summary>
public double TimeOffset { get; set; }

View File

@ -38,9 +38,6 @@ namespace osu.Game.Rulesets.Objects.Drawables
public event Action<DrawableHitObject, Judgement> OnJudgement;
public event Action<DrawableHitObject, Judgement> OnJudgementRemoved;
public IReadOnlyList<Judgement> Judgements => judgements;
private readonly List<Judgement> judgements = new List<Judgement>();
/// <summary>
/// Whether a visible judgement should be displayed when this representation is hit.
/// </summary>
@ -49,20 +46,20 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// <summary>
/// Whether this <see cref="DrawableHitObject"/> and all of its nested <see cref="DrawableHitObject"/>s have been hit.
/// </summary>
public bool IsHit => Judgements.Any(j => j.Final && j.IsHit) && NestedHitObjects.All(n => n.IsHit);
public bool IsHit => HitObject.Judgements.All(j => j.IsHit) && NestedHitObjects.All(n => n.IsHit);
/// <summary>
/// Whether this <see cref="DrawableHitObject"/> and all of its nested <see cref="DrawableHitObject"/>s have been judged.
/// </summary>
public bool AllJudged => (!ProvidesJudgement || judgementFinalized) && NestedHitObjects.All(h => h.AllJudged);
public bool AllJudged => Judged && NestedHitObjects.All(h => h.AllJudged);
/// <summary>
/// Whether this <see cref="DrawableHitObject"/> can be judged.
/// Whether this <see cref="DrawableHitObject"/> has been judged.
/// Note: This does NOT include nested hitobjects.
/// </summary>
protected virtual bool ProvidesJudgement => true;
public bool Judged => HitObject.Judgements.All(h => h.HasResult);
private bool judgementOccurred;
private bool judgementFinalized => judgements.LastOrDefault()?.Final == true;
public bool Interactive = true;
public override bool HandleKeyboardInput => Interactive;
@ -128,23 +125,31 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// </summary>
public void PlaySamples() => Samples?.Play();
private double lastUpdateTime;
protected override void Update()
{
base.Update();
var endTime = (HitObject as IHasEndTime)?.EndTime ?? HitObject.StartTime;
while (judgements.Count > 0)
if (lastUpdateTime > Time.Current)
{
var lastJudgement = judgements[judgements.Count - 1];
if (lastJudgement.TimeOffset + endTime <= Time.Current)
break;
var endTime = (HitObject as IHasEndTime)?.EndTime ?? HitObject.StartTime;
judgements.RemoveAt(judgements.Count - 1);
State.Value = ArmedState.Idle;
for (int i = HitObject.Judgements.Count - 1; i >= 0; i--)
{
var judgement = HitObject.Judgements[i];
OnJudgementRemoved?.Invoke(this, lastJudgement);
if (judgement.TimeOffset + endTime <= Time.Current)
break;
judgement.Result = HitResult.None;
State.Value = ArmedState.Idle;
OnJudgementRemoved?.Invoke(this, judgement);
}
}
lastUpdateTime = Time.Current;
}
protected override void UpdateAfterChildren()
@ -167,16 +172,17 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// Notifies that a new judgement has occurred for this <see cref="DrawableHitObject"/>.
/// </summary>
/// <param name="judgement">The <see cref="Judgement"/>.</param>
protected void AddJudgement(Judgement judgement)
protected void ApplyJudgement<T>(T judgement, Action<T> application)
where T : Judgement
{
judgementOccurred = true;
application?.Invoke(judgement);
// Ensure that the judgement is given a valid time offset, because this may not get set by the caller
var endTime = (HitObject as IHasEndTime)?.EndTime ?? HitObject.StartTime;
judgement.TimeOffset = Time.Current - endTime;
judgements.Add(judgement);
switch (judgement.Result)
{
case HitResult.None:
@ -207,7 +213,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
foreach (var d in NestedHitObjects)
judgementOccurred |= d.UpdateJudgement(userTriggered);
if (!ProvidesJudgement || judgementFinalized || judgementOccurred)
if (judgementOccurred || Judged)
return judgementOccurred;
var endTime = (HitObject as IHasEndTime)?.EndTime ?? HitObject.StartTime;
@ -218,7 +224,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// <summary>
/// Checks if any judgements have occurred for this <see cref="DrawableHitObject"/>. This method must construct
/// all <see cref="Judgement"/>s and notify of them through <see cref="AddJudgement"/>.
/// all <see cref="Judgement"/>s and notify of them through <see cref="ApplyJudgement"/>.
/// </summary>
/// <param name="userTriggered">Whether the user triggered this check.</param>
/// <param name="timeOffset">The offset from the <see cref="HitObject"/> end time at which this check occurred. A <paramref name="timeOffset"/> &gt; 0

View File

@ -3,12 +3,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Lists;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects.Types;
namespace osu.Game.Rulesets.Objects
@ -62,6 +64,9 @@ namespace osu.Game.Rulesets.Objects
[JsonIgnore]
public IReadOnlyList<HitObject> NestedHitObjects => nestedHitObjects.Value;
private readonly List<Judgement> judgements = new List<Judgement>();
public IReadOnlyList<Judgement> Judgements => judgements;
/// <summary>
/// Applies default values to this HitObject.
/// </summary>
@ -71,6 +76,9 @@ namespace osu.Game.Rulesets.Objects
{
ApplyDefaultsToSelf(controlPointInfo, difficulty);
judgements.Clear();
judgements.AddRange(CreateJudgements());
if (nestedHitObjects.IsValueCreated)
nestedHitObjects.Value.Clear();
@ -103,6 +111,8 @@ namespace osu.Game.Rulesets.Objects
{
}
protected virtual IEnumerable<Judgement> CreateJudgements() => Enumerable.Empty<Judgement>();
protected void AddNested(HitObject hitObject) => nestedHitObjects.Value.Add(hitObject);
/// <summary>