From cc4f05f3d3ce98a33f3c51a2779d42930f4cc480 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 16 Nov 2022 15:12:57 +0300 Subject: [PATCH] Replace Scale with SpeedMultiplier --- osu.Game/Graphics/Backgrounds/TrianglesV2.cs | 35 +++++++------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs index 01e4a39431..da31c6112b 100644 --- a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs +++ b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs @@ -57,14 +57,6 @@ namespace osu.Game.Graphics.Backgrounds /// protected virtual float SpawnRatio => 1; - private readonly BindableFloat triangleScale = new BindableFloat(1f); - - public float TriangleScale - { - get => triangleScale.Value; - set => triangleScale.Value = value; - } - /// /// The relative velocity of the triangles. Default is 1. /// @@ -102,7 +94,7 @@ namespace osu.Game.Graphics.Backgrounds colourTop.BindValueChanged(_ => updateTexture()); colourBottom.BindValueChanged(_ => updateTexture(), true); - triangleScale.BindValueChanged(_ => Reset(), true); + addTriangles(true); } private void updateTexture() @@ -138,20 +130,17 @@ namespace osu.Game.Graphics.Backgrounds float elapsedSeconds = (float)Time.Elapsed / 1000; // Since position is relative, the velocity needs to scale inversely with DrawHeight. - // Since we will later multiply by the scale of individual triangles we normalize by - // dividing by triangleScale. - float movedDistance = -elapsedSeconds * Velocity * base_velocity / (DrawHeight * TriangleScale); + float movedDistance = -elapsedSeconds * Velocity * base_velocity / DrawHeight; for (int i = 0; i < parts.Count; i++) { TriangleParticle newParticle = parts[i]; - // Scale moved distance by the size of the triangle. Smaller triangles should move more slowly. - newParticle.Position.Y += Math.Max(0.5f, parts[i].Scale) * movedDistance; + newParticle.Position.Y += Math.Max(0.5f, parts[i].SpeedMultiplier) * movedDistance; parts[i] = newParticle; - float bottomPos = parts[i].Position.Y + triangle_size * parts[i].Scale * equilateral_triangle_ratio / DrawHeight; + float bottomPos = parts[i].Position.Y + triangle_size * equilateral_triangle_ratio / DrawHeight; if (bottomPos < 0) parts.RemoveAt(i); } @@ -177,7 +166,7 @@ namespace osu.Game.Graphics.Backgrounds // Limited by the maximum size of QuadVertexBuffer for safety. const int max_triangles = ushort.MaxValue / (IRenderer.VERTICES_PER_QUAD + 2); - AimCount = (int)Math.Min(max_triangles, DrawWidth * DrawHeight * 0.002f / (TriangleScale * TriangleScale) * SpawnRatio); + AimCount = (int)Math.Min(max_triangles, DrawWidth * DrawHeight * 0.001f * SpawnRatio); int currentCount = parts.Count; @@ -194,7 +183,7 @@ namespace osu.Game.Graphics.Backgrounds if (randomY) { // since triangles are drawn from the top - allow them to be positioned a bit above the screen - float maxOffset = triangle_size * particle.Scale * equilateral_triangle_ratio / DrawHeight; + float maxOffset = triangle_size * equilateral_triangle_ratio / DrawHeight; y = Interpolation.ValueAt(nextRandom(), -maxOffset, 1f, 0f, 1f); } @@ -204,7 +193,7 @@ namespace osu.Game.Graphics.Backgrounds } /// - /// Creates a triangle particle with a random scale. + /// Creates a triangle particle with a random speed multiplier. /// /// The triangle particle. protected virtual TriangleParticle CreateTriangle() @@ -215,9 +204,9 @@ namespace osu.Game.Graphics.Backgrounds float u1 = 1 - nextRandom(); //uniform(0,1] random floats float u2 = 1 - nextRandom(); float randStdNormal = (float)(Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2)); // random normal(0,1) - float scale = Math.Max(TriangleScale * (mean + std_dev * randStdNormal), 0.1f); // random normal(mean,stdDev^2) + float speedMultiplier = Math.Max(mean + std_dev * randStdNormal, 0.1f); // random normal(mean,stdDev^2) - return new TriangleParticle { Scale = scale }; + return new TriangleParticle { SpeedMultiplier = speedMultiplier }; } private float nextRandom() => (float)(stableRandom?.NextDouble() ?? RNG.NextSingle()); @@ -267,7 +256,7 @@ namespace osu.Game.Graphics.Backgrounds foreach (TriangleParticle particle in parts) { - var offset = triangle_size * new Vector2(particle.Scale * 0.5f, particle.Scale * equilateral_triangle_ratio); + var offset = triangle_size * new Vector2(0.5f, equilateral_triangle_ratio); Vector2 topLeft = particle.Position * size + new Vector2(-offset.X, 0f); Vector2 topRight = particle.Position * size + new Vector2(offset.X, 0); @@ -310,9 +299,9 @@ namespace osu.Game.Graphics.Backgrounds public Vector2 Position; /// - /// The scale of the triangle. + /// The speed multiplier of the triangle. /// - public float Scale; + public float SpeedMultiplier; } } }