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

Update RulesetInputManager to support new clock structure more accurately

This commit is contained in:
Dean Herbert 2019-03-05 16:34:50 +09:00
parent 4e33a98dbc
commit ec063a13db
2 changed files with 44 additions and 33 deletions

View File

@ -12,7 +12,6 @@ using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Play;
using osuTK; using osuTK;
namespace osu.Game.Rulesets.UI namespace osu.Game.Rulesets.UI
@ -60,12 +59,10 @@ namespace osu.Game.Rulesets.UI
private WorkingBeatmap beatmap; private WorkingBeatmap beatmap;
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader]
private void load(IBindable<WorkingBeatmap> beatmap, GameplayClock clock) private void load(IBindable<WorkingBeatmap> beatmap)
{ {
this.beatmap = beatmap.Value; this.beatmap = beatmap.Value;
if (clock != null) Clock = clock;
} }
/// <summary> /// <summary>

View File

@ -41,6 +41,7 @@ namespace osu.Game.Rulesets.UI
protected RulesetInputManager(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique) protected RulesetInputManager(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
{ {
InternalChild = KeyBindingContainer = CreateKeyBindingContainer(ruleset, variant, unique); InternalChild = KeyBindingContainer = CreateKeyBindingContainer(ruleset, variant, unique);
gameplayClock = new GameplayClock(framedClock = new FramedClock(manualClock = new ManualClock()));
} }
#region Action mapping (for replays) #region Action mapping (for replays)
@ -86,22 +87,35 @@ namespace osu.Game.Rulesets.UI
#region Clock control #region Clock control
private ManualClock clock; private readonly ManualClock manualClock;
private IFrameBasedClock parentClock;
private readonly FramedClock framedClock;
[Cached]
private GameplayClock gameplayClock;
private IFrameBasedClock parentGameplayClock;
[BackgroundDependencyLoader(true)]
private void load(OsuConfigManager config, GameplayClock clock)
{
mouseDisabled = config.GetBindable<bool>(OsuSetting.MouseDisableButtons);
if (clock != null)
parentGameplayClock = clock;
}
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
//our clock will now be our parent's clock, but we want to replace this to allow manual control. // in case a parent gameplay clock isn't available, just use the parent clock.
parentClock = Clock; if (parentGameplayClock == null)
parentGameplayClock = Clock;
Clock = gameplayClock;
ProcessCustomClock = false; ProcessCustomClock = false;
Clock = new FramedClock(clock = new ManualClock
{
CurrentTime = parentClock.CurrentTime,
Rate = parentClock.Rate,
});
} }
/// <summary> /// <summary>
@ -147,25 +161,31 @@ namespace osu.Game.Rulesets.UI
private void updateClock() private void updateClock()
{ {
if (parentClock == null) return; if (parentGameplayClock == null)
{
validState = false;
return;
}
clock.Rate = parentClock.Rate; validState = true;
clock.IsRunning = parentClock.IsRunning;
var newProposedTime = parentClock.CurrentTime; manualClock.Rate = parentGameplayClock.Rate;
manualClock.IsRunning = parentGameplayClock.IsRunning;
var newProposedTime = parentGameplayClock.CurrentTime;
try 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 newProposedTime = manualClock.Rate > 0
? Math.Min(newProposedTime, clock.CurrentTime + sixty_frame_time) ? Math.Min(newProposedTime, manualClock.CurrentTime + sixty_frame_time)
: Math.Max(newProposedTime, clock.CurrentTime - sixty_frame_time); : Math.Max(newProposedTime, manualClock.CurrentTime - sixty_frame_time);
} }
if (!isAttached) if (!isAttached)
{ {
clock.CurrentTime = newProposedTime; manualClock.CurrentTime = newProposedTime;
} }
else else
{ {
@ -177,20 +197,20 @@ namespace osu.Game.Rulesets.UI
validState = false; validState = false;
requireMoreUpdateLoops = true; requireMoreUpdateLoops = true;
clock.CurrentTime = newProposedTime; manualClock.CurrentTime = newProposedTime;
return; return;
} }
clock.CurrentTime = newTime.Value; manualClock.CurrentTime = newTime.Value;
} }
requireMoreUpdateLoops = clock.CurrentTime != parentClock.CurrentTime; requireMoreUpdateLoops = manualClock.CurrentTime != parentGameplayClock.CurrentTime;
} }
finally finally
{ {
// The manual clock time has changed in the above code. The framed clock now needs to be updated // 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 // 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<bool> mouseDisabled; private Bindable<bool> mouseDisabled;
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
mouseDisabled = config.GetBindable<bool>(OsuSetting.MouseDisableButtons);
}
protected override bool Handle(UIEvent e) protected override bool Handle(UIEvent e)
{ {
switch (e) switch (e)