Core/Transports: Path generation rewrite v2 (needs testing)

Port From (https://github.com/TrinityCore/TrinityCore/commit/a2c1b699e6e4d30c752b65241bc23191920a86fd)
This commit is contained in:
hondacrx
2022-06-14 00:40:57 -04:00
parent 9c015e71fa
commit bbe99e3be8
10 changed files with 544 additions and 527 deletions
+11 -8
View File
@@ -87,7 +87,7 @@ namespace Game.Movement
void InitSpline(MoveSplineInitArgs args)
{
Spline.EvaluationMode[] modes = new Spline.EvaluationMode[2] { Spline.EvaluationMode.Linear, Spline.EvaluationMode.Catmullrom };
EvaluationMode[] modes = new EvaluationMode[2] { EvaluationMode.Linear, EvaluationMode.Catmullrom };
if (args.flags.HasFlag(SplineFlag.Cyclic))
{
int cyclic_point = 0;
@@ -351,7 +351,7 @@ namespace Game.Movement
#region Fields
public MoveSplineInitArgs InitArgs;
public Spline spline = new();
public Spline<int> spline = new();
public FacingInfo facing;
public MoveSplineFlag splineflags = new();
public bool onTransport;
@@ -368,7 +368,7 @@ namespace Game.Movement
public AnimTierTransition anim_tier;
#endregion
public class CommonInitializer : IInitializer
public class CommonInitializer : IInitializer<int>
{
public CommonInitializer(float _velocity)
{
@@ -377,20 +377,23 @@ namespace Game.Movement
}
public float velocityInv;
public int time;
public int SetGetTime(Spline s, int i)
public int Invoke(Spline<int> s, int i)
{
time += (int)(s.SegLength(i) * velocityInv);
return time;
}
}
public class FallInitializer : IInitializer
public class FallInitializer : IInitializer<int>
{
public FallInitializer(float startelevation)
{
startElevation = startelevation;
}
float startElevation;
public int SetGetTime(Spline s, int i)
public int Invoke(Spline<int> s, int i)
{
return (int)(ComputeFallTime(startElevation - s.GetPoint(i + 1).Z, false) * 1000.0f);
}
@@ -427,9 +430,9 @@ namespace Game.Movement
NextSegment = 0x08
}
}
public interface IInitializer
public interface IInitializer<T>
{
int SetGetTime(Spline s, int i);
int Invoke(Spline<T> s, int i);
}
public class SplineChainLink
+29 -27
View File
@@ -23,7 +23,7 @@ using System.Numerics;
namespace Game.Movement
{
public class Spline
public class Spline<T>
{
public int GetPointCount() { return points.Length; }
public Vector3 GetPoint(int i) { return points[i]; }
@@ -262,18 +262,18 @@ namespace Game.Movement
}
#endregion
void set_steps_per_segment(int newStepsPerSegment) { stepsPerSegment = newStepsPerSegment; }
public void set_steps_per_segment(int newStepsPerSegment) { stepsPerSegment = newStepsPerSegment; }
public void ComputeIndex(float t, ref int index, ref float u)
{
//ASSERT(t >= 0.f && t <= 1.f);
int length_ = (int)(t * Length());
T length_ = t * (dynamic)Length();
index = ComputeIndexInBounds(length_);
//ASSERT(index < index_hi);
u = (length_ - Length(index)) / (float)Length(index, index + 1);
}
int ComputeIndexInBounds(int length_)
int ComputeIndexInBounds(T length_)
{
// Temporary disabled: causes infinite loop with t = 1.f
/*
@@ -294,11 +294,12 @@ namespace Game.Movement
int i = index_lo;
int N = index_hi;
while (i + 1 < N && lengths[i + 1] < length_)
while (i + 1 < N && (dynamic)lengths[i + 1] < length_)
++i;
return i;
}
private static readonly Matrix4x4 s_catmullRomCoeffs = new(-0.5f, 1.5f, -1.5f, 0.5f, 1.0f, -2.5f, 2.0f, -0.5f, -0.5f, 0.0f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);
private static readonly Matrix4x4 s_Bezier3Coeffs = new(-1.0f, 3.0f, -3.0f, 1.0f, 3.0f, -6.0f, 3.0f, 0.0f, -3.0f, 3.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f);
@@ -320,31 +321,31 @@ namespace Game.Movement
+ vertice[2] * weights.Z + vertice[3] * weights.W;
}
public int Length()
public dynamic Length()
{
if (lengths.Length == 0)
return 0;
return default;
return lengths[index_hi];
}
public int Length(int first, int last) { return lengths[last] - lengths[first]; }
public dynamic Length(int first, int last) { return lengths[last] - (dynamic)lengths[first]; }
public int Length(int Idx) { return lengths[Idx]; }
public dynamic Length(int Idx) { return lengths[Idx]; }
public void Set_length(int i, int length) { lengths[i] = length; }
public void Set_length(int i, T length) { lengths[i] = length; }
public void InitLengths(IInitializer cacher)
public void InitLengths(IInitializer<T> cacher)
{
int i = index_lo;
Array.Resize(ref lengths, index_hi+1);
int prev_length;
int new_length;
T prev_length;
T new_length;
while (i < index_hi)
{
new_length = cacher.SetGetTime(this, i);
if (new_length < 0)
new_length = int.MaxValue;
new_length = (dynamic)cacher.Invoke(this, i);
if ((dynamic)new_length < 0)// todo fix me this is a ulgy hack.
new_length = (dynamic)(Type.GetTypeCode(typeof(T)) == TypeCode.Int32 ? int.MaxValue : double.MaxValue);
lengths[++i] = new_length;
prev_length = new_length;
@@ -354,18 +355,18 @@ namespace Game.Movement
public void InitLengths()
{
int i = index_lo;
int length = 0;
dynamic length = default(T);
Array.Resize(ref lengths, index_hi + 1);
while (i < index_hi)
{
length += (int)SegLength(i);
length += SegLength(i);
lengths[++i] = length;
}
}
public bool Empty() { return index_lo == index_hi;}
int[] lengths = Array.Empty<int>();
T[] lengths = Array.Empty<T>();
Vector3[] points = Array.Empty<Vector3>();
public EvaluationMode m_mode;
bool _cyclic;
@@ -379,14 +380,6 @@ namespace Game.Movement
int index_lo;
int index_hi;
public enum EvaluationMode
{
Linear,
Catmullrom,
Bezier3_Unused,
UninitializedMode,
ModesEnd
}
}
public class FacingInfo
@@ -396,4 +389,13 @@ namespace Game.Movement
public float angle;
public MonsterMoveType type;
}
public enum EvaluationMode
{
Linear,
Catmullrom,
Bezier3_Unused,
UninitializedMode,
ModesEnd
}
}