1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 00:53:22 +08:00

Use IntervalList<double> for tracking break periods

This commit is contained in:
Salman Ahmed 2020-04-09 23:00:16 +03:00
parent 38ee5f3103
commit 9a29797a5b
3 changed files with 16 additions and 40 deletions

View File

@ -52,7 +52,7 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep($"seek to break {breakIndex}", () => Player.GameplayClockContainer.Seek(destBreak().StartTime)); AddStep($"seek to break {breakIndex}", () => Player.GameplayClockContainer.Seek(destBreak().StartTime));
AddUntilStep("wait for seek to complete", () => Player.HUDOverlay.Progress.ReferenceClock.CurrentTime >= destBreak().StartTime); AddUntilStep("wait for seek to complete", () => Player.HUDOverlay.Progress.ReferenceClock.CurrentTime >= destBreak().StartTime);
BreakPeriod destBreak() => Player.ChildrenOfType<BreakTracker>().First().Breaks.ElementAt(breakIndex); BreakPeriod destBreak() => Beatmap.Value.Beatmap.Breaks.ElementAt(breakIndex);
} }
} }
} }

View File

@ -97,8 +97,6 @@ namespace osu.Game.Tests.Visual.Gameplay
loadBreaksStep("multiple breaks", testBreaks); loadBreaksStep("multiple breaks", testBreaks);
seekAndAssertBreak("seek to break start", testBreaks[1].StartTime, true); seekAndAssertBreak("seek to break start", testBreaks[1].StartTime, true);
AddAssert("is skipped to break #2", () => breakTracker.CurrentBreakIndex == 1);
seekAndAssertBreak("seek to break middle", testBreaks[1].StartTime + testBreaks[1].Duration / 2, true); seekAndAssertBreak("seek to break middle", testBreaks[1].StartTime + testBreaks[1].Duration / 2, true);
seekAndAssertBreak("seek to break end", testBreaks[1].EndTime, false); seekAndAssertBreak("seek to break end", testBreaks[1].EndTime, false);
seekAndAssertBreak("seek to break after end", testBreaks[1].EndTime + 500, false); seekAndAssertBreak("seek to break after end", testBreaks[1].EndTime + 500, false);
@ -174,8 +172,6 @@ namespace osu.Game.Tests.Visual.Gameplay
private readonly ManualClock manualClock; private readonly ManualClock manualClock;
private IFrameBasedClock originalClock; private IFrameBasedClock originalClock;
public new int CurrentBreakIndex => base.CurrentBreakIndex;
public double ManualClockTime public double ManualClockTime
{ {
get => manualClock.CurrentTime; get => manualClock.CurrentTime;

View File

@ -5,6 +5,7 @@ using System.Collections.Generic;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Beatmaps.Timing; using osu.Game.Beatmaps.Timing;
using osu.Game.Lists;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
@ -20,22 +21,24 @@ namespace osu.Game.Screens.Play
/// </summary> /// </summary>
public IBindable<bool> IsBreakTime => isBreakTime; public IBindable<bool> IsBreakTime => isBreakTime;
protected int CurrentBreakIndex;
private readonly BindableBool isBreakTime = new BindableBool(); private readonly BindableBool isBreakTime = new BindableBool();
private IReadOnlyList<BreakPeriod> breaks; private readonly IntervalList<double> breakIntervals = new IntervalList<double>();
public IReadOnlyList<BreakPeriod> Breaks public IReadOnlyList<BreakPeriod> Breaks
{ {
get => breaks;
set set
{ {
breaks = value;
// reset index in case the new breaks list is smaller than last one
isBreakTime.Value = false; isBreakTime.Value = false;
CurrentBreakIndex = 0; breakIntervals.Clear();
foreach (var b in value)
{
if (!b.HasEffect)
continue;
breakIntervals.Add(b.StartTime, b.EndTime - BreakOverlay.BREAK_FADE_DURATION);
}
} }
} }
@ -49,34 +52,11 @@ namespace osu.Game.Screens.Play
{ {
base.Update(); base.Update();
isBreakTime.Value = getCurrentBreak()?.HasEffect == true var time = Clock.CurrentTime;
|| Clock.CurrentTime < gameplayStartTime
isBreakTime.Value = breakIntervals.IsInAnyInterval(time)
|| time < gameplayStartTime
|| scoreProcessor?.HasCompleted == true; || scoreProcessor?.HasCompleted == true;
} }
private BreakPeriod getCurrentBreak()
{
if (breaks?.Count > 0)
{
var time = Clock.CurrentTime;
if (time > breaks[CurrentBreakIndex].EndTime)
{
while (time > breaks[CurrentBreakIndex].EndTime && CurrentBreakIndex < breaks.Count - 1)
CurrentBreakIndex++;
}
else
{
while (time < breaks[CurrentBreakIndex].StartTime && CurrentBreakIndex > 0)
CurrentBreakIndex--;
}
var closest = breaks[CurrentBreakIndex];
return closest.Contains(time) ? closest : null;
}
return null;
}
} }
} }