From 5e742eb4663a38db9389e34d341fd0a596082e25 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 15 Mar 2018 17:10:08 +0900 Subject: [PATCH 1/8] Move editor constructions to BDL load --- osu.Game/Screens/Edit/Editor.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index bb43099352..f1b6419741 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -26,12 +26,13 @@ namespace osu.Game.Screens.Edit public override bool ShowOverlaysOnEnter => false; - private readonly Box bottomBackground; - private readonly Container screenContainer; + private Box bottomBackground; + private Container screenContainer; private EditorScreen currentScreen; - public Editor() + [BackgroundDependencyLoader] + private void load(OsuColour colours) { EditorMenuBar menuBar; TimeInfoContainer timeInfo; @@ -130,12 +131,9 @@ namespace osu.Game.Screens.Edit timeline.Beatmap.BindTo(Beatmap); playback.Beatmap.BindTo(Beatmap); menuBar.Mode.ValueChanged += onModeChanged; - } - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { bottomBackground.Colour = colours.Gray2; + } private void exportBeatmap() From c8f6a6980be01eb88b56757318ca324479f77a65 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 15 Mar 2018 17:19:47 +0900 Subject: [PATCH 2/8] Move clock construction to Editor --- .../Edit/OsuHitObjectComposer.cs | 5 +++-- osu.Game.Rulesets.Osu/OsuRuleset.cs | 3 ++- osu.Game/Rulesets/Edit/HitObjectComposer.cs | 18 +++++++----------- osu.Game/Rulesets/Ruleset.cs | 3 ++- osu.Game/Screens/Edit/Editor.cs | 10 +++++++++- .../Screens/Edit/Screens/Compose/Compose.cs | 18 +++++++++++++++--- 6 files changed, 38 insertions(+), 19 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs index 70d49a6b4f..f8991e050b 100644 --- a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs +++ b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using osu.Framework.Graphics; +using osu.Framework.Timing; using osu.Game.Beatmaps; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit.Layers.Selection; @@ -16,8 +17,8 @@ namespace osu.Game.Rulesets.Osu.Edit { public class OsuHitObjectComposer : HitObjectComposer { - public OsuHitObjectComposer(Ruleset ruleset) - : base(ruleset) + public OsuHitObjectComposer(Ruleset ruleset, IAdjustableClock adjustableClock, IFrameBasedClock framedClock) + : base(ruleset, adjustableClock, framedClock) { } diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index d407835a96..5dcc8e8a6e 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -13,6 +13,7 @@ using System.Linq; using osu.Framework.Graphics; using osu.Game.Overlays.Settings; using osu.Framework.Input.Bindings; +using osu.Framework.Timing; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Osu.Scoring; using osu.Game.Rulesets.Osu.Edit; @@ -137,7 +138,7 @@ namespace osu.Game.Rulesets.Osu public override PerformanceCalculator CreatePerformanceCalculator(Beatmap beatmap, Score score) => new OsuPerformanceCalculator(this, beatmap, score); - public override HitObjectComposer CreateHitObjectComposer() => new OsuHitObjectComposer(this); + public override HitObjectComposer CreateHitObjectComposer(IAdjustableClock adjustableClock, IFrameBasedClock framedClock) => new OsuHitObjectComposer(this, adjustableClock, framedClock); public override string Description => "osu!"; diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index 8934448301..9499e15e92 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -32,12 +32,15 @@ namespace osu.Game.Rulesets.Edit private readonly Bindable beatmap = new Bindable(); - private IAdjustableClock sourceClock; - private DecoupleableInterpolatingFramedClock adjustableClock; + private readonly IAdjustableClock adjustableClock; + private readonly IFrameBasedClock framedClock; - protected HitObjectComposer(Ruleset ruleset) + protected HitObjectComposer(Ruleset ruleset, IAdjustableClock adjustableClock, IFrameBasedClock framedClock) { this.ruleset = ruleset; + this.adjustableClock = adjustableClock; + this.framedClock = framedClock; + RelativeSizeAxes = Axes.Both; } @@ -49,14 +52,7 @@ namespace osu.Game.Rulesets.Edit try { rulesetContainer = CreateRulesetContainer(ruleset, beatmap.Value); - - // TODO: should probably be done at a RulesetContainer level to share logic with Player. - sourceClock = (IAdjustableClock)beatmap.Value.Track ?? new StopwatchClock(); - adjustableClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; - adjustableClock.ChangeSource(sourceClock); - - rulesetContainer.Clock = adjustableClock; - + rulesetContainer.Clock = framedClock; } catch (Exception e) { diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index cba849a491..fc0c7966c6 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Graphics; using osu.Framework.Input.Bindings; +using osu.Framework.Timing; using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Overlays.Settings; @@ -53,7 +54,7 @@ namespace osu.Game.Rulesets public virtual PerformanceCalculator CreatePerformanceCalculator(Beatmap beatmap, Score score) => null; - public virtual HitObjectComposer CreateHitObjectComposer() => null; + public virtual HitObjectComposer CreateHitObjectComposer(IAdjustableClock adjustableClock, IFrameBasedClock framedClock) => null; public virtual Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.fa_question_circle }; diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index f1b6419741..1a145478eb 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -12,6 +12,7 @@ using osu.Game.Screens.Edit.Menus; using osu.Game.Screens.Edit.Components.Timelines.Summary; using osu.Framework.Allocation; using osu.Framework.Graphics.UserInterface; +using osu.Framework.Timing; using osu.Game.Graphics.UserInterface; using osu.Game.Screens.Edit.Screens; using osu.Game.Screens.Edit.Screens.Compose; @@ -31,9 +32,16 @@ namespace osu.Game.Screens.Edit private EditorScreen currentScreen; + private DecoupleableInterpolatingFramedClock adjustableClock; + [BackgroundDependencyLoader] private void load(OsuColour colours) { + // TODO: should probably be done at a RulesetContainer level to share logic with Player. + var sourceClock = (IAdjustableClock)Beatmap.Value.Track ?? new StopwatchClock(); + adjustableClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; + adjustableClock.ChangeSource(sourceClock); + EditorMenuBar menuBar; TimeInfoContainer timeInfo; SummaryTimeline timeline; @@ -148,7 +156,7 @@ namespace osu.Game.Screens.Edit switch (mode) { case EditorScreenMode.Compose: - currentScreen = new Compose(); + currentScreen = new Compose(adjustableClock, adjustableClock); break; case EditorScreenMode.Design: currentScreen = new Design(); diff --git a/osu.Game/Screens/Edit/Screens/Compose/Compose.cs b/osu.Game/Screens/Edit/Screens/Compose/Compose.cs index d42c0bfdac..b0fad58084 100644 --- a/osu.Game/Screens/Edit/Screens/Compose/Compose.cs +++ b/osu.Game/Screens/Edit/Screens/Compose/Compose.cs @@ -1,12 +1,14 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Framework.Allocation; using OpenTK.Graphics; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Logging; +using osu.Framework.Timing; using osu.Game.Beatmaps; using osu.Game.Screens.Edit.Screens.Compose.Timeline; @@ -17,9 +19,19 @@ namespace osu.Game.Screens.Edit.Screens.Compose private const float vertical_margins = 10; private const float horizontal_margins = 20; - private readonly Container composerContainer; + private Container composerContainer; - public Compose() + private readonly IAdjustableClock adjustableClock; + private readonly IFrameBasedClock framedClock; + + public Compose(IAdjustableClock adjustableClock, IFrameBasedClock framedClock) + { + this.adjustableClock = adjustableClock; + this.framedClock = framedClock; + } + + [BackgroundDependencyLoader] + private void load() { ScrollableTimeline timeline; Children = new Drawable[] @@ -90,7 +102,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose return; } - var composer = ruleset.CreateHitObjectComposer(); + var composer = ruleset.CreateHitObjectComposer(adjustableClock, framedClock); if (composer == null) { Logger.Log($"Ruleset {ruleset.Description} doesn't support hitobject composition."); From d05947ef481f09749af41d59cb27136a7404a80a Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 15 Mar 2018 18:08:37 +0900 Subject: [PATCH 3/8] Pass adjustable clocks to components, rather than relying on the track --- .../Screens/Edit/Components/PlaybackControl.cs | 17 +++++++++++------ .../Edit/Components/TimeInfoContainer.cs | 9 +++++++-- .../Timelines/Summary/Parts/MarkerPart.cs | 11 ++++++++--- .../Timelines/Summary/SummaryTimeline.cs | 5 +++-- osu.Game/Screens/Edit/Editor.cs | 6 +++--- .../Screens/Edit/Screens/Compose/Compose.cs | 9 +-------- 6 files changed, 33 insertions(+), 24 deletions(-) diff --git a/osu.Game/Screens/Edit/Components/PlaybackControl.cs b/osu.Game/Screens/Edit/Components/PlaybackControl.cs index 05e47ef5b1..71154006ce 100644 --- a/osu.Game/Screens/Edit/Components/PlaybackControl.cs +++ b/osu.Game/Screens/Edit/Components/PlaybackControl.cs @@ -9,6 +9,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.UserInterface; using osu.Framework.Input; +using osu.Framework.Timing; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; @@ -19,8 +20,12 @@ namespace osu.Game.Screens.Edit.Components { private readonly IconButton playButton; - public PlaybackControl() + private readonly IAdjustableClock adjustableClock; + + public PlaybackControl(IAdjustableClock adjustableClock) { + this.adjustableClock = adjustableClock; + PlaybackTabControl tabs; Children = new Drawable[] @@ -54,22 +59,22 @@ namespace osu.Game.Screens.Edit.Components } }; - tabs.Current.ValueChanged += newValue => Track.Tempo.Value = newValue; + tabs.Current.ValueChanged += newValue => Beatmap.Value.Track.Tempo.Value = newValue; } private void togglePause() { - if (Track.IsRunning) - Track.Stop(); + if (adjustableClock.IsRunning) + adjustableClock.Stop(); else - Track.Start(); + adjustableClock.Start(); } protected override void Update() { base.Update(); - playButton.Icon = Track.IsRunning ? FontAwesome.fa_pause_circle_o : FontAwesome.fa_play_circle_o; + playButton.Icon = adjustableClock.IsRunning ? FontAwesome.fa_pause_circle_o : FontAwesome.fa_play_circle_o; } private class PlaybackTabControl : OsuTabControl diff --git a/osu.Game/Screens/Edit/Components/TimeInfoContainer.cs b/osu.Game/Screens/Edit/Components/TimeInfoContainer.cs index 9a78e6e189..6bbaad432b 100644 --- a/osu.Game/Screens/Edit/Components/TimeInfoContainer.cs +++ b/osu.Game/Screens/Edit/Components/TimeInfoContainer.cs @@ -4,6 +4,7 @@ using osu.Framework.Graphics; using osu.Game.Graphics.Sprites; using System; +using osu.Framework.Timing; namespace osu.Game.Screens.Edit.Components { @@ -13,8 +14,12 @@ namespace osu.Game.Screens.Edit.Components private readonly OsuSpriteText trackTimer; - public TimeInfoContainer() + private readonly IAdjustableClock adjustableClock; + + public TimeInfoContainer(IAdjustableClock adjustableClock) { + this.adjustableClock = adjustableClock; + Children = new Drawable[] { trackTimer = new OsuSpriteText @@ -32,7 +37,7 @@ namespace osu.Game.Screens.Edit.Components { base.Update(); - trackTimer.Text = TimeSpan.FromMilliseconds(Track.CurrentTime).ToString(@"mm\:ss\:fff"); + trackTimer.Text = TimeSpan.FromMilliseconds(adjustableClock.CurrentTime).ToString(@"mm\:ss\:fff"); } } } diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/MarkerPart.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/MarkerPart.cs index c7f40327a9..b249713581 100644 --- a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/MarkerPart.cs +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/MarkerPart.cs @@ -7,6 +7,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Input; +using osu.Framework.Timing; using osu.Game.Beatmaps; using osu.Game.Graphics; @@ -19,8 +20,12 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts { private readonly Drawable marker; - public MarkerPart() + private readonly IAdjustableClock adjustableClock; + + public MarkerPart(IAdjustableClock adjustableClock) { + this.adjustableClock = adjustableClock; + Add(marker = new MarkerVisualisation()); } @@ -53,12 +58,12 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts seekTo(markerPos / DrawWidth * Beatmap.Value.Track.Length); } - private void seekTo(double time) => Beatmap.Value?.Track.Seek(time); + private void seekTo(double time) => adjustableClock.Seek(time); protected override void Update() { base.Update(); - marker.X = (float)(Beatmap.Value?.Track.CurrentTime ?? 0); + marker.X = (float)adjustableClock.CurrentTime; } protected override void LoadBeatmap(WorkingBeatmap beatmap) diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs index 8a472dc357..9921c24083 100644 --- a/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs @@ -6,6 +6,7 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; +using osu.Framework.Timing; using osu.Game.Graphics; using osu.Game.Screens.Edit.Components.Timelines.Summary.Parts; @@ -18,13 +19,13 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary { private readonly Drawable timelineBar; - public SummaryTimeline() + public SummaryTimeline(IAdjustableClock adjustableClock) { TimelinePart markerPart, controlPointPart, bookmarkPart, breakPart; Children = new[] { - markerPart = new MarkerPart { RelativeSizeAxes = Axes.Both }, + markerPart = new MarkerPart(adjustableClock) { RelativeSizeAxes = Axes.Both }, controlPointPart = new ControlPointPart { Anchor = Anchor.Centre, diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 1a145478eb..cc7f77e770 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -115,9 +115,9 @@ namespace osu.Game.Screens.Edit { RelativeSizeAxes = Axes.Both, Padding = new MarginPadding { Right = 10 }, - Child = timeInfo = new TimeInfoContainer { RelativeSizeAxes = Axes.Both }, + Child = timeInfo = new TimeInfoContainer(adjustableClock) { RelativeSizeAxes = Axes.Both }, }, - timeline = new SummaryTimeline + timeline = new SummaryTimeline(adjustableClock) { RelativeSizeAxes = Axes.Both, }, @@ -125,7 +125,7 @@ namespace osu.Game.Screens.Edit { RelativeSizeAxes = Axes.Both, Padding = new MarginPadding { Left = 10 }, - Child = playback = new PlaybackControl { RelativeSizeAxes = Axes.Both }, + Child = playback = new PlaybackControl(adjustableClock) { RelativeSizeAxes = Axes.Both }, } }, } diff --git a/osu.Game/Screens/Edit/Screens/Compose/Compose.cs b/osu.Game/Screens/Edit/Screens/Compose/Compose.cs index b0fad58084..9a720e1608 100644 --- a/osu.Game/Screens/Edit/Screens/Compose/Compose.cs +++ b/osu.Game/Screens/Edit/Screens/Compose/Compose.cs @@ -9,7 +9,6 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Logging; using osu.Framework.Timing; -using osu.Game.Beatmaps; using osu.Game.Screens.Edit.Screens.Compose.Timeline; namespace osu.Game.Screens.Edit.Screens.Compose @@ -87,14 +86,8 @@ namespace osu.Game.Screens.Edit.Screens.Compose }; timeline.Beatmap.BindTo(Beatmap); - Beatmap.ValueChanged += beatmapChanged; - } - private void beatmapChanged(WorkingBeatmap newBeatmap) - { - composerContainer.Clear(); - - var ruleset = newBeatmap.BeatmapInfo.Ruleset?.CreateInstance(); + var ruleset = Beatmap.Value.BeatmapInfo.Ruleset?.CreateInstance(); if (ruleset == null) { Logger.Log("Beatmap doesn't have a ruleset assigned."); From 8fbaa86e640de70eb86cd043ebe4e53225e88c63 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 15 Mar 2018 18:24:57 +0900 Subject: [PATCH 4/8] Fix testcases --- .../Visual/TestCaseEditorCompose.cs | 5 +- .../Visual/TestCaseEditorSeekSnapping.cs | 131 +++++++++--------- .../Visual/TestCaseEditorSelectionLayer.cs | 5 +- .../Visual/TestCaseEditorSummaryTimeline.cs | 5 +- .../Visual/TestCasePlaybackControl.cs | 5 +- 5 files changed, 84 insertions(+), 67 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseEditorCompose.cs b/osu.Game.Tests/Visual/TestCaseEditorCompose.cs index 15bccac172..edc790e809 100644 --- a/osu.Game.Tests/Visual/TestCaseEditorCompose.cs +++ b/osu.Game.Tests/Visual/TestCaseEditorCompose.cs @@ -4,6 +4,7 @@ using System; using NUnit.Framework; using osu.Framework.Allocation; +using osu.Framework.Timing; using osu.Game.Beatmaps; using osu.Game.Screens.Edit.Screens.Compose; @@ -19,7 +20,9 @@ namespace osu.Game.Tests.Visual { random = new Random(1337); - Add(compose = new Compose()); + var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; + + Add(compose = new Compose(clock, clock)); AddStep("Next beatmap", nextBeatmap); } diff --git a/osu.Game.Tests/Visual/TestCaseEditorSeekSnapping.cs b/osu.Game.Tests/Visual/TestCaseEditorSeekSnapping.cs index 2d60c6848d..3b4b31c92a 100644 --- a/osu.Game.Tests/Visual/TestCaseEditorSeekSnapping.cs +++ b/osu.Game.Tests/Visual/TestCaseEditorSeekSnapping.cs @@ -10,6 +10,7 @@ using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; +using osu.Framework.Timing; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; using osu.Game.Rulesets; @@ -30,9 +31,13 @@ namespace osu.Game.Tests.Visual private Track track; private HitObjectComposer composer; + private DecoupleableInterpolatingFramedClock clock; + [BackgroundDependencyLoader] private void load(OsuGameBase osuGame) { + clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; + var testBeatmap = new Beatmap { ControlPointInfo = new ControlPointInfo @@ -62,8 +67,8 @@ namespace osu.Game.Tests.Visual RelativeSizeAxes = Axes.Both, Content = new[] { - new Drawable[] { composer = new TestHitObjectComposer(new OsuRuleset()) }, - new Drawable[] { new TimingPointVisualiser(testBeatmap, track) }, + new Drawable[] { composer = new TestHitObjectComposer(new OsuRuleset(), clock, clock) }, + new Drawable[] { new TimingPointVisualiser(testBeatmap, track) { Clock = clock } }, }, RowDimensions = new[] { @@ -92,17 +97,17 @@ namespace osu.Game.Tests.Visual // Forwards AddStep("Seek(0)", () => composer.SeekTo(0)); - AddAssert("Time = 0", () => track.CurrentTime == 0); + AddAssert("Time = 0", () => clock.CurrentTime == 0); AddStep("Seek(33)", () => composer.SeekTo(33)); - AddAssert("Time = 33", () => track.CurrentTime == 33); + AddAssert("Time = 33", () => clock.CurrentTime == 33); AddStep("Seek(89)", () => composer.SeekTo(89)); - AddAssert("Time = 89", () => track.CurrentTime == 89); + AddAssert("Time = 89", () => clock.CurrentTime == 89); // Backwards AddStep("Seek(25)", () => composer.SeekTo(25)); - AddAssert("Time = 25", () => track.CurrentTime == 25); + AddAssert("Time = 25", () => clock.CurrentTime == 25); AddStep("Seek(0)", () => composer.SeekTo(0)); - AddAssert("Time = 0", () => track.CurrentTime == 0); + AddAssert("Time = 0", () => clock.CurrentTime == 0); } /// @@ -114,19 +119,19 @@ namespace osu.Game.Tests.Visual reset(); AddStep("Seek(0), Snap", () => composer.SeekTo(0, true)); - AddAssert("Time = 0", () => track.CurrentTime == 0); + AddAssert("Time = 0", () => clock.CurrentTime == 0); AddStep("Seek(50), Snap", () => composer.SeekTo(50, true)); - AddAssert("Time = 50", () => track.CurrentTime == 50); + AddAssert("Time = 50", () => clock.CurrentTime == 50); AddStep("Seek(100), Snap", () => composer.SeekTo(100, true)); - AddAssert("Time = 100", () => track.CurrentTime == 100); + AddAssert("Time = 100", () => clock.CurrentTime == 100); AddStep("Seek(175), Snap", () => composer.SeekTo(175, true)); - AddAssert("Time = 175", () => track.CurrentTime == 175); + AddAssert("Time = 175", () => clock.CurrentTime == 175); AddStep("Seek(350), Snap", () => composer.SeekTo(350, true)); - AddAssert("Time = 350", () => track.CurrentTime == 350); + AddAssert("Time = 350", () => clock.CurrentTime == 350); AddStep("Seek(400), Snap", () => composer.SeekTo(400, true)); - AddAssert("Time = 400", () => track.CurrentTime == 400); + AddAssert("Time = 400", () => clock.CurrentTime == 400); AddStep("Seek(450), Snap", () => composer.SeekTo(450, true)); - AddAssert("Time = 450", () => track.CurrentTime == 450); + AddAssert("Time = 450", () => clock.CurrentTime == 450); } /// @@ -139,17 +144,17 @@ namespace osu.Game.Tests.Visual reset(); AddStep("Seek(24), Snap", () => composer.SeekTo(24, true)); - AddAssert("Time = 0", () => track.CurrentTime == 0); + AddAssert("Time = 0", () => clock.CurrentTime == 0); AddStep("Seek(26), Snap", () => composer.SeekTo(26, true)); - AddAssert("Time = 50", () => track.CurrentTime == 50); + AddAssert("Time = 50", () => clock.CurrentTime == 50); AddStep("Seek(150), Snap", () => composer.SeekTo(150, true)); - AddAssert("Time = 100", () => track.CurrentTime == 100); + AddAssert("Time = 100", () => clock.CurrentTime == 100); AddStep("Seek(170), Snap", () => composer.SeekTo(170, true)); - AddAssert("Time = 175", () => track.CurrentTime == 175); + AddAssert("Time = 175", () => clock.CurrentTime == 175); AddStep("Seek(274), Snap", () => composer.SeekTo(274, true)); - AddAssert("Time = 175", () => track.CurrentTime == 175); + AddAssert("Time = 175", () => clock.CurrentTime == 175); AddStep("Seek(276), Snap", () => composer.SeekTo(276, true)); - AddAssert("Time = 350", () => track.CurrentTime == 350); + AddAssert("Time = 350", () => clock.CurrentTime == 350); } /// @@ -160,15 +165,15 @@ namespace osu.Game.Tests.Visual reset(); AddStep("SeekForward", () => composer.SeekForward()); - AddAssert("Time = 50", () => track.CurrentTime == 50); + AddAssert("Time = 50", () => clock.CurrentTime == 50); AddStep("SeekForward", () => composer.SeekForward()); - AddAssert("Time = 100", () => track.CurrentTime == 100); + AddAssert("Time = 100", () => clock.CurrentTime == 100); AddStep("SeekForward", () => composer.SeekForward()); - AddAssert("Time = 200", () => track.CurrentTime == 200); + AddAssert("Time = 200", () => clock.CurrentTime == 200); AddStep("SeekForward", () => composer.SeekForward()); - AddAssert("Time = 400", () => track.CurrentTime == 400); + AddAssert("Time = 400", () => clock.CurrentTime == 400); AddStep("SeekForward", () => composer.SeekForward()); - AddAssert("Time = 450", () => track.CurrentTime == 450); + AddAssert("Time = 450", () => clock.CurrentTime == 450); } /// @@ -179,17 +184,17 @@ namespace osu.Game.Tests.Visual reset(); AddStep("SeekForward, Snap", () => composer.SeekForward(true)); - AddAssert("Time = 50", () => track.CurrentTime == 50); + AddAssert("Time = 50", () => clock.CurrentTime == 50); AddStep("SeekForward, Snap", () => composer.SeekForward(true)); - AddAssert("Time = 100", () => track.CurrentTime == 100); + AddAssert("Time = 100", () => clock.CurrentTime == 100); AddStep("SeekForward, Snap", () => composer.SeekForward(true)); - AddAssert("Time = 175", () => track.CurrentTime == 175); + AddAssert("Time = 175", () => clock.CurrentTime == 175); AddStep("SeekForward, Snap", () => composer.SeekForward(true)); - AddAssert("Time = 350", () => track.CurrentTime == 350); + AddAssert("Time = 350", () => clock.CurrentTime == 350); AddStep("SeekForward, Snap", () => composer.SeekForward(true)); - AddAssert("Time = 400", () => track.CurrentTime == 400); + AddAssert("Time = 400", () => clock.CurrentTime == 400); AddStep("SeekForward, Snap", () => composer.SeekForward(true)); - AddAssert("Time = 450", () => track.CurrentTime == 450); + AddAssert("Time = 450", () => clock.CurrentTime == 450); } /// @@ -202,28 +207,28 @@ namespace osu.Game.Tests.Visual AddStep("Seek(49)", () => composer.SeekTo(49)); AddStep("SeekForward, Snap", () => composer.SeekForward(true)); - AddAssert("Time = 50", () => track.CurrentTime == 50); + AddAssert("Time = 50", () => clock.CurrentTime == 50); AddStep("Seek(49.999)", () => composer.SeekTo(49.999)); AddStep("SeekForward, Snap", () => composer.SeekForward(true)); - AddAssert("Time = 50", () => track.CurrentTime == 50); + AddAssert("Time = 50", () => clock.CurrentTime == 50); AddStep("Seek(99)", () => composer.SeekTo(99)); AddStep("SeekForward, Snap", () => composer.SeekForward(true)); - AddAssert("Time = 100", () => track.CurrentTime == 100); + AddAssert("Time = 100", () => clock.CurrentTime == 100); AddStep("Seek(99.999)", () => composer.SeekTo(99.999)); AddStep("SeekForward, Snap", () => composer.SeekForward(true)); - AddAssert("Time = 100", () => track.CurrentTime == 100); + AddAssert("Time = 100", () => clock.CurrentTime == 100); AddStep("Seek(174)", () => composer.SeekTo(174)); AddStep("SeekForward, Snap", () => composer.SeekForward(true)); - AddAssert("Time = 175", () => track.CurrentTime == 175); + AddAssert("Time = 175", () => clock.CurrentTime == 175); AddStep("Seek(349)", () => composer.SeekTo(349)); AddStep("SeekForward, Snap", () => composer.SeekForward(true)); - AddAssert("Time = 350", () => track.CurrentTime == 350); + AddAssert("Time = 350", () => clock.CurrentTime == 350); AddStep("Seek(399)", () => composer.SeekTo(399)); AddStep("SeekForward, Snap", () => composer.SeekForward(true)); - AddAssert("Time = 400", () => track.CurrentTime == 400); + AddAssert("Time = 400", () => clock.CurrentTime == 400); AddStep("Seek(449)", () => composer.SeekTo(449)); AddStep("SeekForward, Snap", () => composer.SeekForward(true)); - AddAssert("Time = 450", () => track.CurrentTime == 450); + AddAssert("Time = 450", () => clock.CurrentTime == 450); } /// @@ -235,17 +240,17 @@ namespace osu.Game.Tests.Visual AddStep("Seek(450)", () => composer.SeekTo(450)); AddStep("SeekBackward", () => composer.SeekBackward()); - AddAssert("Time = 425", () => track.CurrentTime == 425); + AddAssert("Time = 425", () => clock.CurrentTime == 425); AddStep("SeekBackward", () => composer.SeekBackward()); - AddAssert("Time = 375", () => track.CurrentTime == 375); + AddAssert("Time = 375", () => clock.CurrentTime == 375); AddStep("SeekBackward", () => composer.SeekBackward()); - AddAssert("Time = 325", () => track.CurrentTime == 325); + AddAssert("Time = 325", () => clock.CurrentTime == 325); AddStep("SeekBackward", () => composer.SeekBackward()); - AddAssert("Time = 125", () => track.CurrentTime == 125); + AddAssert("Time = 125", () => clock.CurrentTime == 125); AddStep("SeekBackward", () => composer.SeekBackward()); - AddAssert("Time = 25", () => track.CurrentTime == 25); + AddAssert("Time = 25", () => clock.CurrentTime == 25); AddStep("SeekBackward", () => composer.SeekBackward()); - AddAssert("Time = 0", () => track.CurrentTime == 0); + AddAssert("Time = 0", () => clock.CurrentTime == 0); } /// @@ -257,17 +262,17 @@ namespace osu.Game.Tests.Visual AddStep("Seek(450)", () => composer.SeekTo(450)); AddStep("SeekBackward, Snap", () => composer.SeekBackward(true)); - AddAssert("Time = 400", () => track.CurrentTime == 400); + AddAssert("Time = 400", () => clock.CurrentTime == 400); AddStep("SeekBackward, Snap", () => composer.SeekBackward(true)); - AddAssert("Time = 350", () => track.CurrentTime == 350); + AddAssert("Time = 350", () => clock.CurrentTime == 350); AddStep("SeekBackward, Snap", () => composer.SeekBackward(true)); - AddAssert("Time = 175", () => track.CurrentTime == 175); + AddAssert("Time = 175", () => clock.CurrentTime == 175); AddStep("SeekBackward, Snap", () => composer.SeekBackward(true)); - AddAssert("Time = 100", () => track.CurrentTime == 100); + AddAssert("Time = 100", () => clock.CurrentTime == 100); AddStep("SeekBackward, Snap", () => composer.SeekBackward(true)); - AddAssert("Time = 50", () => track.CurrentTime == 50); + AddAssert("Time = 50", () => clock.CurrentTime == 50); AddStep("SeekBackward, Snap", () => composer.SeekBackward(true)); - AddAssert("Time = 0", () => track.CurrentTime == 0); + AddAssert("Time = 0", () => clock.CurrentTime == 0); } /// @@ -280,16 +285,16 @@ namespace osu.Game.Tests.Visual AddStep("Seek(451)", () => composer.SeekTo(451)); AddStep("SeekBackward, Snap", () => composer.SeekBackward(true)); - AddAssert("Time = 450", () => track.CurrentTime == 450); + AddAssert("Time = 450", () => clock.CurrentTime == 450); AddStep("Seek(450.999)", () => composer.SeekTo(450.999)); AddStep("SeekBackward, Snap", () => composer.SeekBackward(true)); - AddAssert("Time = 450", () => track.CurrentTime == 450); + AddAssert("Time = 450", () => clock.CurrentTime == 450); AddStep("Seek(401)", () => composer.SeekTo(401)); AddStep("SeekBackward, Snap", () => composer.SeekBackward(true)); - AddAssert("Time = 400", () => track.CurrentTime == 400); + AddAssert("Time = 400", () => clock.CurrentTime == 400); AddStep("Seek(401.999)", () => composer.SeekTo(401.999)); AddStep("SeekBackward, Snap", () => composer.SeekBackward(true)); - AddAssert("Time = 400", () => track.CurrentTime == 400); + AddAssert("Time = 400", () => clock.CurrentTime == 400); } /// @@ -307,23 +312,23 @@ namespace osu.Game.Tests.Visual { AddStep("SeekForward, Snap", () => { - lastTime = track.CurrentTime; + lastTime = clock.CurrentTime; composer.SeekForward(true); }); - AddAssert("Time > lastTime", () => track.CurrentTime > lastTime); + AddAssert("Time > lastTime", () => clock.CurrentTime > lastTime); } for (int i = 0; i < 20; i++) { AddStep("SeekBackward, Snap", () => { - lastTime = track.CurrentTime; + lastTime = clock.CurrentTime; composer.SeekBackward(true); }); - AddAssert("Time < lastTime", () => track.CurrentTime < lastTime); + AddAssert("Time < lastTime", () => clock.CurrentTime < lastTime); } - AddAssert("Time = 0", () => track.CurrentTime == 0); + AddAssert("Time = 0", () => clock.CurrentTime == 0); } private void reset() @@ -333,8 +338,8 @@ namespace osu.Game.Tests.Visual private class TestHitObjectComposer : HitObjectComposer { - public TestHitObjectComposer(Ruleset ruleset) - : base(ruleset) + public TestHitObjectComposer(Ruleset ruleset, IAdjustableClock adjustableClock, IFrameBasedClock framedClock) + : base(ruleset, adjustableClock, framedClock) { } @@ -409,7 +414,7 @@ namespace osu.Game.Tests.Visual { base.Update(); - tracker.X = (float)(track.CurrentTime / track.Length); + tracker.X = (float)(Time.Current / track.Length); } private class TimingPointTimeline : CompositeDrawable diff --git a/osu.Game.Tests/Visual/TestCaseEditorSelectionLayer.cs b/osu.Game.Tests/Visual/TestCaseEditorSelectionLayer.cs index 8d12dfc517..87ad909354 100644 --- a/osu.Game.Tests/Visual/TestCaseEditorSelectionLayer.cs +++ b/osu.Game.Tests/Visual/TestCaseEditorSelectionLayer.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using NUnit.Framework; using osu.Framework.Allocation; +using osu.Framework.Timing; using OpenTK; using osu.Game.Beatmaps; using osu.Game.Rulesets.Edit; @@ -62,7 +63,9 @@ namespace osu.Game.Tests.Visual }, }); - Child = new OsuHitObjectComposer(new OsuRuleset()); + var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; + + Child = new OsuHitObjectComposer(new OsuRuleset(), clock, clock); } } } diff --git a/osu.Game.Tests/Visual/TestCaseEditorSummaryTimeline.cs b/osu.Game.Tests/Visual/TestCaseEditorSummaryTimeline.cs index 26c8814bc4..6e4b0c2a72 100644 --- a/osu.Game.Tests/Visual/TestCaseEditorSummaryTimeline.cs +++ b/osu.Game.Tests/Visual/TestCaseEditorSummaryTimeline.cs @@ -12,6 +12,7 @@ using osu.Game.Beatmaps.ControlPoints; using OpenTK; using osu.Game.Screens.Edit.Components.Timelines.Summary; using osu.Framework.Configuration; +using osu.Framework.Timing; namespace osu.Game.Tests.Visual { @@ -29,8 +30,10 @@ namespace osu.Game.Tests.Visual { random = new Random(1337); + var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; + SummaryTimeline summaryTimeline; - Add(summaryTimeline = new SummaryTimeline + Add(summaryTimeline = new SummaryTimeline(clock) { Anchor = Anchor.Centre, Origin = Anchor.Centre, diff --git a/osu.Game.Tests/Visual/TestCasePlaybackControl.cs b/osu.Game.Tests/Visual/TestCasePlaybackControl.cs index 43e977ba23..37bf38bbc6 100644 --- a/osu.Game.Tests/Visual/TestCasePlaybackControl.cs +++ b/osu.Game.Tests/Visual/TestCasePlaybackControl.cs @@ -3,6 +3,7 @@ using NUnit.Framework; using osu.Framework.Graphics; +using osu.Framework.Timing; using osu.Game.Beatmaps; using osu.Game.Screens.Edit.Components; using osu.Game.Tests.Beatmaps; @@ -15,7 +16,9 @@ namespace osu.Game.Tests.Visual { public TestCasePlaybackControl() { - var playback = new PlaybackControl + var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; + + var playback = new PlaybackControl(clock) { Anchor = Anchor.Centre, Origin = Anchor.Centre, From abb5dcf678607c7e7347f07ea37fbc4850bbdddb Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 16 Mar 2018 23:53:46 +0900 Subject: [PATCH 5/8] Fix null-refing testcase This would also be fixed with BDL loading children after we're fully loaded ;). --- .../Visual/TestCaseEditorCompose.cs | 37 ++++--------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseEditorCompose.cs b/osu.Game.Tests/Visual/TestCaseEditorCompose.cs index edc790e809..945c3c3901 100644 --- a/osu.Game.Tests/Visual/TestCaseEditorCompose.cs +++ b/osu.Game.Tests/Visual/TestCaseEditorCompose.cs @@ -1,51 +1,28 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Timing; -using osu.Game.Beatmaps; +using osu.Game.Rulesets.Osu; using osu.Game.Screens.Edit.Screens.Compose; +using osu.Game.Tests.Beatmaps; namespace osu.Game.Tests.Visual { [TestFixture] public class TestCaseEditorCompose : OsuTestCase { - private readonly Random random; - private readonly Compose compose; - - public TestCaseEditorCompose() + [BackgroundDependencyLoader] + private void load(OsuGameBase osuGame) { - random = new Random(1337); + osuGame.Beatmap.Value = new TestWorkingBeatmap(new OsuRuleset().RulesetInfo); var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; - - Add(compose = new Compose(clock, clock)); - AddStep("Next beatmap", nextBeatmap); - } - - private OsuGameBase osuGame; - private BeatmapManager beatmaps; - - [BackgroundDependencyLoader] - private void load(OsuGameBase osuGame, BeatmapManager beatmaps) - { - this.osuGame = osuGame; - this.beatmaps = beatmaps; - + var compose = new Compose(clock, clock); compose.Beatmap.BindTo(osuGame.Beatmap); - } - private void nextBeatmap() - { - var sets = beatmaps.GetAllUsableBeatmapSets(); - if (sets.Count == 0) - return; - - var b = sets[random.Next(0, sets.Count)].Beatmaps[0]; - osuGame.Beatmap.Value = beatmaps.GetWorkingBeatmap(b); + Child = compose; } } } From e25d1f69826b62a3765521ab19bf822ad14dd14f Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 19 Mar 2018 16:27:52 +0900 Subject: [PATCH 6/8] Pass down editor clocks through DI --- .../Edit/OsuHitObjectComposer.cs | 5 +- osu.Game.Rulesets.Osu/OsuRuleset.cs | 3 +- .../Visual/TestCaseEditorCompose.cs | 10 ++- .../Visual/TestCaseEditorSeekSnapping.cs | 13 +++- .../Visual/TestCaseEditorSelectionLayer.cs | 9 ++- .../Visual/TestCaseEditorSummaryTimeline.cs | 75 ++++--------------- .../Visual/TestCasePlaybackControl.cs | 11 ++- osu.Game/Rulesets/Edit/HitObjectComposer.cs | 11 ++- osu.Game/Rulesets/Ruleset.cs | 3 +- .../Edit/Components/PlaybackControl.cs | 7 +- .../Edit/Components/TimeInfoContainer.cs | 14 ++-- .../Timelines/Summary/SummaryTimeline.cs | 16 ++-- osu.Game/Screens/Edit/Editor.cs | 18 +++-- .../Screens/Edit/Screens/Compose/Compose.cs | 12 +-- 14 files changed, 91 insertions(+), 116 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs index 77f48d704e..026c85d909 100644 --- a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs +++ b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using osu.Framework.Graphics; -using osu.Framework.Timing; using osu.Game.Beatmaps; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit.Tools; @@ -18,8 +17,8 @@ namespace osu.Game.Rulesets.Osu.Edit { public class OsuHitObjectComposer : HitObjectComposer { - public OsuHitObjectComposer(Ruleset ruleset, IAdjustableClock adjustableClock, IFrameBasedClock framedClock) - : base(ruleset, adjustableClock, framedClock) + public OsuHitObjectComposer(Ruleset ruleset) + : base(ruleset) { } diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index 5dcc8e8a6e..d407835a96 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -13,7 +13,6 @@ using System.Linq; using osu.Framework.Graphics; using osu.Game.Overlays.Settings; using osu.Framework.Input.Bindings; -using osu.Framework.Timing; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Osu.Scoring; using osu.Game.Rulesets.Osu.Edit; @@ -138,7 +137,7 @@ namespace osu.Game.Rulesets.Osu public override PerformanceCalculator CreatePerformanceCalculator(Beatmap beatmap, Score score) => new OsuPerformanceCalculator(this, beatmap, score); - public override HitObjectComposer CreateHitObjectComposer(IAdjustableClock adjustableClock, IFrameBasedClock framedClock) => new OsuHitObjectComposer(this, adjustableClock, framedClock); + public override HitObjectComposer CreateHitObjectComposer() => new OsuHitObjectComposer(this); public override string Description => "osu!"; diff --git a/osu.Game.Tests/Visual/TestCaseEditorCompose.cs b/osu.Game.Tests/Visual/TestCaseEditorCompose.cs index 945c3c3901..5fd0f96f4a 100644 --- a/osu.Game.Tests/Visual/TestCaseEditorCompose.cs +++ b/osu.Game.Tests/Visual/TestCaseEditorCompose.cs @@ -13,13 +13,21 @@ namespace osu.Game.Tests.Visual [TestFixture] public class TestCaseEditorCompose : OsuTestCase { + private DependencyContainer dependencies; + + protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) + => dependencies = new DependencyContainer(parent); + [BackgroundDependencyLoader] private void load(OsuGameBase osuGame) { osuGame.Beatmap.Value = new TestWorkingBeatmap(new OsuRuleset().RulesetInfo); var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; - var compose = new Compose(clock, clock); + dependencies.CacheAs(clock); + dependencies.CacheAs(clock); + + var compose = new Compose(); compose.Beatmap.BindTo(osuGame.Beatmap); Child = compose; diff --git a/osu.Game.Tests/Visual/TestCaseEditorSeekSnapping.cs b/osu.Game.Tests/Visual/TestCaseEditorSeekSnapping.cs index 3b4b31c92a..bfdb39dd5e 100644 --- a/osu.Game.Tests/Visual/TestCaseEditorSeekSnapping.cs +++ b/osu.Game.Tests/Visual/TestCaseEditorSeekSnapping.cs @@ -33,10 +33,17 @@ namespace osu.Game.Tests.Visual private DecoupleableInterpolatingFramedClock clock; + private DependencyContainer dependencies; + + protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) + => dependencies = new DependencyContainer(parent); + [BackgroundDependencyLoader] private void load(OsuGameBase osuGame) { clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; + dependencies.CacheAs(clock); + dependencies.CacheAs(clock); var testBeatmap = new Beatmap { @@ -67,7 +74,7 @@ namespace osu.Game.Tests.Visual RelativeSizeAxes = Axes.Both, Content = new[] { - new Drawable[] { composer = new TestHitObjectComposer(new OsuRuleset(), clock, clock) }, + new Drawable[] { composer = new TestHitObjectComposer(new OsuRuleset()) }, new Drawable[] { new TimingPointVisualiser(testBeatmap, track) { Clock = clock } }, }, RowDimensions = new[] @@ -338,8 +345,8 @@ namespace osu.Game.Tests.Visual private class TestHitObjectComposer : HitObjectComposer { - public TestHitObjectComposer(Ruleset ruleset, IAdjustableClock adjustableClock, IFrameBasedClock framedClock) - : base(ruleset, adjustableClock, framedClock) + public TestHitObjectComposer(Ruleset ruleset) + : base(ruleset) { } diff --git a/osu.Game.Tests/Visual/TestCaseEditorSelectionLayer.cs b/osu.Game.Tests/Visual/TestCaseEditorSelectionLayer.cs index 79c722be40..bbbfef477a 100644 --- a/osu.Game.Tests/Visual/TestCaseEditorSelectionLayer.cs +++ b/osu.Game.Tests/Visual/TestCaseEditorSelectionLayer.cs @@ -35,6 +35,11 @@ namespace osu.Game.Tests.Visual typeof(SliderCircleMask) }; + private DependencyContainer dependencies; + + protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) + => dependencies = new DependencyContainer(parent); + [BackgroundDependencyLoader] private void load(OsuGameBase osuGame) { @@ -61,8 +66,10 @@ namespace osu.Game.Tests.Visual }); var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; + dependencies.CacheAs(clock); + dependencies.CacheAs(clock); - Child = new OsuHitObjectComposer(new OsuRuleset(), clock, clock); + Child = new OsuHitObjectComposer(new OsuRuleset()); } } } diff --git a/osu.Game.Tests/Visual/TestCaseEditorSummaryTimeline.cs b/osu.Game.Tests/Visual/TestCaseEditorSummaryTimeline.cs index 6e4b0c2a72..bbe2956c5d 100644 --- a/osu.Game.Tests/Visual/TestCaseEditorSummaryTimeline.cs +++ b/osu.Game.Tests/Visual/TestCaseEditorSummaryTimeline.cs @@ -4,36 +4,41 @@ using System; using System.Collections.Generic; using NUnit.Framework; -using osu.Framework.Audio.Track; -using osu.Framework.Graphics.Textures; +using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Game.Beatmaps; -using osu.Game.Beatmaps.ControlPoints; using OpenTK; using osu.Game.Screens.Edit.Components.Timelines.Summary; using osu.Framework.Configuration; using osu.Framework.Timing; +using osu.Game.Rulesets.Osu; +using osu.Game.Tests.Beatmaps; namespace osu.Game.Tests.Visual { [TestFixture] public class TestCaseEditorSummaryTimeline : OsuTestCase { - private const int length = 60000; - private readonly Random random; - public override IReadOnlyList RequiredTypes => new[] { typeof(SummaryTimeline) }; private readonly Bindable beatmap = new Bindable(); - public TestCaseEditorSummaryTimeline() + private DependencyContainer dependencies; + + protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) + => dependencies = new DependencyContainer(parent); + + [BackgroundDependencyLoader] + private void load() { - random = new Random(1337); + beatmap.Value = new TestWorkingBeatmap(new OsuRuleset().RulesetInfo); var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; + dependencies.CacheAs(clock); + dependencies.CacheAs(clock); SummaryTimeline summaryTimeline; - Add(summaryTimeline = new SummaryTimeline(clock) + Add(summaryTimeline = new SummaryTimeline { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -41,58 +46,6 @@ namespace osu.Game.Tests.Visual }); summaryTimeline.Beatmap.BindTo(beatmap); - - AddStep("New beatmap", newBeatmap); - - newBeatmap(); - } - - private void newBeatmap() - { - var b = new Beatmap(); - - for (int i = 0; i < random.Next(1, 10); i++) - b.ControlPointInfo.TimingPoints.Add(new TimingControlPoint { Time = random.Next(0, length) }); - - for (int i = 0; i < random.Next(1, 5); i++) - b.ControlPointInfo.DifficultyPoints.Add(new DifficultyControlPoint { Time = random.Next(0, length) }); - - for (int i = 0; i < random.Next(1, 5); i++) - b.ControlPointInfo.EffectPoints.Add(new EffectControlPoint { Time = random.Next(0, length) }); - - for (int i = 0; i < random.Next(1, 5); i++) - b.ControlPointInfo.SamplePoints.Add(new SampleControlPoint { Time = random.Next(0, length) }); - - b.BeatmapInfo.Bookmarks = new int[random.Next(10, 30)]; - for (int i = 0; i < b.BeatmapInfo.Bookmarks.Length; i++) - b.BeatmapInfo.Bookmarks[i] = random.Next(0, length); - - beatmap.Value = new TestWorkingBeatmap(b); - } - - private class TestWorkingBeatmap : WorkingBeatmap - { - private readonly Beatmap beatmap; - - public TestWorkingBeatmap(Beatmap beatmap) - : base(beatmap.BeatmapInfo) - { - this.beatmap = beatmap; - } - - protected override Texture GetBackground() => null; - - protected override Beatmap GetBeatmap() => beatmap; - - protected override Track GetTrack() => new TestTrack(); - - private class TestTrack : TrackVirtual - { - public TestTrack() - { - Length = length; - } - } } } } diff --git a/osu.Game.Tests/Visual/TestCasePlaybackControl.cs b/osu.Game.Tests/Visual/TestCasePlaybackControl.cs index 37bf38bbc6..33a801e98f 100644 --- a/osu.Game.Tests/Visual/TestCasePlaybackControl.cs +++ b/osu.Game.Tests/Visual/TestCasePlaybackControl.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using NUnit.Framework; +using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Timing; using osu.Game.Beatmaps; @@ -14,16 +15,24 @@ namespace osu.Game.Tests.Visual [TestFixture] public class TestCasePlaybackControl : OsuTestCase { + private DependencyContainer dependencies; + + protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) + => dependencies = new DependencyContainer(parent); + public TestCasePlaybackControl() { var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; + dependencies.CacheAs(clock); + dependencies.CacheAs(clock); - var playback = new PlaybackControl(clock) + var playback = new PlaybackControl { Anchor = Anchor.Centre, Origin = Anchor.Centre, Size = new Vector2(200,100) }; + playback.Beatmap.Value = new TestWorkingBeatmap(new Beatmap()); Add(playback); diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index c2a286c6dd..ae1c8af1a4 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -32,21 +32,20 @@ namespace osu.Game.Rulesets.Edit private readonly Bindable beatmap = new Bindable(); - private readonly IAdjustableClock adjustableClock; - private readonly IFrameBasedClock framedClock; + private IAdjustableClock adjustableClock; - protected HitObjectComposer(Ruleset ruleset, IAdjustableClock adjustableClock, IFrameBasedClock framedClock) + protected HitObjectComposer(Ruleset ruleset) { this.ruleset = ruleset; - this.adjustableClock = adjustableClock; - this.framedClock = framedClock; RelativeSizeAxes = Axes.Both; } [BackgroundDependencyLoader] - private void load(OsuGameBase osuGame) + private void load(OsuGameBase osuGame, IAdjustableClock adjustableClock, IFrameBasedClock framedClock) { + this.adjustableClock = adjustableClock; + beatmap.BindTo(osuGame.Beatmap); try diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index fc0c7966c6..cba849a491 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Graphics; using osu.Framework.Input.Bindings; -using osu.Framework.Timing; using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Overlays.Settings; @@ -54,7 +53,7 @@ namespace osu.Game.Rulesets public virtual PerformanceCalculator CreatePerformanceCalculator(Beatmap beatmap, Score score) => null; - public virtual HitObjectComposer CreateHitObjectComposer(IAdjustableClock adjustableClock, IFrameBasedClock framedClock) => null; + public virtual HitObjectComposer CreateHitObjectComposer() => null; public virtual Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.fa_question_circle }; diff --git a/osu.Game/Screens/Edit/Components/PlaybackControl.cs b/osu.Game/Screens/Edit/Components/PlaybackControl.cs index 71154006ce..fe2549d300 100644 --- a/osu.Game/Screens/Edit/Components/PlaybackControl.cs +++ b/osu.Game/Screens/Edit/Components/PlaybackControl.cs @@ -18,11 +18,12 @@ namespace osu.Game.Screens.Edit.Components { public class PlaybackControl : BottomBarContainer { - private readonly IconButton playButton; + private IconButton playButton; - private readonly IAdjustableClock adjustableClock; + private IAdjustableClock adjustableClock; - public PlaybackControl(IAdjustableClock adjustableClock) + [BackgroundDependencyLoader] + private void load(IAdjustableClock adjustableClock) { this.adjustableClock = adjustableClock; diff --git a/osu.Game/Screens/Edit/Components/TimeInfoContainer.cs b/osu.Game/Screens/Edit/Components/TimeInfoContainer.cs index 6bbaad432b..5a3b6c652b 100644 --- a/osu.Game/Screens/Edit/Components/TimeInfoContainer.cs +++ b/osu.Game/Screens/Edit/Components/TimeInfoContainer.cs @@ -4,21 +4,19 @@ using osu.Framework.Graphics; using osu.Game.Graphics.Sprites; using System; +using osu.Framework.Allocation; using osu.Framework.Timing; namespace osu.Game.Screens.Edit.Components { public class TimeInfoContainer : BottomBarContainer { - private const int count_duration = 150; - private readonly OsuSpriteText trackTimer; - private readonly IAdjustableClock adjustableClock; + private IAdjustableClock adjustableClock; - public TimeInfoContainer(IAdjustableClock adjustableClock) + public TimeInfoContainer() { - this.adjustableClock = adjustableClock; Children = new Drawable[] { @@ -33,6 +31,12 @@ namespace osu.Game.Screens.Edit.Components }; } + [BackgroundDependencyLoader] + private void load(IAdjustableClock adjustableClock) + { + this.adjustableClock = adjustableClock; + } + protected override void Update() { base.Update(); diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs index 9921c24083..0e80c13257 100644 --- a/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs @@ -17,13 +17,12 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary /// public class SummaryTimeline : BottomBarContainer { - private readonly Drawable timelineBar; - - public SummaryTimeline(IAdjustableClock adjustableClock) + [BackgroundDependencyLoader] + private void load(OsuColour colours, IAdjustableClock adjustableClock) { TimelinePart markerPart, controlPointPart, bookmarkPart, breakPart; - Children = new[] + Children = new Drawable[] { markerPart = new MarkerPart(adjustableClock) { RelativeSizeAxes = Axes.Both }, controlPointPart = new ControlPointPart @@ -40,9 +39,10 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary RelativeSizeAxes = Axes.Both, Height = 0.35f }, - timelineBar = new Container + new Container { RelativeSizeAxes = Axes.Both, + Colour = colours.Gray5, Children = new Drawable[] { new Circle @@ -81,11 +81,5 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary bookmarkPart.Beatmap.BindTo(Beatmap); breakPart.Beatmap.BindTo(Beatmap); } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - timelineBar.Colour = colours.Gray5; - } } } diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index cc7f77e770..8b651000fd 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -32,16 +32,22 @@ namespace osu.Game.Screens.Edit private EditorScreen currentScreen; - private DecoupleableInterpolatingFramedClock adjustableClock; + private DependencyContainer dependencies; + + protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) + => dependencies = new DependencyContainer(parent); [BackgroundDependencyLoader] private void load(OsuColour colours) { // TODO: should probably be done at a RulesetContainer level to share logic with Player. var sourceClock = (IAdjustableClock)Beatmap.Value.Track ?? new StopwatchClock(); - adjustableClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; + var adjustableClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; adjustableClock.ChangeSource(sourceClock); + dependencies.CacheAs(adjustableClock); + dependencies.CacheAs(adjustableClock); + EditorMenuBar menuBar; TimeInfoContainer timeInfo; SummaryTimeline timeline; @@ -115,9 +121,9 @@ namespace osu.Game.Screens.Edit { RelativeSizeAxes = Axes.Both, Padding = new MarginPadding { Right = 10 }, - Child = timeInfo = new TimeInfoContainer(adjustableClock) { RelativeSizeAxes = Axes.Both }, + Child = timeInfo = new TimeInfoContainer { RelativeSizeAxes = Axes.Both }, }, - timeline = new SummaryTimeline(adjustableClock) + timeline = new SummaryTimeline { RelativeSizeAxes = Axes.Both, }, @@ -125,7 +131,7 @@ namespace osu.Game.Screens.Edit { RelativeSizeAxes = Axes.Both, Padding = new MarginPadding { Left = 10 }, - Child = playback = new PlaybackControl(adjustableClock) { RelativeSizeAxes = Axes.Both }, + Child = playback = new PlaybackControl { RelativeSizeAxes = Axes.Both }, } }, } @@ -156,7 +162,7 @@ namespace osu.Game.Screens.Edit switch (mode) { case EditorScreenMode.Compose: - currentScreen = new Compose(adjustableClock, adjustableClock); + currentScreen = new Compose(); break; case EditorScreenMode.Design: currentScreen = new Design(); diff --git a/osu.Game/Screens/Edit/Screens/Compose/Compose.cs b/osu.Game/Screens/Edit/Screens/Compose/Compose.cs index 9a720e1608..861a08fb07 100644 --- a/osu.Game/Screens/Edit/Screens/Compose/Compose.cs +++ b/osu.Game/Screens/Edit/Screens/Compose/Compose.cs @@ -8,7 +8,6 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Logging; -using osu.Framework.Timing; using osu.Game.Screens.Edit.Screens.Compose.Timeline; namespace osu.Game.Screens.Edit.Screens.Compose @@ -20,15 +19,6 @@ namespace osu.Game.Screens.Edit.Screens.Compose private Container composerContainer; - private readonly IAdjustableClock adjustableClock; - private readonly IFrameBasedClock framedClock; - - public Compose(IAdjustableClock adjustableClock, IFrameBasedClock framedClock) - { - this.adjustableClock = adjustableClock; - this.framedClock = framedClock; - } - [BackgroundDependencyLoader] private void load() { @@ -95,7 +85,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose return; } - var composer = ruleset.CreateHitObjectComposer(adjustableClock, framedClock); + var composer = ruleset.CreateHitObjectComposer(); if (composer == null) { Logger.Log($"Ruleset {ruleset.Description} doesn't support hitobject composition."); From 193142e90117ebba6668f40c7d69ef8f49a458b3 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 19 Mar 2018 16:44:46 +0900 Subject: [PATCH 7/8] Fix missed BDL case --- osu.Game.Tests/Visual/TestCasePlaybackControl.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCasePlaybackControl.cs b/osu.Game.Tests/Visual/TestCasePlaybackControl.cs index 33a801e98f..9cdb3e36e3 100644 --- a/osu.Game.Tests/Visual/TestCasePlaybackControl.cs +++ b/osu.Game.Tests/Visual/TestCasePlaybackControl.cs @@ -20,7 +20,8 @@ namespace osu.Game.Tests.Visual protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) => dependencies = new DependencyContainer(parent); - public TestCasePlaybackControl() + [BackgroundDependencyLoader] + private void load() { var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; dependencies.CacheAs(clock); @@ -35,7 +36,7 @@ namespace osu.Game.Tests.Visual playback.Beatmap.Value = new TestWorkingBeatmap(new Beatmap()); - Add(playback); + Child = playback; } } } From 8d4c9eda489fb5791a2a4b931f7850a57d134108 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 19 Mar 2018 18:00:11 +0900 Subject: [PATCH 8/8] Fix attempting to add selection boxes with no selection E.g. because DrawableSpinner doesn't (currently) create an overlay, SelectionBox was being constructed with 0 hitobjects and then calculating a non-finite size for itself. --- .../Edit/Screens/Compose/Layers/HitObjectMaskLayer.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Screens/Compose/Layers/HitObjectMaskLayer.cs b/osu.Game/Screens/Edit/Screens/Compose/Layers/HitObjectMaskLayer.cs index 63b5538ad7..46b09e2c23 100644 --- a/osu.Game/Screens/Edit/Screens/Compose/Layers/HitObjectMaskLayer.cs +++ b/osu.Game/Screens/Edit/Screens/Compose/Layers/HitObjectMaskLayer.cs @@ -51,7 +51,11 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers private SelectionBox currentSelectionBox; - public void AddSelectionOverlay() => AddInternal(currentSelectionBox = composer.CreateSelectionOverlay(overlayContainer)); + public void AddSelectionOverlay() + { + if (overlayContainer.Count > 0) + AddInternal(currentSelectionBox = composer.CreateSelectionOverlay(overlayContainer)); + } public void RemoveSelectionOverlay() {