Skip to content

Commit

Permalink
version bump: 0.10.0; updated entities to 1.0.16;
Browse files Browse the repository at this point in the history
  • Loading branch information
dyonng committed Sep 18, 2023
1 parent e705234 commit 3ad88c9
Show file tree
Hide file tree
Showing 55 changed files with 1,135 additions and 461 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## [0.10.0] 2023.09.18

### Added
- Aggressively inline `static` methods for minor performance boost.

### Changed
- Updated dependencies:
- `"com.unity.entities": "1.0.16"`
- `"com.unity.burst": "1.8.8"`
- `"com.unity.entities.graphics": "1.0.16"`

## [0.9.1] 2023.07.31

### Fixed
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

### Updated to Unity 2022.3 LTS

Tweening library for Unity ECS/DOTS 1.0.11
Now uses Entities Graphics library from Unity.
Developed on `2022.3.5f1`, in case you were wondering :)
Tweening library for Unity ECS/DOTS
Updated for Entities 1.0.16
Uses Entities Graphics library from Unity.
Developed on `2022.3.9f1`, in case you were wondering :)

## Table of Contents

Expand Down Expand Up @@ -114,10 +115,10 @@ Developed on `2022.3.5f1`, in case you were wondering :)
```json
"dependencies": {
"com.unity.collections": "2.1.4",
"com.unity.entities": "1.0.11",
"com.unity.burst": "1.8.7",
"com.unity.entities": "1.0.16",
"com.unity.burst": "1.8.8",
"com.unity.mathematics": "1.2.6",
"com.unity.entities.graphics": "1.0.11"
"com.unity.entities.graphics": "1.0.16"
}
```

Expand Down
67 changes: 35 additions & 32 deletions Runtime/Math/EasingFunctions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Unity.Burst;
using System.Runtime.CompilerServices;
using Unity.Burst;
using Unity.Mathematics;

namespace DotsTween.Math
Expand All @@ -14,39 +15,40 @@ public static class EasingFunctions
private const float C4 = (2f * math.PI) / 3f;
private const float C5 = (2f * math.PI) / 4.5f;

