mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 08:43:20 +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;
|
||||||
using osu.Framework.Graphics.Rendering.Vertices;
|
using osu.Framework.Graphics.Rendering.Vertices;
|
||||||
using osu.Framework.Lists;
|
using osu.Framework.Lists;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
|
||||||
namespace osu.Game.Graphics.Backgrounds
|
namespace osu.Game.Graphics.Backgrounds
|
||||||
{
|
{
|
||||||
@ -69,7 +70,13 @@ namespace osu.Game.Graphics.Backgrounds
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual float SpawnRatio => 1;
|
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>
|
/// <summary>
|
||||||
/// Whether we should drop-off alpha values of triangles more quickly to improve
|
/// 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()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
addTriangles(true);
|
triangleScale.BindValueChanged(_ => Reset(), 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update()
|
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 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
|
// Since we will later multiply by the scale of individual triangles we normalize by
|
||||||
// dividing by triangleScale.
|
// 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++)
|
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.
|
// Limited by the maximum size of QuadVertexBuffer for safety.
|
||||||
const int max_triangles = ushort.MaxValue / (IRenderer.VERTICES_PER_QUAD + 2);
|
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++)
|
for (int i = 0; i < AimCount - parts.Count; i++)
|
||||||
parts.Add(createTriangle(randomY));
|
parts.Add(createTriangle(randomY));
|
||||||
@ -214,7 +204,7 @@ namespace osu.Game.Graphics.Backgrounds
|
|||||||
float u1 = 1 - nextRandom(); //uniform(0,1] random floats
|
float u1 = 1 - nextRandom(); //uniform(0,1] random floats
|
||||||
float u2 = 1 - nextRandom();
|
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 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 };
|
return new TriangleParticle { Scale = scale };
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user