Skip to content

Commit

Permalink
Use ulong for sequence id
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Oct 2, 2024
1 parent ca58b12 commit 6a232c4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion osu.Framework/Graphics/Transforms/ITransformable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public interface ITransformable

IEnumerable<Transform> GetTransforms();

TransformSequenceEventHandler? GetTransformEventHandler(Guid? sequenceId);
TransformSequenceEventHandler? GetTransformEventHandler(ulong sequenceId);
}
}
33 changes: 16 additions & 17 deletions osu.Framework/Graphics/Transforms/TargetGroupingTransformTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ internal class TargetGroupingTransformTracker

private readonly Transformable transformable;

private readonly HashSet<Guid> abortedSequences = new HashSet<Guid>();
private readonly HashSet<Guid> completedSequences = new HashSet<Guid>();
private readonly HashSet<ulong> abortedSequences = new HashSet<ulong>();
private readonly HashSet<ulong> completedSequences = new HashSet<ulong>();

/// <summary>
/// Used to assign a monotonically increasing ID to <see cref="Transform"/>s as they are added. This member is
Expand Down Expand Up @@ -143,8 +143,7 @@ public void UpdateTransforms(in double time, bool rewinding)
flushAppliedCache = true;
i--;

if (u.SequenceID is Guid sequenceID)
abortedSequences.Add(sequenceID);
abortedSequences.Add(u.SequenceID);
}
else
u.AppliedToEnd = true;
Expand Down Expand Up @@ -199,8 +198,8 @@ public void UpdateTransforms(in double time, bool rewinding)
transforms.Add(t);
flushAppliedCache = true;
}
else if (t.SequenceID is Guid sequenceID)
completedSequences.Add(sequenceID);
else
completedSequences.Add(t.SequenceID);
}
}

Expand Down Expand Up @@ -247,9 +246,7 @@ public void AddTransform(Transform transform)
if (t.TargetMember == transform.TargetMember)
{
transforms.RemoveAt(i--);

if (t.SequenceID is Guid sequenceID)
abortedSequences.Add(sequenceID);
abortedSequences.Add(t.SequenceID);
}
}

Expand Down Expand Up @@ -287,9 +284,7 @@ public virtual void ClearTransformsAfter(double time, string targetMember = null
if (t.StartTime >= time)
{
transforms.RemoveAt(i--);

if (t.SequenceID is Guid sequenceID)
abortedSequences.Add(sequenceID);
abortedSequences.Add(t.SequenceID);
}
}
}
Expand All @@ -302,9 +297,7 @@ public virtual void ClearTransformsAfter(double time, string targetMember = null
if (t.TargetMember == targetMember && t.StartTime >= time)
{
transforms.RemoveAt(i--);

if (t.SequenceID is Guid sequenceID)
abortedSequences.Add(sequenceID);
abortedSequences.Add(t.SequenceID);
}
}
}
Expand Down Expand Up @@ -348,17 +341,23 @@ public virtual void FinishTransforms(string targetMember = null)

private void invokePendingRemovalActions()
{
foreach (var sequenceId in completedSequences)
foreach (ulong sequenceId in completedSequences)
{
if (sequenceId == 0)
continue;

if (transformable.GetTransformEventHandler(sequenceId) is TransformSequenceEventHandler handler)
{
transformable.RemoveTransformNoAbort(handler);
handler.TriggerComplete();
}
}

foreach (var sequenceId in abortedSequences)
foreach (ulong sequenceId in abortedSequences)
{
if (sequenceId == 0)
continue;

for (int i = 0; i < transforms.Count; i++)
{
if (transforms[i].SequenceID == sequenceId)
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Graphics/Transforms/Transform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public abstract class Transform
public double StartTime { get; internal set; }
public double EndTime { get; internal set; }

internal Guid? SequenceID;
internal ulong SequenceID;
internal Transform SequenceLast;

public bool IsLooping => LoopCount == -1 || LoopCount > 0;
Expand Down
11 changes: 9 additions & 2 deletions osu.Framework/Graphics/Transforms/TransformSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@

using System;
using System.Buffers;
using System.Threading;

namespace osu.Framework.Graphics.Transforms
{
internal static class TransformSequenceStatics
{
private static ulong id = 1;
public static ulong NextId() => Interlocked.Increment(ref id);
}

internal static class TransformSequenceStatics<T>
where T : class, ITransformable
{
Expand All @@ -20,7 +27,7 @@ public readonly struct TransformSequence<T>
where T : class, ITransformable
{
public required T Target { get; init; }
public required Guid SequenceId { get; init; }
public required ulong SequenceId { get; init; }
public required double StartTime { get; init; }

public int SequenceLength { get; init; }
Expand All @@ -41,7 +48,7 @@ public static TransformSequence<T> Create(T target)
return new TransformSequence<T>
{
Target = target,
SequenceId = Guid.NewGuid(),
SequenceId = TransformSequenceStatics.NextId(),
StartTime = target.TransformStartTime,
CurrentTime = target.TransformStartTime,
EndTime = target.TransformStartTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class TransformSequenceEventHandler : Transform
public override string TargetMember => SequenceID.ToString()!;
public override string TargetGrouping => GROUP;

public TransformSequenceEventHandler(ITransformable target, Guid sequenceId)
public TransformSequenceEventHandler(ITransformable target, ulong sequenceId)
{
TargetTransformable = target;
SequenceID = sequenceId;
Expand Down
4 changes: 2 additions & 2 deletions osu.Framework/Graphics/Transforms/Transformable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ public void RemoveTransformNoAbort(Transform toRemove)

public IEnumerable<Transform> GetTransforms() => Transforms;

public TransformSequenceEventHandler GetTransformEventHandler(Guid? sequenceId)
public TransformSequenceEventHandler GetTransformEventHandler(ulong sequenceId)
{
if (sequenceId == null)
if (sequenceId == 0)
return null;

TargetGroupingTransformTracker tracker = getTrackerForGrouping(TransformSequenceEventHandler.GROUP, false);
Expand Down

0 comments on commit 6a232c4

Please sign in to comment.