diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs
index 6c70ab3526..2b55e81788 100644
--- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs
+++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs
@@ -265,7 +265,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
if (Tail.AllJudged)
{
if (Tail.IsHit)
- ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
+ ApplyMaxResult();
else
MissForcefully();
}
diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteBody.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteBody.cs
index 731b1b6298..6259033235 100644
--- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteBody.cs
+++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteBody.cs
@@ -11,8 +11,6 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
public override bool DisplayResult => false;
- private bool hit;
-
public DrawableHoldNoteBody()
: this(null)
{
@@ -27,12 +25,10 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
{
if (AllJudged) return;
- this.hit = hit;
- ApplyResult(static (r, hitObject) =>
- {
- var holdNoteBody = (DrawableHoldNoteBody)hitObject;
- r.Type = holdNoteBody.hit ? r.Judgement.MaxResult : r.Judgement.MinResult;
- });
+ if (hit)
+ ApplyMaxResult();
+ else
+ ApplyMinResult();
}
}
}
diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs
index 2d10fa27cd..e98622b8bf 100644
--- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs
+++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs
@@ -87,7 +87,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
///
/// Causes this to get missed, disregarding all conditions in implementations of .
///
- public virtual void MissForcefully() => ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
+ public virtual void MissForcefully() => ApplyMinResult();
}
public abstract partial class DrawableManiaHitObject : DrawableManiaHitObject
diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs
index a70253798a..2246552abe 100644
--- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs
+++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs
@@ -91,12 +91,13 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
if (!userTriggered)
{
if (!HitObject.HitWindows.CanBeHit(timeOffset))
- ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
+ ApplyMinResult();
return;
}
hitResult = HitObject.HitWindows.ResultFor(timeOffset);
+
if (hitResult == HitResult.None)
return;
diff --git a/osu.Game.Rulesets.Osu.Tests/TestSceneHitCircle.cs b/osu.Game.Rulesets.Osu.Tests/TestSceneHitCircle.cs
index 8d4145f2c1..abe950f9bb 100644
--- a/osu.Game.Rulesets.Osu.Tests/TestSceneHitCircle.cs
+++ b/osu.Game.Rulesets.Osu.Tests/TestSceneHitCircle.cs
@@ -136,7 +136,7 @@ namespace osu.Game.Rulesets.Osu.Tests
if (auto && !userTriggered && timeOffset > hitOffset && CheckHittable?.Invoke(this, Time.Current, HitResult.Great) == ClickAction.Hit)
{
// force success
- ApplyResult(static (r, _) => r.Type = HitResult.Great);
+ ApplyResult(HitResult.Great);
}
else
base.CheckForResult(userTriggered, timeOffset);
diff --git a/osu.Game.Rulesets.Osu.Tests/TestSceneHitCircleLateFade.cs b/osu.Game.Rulesets.Osu.Tests/TestSceneHitCircleLateFade.cs
index 2d1e9c1270..838b426cb4 100644
--- a/osu.Game.Rulesets.Osu.Tests/TestSceneHitCircleLateFade.cs
+++ b/osu.Game.Rulesets.Osu.Tests/TestSceneHitCircleLateFade.cs
@@ -208,7 +208,7 @@ namespace osu.Game.Rulesets.Osu.Tests
if (shouldHit && !userTriggered && timeOffset >= 0)
{
// force success
- ApplyResult(static (r, _) => r.Type = HitResult.Great);
+ ApplyResult(HitResult.Great);
}
else
base.CheckForResult(userTriggered, timeOffset);
diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableHitCircle.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableHitCircle.cs
index ce5422b180..a014ba2e77 100644
--- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableHitCircle.cs
+++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableHitCircle.cs
@@ -44,7 +44,6 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
private Container scaleContainer;
private InputManager inputManager;
- private HitResult hitResult;
public DrawableHitCircle()
: this(null)
@@ -156,12 +155,12 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
if (!userTriggered)
{
if (!HitObject.HitWindows.CanBeHit(timeOffset))
- ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
+ ApplyMinResult();
return;
}
- hitResult = ResultFor(timeOffset);
+ HitResult hitResult = ResultFor(timeOffset);
var clickAction = CheckHittable?.Invoke(this, Time.Current, hitResult);
if (clickAction == ClickAction.Shake)
@@ -170,20 +169,22 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
if (hitResult == HitResult.None || clickAction != ClickAction.Hit)
return;
- ApplyResult(static (r, hitObject) =>
+ Vector2? hitPosition = null;
+
+ // Todo: This should also consider misses, but they're a little more interesting to handle, since we don't necessarily know the position at the time of a miss.
+ if (hitResult.IsHit())
+ {
+ var localMousePosition = ToLocalSpace(inputManager.CurrentState.Mouse.Position);
+ hitPosition = HitObject.StackedPosition + (localMousePosition - DrawSize / 2);
+ }
+
+ ApplyResult<(HitResult result, Vector2? position)>((r, state) =>
{
- var hitCircle = (DrawableHitCircle)hitObject;
var circleResult = (OsuHitCircleJudgementResult)r;
- // Todo: This should also consider misses, but they're a little more interesting to handle, since we don't necessarily know the position at the time of a miss.
- if (hitCircle.hitResult.IsHit())
- {
- var localMousePosition = hitCircle.ToLocalSpace(hitCircle.inputManager.CurrentState.Mouse.Position);
- circleResult.CursorPositionAtHit = hitCircle.HitObject.StackedPosition + (localMousePosition - hitCircle.DrawSize / 2);
- }
-
- circleResult.Type = hitCircle.hitResult;
- });
+ circleResult.Type = state.result;
+ circleResult.CursorPositionAtHit = state.position;
+ }, (hitResult, hitPosition));
}
///
diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs
index 6de60a9d51..5271c03e08 100644
--- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs
+++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs
@@ -100,12 +100,12 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
///
/// Causes this to get hit, disregarding all conditions in implementations of .
///
- public void HitForcefully() => ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
+ public void HitForcefully() => ApplyMaxResult();
///
/// Causes this to get missed, disregarding all conditions in implementations of .
///
- public void MissForcefully() => ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
+ public void MissForcefully() => ApplyMinResult();
private RectangleF parentScreenSpaceRectangle => ((DrawableOsuHitObject)ParentHitObject)?.parentScreenSpaceRectangle ?? Parent!.ScreenSpaceDrawQuad.AABBFloat;
diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRoll.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRoll.cs
index e15298f3ca..1af4719b02 100644
--- a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRoll.cs
+++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRoll.cs
@@ -143,7 +143,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
if (timeOffset < 0)
return;
- ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
+ ApplyMaxResult();
}
protected override void UpdateHitStateTransforms(ArmedState state)
diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRollTick.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRollTick.cs
index aa678d7043..0333fd71a9 100644
--- a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRollTick.cs
+++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRollTick.cs
@@ -49,14 +49,14 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
if (!userTriggered)
{
if (timeOffset > HitObject.HitWindow)
- ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
+ ApplyMinResult();
return;
}
if (Math.Abs(timeOffset) > HitObject.HitWindow)
return;
- ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
+ ApplyMaxResult();
}
public override void OnKilled()
@@ -64,7 +64,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
base.OnKilled();
if (Time.Current > HitObject.GetEndTime() && !Judged)
- ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
+ ApplyMinResult();
}
protected override void UpdateHitStateTransforms(ArmedState state)
diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableFlyingHit.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableFlyingHit.cs
index 4349dff9f9..aad9214c5e 100644
--- a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableFlyingHit.cs
+++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableFlyingHit.cs
@@ -25,7 +25,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
protected override void LoadComplete()
{
base.LoadComplete();
- ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
+ ApplyMaxResult();
}
protected override void LoadSamples()
diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableHit.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableHit.cs
index cf8e4050ee..ca49ddb7e1 100644
--- a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableHit.cs
+++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableHit.cs
@@ -101,7 +101,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
if (!userTriggered)
{
if (!HitObject.HitWindows.CanBeHit(timeOffset))
- ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
+ ApplyMinResult();
return;
}
@@ -110,7 +110,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
return;
if (!validActionPressed)
- ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
+ ApplyMinResult();
else
{
ApplyResult(static (r, hitObject) =>
@@ -217,19 +217,19 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
if (!ParentHitObject.Result.IsHit)
{
- ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
+ ApplyMinResult();
return;
}
if (!userTriggered)
{
if (timeOffset - ParentHitObject.Result.TimeOffset > SECOND_HIT_WINDOW)
- ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
+ ApplyMinResult();
return;
}
if (Math.Abs(timeOffset - ParentHitObject.Result.TimeOffset) <= SECOND_HIT_WINDOW)
- ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
+ ApplyMaxResult();
}
public override bool OnPressed(KeyBindingPressEvent e)
diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableStrongNestedHit.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableStrongNestedHit.cs
index 8f99538448..11759927a9 100644
--- a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableStrongNestedHit.cs
+++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableStrongNestedHit.cs
@@ -27,7 +27,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
// it can happen that the hit window of the nested strong hit extends past the lifetime of the parent object.
// this is a safety to prevent such cases from causing the nested hit to never be judged and as such prevent gameplay from completing.
if (!Judged && Time.Current > ParentHitObject?.HitObject.GetEndTime())
- ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
+ ApplyMinResult();
}
}
}
diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableSwell.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableSwell.cs
index 0781ea5e2a..6eb62cce22 100644
--- a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableSwell.cs
+++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableSwell.cs
@@ -208,7 +208,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
expandingRing.ScaleTo(1f + Math.Min(target_ring_scale - 1f, (target_ring_scale - 1f) * completion * 1.3f), 260, Easing.OutQuint);
if (numHits == HitObject.RequiredHits)
- ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
+ ApplyMaxResult();
}
else
{
diff --git a/osu.Game.Tests/Gameplay/TestSceneDrawableHitObject.cs b/osu.Game.Tests/Gameplay/TestSceneDrawableHitObject.cs
index bf1e52aab5..73177e36e1 100644
--- a/osu.Game.Tests/Gameplay/TestSceneDrawableHitObject.cs
+++ b/osu.Game.Tests/Gameplay/TestSceneDrawableHitObject.cs
@@ -216,7 +216,7 @@ namespace osu.Game.Tests.Gameplay
LifetimeStart = LIFETIME_ON_APPLY;
}
- public void MissForcefully() => ApplyResult(static (r, _) => r.Type = HitResult.Miss);
+ public void MissForcefully() => ApplyResult(HitResult.Miss);
protected override void UpdateHitStateTransforms(ArmedState state)
{
diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePoolingRuleset.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePoolingRuleset.cs
index 00bd58e303..b567e8de8d 100644
--- a/osu.Game.Tests/Visual/Gameplay/TestScenePoolingRuleset.cs
+++ b/osu.Game.Tests/Visual/Gameplay/TestScenePoolingRuleset.cs
@@ -431,7 +431,7 @@ namespace osu.Game.Tests.Visual.Gameplay
protected override void CheckForResult(bool userTriggered, double timeOffset)
{
if (timeOffset > HitObject.Duration)
- ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
+ ApplyMaxResult();
}
protected override void UpdateHitStateTransforms(ArmedState state)
@@ -468,7 +468,7 @@ namespace osu.Game.Tests.Visual.Gameplay
public override void OnKilled()
{
base.OnKilled();
- ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
+ ApplyMinResult();
}
}
@@ -547,7 +547,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{
base.CheckForResult(userTriggered, timeOffset);
if (timeOffset >= 0)
- ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
+ ApplyMaxResult();
}
}
@@ -596,7 +596,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{
base.CheckForResult(userTriggered, timeOffset);
if (timeOffset >= 0)
- ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
+ ApplyMaxResult();
}
}
diff --git a/osu.Game/Rulesets/Judgements/JudgementResult.cs b/osu.Game/Rulesets/Judgements/JudgementResult.cs
index b781a13929..4b98df50d7 100644
--- a/osu.Game/Rulesets/Judgements/JudgementResult.cs
+++ b/osu.Game/Rulesets/Judgements/JudgementResult.cs
@@ -30,7 +30,7 @@ namespace osu.Game.Rulesets.Judgements
///
/// The time at which this occurred.
- /// Populated when this is applied via .
+ /// Populated when this is applied via .
///
///
/// This is used instead of to check whether this should be reverted.
diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs
index e30ce13f08..07fab72814 100644
--- a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs
+++ b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs
@@ -682,17 +682,28 @@ namespace osu.Game.Rulesets.Objects.Drawables
UpdateResult(false);
}
+ protected void ApplyMaxResult() => ApplyResult((r, _) => r.Type = r.Judgement.MaxResult);
+ protected void ApplyMinResult() => ApplyResult((r, _) => r.Type = r.Judgement.MinResult);
+
+ protected void ApplyResult(HitResult type) => ApplyResult(static (result, state) => result.Type = state, type);
+
+ [Obsolete("Use overload with state, preferrably with static delegates to avoid allocation overhead.")] // Can be removed 2024-07-26
+ protected void ApplyResult(Action application) => ApplyResult((r, _) => application(r), this);
+
+ protected void ApplyResult(Action application) => ApplyResult(application, this);
+
///
/// Applies the of this , notifying responders such as
/// the of the .
///
/// The callback that applies changes to the . Using a `static` delegate is recommended to avoid allocation overhead.
- protected void ApplyResult(Action application)
+ /// The state.
+ protected void ApplyResult(Action application, T state)
{
if (Result.HasResult)
throw new InvalidOperationException("Cannot apply result on a hitobject that already has a result.");
- application?.Invoke(Result, this);
+ application?.Invoke(Result, state);
if (!Result.HasResult)
throw new InvalidOperationException($"{GetType().ReadableName()} applied a {nameof(JudgementResult)} but did not update {nameof(JudgementResult.Type)}.");
@@ -737,7 +748,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// Checks if a scoring result has occurred for this .
///
///
- /// If a scoring result has occurred, this method must invoke to update the result and notify responders.
+ /// If a scoring result has occurred, this method must invoke to update the result and notify responders.
///
/// Whether the user triggered this check.
/// The offset from the end time of the at which this check occurred.