Cache and resolve editor clock as EditorClock in all cases

This commit is contained in:
Dean Herbert 2020-05-22 16:37:28 +09:00
parent eefff6cc49
commit dd09d7830d
11 changed files with 41 additions and 54 deletions

View File

@ -11,7 +11,6 @@
using osu.Framework.Input;
using osu.Framework.Input.Events;
using osu.Framework.Logging;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Configuration;
@ -38,14 +37,11 @@ public abstract class HitObjectComposer<TObject> : HitObjectComposer, IPlacement
protected readonly Ruleset Ruleset;
[Resolved]
protected IFrameBasedClock EditorClock { get; private set; }
protected EditorClock EditorClock { get; private set; }
[Resolved]
protected EditorBeatmap EditorBeatmap { get; private set; }
[Resolved]
private IAdjustableClock adjustableClock { get; set; }
[Resolved]
protected IBeatSnapProvider BeatSnapProvider { get; private set; }
@ -68,7 +64,7 @@ protected HitObjectComposer(Ruleset ruleset)
}
[BackgroundDependencyLoader]
private void load(IFrameBasedClock framedClock)
private void load()
{
Config = Dependencies.Get<RulesetConfigCache>().GetConfigFor(Ruleset);
@ -76,7 +72,7 @@ private void load(IFrameBasedClock framedClock)
{
drawableRulesetWrapper = new DrawableEditRulesetWrapper<TObject>(CreateDrawableRuleset(Ruleset, EditorBeatmap.PlayableBeatmap))
{
Clock = framedClock,
Clock = EditorClock,
ProcessCustomClock = false
};
}
@ -221,8 +217,8 @@ public void EndPlacement(HitObject hitObject, bool commit)
{
EditorBeatmap.Add(hitObject);
if (adjustableClock.CurrentTime < hitObject.StartTime)
adjustableClock.Seek(hitObject.StartTime);
if (EditorClock.CurrentTime < hitObject.StartTime)
EditorClock.Seek(hitObject.StartTime);
}
}

View File

@ -6,10 +6,10 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Objects;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Compose;
using osuTK;
@ -30,7 +30,8 @@ public abstract class PlacementBlueprint : CompositeDrawable
/// </summary>
protected readonly HitObject HitObject;
protected IClock EditorClock { get; private set; }
[Resolved]
protected EditorClock EditorClock { get; private set; }
private readonly IBindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
@ -49,12 +50,10 @@ protected PlacementBlueprint(HitObject hitObject)
}
[BackgroundDependencyLoader]
private void load(IBindable<WorkingBeatmap> beatmap, IAdjustableClock clock)
private void load(IBindable<WorkingBeatmap> beatmap)
{
this.beatmap.BindTo(beatmap);
EditorClock = clock;
ApplyDefaultsToHitObject();
}
@ -84,7 +83,7 @@ public void EndPlacement(bool commit)
}
[Resolved(canBeNull: true)]
private IFrameBasedClock editorClock { get; set; }
private EditorClock editorClock { get; set; }
/// <summary>
/// Updates the position of this <see cref="PlacementBlueprint"/> to a new screen-space position.

View File

@ -13,7 +13,6 @@
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Framework.Timing;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
@ -26,7 +25,7 @@ public class PlaybackControl : BottomBarContainer
private IconButton playButton;
[Resolved]
private IAdjustableClock adjustableClock { get; set; }
private EditorClock editorClock { get; set; }
private readonly BindableNumber<double> tempo = new BindableDouble(1);
@ -87,17 +86,17 @@ protected override bool OnKeyDown(KeyDownEvent e)
private void togglePause()
{
if (adjustableClock.IsRunning)
adjustableClock.Stop();
if (editorClock.IsRunning)
editorClock.Stop();
else
adjustableClock.Start();
editorClock.Start();
}
protected override void Update()
{
base.Update();
playButton.Icon = adjustableClock.IsRunning ? FontAwesome.Regular.PauseCircle : FontAwesome.Regular.PlayCircle;
playButton.Icon = editorClock.IsRunning ? FontAwesome.Regular.PauseCircle : FontAwesome.Regular.PlayCircle;
}
private class PlaybackTabControl : OsuTabControl<double>

