osu/osu.Game.Rulesets.Osu/UI/ReplayAnalysis/MovementPathContainer.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
2.1 KiB
C#
Raw Normal View History

// 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.
using System;
using System.Collections.Generic;
2024-09-04 11:25:29 +00:00
using osu.Framework.Allocation;
using osu.Framework.Graphics.Lines;
using osu.Framework.Graphics.Performance;
2024-09-04 11:25:29 +00:00
using osu.Game.Graphics;
namespace osu.Game.Rulesets.Osu.UI.ReplayAnalysis
{
2024-09-04 11:17:22 +00:00
public partial class MovementPathContainer : Path
{
private readonly LifetimeEntryManager lifetimeManager = new LifetimeEntryManager();
2024-09-04 11:25:29 +00:00
private readonly SortedSet<AnalysisFrameEntry> aliveEntries = new SortedSet<AnalysisFrameEntry>(new AimLinePointComparator());
2024-09-04 11:17:22 +00:00
public MovementPathContainer()
{
lifetimeManager.EntryBecameAlive += entryBecameAlive;
lifetimeManager.EntryBecameDead += entryBecameDead;
2024-09-04 12:04:59 +00:00
PathRadius = 0.5f;
2024-09-04 11:25:29 +00:00
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Colour = colours.Pink2;
}
protected override void Update()
{
base.Update();
lifetimeManager.Update(Time.Current);
}
2024-09-04 11:25:29 +00:00
public void Add(AnalysisFrameEntry entry) => lifetimeManager.AddEntry(entry);
private void entryBecameAlive(LifetimeEntry entry)
{
2024-09-04 11:25:29 +00:00
aliveEntries.Add((AnalysisFrameEntry)entry);
updateVertices();
}
private void entryBecameDead(LifetimeEntry entry)
{
2024-09-04 11:25:29 +00:00
aliveEntries.Remove((AnalysisFrameEntry)entry);
updateVertices();
}
private void updateVertices()
{
ClearVertices();
foreach (var entry in aliveEntries)
{
AddVertex(entry.Position);
}
}
2024-09-04 11:25:29 +00:00
private sealed class AimLinePointComparator : IComparer<AnalysisFrameEntry>
{
2024-09-04 11:25:29 +00:00
public int Compare(AnalysisFrameEntry? x, AnalysisFrameEntry? y)
{
ArgumentNullException.ThrowIfNull(x);
ArgumentNullException.ThrowIfNull(y);
return x.LifetimeStart.CompareTo(y.LifetimeStart);
}
}
}
}