1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-28 17:17:46 +08:00

Move all the logic into BarsInfo class

This commit is contained in:
Andrei Zavatski 2022-11-20 23:00:13 +03:00
parent 36141cb2a4
commit 18c79dfda3

View File

@ -58,27 +58,9 @@ namespace osu.Game.Graphics.UserInterface
return; return;
} }
int newCount = value.Count();
bars.Breadth = 1.0f / newCount;
float maxLength = MaxValue ?? value.Max(); float maxLength = MaxValue ?? value.Max();
foreach (var bar in value.Select((length, index) => (Value: length, Index: index))) bars.SetLengths(value.Select(v => maxLength == 0 ? 0 : Math.Max(0f, v / maxLength)).ToArray());
{
float length = maxLength == 0 ? 0 : Math.Max(0f, bar.Value / maxLength);
if (bar.Index < bars.Count)
{
bars.UpdateLength(bar.Index, length);
continue;
}
bars.AddBar(length);
}
if (bars.Count > newCount)
bars.RemoveRange(newCount, bars.Count - newCount);
animationStartTime = Clock.CurrentTime; animationStartTime = Clock.CurrentTime;
animationComplete = false; animationComplete = false;
@ -208,44 +190,48 @@ namespace osu.Game.Graphics.UserInterface
public int Count { get; private set; } public int Count { get; private set; }
public float Breadth { get; set; } public float Breadth { get; private set; }
public List<float> InstantaneousLengths { get; } = new List<float>(); public List<float> InstantaneousLengths { get; } = new List<float>();
private readonly List<float> initialLengths = new List<float>(); private readonly List<float> initialLengths = new List<float>();
private readonly List<float> finalLengths = new List<float>(); private readonly List<float> finalLengths = new List<float>();
public void UpdateLength(int index, float newLength) public void Clear() => SetLengths(Array.Empty<float>());
public void SetLengths(float[] newLengths)
{ {
initialLengths[index] = finalLengths[index]; int newCount = newLengths.Length;
finalLengths[index] = newLength;
}
public void AddBar(float finalLength) for (int i = 0; i < newCount; i++)
{ {
initialLengths.Add(0); // If we have an old bar at this index - change it's length
finalLengths.Add(finalLength); if (i < Count)
InstantaneousLengths.Add(0); {
initialLengths[i] = finalLengths[i];
finalLengths[i] = newLengths[i];
Count++; continue;
} }
public void Clear() // If exceeded old bars count - add new one
{ initialLengths.Add(0);
initialLengths.Clear(); finalLengths.Add(newLengths[i]);
finalLengths.Clear(); InstantaneousLengths.Add(0);
InstantaneousLengths.Clear(); }
Count = 0; // Remove excessive bars
} if (Count > newCount)
{
int barsToRemove = Count - newCount;
public void RemoveRange(int index, int count) initialLengths.RemoveRange(newCount, barsToRemove);
{ finalLengths.RemoveRange(newCount, barsToRemove);
initialLengths.RemoveRange(index, count); InstantaneousLengths.RemoveRange(newCount, barsToRemove);
finalLengths.RemoveRange(index, count); }
InstantaneousLengths.RemoveRange(index, count);
Count -= count; Count = newCount;
Breadth = Count == 0 ? 0 : (1f / Count);
} }
public void Animate(double animationStartTime, double currentTime) public void Animate(double animationStartTime, double currentTime)