2020-04-09 17:02:09 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2020-04-17 05:22:03 +00:00
|
|
|
using System;
|
2020-04-17 04:34:20 +00:00
|
|
|
using System.Collections.Generic;
|
2020-04-09 17:02:09 +00:00
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
2021-02-08 11:11:06 +00:00
|
|
|
using osu.Game.Rulesets.UI;
|
2020-04-09 17:02:09 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.UI
|
|
|
|
{
|
|
|
|
/// <summary>
|
2021-02-05 05:04:21 +00:00
|
|
|
/// Ensures that <see cref="HitObject"/>s are hit in-order of their start times. Affectionately known as "note lock".
|
2020-04-09 17:02:09 +00:00
|
|
|
/// If a <see cref="HitObject"/> is hit out of order:
|
|
|
|
/// <list type="number">
|
|
|
|
/// <item><description>The hit is blocked if it occurred earlier than the previous <see cref="HitObject"/>'s start time.</description></item>
|
|
|
|
/// <item><description>The hit causes all previous <see cref="HitObject"/>s to missed otherwise.</description></item>
|
|
|
|
/// </list>
|
|
|
|
/// </summary>
|
2021-02-05 05:04:32 +00:00
|
|
|
public class StartTimeOrderedHitPolicy : IHitPolicy
|
2020-04-09 17:02:09 +00:00
|
|
|
{
|
2021-02-08 11:11:06 +00:00
|
|
|
public IHitObjectContainer HitObjectContainer { get; set; }
|
2020-04-09 17:02:09 +00:00
|
|
|
|
|
|
|
public bool IsHittable(DrawableHitObject hitObject, double time)
|
|
|
|
{
|
2020-04-09 17:41:37 +00:00
|
|
|
DrawableHitObject blockingObject = null;
|
2020-04-09 17:02:09 +00:00
|
|
|
|
2020-04-17 05:48:12 +00:00
|
|
|
foreach (var obj in enumerateHitObjectsUpTo(hitObject.HitObject.StartTime))
|
2020-04-09 17:02:09 +00:00
|
|
|
{
|
2020-04-17 05:48:12 +00:00
|
|
|
if (hitObjectCanBlockFutureHits(obj))
|
|
|
|
blockingObject = obj;
|
2020-04-09 17:02:09 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 17:41:37 +00:00
|
|
|
// If there is no previous hitobject, allow the hit.
|
|
|
|
if (blockingObject == null)
|
2020-04-09 17:02:09 +00:00
|
|
|
return true;
|
|
|
|
|
2020-04-09 17:41:37 +00:00
|
|
|
// A hit is allowed if:
|
|
|
|
// 1. The last blocking hitobject has been judged.
|
|
|
|
// 2. The current time is after the last hitobject's start time.
|
|
|
|
// Hits at exactly the same time as the blocking hitobject are allowed for maps that contain simultaneous hitobjects (e.g. /b/372245).
|
2020-04-20 01:59:44 +00:00
|
|
|
return blockingObject.Judged || time >= blockingObject.HitObject.StartTime;
|
2020-04-09 17:02:09 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 04:34:20 +00:00
|
|
|
public void HandleHit(DrawableHitObject hitObject)
|
2020-04-09 17:02:09 +00:00
|
|
|
{
|
2020-04-09 18:12:13 +00:00
|
|
|
// Hitobjects which themselves don't block future hitobjects don't cause misses (e.g. slider ticks, spinners).
|
2020-04-09 17:57:31 +00:00
|
|
|
if (!hitObjectCanBlockFutureHits(hitObject))
|
2020-04-09 17:02:09 +00:00
|
|
|
return;
|
|
|
|
|
2020-04-17 05:22:03 +00:00
|
|
|
if (!IsHittable(hitObject, hitObject.HitObject.StartTime + hitObject.Result.TimeOffset))
|
2020-04-20 04:23:27 +00:00
|
|
|
throw new InvalidOperationException($"A {hitObject} was hit before it became hittable!");
|
2020-04-17 05:22:03 +00:00
|
|
|
|
2021-02-05 05:04:32 +00:00
|
|
|
// Miss all hitobjects prior to the hit one.
|
2020-04-17 05:48:12 +00:00
|
|
|
foreach (var obj in enumerateHitObjectsUpTo(hitObject.HitObject.StartTime))
|
2020-04-09 17:02:09 +00:00
|
|
|
{
|
2020-04-17 05:48:12 +00:00
|
|
|
if (obj.Judged)
|
|
|
|
continue;
|
2020-04-09 17:41:37 +00:00
|
|
|
|
2020-04-17 05:48:12 +00:00
|
|
|
if (hitObjectCanBlockFutureHits(obj))
|
|
|
|
((DrawableOsuHitObject)obj).MissForcefully();
|
2020-04-09 17:02:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Whether a <see cref="HitObject"/> blocks hits on future <see cref="HitObject"/>s until its start time is reached.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="hitObject">The <see cref="HitObject"/> to test.</param>
|
2020-04-17 04:34:20 +00:00
|
|
|
private static bool hitObjectCanBlockFutureHits(DrawableHitObject hitObject)
|
|
|
|
=> hitObject is DrawableHitCircle;
|
|
|
|
|
2020-04-17 05:48:12 +00:00
|
|
|
private IEnumerable<DrawableHitObject> enumerateHitObjectsUpTo(double targetTime)
|
2020-04-09 17:41:37 +00:00
|
|
|
{
|
2021-02-08 11:11:06 +00:00
|
|
|
foreach (var obj in HitObjectContainer.AliveObjects)
|
2020-04-17 05:00:00 +00:00
|
|
|
{
|
2020-04-17 05:48:12 +00:00
|
|
|
if (obj.HitObject.StartTime >= targetTime)
|
|
|
|
yield break;
|
2020-04-17 05:00:00 +00:00
|
|
|
|
2020-04-17 05:48:12 +00:00
|
|
|
yield return obj;
|
2020-04-17 04:34:20 +00:00
|
|
|
|
2020-04-20 02:00:42 +00:00
|
|
|
foreach (var nestedObj in obj.NestedHitObjects)
|
2020-04-17 05:48:12 +00:00
|
|
|
{
|
2020-04-20 02:00:42 +00:00
|
|
|
if (nestedObj.HitObject.StartTime >= targetTime)
|
2020-04-17 05:48:12 +00:00
|
|
|
break;
|
2020-04-17 05:00:00 +00:00
|
|
|
|
2020-04-20 02:00:42 +00:00
|
|
|
yield return nestedObj;
|
2020-04-17 05:48:12 +00:00
|
|
|
}
|
2020-04-17 04:34:20 +00:00
|
|
|
}
|
2020-04-09 17:41:37 +00:00
|
|
|
}
|
2020-04-09 17:02:09 +00:00
|
|
|
}
|
|
|
|
}
|