mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 12:53:11 +08:00
Update in-line with drawnode changes
This commit is contained in:
parent
14548e8a2d
commit
d8af5e1c5a
@ -43,22 +43,7 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
||||
|
||||
private readonly InputResampler resampler = new InputResampler();
|
||||
|
||||
protected override DrawNode CreateDrawNode() => new TrailDrawNode();
|
||||
|
||||
protected override void ApplyDrawNode(DrawNode node)
|
||||
{
|
||||
base.ApplyDrawNode(node);
|
||||
|
||||
TrailDrawNode tNode = (TrailDrawNode)node;
|
||||
tNode.Shader = shader;
|
||||
tNode.Texture = texture;
|
||||
tNode.Size = size;
|
||||
tNode.Time = time;
|
||||
|
||||
for (int i = 0; i < parts.Length; ++i)
|
||||
if (parts[i].InvalidationID > tNode.Parts[i].InvalidationID)
|
||||
tNode.Parts[i] = parts[i];
|
||||
}
|
||||
protected override DrawNode CreateDrawNode() => new TrailDrawNode(this);
|
||||
|
||||
public CursorTrail()
|
||||
{
|
||||
@ -167,33 +152,52 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
||||
|
||||
private class TrailDrawNode : DrawNode
|
||||
{
|
||||
public IShader Shader;
|
||||
public Texture Texture;
|
||||
protected new CursorTrail Source => (CursorTrail)base.Source;
|
||||
|
||||
public float Time;
|
||||
private IShader shader;
|
||||
private Texture texture;
|
||||
|
||||
public readonly TrailPart[] Parts = new TrailPart[max_sprites];
|
||||
public Vector2 Size;
|
||||
private float time;
|
||||
|
||||
private readonly TrailPart[] parts = new TrailPart[max_sprites];
|
||||
private Vector2 size;
|
||||
|
||||
private readonly VertexBuffer<TexturedTrailVertex> vertexBuffer = new QuadVertexBuffer<TexturedTrailVertex>(max_sprites, BufferUsageHint.DynamicDraw);
|
||||
|
||||
public TrailDrawNode()
|
||||
public TrailDrawNode(CursorTrail source)
|
||||
: base(source)
|
||||
{
|
||||
for (int i = 0; i < max_sprites; i++)
|
||||
{
|
||||
Parts[i].InvalidationID = 0;
|
||||
Parts[i].WasUpdated = false;
|
||||
parts[i].InvalidationID = 0;
|
||||
parts[i].WasUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ApplyState()
|
||||
{
|
||||
base.ApplyState();
|
||||
|
||||
shader = Source.shader;
|
||||
texture = Source.texture;
|
||||
size = Source.size;
|
||||
time = Source.time;
|
||||
|
||||
for (int i = 0; i < Source.parts.Length; ++i)
|
||||
{
|
||||
if (Source.parts[i].InvalidationID > parts[i].InvalidationID)
|
||||
parts[i] = Source.parts[i];
|
||||
}
|
||||
}
|
||||
|
||||
public override void Draw(Action<TexturedVertex2D> vertexAction)
|
||||
{
|
||||
Shader.GetUniform<float>("g_FadeClock").UpdateValue(ref Time);
|
||||
shader.GetUniform<float>("g_FadeClock").UpdateValue(ref time);
|
||||
|
||||
int updateStart = -1, updateEnd = 0;
|
||||
for (int i = 0; i < Parts.Length; ++i)
|
||||
for (int i = 0; i < parts.Length; ++i)
|
||||
{
|
||||
if (Parts[i].WasUpdated)
|
||||
if (parts[i].WasUpdated)
|
||||
{
|
||||
if (updateStart == -1)
|
||||
updateStart = i;
|
||||
@ -202,22 +206,22 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
||||
int start = i * 4;
|
||||
int end = start;
|
||||
|
||||
Vector2 pos = Parts[i].Position;
|
||||
float time = Parts[i].Time;
|
||||
Vector2 pos = parts[i].Position;
|
||||
float localTime = parts[i].Time;
|
||||
|
||||
Texture.DrawQuad(
|
||||
new Quad(pos.X - Size.X / 2, pos.Y - Size.Y / 2, Size.X, Size.Y),
|
||||
texture.DrawQuad(
|
||||
new Quad(pos.X - size.X / 2, pos.Y - size.Y / 2, size.X, size.Y),
|
||||
DrawColourInfo.Colour,
|
||||
null,
|
||||
v => vertexBuffer.Vertices[end++] = new TexturedTrailVertex
|
||||
{
|
||||
Position = v.Position,
|
||||
TexturePosition = v.TexturePosition,
|
||||
Time = time + 1,
|
||||
Time = localTime + 1,
|
||||
Colour = v.Colour,
|
||||
});
|
||||
|
||||
Parts[i].WasUpdated = false;
|
||||
parts[i].WasUpdated = false;
|
||||
}
|
||||
else if (updateStart != -1)
|
||||
{
|
||||
@ -232,12 +236,12 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
||||
|
||||
base.Draw(vertexAction);
|
||||
|
||||
Shader.Bind();
|
||||
shader.Bind();
|
||||
|
||||
Texture.TextureGL.Bind();
|
||||
texture.TextureGL.Bind();
|
||||
vertexBuffer.Draw();
|
||||
|
||||
Shader.Unbind();
|
||||
shader.Unbind();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
|
@ -178,64 +178,68 @@ namespace osu.Game.Graphics.Backgrounds
|
||||
/// <returns>The colour.</returns>
|
||||
protected virtual Color4 CreateTriangleShade() => Interpolation.ValueAt(RNG.NextSingle(), ColourDark, ColourLight, 0, 1);
|
||||
|
||||
protected override DrawNode CreateDrawNode() => new TrianglesDrawNode();
|
||||
|
||||
protected override void ApplyDrawNode(DrawNode node)
|
||||
{
|
||||
base.ApplyDrawNode(node);
|
||||
|
||||
var trianglesNode = (TrianglesDrawNode)node;
|
||||
|
||||
trianglesNode.Shader = shader;
|
||||
trianglesNode.Texture = texture;
|
||||
trianglesNode.Size = DrawSize;
|
||||
|
||||
trianglesNode.Parts.Clear();
|
||||
trianglesNode.Parts.AddRange(parts);
|
||||
}
|
||||
protected override DrawNode CreateDrawNode() => new TrianglesDrawNode(this);
|
||||
|
||||
private class TrianglesDrawNode : DrawNode
|
||||
{
|
||||
public IShader Shader;
|
||||
public Texture Texture;
|
||||
protected new Triangles Source => (Triangles)base.Source;
|
||||
|
||||
public readonly List<TriangleParticle> Parts = new List<TriangleParticle>();
|
||||
public Vector2 Size;
|
||||
private IShader shader;
|
||||
private Texture texture;
|
||||
|
||||
private readonly List<TriangleParticle> parts = new List<TriangleParticle>();
|
||||
private Vector2 size;
|
||||
|
||||
private readonly LinearBatch<TexturedVertex2D> vertexBatch = new LinearBatch<TexturedVertex2D>(100 * 3, 10, PrimitiveType.Triangles);
|
||||
|
||||
public TrianglesDrawNode(Triangles source)
|
||||
: base(source)
|
||||
{
|
||||
}
|
||||
|
||||
public override void ApplyState()
|
||||
{
|
||||
base.ApplyState();
|
||||
|
||||
shader = Source.shader;
|
||||
texture = Source.texture;
|
||||
size = Source.DrawSize;
|
||||
|
||||
parts.Clear();
|
||||
parts.AddRange(Source.parts);
|
||||
}
|
||||
|
||||
public override void Draw(Action<TexturedVertex2D> vertexAction)
|
||||
{
|
||||
base.Draw(vertexAction);
|
||||
|
||||
Shader.Bind();
|
||||
Texture.TextureGL.Bind();
|
||||
shader.Bind();
|
||||
texture.TextureGL.Bind();
|
||||
|
||||
Vector2 localInflationAmount = edge_smoothness * DrawInfo.MatrixInverse.ExtractScale().Xy;
|
||||
|
||||
foreach (TriangleParticle particle in Parts)
|
||||
foreach (TriangleParticle particle in parts)
|
||||
{
|
||||
var offset = triangle_size * new Vector2(particle.Scale * 0.5f, particle.Scale * 0.866f);
|
||||
var size = new Vector2(2 * offset.X, offset.Y);
|
||||
|
||||
var triangle = new Triangle(
|
||||
Vector2Extensions.Transform(particle.Position * Size, DrawInfo.Matrix),
|
||||
Vector2Extensions.Transform(particle.Position * Size + offset, DrawInfo.Matrix),
|
||||
Vector2Extensions.Transform(particle.Position * Size + new Vector2(-offset.X, offset.Y), DrawInfo.Matrix)
|
||||
Vector2Extensions.Transform(particle.Position * size, DrawInfo.Matrix),
|
||||
Vector2Extensions.Transform(particle.Position * size + offset, DrawInfo.Matrix),
|
||||
Vector2Extensions.Transform(particle.Position * size + new Vector2(-offset.X, offset.Y), DrawInfo.Matrix)
|
||||
);
|
||||
|
||||
ColourInfo colourInfo = DrawColourInfo.Colour;
|
||||
colourInfo.ApplyChild(particle.Colour);
|
||||
|
||||
Texture.DrawTriangle(
|
||||
texture.DrawTriangle(
|
||||
triangle,
|
||||
colourInfo,
|
||||
null,
|
||||
vertexBatch.AddAction,
|
||||
Vector2.Divide(localInflationAmount, size));
|
||||
Vector2.Divide(localInflationAmount, new Vector2(2 * offset.X, offset.Y)));
|
||||
}
|
||||
|
||||
Shader.Unbind();
|
||||
shader.Unbind();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
|
@ -64,24 +64,12 @@ namespace osu.Game.Rulesets.Mods
|
||||
internal BindableInt Combo;
|
||||
private IShader shader;
|
||||
|
||||
protected override DrawNode CreateDrawNode() => new FlashlightDrawNode();
|
||||
protected override DrawNode CreateDrawNode() => new FlashlightDrawNode(this);
|
||||
|
||||
public override bool RemoveCompletedTransforms => false;
|
||||
|
||||
public List<BreakPeriod> Breaks;
|
||||
|
||||
protected override void ApplyDrawNode(DrawNode node)
|
||||
{
|
||||
base.ApplyDrawNode(node);
|
||||
|
||||
var flashNode = (FlashlightDrawNode)node;
|
||||
|
||||
flashNode.Shader = shader;
|
||||
flashNode.ScreenSpaceDrawQuad = ScreenSpaceDrawQuad;
|
||||
flashNode.FlashlightPosition = Vector2Extensions.Transform(FlashlightPosition, DrawInfo.Matrix);
|
||||
flashNode.FlashlightSize = Vector2Extensions.Transform(FlashlightSize, DrawInfo.Matrix);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(ShaderManager shaderManager)
|
||||
{
|
||||
@ -136,27 +124,44 @@ namespace osu.Game.Rulesets.Mods
|
||||
Invalidate(Invalidation.DrawNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class FlashlightDrawNode : DrawNode
|
||||
{
|
||||
public IShader Shader;
|
||||
public Quad ScreenSpaceDrawQuad;
|
||||
public Vector2 FlashlightPosition;
|
||||
public Vector2 FlashlightSize;
|
||||
|
||||
public override void Draw(Action<TexturedVertex2D> vertexAction)
|
||||
private class FlashlightDrawNode : DrawNode
|
||||
{
|
||||
base.Draw(vertexAction);
|
||||
protected new Flashlight Source => (Flashlight)base.Source;
|
||||
|
||||
Shader.Bind();
|
||||
private IShader shader;
|
||||
private Quad screenSpaceDrawQuad;
|
||||
private Vector2 flashlightPosition;
|
||||
private Vector2 flashlightSize;
|
||||
|
||||
Shader.GetUniform<Vector2>("flashlightPos").UpdateValue(ref FlashlightPosition);
|
||||
Shader.GetUniform<Vector2>("flashlightSize").UpdateValue(ref FlashlightSize);
|
||||
public FlashlightDrawNode(Flashlight source)
|
||||
: base(source)
|
||||
{
|
||||
}
|
||||
|
||||
Texture.WhitePixel.DrawQuad(ScreenSpaceDrawQuad, DrawColourInfo.Colour, vertexAction: vertexAction);
|
||||
public override void ApplyState()
|
||||
{
|
||||
base.ApplyState();
|
||||
|
||||
Shader.Unbind();
|
||||
shader = Source.shader;
|
||||
screenSpaceDrawQuad = Source.ScreenSpaceDrawQuad;
|
||||
flashlightPosition = Vector2Extensions.Transform(Source.FlashlightPosition, DrawInfo.Matrix);
|
||||
flashlightSize = Vector2Extensions.Transform(Source.FlashlightSize, DrawInfo.Matrix);
|
||||
}
|
||||
|
||||
public override void Draw(Action<TexturedVertex2D> vertexAction)
|
||||
{
|
||||
base.Draw(vertexAction);
|
||||
|
||||
shader.Bind();
|
||||
|
||||
shader.GetUniform<Vector2>("flashlightPos").UpdateValue(ref flashlightPosition);
|
||||
shader.GetUniform<Vector2>("flashlightSize").UpdateValue(ref flashlightSize);
|
||||
|
||||
Texture.WhitePixel.DrawQuad(screenSpaceDrawQuad, DrawColourInfo.Colour, vertexAction: vertexAction);
|
||||
|
||||
shader.Unbind();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -150,62 +150,67 @@ namespace osu.Game.Screens.Menu
|
||||
Invalidate(Invalidation.DrawNode, shallPropagate: false);
|
||||
}
|
||||
|
||||
protected override DrawNode CreateDrawNode() => new VisualisationDrawNode();
|
||||
|
||||
protected override void ApplyDrawNode(DrawNode node)
|
||||
{
|
||||
base.ApplyDrawNode(node);
|
||||
|
||||
var visNode = (VisualisationDrawNode)node;
|
||||
|
||||
visNode.Shader = shader;
|
||||
visNode.Texture = texture;
|
||||
visNode.Size = DrawSize.X;
|
||||
visNode.Colour = AccentColour;
|
||||
visNode.AudioData = frequencyAmplitudes;
|
||||
}
|
||||
protected override DrawNode CreateDrawNode() => new VisualisationDrawNode(this);
|
||||
|
||||
private class VisualisationDrawNode : DrawNode
|
||||
{
|
||||
public IShader Shader;
|
||||
public Texture Texture;
|
||||
protected new LogoVisualisation Source => (LogoVisualisation)base.Source;
|
||||
|
||||
private IShader shader;
|
||||
private Texture texture;
|
||||
|
||||
//Asuming the logo is a circle, we don't need a second dimension.
|
||||
public float Size;
|
||||
private float size;
|
||||
|
||||
public Color4 Colour;
|
||||
public float[] AudioData;
|
||||
private Color4 colour;
|
||||
private float[] audioData;
|
||||
|
||||
private readonly QuadBatch<TexturedVertex2D> vertexBatch = new QuadBatch<TexturedVertex2D>(100, 10);
|
||||
|
||||
public VisualisationDrawNode(LogoVisualisation source)
|
||||
: base(source)
|
||||
{
|
||||
}
|
||||
|
||||
public override void ApplyState()
|
||||
{
|
||||
base.ApplyState();
|
||||
|
||||
shader = Source.shader;
|
||||
texture = Source.texture;
|
||||
size = Source.DrawSize.X;
|
||||
colour = Source.AccentColour;
|
||||
audioData = Source.frequencyAmplitudes;
|
||||
}
|
||||
|
||||
public override void Draw(Action<TexturedVertex2D> vertexAction)
|
||||
{
|
||||
base.Draw(vertexAction);
|
||||
|
||||
Shader.Bind();
|
||||
Texture.TextureGL.Bind();
|
||||
shader.Bind();
|
||||
texture.TextureGL.Bind();
|
||||
|
||||
Vector2 inflation = DrawInfo.MatrixInverse.ExtractScale().Xy;
|
||||
|
||||
ColourInfo colourInfo = DrawColourInfo.Colour;
|
||||
colourInfo.ApplyChild(Colour);
|
||||
colourInfo.ApplyChild(colour);
|
||||
|
||||
if (AudioData != null)
|
||||
if (audioData != null)
|
||||
{
|
||||
for (int j = 0; j < visualiser_rounds; j++)
|
||||
{
|
||||
for (int i = 0; i < bars_per_visualiser; i++)
|
||||
{
|
||||
if (AudioData[i] < amplitude_dead_zone)
|
||||
if (audioData[i] < amplitude_dead_zone)
|
||||
continue;
|
||||
|
||||
float rotation = MathHelper.DegreesToRadians(i / (float)bars_per_visualiser * 360 + j * 360 / visualiser_rounds);
|
||||
float rotationCos = (float)Math.Cos(rotation);
|
||||
float rotationSin = (float)Math.Sin(rotation);
|
||||
//taking the cos and sin to the 0..1 range
|
||||
var barPosition = new Vector2(rotationCos / 2 + 0.5f, rotationSin / 2 + 0.5f) * Size;
|
||||
var barPosition = new Vector2(rotationCos / 2 + 0.5f, rotationSin / 2 + 0.5f) * size;
|
||||
|
||||
var barSize = new Vector2(Size * (float)Math.Sqrt(2 * (1 - Math.Cos(MathHelper.DegreesToRadians(360f / bars_per_visualiser)))) / 2f, bar_length * AudioData[i]);
|
||||
var barSize = new Vector2(size * (float)Math.Sqrt(2 * (1 - Math.Cos(MathHelper.DegreesToRadians(360f / bars_per_visualiser)))) / 2f, bar_length * audioData[i]);
|
||||
//The distance between the position and the sides of the bar.
|
||||
var bottomOffset = new Vector2(-rotationSin * barSize.X / 2, rotationCos * barSize.X / 2);
|
||||
//The distance between the bottom side of the bar and the top side.
|
||||
@ -218,7 +223,7 @@ namespace osu.Game.Screens.Menu
|
||||
Vector2Extensions.Transform(barPosition + bottomOffset + amplitudeOffset, DrawInfo.Matrix)
|
||||
);
|
||||
|
||||
Texture.DrawQuad(
|
||||
texture.DrawQuad(
|
||||
rectangle,
|
||||
colourInfo,
|
||||
null,
|
||||
@ -229,7 +234,7 @@ namespace osu.Game.Screens.Menu
|
||||
}
|
||||
}
|
||||
|
||||
Shader.Unbind();
|
||||
shader.Unbind();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
|
Loading…
Reference in New Issue
Block a user