View File

@ -5,7 +5,6 @@
using osu.Game.Graphics.Sprites;
using System;
using osu.Framework.Allocation;
using osu.Framework.Timing;
using osu.Game.Graphics;
namespace osu.Game.Screens.Edit.Components
@ -15,7 +14,7 @@ public class TimeInfoContainer : BottomBarContainer
private readonly OsuSpriteText trackTimer;
[Resolved]
private IAdjustableClock adjustableClock { get; set; }
private EditorClock editorClock { get; set; }
public TimeInfoContainer()
{
@ -35,7 +34,7 @@ protected override void Update()
{
base.Update();
trackTimer.Text = TimeSpan.FromMilliseconds(adjustableClock.CurrentTime).ToString(@"mm\:ss\:fff");
trackTimer.Text = TimeSpan.FromMilliseconds(editorClock.CurrentTime).ToString(@"mm\:ss\:fff");
}
}
}

View File

@ -9,7 +9,6 @@
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Framework.Threading;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
@ -20,14 +19,14 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
/// </summary>
public class MarkerPart : TimelinePart
{
private readonly Drawable marker;
private Drawable marker;
private readonly IAdjustableClock adjustableClock;
[Resolved]
private EditorClock editorClock { get; set; }
public MarkerPart(IAdjustableClock adjustableClock)
[BackgroundDependencyLoader]
private void load()
{
this.adjustableClock = adjustableClock;
Add(marker = new MarkerVisualisation());
}
@ -59,14 +58,14 @@ private void seekToPosition(Vector2 screenPosition)
return;
float markerPos = Math.Clamp(ToLocalSpace(screenPosition).X, 0, DrawWidth);
adjustableClock.Seek(markerPos / DrawWidth * Beatmap.Value.Track.Length);
editorClock.Seek(markerPos / DrawWidth * editorClock.TrackLength);
});
}
protected override void Update()
{
base.Update();
marker.X = (float)adjustableClock.CurrentTime;
marker.X = (float)editorClock.CurrentTime;
}
protected override void LoadBeatmap(WorkingBeatmap beatmap)

View File

