1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 18:47:27 +08:00

Use empty hitwindows instead of null

This commit is contained in:
Dean Herbert 2019-10-09 19:08:31 +09:00
parent 93d2c3d7a1
commit 51bf600ea7
27 changed files with 62 additions and 31 deletions

View File

@ -93,7 +93,7 @@ namespace osu.Game.Rulesets.Catch.Objects
Scale = 1.0f - 0.7f * (difficulty.CircleSize - 5) / 5; Scale = 1.0f - 0.7f * (difficulty.CircleSize - 5) / 5;
} }
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
public enum FruitVisualRepresentation public enum FruitVisualRepresentation

View File

@ -101,6 +101,6 @@ namespace osu.Game.Rulesets.Mania.Objects
public override Judgement CreateJudgement() => new HoldNoteJudgement(); public override Judgement CreateJudgement() => new HoldNoteJudgement();
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -14,6 +14,6 @@ namespace osu.Game.Rulesets.Mania.Objects
{ {
public override Judgement CreateJudgement() => new HoldNoteTickJudgement(); public override Judgement CreateJudgement() => new HoldNoteTickJudgement();
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -30,6 +30,6 @@ namespace osu.Game.Rulesets.Osu.Objects
public override Judgement CreateJudgement() => new OsuJudgement(); public override Judgement CreateJudgement() => new OsuJudgement();
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -205,6 +205,6 @@ namespace osu.Game.Rulesets.Osu.Objects
public override Judgement CreateJudgement() => new OsuJudgement(); public override Judgement CreateJudgement() => new OsuJudgement();
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -25,6 +25,6 @@ namespace osu.Game.Rulesets.Osu.Objects
public override Judgement CreateJudgement() => new OsuSliderTailJudgement(); public override Judgement CreateJudgement() => new OsuSliderTailJudgement();
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -32,6 +32,6 @@ namespace osu.Game.Rulesets.Osu.Objects
public override Judgement CreateJudgement() => new OsuJudgement(); public override Judgement CreateJudgement() => new OsuJudgement();
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -33,6 +33,6 @@ namespace osu.Game.Rulesets.Osu.Objects
public override Judgement CreateJudgement() => new OsuJudgement(); public override Judgement CreateJudgement() => new OsuJudgement();
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -88,6 +88,6 @@ namespace osu.Game.Rulesets.Taiko.Objects
public override Judgement CreateJudgement() => new TaikoDrumRollJudgement(); public override Judgement CreateJudgement() => new TaikoDrumRollJudgement();
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -27,6 +27,6 @@ namespace osu.Game.Rulesets.Taiko.Objects
public override Judgement CreateJudgement() => new TaikoDrumRollTickJudgement(); public override Judgement CreateJudgement() => new TaikoDrumRollTickJudgement();
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -11,6 +11,6 @@ namespace osu.Game.Rulesets.Taiko.Objects
{ {
public override Judgement CreateJudgement() => new TaikoStrongJudgement(); public override Judgement CreateJudgement() => new TaikoStrongJudgement();
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -35,6 +35,6 @@ namespace osu.Game.Rulesets.Taiko.Objects
public override Judgement CreateJudgement() => new TaikoSwellJudgement(); public override Judgement CreateJudgement() => new TaikoSwellJudgement();
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -11,6 +11,6 @@ namespace osu.Game.Rulesets.Taiko.Objects
{ {
public override Judgement CreateJudgement() => new TaikoSwellTickJudgement(); public override Judgement CreateJudgement() => new TaikoSwellTickJudgement();
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -66,7 +66,6 @@ namespace osu.Game.Rulesets.Objects
/// <summary> /// <summary>
/// The hit windows for this <see cref="HitObject"/>. /// The hit windows for this <see cref="HitObject"/>.
/// </summary> /// </summary>
[CanBeNull]
public HitWindows HitWindows { get; set; } public HitWindows HitWindows { get; set; }
private readonly List<HitObject> nestedHitObjects = new List<HitObject>(); private readonly List<HitObject> nestedHitObjects = new List<HitObject>();
@ -113,10 +112,7 @@ namespace osu.Game.Rulesets.Objects
nestedHitObjects.Sort((h1, h2) => h1.StartTime.CompareTo(h2.StartTime)); nestedHitObjects.Sort((h1, h2) => h1.StartTime.CompareTo(h2.StartTime));
foreach (var h in nestedHitObjects) foreach (var h in nestedHitObjects)
{
h.HitWindows = HitWindows;
h.ApplyDefaults(controlPointInfo, difficulty); h.ApplyDefaults(controlPointInfo, difficulty);
}
} }
protected virtual void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) protected virtual void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
@ -147,7 +143,7 @@ namespace osu.Game.Rulesets.Objects
/// This will only be invoked if <see cref="HitWindows"/> hasn't been set externally (e.g. from a <see cref="BeatmapConverter{T}"/>. /// This will only be invoked if <see cref="HitWindows"/> hasn't been set externally (e.g. from a <see cref="BeatmapConverter{T}"/>.
/// </para> /// </para>
/// </summary> /// </summary>
[CanBeNull] [NotNull]
protected virtual HitWindows CreateHitWindows() => new HitWindows(); protected virtual HitWindows CreateHitWindows() => new HitWindows();
} }
} }

