Skip to content

Commit

Permalink
Merge pull request #53 from AnnulusGames/optimize-addto
Browse files Browse the repository at this point in the history
Optimize: AddTo
  • Loading branch information
AnnulusGames authored Jan 16, 2024
2 parents 7b7afad + 01b1aae commit 7a0618a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;

namespace LitMotion
Expand All @@ -7,18 +7,20 @@ namespace LitMotion
[AddComponentMenu("")]
internal sealed class MotionHandleLinker : MonoBehaviour
{
readonly List<MotionHandle> handleList = new(8);
readonly MinimumList<MotionHandle> handleList = new(8);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Register(MotionHandle handle)
{
handleList.Add(handle);
}

void OnDestroy()
{
for (int i = 0; i < handleList.Count; i++)
var span = handleList.AsSpan();
for (int i = 0; i < span.Length; i++)
{
var handle = handleList[i];
ref var handle = ref span[i];
if (handle.IsActive()) handle.Cancel();
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/LitMotion/Assets/LitMotion/Tests/Runtime/AddToTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;

namespace LitMotion.Tests.Runtime
{
public class AddToTest
{
[UnityTest]
public IEnumerator Test_AddTo()
{
var canceled = false;
var obj = new GameObject("Target");
var handle = LMotion.Create(0f, 1f, 2f)
.WithOnCancel(() => canceled = true)
.RunWithoutBinding()
.AddTo(obj);
yield return new WaitForSeconds(0.1f);
Object.DestroyImmediate(obj);
Assert.IsTrue(canceled);
}
}
}
11 changes: 11 additions & 0 deletions src/LitMotion/Assets/LitMotion/Tests/Runtime/AddToTest.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7a0618a

Please sign in to comment.