From f70f25098b2b64999708d1771dce0189e4a4f029 Mon Sep 17 00:00:00 2001 From: Sebastian Krajewski Date: Mon, 6 Jan 2020 00:32:13 +0100 Subject: [PATCH 1/4] Change visible triangles colour when dark or light colour is changed --- osu.Game/Graphics/Backgrounds/Triangles.cs | 46 ++++++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/Triangles.cs b/osu.Game/Graphics/Backgrounds/Triangles.cs index 6d88808150..cbb50f7ddb 100644 --- a/osu.Game/Graphics/Backgrounds/Triangles.cs +++ b/osu.Game/Graphics/Backgrounds/Triangles.cs @@ -29,8 +29,29 @@ namespace osu.Game.Graphics.Backgrounds /// private const float edge_smoothness = 1; - public Color4 ColourLight = Color4.White; - public Color4 ColourDark = Color4.Black; + private Color4 colourLight = Color4.White; + + public Color4 ColourLight + { + get => colourLight; + set + { + colourLight = value; + updateColours(); + } + } + + private Color4 colourDark = Color4.Black; + + public Color4 ColourDark + { + get => colourDark; + set + { + colourDark = value; + updateColours(); + } + } /// /// Whether we want to expire triangles as they exit our draw area completely. @@ -151,7 +172,8 @@ namespace osu.Game.Graphics.Backgrounds TriangleParticle particle = CreateTriangle(); particle.Position = new Vector2(RNG.NextSingle(), randomY ? RNG.NextSingle() : 1); - particle.Colour = CreateTriangleShade(); + particle.ColourShade = RNG.NextSingle(); + particle.Colour = CreateTriangleShade(particle.ColourShade); return particle; } @@ -177,7 +199,17 @@ namespace osu.Game.Graphics.Backgrounds /// Creates a shade of colour for the triangles. /// /// The colour. - protected virtual Color4 CreateTriangleShade() => Interpolation.ValueAt(RNG.NextSingle(), ColourDark, ColourLight, 0, 1); + protected virtual Color4 CreateTriangleShade(float shade) => Interpolation.ValueAt(shade, colourDark, colourLight, 0, 1); + + private void updateColours() + { + for (int i = 0; i < parts.Count; i++) + { + TriangleParticle newParticle = parts[i]; + newParticle.Colour = CreateTriangleShade(newParticle.ColourShade); + parts[i] = newParticle; + } + } protected override DrawNode CreateDrawNode() => new TrianglesDrawNode(this); @@ -264,6 +296,12 @@ namespace osu.Game.Graphics.Backgrounds /// public Vector2 Position; + /// + /// The colour shade of the triangle. + /// This is needed for colour recalculation of visible triangles when or is changed. + /// + public float ColourShade; + /// /// The colour of the triangle. /// From d1f3cb3dbdc928317d21242374d1a6d0ec2f1152 Mon Sep 17 00:00:00 2001 From: Sebastian Krajewski Date: Mon, 6 Jan 2020 01:53:29 +0100 Subject: [PATCH 2/4] Premature checks to avoid unnecessary updates --- osu.Game/Graphics/Backgrounds/Triangles.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/osu.Game/Graphics/Backgrounds/Triangles.cs b/osu.Game/Graphics/Backgrounds/Triangles.cs index cbb50f7ddb..af492bacc9 100644 --- a/osu.Game/Graphics/Backgrounds/Triangles.cs +++ b/osu.Game/Graphics/Backgrounds/Triangles.cs @@ -36,6 +36,8 @@ namespace osu.Game.Graphics.Backgrounds get => colourLight; set { + if (colourLight == value) return; + colourLight = value; updateColours(); } @@ -48,6 +50,8 @@ namespace osu.Game.Graphics.Backgrounds get => colourDark; set { + if (colourDark == value) return; + colourDark = value; updateColours(); } From de4c62788c88bb9ced4e976c9a32ccafba3f4266 Mon Sep 17 00:00:00 2001 From: Sebastian Krajewski Date: Mon, 6 Jan 2020 12:51:38 +0100 Subject: [PATCH 3/4] Move colour generation to TriangleParticle --- osu.Game/Graphics/Backgrounds/Triangles.cs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/Triangles.cs b/osu.Game/Graphics/Backgrounds/Triangles.cs index af492bacc9..0eb5e90d3e 100644 --- a/osu.Game/Graphics/Backgrounds/Triangles.cs +++ b/osu.Game/Graphics/Backgrounds/Triangles.cs @@ -176,8 +176,7 @@ namespace osu.Game.Graphics.Backgrounds TriangleParticle particle = CreateTriangle(); particle.Position = new Vector2(RNG.NextSingle(), randomY ? RNG.NextSingle() : 1); - particle.ColourShade = RNG.NextSingle(); - particle.Colour = CreateTriangleShade(particle.ColourShade); + particle.UpdateColour(colourDark, colourLight); return particle; } @@ -199,18 +198,12 @@ namespace osu.Game.Graphics.Backgrounds return new TriangleParticle { Scale = scale }; } - /// - /// Creates a shade of colour for the triangles. - /// - /// The colour. - protected virtual Color4 CreateTriangleShade(float shade) => Interpolation.ValueAt(shade, colourDark, colourLight, 0, 1); - private void updateColours() { for (int i = 0; i < parts.Count; i++) { TriangleParticle newParticle = parts[i]; - newParticle.Colour = CreateTriangleShade(newParticle.ColourShade); + newParticle.UpdateColour(colourDark, colourLight); parts[i] = newParticle; } } @@ -293,7 +286,7 @@ namespace osu.Game.Graphics.Backgrounds } } - protected struct TriangleParticle : IComparable + protected class TriangleParticle : IComparable { /// /// The position of the top vertex of the triangle. @@ -304,7 +297,7 @@ namespace osu.Game.Graphics.Backgrounds /// The colour shade of the triangle. /// This is needed for colour recalculation of visible triangles when or is changed. /// - public float ColourShade; + private readonly float colourShade = RNG.NextSingle(); /// /// The colour of the triangle. @@ -316,6 +309,11 @@ namespace osu.Game.Graphics.Backgrounds /// public float Scale; + public void UpdateColour(Color4 colourDark, Color4 colourLight) + { + Colour = Interpolation.ValueAt(colourShade, colourDark, colourLight, 0, 1); + } + /// /// Compares two s. This is a reverse comparer because when the /// triangles are added to the particles list, they should be drawn from largest to smallest From 0b9cc8ed1b4e2f15ceb11228a51a7f27afce5e67 Mon Sep 17 00:00:00 2001 From: Sebastian Krajewski Date: Mon, 6 Jan 2020 12:51:38 +0100 Subject: [PATCH 4/4] Revert "Move colour generation to TriangleParticle" This reverts commit de4c62788c88bb9ced4e976c9a32ccafba3f4266. --- osu.Game/Graphics/Backgrounds/Triangles.cs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/Triangles.cs b/osu.Game/Graphics/Backgrounds/Triangles.cs index 0eb5e90d3e..af492bacc9 100644 --- a/osu.Game/Graphics/Backgrounds/Triangles.cs +++ b/osu.Game/Graphics/Backgrounds/Triangles.cs @@ -176,7 +176,8 @@ namespace osu.Game.Graphics.Backgrounds TriangleParticle particle = CreateTriangle(); particle.Position = new Vector2(RNG.NextSingle(), randomY ? RNG.NextSingle() : 1); - particle.UpdateColour(colourDark, colourLight); + particle.ColourShade = RNG.NextSingle(); + particle.Colour = CreateTriangleShade(particle.ColourShade); return particle; } @@ -198,12 +199,18 @@ namespace osu.Game.Graphics.Backgrounds return new TriangleParticle { Scale = scale }; } + /// + /// Creates a shade of colour for the triangles. + /// + /// The colour. + protected virtual Color4 CreateTriangleShade(float shade) => Interpolation.ValueAt(shade, colourDark, colourLight, 0, 1); + private void updateColours() { for (int i = 0; i < parts.Count; i++) { TriangleParticle newParticle = parts[i]; - newParticle.UpdateColour(colourDark, colourLight); + newParticle.Colour = CreateTriangleShade(newParticle.ColourShade); parts[i] = newParticle; } } @@ -286,7 +293,7 @@ namespace osu.Game.Graphics.Backgrounds } } - protected class TriangleParticle : IComparable + protected struct TriangleParticle : IComparable { /// /// The position of the top vertex of the triangle. @@ -297,7 +304,7 @@ namespace osu.Game.Graphics.Backgrounds /// The colour shade of the triangle. /// This is needed for colour recalculation of visible triangles when or is changed. /// - private readonly float colourShade = RNG.NextSingle(); + public float ColourShade; /// /// The colour of the triangle. @@ -309,11 +316,6 @@ namespace osu.Game.Graphics.Backgrounds /// public float Scale; - public void UpdateColour(Color4 colourDark, Color4 colourLight) - { - Colour = Interpolation.ValueAt(colourShade, colourDark, colourLight, 0, 1); - } - /// /// Compares two s. This is a reverse comparer because when the /// triangles are added to the particles list, they should be drawn from largest to smallest