1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 16:32:54 +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; velocityFrameLength = 0;
} }
protected override FallingParticle SpawnParticle() protected override FallingParticle CreateParticle() =>
{ new FallingParticle
var p = base.SpawnParticle(); {
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); private Vector2 getVelocity()
p.Duration = RNG.NextSingle(particle_lifetime_min, particle_lifetime_max); {
p.StartAngle = (float)(RNG.NextDouble() * 4 - 2); Vector2 velocity = Vector2.Zero;
p.EndAngle = RNG.NextSingle(-2f, 2f);
p.EndScale = RNG.NextSingle(2f);
switch (Direction) switch (Direction)
{ {
case SpewDirection.None:
p.Velocity = Vector2.Zero;
break;
case SpewDirection.Left: case SpewDirection.Left:
p.Velocity = new Vector2( velocity = new Vector2(
RNG.NextSingle(-460f, 0), RNG.NextSingle(-460f, 0),
RNG.NextSingle(-40f, 40f) RNG.NextSingle(-40f, 40f)
); );
break; break;
case SpewDirection.Right: case SpewDirection.Right:
p.Velocity = new Vector2( velocity = new Vector2(
RNG.NextSingle(0, 460f), RNG.NextSingle(0, 460f),
RNG.NextSingle(-40f, 40f) RNG.NextSingle(-40f, 40f)
); );
break; break;
case SpewDirection.Omni: case SpewDirection.Omni:
p.Velocity = new Vector2( velocity = new Vector2(
RNG.NextSingle(-460f, 460f), RNG.NextSingle(-460f, 460f),
RNG.NextSingle(-160f, 160f) RNG.NextSingle(-160f, 160f)
); );
break; 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() protected override FallingParticle CreateParticle() =>
{ new FallingParticle
var p = base.SpawnParticle(); {
p.Velocity = new Vector2( Velocity = new Vector2(
RNG.NextSingle(-MaxVelocity, MaxVelocity), RNG.NextSingle(-MaxVelocity, MaxVelocity),
RNG.NextSingle(-MaxVelocity, MaxVelocity) RNG.NextSingle(-MaxVelocity, MaxVelocity)
); ),
p.Duration = RNG.NextSingle(lifetime); Duration = RNG.NextSingle(lifetime),
p.StartAngle = RNG.NextSingle(MathF.PI * 2); StartAngle = RNG.NextSingle(MathF.PI * 2),
p.EndAngle = RNG.NextSingle(MathF.PI * 2); EndAngle = RNG.NextSingle(MathF.PI * 2),
p.EndScale = RNG.NextSingle(0.5f, 1.5f); EndScale = RNG.NextSingle(0.5f, 1.5f)
};
return p;
}
} }
} }
} }

View File

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