1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-18 03:05:10 +08:00
osu-lazer/osu.Game/Beatmaps/Timing/BreakPeriod.cs

81 lines
2.8 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
2024-06-19 15:01:33 +08:00
using System;
using osu.Game.Screens.Play;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Beatmaps.Timing
{
public class BreakPeriod : IEquatable<BreakPeriod>
2018-04-13 17:19:50 +08:00
{
/// <summary>
/// The minimum gap between the start of the break and the previous object.
/// </summary>
public const double GAP_BEFORE_BREAK = 200;
/// <summary>
/// The minimum gap between the end of the break and the next object.
/// Based on osu! preempt time at AR=10.
/// See also: https://github.com/ppy/osu/issues/14330#issuecomment-1002158551
/// </summary>
public const double GAP_AFTER_BREAK = 450;
2018-04-13 17:19:50 +08:00
/// <summary>
/// The minimum duration required for a break to have any effect.
/// </summary>
public const double MIN_BREAK_DURATION = 650;
/// <summary>
/// The minimum required duration of a gap between two objects such that a break can be placed between them.
/// </summary>
public const double MIN_GAP_DURATION = GAP_BEFORE_BREAK + MIN_BREAK_DURATION + GAP_AFTER_BREAK;
2018-04-13 17:19:50 +08:00
/// <summary>
/// The break start time.
/// </summary>
public double StartTime { get; }
2018-04-13 17:19:50 +08:00
/// <summary>
/// The break end time.
/// </summary>
public double EndTime { get; }
2018-04-13 17:19:50 +08:00
/// <summary>
/// The break duration.
/// </summary>
public double Duration => EndTime - StartTime;
/// <summary>
2020-10-12 14:28:16 +08:00
/// Whether the break has any effect.
2018-04-13 17:19:50 +08:00
/// </summary>
public bool HasEffect => Duration >= MIN_BREAK_DURATION;
2019-05-12 15:25:25 +08:00
/// <summary>
/// Constructs a new break period.
/// </summary>
/// <param name="startTime">The start time of the break period.</param>
/// <param name="endTime">The end time of the break period.</param>
public BreakPeriod(double startTime, double endTime)
{
StartTime = startTime;
EndTime = endTime;
}
2019-05-12 15:25:25 +08:00
/// <summary>
/// Whether this break contains a specified time.
/// </summary>
/// <param name="time">The time to check in milliseconds.</param>
/// <returns>Whether the time falls within this <see cref="BreakPeriod"/>.</returns>
public bool Contains(double time) => time >= StartTime && time <= EndTime - BreakOverlay.BREAK_FADE_DURATION;
2024-06-19 15:01:33 +08:00
public bool Intersects(BreakPeriod other) => StartTime <= other.EndTime && EndTime >= other.StartTime;
public virtual bool Equals(BreakPeriod? other) =>
other != null
&& StartTime == other.StartTime
&& EndTime == other.EndTime;
2024-06-19 15:01:33 +08:00
public override int GetHashCode() => HashCode.Combine(StartTime, EndTime);
2018-04-13 17:19:50 +08:00
}
}