Boost visualiser performance

Also fixes amplitudes being set wrongly if kiai was false.
This commit is contained in:
ColdVolcano 2017-06-21 18:32:31 -05:00
parent 08cf5b6952
commit 1978a4e8a6
1 changed files with 18 additions and 8 deletions

View File

@ -44,7 +44,7 @@ internal class LogoVisualisation : Drawable, IHasAccentColour
private const float visualiser_rounds = 5;
/// <summary>
/// How much should each bar go down each milisecond (based on a full bar)
/// How much should each bar go down each milisecond (based on a full bar).
/// </summary>
private const float decay_per_milisecond = 0.0024f;
@ -53,6 +53,11 @@ internal class LogoVisualisation : Drawable, IHasAccentColour
/// </summary>
private const float time_between_updates = 50;
/// <summary>
/// The minimum amplitude to show a bar.
/// </summary>
private const float amplitude_dead_zone = 1f / (bar_length);
private int indexOffset;
public Color4 AccentColour { get; set; }
@ -87,16 +92,17 @@ private void updateAmplitudes()
for (int i = 0; i < bars_per_visualiser; i++)
{
int index = (i + indexOffset) % bars_per_visualiser;
if (beatmap?.Value?.Track?.IsRunning ?? false)
{
if (temporalAmplitudes[index] > frequencyAmplitudes[i])
frequencyAmplitudes[i] = temporalAmplitudes[index] * (effect?.KiaiMode == true ? 1 : 0.5f);
float targetAmplitude = temporalAmplitudes[(i + indexOffset) % bars_per_visualiser] * (effect?.KiaiMode == true ? 1 : 0.5f);
if (targetAmplitude > frequencyAmplitudes[i])
frequencyAmplitudes[i] = targetAmplitude;
}
else
{
if (frequencyAmplitudes[(i + index_change) % bars_per_visualiser] > frequencyAmplitudes[i])
frequencyAmplitudes[i] = frequencyAmplitudes[(i + index_change) % bars_per_visualiser];
int index = (i + index_change) % bars_per_visualiser;
if (frequencyAmplitudes[index] > frequencyAmplitudes[i])
frequencyAmplitudes[i] = frequencyAmplitudes[index];
}
}
@ -117,7 +123,7 @@ protected override void Update()
float decayFactor = (float)Time.Elapsed * decay_per_milisecond;
for (int i = 0; i < bars_per_visualiser; i++)
{
//0.03% of extra bar length to make it a little faster when bar is almost at it's minimum
//3% of extra bar length to make it a little faster when bar is almost at it's minimum
frequencyAmplitudes[i] -= decayFactor * (frequencyAmplitudes[i] + 0.03f);
if (frequencyAmplitudes[i] < 0)
frequencyAmplitudes[i] = 0;
@ -129,6 +135,7 @@ protected override void Update()
protected override DrawNode CreateDrawNode() => new VisualisationDrawNode();
private readonly VisualiserSharedData sharedData = new VisualiserSharedData();
protected override void ApplyDrawNode(DrawNode node)
{
base.ApplyDrawNode(node);
@ -177,13 +184,16 @@ public override void Draw(Action<TexturedVertex2D> vertexAction)
{
for (int i = 0; i < bars_per_visualiser; i++)
{
if (AudioData[i] < bar_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 barSize = new Vector2(Size * (float)Math.Sqrt(2 * (1 - Math.Cos(MathHelper.DegreesToRadians(360f / bars_per_visualiser)))) / 2f, bar_length * AudioData[i % bars_per_visualiser]);
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.