1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-27 14:52:55 +08:00

Merge pull request #19974 from peppy/no-gameplay-clock-editor-offset

Fix editor not applying offsets
This commit is contained in:
Dan Balasescu 2022-08-29 21:10:29 +09:00 committed by GitHub
commit 0491addbbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 232 additions and 227 deletions

View File

@ -70,10 +70,17 @@ namespace osu.Game.Rulesets.Catch.Tests.Editor
[Cached] [Cached]
private readonly BindableBeatDivisor beatDivisor; private readonly BindableBeatDivisor beatDivisor;
protected override Container<Drawable> Content { get; } = new Container { RelativeSizeAxes = Axes.Both };
public EditorBeatmapDependencyContainer(IBeatmap beatmap, BindableBeatDivisor beatDivisor) public EditorBeatmapDependencyContainer(IBeatmap beatmap, BindableBeatDivisor beatDivisor)
{ {
editorClock = new EditorClock(beatmap, beatDivisor);
this.beatDivisor = beatDivisor; this.beatDivisor = beatDivisor;
InternalChildren = new Drawable[]
{
editorClock = new EditorClock(beatmap, beatDivisor),
Content,
};
} }
} }
} }

View File

@ -35,7 +35,7 @@ namespace osu.Game.Rulesets.Mania.Tests.Editor
public void Setup() => Schedule(() => public void Setup() => Schedule(() =>
{ {
BeatDivisor.Value = 8; BeatDivisor.Value = 8;
Clock.Seek(0); EditorClock.Seek(0);
Child = composer = new TestComposer { RelativeSizeAxes = Axes.Both }; Child = composer = new TestComposer { RelativeSizeAxes = Axes.Both };
}); });
@ -53,7 +53,7 @@ namespace osu.Game.Rulesets.Mania.Tests.Editor
{ {
lastObject = this.ChildrenOfType<DrawableHitObject>().Single(d => d.HitObject == composer.EditorBeatmap.HitObjects.Last()); lastObject = this.ChildrenOfType<DrawableHitObject>().Single(d => d.HitObject == composer.EditorBeatmap.HitObjects.Last());
originalTime = lastObject.HitObject.StartTime; originalTime = lastObject.HitObject.StartTime;
Clock.Seek(composer.EditorBeatmap.HitObjects.Last().StartTime); EditorClock.Seek(composer.EditorBeatmap.HitObjects.Last().StartTime);
}); });
AddStep("select all objects", () => composer.EditorBeatmap.SelectedHitObjects.AddRange(composer.EditorBeatmap.HitObjects)); AddStep("select all objects", () => composer.EditorBeatmap.SelectedHitObjects.AddRange(composer.EditorBeatmap.HitObjects));
@ -90,7 +90,7 @@ namespace osu.Game.Rulesets.Mania.Tests.Editor
{ {
lastObject = this.ChildrenOfType<DrawableHitObject>().Single(d => d.HitObject == composer.EditorBeatmap.HitObjects.Last()); lastObject = this.ChildrenOfType<DrawableHitObject>().Single(d => d.HitObject == composer.EditorBeatmap.HitObjects.Last());
originalTime = lastObject.HitObject.StartTime; originalTime = lastObject.HitObject.StartTime;
Clock.Seek(composer.EditorBeatmap.HitObjects.Last().StartTime); EditorClock.Seek(composer.EditorBeatmap.HitObjects.Last().StartTime);
}); });
AddStep("select all objects", () => composer.EditorBeatmap.SelectedHitObjects.AddRange(composer.EditorBeatmap.HitObjects)); AddStep("select all objects", () => composer.EditorBeatmap.SelectedHitObjects.AddRange(composer.EditorBeatmap.HitObjects));
@ -125,7 +125,7 @@ namespace osu.Game.Rulesets.Mania.Tests.Editor
AddStep("seek to last object", () => AddStep("seek to last object", () =>
{ {
lastObject = this.ChildrenOfType<DrawableHitObject>().Single(d => d.HitObject == composer.EditorBeatmap.HitObjects.Last()); lastObject = this.ChildrenOfType<DrawableHitObject>().Single(d => d.HitObject == composer.EditorBeatmap.HitObjects.Last());
Clock.Seek(composer.EditorBeatmap.HitObjects.Last().StartTime); EditorClock.Seek(composer.EditorBeatmap.HitObjects.Last().StartTime);
}); });
AddStep("select all objects", () => composer.EditorBeatmap.SelectedHitObjects.AddRange(composer.EditorBeatmap.HitObjects)); AddStep("select all objects", () => composer.EditorBeatmap.SelectedHitObjects.AddRange(composer.EditorBeatmap.HitObjects));

View File

@ -59,10 +59,9 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
} }
}); });
editorClock = new EditorClock(editorBeatmap);
base.Content.Children = new Drawable[] base.Content.Children = new Drawable[]
{ {
editorClock = new EditorClock(editorBeatmap),
snapProvider, snapProvider,
Content Content
}; };

View File

@ -22,7 +22,7 @@ namespace osu.Game.Rulesets.Taiko.Tests.Editor
public void Setup() => Schedule(() => public void Setup() => Schedule(() =>
{ {
BeatDivisor.Value = 8; BeatDivisor.Value = 8;
Clock.Seek(0); EditorClock.Seek(0);
Child = new TestComposer { RelativeSizeAxes = Axes.Both }; Child = new TestComposer { RelativeSizeAxes = Axes.Both };
}); });

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -23,13 +21,13 @@ namespace osu.Game.Tests.Editing
[HeadlessTest] [HeadlessTest]
public class TestSceneHitObjectComposerDistanceSnapping : EditorClockTestScene public class TestSceneHitObjectComposerDistanceSnapping : EditorClockTestScene
{ {
private TestHitObjectComposer composer; private TestHitObjectComposer composer = null!;
[Cached(typeof(EditorBeatmap))] [Cached(typeof(EditorBeatmap))]
[Cached(typeof(IBeatSnapProvider))] [Cached(typeof(IBeatSnapProvider))]
private readonly EditorBeatmap editorBeatmap; private readonly EditorBeatmap editorBeatmap;
protected override Container<Drawable> Content { get; } protected override Container<Drawable> Content { get; } = new Container { RelativeSizeAxes = Axes.Both };
public TestSceneHitObjectComposerDistanceSnapping() public TestSceneHitObjectComposerDistanceSnapping()
{ {
@ -40,15 +38,9 @@ namespace osu.Game.Tests.Editing
{ {
editorBeatmap = new EditorBeatmap(new OsuBeatmap editorBeatmap = new EditorBeatmap(new OsuBeatmap
{ {
BeatmapInfo = BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo },
{
Ruleset = new OsuRuleset().RulesetInfo,
},
}), }),
Content = new Container Content
{
RelativeSizeAxes = Axes.Both,
}
}, },
}); });
} }
@ -205,7 +197,7 @@ namespace osu.Game.Tests.Editing
assertSnappedDistance(400, 400); assertSnappedDistance(400, 400);
} }
private void assertSnapDistance(float expectedDistance, HitObject hitObject = null) private void assertSnapDistance(float expectedDistance, HitObject? hitObject = null)
=> AddAssert($"distance is {expectedDistance}", () => composer.GetBeatSnapDistanceAt(hitObject ?? new HitObject()), () => Is.EqualTo(expectedDistance)); => AddAssert($"distance is {expectedDistance}", () => composer.GetBeatSnapDistanceAt(hitObject ?? new HitObject()), () => Is.EqualTo(expectedDistance));
private void assertDurationToDistance(double duration, float expectedDistance) private void assertDurationToDistance(double duration, float expectedDistance)

