mirror of
https://github.com/osukey/osukey.git
synced 2025-05-29 17:37:23 +09:00
Expose less stuff, clean up implementation
This commit is contained in:
parent
ff6e4e3a96
commit
c28ed477e1
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Rendering;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
@ -34,9 +33,9 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateDrawVariables(IRenderer renderer)
|
public override void ApplyState()
|
||||||
{
|
{
|
||||||
base.UpdateDrawVariables(renderer);
|
base.ApplyState();
|
||||||
|
|
||||||
fadeOutTime = SmokeStartTime + fade_out_speed * (CurrentTime - (SmokeEndTime + fade_out_delay));
|
fadeOutTime = SmokeStartTime + fade_out_speed * (CurrentTime - (SmokeEndTime + fade_out_delay));
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Rendering;
|
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
@ -99,11 +98,6 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
|||||||
|
|
||||||
initialFadeOutDurationTrunc = Math.Min(initial_fade_out_duration, SmokeEndTime - SmokeStartTime);
|
initialFadeOutDurationTrunc = Math.Min(initial_fade_out_duration, SmokeEndTime - SmokeStartTime);
|
||||||
rotationSeed = Source.RotationSeed;
|
rotationSeed = Source.RotationSeed;
|
||||||
}
|
|
||||||
|
|
||||||
protected override void UpdateDrawVariables(IRenderer renderer)
|
|
||||||
{
|
|
||||||
base.UpdateDrawVariables(renderer);
|
|
||||||
|
|
||||||
rotationRNG = new Random(rotationSeed);
|
rotationRNG = new Random(rotationSeed);
|
||||||
initialFadeOutTime = Math.Min(CurrentTime, SmokeEndTime);
|
initialFadeOutTime = Math.Min(CurrentTime, SmokeEndTime);
|
||||||
|
@ -13,7 +13,6 @@ using osu.Framework.Graphics.Rendering;
|
|||||||
using osu.Framework.Graphics.Rendering.Vertices;
|
using osu.Framework.Graphics.Rendering.Vertices;
|
||||||
using osu.Framework.Graphics.Shaders;
|
using osu.Framework.Graphics.Shaders;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Framework.Timing;
|
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Rulesets.Osu.UI;
|
using osu.Game.Rulesets.Osu.UI;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
@ -41,57 +40,11 @@ namespace osu.Game.Rulesets.Osu.Skinning
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Texture? texture;
|
protected Texture? Texture { get; set; }
|
||||||
|
|
||||||
protected Texture? Texture
|
protected double SmokeStartTime { get; private set; } = double.MinValue;
|
||||||
{
|
|
||||||
get => texture;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
texture = value;
|
|
||||||
Invalidate(Invalidation.DrawNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private double smokeTimeStart = double.MinValue;
|
protected double SmokeEndTime { get; private set; } = double.MaxValue;
|
||||||
|
|
||||||
protected double SmokeStartTime
|
|
||||||
{
|
|
||||||
get => smokeTimeStart;
|
|
||||||
private set
|
|
||||||
{
|
|
||||||
if (smokeTimeStart == value)
|
|
||||||
return;
|
|
||||||
|
|
||||||
smokeTimeStart = value;
|
|
||||||
Invalidate(Invalidation.DrawNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private double smokeTimeEnd = double.MaxValue;
|
|
||||||
|
|
||||||
protected double SmokeEndTime
|
|
||||||
{
|
|
||||||
get => smokeTimeEnd;
|
|
||||||
private set
|
|
||||||
{
|
|
||||||
if (smokeTimeEnd == value)
|
|
||||||
return;
|
|
||||||
|
|
||||||
smokeTimeEnd = value;
|
|
||||||
Invalidate(Invalidation.DrawNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override IFrameBasedClock Clock
|
|
||||||
{
|
|
||||||
get => base.Clock;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
base.Clock = value;
|
|
||||||
Invalidate(Invalidation.DrawNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Vector2 topLeft;
|
private Vector2 topLeft;
|
||||||
|
|
||||||
@ -104,7 +57,7 @@ namespace osu.Game.Rulesets.Osu.Skinning
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
topLeft = value;
|
topLeft = value;
|
||||||
Invalidate();
|
Invalidate(Invalidation.Layout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,6 +230,8 @@ namespace osu.Game.Rulesets.Osu.Skinning
|
|||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
Position = TopLeft;
|
Position = TopLeft;
|
||||||
|
|
||||||
|
Invalidate(Invalidation.DrawNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
@ -314,21 +269,16 @@ namespace osu.Game.Rulesets.Osu.Skinning
|
|||||||
{
|
{
|
||||||
protected new Smoke Source => (Smoke)base.Source;
|
protected new Smoke Source => (Smoke)base.Source;
|
||||||
|
|
||||||
protected IVertexBatch<TexturedVertex2D>? QuadBatch { get; private set; }
|
|
||||||
protected readonly List<SmokePoint> Points = new List<SmokePoint>();
|
|
||||||
|
|
||||||
protected float Radius { get; private set; }
|
|
||||||
protected Vector2 DrawSize { get; private set; }
|
|
||||||
protected Vector2 PositionOffset { get; private set; }
|
|
||||||
protected Texture? Texture { get; private set; }
|
|
||||||
|
|
||||||
protected double SmokeStartTime { get; private set; }
|
protected double SmokeStartTime { get; private set; }
|
||||||
protected double SmokeEndTime { get; private set; }
|
protected double SmokeEndTime { get; private set; }
|
||||||
protected double CurrentTime { get; private set; }
|
protected double CurrentTime { get; private set; }
|
||||||
|
|
||||||
protected RectangleF TextureRect { get; private set; }
|
private readonly List<SmokePoint> points = new List<SmokePoint>();
|
||||||
|
private IVertexBatch<TexturedVertex2D>? quadBatch;
|
||||||
private IFrameBasedClock? clock;
|
private float radius;
|
||||||
|
private Vector2 drawSize;
|
||||||
|
private Vector2 positionOffset;
|
||||||
|
private Texture? texture;
|
||||||
|
|
||||||
protected SmokeDrawNode(ITexturedShaderDrawable source)
|
protected SmokeDrawNode(ITexturedShaderDrawable source)
|
||||||
: base(source)
|
: base(source)
|
||||||
@ -339,28 +289,29 @@ namespace osu.Game.Rulesets.Osu.Skinning
|
|||||||
{
|
{
|
||||||
base.ApplyState();
|
base.ApplyState();
|
||||||
|
|
||||||
Points.Clear();
|
points.Clear();
|
||||||
Points.AddRange(Source.SmokePoints);
|
points.AddRange(Source.SmokePoints);
|
||||||
|
|
||||||
Radius = Source.Radius;
|
radius = Source.Radius;
|
||||||
DrawSize = Source.DrawSize;
|
drawSize = Source.DrawSize;
|
||||||
PositionOffset = Source.TopLeft;
|
positionOffset = Source.TopLeft;
|
||||||
Texture = Source.Texture;
|
texture = Source.Texture;
|
||||||
clock = Source.Clock;
|
|
||||||
|
|
||||||
SmokeStartTime = Source.SmokeStartTime;
|
SmokeStartTime = Source.SmokeStartTime;
|
||||||
SmokeEndTime = Source.SmokeEndTime;
|
SmokeEndTime = Source.SmokeEndTime;
|
||||||
|
CurrentTime = Source.Clock.CurrentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed override void Draw(IRenderer renderer)
|
public sealed override void Draw(IRenderer renderer)
|
||||||
{
|
{
|
||||||
base.Draw(renderer);
|
base.Draw(renderer);
|
||||||
|
|
||||||
if (Points.Count == 0)
|
if (points.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QuadBatch ??= renderer.CreateQuadBatch<TexturedVertex2D>(max_point_count / 10, 10);
|
quadBatch ??= renderer.CreateQuadBatch<TexturedVertex2D>(max_point_count / 10, 10);
|
||||||
Texture ??= renderer.WhitePixel;
|
texture ??= renderer.WhitePixel;
|
||||||
|
RectangleF textureRect = texture.GetTextureRect();
|
||||||
|
|
||||||
var shader = GetAppropriateShader(renderer);
|
var shader = GetAppropriateShader(renderer);
|
||||||
|
|
||||||
@ -368,10 +319,10 @@ namespace osu.Game.Rulesets.Osu.Skinning
|
|||||||
renderer.PushLocalMatrix(DrawInfo.Matrix);
|
renderer.PushLocalMatrix(DrawInfo.Matrix);
|
||||||
|
|
||||||
shader.Bind();
|
shader.Bind();
|
||||||
Texture.Bind();
|
texture.Bind();
|
||||||
|
|
||||||
UpdateDrawVariables(renderer);
|
foreach (var point in points)
|
||||||
UpdateVertexBuffer(renderer);
|
drawPointQuad(point, textureRect);
|
||||||
|
|
||||||
shader.Unbind();
|
shader.Unbind();
|
||||||
renderer.PopLocalMatrix();
|
renderer.PopLocalMatrix();
|
||||||
@ -379,7 +330,7 @@ namespace osu.Game.Rulesets.Osu.Skinning
|
|||||||
|
|
||||||
protected Color4 ColourAtPosition(Vector2 localPos) => DrawColourInfo.Colour.HasSingleColour
|
protected Color4 ColourAtPosition(Vector2 localPos) => DrawColourInfo.Colour.HasSingleColour
|
||||||
? ((SRGBColour)DrawColourInfo.Colour).Linear
|
? ((SRGBColour)DrawColourInfo.Colour).Linear
|
||||||
: DrawColourInfo.Colour.Interpolate(Vector2.Divide(localPos, DrawSize)).Linear;
|
: DrawColourInfo.Colour.Interpolate(Vector2.Divide(localPos, drawSize)).Linear;
|
||||||
|
|
||||||
protected abstract Color4 PointColour(SmokePoint point);
|
protected abstract Color4 PointColour(SmokePoint point);
|
||||||
|
|
||||||
@ -387,24 +338,9 @@ namespace osu.Game.Rulesets.Osu.Skinning
|
|||||||
|
|
||||||
protected abstract Vector2 PointDirection(SmokePoint point);
|
protected abstract Vector2 PointDirection(SmokePoint point);
|
||||||
|
|
||||||
protected virtual void UpdateDrawVariables(IRenderer renderer)
|
private void drawPointQuad(SmokePoint point, RectangleF textureRect)
|
||||||
{
|
{
|
||||||
Debug.Assert(clock != null);
|
Debug.Assert(quadBatch != null);
|
||||||
Debug.Assert(Texture != null);
|
|
||||||
|
|
||||||
CurrentTime = clock.CurrentTime;
|
|
||||||
TextureRect = Texture.GetTextureRect();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void UpdateVertexBuffer(IRenderer renderer)
|
|
||||||
{
|
|
||||||
foreach (var point in Points)
|
|
||||||
drawPointQuad(point);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void drawPointQuad(SmokePoint point)
|
|
||||||
{
|
|
||||||
Debug.Assert(QuadBatch != null);
|
|
||||||
|
|
||||||
var colour = PointColour(point);
|
var colour = PointColour(point);
|
||||||
float scale = PointScale(point);
|
float scale = PointScale(point);
|
||||||
@ -414,33 +350,33 @@ namespace osu.Game.Rulesets.Osu.Skinning
|
|||||||
if (colour.A == 0 || scale == 0)
|
if (colour.A == 0 || scale == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var localTopLeft = point.Position + (Radius * scale * (-ortho - dir)) - PositionOffset;
|
var localTopLeft = point.Position + (radius * scale * (-ortho - dir)) - positionOffset;
|
||||||
var localTopRight = point.Position + (Radius * scale * (-ortho + dir)) - PositionOffset;
|
var localTopRight = point.Position + (radius * scale * (-ortho + dir)) - positionOffset;
|
||||||
var localBotLeft = point.Position + (Radius * scale * (ortho - dir)) - PositionOffset;
|
var localBotLeft = point.Position + (radius * scale * (ortho - dir)) - positionOffset;
|
||||||
var localBotRight = point.Position + (Radius * scale * (ortho + dir)) - PositionOffset;
|
var localBotRight = point.Position + (radius * scale * (ortho + dir)) - positionOffset;
|
||||||
|
|
||||||
QuadBatch.Add(new TexturedVertex2D
|
quadBatch.Add(new TexturedVertex2D
|
||||||
{
|
{
|
||||||
Position = localTopLeft,
|
Position = localTopLeft,
|
||||||
TexturePosition = TextureRect.TopLeft,
|
TexturePosition = textureRect.TopLeft,
|
||||||
Colour = Color4Extensions.Multiply(ColourAtPosition(localTopLeft), colour),
|
Colour = Color4Extensions.Multiply(ColourAtPosition(localTopLeft), colour),
|
||||||
});
|
});
|
||||||
QuadBatch.Add(new TexturedVertex2D
|
quadBatch.Add(new TexturedVertex2D
|
||||||
{
|
{
|
||||||
Position = localTopRight,
|
Position = localTopRight,
|
||||||
TexturePosition = TextureRect.TopRight,
|
TexturePosition = textureRect.TopRight,
|
||||||
Colour = Color4Extensions.Multiply(ColourAtPosition(localTopRight), colour),
|
Colour = Color4Extensions.Multiply(ColourAtPosition(localTopRight), colour),
|
||||||
});
|
});
|
||||||
QuadBatch.Add(new TexturedVertex2D
|
quadBatch.Add(new TexturedVertex2D
|
||||||
{
|
{
|
||||||
Position = localBotRight,
|
Position = localBotRight,
|
||||||
TexturePosition = TextureRect.BottomRight,
|
TexturePosition = textureRect.BottomRight,
|
||||||
Colour = Color4Extensions.Multiply(ColourAtPosition(localBotRight), colour),
|
Colour = Color4Extensions.Multiply(ColourAtPosition(localBotRight), colour),
|
||||||
});
|
});
|
||||||
QuadBatch.Add(new TexturedVertex2D
|
quadBatch.Add(new TexturedVertex2D
|
||||||
{
|
{
|
||||||
Position = localBotLeft,
|
Position = localBotLeft,
|
||||||
TexturePosition = TextureRect.BottomLeft,
|
TexturePosition = textureRect.BottomLeft,
|
||||||
Colour = Color4Extensions.Multiply(ColourAtPosition(localBotLeft), colour),
|
Colour = Color4Extensions.Multiply(ColourAtPosition(localBotLeft), colour),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -448,7 +384,7 @@ namespace osu.Game.Rulesets.Osu.Skinning
|
|||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
QuadBatch?.Dispose();
|
quadBatch?.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user