1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 15:12:57 +08:00

Nest class

This commit is contained in:
Dean Herbert 2019-02-19 12:35:52 +09:00
parent f8033a3b35
commit 62fe5ad481

View File

@ -43,63 +43,63 @@ namespace osu.Game.Tests.Beatmaps
protected override IBeatmap GetBeatmap() => beatmap; protected override IBeatmap GetBeatmap() => beatmap;
protected override Texture GetBackground() => null; protected override Texture GetBackground() => null;
protected override Track GetTrack() => track; protected override Track GetTrack() => track;
}
/// <summary> /// <summary>
/// A virtual track which tracks a reference clock. /// A virtual track which tracks a reference clock.
/// </summary> /// </summary>
public class TrackVirtualManual : Track public class TrackVirtualManual : Track
{
private readonly IFrameBasedClock referenceClock;
private readonly ManualClock clock;
private bool running;
private double offset;
public TrackVirtualManual(IFrameBasedClock referenceClock)
{ {
this.referenceClock = referenceClock; private readonly IFrameBasedClock referenceClock;
Length = double.PositiveInfinity; private readonly ManualClock clock;
clock = new ManualClock();
}
public override bool Seek(double seek) private bool running;
{ private double offset;
offset = MathHelper.Clamp(seek, 0, Length) - referenceClock.CurrentTime;
return true;
}
public override void Start() public TrackVirtualManual(IFrameBasedClock referenceClock)
{
running = true;
Seek(0);
}
public override void Reset()
{
Seek(0);
base.Reset();
}
public override void Stop()
{
running = false;
}
public override bool IsRunning => running;
public override double CurrentTime => running ? clock.CurrentTime : 0;
protected override void UpdateState()
{
base.UpdateState();
clock.CurrentTime = Math.Min(referenceClock.CurrentTime + offset, Length);
if (CurrentTime >= Length)
{ {
Stop(); this.referenceClock = referenceClock;
RaiseCompleted(); Length = double.PositiveInfinity;
clock = new ManualClock();
}
public override bool Seek(double seek)
{
offset = MathHelper.Clamp(seek, 0, Length) - referenceClock.CurrentTime;
return true;
}
public override void Start()
{
running = true;
Seek(0);
}
public override void Reset()
{
Seek(0);
base.Reset();
}
public override void Stop()
{
running = false;
}
public override bool IsRunning => running;
public override double CurrentTime => running ? clock.CurrentTime : 0;
protected override void UpdateState()
{
base.UpdateState();
clock.CurrentTime = Math.Min(referenceClock.CurrentTime + offset, Length);
if (CurrentTime >= Length)
{
Stop();
RaiseCompleted();
}
} }
} }
} }