Skip to content

Commit

Permalink
version bump: 0.8.12; fixed timeline cleanup concerning same type twe…
Browse files Browse the repository at this point in the history
…ens; added more timeline hashing for more unique ids;
  • Loading branch information
dyonng committed Mar 28, 2023
1 parent 7ed1bc1 commit ce579b5
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [0.8.12] 2023.03.28

### Fixed
- Timelines should now properly wait for previous tweens (of the same type) to be cleaned up before trying to play the new one.
- Timeline Id generation now using more unique hashcodes.

## [0.8.11] 2023.03.23

### Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
![GitHub](https://img.shields.io/github/license/dyonng/dots-tween)
![GitHub repo size](https://img.shields.io/github/repo-size/dyonng/dots-tween)

Entity compatible tween library for Unity ECS/DOTS.
Tweening library for Unity ECS/DOTS 1.0
Now uses Entities Graphics library from Unity.

## Table of Contents
Expand Down
12 changes: 6 additions & 6 deletions Runtime/Timelines/Components/TimelineComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public uint Play(ref EntityCommandBuffer entityCommandBuffer)
{
var e = entityCommandBuffer.CreateEntity();

SetupPlaybackId(ref e, e.GetHashCode());
SetupPlaybackId(ref e, World.DefaultGameObjectInjectionWorld.Unmanaged.Time.ElapsedTime.GetHashCode());
entityCommandBuffer.AddComponent(e, this);
return PlaybackId;
}
Expand All @@ -179,8 +179,8 @@ public uint Play(ref EntityCommandBuffer entityCommandBuffer)
[BurstCompile]
public uint Play(EntityManager entityManager, ref EntityCommandBuffer entityCommandBuffer)
{
var e = entityCommandBuffer.CreateEntity();
SetupPlaybackId(ref e, entityManager.GetHashCode());
var e = entityManager.CreateEntity();
SetupPlaybackId(ref e, entityManager.WorldUnmanaged.Time.ElapsedTime.GetHashCode());
entityCommandBuffer.AddComponent(e, this);
return PlaybackId;
}
Expand All @@ -190,7 +190,7 @@ public uint Play(ref EntityCommandBuffer.ParallelWriter parallelWriter, in int s
{
var e = parallelWriter.CreateEntity(sortKey);

SetupPlaybackId(ref e, sortKey);
SetupPlaybackId(ref e, sortKey ^ World.DefaultGameObjectInjectionWorld.Unmanaged.Time.ElapsedTime.GetHashCode());
parallelWriter.AddComponent(sortKey, e, this);
return PlaybackId;
}
Expand All @@ -200,7 +200,7 @@ public uint Play(EntityManager entityManager, ref EntityCommandBuffer.ParallelWr
{
var e = entityManager.CreateEntity();

SetupPlaybackId(ref e, sortKey);
SetupPlaybackId(ref e, sortKey ^ entityManager.WorldUnmanaged.Time.ElapsedTime.GetHashCode());
parallelWriter.AddComponent(sortKey, e, this);
return PlaybackId;
}
Expand Down Expand Up @@ -228,7 +228,7 @@ public JobHandle Dispose(JobHandle inputDeps)
}

[BurstCompile]
internal void SetupPlaybackId(ref Entity e, in int extraHash = 0)
internal void SetupPlaybackId(ref Entity e, in int extraHash)
{
unchecked
{
Expand Down
1 change: 1 addition & 0 deletions Runtime/Timelines/Components/TimelineElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private static uint GenerateId(in Entity target, in float startTime, in float en
hashCode = (hashCode * 1091) ^ tweenParams.StartDelay.GetHashCode();
hashCode = (hashCode * 1091) ^ tweenParams.TimelineStartPosition.GetHashCode();
hashCode = (hashCode * 1091) ^ tweenParams.TimelineEndPosition.GetHashCode();
hashCode = (hashCode * 1091) ^ tweenParams.Id.GetHashCode();
return (uint)hashCode;
}
}
Expand Down
5 changes: 4 additions & 1 deletion Runtime/Timelines/Systems/TimelineDestroySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ protected override void OnUpdate()
while (!bufferReader.EndOfBuffer && index < timelineRef.ValueRO.Size)
{
var timelineElement = TimelineSystemCommandTypeHelper.DereferenceNextTimelineElement(timelineRef.ValueRO.GetTimelineElementType(index), ref bufferReader);
Tween.Controls.Stop(ref ecb, timelineElement.GetTargetEntity(), timelineElement.GetTweenId());
if (timelineRef.ValueRO.IsTimelineElementActive(timelineElement.GetId()))
{
Tween.Controls.Stop(ref ecb, timelineElement.GetTargetEntity(), timelineElement.GetTweenId());
}
++index;
}

Expand Down
3 changes: 2 additions & 1 deletion Runtime/Timelines/Systems/TimelinePlaybackSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ private void TryToStartPlayingTimelineElement(in ComponentType componentType, re
var hasAlreadyPlayed = timelineElement.GetEndTime() <= timeline.CurrentTime;

if (!pastStartTime || alreadyPlaying || hasAlreadyPlayed) return;

if (TimelineSystemCommandTypeHelper.AlreadyHasInfoComponent(timelineElement.GetTargetEntity(), componentType, EntityManager)) return;

timeline.AddTimelineElementIdToActive(timelineElement.GetId());
TimelineSystemCommandTypeHelper.Add(ref ecb, componentType, ref timelineElement);
}
Expand Down
44 changes: 44 additions & 0 deletions Runtime/Timelines/Systems/TimelineSystemCommandTypeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,49 @@ internal static void Add(ref EntityCommandBuffer ecb, in ComponentType component
if (componentType == SplineMovement) { ecb.AddComponent<TweenSplineMovementCommand>(target, (TweenSplineMovementCommand)command); return; }
#endif
}

[BurstDiscard]
internal static bool AlreadyHasInfoComponent(in Entity target, in ComponentType componentType, in EntityManager entityManager)
{
if (componentType == Translation) return entityManager.HasComponent<TweenTranslation>(target);
if (componentType == Scale) return entityManager.HasComponent<TweenRotation>(target);
if (componentType == Rotation) return entityManager.HasComponent<TweenScale>(target);
if (componentType == NonUniformScale) return entityManager.HasComponent<TweenNonUniformScale>(target);
#if DOTS_TWEEN_URP
if (componentType == URPTint) return entityManager.HasComponent<TweenURPTint>(target);
if (componentType == URPFade) return entityManager.HasComponent<TweenURPFade>(target);
if (componentType == URPBumpScale) return entityManager.HasComponent<TweenURPBumpScale>(target);
if (componentType == URPCutoff) return entityManager.HasComponent<TweenURPCutoff>(target);
if (componentType == URPEmissionColor) return entityManager.HasComponent<TweenURPEmissionColor>(target);
if (componentType == URPMetallic) return entityManager.HasComponent<TweenURPMetallic>(target);
if (componentType == URPOcclusionStrength) return entityManager.HasComponent<TweenURPOcclusionStrength>(target);
if (componentType == URPSmoothness) return entityManager.HasComponent<TweenURPSmoothness>(target);
if (componentType == URPSpecularColor) return entityManager.HasComponent<TweenURPSpecularColor>(target);
#elif DOTS_TWEEN_HDRP
if (componentType == HDRPAlphaCutoff) return entityManager.HasComponent<TweenHDRPAlphaCutoff>(target);
if (componentType == HDRPAmbientOcclusionRemapMax) return entityManager.HasComponent<TweenHDRPAmbientOcclusionRemapMax>(target);
if (componentType == HDRPAmbientOcclusionRemapMin) return entityManager.HasComponent<TweenHDRPAmbientOcclusionRemapMin>(target);
if (componentType == HDRPDetailAlbedoScale) return entityManager.HasComponent<TweenHDRPDetailAlbedoScale>(target);
if (componentType == HDRPDetailNormalScale) return entityManager.HasComponent<TweenHDRPDetailNormalScale>(target);
if (componentType == HDRPDetailSmoothnessScale) return entityManager.HasComponent<TweenHDRPDetailSmoothnessScale>(target);
if (componentType == HDRPDiffusionProfileHash) return entityManager.HasComponent<TweenHDRPDiffusionProfileHash>(target);
if (componentType == HDRPEmissiveColor) return entityManager.HasComponent<TweenHDRPEmissiveColor>(target);
if (componentType == HDRPMetallic) return entityManager.HasComponent<TweenHDRPMetallic>(target);
if (componentType == HDRPSmoothness) return entityManager.HasComponent<TweenHDRPSmoothness>(target);
if (componentType == HDRPSmoothnessRemapMax) return entityManager.HasComponent<TweenHDRPSmoothnessRemapMax>(target);
if (componentType == HDRPSmoothnessRemapMin) return entityManager.HasComponent<TweenHDRPSmoothnessRemapMin>(target);
if (componentType == HDRPSpecularColor) return entityManager.HasComponent<TweenHDRPSpecularColor>(target);
if (componentType == HDRPThickness) return entityManager.HasComponent<TweenHDRPThickness>(target);
if (componentType == HDRPThicknessRemap) return entityManager.HasComponent<TweenHDRPThicknessRemap>(target);
if (componentType == HDRPTint) return entityManager.HasComponent<TweenHDRPTint>(target);
if (componentType == HDRPTintUnlit) return entityManager.HasComponent<TweenHDRPTintUnlit>(target);
if (componentType == HDRPFade) return entityManager.HasComponent<TweenHDRPFade>(target);
if (componentType == HDRPFadeUnlit) return entityManager.HasComponent<TweenHDRPFadeUnlit>(target);
#endif
#if DOTS_TWEEN_SPLINES
if (componentType == SplineMovement) return entityManager.HasComponent<TweenSplineMovement>(target);
#endif
return false;
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.dyonng.dotstween",
"version": "0.8.11",
"version": "0.8.12",
"displayName": "DOTS Tween",
"description": "Tween library for Unity ECS/DOTS.",
"unity": "2022.2",
Expand Down

0 comments on commit ce579b5

Please sign in to comment.