View File

@ -55,51 +55,51 @@ namespace osu.Game.Tests.Visual.Editing
[Test] [Test]
public void TestStopAtTrackEnd() public void TestStopAtTrackEnd()
{ {
AddStep("reset clock", () => Clock.Seek(0)); AddStep("reset clock", () => EditorClock.Seek(0));
AddStep("start clock", () => Clock.Start()); AddStep("start clock", () => EditorClock.Start());
AddAssert("clock running", () => Clock.IsRunning); AddAssert("clock running", () => EditorClock.IsRunning);
AddStep("seek near end", () => Clock.Seek(Clock.TrackLength - 250)); AddStep("seek near end", () => EditorClock.Seek(EditorClock.TrackLength - 250));
AddUntilStep("clock stops", () => !Clock.IsRunning); AddUntilStep("clock stops", () => !EditorClock.IsRunning);
AddUntilStep("clock stopped at end", () => Clock.CurrentTime, () => Is.EqualTo(Clock.TrackLength)); AddUntilStep("clock stopped at end", () => EditorClock.CurrentTime - EditorClock.TotalAppliedOffset, () => Is.EqualTo(EditorClock.TrackLength));
AddStep("start clock again", () => Clock.Start()); AddStep("start clock again", () => EditorClock.Start());
AddAssert("clock looped to start", () => Clock.IsRunning && Clock.CurrentTime < 500); AddAssert("clock looped to start", () => EditorClock.IsRunning && EditorClock.CurrentTime < 500);
} }
[Test] [Test]
public void TestWrapWhenStoppedAtTrackEnd() public void TestWrapWhenStoppedAtTrackEnd()
{ {
AddStep("reset clock", () => Clock.Seek(0)); AddStep("reset clock", () => EditorClock.Seek(0));
AddStep("stop clock", () => Clock.Stop()); AddStep("stop clock", () => EditorClock.Stop());
AddAssert("clock stopped", () => !Clock.IsRunning); AddAssert("clock stopped", () => !EditorClock.IsRunning);
AddStep("seek exactly to end", () => Clock.Seek(Clock.TrackLength)); AddStep("seek exactly to end", () => EditorClock.Seek(EditorClock.TrackLength));
AddAssert("clock stopped at end", () => Clock.CurrentTime, () => Is.EqualTo(Clock.TrackLength)); AddAssert("clock stopped at end", () => EditorClock.CurrentTime, () => Is.EqualTo(EditorClock.TrackLength));
AddStep("start clock again", () => Clock.Start()); AddStep("start clock again", () => EditorClock.Start());
AddAssert("clock looped to start", () => Clock.IsRunning && Clock.CurrentTime < 500); AddAssert("clock looped to start", () => EditorClock.IsRunning && EditorClock.CurrentTime < 500);
} }
[Test] [Test]
public void TestClampWhenSeekOutsideBeatmapBounds() public void TestClampWhenSeekOutsideBeatmapBounds()
{ {
AddStep("stop clock", () => Clock.Stop()); AddStep("stop clock", () => EditorClock.Stop());
AddStep("seek before start time", () => Clock.Seek(-1000)); AddStep("seek before start time", () => EditorClock.Seek(-1000));
AddAssert("time is clamped to 0", () => Clock.CurrentTime, () => Is.EqualTo(0)); AddAssert("time is clamped to 0", () => EditorClock.CurrentTime, () => Is.EqualTo(0));
AddStep("seek beyond track length", () => Clock.Seek(Clock.TrackLength + 1000)); AddStep("seek beyond track length", () => EditorClock.Seek(EditorClock.TrackLength + 1000));
AddAssert("time is clamped to track length", () => Clock.CurrentTime, () => Is.EqualTo(Clock.TrackLength)); AddAssert("time is clamped to track length", () => EditorClock.CurrentTime, () => Is.EqualTo(EditorClock.TrackLength));
AddStep("seek smoothly before start time", () => Clock.SeekSmoothlyTo(-1000)); AddStep("seek smoothly before start time", () => EditorClock.SeekSmoothlyTo(-1000));
AddUntilStep("time is clamped to 0", () => Clock.CurrentTime, () => Is.EqualTo(0)); AddUntilStep("time is clamped to 0", () => EditorClock.CurrentTime, () => Is.EqualTo(0));
AddStep("seek smoothly beyond track length", () => Clock.SeekSmoothlyTo(Clock.TrackLength + 1000)); AddStep("seek smoothly beyond track length", () => EditorClock.SeekSmoothlyTo(EditorClock.TrackLength + 1000));
AddUntilStep("time is clamped to track length", () => Clock.CurrentTime, () => Is.EqualTo(Clock.TrackLength)); AddUntilStep("time is clamped to track length", () => EditorClock.CurrentTime, () => Is.EqualTo(EditorClock.TrackLength));
} }
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)

View File