private static float Linear(float x) { return x; }
private static float InQuad(float x) { return x * x; }
private static float OutQuad(float x) { return 1f - (1f - x) * (1f - x); }
private static float InOutQuad(float x) { return x < 0.5f ? 2f * x * x : 1f - math.pow(-2f * x + 2f, 2f) / 2f; }
private static float InCubic(float x) { return x * x * x; }
private static float OutCubic(float x) { return 1 - math.pow(1 - x, 3); }
private static float InOutCubic(float x) { return x < 0.5 ? 4 * x * x * x : 1 - math.pow(-2 * x + 2, 3) / 2; }
private static float InQuart(float x) { return x * x * x * x; }
private static float OutQuart(float x) { return 1f - math.pow(1f - x, 4f); }
private static float InOutQuart(float x) { return x < 0.5f ? 8f * x * x * x * x : 1f - math.pow(-2f * x + 2f, 4f) / 2f; }
private static float InQuint(float x) { return x * x * x * x * x; }
private static float OutQuint(float x) { return 1f - math.pow(1f - x, 5f); }
private static float InOutQuint(float x) { return x < 0.5f ? 16f * x * x * x * x * x : 1 - math.pow(-2f * x + 2f, 5f) / 2f; }
private static float InSine(float x) { return 1f - math.cos((x * math.PI) / 2f); }
private static float OutSine(float x) { return math.sin((x * math.PI) / 2f); }
private static float InOutSine(float x) { return -(math.cos(math.PI * x) - 1f) / 2f; }
private static float InExpo(float x) { return x <= 0f ? 0f : math.pow(2f, 10f * x - 10f); }
private static float OutExpo(float x) { return x >= 1f ? 1f : 1f - math.pow(2f, -10f * x); }
private static float InOutExpo(float x) { return x <= 0f ? 0f : x >= 1f ? 1f : x < 0.5f ? math.pow(2f, 20f * x - 10f) / 2f : (2f - math.pow(2f, -20f * x + 10f)) / 2f; }
private static float InCirc(float x) { return 1f - math.sqrt(1f - math.pow(x, 2f)); }
private static float OutCirc(float x) { return math.sqrt(1f - math.pow(x - 1f, 2f)); }
private static float InOutCirc(float x) { return x < 0.5f ? (1f - math.sqrt(1f - math.pow(2f * x, 2f))) / 2f : (math.sqrt(1f - math.pow(-2f * x + 2f, 2f)) + 1f) / 2f; }
private static float InBack(float x) { return C3 * x * x * x - C1 * x * x; }
private static float OutBack(float x) { return 1f + C3 * math.pow(x - 1f, 3f) + C1 * math.pow(x - 1f, 2f); }
private static float InOutBack(float x) { return x < 0.5f ? (math.pow(2f * x, 2f) * ((C2 + 1f) * 2f * x - C2)) / 2f : (math.pow(2f * x - 2f, 2f) * ((C2 + 1f) * (x * 2f - 2f) + C2) + 2f) / 2f; }
private static float InElastic(float x) { return x <= 0f ? 0f : x >= 1f ? 1f : -math.pow(2f, 10f * x - 10f) * math.sin((x * 10f - 10.75f) * C4); }
private static float OutElastic(float x) { return x <= 0f ? 0f : x >= 1f ? 1f : math.pow(2f, -10f * x) * math.sin((x * 10f - 0.75f) * C4) + 1f; }
private static float InOutElastic(float x) { return x <= 0f ? 0f : x >= 1f ? 1f : x < 0.5f ? -(math.pow(2f, 20f * x - 10f) * math.sin((20f * x - 11.125f) * C5)) / 2 : (math.pow(2f, -20f * x + 10f) * math.sin((20f * x - 11.125f) * C5)) / 2f + 1f; }
private static float InBounce(float x) { return 1 - InterpolateOutBounceStatic(1 - x); }
private static float OutBounce(float x) { return InterpolateOutBounceStatic(x); }
private static float InOutBounce(float x) { return x < 0.5f ? (1f - InterpolateOutBounceStatic(1f - 2f * x)) / 2f : (1f + InterpolateOutBounceStatic(2f * x - 1f)) / 2f; }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float Linear(float x) { return x; }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InQuad(float x) { return x * x; }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float OutQuad(float x) { return 1f - (1f - x) * (1f - x); }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InOutQuad(float x) { return x < 0.5f ? 2f * x * x : 1f - math.pow(-2f * x + 2f, 2f) / 2f; }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InCubic(float x) { return x * x * x; }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float OutCubic(float x) { return 1 - math.pow(1 - x, 3); }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InOutCubic(float x) { return x < 0.5 ? 4 * x * x * x : 1 - math.pow(-2 * x + 2, 3) / 2; }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InQuart(float x) { return x * x * x * x; }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float OutQuart(float x) { return 1f - math.pow(1f - x, 4f); }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InOutQuart(float x) { return x < 0.5f ? 8f * x * x * x * x : 1f - math.pow(-2f * x + 2f, 4f) / 2f; }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InQuint(float x) { return x * x * x * x * x; }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float OutQuint(float x) { return 1f - math.pow(1f - x, 5f); }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InOutQuint(float x) { return x < 0.5f ? 16f * x * x * x * x * x : 1 - math.pow(-2f * x + 2f, 5f) / 2f; }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InSine(float x) { return 1f - math.cos((x * math.PI) / 2f); }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float OutSine(float x) { return math.sin((x * math.PI) / 2f); }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InOutSine(float x) { return -(math.cos(math.PI * x) - 1f) / 2f; }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InExpo(float x) { return x <= 0f ? 0f : math.pow(2f, 10f * x - 10f); }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float OutExpo(float x) { return x >= 1f ? 1f : 1f - math.pow(2f, -10f * x); }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InOutExpo(float x) { return x <= 0f ? 0f : x >= 1f ? 1f : x < 0.5f ? math.pow(2f, 20f * x - 10f) / 2f : (2f - math.pow(2f, -20f * x + 10f)) / 2f; }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InCirc(float x) { return 1f - math.sqrt(1f - math.pow(x, 2f)); }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float OutCirc(float x) { return math.sqrt(1f - math.pow(x - 1f, 2f)); }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InOutCirc(float x) { return x < 0.5f ? (1f - math.sqrt(1f - math.pow(2f * x, 2f))) / 2f : (math.sqrt(1f - math.pow(-2f * x + 2f, 2f)) + 1f) / 2f; }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InBack(float x) { return C3 * x * x * x - C1 * x * x; }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float OutBack(float x) { return 1f + C3 * math.pow(x - 1f, 3f) + C1 * math.pow(x - 1f, 2f); }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InOutBack(float x) { return x < 0.5f ? (math.pow(2f * x, 2f) * ((C2 + 1f) * 2f * x - C2)) / 2f : (math.pow(2f * x - 2f, 2f) * ((C2 + 1f) * (x * 2f - 2f) + C2) + 2f) / 2f; }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InElastic(float x) { return x <= 0f ? 0f : x >= 1f ? 1f : -math.pow(2f, 10f * x - 10f) * math.sin((x * 10f - 10.75f) * C4); }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float OutElastic(float x) { return x <= 0f ? 0f : x >= 1f ? 1f : math.pow(2f, -10f * x) * math.sin((x * 10f - 0.75f) * C4) + 1f; }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InOutElastic(float x) { return x <= 0f ? 0f : x >= 1f ? 1f : x < 0.5f ? -(math.pow(2f, 20f * x - 10f) * math.sin((20f * x - 11.125f) * C5)) / 2 : (math.pow(2f, -20f * x + 10f) * math.sin((20f * x - 11.125f) * C5)) / 2f + 1f; }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InBounce(float x) { return 1 - InterpolateOutBounceStatic(1 - x); }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float OutBounce(float x) { return InterpolateOutBounceStatic(x); }
[BurstCompile] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float InOutBounce(float x) { return x < 0.5f ? (1f - InterpolateOutBounceStatic(1f - 2f * x)) / 2f : (1f + InterpolateOutBounceStatic(2f * x - 1f)) / 2f; }