View File

@ -13,6 +13,6 @@ namespace osu.Game.Rulesets.Objects.Legacy.Mania
{ {
public float X { get; set; } public float X { get; set; }
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -14,6 +14,6 @@ namespace osu.Game.Rulesets.Objects.Legacy.Mania
public double Duration => EndTime - StartTime; public double Duration => EndTime - StartTime;
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -13,6 +13,6 @@ namespace osu.Game.Rulesets.Objects.Legacy.Mania
{ {
public float X { get; set; } public float X { get; set; }
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -17,6 +17,6 @@ namespace osu.Game.Rulesets.Objects.Legacy.Mania
public float X { get; set; } public float X { get; set; }
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -22,6 +22,6 @@ namespace osu.Game.Rulesets.Objects.Legacy.Osu
public int ComboOffset { get; set; } public int ComboOffset { get; set; }
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -22,6 +22,6 @@ namespace osu.Game.Rulesets.Objects.Legacy.Osu
public int ComboOffset { get; set; } public int ComboOffset { get; set; }
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -22,7 +22,7 @@ namespace osu.Game.Rulesets.Objects.Legacy.Osu
public float Y => Position.Y; public float Y => Position.Y;
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
public bool NewCombo { get; set; } public bool NewCombo { get; set; }

View File

@ -10,6 +10,6 @@ namespace osu.Game.Rulesets.Objects.Legacy.Taiko
/// </summary> /// </summary>
internal sealed class ConvertHit : HitObject internal sealed class ConvertHit : HitObject
{ {
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -10,6 +10,6 @@ namespace osu.Game.Rulesets.Objects.Legacy.Taiko
/// </summary> /// </summary>
internal sealed class ConvertSlider : Legacy.ConvertSlider internal sealed class ConvertSlider : Legacy.ConvertSlider
{ {
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -15,6 +15,6 @@ namespace osu.Game.Rulesets.Objects.Legacy.Taiko
public double Duration => EndTime - StartTime; public double Duration => EndTime - StartTime;
protected override HitWindows CreateHitWindows() => null; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
} }
} }

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
@ -30,6 +31,17 @@ namespace osu.Game.Rulesets.Scoring
private double meh; private double meh;
private double miss; private double miss;
/// <summary>
/// An empty <see cref="HitWindows"/> with only <see cref="HitResult.Miss"/> and <see cref="HitResult.Perfect"/>.
/// No time values are provided (meaning instantaneous hit or miss).
/// </summary>
public static HitWindows Empty => new EmptyHitWindows();
public HitWindows()
{
Debug.Assert(GetRanges().Length >= 1, $"{nameof(HitWindows)}");
}
/// <summary> /// <summary>
/// Retrieves the <see cref="HitResult"/> with the largest hit window that produces a successful hit. /// Retrieves the <see cref="HitResult"/> with the largest hit window that produces a successful hit.
/// </summary> /// </summary>
@ -168,6 +180,29 @@ namespace osu.Game.Rulesets.Scoring
/// Defaults are provided but can be overridden to customise for a ruleset. /// Defaults are provided but can be overridden to customise for a ruleset.
/// </summary> /// </summary>
protected virtual DifficultyRange[] GetRanges() => base_ranges; protected virtual DifficultyRange[] GetRanges() => base_ranges;
public class EmptyHitWindows : HitWindows
{
private static readonly DifficultyRange[] ranges =
{
new DifficultyRange(HitResult.Perfect, 0, 0, 0),
new DifficultyRange(HitResult.Miss, 0, 0, 0),
};
public override bool IsHitResultAllowed(HitResult result)
{
switch (result)
{
case HitResult.Great:
case HitResult.Miss:
return true;
}
return false;
}
protected override DifficultyRange[] GetRanges() => ranges;
}
} }
public struct DifficultyRange public struct DifficultyRange

View File

@ -426,11 +426,11 @@ namespace osu.Game.Rulesets.UI
{ {
foreach (var h in Objects) foreach (var h in Objects)
{ {
if (h.HitWindows != null) if (h.HitWindows.WindowFor(HitResult.Miss) > 0)
return h.HitWindows; return h.HitWindows;
foreach (var n in h.NestedHitObjects) foreach (var n in h.NestedHitObjects)
if (n.HitWindows != null) if (h.HitWindows.WindowFor(HitResult.Miss) > 0)
return n.HitWindows; return n.HitWindows;
} }

View File

@ -48,7 +48,7 @@ namespace osu.Game.Screens.Play.HUD
private void onNewJudgement(JudgementResult result) private void onNewJudgement(JudgementResult result)
{ {
if (result.HitObject.HitWindows == null) if (result.HitObject.HitWindows.WindowFor(HitResult.Miss) == 0)
return; return;
foreach (var c in Children) foreach (var c in Children)