@ -28,6 +28,11 @@ namespace osu.Game.Tests.Visual.Editing
{ {
base.LoadComplete(); base.LoadComplete();
Child = new TimingPointVisualiser(Beatmap.Value.Beatmap, 5000) { Clock = EditorClock };
}
protected override Beatmap CreateEditorClockBeatmap()
{
var testBeatmap = new Beatmap var testBeatmap = new Beatmap
{ {
ControlPointInfo = new ControlPointInfo(), ControlPointInfo = new ControlPointInfo(),
@ -45,9 +50,7 @@ namespace osu.Game.Tests.Visual.Editing
testBeatmap.ControlPointInfo.Add(450, new TimingControlPoint { BeatLength = 100 }); testBeatmap.ControlPointInfo.Add(450, new TimingControlPoint { BeatLength = 100 });
testBeatmap.ControlPointInfo.Add(500, new TimingControlPoint { BeatLength = 307.69230769230802 }); testBeatmap.ControlPointInfo.Add(500, new TimingControlPoint { BeatLength = 307.69230769230802 });
Beatmap.Value = CreateWorkingBeatmap(testBeatmap); return testBeatmap;
Child = new TimingPointVisualiser(testBeatmap, 5000) { Clock = Clock };
} }
/// <summary> /// <summary>
@ -59,17 +62,17 @@ namespace osu.Game.Tests.Visual.Editing
reset(); reset();
// Forwards // Forwards
AddStep("Seek(0)", () => Clock.Seek(0)); AddStep("Seek(0)", () => EditorClock.Seek(0));
checkTime(0); checkTime(0);
AddStep("Seek(33)", () => Clock.Seek(33)); AddStep("Seek(33)", () => EditorClock.Seek(33));
checkTime(33); checkTime(33);
AddStep("Seek(89)", () => Clock.Seek(89)); AddStep("Seek(89)", () => EditorClock.Seek(89));
checkTime(89); checkTime(89);
// Backwards // Backwards
AddStep("Seek(25)", () => Clock.Seek(25)); AddStep("Seek(25)", () => EditorClock.Seek(25));
checkTime(25); checkTime(25);
AddStep("Seek(0)", () => Clock.Seek(0)); AddStep("Seek(0)", () => EditorClock.Seek(0));
checkTime(0); checkTime(0);
} }
@ -82,19 +85,19 @@ namespace osu.Game.Tests.Visual.Editing
{ {
reset(); reset();
AddStep("Seek(0), Snap", () => Clock.SeekSnapped(0)); AddStep("Seek(0), Snap", () => EditorClock.SeekSnapped(0));
checkTime(0); checkTime(0);
AddStep("Seek(50), Snap", () => Clock.SeekSnapped(50)); AddStep("Seek(50), Snap", () => EditorClock.SeekSnapped(50));
checkTime(50); checkTime(50);
AddStep("Seek(100), Snap", () => Clock.SeekSnapped(100)); AddStep("Seek(100), Snap", () => EditorClock.SeekSnapped(100));
checkTime(100); checkTime(100);
AddStep("Seek(175), Snap", () => Clock.SeekSnapped(175)); AddStep("Seek(175), Snap", () => EditorClock.SeekSnapped(175));
checkTime(175); checkTime(175);
AddStep("Seek(350), Snap", () => Clock.SeekSnapped(350)); AddStep("Seek(350), Snap", () => EditorClock.SeekSnapped(350));
checkTime(350); checkTime(350);
AddStep("Seek(400), Snap", () => Clock.SeekSnapped(400)); AddStep("Seek(400), Snap", () => EditorClock.SeekSnapped(400));
checkTime(400); checkTime(400);
AddStep("Seek(450), Snap", () => Clock.SeekSnapped(450)); AddStep("Seek(450), Snap", () => EditorClock.SeekSnapped(450));
checkTime(450); checkTime(450);
} }
@ -107,17 +110,17 @@ namespace osu.Game.Tests.Visual.Editing
{ {
reset(); reset();
AddStep("Seek(24), Snap", () => Clock.SeekSnapped(24)); AddStep("Seek(24), Snap", () => EditorClock.SeekSnapped(24));
checkTime(0); checkTime(0);
AddStep("Seek(26), Snap", () => Clock.SeekSnapped(26)); AddStep("Seek(26), Snap", () => EditorClock.SeekSnapped(26));
checkTime(50); checkTime(50);
AddStep("Seek(150), Snap", () => Clock.SeekSnapped(150)); AddStep("Seek(150), Snap", () => EditorClock.SeekSnapped(150));
checkTime(100); checkTime(100);
AddStep("Seek(170), Snap", () => Clock.SeekSnapped(170)); AddStep("Seek(170), Snap", () => EditorClock.SeekSnapped(170));
checkTime(175); checkTime(175);
AddStep("Seek(274), Snap", () => Clock.SeekSnapped(274)); AddStep("Seek(274), Snap", () => EditorClock.SeekSnapped(274));
checkTime(175); checkTime(175);
AddStep("Seek(276), Snap", () => Clock.SeekSnapped(276)); AddStep("Seek(276), Snap", () => EditorClock.SeekSnapped(276));
checkTime(350); checkTime(350);
} }
@ -129,15 +132,15 @@ namespace osu.Game.Tests.Visual.Editing
{ {
reset(); reset();
AddStep("SeekForward", () => Clock.SeekForward()); AddStep("SeekForward", () => EditorClock.SeekForward());
checkTime(50); checkTime(50);
AddStep("SeekForward", () => Clock.SeekForward()); AddStep("SeekForward", () => EditorClock.SeekForward());
checkTime(100); checkTime(100);
AddStep("SeekForward", () => Clock.SeekForward()); AddStep("SeekForward", () => EditorClock.SeekForward());
checkTime(200); checkTime(200);
AddStep("SeekForward", () => Clock.SeekForward()); AddStep("SeekForward", () => EditorClock.SeekForward());
checkTime(400); checkTime(400);
AddStep("SeekForward", () => Clock.SeekForward()); AddStep("SeekForward", () => EditorClock.SeekForward());
checkTime(450); checkTime(450);
} }
@ -149,17 +152,17 @@ namespace osu.Game.Tests.Visual.Editing
{ {
reset(); reset();
AddStep("SeekForward, Snap", () => Clock.SeekForward(true)); AddStep("SeekForward, Snap", () => EditorClock.SeekForward(true));
checkTime(50); checkTime(50);
AddStep("SeekForward, Snap", () => Clock.SeekForward(true)); AddStep("SeekForward, Snap", () => EditorClock.SeekForward(true));
checkTime(100); checkTime(100);
AddStep("SeekForward, Snap", () => Clock.SeekForward(true)); AddStep("SeekForward, Snap", () => EditorClock.SeekForward(true));
checkTime(175); checkTime(175);
AddStep("SeekForward, Snap", () => Clock.SeekForward(true)); AddStep("SeekForward, Snap", () => EditorClock.SeekForward(true));
checkTime(350); checkTime(350);
AddStep("SeekForward, Snap", () => Clock.SeekForward(true)); AddStep("SeekForward, Snap", () => EditorClock.SeekForward(true));
checkTime(400); checkTime(400);
AddStep("SeekForward, Snap", () => Clock.SeekForward(true)); AddStep("SeekForward, Snap", () => EditorClock.SeekForward(true));
checkTime(450); checkTime(450);
} }
@ -172,30 +175,30 @@ namespace osu.Game.Tests.Visual.Editing
{ {
reset(); reset();
AddStep("Seek(49)", () => Clock.Seek(49)); AddStep("Seek(49)", () => EditorClock.Seek(49));
checkTime(49); checkTime(49);
AddStep("SeekForward, Snap", () => Clock.SeekForward(true)); AddStep("SeekForward, Snap", () => EditorClock.SeekForward(true));
checkTime(50); checkTime(50);
AddStep("Seek(49.999)", () => Clock.Seek(49.999)); AddStep("Seek(49.999)", () => EditorClock.Seek(49.999));
AddStep("SeekForward, Snap", () => Clock.SeekForward(true)); AddStep("SeekForward, Snap", () => EditorClock.SeekForward(true));
checkTime(100); checkTime(100);
AddStep("Seek(99)", () => Clock.Seek(99)); AddStep("Seek(99)", () => EditorClock.Seek(99));
AddStep("SeekForward, Snap", () => Clock.SeekForward(true)); AddStep("SeekForward, Snap", () => EditorClock.SeekForward(true));
checkTime(100); checkTime(100);
AddStep("Seek(99.999)", () => Clock.Seek(99.999)); AddStep("Seek(99.999)", () => EditorClock.Seek(99.999));
AddStep("SeekForward, Snap", () => Clock.SeekForward(true)); AddStep("SeekForward, Snap", () => EditorClock.SeekForward(true));
checkTime(150); checkTime(150);
AddStep("Seek(174)", () => Clock.Seek(174)); AddStep("Seek(174)", () => EditorClock.Seek(174));
AddStep("SeekForward, Snap", () => Clock.SeekForward(true)); AddStep("SeekForward, Snap", () => EditorClock.SeekForward(true));
checkTime(175); checkTime(175);
AddStep("Seek(349)", () => Clock.Seek(349)); AddStep("Seek(349)", () => EditorClock.Seek(349));
AddStep("SeekForward, Snap", () => Clock.SeekForward(true)); AddStep("SeekForward, Snap", () => EditorClock.SeekForward(true));
checkTime(350); checkTime(350);
AddStep("Seek(399)", () => Clock.Seek(399)); AddStep("Seek(399)", () => EditorClock.Seek(399));
AddStep("SeekForward, Snap", () => Clock.SeekForward(true)); AddStep("SeekForward, Snap", () => EditorClock.SeekForward(true));
checkTime(400); checkTime(400);
AddStep("Seek(449)", () => Clock.Seek(449)); AddStep("Seek(449)", () => EditorClock.Seek(449));
AddStep("SeekForward, Snap", () => Clock.SeekForward(true)); AddStep("SeekForward, Snap", () => EditorClock.SeekForward(true));
checkTime(450); checkTime(450);
} }
@ -207,17 +210,17 @@ namespace osu.Game.Tests.Visual.Editing
{ {
reset(); reset();
AddStep("Seek(450)", () => Clock.Seek(450)); AddStep("Seek(450)", () => EditorClock.Seek(450));
checkTime(450); checkTime(450);
AddStep("SeekBackward", () => Clock.SeekBackward()); AddStep("SeekBackward", () => EditorClock.SeekBackward());
checkTime(400); checkTime(400);
AddStep("SeekBackward", () => Clock.SeekBackward()); AddStep("SeekBackward", () => EditorClock.SeekBackward());
checkTime(350); checkTime(350);
AddStep("SeekBackward", () => Clock.SeekBackward()); AddStep("SeekBackward", () => EditorClock.SeekBackward());
checkTime(150); checkTime(150);
AddStep("SeekBackward", () => Clock.SeekBackward()); AddStep("SeekBackward", () => EditorClock.SeekBackward());
checkTime(50); checkTime(50);
AddStep("SeekBackward", () => Clock.SeekBackward()); AddStep("SeekBackward", () => EditorClock.SeekBackward());
checkTime(0); checkTime(0);
} }
@ -229,19 +232,19 @@ namespace osu.Game.Tests.Visual.Editing
{ {
reset(); reset();
AddStep("Seek(450)", () => Clock.Seek(450)); AddStep("Seek(450)", () => EditorClock.Seek(450));
checkTime(450); checkTime(450);
AddStep("SeekBackward, Snap", () => Clock.SeekBackward(true)); AddStep("SeekBackward, Snap", () => EditorClock.SeekBackward(true));
checkTime(400); checkTime(400);
AddStep("SeekBackward, Snap", () => Clock.SeekBackward(true)); AddStep("SeekBackward, Snap", () => EditorClock.SeekBackward(true));
checkTime(350); checkTime(350);
AddStep("SeekBackward, Snap", () => Clock.SeekBackward(true)); AddStep("SeekBackward, Snap", () => EditorClock.SeekBackward(true));
checkTime(175); checkTime(175);
AddStep("SeekBackward, Snap", () => Clock.SeekBackward(true)); AddStep("SeekBackward, Snap", () => EditorClock.SeekBackward(true));
checkTime(100); checkTime(100);
AddStep("SeekBackward, Snap", () => Clock.SeekBackward(true)); AddStep("SeekBackward, Snap", () => EditorClock.SeekBackward(true));
checkTime(50); checkTime(50);
AddStep("SeekBackward, Snap", () => Clock.SeekBackward(true)); AddStep("SeekBackward, Snap", () => EditorClock.SeekBackward(true));
checkTime(0); checkTime(0);
} }
@ -254,18 +257,18 @@ namespace osu.Game.Tests.Visual.Editing
{ {
reset(); reset();
AddStep("Seek(451)", () => Clock.Seek(451)); AddStep("Seek(451)", () => EditorClock.Seek(451));
checkTime(451); checkTime(451);
AddStep("SeekBackward, Snap", () => Clock.SeekBackward(true)); AddStep("SeekBackward, Snap", () => EditorClock.SeekBackward(true));
checkTime(450); checkTime(450);
AddStep("Seek(450.999)", () => Clock.Seek(450.999)); AddStep("Seek(450.999)", () => EditorClock.Seek(450.999));
AddStep("SeekBackward, Snap", () => Clock.SeekBackward(true)); AddStep("SeekBackward, Snap", () => EditorClock.SeekBackward(true));
checkTime(450); checkTime(450);
AddStep("Seek(401)", () => Clock.Seek(401)); AddStep("Seek(401)", () => EditorClock.Seek(401));
AddStep("SeekBackward, Snap", () => Clock.SeekBackward(true)); AddStep("SeekBackward, Snap", () => EditorClock.SeekBackward(true));
checkTime(400); checkTime(400);
AddStep("Seek(401.999)", () => Clock.Seek(401.999)); AddStep("Seek(401.999)", () => EditorClock.Seek(401.999));
AddStep("SeekBackward, Snap", () => Clock.SeekBackward(true)); AddStep("SeekBackward, Snap", () => EditorClock.SeekBackward(true));
checkTime(400); checkTime(400);
} }
@ -279,37 +282,37 @@ namespace osu.Game.Tests.Visual.Editing
double lastTime = 0; double lastTime = 0;
AddStep("Seek(0)", () => Clock.Seek(0)); AddStep("Seek(0)", () => EditorClock.Seek(0));
checkTime(0); checkTime(0);
for (int i = 0; i < 9; i++) for (int i = 0; i < 9; i++)
{ {
AddStep("SeekForward, Snap", () => AddStep("SeekForward, Snap", () =>
{ {
lastTime = Clock.CurrentTime; lastTime = EditorClock.CurrentTime;
Clock.SeekForward(true); EditorClock.SeekForward(true);
}); });
AddAssert("Time > lastTime", () => Clock.CurrentTime > lastTime); AddAssert("Time > lastTime", () => EditorClock.CurrentTime > lastTime);
} }
for (int i = 0; i < 9; i++) for (int i = 0; i < 9; i++)
{ {
AddStep("SeekBackward, Snap", () => AddStep("SeekBackward, Snap", () =>
{ {
lastTime = Clock.CurrentTime; lastTime = EditorClock.CurrentTime;
Clock.SeekBackward(true); EditorClock.SeekBackward(true);
}); });
AddAssert("Time < lastTime", () => Clock.CurrentTime < lastTime); AddAssert("Time < lastTime", () => EditorClock.CurrentTime < lastTime);
} }
checkTime(0); checkTime(0);
} }
private void checkTime(double expectedTime) => AddAssert($"Current time is {expectedTime}", () => Clock.CurrentTime, () => Is.EqualTo(expectedTime)); private void checkTime(double expectedTime) => AddUntilStep($"Current time is {expectedTime}", () => EditorClock.CurrentTime, () => Is.EqualTo(expectedTime));
private void reset() private void reset()
{ {
AddStep("Reset", () => Clock.Seek(0)); AddStep("Reset", () => EditorClock.Seek(0));
} }
private class TimingPointVisualiser : CompositeDrawable private class TimingPointVisualiser : CompositeDrawable

