Core/Movement: Spline code cleanup

Port From (https://github.com/TrinityCore/TrinityCore/commit/e02e8a474244c229cc34c4efb987e24b6dd417f5)
This commit is contained in:
Hondacrx
2025-08-18 11:03:03 -04:00
parent 6995976f3c
commit 5f6329665a
3 changed files with 63 additions and 72 deletions
+36 -31
View File
@@ -77,17 +77,17 @@ namespace Game.Movement
void InitSpline(MoveSplineInitArgs args)
{
EvaluationMode[] modes = new EvaluationMode[2] { EvaluationMode.Linear, EvaluationMode.Catmullrom };
EvaluationMode mode = args.flags.IsSmooth() ? EvaluationMode.Catmullrom : EvaluationMode.Linear;
if (args.flags.HasFlag(MoveSplineFlagEnum.Cyclic))
{
int cyclic_point = 0;
if (splineflags.HasFlag(MoveSplineFlagEnum.EnterCycle))
cyclic_point = 1; // shouldn't be modified, came from client
spline.InitCyclicSpline(args.path.ToArray(), args.path.Count, modes[Convert.ToInt32(args.flags.IsSmooth())], cyclic_point, args.initialOrientation);
spline.InitCyclicSpline(args.path.ToArray(), args.path.Count, mode, cyclic_point, args.initialOrientation);
}
else
{
spline.InitSpline(args.path.ToArray(), args.path.Count, modes[Convert.ToInt32(args.flags.IsSmooth())], args.initialOrientation);
spline.InitSpline(args.path.ToArray(), args.path.Count, mode, args.initialOrientation);
}
// init spline timestamps
@@ -290,34 +290,7 @@ namespace Game.Movement
if (splineflags.HasFlag(MoveSplineFlagEnum.EnterCycle))
{
splineflags.SetUnsetFlag(MoveSplineFlagEnum.EnterCycle, false);
MoveSplineInitArgs args = new(spline.GetPointCount());
args.path.AddRange(spline.GetPoints().AsSpan().Slice(spline.First() + 1, spline.Last()).ToArray());
args.facing = facing;
args.flags = splineflags;
args.path_Idx_offset = point_Idx_offset;
// MoveSplineFlag::Parabolic | MoveSplineFlag::Animation not supported currently
//args.parabolic_amplitude = ?;
//args.time_perc = ?;
args.splineId = m_Id;
args.initialOrientation = initialOrientation;
args.velocity = 1.0f; // Calculated below
args.HasVelocity = true;
args.TransformForTransport = onTransport;
if (args.Validate(null))
{
// New cycle should preserve previous cycle's duration for some weird reason, even though
// the path is really different now. Blizzard is weird. Or this was just a simple oversight.
// Since our splines precalculate length with velocity in mind, if we want to find the desired
// velocity, we have to make a fake spline, calculate its duration and then compare it to the
// desired duration, thus finding out how much the velocity has to be increased for them to match.
MoveSpline tempSpline = new();
tempSpline.Initialize(args);
args.velocity = (float)tempSpline.Duration() / Duration();
if (args.Validate(null))
InitSpline(args);
}
reinit_spline_for_next_cycle();
}
}
else
@@ -331,6 +304,38 @@ namespace Game.Movement
return result;
}
void reinit_spline_for_next_cycle()
{
MoveSplineInitArgs args = new(spline.GetPointCount());
args.path.AddRange(spline.GetPoints().AsSpan().Slice(spline.First() + 1, spline.Last()).ToArray());
args.facing = facing;
args.flags = splineflags;
args.path_Idx_offset = point_Idx_offset;
// MoveSplineFlag::Parabolic | MoveSplineFlag::Animation not supported currently
//args.parabolic_amplitude = ?;
//args.time_perc = ?;
args.splineId = m_Id;
args.initialOrientation = initialOrientation;
args.velocity = 1.0f; // Calculated below
args.HasVelocity = true;
args.TransformForTransport = onTransport;
if (args.Validate(null))
{
// New cycle should preserve previous cycle's duration for some weird reason, even though
// the path is really different now. Blizzard is weird. Or this was just a simple oversight.
// Since our splines precalculate length with velocity in mind, if we want to find the desired
// velocity, we have to make a fake spline, calculate its duration and then compare it to the
// desired duration, thus finding out how much the velocity has to be increased for them to match.
MoveSpline tempSpline = new();
tempSpline.Initialize(args);
args.velocity = (float)tempSpline.Duration() / Duration();
if (args.Validate(null))
InitSpline(args);
}
}
int NextTimestamp() { return spline.Length(point_Idx + 1); }
int SegmentTimeElapsed() { return NextTimestamp() - time_passed; }
public bool IsCyclic() { return splineflags.HasFlag(MoveSplineFlagEnum.Cyclic); }