mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 16:59:53 +09:00
Refactor a bit
This commit is contained in:
@ -162,7 +162,7 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
|||||||
private readonly TrailPart[] parts = new TrailPart[max_sprites];
|
private readonly TrailPart[] parts = new TrailPart[max_sprites];
|
||||||
private Vector2 size;
|
private Vector2 size;
|
||||||
|
|
||||||
private readonly CustomBatch vertexBatch = new CustomBatch(max_sprites, 1);
|
private readonly TrailBatch vertexBatch = new TrailBatch(max_sprites, 1);
|
||||||
|
|
||||||
public TrailDrawNode(CursorTrail source)
|
public TrailDrawNode(CursorTrail source)
|
||||||
: base(source)
|
: base(source)
|
||||||
@ -196,9 +196,10 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
|||||||
|
|
||||||
for (int i = 0; i < parts.Length; ++i)
|
for (int i = 0; i < parts.Length; ++i)
|
||||||
{
|
{
|
||||||
Vector2 pos = parts[i].Position;
|
|
||||||
vertexBatch.DrawTime = parts[i].Time;
|
vertexBatch.DrawTime = parts[i].Time;
|
||||||
|
|
||||||
|
Vector2 pos = parts[i].Position;
|
||||||
|
|
||||||
DrawQuad(
|
DrawQuad(
|
||||||
texture,
|
texture,
|
||||||
new Quad(pos.X - size.X / 2, pos.Y - size.Y / 2, size.X, size.Y),
|
new Quad(pos.X - size.X / 2, pos.Y - size.Y / 2, size.X, size.Y),
|
||||||
@ -217,25 +218,23 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
|||||||
vertexBatch.Dispose();
|
vertexBatch.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CustomBatch : QuadBatch<TexturedTrailVertex>
|
// Todo: This shouldn't exist, but is currently used to reduce allocations by caching variable-capturing closures.
|
||||||
|
private class TrailBatch : QuadBatch<TexturedTrailVertex>
|
||||||
{
|
{
|
||||||
public new readonly Action<TexturedVertex2D> AddAction;
|
public new readonly Action<TexturedVertex2D> AddAction;
|
||||||
|
|
||||||
public float DrawTime;
|
public float DrawTime;
|
||||||
|
|
||||||
public CustomBatch(int size, int maxBuffers)
|
public TrailBatch(int size, int maxBuffers)
|
||||||
: base(size, maxBuffers)
|
: base(size, maxBuffers)
|
||||||
{
|
{
|
||||||
AddAction = add;
|
AddAction = v => Add(new TexturedTrailVertex
|
||||||
|
{
|
||||||
|
Position = v.Position,
|
||||||
|
TexturePosition = v.TexturePosition,
|
||||||
|
Time = DrawTime + 1,
|
||||||
|
Colour = v.Colour,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void add(TexturedVertex2D vertex) => Add(new TexturedTrailVertex
|
|
||||||
{
|
|
||||||
Position = vertex.Position,
|
|
||||||
TexturePosition = vertex.TexturePosition,
|
|
||||||
Time = DrawTime + 1,
|
|
||||||
Colour = vertex.Colour,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user