View File

@ -113,7 +113,7 @@ namespace osu.Game.Tests.Visual.Editing
.TriggerClick(); .TriggerClick();
}); });
AddUntilStep("wait for track playing", () => Clock.IsRunning); AddUntilStep("wait for track playing", () => EditorClock.IsRunning);
AddStep("click reset button", () => AddStep("click reset button", () =>
{ {
@ -122,7 +122,7 @@ namespace osu.Game.Tests.Visual.Editing
.TriggerClick(); .TriggerClick();
}); });
AddUntilStep("wait for track stopped", () => !Clock.IsRunning); AddUntilStep("wait for track stopped", () => !EditorClock.IsRunning);
} }
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)

View File

@ -17,7 +17,7 @@ namespace osu.Game.Tests.Visual.Editing
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
Clock.Seek(10000); EditorClock.Seek(10000);
} }
} }
} }

View File

@ -17,8 +17,6 @@ namespace osu.Game.Tests.Visual.Editing
{ {
double initialVisibleRange = 0; double initialVisibleRange = 0;
AddUntilStep("wait for load", () => MusicController.TrackLoaded);
AddStep("reset zoom", () => TimelineArea.Timeline.Zoom = 100); AddStep("reset zoom", () => TimelineArea.Timeline.Zoom = 100);
AddStep("get initial range", () => initialVisibleRange = TimelineArea.Timeline.VisibleRange); AddStep("get initial range", () => initialVisibleRange = TimelineArea.Timeline.VisibleRange);
@ -36,8 +34,6 @@ namespace osu.Game.Tests.Visual.Editing
{ {
double initialVisibleRange = 0; double initialVisibleRange = 0;
AddUntilStep("wait for load", () => MusicController.TrackLoaded);
AddStep("reset timeline size", () => TimelineArea.Timeline.Width = 1); AddStep("reset timeline size", () => TimelineArea.Timeline.Width = 1);
AddStep("get initial range", () => initialVisibleRange = TimelineArea.Timeline.VisibleRange); AddStep("get initial range", () => initialVisibleRange = TimelineArea.Timeline.VisibleRange);

View File

@ -53,7 +53,7 @@ namespace osu.Game.Tests.Visual.Editing
[SetUpSteps] [SetUpSteps]
public void SetUpSteps() public void SetUpSteps()
{ {
AddStep("Stop clock", () => Clock.Stop()); AddStep("Stop clock", () => EditorClock.Stop());
AddUntilStep("wait for rows to load", () => Child.ChildrenOfType<EffectRowAttribute>().Any()); AddUntilStep("wait for rows to load", () => Child.ChildrenOfType<EffectRowAttribute>().Any());
} }
@ -68,10 +68,10 @@ namespace osu.Game.Tests.Visual.Editing
}); });
AddUntilStep("Selection changed", () => timingScreen.SelectedGroup.Value.Time == 54670); AddUntilStep("Selection changed", () => timingScreen.SelectedGroup.Value.Time == 54670);
AddUntilStep("Ensure seeked to correct time", () => Clock.CurrentTimeAccurate == 54670); AddUntilStep("Ensure seeked to correct time", () => EditorClock.CurrentTimeAccurate == 54670);
AddStep("Seek to just before next point", () => Clock.Seek(69000)); AddStep("Seek to just before next point", () => EditorClock.Seek(69000));
AddStep("Start clock", () => Clock.Start()); AddStep("Start clock", () => EditorClock.Start());
AddUntilStep("Selection changed", () => timingScreen.SelectedGroup.Value.Time == 69670); AddUntilStep("Selection changed", () => timingScreen.SelectedGroup.Value.Time == 69670);
} }
@ -86,9 +86,9 @@ namespace osu.Game.Tests.Visual.Editing
}); });
AddUntilStep("Selection changed", () => timingScreen.SelectedGroup.Value.Time == 54670); AddUntilStep("Selection changed", () => timingScreen.SelectedGroup.Value.Time == 54670);
AddUntilStep("Ensure seeked to correct time", () => Clock.CurrentTimeAccurate == 54670); AddUntilStep("Ensure seeked to correct time", () => EditorClock.CurrentTimeAccurate == 54670);
AddStep("Seek to later", () => Clock.Seek(80000)); AddStep("Seek to later", () => EditorClock.Seek(80000));
AddUntilStep("Selection changed", () => timingScreen.SelectedGroup.Value.Time == 69670); AddUntilStep("Selection changed", () => timingScreen.SelectedGroup.Value.Time == 69670);
} }

