From 953cf5af58f69f27974c357b69bd345167e61e9e Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 7 Aug 2017 13:26:45 +0900 Subject: [PATCH 1/2] Fix SpriteIcon invalidation causing game breakness. --- osu.Game/Graphics/SpriteIcon.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/SpriteIcon.cs b/osu.Game/Graphics/SpriteIcon.cs index 93c85d67cb..30125330c8 100644 --- a/osu.Game/Graphics/SpriteIcon.cs +++ b/osu.Game/Graphics/SpriteIcon.cs @@ -9,6 +9,7 @@ using osu.Framework.Graphics; using osu.Framework.IO.Stores; using OpenTK; using OpenTK.Graphics; +using osu.Framework.Caching; namespace osu.Game.Graphics { @@ -17,6 +18,7 @@ namespace osu.Game.Graphics private readonly Sprite spriteShadow; private readonly Sprite spriteMain; + private readonly Cached layout = new Cached(); private readonly Container shadowVisibility; public SpriteIcon() @@ -71,16 +73,23 @@ namespace osu.Game.Graphics public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true) { - if ((invalidation & Invalidation.Colour) > 0) + if ((invalidation & Invalidation.Colour) > 0 && Shadow) + layout.Invalidate(); + return base.Invalidate(invalidation, source, shallPropagate); + } + + protected override void Update() + { + if (!layout.IsValid) { //adjust shadow alpha based on highest component intensity to avoid muddy display of darker text. //squared result for quadratic fall-off seems to give the best result. var avgColour = (Color4)DrawInfo.Colour.AverageColour; spriteShadow.Alpha = (float)Math.Pow(Math.Max(Math.Max(avgColour.R, avgColour.G), avgColour.B), 2); - } - return base.Invalidate(invalidation, source, shallPropagate); + layout.Validate(); + } } public bool Shadow From ce7d391f06f9d52762f931b4d05e34bf4828bd20 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 7 Aug 2017 13:37:07 +0900 Subject: [PATCH 2/2] These method calls are impure. --- osu.Game/Graphics/SpriteIcon.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Graphics/SpriteIcon.cs b/osu.Game/Graphics/SpriteIcon.cs index 30125330c8..d49814952c 100644 --- a/osu.Game/Graphics/SpriteIcon.cs +++ b/osu.Game/Graphics/SpriteIcon.cs @@ -18,7 +18,7 @@ namespace osu.Game.Graphics private readonly Sprite spriteShadow; private readonly Sprite spriteMain; - private readonly Cached layout = new Cached(); + private Cached layout = new Cached(); private readonly Container shadowVisibility; public SpriteIcon()