mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 00:42:55 +08:00
Reset triangles on scale change
This commit is contained in:
parent
333165e052
commit
ebff844334
@ -17,6 +17,7 @@ using System.Collections.Generic;
|
||||
using osu.Framework.Graphics.Rendering;
|
||||
using osu.Framework.Graphics.Rendering.Vertices;
|
||||
using osu.Framework.Lists;
|
||||
using osu.Framework.Bindables;
|
||||
|
||||
namespace osu.Game.Graphics.Backgrounds
|
||||
{
|
||||
@ -69,7 +70,13 @@ namespace osu.Game.Graphics.Backgrounds
|
||||
/// </summary>
|
||||
protected virtual float SpawnRatio => 1;
|
||||
|
||||
private float triangleScale = 1;
|
||||
private readonly BindableFloat triangleScale = new BindableFloat(1f);
|
||||
|
||||
public float TriangleScale
|
||||
{
|
||||
get => triangleScale.Value;
|
||||
set => triangleScale.Value = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether we should drop-off alpha values of triangles more quickly to improve
|
||||
@ -109,24 +116,7 @@ namespace osu.Game.Graphics.Backgrounds
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
addTriangles(true);
|
||||
}
|
||||
|
||||
public float TriangleScale
|
||||
{
|
||||
get => triangleScale;
|
||||
set
|
||||
{
|
||||
float change = value / triangleScale;
|
||||
triangleScale = value;
|
||||
|
||||
for (int i = 0; i < parts.Count; i++)
|
||||
{
|
||||
TriangleParticle newParticle = parts[i];
|
||||
newParticle.Scale *= change;
|
||||
parts[i] = newParticle;
|
||||
}
|
||||
}
|
||||
triangleScale.BindValueChanged(_ => Reset(), true);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
@ -147,7 +137,7 @@ namespace osu.Game.Graphics.Backgrounds
|
||||
// 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 * TriangleScale);
|
||||
|
||||
for (int i = 0; i < parts.Count; i++)
|
||||
{
|
||||
@ -185,7 +175,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.002f / (TriangleScale * TriangleScale) * SpawnRatio);
|
||||
|
||||
for (int i = 0; i < AimCount - parts.Count; i++)
|
||||
parts.Add(createTriangle(randomY));
|
||||
@ -214,7 +204,7 @@ 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 scale = Math.Max(TriangleScale * (mean + std_dev * randStdNormal), 0.1f); // random normal(mean,stdDev^2)
|
||||
|
||||
return new TriangleParticle { Scale = scale };
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user