diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs b/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs index 8645730d09..6592b8b313 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModFlashlight.cs @@ -40,9 +40,9 @@ namespace osu.Game.Rulesets.Catch.Mods { base.Update(); - var catcher = playfield.CatcherArea.MovableCatcher; + var catcherArea = playfield.CatcherArea; - FlashlightPosition = catcher.ToSpaceOfOtherDrawable(catcher.Position, this); + FlashlightPosition = catcherArea.ToSpaceOfOtherDrawable(catcherArea.MovableCatcher.DrawPosition, this); } private float getSizeFor(int combo) diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModFlashlight.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModFlashlight.cs index 32ac668f69..e0e395ce55 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModFlashlight.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModFlashlight.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; +using osu.Framework.Caching; using osu.Framework.Graphics; using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mods; @@ -20,6 +21,8 @@ namespace osu.Game.Rulesets.Mania.Mods private class ManiaFlashlight : Flashlight { + private readonly Cached flashlightProperties = new Cached(); + public ManiaFlashlight() { FlashlightSize = new Vector2(0, default_flashlight_size); @@ -29,29 +32,30 @@ namespace osu.Game.Rulesets.Mania.Mods { if ((invalidation & Invalidation.DrawSize) > 0) { - Schedule(() => - { - FlashlightSize = new Vector2(DrawWidth, FlashlightSize.Y); - - FlashlightPosition = DrawPosition + DrawSize / 2; - }); + flashlightProperties.Invalidate(); } return base.Invalidate(invalidation, source, shallPropagate); } + protected override void Update() + { + base.Update(); + + if (!flashlightProperties.IsValid) + { + FlashlightSize = new Vector2(DrawWidth, FlashlightSize.Y); + + FlashlightPosition = DrawPosition + DrawSize / 2; + flashlightProperties.Validate(); + } + } + protected override void OnComboChange(int newCombo) { } protected override string FragmentShader => "RectangularFlashlight"; - - protected override void LoadComplete() - { - FlashlightSize = new Vector2(DrawWidth, FlashlightSize.Y); - - FlashlightPosition = DrawPosition + DrawSize / 2; - } } } } diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs index a58d55f904..5e865d7727 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModFlashlight.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Framework.Caching; using osu.Framework.Graphics; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Taiko.Objects; @@ -28,6 +29,7 @@ namespace osu.Game.Rulesets.Taiko.Mods private class TaikoFlashlight : Flashlight { + private readonly Cached flashlightProperties = new Cached(); private readonly TaikoPlayfield taikoPlayfield; public TaikoFlashlight(TaikoPlayfield taikoPlayfield) @@ -57,20 +59,21 @@ namespace osu.Game.Rulesets.Taiko.Mods { if ((invalidation & Invalidation.DrawSize) > 0) { - Schedule(() => - { - FlashlightPosition = taikoPlayfield.HitTarget.ToSpaceOfOtherDrawable(taikoPlayfield.HitTarget.OriginPosition, this); - }); + flashlightProperties.Invalidate(); } return base.Invalidate(invalidation, source, shallPropagate); } - protected override void LoadComplete() + protected override void Update() { - base.LoadComplete(); + base.Update(); - FlashlightPosition = taikoPlayfield.HitTarget.ToSpaceOfOtherDrawable(taikoPlayfield.HitTarget.OriginPosition, this); + if (!flashlightProperties.IsValid) + { + FlashlightPosition = taikoPlayfield.HitTarget.ToSpaceOfOtherDrawable(taikoPlayfield.HitTarget.OriginPosition, this); + flashlightProperties.Validate(); + } } } } diff --git a/osu.Game/Rulesets/Mods/ModFlashlight.cs b/osu.Game/Rulesets/Mods/ModFlashlight.cs index 2063f5cf88..5e5353bfdd 100644 --- a/osu.Game/Rulesets/Mods/ModFlashlight.cs +++ b/osu.Game/Rulesets/Mods/ModFlashlight.cs @@ -70,8 +70,8 @@ namespace osu.Game.Rulesets.Mods flashNode.Shader = shader; flashNode.ScreenSpaceDrawQuad = ScreenSpaceDrawQuad; - flashNode.MousePosWrapper.FlashlightPosition = Vector2Extensions.Transform(FlashlightPosition, DrawInfo.Matrix); - flashNode.MousePosWrapper.FlashlightSize = Vector2Extensions.Transform(FlashlightSize, DrawInfo.Matrix); + flashNode.FlashlightPosition = Vector2Extensions.Transform(FlashlightPosition, DrawInfo.Matrix); + flashNode.FlashlightSize = Vector2Extensions.Transform(FlashlightSize, DrawInfo.Matrix); } [BackgroundDependencyLoader] @@ -128,17 +128,12 @@ namespace osu.Game.Rulesets.Mods } } - public struct FlashlightUniformWrapper - { - public Vector2 FlashlightPosition; - public Vector2 FlashlightSize; - } - private class FlashlightDrawNode : DrawNode { public Shader Shader; public Quad ScreenSpaceDrawQuad; - public FlashlightUniformWrapper MousePosWrapper; + public Vector2 FlashlightPosition; + public Vector2 FlashlightSize; public override void Draw(Action vertexAction) { @@ -146,8 +141,8 @@ namespace osu.Game.Rulesets.Mods Shader.Bind(); - Shader.GetUniform("flashlightPos").UpdateValue(ref MousePosWrapper.FlashlightPosition); - Shader.GetUniform("flashlightSize").UpdateValue(ref MousePosWrapper.FlashlightSize); + Shader.GetUniform("flashlightPos").UpdateValue(ref FlashlightPosition); + Shader.GetUniform("flashlightSize").UpdateValue(ref FlashlightSize); Texture.WhitePixel.DrawQuad(ScreenSpaceDrawQuad, DrawColourInfo.Colour, vertexAction: vertexAction);