1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:57:36 +08:00

Replace Scale with SpeedMultiplier

This commit is contained in:
Andrei Zavatski 2022-11-16 15:12:57 +03:00
parent 109aa37dd8
commit cc4f05f3d3

View File

@ -57,14 +57,6 @@ namespace osu.Game.Graphics.Backgrounds
/// </summary>
protected virtual float SpawnRatio => 1;
private readonly BindableFloat triangleScale = new BindableFloat(1f);
public float TriangleScale
{
get => triangleScale.Value;
set => triangleScale.Value = value;
}
/// <summary>
/// The relative velocity of the triangles. Default is 1.
/// </summary>
@ -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
}
/// <summary>
/// Creates a triangle particle with a random scale.
/// Creates a triangle particle with a random speed multiplier.
/// </summary>
/// <returns>The triangle particle.</returns>
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;
/// <summary>
/// The scale of the triangle.
/// The speed multiplier of the triangle.
/// </summary>
public float Scale;
public float SpeedMultiplier;
}
}
}