mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 12:42:54 +08:00
Use lookup direction than 2 while loops
This commit is contained in:
parent
a08d54eb06
commit
b4c93b1777
@ -31,7 +31,9 @@ namespace osu.Game.Screens.Play
|
||||
set
|
||||
{
|
||||
breaks = value;
|
||||
nearestBreakIndex = 0;
|
||||
|
||||
// reset index in case the new breaks list is smaller than last one
|
||||
currentBreakIndex = 0;
|
||||
|
||||
initializeBreaks();
|
||||
}
|
||||
@ -44,7 +46,7 @@ namespace osu.Game.Screens.Play
|
||||
/// </summary>
|
||||
public IBindable<bool> IsBreakTime => isBreakTime;
|
||||
|
||||
private int nearestBreakIndex;
|
||||
private int currentBreakIndex;
|
||||
private readonly BindableBool isBreakTime = new BindableBool();
|
||||
|
||||
private readonly Container remainingTimeAdjustmentBox;
|
||||
@ -133,20 +135,31 @@ namespace osu.Game.Screens.Play
|
||||
if (breaks == null || !breaks.Any())
|
||||
{
|
||||
isBreakTime.Value = false;
|
||||
currentBreakIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
while (nearestBreakIndex < breaks.Count - 1 && Clock.CurrentTime > breaks[nearestBreakIndex].EndTime)
|
||||
nearestBreakIndex++;
|
||||
var lastIndex = currentBreakIndex;
|
||||
var lookupDirection = Clock.CurrentTime > breaks[lastIndex].EndTime ? 1 : (Clock.CurrentTime < breaks[lastIndex].StartTime ? -1 : 0);
|
||||
|
||||
while (nearestBreakIndex > 0 && Clock.CurrentTime < breaks[nearestBreakIndex].StartTime)
|
||||
nearestBreakIndex--;
|
||||
while (Clock.CurrentTime < breaks[currentBreakIndex].StartTime || Clock.CurrentTime > breaks[currentBreakIndex].EndTime)
|
||||
{
|
||||
currentBreakIndex += lookupDirection;
|
||||
|
||||
// restore index if out of bounds
|
||||
if (currentBreakIndex < 0 || currentBreakIndex >= breaks.Count)
|
||||
{
|
||||
isBreakTime.Value = false;
|
||||
currentBreakIndex = lastIndex;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// This ensures that IsBreakTime is generally consistent with the overlay's transforms during a break.
|
||||
// If the overlay never shows (break.HasEffect is false), IsBreakTime should be false.
|
||||
// If the current break doesn't have effects, IsBreakTime should be false.
|
||||
// We also assume that the overlay's fade out transform is "not break time".
|
||||
var nearestBreak = breaks[nearestBreakIndex];
|
||||
isBreakTime.Value = nearestBreak.HasEffect && Clock.CurrentTime >= nearestBreak.StartTime && Clock.CurrentTime <= nearestBreak.EndTime - fade_duration;
|
||||
var currentBreak = breaks[currentBreakIndex];
|
||||
isBreakTime.Value = currentBreak.HasEffect && Clock.CurrentTime <= currentBreak.EndTime - fade_duration;
|
||||
}
|
||||
|
||||
private void initializeBreaks()
|
||||
|
Loading…
Reference in New Issue
Block a user