View File

@ -9,12 +9,14 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Testing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics.Cursor; using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Screens.Edit; using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Compose.Components.Timeline; using osu.Game.Screens.Edit.Compose.Components.Timeline;
using osu.Game.Storyboards;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -28,10 +30,14 @@ namespace osu.Game.Tests.Visual.Editing
protected EditorBeatmap EditorBeatmap { get; private set; } protected EditorBeatmap EditorBeatmap { get; private set; }
[BackgroundDependencyLoader] [Resolved]
private void load(AudioManager audio) private AudioManager audio { get; set; }
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null) => new WaveformTestBeatmap(audio);
protected override void LoadComplete()
{ {
Beatmap.Value = new WaveformTestBeatmap(audio); base.LoadComplete();
var playable = Beatmap.Value.GetPlayableBeatmap(Beatmap.Value.BeatmapInfo.Ruleset); var playable = Beatmap.Value.GetPlayableBeatmap(Beatmap.Value.BeatmapInfo.Ruleset);
EditorBeatmap = new EditorBeatmap(playable); EditorBeatmap = new EditorBeatmap(playable);
@ -68,11 +74,11 @@ namespace osu.Game.Tests.Visual.Editing
}); });
} }
protected override void LoadComplete() [SetUpSteps]
public void SetUpSteps()
{ {
base.LoadComplete(); AddUntilStep("wait for track loaded", () => MusicController.TrackLoaded);
AddStep("seek forward", () => EditorClock.Seek(2500));
Clock.Seek(2500);
} }
public abstract Drawable CreateTestComponent(); public abstract Drawable CreateTestComponent();

