Skip to content

Commit

Permalink
Merge pull request #14 from AnnulusGames/v0.1.9
Browse files Browse the repository at this point in the history
v0.1.9
  • Loading branch information
AnnulusGames committed Oct 24, 2023
2 parents ce25b7f + 3427ab1 commit f8fd81e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace MagicTween.Core
[UpdateInGroup(typeof(MagicTweenCallbackSystemGroup))]
public sealed partial class TweenCallbackSystem : SystemBase
{
public bool IsExecuting => _isExecuting;

bool _isExecuting;
EntityQuery query;

protected override void OnCreate()
Expand All @@ -21,9 +24,17 @@ protected override void OnCreate()

protected override void OnUpdate()
{
CompleteDependency();
var job = new SystemJob();
job.Run(query);
_isExecuting = true;
try
{
CompleteDependency();
var job = new SystemJob();
job.Run(query);
}
finally
{
_isExecuting = false;
}
}

partial struct SystemJob : IJobEntity
Expand Down
19 changes: 13 additions & 6 deletions MagicTween/Assets/MagicTween/Runtime/Core/TweenFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,20 @@ static void CreateTweenEntity(ref EntityManager entityManager, in EntityArchetyp
entityManager.SetComponentData(entity, new TweenControllerReference(controllerId));
}

[BurstCompile]
static void SetStartAndEndValue<TValue>(in Entity entity, in TValue startValue, in TValue endValue)
where TValue : unmanaged
{
EntityManagerRef.SetComponentData(entity, new TweenStartValue<TValue>() { value = startValue });
EntityManagerRef.SetComponentData(entity, new TweenEndValue<TValue>() { value = endValue });
}

static void InitializeLambdaTweenComponents<TValue, TPlugin>(
in Entity entity, in TValue startValue, in TValue endValue, TweenGetter<TValue> getter, TweenSetter<TValue> setter)
where TValue : unmanaged
where TPlugin : unmanaged, ITweenPlugin<TValue>
{
EntityManagerRef.SetComponentData(entity, new TweenStartValue<TValue>() { value = startValue });
EntityManagerRef.SetComponentData(entity, new TweenEndValue<TValue>() { value = endValue });
SetStartAndEndValue(entity, startValue, endValue);
EntityManagerRef.SetComponentData(entity, new TweenPropertyAccessor<TValue>(getter, setter));
}

Expand All @@ -355,15 +362,15 @@ static void InitializeUnsafeLambdaTweenComponents<TObject, TValue, TPlugin>(
where TValue : unmanaged
where TPlugin : unmanaged, ITweenPlugin<TValue>
{
EntityManagerRef.SetComponentData(entity, new TweenStartValue<TValue>() { value = startValue });
EntityManagerRef.SetComponentData(entity, new TweenEndValue<TValue>() { value = endValue });
SetStartAndEndValue(entity, startValue, endValue);
EntityManagerRef.SetComponentData(entity, new TweenPropertyAccessorUnsafe<TValue>(
target,
UnsafeUtility.As<TweenGetter<TObject, TValue>, TweenGetter<object, TValue>>(ref getter),
UnsafeUtility.As<TweenSetter<TObject, TValue>, TweenSetter<object, TValue>>(ref setter)
));
}

[BurstCompile]
static void InitializeEntityTweenComponents<TValue, TTranslator>(
ref EntityManager entityManager, in Entity entity, in TValue startValue, in TValue endValue, in Entity target)
where TValue : unmanaged
Expand All @@ -372,10 +379,10 @@ static void InitializeEntityTweenComponents<TValue, TTranslator>(
var translator = default(TTranslator);
translator.TargetEntity = target;

entityManager.SetComponentData(entity, new TweenStartValue<TValue>() { value = startValue });
entityManager.SetComponentData(entity, new TweenEndValue<TValue>() { value = endValue });
SetStartAndEndValue(entity, startValue, endValue);
entityManager.SetComponentData(entity, translator);
}
[BurstCompile]

static void InitializeEntityTweenComponents<TValue, TTranslator>(
ref EntityManager entityManager, in Entity entity, in TValue endValue, in Entity target)
Expand Down
3 changes: 3 additions & 0 deletions MagicTween/Assets/MagicTween/Runtime/Core/TweenWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ public static void Initialize()
_world = World.DefaultGameObjectInjectionWorld;
_entityManager = _world.EntityManager;
_cleanupSystem = _world.GetExistingSystemManaged<TweenCleanupSystem>();
_callbackSystem = _world.GetExistingSystemManaged<TweenCallbackSystem>();
ArchetypeStorage.Create(Allocator.Persistent, out _archetypeStorage);
}

static World _world;
static EntityManager _entityManager;
static TweenCleanupSystem _cleanupSystem;
static TweenCallbackSystem _callbackSystem;
static ArchetypeStorage _archetypeStorage;

public static World World => _world;
public static EntityManager EntityManager => _entityManager;
public static ref EntityManager EntityManagerRef => ref _entityManager;
public static TweenCleanupSystem CleanupSystem => _cleanupSystem;
public static TweenCallbackSystem CallbackSystem => _callbackSystem;
internal static ref ArchetypeStorage ArchetypeStorageRef => ref _archetypeStorage;
}
}
13 changes: 10 additions & 3 deletions MagicTween/Assets/MagicTween/Runtime/TweenCallbackExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ internal static TweenCallbackActions GetOrAddComponent(in Entity entity)
}
else
{
// Use EntityCommandBuffer to avoid structural changes
var actions = new TweenCallbackActions();
var commandBuffer = TweenWorld.World.GetExistingSystemManaged<EndSimulationEntityCommandBufferSystem>().CreateCommandBuffer();
commandBuffer.AddComponent(entity, actions);
if (TweenWorld.CallbackSystem.IsExecuting)
{
// Use EntityCommandBuffer to avoid structural changes
var commandBuffer = TweenWorld.World.GetExistingSystemManaged<EndSimulationEntityCommandBufferSystem>().CreateCommandBuffer();
commandBuffer.AddComponent(entity, actions);
}
else
{
TweenWorld.EntityManager.AddComponentData(entity, actions);
}
return actions;
}
}
Expand Down
2 changes: 1 addition & 1 deletion MagicTween/Assets/MagicTween/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.annulusgames.magic-tween",
"version": "0.1.8",
"version": "0.1.9",
"displayName": "Magic Tween",
"description": "Extremely fast tween library implemented with Unity ECS",
"unity": "2022.1",
Expand Down
2 changes: 1 addition & 1 deletion MagicTween/ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ PlayerSettings:
vulkanEnableLateAcquireNextImage: 0
vulkanEnableCommandBufferRecycling: 1
loadStoreDebugModeEnabled: 0
bundleVersion: 0.1.8
bundleVersion: 0.1.9
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
Expand Down

0 comments on commit f8fd81e

Please sign in to comment.