Prune and clean up code.

This commit is contained in:
2023-04-04 20:48:17 +08:00
parent a013d59379
commit c98536e8ab
12 changed files with 23 additions and 377 deletions

View File

@@ -7,6 +7,7 @@ using System.Text.RegularExpressions;
using UnityEngine;
namespace Cryville.Crtr {
[Obsolete]
public enum TransitionType : byte {
In = 0,
Out = 1,
@@ -22,6 +23,7 @@ namespace Cryville.Crtr {
Bounce = 24,
}
[Obsolete]
public static class MotionLerper {
public static void Lerp<T>(double time, double tt, T tv, double ft, T fv, TransitionType type, float rate, ref T result) where T : Vector {
if (fv == null) fv = (T)ReflectionHelper.InvokeEmptyConstructor(tv.GetType());
@@ -35,19 +37,6 @@ namespace Cryville.Crtr {
to.LerpWith(from, GetEaseTime(scaledTime, type, rate), ref r);
}
public static double Delerp<T>(T value, double tt, T tv, double ft, T fv, TransitionType type, float rate) where T : Vector {
if (fv == null) fv = (T)ReflectionHelper.InvokeEmptyConstructor(tv.GetType());
var t = Delerp(value, fv, tv, type, rate);
return ft * (1 - t) + tt * t;
}
public static float Delerp<T>(T value, T from, T to, TransitionType type, float rate) where T : Vector {
if (value.CompareTo(to) >= 0) return 1;
if (value.CompareTo(from) < 0) return 0;
float lerpedTime = to.DelerpWith(from, value);
return GetUneaseTime(lerpedTime, type, rate);
}
public static float GetEaseTime(float time, TransitionType type, float rate) {
switch ((byte)type & 3) {
case (byte)TransitionType.In:
@@ -67,25 +56,6 @@ namespace Cryville.Crtr {
}
}
static float GetUneaseTime(float time, TransitionType type, float rate) {
switch ((byte)type & 3) {
case (byte)TransitionType.In:
return 1 - GetUneaseOutTime(1 - time, type, rate);
case (byte)TransitionType.Out:
return GetUneaseOutTime(time, type, rate);
case (byte)TransitionType.InOut:
time *= 2;
if (time <= 1) return (1 - GetUneaseOutTime(1 - time, type, rate)) / 2;
else return (GetUneaseOutTime(time - 1, type, rate) + 1) / 2;
case (byte)TransitionType.OutIn:
time *= 2;
if (time <= 1) return GetUneaseOutTime(time, type, rate) / 2;
else return (2 - GetUneaseOutTime(2 - time, type, rate)) / 2;
default:
throw new ArgumentException("Unknown transition");
}
}
static float GetEaseOutTime(float p, TransitionType type, float rate) {
switch ((byte)type & 252) {
case (byte)TransitionType.Ease:
@@ -123,21 +93,6 @@ namespace Cryville.Crtr {
throw new ArgumentException("Unknown transition");
}
}
static float GetUneaseOutTime(float p, TransitionType type, float rate) {
switch ((byte)type & 252) {
case (byte)TransitionType.Ease:
return 1 - Mathf.Pow(1 - p, 1 / rate);
case (byte)TransitionType.Sine:
return Mathf.Asin(p) / (Mathf.PI / 2);
case (byte)TransitionType.Expo:
return -Mathf.Log(1 - p, 2) / 10;
case (byte)TransitionType.Circ:
return 1 - Mathf.Sqrt(1 - p * p);
default:
throw new ArgumentException("Unknown transition");
}
}
}
public struct MotionRegistry {
@@ -229,7 +184,7 @@ namespace Cryville.Crtr {
public MotionNode QueryRelativeNode(ushort id) {
int i = RelativeNodes.FindIndex(n => n.Id == id);
MotionNode cnode;
if (i == -1) cnode = new MotionNode() { Id = id };
if (i == -1) cnode = new MotionNode { Id = id };
else cnode = RelativeNodes[i];
return cnode;
}
@@ -238,7 +193,7 @@ namespace Cryville.Crtr {
int i = RelativeNodes.FindIndex(n => n.Id == node.Id);
MotionNode cnode;
if (i == -1) {
cnode = new MotionNode() {
cnode = new MotionNode {
Id = node.Id,
Time = new Vec1(0),
Rate = new Vec1(1),
@@ -304,7 +259,9 @@ namespace Cryville.Crtr {
public ushort Id;
public Vec1 Time;
float CmpTime { get { return Time != null ? Time.Value : 0; } }
[Obsolete]
public TransitionType? Transition;
[Obsolete]
public Vec1 Rate;
public Vector Value;