View File

@ -124,7 +124,7 @@ namespace osu.Game.Beatmaps
finalClockSource.ProcessFrame(); finalClockSource.ProcessFrame();
} }
private double totalAppliedOffset public double TotalAppliedOffset
{ {
get get
{ {
@ -169,7 +169,7 @@ namespace osu.Game.Beatmaps
public bool Seek(double position) public bool Seek(double position)
{ {
bool success = decoupledClock.Seek(position - totalAppliedOffset); bool success = decoupledClock.Seek(position - TotalAppliedOffset);
finalClockSource.ProcessFrame(); finalClockSource.ProcessFrame();
return success; return success;

View File

@ -5,7 +5,6 @@
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -64,8 +63,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
/// </summary> /// </summary>
private bool trackWasPlaying; private bool trackWasPlaying;
private Track track;
/// <summary> /// <summary>
/// The timeline zoom level at a 1x zoom scale. /// The timeline zoom level at a 1x zoom scale.
/// </summary> /// </summary>
@ -93,6 +90,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
private Bindable<float> waveformOpacity; private Bindable<float> waveformOpacity;
private double trackLengthForZoom;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(IBindable<WorkingBeatmap> beatmap, OsuColour colours, OsuConfigManager config) private void load(IBindable<WorkingBeatmap> beatmap, OsuColour colours, OsuConfigManager config)
{ {
@ -144,9 +143,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
Beatmap.BindValueChanged(b => Beatmap.BindValueChanged(b =>
{ {
waveform.Waveform = b.NewValue.Waveform; waveform.Waveform = b.NewValue.Waveform;
track = b.NewValue.Track;
setupTimelineZoom();
}, true); }, true);
Zoom = (float)(defaultTimelineZoom * editorBeatmap.BeatmapInfo.TimelineZoom); Zoom = (float)(defaultTimelineZoom * editorBeatmap.BeatmapInfo.TimelineZoom);
@ -185,8 +181,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
private void updateWaveformOpacity() => private void updateWaveformOpacity() =>
waveform.FadeTo(WaveformVisible.Value ? waveformOpacity.Value : 0, 200, Easing.OutQuint); waveform.FadeTo(WaveformVisible.Value ? waveformOpacity.Value : 0, 200, Easing.OutQuint);
private float getZoomLevelForVisibleMilliseconds(double milliseconds) => Math.Max(1, (float)(track.Length / milliseconds));
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
@ -197,20 +191,21 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
// This needs to happen after transforms are updated, but before the scroll position is updated in base.UpdateAfterChildren // This needs to happen after transforms are updated, but before the scroll position is updated in base.UpdateAfterChildren
if (editorClock.IsRunning) if (editorClock.IsRunning)
scrollToTrackTime(); scrollToTrackTime();
}
private void setupTimelineZoom() if (editorClock.TrackLength != trackLengthForZoom)
{
if (!track.IsLoaded)
{ {
Scheduler.AddOnce(setupTimelineZoom); defaultTimelineZoom = getZoomLevelForVisibleMilliseconds(6000);
return;
float initialZoom = (float)(defaultTimelineZoom * editorBeatmap.BeatmapInfo.TimelineZoom);
float minimumZoom = getZoomLevelForVisibleMilliseconds(10000);
float maximumZoom = getZoomLevelForVisibleMilliseconds(500);
SetupZoom(initialZoom, minimumZoom, maximumZoom);
float getZoomLevelForVisibleMilliseconds(double milliseconds) => Math.Max(1, (float)(editorClock.TrackLength / milliseconds));
trackLengthForZoom = editorClock.TrackLength;
} }
defaultTimelineZoom = getZoomLevelForVisibleMilliseconds(6000);
float initialZoom = (float)(defaultTimelineZoom * editorBeatmap.BeatmapInfo.TimelineZoom);
SetupZoom(initialZoom, getZoomLevelForVisibleMilliseconds(10000), getZoomLevelForVisibleMilliseconds(500));
} }
protected override bool OnScroll(ScrollEvent e) protected override bool OnScroll(ScrollEvent e)
@ -255,16 +250,13 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
private void seekTrackToCurrent() private void seekTrackToCurrent()
{ {
if (!track.IsLoaded) double target = Current / Content.DrawWidth * editorClock.TrackLength;
return; editorClock.Seek(Math.Min(editorClock.TrackLength, target));
double target = Current / Content.DrawWidth * track.Length;
editorClock.Seek(Math.Min(track.Length, target));
} }
private void scrollToTrackTime() private void scrollToTrackTime()
{ {
if (!track.IsLoaded || track.Length == 0) if (editorClock.TrackLength == 0)
return; return;
// covers the case where the user starts playback after a drag is in progress. // covers the case where the user starts playback after a drag is in progress.
@ -272,7 +264,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
if (handlingDragInput) if (handlingDragInput)
editorClock.Stop(); editorClock.Stop();
ScrollTo((float)(editorClock.CurrentTime / track.Length) * Content.DrawWidth, false); ScrollTo((float)(editorClock.CurrentTime / editorClock.TrackLength) * Content.DrawWidth, false);
} }
protected override bool OnMouseDown(MouseDownEvent e) protected override bool OnMouseDown(MouseDownEvent e)
@ -310,12 +302,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
/// <summary> /// <summary>
/// The total amount of time visible on the timeline. /// The total amount of time visible on the timeline.
/// </summary> /// </summary>
public double VisibleRange => track.Length / Zoom; public double VisibleRange => editorClock.TrackLength / Zoom;
public SnapResult FindSnappedPositionAndTime(Vector2 screenSpacePosition, SnapType snapType = SnapType.All) => public SnapResult FindSnappedPositionAndTime(Vector2 screenSpacePosition, SnapType snapType = SnapType.All) =>
new SnapResult(screenSpacePosition, beatSnapProvider.SnapTime(getTimeFromPosition(Content.ToLocalSpace(screenSpacePosition)))); new SnapResult(screenSpacePosition, beatSnapProvider.SnapTime(getTimeFromPosition(Content.ToLocalSpace(screenSpacePosition))));
private double getTimeFromPosition(Vector2 localPosition) => private double getTimeFromPosition(Vector2 localPosition) =>
(localPosition.X / Content.DrawWidth) * track.Length; (localPosition.X / Content.DrawWidth) * editorClock.TrackLength;
} }
} }

View File

@ -220,7 +220,7 @@ namespace osu.Game.Screens.Edit
} }
// Todo: should probably be done at a DrawableRuleset level to share logic with Player. // Todo: should probably be done at a DrawableRuleset level to share logic with Player.
clock = new EditorClock(playableBeatmap, beatDivisor) { IsCoupled = false }; clock = new EditorClock(playableBeatmap, beatDivisor);
clock.ChangeSource(loadableBeatmap.Track); clock.ChangeSource(loadableBeatmap.Track);
dependencies.CacheAs(clock); dependencies.CacheAs(clock);

