diff --git a/osu.Game/Rulesets/UI/Playfield.cs b/osu.Game/Rulesets/UI/Playfield.cs index 7b8e044461..3b8a7353c6 100644 --- a/osu.Game/Rulesets/UI/Playfield.cs +++ b/osu.Game/Rulesets/UI/Playfield.cs @@ -12,7 +12,6 @@ using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; using osu.Game.Rulesets.Mods; -using osu.Game.Screens.Play; using osuTK; namespace osu.Game.Rulesets.UI @@ -60,12 +59,10 @@ namespace osu.Game.Rulesets.UI private WorkingBeatmap beatmap; - [BackgroundDependencyLoader(true)] - private void load(IBindable beatmap, GameplayClock clock) + [BackgroundDependencyLoader] + private void load(IBindable beatmap) { this.beatmap = beatmap.Value; - - if (clock != null) Clock = clock; } /// diff --git a/osu.Game/Rulesets/UI/RulesetInputManager.cs b/osu.Game/Rulesets/UI/RulesetInputManager.cs index fc61d41ab4..d5c8f9a32f 100644 --- a/osu.Game/Rulesets/UI/RulesetInputManager.cs +++ b/osu.Game/Rulesets/UI/RulesetInputManager.cs @@ -41,6 +41,7 @@ namespace osu.Game.Rulesets.UI protected RulesetInputManager(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique) { InternalChild = KeyBindingContainer = CreateKeyBindingContainer(ruleset, variant, unique); + gameplayClock = new GameplayClock(framedClock = new FramedClock(manualClock = new ManualClock())); } #region Action mapping (for replays) @@ -86,22 +87,35 @@ namespace osu.Game.Rulesets.UI #region Clock control - private ManualClock clock; - private IFrameBasedClock parentClock; + private readonly ManualClock manualClock; + + private readonly FramedClock framedClock; + + [Cached] + private GameplayClock gameplayClock; + + private IFrameBasedClock parentGameplayClock; + + [BackgroundDependencyLoader(true)] + private void load(OsuConfigManager config, GameplayClock clock) + { + mouseDisabled = config.GetBindable(OsuSetting.MouseDisableButtons); + + if (clock != null) + parentGameplayClock = clock; + } + protected override void LoadComplete() { base.LoadComplete(); - //our clock will now be our parent's clock, but we want to replace this to allow manual control. - parentClock = Clock; + // in case a parent gameplay clock isn't available, just use the parent clock. + if (parentGameplayClock == null) + parentGameplayClock = Clock; + Clock = gameplayClock; ProcessCustomClock = false; - Clock = new FramedClock(clock = new ManualClock - { - CurrentTime = parentClock.CurrentTime, - Rate = parentClock.Rate, - }); } /// @@ -147,25 +161,31 @@ namespace osu.Game.Rulesets.UI private void updateClock() { - if (parentClock == null) return; + if (parentGameplayClock == null) + { + validState = false; + return; + } - clock.Rate = parentClock.Rate; - clock.IsRunning = parentClock.IsRunning; + validState = true; - var newProposedTime = parentClock.CurrentTime; + manualClock.Rate = parentGameplayClock.Rate; + manualClock.IsRunning = parentGameplayClock.IsRunning; + + var newProposedTime = parentGameplayClock.CurrentTime; try { - if (Math.Abs(clock.CurrentTime - newProposedTime) > sixty_frame_time * 1.2f) + if (Math.Abs(manualClock.CurrentTime - newProposedTime) > sixty_frame_time * 1.2f) { - newProposedTime = clock.Rate > 0 - ? Math.Min(newProposedTime, clock.CurrentTime + sixty_frame_time) - : Math.Max(newProposedTime, clock.CurrentTime - sixty_frame_time); + newProposedTime = manualClock.Rate > 0 + ? Math.Min(newProposedTime, manualClock.CurrentTime + sixty_frame_time) + : Math.Max(newProposedTime, manualClock.CurrentTime - sixty_frame_time); } if (!isAttached) { - clock.CurrentTime = newProposedTime; + manualClock.CurrentTime = newProposedTime; } else { @@ -177,20 +197,20 @@ namespace osu.Game.Rulesets.UI validState = false; requireMoreUpdateLoops = true; - clock.CurrentTime = newProposedTime; + manualClock.CurrentTime = newProposedTime; return; } - clock.CurrentTime = newTime.Value; + manualClock.CurrentTime = newTime.Value; } - requireMoreUpdateLoops = clock.CurrentTime != parentClock.CurrentTime; + requireMoreUpdateLoops = manualClock.CurrentTime != parentGameplayClock.CurrentTime; } finally { // The manual clock time has changed in the above code. The framed clock now needs to be updated // to ensure that the its time is valid for our children before input is processed - Clock.ProcessFrame(); + framedClock.ProcessFrame(); } } @@ -200,12 +220,6 @@ namespace osu.Game.Rulesets.UI private Bindable mouseDisabled; - [BackgroundDependencyLoader] - private void load(OsuConfigManager config) - { - mouseDisabled = config.GetBindable(OsuSetting.MouseDisableButtons); - } - protected override bool Handle(UIEvent e) { switch (e)