Remove motion lerper. Reconstruct RMV and motion node. Add motion node pool.

This commit is contained in:
2023-04-19 13:48:06 +08:00
parent a5439430fb
commit 659f2165ff
3 changed files with 94 additions and 209 deletions

View File

@@ -1,5 +1,3 @@
//#define DISABLE_CACHE
using Cryville.Common;
using Cryville.Common.Buffers;
using Cryville.Common.Collections.Specialized;
@@ -248,32 +246,26 @@ namespace Cryville.Crtr.Event {
Children[c].InvalidateMotion(name);
}
public Vector GetRawValue(int key) {
public Vector GetComputedValue(int key) {
MotionCache tr;
if (!CachedValues.TryGetValue(key, out tr))
CachedValues.Add(key, tr = _mcpa.Rent(key));
Vector r = tr.Value;
#if !DISABLE_CACHE
if (tr.Valid) return r;
#endif
float reltime = 0;
if (rootPrototype != null) reltime = (float)(Time - rootPrototype.Time);
GetMotionValue(key).GetValue(reltime, ref r);
if (Parent != null) r.ApplyFrom(Parent.GetRawValue(key));
#if !DISABLE_CACHE
GetMotionValue(key).Compute(ref r);
if (Parent != null) r.ApplyFrom(Parent.GetComputedValue(key));
tr.Valid = true;
#endif
return r;
}
public T GetRawValue<T>(int key) where T : Vector {
return (T)GetRawValue(key);
public T GetComputedValue<T>(int key) where T : Vector {
return (T)GetComputedValue(key);
}
static readonly int n_pt = IdentifierManager.SharedInstance.Request("pt");
public Vector2 ScreenPoint {
get {
var mv = GetRawValue<Vec2>(n_pt);
var mv = GetComputedValue<Vec2>(n_pt);
return mv.ToVector2();
}
}
@@ -281,7 +273,7 @@ namespace Cryville.Crtr.Event {
static readonly int n_dir = IdentifierManager.SharedInstance.Request("dir");
public Vector3 Direction {
get {
Vec3 r = GetRawValue<Vec3>(n_dir);
Vec3 r = GetComputedValue<Vec3>(n_dir);
return r.ToVector3();
}
}
@@ -289,7 +281,7 @@ namespace Cryville.Crtr.Event {
static readonly int n_normal = IdentifierManager.SharedInstance.Request("normal");
public Vector3 Normal {
get {
Vec3 r = GetRawValue<Vec3>(n_normal);
Vec3 r = GetComputedValue<Vec3>(n_normal);
return r.ToVector3();
}
}
@@ -304,21 +296,21 @@ namespace Cryville.Crtr.Event {
static readonly int n_svm = IdentifierManager.SharedInstance.Request("svm");
public float ScrollVelocity {
get {
return GetRawValue<Vec1>(n_sv).Value * GetRawValue<Vec1m>(n_svm).Value;
return GetComputedValue<Vec1>(n_sv).Value * GetComputedValue<Vec1m>(n_svm).Value;
}
}
static readonly int n_dist = IdentifierManager.SharedInstance.Request("dist");
public float Distance {
get {
return GetRawValue<Vec1>(n_dist).Value;
return GetComputedValue<Vec1>(n_dist).Value;
}
}
static readonly int n_track = IdentifierManager.SharedInstance.Request("track");
public float Track {
get {
return GetRawValue<Vec1>(n_track).Value;
return GetComputedValue<Vec1>(n_track).Value;
}
}
#endregion
@@ -403,7 +395,6 @@ namespace Cryville.Crtr.Event {
}
else {
var scaledTime = (float)((Time - m.Key.Time - ChartPlayer.actualRenderStep * tev.sumfix) / m.Key.Duration);
var lerpedTime = MotionLerper.GetEaseTime(scaledTime, TransitionType.Ease, 1);
if (tev.Node.Id >= 0) {
var start = m.Value.GetRelativeNode(tev.Node.Id);
if (start == null) {
@@ -412,11 +403,12 @@ namespace Cryville.Crtr.Event {
else {
var target = value.GetRelativeNode(tev.Node.Id);
if (target == null) value.SetRelativeNode(tev.Node);
else tev.Node.LerpWith(m.Value.GetRelativeNode(tev.Node.Id), lerpedTime, ref target);
else tev.Node.LerpWith(m.Value.GetRelativeNode(tev.Node.Id), scaledTime, ref target);
}
}
else {
tev.Node.Value.LerpWith(m.Value.AbsoluteValue, lerpedTime, ref value.AbsoluteValue);
tev.Node.Value.LerpWith(m.Value.AbsoluteValue, scaledTime, ref value.AbsoluteValue);
}
}
}
}