Avoid checking gameplay clock time in Update method

This commit is contained in:
Dean Herbert 2022-02-02 14:33:17 +09:00
parent c7a192cc5f
commit a2affefb0a

View File

@ -16,7 +16,7 @@ using osu.Game.Screens.Play;
namespace osu.Game.Rulesets.Osu.Mods namespace osu.Game.Rulesets.Osu.Mods
{ {
public class OsuModAlternate : Mod, IApplicableToDrawableRuleset<OsuHitObject>, IApplicableToPlayer, IUpdatableByPlayfield public class OsuModAlternate : Mod, IApplicableToDrawableRuleset<OsuHitObject>, IApplicableToPlayer
{ {
public override string Name => @"Alternate"; public override string Name => @"Alternate";
public override string Acronym => @"AL"; public override string Acronym => @"AL";
@ -26,20 +26,23 @@ namespace osu.Game.Rulesets.Osu.Mods
public override ModType Type => ModType.Conversion; public override ModType Type => ModType.Conversion;
public override IconUsage? Icon => FontAwesome.Solid.Keyboard; public override IconUsage? Icon => FontAwesome.Solid.Keyboard;
private bool introEnded; private double firstObjectValidJudgementTime;
private double earliestStartTime;
private IBindable<bool> isBreakTime; private IBindable<bool> isBreakTime;
private const double flash_duration = 1000; private const double flash_duration = 1000;
private OsuAction? lastActionPressed; private OsuAction? lastActionPressed;
private DrawableRuleset<OsuHitObject> ruleset; private DrawableRuleset<OsuHitObject> ruleset;
private IFrameStableClock gameplayClock;
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset) public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
{ {
ruleset = drawableRuleset; ruleset = drawableRuleset;
drawableRuleset.KeyBindingInputManager.Add(new InputInterceptor(this)); drawableRuleset.KeyBindingInputManager.Add(new InputInterceptor(this));
var firstHitObject = ruleset.Objects.FirstOrDefault(); var firstHitObject = ruleset.Objects.FirstOrDefault();
earliestStartTime = (firstHitObject?.StartTime ?? 0) - (firstHitObject?.HitWindows.WindowFor(HitResult.Meh) ?? 0); firstObjectValidJudgementTime = (firstHitObject?.StartTime ?? 0) - (firstHitObject?.HitWindows.WindowFor(HitResult.Meh) ?? 0);
gameplayClock = drawableRuleset.FrameStableClock;
} }
public void ApplyToPlayer(Player player) public void ApplyToPlayer(Player player)
@ -57,7 +60,7 @@ namespace osu.Game.Rulesets.Osu.Mods
if (isBreakTime.Value) if (isBreakTime.Value)
return true; return true;
if (!introEnded) if (gameplayClock.CurrentTime < firstObjectValidJudgementTime)
return true; return true;
switch (action) switch (action)
@ -82,12 +85,6 @@ namespace osu.Game.Rulesets.Osu.Mods
return false; return false;
} }
public void Update(Playfield playfield)
{
if (!introEnded)
introEnded = playfield.Clock.CurrentTime > earliestStartTime;
}
private class InputInterceptor : Component, IKeyBindingHandler<OsuAction> private class InputInterceptor : Component, IKeyBindingHandler<OsuAction>
{ {
private readonly OsuModAlternate mod; private readonly OsuModAlternate mod;