Some Cleanups

This commit is contained in:
hondacrx
2021-06-07 18:06:16 -04:00
parent cb7640e3c6
commit 302a1f293c
53 changed files with 382 additions and 477 deletions
@@ -67,7 +67,7 @@ namespace Game.Movement
if (!nodes.Empty())
{
TaxiPathNodeRecord start = nodes[0];
TaxiPathNodeRecord end = nodes[nodes.Length - 1];
TaxiPathNodeRecord end = nodes[^1];
bool passedPreviousSegmentProximityCheck = false;
for (uint i = 0; i < nodes.Length; ++i)
{
@@ -83,7 +83,7 @@ namespace Game.Movement
else
{
_path.RemoveAt(_path.Count - 1);
_pointsForPathSwitch[_pointsForPathSwitch.Count - 1].PathIndex -= 1;
_pointsForPathSwitch[^1].PathIndex -= 1;
}
}
}
@@ -468,7 +468,7 @@ namespace Game.Movement
{
float[] pathPoints = new float[74 * 3];
int pointCount = 0;
uint dtResult = Detour.DT_FAILURE;
uint dtResult;
if (_straightLine)
{
@@ -556,7 +556,7 @@ namespace Game.Movement
if (Dist3DSqr(GetActualEndPosition(), GetEndPosition()) < 0.3f * Dist3DSqr(GetStartPosition(), GetEndPosition()))
{
SetActualEndPosition(GetEndPosition());
_pathPoints[_pathPoints.Length - 1] = GetEndPosition();
_pathPoints[^1] = GetEndPosition();
}
else
{
@@ -636,7 +636,7 @@ namespace Game.Movement
Span<float> span = steerPath;
// Stop at Off-Mesh link or when point is further than slop away.
if ((steerPathFlags[ns].HasAnyFlag((byte)Detour.dtStraightPathFlags.DT_STRAIGHTPATH_OFFMESH_CONNECTION) ||
!InRangeYZX(span.Slice((int)ns * 3).ToArray(), startPos, minTargetDist, 1000.0f)))
!InRangeYZX(span[((int)ns * 3)..].ToArray(), startPos, minTargetDist, 1000.0f)))
break;
ns++;
}
@@ -678,11 +678,7 @@ namespace Game.Movement
while (npolys != 0 && nsmoothPath < maxSmoothPathSize)
{
// Find location to steer towards.
float[] steerPos;
Detour.dtStraightPathFlags steerPosFlag;
ulong steerPosRef = 0;
if (!GetSteerTarget(iterPos, targetPos, 0.3f, polys, npolys, out steerPos, out steerPosFlag, out steerPosRef))
if (!GetSteerTarget(iterPos, targetPos, 0.3f, polys, npolys, out float[] steerPos, out Detour.dtStraightPathFlags steerPosFlag, out ulong steerPosRef))
break;
bool endOfPath = steerPosFlag.HasAnyFlag(Detour.dtStraightPathFlags.DT_STRAIGHTPATH_END);
@@ -57,7 +57,7 @@ namespace Game.Movement
return (uint)init.Launch();
}
void SendSplineFor(Unit me, int index, uint toNext)
void SendSplineFor(Unit me, int index, ref uint toNext)
{
Cypher.Assert(index < _chainSize);
Log.outDebug(LogFilter.Movement, "{0}: Sending spline for {1}.", me.GetGUID().ToString(), index);
@@ -90,7 +90,7 @@ namespace Game.Movement
_nextFirstWP = (byte)(thisLink.Points.Count - 1);
}
Span<Vector3> span = thisLink.Points.ToArray();
SendPathSpline(me, span.Slice(_nextFirstWP - 1));
SendPathSpline(me, span[(_nextFirstWP - 1)..]);
Log.outDebug(LogFilter.Movement, "{0}: Resumed spline chain generator from resume state.", me.GetGUID().ToString());
++_nextIndex;
if (_nextIndex >= _chainSize)
@@ -102,7 +102,7 @@ namespace Game.Movement
else
{
_msToNext = Math.Max(_chain[_nextIndex].TimeToNext, 1u);
SendSplineFor(me, _nextIndex, _msToNext);
SendSplineFor(me, _nextIndex, ref _msToNext);
++_nextIndex;
if (_nextIndex >= _chainSize)
_msToNext = 0;
@@ -141,7 +141,7 @@ namespace Game.Movement
// Send next spline
Log.outDebug(LogFilter.Movement, "{0}: Should send spline {1} ({2} ms late).", me.GetGUID().ToString(), _nextIndex, diff - _msToNext);
_msToNext = Math.Max(_chain[_nextIndex].TimeToNext, 1u);
SendSplineFor(me, _nextIndex, _msToNext);
SendSplineFor(me, _nextIndex, ref _msToNext);
++_nextIndex;
if (_nextIndex >= _chainSize)
{
@@ -228,7 +228,7 @@ namespace Game.Movement
init.Launch();
// inform formation
creature.SignalFormationMovement(formationDest, waypoint.id, waypoint.moveType, (waypoint.orientation != 0 && waypoint.delay != 0) ? true : false);
creature.SignalFormationMovement(formationDest, waypoint.id, waypoint.moveType, (waypoint.orientation != 0 && waypoint.delay != 0));
return true;
}
@@ -307,7 +307,7 @@ namespace Game.Movement
public override void Pause(uint timer = 0)
{
_stalled = timer != 0 ? false : true;
_stalled = timer == 0;
_nextMoveTime.Reset(timer != 0 ? (int)timer : 1);
}
+3 -3
View File
@@ -113,7 +113,7 @@ namespace Game.Movement
{
int point = point_Idx_offset + point_Idx - spline.First() + (Finalized() ? 1 : 0);
if (IsCyclic())
point = point % (spline.Last() - spline.First());
point %= (spline.Last() - spline.First());
return point;
}
@@ -164,7 +164,7 @@ namespace Game.Movement
}
if (splineflags.HasFlag(SplineFlag.Backward))
orientation = orientation - (float)Math.PI;
orientation -= (float)Math.PI;
}
return new Vector4(c.X, c.Y, c.Z, orientation);
@@ -274,7 +274,7 @@ namespace Game.Movement
if (spline.IsCyclic())
{
point_Idx = spline.First();
time_passed = time_passed % Duration();
time_passed %= Duration();
result = UpdateResult.NextCycle;
}
else
+9 -8
View File
@@ -64,13 +64,13 @@ namespace Game.Movement
void EvaluateCatmullRom(int index, float t, out Vector3 result)
{
Span<Vector3> span = points;
C_Evaluate(span.Slice(index - 1), t, s_catmullRomCoeffs, out result);
C_Evaluate(span[(index - 1)..], t, s_catmullRomCoeffs, out result);
}
void EvaluateBezier3(int index, float t, out Vector3 result)
{
index *= (int)3u;
Span<Vector3> span = points;
C_Evaluate(span.Slice(index), t, s_Bezier3Coeffs, out result);
C_Evaluate(span[index..], t, s_Bezier3Coeffs, out result);
}
#endregion
@@ -192,13 +192,13 @@ namespace Game.Movement
void EvaluateDerivativeCatmullRom(int index, float t, out Vector3 result)
{
Span<Vector3> span = points;
C_Evaluate_Derivative(span.Slice(index - 1), t, s_catmullRomCoeffs, out result);
C_Evaluate_Derivative(span[(index - 1)..], t, s_catmullRomCoeffs, out result);
}
void EvaluateDerivativeBezier3(int index, float t, out Vector3 result)
{
index *= (int)3u;
Span<Vector3> span = points;
C_Evaluate_Derivative(span.Slice(index), t, s_Bezier3Coeffs, out result);
C_Evaluate_Derivative(span[index..], t, s_Bezier3Coeffs, out result);
}
#endregion
@@ -225,7 +225,7 @@ namespace Game.Movement
{
Vector3 nextPos;
Span<Vector3> p = points.AsSpan(index - 1);
Vector3 curPos = nextPos = p[1];
Vector3 curPos = p[1];
int i = 1;
double length = 0;
@@ -329,7 +329,8 @@ namespace Game.Movement
{
int i = index_lo;
Array.Resize(ref lengths, index_hi+1);
int prev_length = 0, new_length = 0;
int prev_length;
int new_length;
while (i < index_hi)
{
new_length = cacher.SetGetTime(this, i);
@@ -355,8 +356,8 @@ namespace Game.Movement
public bool Empty() { return index_lo == index_hi;}
int[] lengths = new int[0];
Vector3[] points = new Vector3[0];
int[] lengths = Array.Empty<int>();
Vector3[] points = Array.Empty<Vector3>();
public EvaluationMode m_mode;
bool _cyclic;
int index_lo;