From acf20c079cbd201c6dd77135b581bc625491c184 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 2 Feb 2018 18:47:54 +0900 Subject: [PATCH] General improvements around usage of HitWindows for mania --- .../Objects/Drawables/DrawableHoldNote.cs | 10 ++- .../Objects/Drawables/DrawableNote.cs | 10 ++- osu.Game/Rulesets/Objects/HitWindows.cs | 72 +++++++++++-------- 3 files changed, 50 insertions(+), 42 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs index 57a4888b2b..9d1088f69d 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs @@ -1,7 +1,6 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; using System.Linq; using osu.Game.Rulesets.Objects.Drawables; using osu.Framework.Graphics; @@ -212,7 +211,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables { if (!userTriggered) { - if (timeOffset > HitObject.HitWindows.Bad / 2) + if (!HitObject.HitWindows.CanBeHit(timeOffset)) { AddJudgement(new HoldNoteTailJudgement { @@ -224,14 +223,13 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables return; } - double offset = Math.Abs(timeOffset); - - if (offset > HitObject.HitWindows.Miss / 2) + var result = HitObject.HitWindows.ResultFor(timeOffset); + if (result == null) return; AddJudgement(new HoldNoteTailJudgement { - Result = HitObject.HitWindows.ResultFor(offset) ?? HitResult.Miss, + Result = result.Value, HasBroken = holdNote.hasBroken }); } diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs index 101db0205c..a9a0741370 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs @@ -1,7 +1,6 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; using OpenTK.Graphics; using osu.Framework.Graphics; using osu.Framework.Input.Bindings; @@ -63,17 +62,16 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables { if (!userTriggered) { - if (timeOffset > HitObject.HitWindows.Bad / 2) + if (!HitObject.HitWindows.CanBeHit(timeOffset)) AddJudgement(new ManiaJudgement { Result = HitResult.Miss }); return; } - double offset = Math.Abs(timeOffset); - - if (offset > HitObject.HitWindows.Miss / 2) + var result = HitObject.HitWindows.ResultFor(timeOffset); + if (result == null) return; - AddJudgement(new ManiaJudgement { Result = HitObject.HitWindows.ResultFor(offset) ?? HitResult.Miss }); + AddJudgement(new ManiaJudgement { Result = result.Value }); } protected override void UpdateState(ArmedState state) diff --git a/osu.Game/Rulesets/Objects/HitWindows.cs b/osu.Game/Rulesets/Objects/HitWindows.cs index ab2de7558a..57e3d0a976 100644 --- a/osu.Game/Rulesets/Objects/HitWindows.cs +++ b/osu.Game/Rulesets/Objects/HitWindows.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using osu.Game.Beatmaps; using osu.Game.Rulesets.Scoring; @@ -144,57 +145,68 @@ namespace osu.Game.Rulesets.Objects /// /// Retrieves the hit result for a time offset. /// - /// The time offset. - /// The hit result, or null if the time offset results in a miss. - public HitResult? ResultFor(double hitOffset) + /// The time offset. This should always be a positive value indicating the absolute time offset. + /// The hit result, or null if doesn't result in a judgement. + public HitResult? ResultFor(double timeOffset) { - if (hitOffset <= Perfect / 2) + timeOffset = Math.Abs(timeOffset); + + if (timeOffset <= Perfect / 2) return HitResult.Perfect; - if (hitOffset <= Great / 2) + if (timeOffset <= Great / 2) return HitResult.Great; - if (hitOffset <= Good / 2) + if (timeOffset <= Good / 2) return HitResult.Good; - if (hitOffset <= Ok / 2) + if (timeOffset <= Ok / 2) return HitResult.Ok; - if (hitOffset <= Bad / 2) + if (timeOffset <= Bad / 2) return HitResult.Meh; + if (timeOffset <= Miss / 2) + return HitResult.Miss; + return null; } /// - /// Constructs new hit windows which have been multiplied by a value. + /// Given a time offset, whether the can ever be hit in the future. + /// This happens if > . /// - /// The original hit windows. + /// The time offset. + /// Whether the can be hit at any point in the future from this time offset. + public bool CanBeHit(double timeOffset) => timeOffset <= Bad / 2; + + /// + /// Multiplies all hit windows by a value. + /// + /// The hit windows to multiply. /// The value to multiply each hit window by. public static HitWindows operator *(HitWindows windows, double value) { - return new HitWindows - { - Perfect = windows.Perfect * value, - Great = windows.Great * value, - Good = windows.Good * value, - Ok = windows.Ok * value, - Bad = windows.Bad * value, - Miss = windows.Miss * value - }; + windows.Perfect *= value; + windows.Great *= value; + windows.Good *= value; + windows.Ok *= value; + windows.Bad *= value; + windows.Miss *= value; + + return windows; } /// - /// Constructs new hit windows which have been divided by a value. + /// Divides all hit windows by a value. /// - /// The original hit windows. + /// The hit windows to divide. /// The value to divide each hit window by. public static HitWindows operator /(HitWindows windows, double value) { - return new HitWindows - { - Perfect = windows.Perfect / value, - Great = windows.Great / value, - Good = windows.Good / value, - Ok = windows.Ok / value, - Bad = windows.Bad / value, - Miss = windows.Miss / value - }; + windows.Perfect /= value; + windows.Great /= value; + windows.Good /= value; + windows.Ok /= value; + windows.Bad /= value; + windows.Miss /= value; + + return windows; } } }