1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 10:33:30 +08:00

SpawnParticle -> CreateParticle (and set time outside of virtual call)

Allows easier overriding (no need to call the `base.CreateParticle` call
and worry about overwriting the time value.
This commit is contained in:
Dean Herbert 2021-09-16 16:50:03 +09:00
parent 29ce2f05bd
commit 2df4073946
3 changed files with 35 additions and 39 deletions

View File

@ -179,47 +179,48 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
velocityFrameLength = 0;
}
protected override FallingParticle SpawnParticle()
{
var p = base.SpawnParticle();
protected override FallingParticle CreateParticle() =>
new FallingParticle
{
StartPosition = ToLocalSpace(cursorScreenPosition ?? Vector2.Zero),
Duration = RNG.NextSingle(particle_lifetime_min, particle_lifetime_max),
StartAngle = (float)(RNG.NextDouble() * 4 - 2),
EndAngle = RNG.NextSingle(-2f, 2f),
EndScale = RNG.NextSingle(2f),
Velocity = getVelocity(),
};
p.StartPosition = ToLocalSpace(cursorScreenPosition ?? Vector2.Zero);
p.Duration = RNG.NextSingle(particle_lifetime_min, particle_lifetime_max);
p.StartAngle = (float)(RNG.NextDouble() * 4 - 2);
p.EndAngle = RNG.NextSingle(-2f, 2f);
p.EndScale = RNG.NextSingle(2f);
private Vector2 getVelocity()
{
Vector2 velocity = Vector2.Zero;
switch (Direction)
{
case SpewDirection.None:
p.Velocity = Vector2.Zero;
break;
case SpewDirection.Left:
p.Velocity = new Vector2(
velocity = new Vector2(
RNG.NextSingle(-460f, 0),
RNG.NextSingle(-40f, 40f)
);
break;
case SpewDirection.Right:
p.Velocity = new Vector2(
velocity = new Vector2(
RNG.NextSingle(0, 460f),
RNG.NextSingle(-40f, 40f)
);
break;
case SpewDirection.Omni:
p.Velocity = new Vector2(
velocity = new Vector2(
RNG.NextSingle(-460f, 460f),
RNG.NextSingle(-160f, 160f)
);
break;
}
p.Velocity += cursorVelocity * 40;
velocity += cursorVelocity * 40;
return p;
return velocity;
}
}

View File

@ -75,20 +75,18 @@ namespace osu.Game.Tests.Visual.Gameplay
{
}
protected override FallingParticle SpawnParticle()
{
var p = base.SpawnParticle();
p.Velocity = new Vector2(
RNG.NextSingle(-MaxVelocity, MaxVelocity),
RNG.NextSingle(-MaxVelocity, MaxVelocity)
);
p.Duration = RNG.NextSingle(lifetime);
p.StartAngle = RNG.NextSingle(MathF.PI * 2);
p.EndAngle = RNG.NextSingle(MathF.PI * 2);
p.EndScale = RNG.NextSingle(0.5f, 1.5f);
return p;
}
protected override FallingParticle CreateParticle() =>
new FallingParticle
{
Velocity = new Vector2(
RNG.NextSingle(-MaxVelocity, MaxVelocity),
RNG.NextSingle(-MaxVelocity, MaxVelocity)
),
Duration = RNG.NextSingle(lifetime),
StartAngle = RNG.NextSingle(MathF.PI * 2),
EndAngle = RNG.NextSingle(MathF.PI * 2),
EndScale = RNG.NextSingle(0.5f, 1.5f)
};
}
}
}

View File

@ -53,7 +53,10 @@ namespace osu.Game.Graphics
if (Active.Value && CanSpawnParticles && Time.Current > lastParticleAdded + cooldown)
{
particles[currentIndex] = SpawnParticle();
var newParticle = CreateParticle();
newParticle.StartTime = (float)Time.Current;
particles[currentIndex] = newParticle;
currentIndex = (currentIndex + 1) % particles.Length;
lastParticleAdded = Time.Current;
@ -65,13 +68,7 @@ namespace osu.Game.Graphics
/// <summary>
/// Called each time a new particle should be spawned.
/// </summary>
protected virtual FallingParticle SpawnParticle()
{
return new FallingParticle
{
StartTime = (float)Time.Current,
};
}
protected virtual FallingParticle CreateParticle() => new FallingParticle();
protected override DrawNode CreateDrawNode() => new ParticleSpewerDrawNode(this);