View File

@ -4,10 +4,12 @@
#nullable disable #nullable disable
using System; using System;
using System.Diagnostics;
using System.Linq; using System.Linq;
using osu.Framework.Audio.Track; using osu.Framework.Audio.Track;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transforms; using osu.Framework.Graphics.Transforms;
using osu.Framework.Timing; using osu.Framework.Timing;
using osu.Framework.Utils; using osu.Framework.Utils;
@ -19,7 +21,7 @@ namespace osu.Game.Screens.Edit
/// <summary> /// <summary>
/// A decoupled clock which adds editor-specific functionality, such as snapping to a user-defined beat divisor. /// A decoupled clock which adds editor-specific functionality, such as snapping to a user-defined beat divisor.
/// </summary> /// </summary>
public class EditorClock : Component, IFrameBasedClock, IAdjustableClock, ISourceChangeableClock public class EditorClock : CompositeComponent, IFrameBasedClock, IAdjustableClock, ISourceChangeableClock
{ {
public IBindable<Track> Track => track; public IBindable<Track> Track => track;
@ -33,7 +35,7 @@ namespace osu.Game.Screens.Edit
private readonly BindableBeatDivisor beatDivisor; private readonly BindableBeatDivisor beatDivisor;
private readonly DecoupleableInterpolatingFramedClock underlyingClock; private readonly FramedBeatmapClock underlyingClock;
private bool playbackFinished; private bool playbackFinished;
@ -52,7 +54,8 @@ namespace osu.Game.Screens.Edit
this.beatDivisor = beatDivisor ?? new BindableBeatDivisor(); this.beatDivisor = beatDivisor ?? new BindableBeatDivisor();
underlyingClock = new DecoupleableInterpolatingFramedClock(); underlyingClock = new FramedBeatmapClock(applyOffsets: true) { IsCoupled = false };
AddInternal(underlyingClock);
} }
/// <summary> /// <summary>
@ -155,6 +158,8 @@ namespace osu.Game.Screens.Edit
public double CurrentTime => underlyingClock.CurrentTime; public double CurrentTime => underlyingClock.CurrentTime;
public double TotalAppliedOffset => underlyingClock.TotalAppliedOffset;
public void Reset() public void Reset()
{ {
ClearTransforms(); ClearTransforms();
@ -219,18 +224,7 @@ namespace osu.Game.Screens.Edit
public void ProcessFrame() public void ProcessFrame()
{ {
underlyingClock.ProcessFrame(); // Noop to ensure an external consumer doesn't process the internal clock an extra time.
playbackFinished = CurrentTime >= TrackLength;
if (playbackFinished)
{
if (IsRunning)
underlyingClock.Stop();
if (CurrentTime > TrackLength)
underlyingClock.Seek(TrackLength);
}
} }
public double ElapsedFrameTime => underlyingClock.ElapsedFrameTime; public double ElapsedFrameTime => underlyingClock.ElapsedFrameTime;
@ -247,18 +241,26 @@ namespace osu.Game.Screens.Edit
public IClock Source => underlyingClock.Source; public IClock Source => underlyingClock.Source;
public bool IsCoupled
{
get => underlyingClock.IsCoupled;
set => underlyingClock.IsCoupled = value;
}
private const double transform_time = 300; private const double transform_time = 300;
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
// EditorClock wasn't being added in many places. This gives us more certainty that it is.
Debug.Assert(underlyingClock.LoadState > LoadState.NotLoaded);
playbackFinished = CurrentTime >= TrackLength;
if (playbackFinished)
{
if (IsRunning)
underlyingClock.Stop();
if (CurrentTime > TrackLength)
underlyingClock.Seek(TrackLength);
}
updateSeekingState(); updateSeekingState();
} }

