mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 06:57:39 +08:00
Revert af4c3727d77a16e2534df9bbf452336b5c544342
This commit is contained in:
parent
af4c3727d7
commit
761da45f6a
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ContentModelUserStore">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
|
@ -6,6 +6,7 @@ using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Input.Events;
|
||||
@ -20,17 +21,12 @@ using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
||||
{
|
||||
public class LegacyCursorParticles : CompositeDrawable, IKeyBindingHandler<OsuAction>, IRequireHighFrequencyMousePosition
|
||||
public class LegacyCursorParticles : CompositeDrawable, IKeyBindingHandler<OsuAction>
|
||||
{
|
||||
private const int particle_lifetime_min = 300;
|
||||
private const int particle_lifetime_max = 1000;
|
||||
private const float particle_gravity = 240;
|
||||
|
||||
public bool Active => breakSpewer?.Active.Value == true || kiaiSpewer?.Active.Value == true;
|
||||
|
||||
private Vector2 cursorVelocity;
|
||||
private ParticleSpewer breakSpewer;
|
||||
private ParticleSpewer kiaiSpewer;
|
||||
private LegacyCursorParticleSpewer breakSpewer;
|
||||
private LegacyCursorParticleSpewer kiaiSpewer;
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private Player player { get; set; }
|
||||
@ -50,25 +46,21 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
||||
texture.ScaleAdjust *= 1.6f;
|
||||
}
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
Anchor = Anchor.Centre;
|
||||
InternalChildren = new[]
|
||||
{
|
||||
breakSpewer = new ParticleSpewer(texture, 20, particle_lifetime_max)
|
||||
breakSpewer = new LegacyCursorParticleSpewer(texture, 20)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Size = Vector2.One,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Colour = starBreakAdditive,
|
||||
ParticleGravity = particle_gravity,
|
||||
CreateParticle = createBreakParticle,
|
||||
Direction = SpewDirection.None,
|
||||
},
|
||||
kiaiSpewer = new ParticleSpewer(texture, 60, particle_lifetime_max)
|
||||
kiaiSpewer = new LegacyCursorParticleSpewer(texture, 60)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Size = Vector2.One,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Colour = starBreakAdditive,
|
||||
ParticleGravity = particle_gravity,
|
||||
CreateParticle = createParticle,
|
||||
Direction = SpewDirection.None,
|
||||
},
|
||||
};
|
||||
|
||||
@ -94,39 +86,6 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
||||
kiaiSpewer.Active.Value = kiaiHitObject != null;
|
||||
}
|
||||
|
||||
private Vector2? cursorScreenPosition;
|
||||
|
||||
private const double max_velocity_frame_length = 15;
|
||||
private double velocityFrameLength;
|
||||
private Vector2 totalPosDifference;
|
||||
|
||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
||||
|
||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||
{
|
||||
if (cursorScreenPosition == null)
|
||||
{
|
||||
cursorScreenPosition = e.ScreenSpaceMousePosition;
|
||||
return base.OnMouseMove(e);
|
||||
}
|
||||
|
||||
// calculate cursor velocity.
|
||||
totalPosDifference += e.ScreenSpaceMousePosition - cursorScreenPosition.Value;
|
||||
cursorScreenPosition = e.ScreenSpaceMousePosition;
|
||||
|
||||
velocityFrameLength += Math.Abs(Clock.ElapsedFrameTime);
|
||||
|
||||
if (velocityFrameLength > max_velocity_frame_length)
|
||||
{
|
||||
cursorVelocity = totalPosDifference / (float)velocityFrameLength;
|
||||
|
||||
totalPosDifference = Vector2.Zero;
|
||||
velocityFrameLength = 0;
|
||||
}
|
||||
|
||||
return base.OnMouseMove(e);
|
||||
}
|
||||
|
||||
public bool OnPressed(KeyBindingPressEvent<OsuAction> e)
|
||||
{
|
||||
handleInput(e.Action, true);
|
||||
@ -153,53 +112,125 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
||||
rightPressed = pressed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private ParticleSpewer.FallingParticle? createParticle()
|
||||
{
|
||||
if (!cursorScreenPosition.HasValue) return null;
|
||||
|
||||
return new ParticleSpewer.FallingParticle
|
||||
{
|
||||
StartPosition = ToLocalSpace(cursorScreenPosition.Value),
|
||||
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 = cursorVelocity * 40,
|
||||
};
|
||||
}
|
||||
|
||||
private ParticleSpewer.FallingParticle? createBreakParticle()
|
||||
{
|
||||
var baseParticle = createParticle();
|
||||
if (!baseParticle.HasValue) return null;
|
||||
|
||||
var p = baseParticle.Value;
|
||||
|
||||
if (leftPressed && rightPressed)
|
||||
{
|
||||
p.Velocity += new Vector2(
|
||||
RNG.NextSingle(-460f, 460f),
|
||||
RNG.NextSingle(-160f, 160f)
|
||||
);
|
||||
}
|
||||
breakSpewer.Direction = SpewDirection.Omni;
|
||||
else if (leftPressed)
|
||||
{
|
||||
p.Velocity += new Vector2(
|
||||
RNG.NextSingle(-460f, 0),
|
||||
RNG.NextSingle(-40f, 40f)
|
||||
);
|
||||
}
|
||||
breakSpewer.Direction = SpewDirection.Left;
|
||||
else if (rightPressed)
|
||||
breakSpewer.Direction = SpewDirection.Right;
|
||||
else
|
||||
breakSpewer.Direction = SpewDirection.None;
|
||||
}
|
||||
|
||||
private class LegacyCursorParticleSpewer : ParticleSpewer, IRequireHighFrequencyMousePosition
|
||||
{
|
||||
private const int particle_duration_min = 300;
|
||||
private const int particle_duration_max = 1000;
|
||||
|
||||
public SpewDirection Direction { get; set; }
|
||||
|
||||
protected override bool CanSpawnParticles => base.CanSpawnParticles && cursorScreenPosition.HasValue;
|
||||
protected override float ParticleGravity => 240;
|
||||
|
||||
public LegacyCursorParticleSpewer(Texture texture, int perSecond)
|
||||
: base(texture, perSecond, particle_duration_max)
|
||||
{
|
||||
p.Velocity += new Vector2(
|
||||
RNG.NextSingle(0, 460f),
|
||||
RNG.NextSingle(-40f, 40f)
|
||||
);
|
||||
Active.BindValueChanged(_ => resetVelocityCalculation());
|
||||
}
|
||||
|
||||
return p;
|
||||
private Vector2? cursorScreenPosition;
|
||||
private Vector2 cursorVelocity;
|
||||
|
||||
private const double max_velocity_frame_length = 15;
|
||||
private double velocityFrameLength;
|
||||
private Vector2 totalPosDifference;
|
||||
|
||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
||||
|
||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||
{
|
||||
if (cursorScreenPosition == null)
|
||||
{
|
||||
cursorScreenPosition = e.ScreenSpaceMousePosition;
|
||||
return base.OnMouseMove(e);
|
||||
}
|
||||
|
||||
// calculate cursor velocity.
|
||||
totalPosDifference += e.ScreenSpaceMousePosition - cursorScreenPosition.Value;
|
||||
cursorScreenPosition = e.ScreenSpaceMousePosition;
|
||||
|
||||
velocityFrameLength += Math.Abs(Clock.ElapsedFrameTime);
|
||||
|
||||
if (velocityFrameLength > max_velocity_frame_length)
|
||||
{
|
||||
cursorVelocity = totalPosDifference / (float)velocityFrameLength;
|
||||
|
||||
totalPosDifference = Vector2.Zero;
|
||||
velocityFrameLength = 0;
|
||||
}
|
||||
|
||||
return base.OnMouseMove(e);
|
||||
}
|
||||
|
||||
private void resetVelocityCalculation()
|
||||
{
|
||||
cursorScreenPosition = null;
|
||||
totalPosDifference = Vector2.Zero;
|
||||
velocityFrameLength = 0;
|
||||
}
|
||||
|
||||
protected override FallingParticle CreateParticle() =>
|
||||
new FallingParticle
|
||||
{
|
||||
StartPosition = ToLocalSpace(cursorScreenPosition ?? Vector2.Zero),
|
||||
Duration = RNG.NextSingle(particle_duration_min, particle_duration_max),
|
||||
StartAngle = (float)(RNG.NextDouble() * 4 - 2),
|
||||
EndAngle = RNG.NextSingle(-2f, 2f),
|
||||
EndScale = RNG.NextSingle(2f),
|
||||
Velocity = getVelocity(),
|
||||
};
|
||||
|
||||
private Vector2 getVelocity()
|
||||
{
|
||||
Vector2 velocity = Vector2.Zero;
|
||||
|
||||
switch (Direction)
|
||||
{
|
||||
case SpewDirection.Left:
|
||||
velocity = new Vector2(
|
||||
RNG.NextSingle(-460f, 0),
|
||||
RNG.NextSingle(-40f, 40f)
|
||||
);
|
||||
break;
|
||||
|
||||
case SpewDirection.Right:
|
||||
velocity = new Vector2(
|
||||
RNG.NextSingle(0, 460f),
|
||||
RNG.NextSingle(-40f, 40f)
|
||||
);
|
||||
break;
|
||||
|
||||
case SpewDirection.Omni:
|
||||
velocity = new Vector2(
|
||||
RNG.NextSingle(-460f, 460f),
|
||||
RNG.NextSingle(-160f, 160f)
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
velocity += cursorVelocity * 40;
|
||||
|
||||
return velocity;
|
||||
}
|
||||
}
|
||||
|
||||
private enum SpewDirection
|
||||
{
|
||||
None,
|
||||
Left,
|
||||
Right,
|
||||
Omni,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using System;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Graphics;
|
||||
@ -16,12 +17,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
[TestFixture]
|
||||
public class TestSceneParticleSpewer : OsuTestScene
|
||||
{
|
||||
private const int max_particle_duration = 1500;
|
||||
|
||||
private float particleMaxVelocity = 0.5f;
|
||||
private Vector2 particleSpawnPosition = new Vector2(0.5f);
|
||||
|
||||
private ParticleSpewer spewer;
|
||||
private TestParticleSpewer spewer;
|
||||
|
||||
[Resolved]
|
||||
private SkinManager skinManager { get; set; }
|
||||
@ -32,11 +28,11 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
Child = spewer = createSpewer();
|
||||
|
||||
AddToggleStep("toggle spawning", value => spewer.Active.Value = value);
|
||||
AddSliderStep("particle velocity", 0f, 1f, 0.5f, value => particleMaxVelocity = value);
|
||||
AddSliderStep("particle gravity", 0f, 1f, 0f, value => spewer.ParticleGravity = value);
|
||||
AddSliderStep("particle gravity", 0f, 1f, 0f, value => spewer.Gravity = value);
|
||||
AddSliderStep("particle velocity", 0f, 1f, 0.5f, value => spewer.MaxVelocity = value);
|
||||
AddStep("move to new location", () =>
|
||||
{
|
||||
this.TransformTo(nameof(particleSpawnPosition), new Vector2(RNG.NextSingle(), RNG.NextSingle()), 1000, Easing.Out);
|
||||
spewer.TransformTo(nameof(spewer.SpawnPosition), new Vector2(RNG.NextSingle(), RNG.NextSingle()), 1000, Easing.Out);
|
||||
});
|
||||
}
|
||||
|
||||
@ -59,29 +55,47 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
AddAssert("is not present", () => !spewer.IsPresent);
|
||||
}
|
||||
|
||||
private ParticleSpewer createSpewer() =>
|
||||
new ParticleSpewer(skinManager.DefaultLegacySkin.GetTexture("star2"), 1500, max_particle_duration)
|
||||
private TestParticleSpewer createSpewer() =>
|
||||
new TestParticleSpewer(skinManager.DefaultLegacySkin.GetTexture("star2"))
|
||||
{
|
||||
Origin = Anchor.Centre,
|
||||
RelativePositionAxes = Axes.Both,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Position = new Vector2(0.5f),
|
||||
Size = new Vector2(0.5f),
|
||||
CreateParticle = createParticle,
|
||||
};
|
||||
|
||||
private ParticleSpewer.FallingParticle? createParticle() =>
|
||||
new ParticleSpewer.FallingParticle
|
||||
private class TestParticleSpewer : ParticleSpewer
|
||||
{
|
||||
private const int max_duration = 1500;
|
||||
private const int rate = 250;
|
||||
|
||||
public float Gravity;
|
||||
|
||||
public float MaxVelocity = 0.25f;
|
||||
|
||||
public Vector2 SpawnPosition { get; set; } = new Vector2(0.5f);
|
||||
|
||||
protected override float ParticleGravity => Gravity;
|
||||
|
||||
public TestParticleSpewer(Texture texture)
|
||||
: base(texture, rate, max_duration)
|
||||
{
|
||||
Velocity = new Vector2(
|
||||
RNG.NextSingle(-particleMaxVelocity, particleMaxVelocity),
|
||||
RNG.NextSingle(-particleMaxVelocity, particleMaxVelocity)
|
||||
),
|
||||
StartPosition = particleSpawnPosition,
|
||||
Duration = RNG.NextSingle(max_particle_duration),
|
||||
StartAngle = RNG.NextSingle(MathF.PI * 2),
|
||||
EndAngle = RNG.NextSingle(MathF.PI * 2),
|
||||
EndScale = RNG.NextSingle(0.5f, 1.5f)
|
||||
};
|
||||
}
|
||||
|
||||
protected override FallingParticle CreateParticle() =>
|
||||
new FallingParticle
|
||||
{
|
||||
Velocity = new Vector2(
|
||||
RNG.NextSingle(-MaxVelocity, MaxVelocity),
|
||||
RNG.NextSingle(-MaxVelocity, MaxVelocity)
|
||||
),
|
||||
StartPosition = SpawnPosition,
|
||||
Duration = RNG.NextSingle(max_duration),
|
||||
StartAngle = RNG.NextSingle(MathF.PI * 2),
|
||||
EndAngle = RNG.NextSingle(MathF.PI * 2),
|
||||
EndScale = RNG.NextSingle(0.5f, 1.5f)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ using osuTK;
|
||||
|
||||
namespace osu.Game.Graphics
|
||||
{
|
||||
public class ParticleSpewer : Sprite
|
||||
public abstract class ParticleSpewer : Sprite
|
||||
{
|
||||
private readonly FallingParticle[] particles;
|
||||
private int currentIndex;
|
||||
@ -29,16 +29,12 @@ namespace osu.Game.Graphics
|
||||
|
||||
public override bool IsPresent => base.IsPresent && hasActiveParticles;
|
||||
|
||||
/// <summary>
|
||||
/// Called each time a new particle should be spawned.
|
||||
/// </summary>
|
||||
public Func<FallingParticle?> CreateParticle = () => new FallingParticle();
|
||||
|
||||
public float ParticleGravity;
|
||||
protected virtual bool CanSpawnParticles => true;
|
||||
protected virtual float ParticleGravity => 0;
|
||||
|
||||
private bool hasActiveParticles => Active.Value || (lastParticleAdded + maxDuration) > Time.Current;
|
||||
|
||||
public ParticleSpewer(Texture texture, int perSecond, double maxDuration)
|
||||
protected ParticleSpewer(Texture texture, int perSecond, double maxDuration)
|
||||
{
|
||||
Texture = texture;
|
||||
Blending = BlendingParameters.Additive;
|
||||
@ -57,25 +53,25 @@ namespace osu.Game.Graphics
|
||||
// this can happen when seeking in replays.
|
||||
if (lastParticleAdded > Time.Current) lastParticleAdded = 0;
|
||||
|
||||
if (Active.Value && Time.Current > lastParticleAdded + cooldown)
|
||||
if (Active.Value && CanSpawnParticles && Time.Current > lastParticleAdded + cooldown)
|
||||
{
|
||||
var newParticle = CreateParticle();
|
||||
newParticle.StartTime = (float)Time.Current;
|
||||
|
||||
if (newParticle.HasValue)
|
||||
{
|
||||
var particle = newParticle.Value;
|
||||
particle.StartTime = (float)Time.Current;
|
||||
particles[currentIndex] = newParticle;
|
||||
|
||||
particles[currentIndex] = particle;
|
||||
|
||||
currentIndex = (currentIndex + 1) % particles.Length;
|
||||
lastParticleAdded = Time.Current;
|
||||
}
|
||||
currentIndex = (currentIndex + 1) % particles.Length;
|
||||
lastParticleAdded = Time.Current;
|
||||
}
|
||||
|
||||
Invalidate(Invalidation.DrawNode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called each time a new particle should be spawned.
|
||||
/// </summary>
|
||||
protected virtual FallingParticle CreateParticle() => new FallingParticle();
|
||||
|
||||
protected override DrawNode CreateDrawNode() => new ParticleSpewerDrawNode(this);
|
||||
|
||||
# region DrawNode
|
||||
@ -178,7 +174,7 @@ namespace osu.Game.Graphics
|
||||
|
||||
#endregion
|
||||
|
||||
public struct FallingParticle
|
||||
protected struct FallingParticle
|
||||
{
|
||||
public float StartTime;
|
||||
public Vector2 StartPosition;
|
||||
|
Loading…
Reference in New Issue
Block a user