Add Triangles.Reset()

This commit is contained in:
smoogipoo 2020-11-17 13:06:30 +09:00
parent 33c643e369
commit 3bcf9c255a
1 changed files with 17 additions and 5 deletions

View File

@ -87,12 +87,9 @@ public Color4 ColourDark
/// </summary>
public float Velocity = 1;
private readonly Random stableRandom;
private float nextRandom() => (float)(stableRandom?.NextDouble() ?? RNG.NextSingle());
private readonly SortedList<TriangleParticle> parts = new SortedList<TriangleParticle>(Comparer<TriangleParticle>.Default);
private Random stableRandom;
private IShader shader;
private readonly Texture texture;
@ -173,7 +170,20 @@ protected override void Update()
}
}
protected int AimCount;
/// <summary>
/// Clears and re-initialises triangles according to a given seed.
/// </summary>
/// <param name="seed">An optional seed to stabilise random positions / attributes. Note that this does not guarantee stable playback when seeking in time.</param>
public void Reset(int? seed = null)
{
if (seed != null)
stableRandom = new Random(seed.Value);
parts.Clear();
addTriangles(true);
}
protected int AimCount { get; private set; }
private void addTriangles(bool randomY)
{
@ -227,6 +237,8 @@ private void updateColours()
}
}
private float nextRandom() => (float)(stableRandom?.NextDouble() ?? RNG.NextSingle());
protected override DrawNode CreateDrawNode() => new TrianglesDrawNode(this);
private class TrianglesDrawNode : DrawNode