2022-09-18 19:08:34 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
2022-09-18 19:10:01 +00:00
|
|
|
|
using System;
|
2022-09-18 19:08:34 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using osu.Framework.Allocation;
|
2022-09-18 19:10:01 +00:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2022-09-18 19:08:34 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2022-09-18 19:10:01 +00:00
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
|
|
|
|
using osu.Framework.Graphics.Rendering;
|
|
|
|
|
using osu.Framework.Graphics.Rendering.Vertices;
|
|
|
|
|
using osu.Framework.Graphics.Shaders;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
|
using osu.Framework.Utils;
|
2022-10-13 23:18:47 +00:00
|
|
|
|
using osu.Game.Utils;
|
2022-09-18 19:08:34 +00:00
|
|
|
|
using osuTK;
|
2022-09-18 19:10:01 +00:00
|
|
|
|
using osuTK.Graphics;
|
2022-09-18 19:08:34 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Skinning
|
|
|
|
|
{
|
2022-10-05 09:27:51 +00:00
|
|
|
|
public abstract partial class SmokeSegment : Drawable, ITexturedShaderDrawable
|
2022-09-18 19:08:34 +00:00
|
|
|
|
{
|
2022-10-04 07:17:00 +00:00
|
|
|
|
// fade anim values
|
|
|
|
|
private const double initial_fade_out_duration = 4000;
|
|
|
|
|
|
|
|
|
|
private const double re_fade_in_speed = 3;
|
|
|
|
|
private const double re_fade_in_duration = 50;
|
|
|
|
|
|
|
|
|
|
private const double final_fade_out_speed = 2;
|
|
|
|
|
private const double final_fade_out_duration = 8000;
|
|
|
|
|
|
|
|
|
|
private const float initial_alpha = 0.6f;
|
|
|
|
|
private const float re_fade_in_alpha = 1f;
|
|
|
|
|
|
|
|
|
|
private readonly int rotationSeed = RNG.Next();
|
|
|
|
|
|
|
|
|
|
// scale anim values
|
|
|
|
|
private const double scale_duration = 1200;
|
|
|
|
|
|
|
|
|
|
private const float initial_scale = 0.65f;
|
|
|
|
|
private const float final_scale = 1f;
|
|
|
|
|
|
|
|
|
|
// rotation anim values
|
|
|
|
|
private const double rotation_duration = 500;
|
|
|
|
|
|
|
|
|
|
private const float max_rotation = 0.25f;
|
2022-09-18 19:08:34 +00:00
|
|
|
|
|
2022-10-05 09:54:14 +00:00
|
|
|
|
public IShader? TextureShader { get; private set; }
|
|
|
|
|
|
|
|
|
|
protected Texture? Texture { get; set; }
|
|
|
|
|
|
2022-11-21 00:50:15 +00:00
|
|
|
|
private float height => Texture?.DisplayHeight * 0.165f ?? 3;
|
|
|
|
|
|
|
|
|
|
private float width => Texture?.DisplayWidth * 0.165f ?? 3;
|
2022-10-05 09:54:14 +00:00
|
|
|
|
|
|
|
|
|
protected readonly List<SmokePoint> SmokePoints = new List<SmokePoint>();
|
|
|
|
|
|
2022-11-21 00:50:15 +00:00
|
|
|
|
private float pointInterval => width * 7f / 8;
|
2022-10-05 09:54:14 +00:00
|
|
|
|
|
|
|
|
|
private double smokeStartTime { get; set; } = double.MinValue;
|
|
|
|
|
|
|
|
|
|
private double smokeEndTime { get; set; } = double.MaxValue;
|
|
|
|
|
|
|
|
|
|
private float totalDistance;
|
|
|
|
|
private Vector2? lastPosition;
|
|
|
|
|
|
2022-09-18 19:10:01 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
2022-10-05 09:37:09 +00:00
|
|
|
|
private void load(ShaderManager shaders)
|
2022-09-18 19:08:34 +00:00
|
|
|
|
{
|
2022-09-18 19:10:01 +00:00
|
|
|
|
TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE);
|
2022-09-18 19:08:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2022-09-20 19:03:07 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2022-09-19 17:16:05 +00:00
|
|
|
|
|
2022-10-06 02:13:06 +00:00
|
|
|
|
LifetimeStart = smokeStartTime = Time.Current;
|
2022-09-19 17:16:05 +00:00
|
|
|
|
|
2022-10-05 09:54:14 +00:00
|
|
|
|
totalDistance = pointInterval;
|
2022-09-18 19:08:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-05 09:37:09 +00:00
|
|
|
|
public void AddPosition(Vector2 position, double time)
|
2022-09-18 19:08:34 +00:00
|
|
|
|
{
|
2022-09-18 19:10:01 +00:00
|
|
|
|
lastPosition ??= position;
|
2022-09-18 19:08:34 +00:00
|
|
|
|
|
2022-09-18 19:10:01 +00:00
|
|
|
|
float delta = (position - (Vector2)lastPosition).LengthFast;
|
|
|
|
|
totalDistance += delta;
|
2022-10-05 09:54:14 +00:00
|
|
|
|
int count = (int)(totalDistance / pointInterval);
|
2022-09-18 19:10:01 +00:00
|
|
|
|
|
|
|
|
|
if (count > 0)
|
|
|
|
|
{
|
|
|
|
|
Vector2 increment = position - (Vector2)lastPosition;
|
|
|
|
|
increment.NormalizeFast();
|
|
|
|
|
|
2022-10-05 09:54:14 +00:00
|
|
|
|
Vector2 pointPos = (pointInterval - (totalDistance - delta)) * increment + (Vector2)lastPosition;
|
|
|
|
|
increment *= pointInterval;
|
2022-09-18 19:10:01 +00:00
|
|
|
|
|
2022-10-05 09:54:14 +00:00
|
|
|
|
totalDistance %= pointInterval;
|
2022-09-19 01:32:33 +00:00
|
|
|
|
|
2022-10-18 10:33:03 +00:00
|
|
|
|
if (SmokePoints.Count == 0 || SmokePoints[^1].Time <= time)
|
2022-09-18 19:10:01 +00:00
|
|
|
|
{
|
2022-10-18 10:33:03 +00:00
|
|
|
|
for (int i = 0; i < count; i++)
|
2022-09-18 19:10:01 +00:00
|
|
|
|
{
|
2022-10-18 10:33:03 +00:00
|
|
|
|
SmokePoints.Add(new SmokePoint
|
|
|
|
|
{
|
|
|
|
|
Position = pointPos,
|
|
|
|
|
Time = time,
|
|
|
|
|
Angle = RNG.NextSingle(0, 2 * MathF.PI),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
pointPos += increment;
|
|
|
|
|
}
|
2022-09-18 19:10:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Invalidate(Invalidation.DrawNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lastPosition = position;
|
2022-09-18 19:08:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-05 09:37:09 +00:00
|
|
|
|
public void FinishDrawing(double time)
|
2022-09-18 19:08:34 +00:00
|
|
|
|
{
|
2022-10-05 09:54:14 +00:00
|
|
|
|
smokeEndTime = time;
|
2022-10-05 09:52:01 +00:00
|
|
|
|
|
2022-10-05 09:54:14 +00:00
|
|
|
|
double initialFadeOutDurationTrunc = Math.Min(initial_fade_out_duration, smokeEndTime - smokeStartTime);
|
|
|
|
|
LifetimeEnd = smokeEndTime + final_fade_out_duration + initialFadeOutDurationTrunc / re_fade_in_speed + initialFadeOutDurationTrunc / final_fade_out_speed;
|
2022-09-18 19:08:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-04 07:17:00 +00:00
|
|
|
|
protected override DrawNode CreateDrawNode() => new SmokeDrawNode(this);
|
2022-09-18 19:10:01 +00:00
|
|
|
|
|
2022-09-18 19:08:34 +00:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2022-09-20 11:54:49 +00:00
|
|
|
|
Invalidate(Invalidation.DrawNode);
|
2022-09-18 19:08:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 19:10:01 +00:00
|
|
|
|
protected struct SmokePoint
|
2022-09-18 19:08:34 +00:00
|
|
|
|
{
|
2022-09-18 19:10:01 +00:00
|
|
|
|
public Vector2 Position;
|
|
|
|
|
public double Time;
|
2022-10-18 10:33:03 +00:00
|
|
|
|
public float Angle;
|
2022-09-18 19:10:01 +00:00
|
|
|
|
|
|
|
|
|
public struct UpperBoundComparer : IComparer<SmokePoint>
|
|
|
|
|
{
|
|
|
|
|
public int Compare(SmokePoint x, SmokePoint target)
|
|
|
|
|
{
|
|
|
|
|
// By returning -1 when the target value is equal to x, guarantees that the
|
|
|
|
|
// element at BinarySearch's returned index will always be the first element
|
|
|
|
|
// larger. Since 0 is never returned, the target is never "found", so the return
|
|
|
|
|
// value will be the index's complement.
|
|
|
|
|
|
|
|
|
|
return x.Time > target.Time ? 1 : -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-18 10:33:03 +00:00
|
|
|
|
|
|
|
|
|
public struct LowerBoundComparer : IComparer<SmokePoint>
|
|
|
|
|
{
|
|
|
|
|
public int Compare(SmokePoint x, SmokePoint target)
|
|
|
|
|
{
|
|
|
|
|
// Similar logic as UpperBoundComparer, except returned index will always be
|
|
|
|
|
// the first element larger or equal
|
|
|
|
|
|
|
|
|
|
return x.Time < target.Time ? -1 : 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-18 19:10:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-04 07:17:00 +00:00
|
|
|
|
protected class SmokeDrawNode : TexturedShaderDrawNode
|
2022-09-18 19:10:01 +00:00
|
|
|
|
{
|
2022-10-05 09:27:51 +00:00
|
|
|
|
protected new SmokeSegment Source => (SmokeSegment)base.Source;
|
2022-09-18 19:10:01 +00:00
|
|
|
|
|
2022-09-20 11:42:12 +00:00
|
|
|
|
protected double SmokeStartTime { get; private set; }
|
|
|
|
|
protected double SmokeEndTime { get; private set; }
|
|
|
|
|
protected double CurrentTime { get; private set; }
|
2022-09-18 19:10:01 +00:00
|
|
|
|
|
2022-09-20 11:54:49 +00:00
|
|
|
|
private readonly List<SmokePoint> points = new List<SmokePoint>();
|
|
|
|
|
private IVertexBatch<TexturedVertex2D>? quadBatch;
|
2022-11-21 00:50:15 +00:00
|
|
|
|
private float width;
|
|
|
|
|
private float height;
|
2022-09-20 11:54:49 +00:00
|
|
|
|
private Vector2 drawSize;
|
|
|
|
|
private Texture? texture;
|
2022-10-13 23:18:47 +00:00
|
|
|
|
private int rotationSeed;
|
2022-10-19 06:05:09 +00:00
|
|
|
|
private int firstVisiblePointIndex;
|
2022-09-18 19:10:01 +00:00
|
|
|
|
|
2022-10-04 07:17:00 +00:00
|
|
|
|
// anim calculation vars (color, scale, direction)
|
|
|
|
|
private double initialFadeOutDurationTrunc;
|
2022-10-18 10:33:03 +00:00
|
|
|
|
private double firstVisiblePointTimeAfterSmokeEnded;
|
2022-10-04 07:17:00 +00:00
|
|
|
|
|
|
|
|
|
private double initialFadeOutTime;
|
|
|
|
|
private double reFadeInTime;
|
|
|
|
|
private double finalFadeOutTime;
|
|
|
|
|
|
|
|
|
|
public SmokeDrawNode(ITexturedShaderDrawable source)
|
2022-09-18 19:10:01 +00:00
|
|
|
|
: base(source)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ApplyState()
|
|
|
|
|
{
|
|
|
|
|
base.ApplyState();
|
|
|
|
|
|
2022-11-21 00:50:15 +00:00
|
|
|
|
width = Source.width;
|
|
|
|
|
height = Source.height;
|
2022-09-20 11:54:49 +00:00
|
|
|
|
drawSize = Source.DrawSize;
|
|
|
|
|
texture = Source.Texture;
|
2022-09-18 19:10:01 +00:00
|
|
|
|
|
2022-10-05 09:54:14 +00:00
|
|
|
|
SmokeStartTime = Source.smokeStartTime;
|
|
|
|
|
SmokeEndTime = Source.smokeEndTime;
|
2022-09-20 11:54:49 +00:00
|
|
|
|
CurrentTime = Source.Clock.CurrentTime;
|
2022-10-04 07:17:00 +00:00
|
|
|
|
|
2022-10-13 23:18:47 +00:00
|
|
|
|
rotationSeed = Source.rotationSeed;
|
|
|
|
|
|
2022-10-04 07:17:00 +00:00
|
|
|
|
initialFadeOutDurationTrunc = Math.Min(initial_fade_out_duration, SmokeEndTime - SmokeStartTime);
|
2022-10-18 10:33:03 +00:00
|
|
|
|
firstVisiblePointTimeAfterSmokeEnded = SmokeEndTime - initialFadeOutDurationTrunc;
|
|
|
|
|
|
|
|
|
|
initialFadeOutTime = Math.Min(CurrentTime, SmokeEndTime);
|
|
|
|
|
reFadeInTime = CurrentTime - initialFadeOutDurationTrunc - firstVisiblePointTimeAfterSmokeEnded * (1 - 1 / re_fade_in_speed);
|
|
|
|
|
finalFadeOutTime = CurrentTime - initialFadeOutDurationTrunc - firstVisiblePointTimeAfterSmokeEnded * (1 - 1 / final_fade_out_speed);
|
|
|
|
|
|
2022-10-19 06:05:09 +00:00
|
|
|
|
double firstVisiblePointTime = Math.Min(SmokeEndTime, CurrentTime) - initialFadeOutDurationTrunc;
|
|
|
|
|
firstVisiblePointIndex = ~Source.SmokePoints.BinarySearch(new SmokePoint { Time = firstVisiblePointTime }, new SmokePoint.LowerBoundComparer());
|
|
|
|
|
int futurePointIndex = ~Source.SmokePoints.BinarySearch(new SmokePoint { Time = CurrentTime }, new SmokePoint.UpperBoundComparer());
|
2022-10-04 07:17:00 +00:00
|
|
|
|
|
2022-10-18 10:33:03 +00:00
|
|
|
|
points.Clear();
|
2024-02-23 15:21:11 +00:00
|
|
|
|
|
|
|
|
|
for (int i = firstVisiblePointIndex; i < futurePointIndex; i++)
|
|
|
|
|
points.Add(Source.SmokePoints[i]);
|
2022-09-18 19:10:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-03 23:51:21 +00:00
|
|
|
|
protected sealed override void Draw(IRenderer renderer)
|
2022-09-18 19:08:34 +00:00
|
|
|
|
{
|
2022-09-18 19:10:01 +00:00
|
|
|
|
base.Draw(renderer);
|
|
|
|
|
|
2022-09-20 11:54:49 +00:00
|
|
|
|
if (points.Count == 0)
|
2022-09-18 19:10:01 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2022-10-18 10:33:03 +00:00
|
|
|
|
quadBatch ??= renderer.CreateQuadBatch<TexturedVertex2D>(200, 4);
|
2022-10-19 05:59:58 +00:00
|
|
|
|
|
2022-10-21 06:37:05 +00:00
|
|
|
|
if (points.Count > quadBatch.Size && quadBatch.Size != IRenderer.MAX_QUADS)
|
2022-10-18 10:33:03 +00:00
|
|
|
|
{
|
2022-10-21 06:37:05 +00:00
|
|
|
|
int batchSize = Math.Min(quadBatch.Size * 2, IRenderer.MAX_QUADS);
|
2022-10-18 10:33:03 +00:00
|
|
|
|
quadBatch = renderer.CreateQuadBatch<TexturedVertex2D>(batchSize, 4);
|
|
|
|
|
}
|
2022-10-19 05:59:58 +00:00
|
|
|
|
|
2022-09-20 11:54:49 +00:00
|
|
|
|
texture ??= renderer.WhitePixel;
|
|
|
|
|
RectangleF textureRect = texture.GetTextureRect();
|
2022-09-18 19:10:01 +00:00
|
|
|
|
|
2022-09-19 05:06:07 +00:00
|
|
|
|
renderer.SetBlend(BlendingParameters.Additive);
|
2022-09-20 11:20:32 +00:00
|
|
|
|
renderer.PushLocalMatrix(DrawInfo.Matrix);
|
2022-09-19 05:06:07 +00:00
|
|
|
|
|
2023-03-16 11:06:35 +00:00
|
|
|
|
BindTextureShader(renderer);
|
|
|
|
|
|
2022-09-20 11:54:49 +00:00
|
|
|
|
texture.Bind();
|
2022-09-18 19:10:01 +00:00
|
|
|
|
|
2022-10-18 10:33:03 +00:00
|
|
|
|
for (int i = 0; i < points.Count; i++)
|
2023-08-17 09:12:04 +00:00
|
|
|
|
drawPointQuad(renderer, points[i], textureRect, i + firstVisiblePointIndex);
|
2022-09-18 19:10:01 +00:00
|
|
|
|
|
2023-03-16 11:06:35 +00:00
|
|
|
|
UnbindTextureShader(renderer);
|
2022-09-20 11:20:32 +00:00
|
|
|
|
renderer.PopLocalMatrix();
|
2022-09-18 19:10:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-20 11:39:12 +00:00
|
|
|
|
protected Color4 ColourAtPosition(Vector2 localPos) => DrawColourInfo.Colour.HasSingleColour
|
2022-09-18 19:10:01 +00:00
|
|
|
|
? ((SRGBColour)DrawColourInfo.Colour).Linear
|
2022-09-20 11:54:49 +00:00
|
|
|
|
: DrawColourInfo.Colour.Interpolate(Vector2.Divide(localPos, drawSize)).Linear;
|
2022-09-18 19:10:01 +00:00
|
|
|
|
|
2022-10-04 07:17:00 +00:00
|
|
|
|
protected virtual Color4 PointColour(SmokePoint point)
|
|
|
|
|
{
|
|
|
|
|
var color = Color4.White;
|
|
|
|
|
|
2022-10-18 10:33:03 +00:00
|
|
|
|
double timeDoingFinalFadeOut = finalFadeOutTime - point.Time / final_fade_out_speed;
|
2022-10-19 05:59:58 +00:00
|
|
|
|
|
2022-10-19 06:05:09 +00:00
|
|
|
|
if (timeDoingFinalFadeOut > 0 && point.Time >= firstVisiblePointTimeAfterSmokeEnded)
|
2022-10-04 07:17:00 +00:00
|
|
|
|
{
|
2022-10-18 10:33:03 +00:00
|
|
|
|
float fraction = Math.Clamp((float)(timeDoingFinalFadeOut / final_fade_out_duration), 0, 1);
|
|
|
|
|
fraction = MathF.Pow(fraction, 5);
|
|
|
|
|
color.A = (1 - fraction) * re_fade_in_alpha;
|
2022-10-04 07:17:00 +00:00
|
|
|
|
}
|
2022-10-18 10:33:03 +00:00
|
|
|
|
else
|
2022-10-04 07:17:00 +00:00
|
|
|
|
{
|
2022-10-18 10:33:03 +00:00
|
|
|
|
double timeDoingInitialFadeOut = initialFadeOutTime - point.Time;
|
2022-10-19 05:59:58 +00:00
|
|
|
|
|
2022-10-18 10:33:03 +00:00
|
|
|
|
if (timeDoingInitialFadeOut > 0)
|
2022-10-04 07:17:00 +00:00
|
|
|
|
{
|
2022-10-18 10:33:03 +00:00
|
|
|
|
float fraction = Math.Clamp((float)(timeDoingInitialFadeOut / initial_fade_out_duration), 0, 1);
|
|
|
|
|
color.A = (1 - fraction) * initial_alpha;
|
2022-10-04 07:17:00 +00:00
|
|
|
|
}
|
2022-10-18 10:33:03 +00:00
|
|
|
|
|
|
|
|
|
if (point.Time > firstVisiblePointTimeAfterSmokeEnded)
|
2022-10-04 07:17:00 +00:00
|
|
|
|
{
|
2022-10-18 10:33:03 +00:00
|
|
|
|
double timeDoingReFadeIn = reFadeInTime - point.Time / re_fade_in_speed;
|
2022-10-19 05:59:58 +00:00
|
|
|
|
|
2022-10-18 10:33:03 +00:00
|
|
|
|
if (timeDoingReFadeIn > 0)
|
|
|
|
|
{
|
|
|
|
|
float fraction = Math.Clamp((float)(timeDoingReFadeIn / re_fade_in_duration), 0, 1);
|
|
|
|
|
fraction = 1 - MathF.Pow(1 - fraction, 5);
|
|
|
|
|
color.A = fraction * (re_fade_in_alpha - color.A) + color.A;
|
|
|
|
|
}
|
2022-10-04 07:17:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return color;
|
|
|
|
|
}
|
2022-09-19 05:06:07 +00:00
|
|
|
|
|
2022-10-04 07:17:00 +00:00
|
|
|
|
protected virtual float PointScale(SmokePoint point)
|
|
|
|
|
{
|
|
|
|
|
double timeDoingScale = CurrentTime - point.Time;
|
|
|
|
|
float fraction = Math.Clamp((float)(timeDoingScale / scale_duration), 0, 1);
|
|
|
|
|
fraction = 1 - MathF.Pow(1 - fraction, 5);
|
|
|
|
|
return fraction * (final_scale - initial_scale) + initial_scale;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 10:33:03 +00:00
|
|
|
|
protected virtual Vector2 PointDirection(SmokePoint point, int index)
|
2022-10-04 07:17:00 +00:00
|
|
|
|
{
|
|
|
|
|
double timeDoingRotation = CurrentTime - point.Time;
|
|
|
|
|
float fraction = Math.Clamp((float)(timeDoingRotation / rotation_duration), 0, 1);
|
|
|
|
|
fraction = 1 - MathF.Pow(1 - fraction, 5);
|
2022-10-18 10:33:03 +00:00
|
|
|
|
float angle = fraction * getRotation(index) + point.Angle;
|
2022-10-04 07:17:00 +00:00
|
|
|
|
|
|
|
|
|
return new Vector2(MathF.Sin(angle), -MathF.Cos(angle));
|
|
|
|
|
}
|
2022-09-19 05:06:07 +00:00
|
|
|
|
|
2022-10-18 10:33:03 +00:00
|
|
|
|
private float getRotation(int index) => max_rotation * (StatelessRNG.NextSingle(rotationSeed, index) * 2 - 1);
|
2022-09-18 19:10:01 +00:00
|
|
|
|
|
2023-08-17 09:12:04 +00:00
|
|
|
|
private void drawPointQuad(IRenderer renderer, SmokePoint point, RectangleF textureRect, int index)
|
2022-09-18 19:10:01 +00:00
|
|
|
|
{
|
2022-09-20 11:54:49 +00:00
|
|
|
|
Debug.Assert(quadBatch != null);
|
2022-09-18 19:10:01 +00:00
|
|
|
|
|
2022-09-20 11:39:12 +00:00
|
|
|
|
var colour = PointColour(point);
|
2022-10-18 10:33:03 +00:00
|
|
|
|
if (colour.A == 0)
|
|
|
|
|
return;
|
2022-09-18 19:10:01 +00:00
|
|
|
|
|
2022-10-18 10:33:03 +00:00
|
|
|
|
float scale = PointScale(point);
|
|
|
|
|
if (scale == 0)
|
2022-09-20 08:40:20 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2022-10-18 10:33:03 +00:00
|
|
|
|
var dir = PointDirection(point, index);
|
|
|
|
|
var ortho = dir.PerpendicularLeft;
|
2022-11-21 00:50:15 +00:00
|
|
|
|
dir *= scale * width;
|
|
|
|
|
ortho *= scale * height;
|
2022-10-18 10:33:03 +00:00
|
|
|
|
|
2022-11-21 00:50:15 +00:00
|
|
|
|
var localTopLeft = point.Position - ortho - dir;
|
|
|
|
|
var localTopRight = point.Position - ortho + dir;
|
|
|
|
|
var localBotLeft = point.Position + ortho - dir;
|
|
|
|
|
var localBotRight = point.Position + ortho + dir;
|
2022-09-18 19:08:34 +00:00
|
|
|
|
|
2023-08-17 09:12:04 +00:00
|
|
|
|
quadBatch.Add(new TexturedVertex2D(renderer)
|
2022-09-18 19:10:01 +00:00
|
|
|
|
{
|
2022-09-20 11:20:32 +00:00
|
|
|
|
Position = localTopLeft,
|
2022-09-20 11:54:49 +00:00
|
|
|
|
TexturePosition = textureRect.TopLeft,
|
2022-09-20 11:39:12 +00:00
|
|
|
|
Colour = Color4Extensions.Multiply(ColourAtPosition(localTopLeft), colour),
|
2022-09-18 19:10:01 +00:00
|
|
|
|
});
|
2023-08-17 09:12:04 +00:00
|
|
|
|
quadBatch.Add(new TexturedVertex2D(renderer)
|
2022-09-18 19:10:01 +00:00
|
|
|
|
{
|
2022-09-20 11:20:32 +00:00
|
|
|
|
Position = localTopRight,
|
2022-09-20 11:54:49 +00:00
|
|
|
|
TexturePosition = textureRect.TopRight,
|
2022-09-20 11:39:12 +00:00
|
|
|
|
Colour = Color4Extensions.Multiply(ColourAtPosition(localTopRight), colour),
|
2022-09-18 19:10:01 +00:00
|
|
|
|
});
|
2023-08-17 09:12:04 +00:00
|
|
|
|
quadBatch.Add(new TexturedVertex2D(renderer)
|
2022-09-18 19:10:01 +00:00
|
|
|
|
{
|
2022-09-20 11:20:32 +00:00
|
|
|
|
Position = localBotRight,
|
2022-09-20 11:54:49 +00:00
|
|
|
|
TexturePosition = textureRect.BottomRight,
|
2022-09-20 11:39:12 +00:00
|
|
|
|
Colour = Color4Extensions.Multiply(ColourAtPosition(localBotRight), colour),
|
2022-09-18 19:10:01 +00:00
|
|
|
|
});
|
2023-08-17 09:12:04 +00:00
|
|
|
|
quadBatch.Add(new TexturedVertex2D(renderer)
|
2022-09-18 19:10:01 +00:00
|
|
|
|
{
|
2022-09-20 11:20:32 +00:00
|
|
|
|
Position = localBotLeft,
|
2022-09-20 11:54:49 +00:00
|
|
|
|
TexturePosition = textureRect.BottomLeft,
|
2022-09-20 11:39:12 +00:00
|
|
|
|
Colour = Color4Extensions.Multiply(ColourAtPosition(localBotLeft), colour),
|
2022-09-18 19:10:01 +00:00
|
|
|
|
});
|
2022-09-18 19:08:34 +00:00
|
|
|
|
}
|
2022-09-20 11:38:22 +00:00
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
2022-09-20 11:54:49 +00:00
|
|
|
|
quadBatch?.Dispose();
|
2022-09-20 11:38:22 +00:00
|
|
|
|
}
|
2022-09-18 19:08:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|