Tidy up clock logic using DI and a GameplayClock

This commit is contained in:
Dean Herbert
2019-03-05 13:26:54 +09:00
parent 7c54e67b6e
commit 01f1018d02
11 changed files with 127 additions and 83 deletions

View File

@ -10,7 +10,6 @@ using osu.Game.Graphics;
using osu.Framework.Allocation;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Timing;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.UI;
@ -29,18 +28,11 @@ namespace osu.Game.Screens.Play
private readonly SongProgressGraph graph;
private readonly SongProgressInfo info;
public Action<double> OnSeek;
public Action<double> RequestSeek;
public override bool HandleNonPositionalInput => AllowSeeking;
public override bool HandlePositionalInput => AllowSeeking;
private IClock audioClock;
public IClock AudioClock
{
set => audioClock = info.AudioClock = value;
}
private double lastHitTime => ((objects.Last() as IHasEndTime)?.EndTime ?? objects.Last().StartTime) + 1;
private double firstHitTime => objects.First().StartTime;
@ -63,9 +55,14 @@ namespace osu.Game.Screens.Play
private readonly BindableBool replayLoaded = new BindableBool();
[BackgroundDependencyLoader]
private void load(OsuColour colours)
private GameplayClock gameplayClock;
[BackgroundDependencyLoader(true)]
private void load(OsuColour colours, GameplayClock clock)
{
if (clock != null)
gameplayClock = clock;
graph.FillColour = bar.FillColour = colours.BlueLighter;
}
@ -99,7 +96,7 @@ namespace osu.Game.Screens.Play
Alpha = 0,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
OnSeek = position => OnSeek?.Invoke(position),
OnSeek = time => RequestSeek?.Invoke(time),
},
};
}
@ -157,14 +154,11 @@ namespace osu.Game.Screens.Play
if (objects == null)
return;
double position = audioClock?.CurrentTime ?? Time.Current;
double progress = (position - firstHitTime) / (lastHitTime - firstHitTime);
double position = gameplayClock?.CurrentTime ?? Time.Current;
double progress = Math.Min(1, (position - firstHitTime) / (lastHitTime - firstHitTime));
if (progress < 1)
{
bar.CurrentTime = position;
graph.Progress = (int)(graph.ColumnCount * progress);
}
bar.CurrentTime = position;
graph.Progress = (int)(graph.ColumnCount * progress);
}
}
}