[BurstCompile]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static float InterpolateOutBounceStatic(float x)
{
switch (x)
Expand All @@ -71,6 +73,7 @@ private static float InterpolateOutBounceStatic(float x)
}

[BurstCompile]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Ease(EaseType easeType, float t)
{
return easeType switch
Expand Down
17 changes: 12 additions & 5 deletions Runtime/Math/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
using Unity.Mathematics;
using System.Runtime.CompilerServices;
using Unity.Burst;
using Unity.Mathematics;
using UnityEngine;

namespace DotsTween.Math
{
[BurstCompile]
internal static class Extensions
{
public static float4 ToFloat4(this Color color)
[BurstCompile]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ToFloat4(in this Color color, out float4 f4)
{
return new float4(color.r, color.g, color.b, color.a);
f4 = new float4(color.r, color.g, color.b, color.a);
}

/// <summary>
/// Truncates alpha channel.
/// </summary>
/// <param name="color"></param>
/// <returns></returns>
public static float3 ToFloat3(this Color color)
[BurstCompile]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ToFloat3(in this Color color, out float3 f3)
{
return new float3(color.r, color.g, color.b);
f3 = new float3(color.r, color.g, color.b);
}
}
}
11 changes: 11 additions & 0 deletions Runtime/Static/HDRP/Tween.HDRP.AlphaCutoff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Unity.Entities;
using Unity.Rendering;
using Unity.Transforms;
using System.Runtime.CompilerServices;

namespace DotsTween
{
Expand All @@ -15,6 +16,7 @@ public static partial class HDRP
public static class AlphaCutoff
{
[BurstCompile]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint FromTo(ref SystemState state, in Entity entity, in float start, in float end, in float duration, in TweenParams tweenParams = default)
{
var command = new TweenHDRPAlphaCutoffCommand(entity, start, end, duration, tweenParams);
Expand All @@ -23,6 +25,7 @@ public static uint FromTo(ref SystemState state, in Entity entity, in float star
}

[BurstCompile]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint FromTo(ref EntityCommandBuffer ecb, in Entity entity, in float start, in float end, in float duration, in TweenParams tweenParams = default)
{
var command = new TweenHDRPAlphaCutoffCommand(entity, start, end, duration, tweenParams);
Expand All @@ -31,6 +34,7 @@ public static uint FromTo(ref EntityCommandBuffer ecb, in Entity entity, in floa
}

[BurstCompile]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint FromTo(ref EntityCommandBuffer.ParallelWriter ecb, in int sortKey, in Entity entity, in float start, in float end, in float duration, in TweenParams tweenParams = default)
{
var command = new TweenHDRPAlphaCutoffCommand(entity, start, end, duration, tweenParams);
Expand All @@ -39,48 +43,55 @@ public static uint FromTo(ref EntityCommandBuffer.ParallelWriter ecb, in int sor
}

[BurstCompile]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint To(ref SystemState state, in Entity entity, in float end, in float duration, in TweenParams tweenParams = default)
{
GetCurrentValue(out var start, ref state, entity);
return FromTo(ref state, entity, start, end, duration, tweenParams);
}

[BurstCompile]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint To(ref SystemState state, ref EntityCommandBuffer ecb, in Entity entity, in float end, in float duration, in TweenParams tweenParams = default)
{
GetCurrentValue(out var start, ref state, entity);
return FromTo(ref ecb, entity, start, end, duration, tweenParams);
}

[BurstCompile]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint To(ref SystemState state, ref EntityCommandBuffer.ParallelWriter ecb, in int sortKey, in Entity entity, in float end, in float duration, in TweenParams tweenParams = default)
{
GetCurrentValue(out var start, ref state, entity);
return FromTo(ref ecb, sortKey, entity, start, end, duration, tweenParams);
}

[BurstCompile]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint From(ref SystemState state, in Entity entity, in float start, in float duration, in TweenParams tweenParams = default)
{
GetCurrentValue(out var end, ref state, entity);
return FromTo(ref state, entity, start, end, duration, tweenParams);
}

[BurstCompile]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint From(ref SystemState state, ref EntityCommandBuffer ecb, in Entity entity, in float start, in float duration, in TweenParams tweenParams = default)
{
GetCurrentValue(out var end, ref state, entity);
return FromTo(ref ecb, entity, start, end, duration, tweenParams);
}

[BurstCompile]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint From(ref SystemState state, ref EntityCommandBuffer.ParallelWriter ecb, in int sortKey, in Entity entity, in float start, in float duration, in TweenParams tweenParams = default)
{
GetCurrentValue(out var end, ref state, entity);
return FromTo(ref ecb, sortKey, entity, start, end, duration, tweenParams);
}

[BurstCompile]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void GetCurrentValue(out float currentValue, ref SystemState state, in Entity entity)
{
currentValue = state.EntityManager.GetComponentData<HDRPMaterialPropertyAlphaCutoff>(entity).Value;
Expand Down
Loading

0 comments on commit 3ad88c9

Please sign in to comment.