View File

@ -6,6 +6,8 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Overlays; using osu.Game.Overlays;
@ -24,30 +26,39 @@ namespace osu.Game.Tests.Visual
protected readonly BindableBeatDivisor BeatDivisor = new BindableBeatDivisor(); protected readonly BindableBeatDivisor BeatDivisor = new BindableBeatDivisor();
[Cached] protected EditorClock EditorClock;
protected new readonly EditorClock Clock;
private readonly Bindable<double> frequencyAdjustment = new BindableDouble(1); private readonly Bindable<double> frequencyAdjustment = new BindableDouble(1);
private IBeatmap editorClockBeatmap;
protected virtual bool ScrollUsingMouseWheel => true; protected virtual bool ScrollUsingMouseWheel => true;
protected EditorClockTestScene() protected override Container<Drawable> Content => content;
{
Clock = new EditorClock(new Beatmap(), BeatDivisor) { IsCoupled = false }; private readonly Container<Drawable> content = new Container { RelativeSizeAxes = Axes.Both };
}
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{ {
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
editorClockBeatmap = CreateEditorClockBeatmap();
base.Content.AddRange(new Drawable[]
{
EditorClock = new EditorClock(editorClockBeatmap, BeatDivisor),
content
});
dependencies.Cache(BeatDivisor); dependencies.Cache(BeatDivisor);
dependencies.CacheAs(Clock); dependencies.CacheAs(EditorClock);
return dependencies; return dependencies;
} }
protected override void LoadComplete() protected override void LoadComplete()
{ {
Beatmap.Value = CreateWorkingBeatmap(editorClockBeatmap);
base.LoadComplete(); base.LoadComplete();
Beatmap.BindValueChanged(beatmapChanged, true); Beatmap.BindValueChanged(beatmapChanged, true);
@ -55,22 +66,13 @@ namespace osu.Game.Tests.Visual
AddSliderStep("editor clock rate", 0.0, 2.0, 1.0, v => frequencyAdjustment.Value = v); AddSliderStep("editor clock rate", 0.0, 2.0, 1.0, v => frequencyAdjustment.Value = v);
} }
protected virtual IBeatmap CreateEditorClockBeatmap() => new Beatmap();
private void beatmapChanged(ValueChangedEvent<WorkingBeatmap> e) private void beatmapChanged(ValueChangedEvent<WorkingBeatmap> e)
{ {
e.OldValue?.Track.RemoveAdjustment(AdjustableProperty.Frequency, frequencyAdjustment); e.OldValue?.Track.RemoveAdjustment(AdjustableProperty.Frequency, frequencyAdjustment);
Clock.Beatmap = e.NewValue.Beatmap;
Clock.ChangeSource(e.NewValue.Track);
Clock.ProcessFrame();
e.NewValue.Track.AddAdjustment(AdjustableProperty.Frequency, frequencyAdjustment); e.NewValue.Track.AddAdjustment(AdjustableProperty.Frequency, frequencyAdjustment);
} EditorClock.ChangeSource(e.NewValue.Track);
protected override void Update()
{
base.Update();
Clock.ProcessFrame();
} }
protected override bool OnScroll(ScrollEvent e) protected override bool OnScroll(ScrollEvent e)
@ -79,9 +81,9 @@ namespace osu.Game.Tests.Visual
return false; return false;
if (e.ScrollDelta.Y > 0) if (e.ScrollDelta.Y > 0)
Clock.SeekBackward(true); EditorClock.SeekBackward(true);
else else
Clock.SeekForward(true); EditorClock.SeekForward(true);
return true; return true;
} }

View File

@ -30,10 +30,15 @@ namespace osu.Game.Tests.Visual
{ {
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.CacheAs(new EditorClock());
var playable = GetPlayableBeatmap(); var playable = GetPlayableBeatmap();
dependencies.CacheAs(new EditorBeatmap(playable));
var editorClock = new EditorClock();
base.Content.Add(editorClock);
dependencies.CacheAs(editorClock);
var editorBeatmap = new EditorBeatmap(playable);
// Not adding to hierarchy as we don't satisfy its dependencies. Probably not good.
dependencies.CacheAs(editorBeatmap);
return dependencies; return dependencies;
} }

View File

@ -1,9 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -19,19 +16,23 @@ namespace osu.Game.Tests.Visual
[Cached] [Cached]
private readonly EditorClock editorClock = new EditorClock(); private readonly EditorClock editorClock = new EditorClock();
protected override Container<Drawable> Content => content ?? base.Content; protected override Container<Drawable> Content => content;
private readonly Container content; private readonly Container content;
protected SelectionBlueprintTestScene() protected SelectionBlueprintTestScene()
{ {
base.Content.Add(content = new Container base.Content.AddRange(new Drawable[]
{ {
Clock = new FramedClock(new StopwatchClock()), editorClock,
RelativeSizeAxes = Axes.Both content = new Container
{
Clock = new FramedClock(new StopwatchClock()),
RelativeSizeAxes = Axes.Both
}
}); });
} }
protected void AddBlueprint(HitObjectSelectionBlueprint blueprint, [CanBeNull] DrawableHitObject drawableObject = null) protected void AddBlueprint(HitObjectSelectionBlueprint blueprint, DrawableHitObject? drawableObject = null)
{ {
Add(blueprint.With(d => Add(blueprint.With(d =>
{ {