@ -6,7 +6,6 @@
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,11 +17,11 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary
public class SummaryTimeline : BottomBarContainer
{
[BackgroundDependencyLoader]
private void load(OsuColour colours, IAdjustableClock adjustableClock)
private void load(OsuColour colours)
{
Children = new Drawable[]
{
new MarkerPart(adjustableClock) { RelativeSizeAxes = Axes.Both },
new MarkerPart { RelativeSizeAxes = Axes.Both },
new ControlPointPart
{
Anchor = Anchor.Centre,

View File

@ -13,7 +13,6 @@
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Timing;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
@ -38,7 +37,7 @@ public abstract class BlueprintContainer : CompositeDrawable, IKeyBindingHandler
private IEditorChangeHandler changeHandler { get; set; }
[Resolved]
private IAdjustableClock adjustableClock { get; set; }
private EditorClock editorClock { get; set; }
[Resolved]
private EditorBeatmap beatmap { get; set; }
@ -144,7 +143,7 @@ protected override bool OnDoubleClick(DoubleClickEvent e)
if (clickedBlueprint == null)
return false;
adjustableClock?.Seek(clickedBlueprint.HitObject.StartTime);
editorClock?.Seek(clickedBlueprint.HitObject.StartTime);
return true;
}

View File

@ -9,7 +9,6 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Audio;
using osu.Framework.Input.Events;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Rulesets.Edit;
@ -25,7 +24,7 @@ public class Timeline : ZoomableScrollContainer, IPositionSnapProvider
public readonly IBindable<WorkingBeatmap> Beatmap = new Bindable<WorkingBeatmap>();
[Resolved]
private IAdjustableClock adjustableClock { get; set; }
private EditorClock editorClock { get; set; }
public Timeline()
{
@ -101,7 +100,7 @@ protected override void Update()
Content.Margin = new MarginPadding { Horizontal = DrawWidth / 2 };
// This needs to happen after transforms are updated, but before the scroll position is updated in base.UpdateAfterChildren
if (adjustableClock.IsRunning)
if (editorClock.IsRunning)
scrollToTrackTime();
}
@ -111,21 +110,21 @@ protected override void UpdateAfterChildren()
if (handlingDragInput)
seekTrackToCurrent();
else if (!adjustableClock.IsRunning)
else if (!editorClock.IsRunning)
{
// The track isn't running. There are two cases we have to be wary of:
// 1) The user flick-drags on this timeline: We want the track to follow us
// 2) The user changes the track time through some other means (scrolling in the editor or overview timeline): We want to follow the track time
// The simplest way to cover both cases is by checking whether the scroll position has changed and the audio hasn't been changed externally
if (Current != lastScrollPosition && adjustableClock.CurrentTime == lastTrackTime)
if (Current != lastScrollPosition && editorClock.CurrentTime == lastTrackTime)
seekTrackToCurrent();
else
scrollToTrackTime();
}
lastScrollPosition = Current;
lastTrackTime = adjustableClock.CurrentTime;
lastTrackTime = editorClock.CurrentTime;
}
private void seekTrackToCurrent()
@ -133,7 +132,7 @@ private void seekTrackToCurrent()
if (!track.IsLoaded)
return;
adjustableClock.Seek(Current / Content.DrawWidth * track.Length);
editorClock.Seek(Current / Content.DrawWidth * track.Length);
}
private void scrollToTrackTime()
@ -141,7 +140,7 @@ private void scrollToTrackTime()
if (!track.IsLoaded || track.Length == 0)
return;
ScrollTo((float)(adjustableClock.CurrentTime / track.Length) * Content.DrawWidth, false);
ScrollTo((float)(editorClock.CurrentTime / track.Length) * Content.DrawWidth, false);
}
protected override bool OnMouseDown(MouseDownEvent e)
@ -164,15 +163,15 @@ protected override void OnMouseUp(MouseUpEvent e)
private void beginUserDrag()
{
handlingDragInput = true;
trackWasPlaying = adjustableClock.IsRunning;
adjustableClock.Stop();
trackWasPlaying = editorClock.IsRunning;
editorClock.Stop();
}
private void endUserDrag()
{
handlingDragInput = false;
if (trackWasPlaying)
adjustableClock.Start();
editorClock.Start();
}
[Resolved]

View File

@ -83,8 +83,7 @@ private void load(OsuColour colours, GameHost host)
clock = new EditorClock(Beatmap.Value, beatDivisor) { IsCoupled = false };
clock.ChangeSource(sourceClock);
dependencies.CacheAs<IFrameBasedClock>(clock);
dependencies.CacheAs<IAdjustableClock>(clock);
dependencies.CacheAs(clock);
// todo: remove caching of this and consume via editorBeatmap?
dependencies.Cache(beatDivisor);

View File

@ -23,7 +23,7 @@ public class TimingScreen : EditorScreenWithTimeline
private Bindable<ControlPointGroup> selectedGroup = new Bindable<ControlPointGroup>();
[Resolved]
private IAdjustableClock clock { get; set; }
private EditorClock clock { get; set; }
protected override Drawable CreateMainContent() => new GridContainer
{

View File

@ -30,8 +30,7 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.Cache(BeatDivisor);
dependencies.CacheAs<IFrameBasedClock>(Clock);
dependencies.CacheAs<IAdjustableClock>(Clock);
dependencies.CacheAs(Clock);
return dependencies;
}