Core: SOme code cleanup, more to follow.

This commit is contained in:
hondacrx
2021-03-20 22:48:48 -04:00
parent 62f554f2e0
commit 62ec699ec6
318 changed files with 5080 additions and 5125 deletions
@@ -83,7 +83,7 @@ namespace Game.Movement
return true;
}
MoveSplineInit init = new MoveSplineInit(owner);
MoveSplineInit init = new(owner);
init.MovebyPath(_path.GetPath());
init.SetWalk(true);
int traveltime = init.Launch();
@@ -122,7 +122,7 @@ namespace Game.Movement
return;
}
MoveSplineInit init = new MoveSplineInit(owner);
MoveSplineInit init = new(owner);
init.MovebyPath(_path.GetPath());
init.SetWalk(false);
int traveltime = init.Launch();
@@ -126,12 +126,12 @@ namespace Game.Movement
owner.AddUnitState(UnitState.InFlight);
owner.AddUnitFlag(UnitFlags.RemoveClientControl | UnitFlags.TaxiFlight);
MoveSplineInit init = new MoveSplineInit(owner);
MoveSplineInit init = new(owner);
uint end = GetPathAtMapEnd();
init.args.path = new Vector3[end];
for (int i = (int)GetCurrentNode(); i != end; ++i)
{
Vector3 vertice = new Vector3(_path[i].Loc.X, _path[i].Loc.Y, _path[i].Loc.Z);
Vector3 vertice = new(_path[i].Loc.X, _path[i].Loc.Y, _path[i].Loc.Z);
init.args.path[i] = vertice;
}
init.SetFirstPointId((int)GetCurrentNode());
@@ -252,9 +252,9 @@ namespace Game.Movement
uint _endMapId; //! map Id of last node location
uint _preloadTargetNode; //! node index where preloading starts
List<TaxiPathNodeRecord> _path = new List<TaxiPathNodeRecord>();
List<TaxiPathNodeRecord> _path = new();
int _currentNode;
List<TaxiNodeChangeInfo> _pointsForPathSwitch = new List<TaxiNodeChangeInfo>(); //! node indexes and costs where TaxiPath changes
List<TaxiNodeChangeInfo> _pointsForPathSwitch = new(); //! node indexes and costs where TaxiPath changes
class TaxiNodeChangeInfo
{
@@ -44,7 +44,7 @@ namespace Game.Movement
owner.AddUnitState(UnitState.RoamingMove);
MoveSplineInit init = new MoveSplineInit(owner);
MoveSplineInit init = new(owner);
init.MoveTo(_destination.GetPositionX(), _destination.GetPositionY(), _destination.GetPositionZ());
if (_orientation)
init.SetFacing(_destination.GetOrientation());
@@ -96,7 +96,7 @@ namespace Game.Movement
owner.AddUnitState(UnitState.RoamingMove);
MoveSplineInit init = new MoveSplineInit(owner);
MoveSplineInit init = new(owner);
init.MoveTo(_destination.GetPositionX(), _destination.GetPositionY(), _destination.GetPositionZ());
if (_orientation)
init.SetFacing(_destination.GetOrientation());
@@ -59,7 +59,7 @@ namespace Game.AI
return;
}
MoveSplineInit init = new MoveSplineInit(owner);
MoveSplineInit init = new(owner);
float x, y, z, o;
// at apply we can select more nice return points base at current movegen
if (owner.GetMotionMaster().Empty() || !owner.GetMotionMaster().Top().GetResetPosition(owner, out x, out y, out z))
@@ -55,10 +55,10 @@ namespace Game.Movement
if (!GridDefines.IsValidMapCoord(destX, destY, destZ) || !GridDefines.IsValidMapCoord(x, y, z))
return false;
Vector3 dest = new Vector3(destX, destY, destZ);
Vector3 dest = new(destX, destY, destZ);
SetEndPosition(dest);
Vector3 start = new Vector3(x, y, z);
Vector3 start = new(x, y, z);
SetStartPosition(start);
_forceDestination = forceDest;
@@ -477,8 +477,8 @@ namespace Game.Movement
Array.Copy(startPoint, pathPoints, 3); // first point
// path has to be split into polygons with dist SMOOTH_PATH_STEP_SIZE between them
Vector3 startVec = new Vector3(startPoint[0], startPoint[1], startPoint[2]);
Vector3 endVec = new Vector3(endPoint[0], endPoint[1], endPoint[2]);
Vector3 startVec = new(startPoint[0], startPoint[1], startPoint[2]);
Vector3 endVec = new(endPoint[0], endPoint[1], endPoint[2]);
Vector3 diffVec = (endVec - startVec);
Vector3 prevVec = startVec;
float len = diffVec.GetLength();
@@ -976,7 +976,7 @@ namespace Game.Movement
Vector3 _endPosition;
PathType pathType;
Detour.dtQueryFilter _filter = new Detour.dtQueryFilter();
Detour.dtQueryFilter _filter = new();
Detour.dtNavMeshQuery _navMeshQuery;
Detour.dtNavMesh _navMesh;
}
@@ -52,7 +52,7 @@ namespace Game.Movement
owner.AddUnitState(UnitState.RoamingMove);
MoveSplineInit init = new MoveSplineInit(owner);
MoveSplineInit init = new(owner);
init.MoveTo(_destination.GetPositionX(), _destination.GetPositionY(), _destination.GetPositionZ(), _generatePath);
if (_speed > 0.0f)
init.SetVelocity(_speed);
@@ -99,7 +99,7 @@ namespace Game.Movement
owner.AddUnitState(UnitState.RoamingMove);
MoveSplineInit init = new MoveSplineInit(owner);
MoveSplineInit init = new(owner);
init.MoveTo(_destination.GetPositionX(), _destination.GetPositionY(), _destination.GetPositionZ(), _generatePath);
if (_speed > 0.0f) // Default value for point motion type is 0.0, if 0.0 spline will use GetSpeed on unit
init.SetVelocity(_speed);
@@ -92,7 +92,7 @@ namespace Game.Movement
owner.AddUnitState(UnitState.RoamingMove);
Position position = new Position(_reference);
Position position = new(_reference);
float distance = RandomHelper.FRand(0.0f, 1.0f) * _wanderDistance;
float angle = RandomHelper.FRand(0.0f, 1.0f) * MathF.PI * 2.0f;
owner.MovePositionToFirstCollision(ref position, distance, angle);
@@ -110,7 +110,7 @@ namespace Game.Movement
return;
}
MoveSplineInit init = new MoveSplineInit(owner);
MoveSplineInit init = new(owner);
init.MovebyPath(_path.GetPath());
init.SetWalk(true);
int traveltime = init.Launch();
@@ -48,7 +48,7 @@ namespace Game.Movement
{
int numWp = wp.Length;
Cypher.Assert(numWp > 1, "Every path must have source & destination");
MoveSplineInit init = new MoveSplineInit(me);
MoveSplineInit init = new(me);
if (numWp > 2)
init.MovebyPath(wp.ToArray());
else
@@ -174,7 +174,7 @@ namespace Game.Movement
public override MovementGeneratorType GetMovementGeneratorType() { return MovementGeneratorType.SplineChain; }
uint _id;
List<SplineChainLink> _chain = new List<SplineChainLink>();
List<SplineChainLink> _chain = new();
byte _chainSize;
bool _walk;
bool finished;
@@ -201,7 +201,7 @@ namespace Game.Movement
if (owner.IsTypeId(TypeId.Unit))
owner.ToCreature().SetCannotReachTarget(false);
MoveSplineInit init = new MoveSplineInit(owner);
MoveSplineInit init = new(owner);
init.MovebyPath(_path.GetPath());
init.SetWalk(EnableWalking());
// Using the same condition for facing target as the one that is used for SetInFront on movement end
@@ -179,14 +179,14 @@ namespace Game.Movement
Cypher.Assert(_currentNode < _path.nodes.Count, $"WaypointMovementGenerator.StartMove: tried to reference a node id ({_currentNode}) which is not included in path ({_path.id})");
WaypointNode waypoint = _path.nodes.ElementAt(_currentNode);
Position formationDest = new Position(waypoint.x, waypoint.y, waypoint.z, (waypoint.orientation != 0 && waypoint.delay != 0) ? waypoint.orientation : 0.0f);
Position formationDest = new(waypoint.x, waypoint.y, waypoint.z, (waypoint.orientation != 0 && waypoint.delay != 0) ? waypoint.orientation : 0.0f);
_isArrivalDone = false;
_recalculateSpeed = false;
creature.AddUnitState(UnitState.RoamingMove);
MoveSplineInit init = new MoveSplineInit(creature);
MoveSplineInit init = new(creature);
//! If creature is on transport, we assume waypoints set in DB are already transport offsets
if (transportPath)
+14 -14
View File
@@ -29,7 +29,7 @@ namespace Game.Movement
{
public const double gravity = 19.29110527038574;
public const float SPEED_CHARGE = 42.0f;
IdleMovementGenerator staticIdleMovement = new IdleMovementGenerator();
IdleMovementGenerator staticIdleMovement = new();
public MotionMaster(Unit me)
{
@@ -285,7 +285,7 @@ namespace Game.Movement
else
{
// we are already close enough. We just need to turn toward the target without changing position.
MoveSplineInit init = new MoveSplineInit(_owner);
MoveSplineInit init = new(_owner);
init.MoveTo(_owner.GetPositionX(), _owner.GetPositionY(), _owner.GetPositionZMinusOffset());
init.SetFacing(target);
init.Launch();
@@ -298,7 +298,7 @@ namespace Game.Movement
float x, y, z;
pos.GetPosition(out x, out y, out z);
MoveSplineInit init = new MoveSplineInit(_owner);
MoveSplineInit init = new(_owner);
init.MoveTo(x, y, z);
init.SetAnimation(AnimType.ToGround);
init.Launch();
@@ -310,7 +310,7 @@ namespace Game.Movement
float x, y, z;
pos.GetPosition(out x, out y, out z);
MoveSplineInit init = new MoveSplineInit(_owner);
MoveSplineInit init = new(_owner);
init.MoveTo(x, y, z);
init.SetAnimation(AnimType.ToFly);
init.Launch();
@@ -335,7 +335,7 @@ namespace Game.Movement
MoveCharge(dest.X, dest.Y, dest.Z, SPEED_CHARGE, EventId.ChargePrepath);
// Charge movement is not started when using EVENT_CHARGE_PREPATH
MoveSplineInit init = new MoveSplineInit(_owner);
MoveSplineInit init = new(_owner);
init.MovebyPath(path.GetPath());
init.SetVelocity(speed);
if (target != null)
@@ -361,7 +361,7 @@ namespace Game.Movement
_owner.GetNearPoint(_owner, out x, out y, out z, _owner.GetCombatReach(), dist, _owner.GetAngle(srcX, srcY) + MathFunctions.PI);
MoveSplineInit init = new MoveSplineInit(_owner);
MoveSplineInit init = new(_owner);
init.MoveTo(x, y, z);
init.SetParabolic(max_height, 0);
init.SetOrientationFixed(true);
@@ -402,7 +402,7 @@ namespace Game.Movement
float moveTimeHalf = (float)(speedZ / gravity);
float max_height = -MoveSpline.ComputeFallElevation(moveTimeHalf, false, -speedZ);
MoveSplineInit init = new MoveSplineInit(_owner);
MoveSplineInit init = new(_owner);
init.MoveTo(x, y, z, false);
init.SetParabolic(max_height, 0);
init.SetVelocity(speedXY);
@@ -426,14 +426,14 @@ namespace Game.Movement
public void MoveCirclePath(float x, float y, float z, float radius, bool clockwise, byte stepCount)
{
float step = 2 * MathFunctions.PI / stepCount * (clockwise ? -1.0f : 1.0f);
Position pos = new Position(x, y, z, 0.0f);
Position pos = new(x, y, z, 0.0f);
float angle = pos.GetAngle(_owner.GetPositionX(), _owner.GetPositionY());
MoveSplineInit init = new MoveSplineInit(_owner);
MoveSplineInit init = new(_owner);
init.args.path = new Vector3[stepCount];
for (byte i = 0; i < stepCount; angle += step, ++i)
{
Vector3 point = new Vector3();
Vector3 point = new();
point.X = (float)(x + radius * Math.Cos(angle));
point.Y = (float)(y + radius * Math.Sin(angle));
@@ -462,7 +462,7 @@ namespace Game.Movement
void MoveSmoothPath(uint pointId, Vector3[] pathPoints, int pathSize, bool walk = false, bool fly = false)
{
MoveSplineInit init = new MoveSplineInit(_owner);
MoveSplineInit init = new(_owner);
if (fly)
{
init.SetFly();
@@ -535,7 +535,7 @@ namespace Game.Movement
return;
}
MoveSplineInit init = new MoveSplineInit(_owner);
MoveSplineInit init = new(_owner);
init.MoveTo(_owner.GetPositionX(), _owner.GetPositionY(), tz, false);
init.SetFall();
init.Launch();
@@ -570,7 +570,7 @@ namespace Game.Movement
if (path < CliDB.TaxiPathNodesByPath.Count)
{
Log.outDebug(LogFilter.Server, "{0} taxi to (Path {1} node {2})", _owner.GetName(), path, pathnode);
FlightPathMovementGenerator mgen = new FlightPathMovementGenerator();
FlightPathMovementGenerator mgen = new();
mgen.LoadPath(_owner.ToPlayer());
StartMovement(mgen, MovementSlot.Controlled);
}
@@ -825,7 +825,7 @@ namespace Game.Movement
MMCleanFlag _cleanFlag;
bool[] _initialize = new bool[(int)MovementSlot.Max];
int _top;
List<IMovementGenerator> _expireList = new List<IMovementGenerator>();
List<IMovementGenerator> _expireList = new();
}
public class JumpArrivalCastArgs
+6 -6
View File
@@ -91,12 +91,12 @@ namespace Game.Movement
// init spline timestamps
if (splineflags.HasFlag(SplineFlag.Falling))
{
FallInitializer init = new FallInitializer(spline.GetPoint(spline.First()).Z);
FallInitializer init = new(spline.GetPoint(spline.First()).Z);
spline.InitLengths(init);
}
else
{
CommonInitializer init = new CommonInitializer(args.velocity);
CommonInitializer init = new(args.velocity);
spline.InitLengths(init);
}
@@ -297,9 +297,9 @@ namespace Game.Movement
#region Fields
public MoveSplineInitArgs InitArgs;
public Spline spline = new Spline();
public Spline spline = new();
public FacingInfo facing;
public MoveSplineFlag splineflags = new MoveSplineFlag();
public MoveSplineFlag splineflags = new();
public bool onTransport;
public bool splineIsFacingOnly;
public uint m_Id;
@@ -392,7 +392,7 @@ namespace Game.Movement
TimeToNext = msToNext;
}
public List<Vector3> Points = new List<Vector3>();
public List<Vector3> Points = new();
public uint ExpectedDuration;
public uint TimeToNext;
}
@@ -414,7 +414,7 @@ namespace Game.Movement
public void Clear() { Chain.Clear(); }
public uint PointID;
public List<SplineChainLink> Chain = new List<SplineChainLink>();
public List<SplineChainLink> Chain = new();
public bool IsWalkMode;
public byte SplineIndex;
public byte PointIndex;
+9 -9
View File
@@ -73,7 +73,7 @@ namespace Game.Movement
MoveSpline move_spline = unit.MoveSpline;
bool transport = !unit.GetTransGUID().IsEmpty();
Vector4 real_position = new Vector4();
Vector4 real_position = new();
// there is a big chance that current position is unknown if current state is not finalized, need compute it
// this also allows calculate spline position and update map position in much greater intervals
// Don't compute for transport movement if the unit is in a motion between two transports
@@ -130,7 +130,7 @@ namespace Game.Movement
unit.m_movementInfo.SetMovementFlags(moveFlags);
move_spline.Initialize(args);
MonsterMove packet = new MonsterMove();
MonsterMove packet = new();
packet.MoverGUID = unit.GetGUID();
packet.Pos = new Vector3(real_position.X, real_position.Y, real_position.Z);
packet.InitializeSplineData(move_spline);
@@ -153,7 +153,7 @@ namespace Game.Movement
return;
bool transport = !unit.GetTransGUID().IsEmpty();
Vector4 loc = new Vector4();
Vector4 loc = new();
if (move_spline.onTransport == transport)
loc = move_spline.ComputePosition();
else
@@ -175,7 +175,7 @@ namespace Game.Movement
move_spline.onTransport = transport;
move_spline.Initialize(args);
MonsterMove packet = new MonsterMove();
MonsterMove packet = new();
packet.MoverGUID = unit.GetGUID();
packet.Pos = new Vector3(loc.X, loc.Y, loc.Z);
packet.SplineData.StopDistanceTolerance = 2;
@@ -217,7 +217,7 @@ namespace Game.Movement
{
if (generatePath)
{
PathGenerator path = new PathGenerator(unit);
PathGenerator path = new(unit);
bool result = path.CalculatePath(dest.X, dest.Y, dest.Z, forceDestination);
if (result && !Convert.ToBoolean(path.GetPathType() & PathType.NoPath))
{
@@ -228,7 +228,7 @@ namespace Game.Movement
args.path_Idx_offset = 0;
args.path = new Vector3[2];
TransportPathTransform transform = new TransportPathTransform(unit, args.TransformForTransport);
TransportPathTransform transform = new(unit, args.TransformForTransport);
args.path[1] = transform.Calc(dest);
}
@@ -264,7 +264,7 @@ namespace Game.Movement
{
args.path_Idx_offset = path_offset;
args.path = new Vector3[controls.Length];
TransportPathTransform transform = new TransportPathTransform(unit, args.TransformForTransport);
TransportPathTransform transform = new(unit, args.TransformForTransport);
for (var i = 0; i < controls.Length; i++)
args.path[i] = transform.Calc(controls[i]);
@@ -292,7 +292,7 @@ namespace Game.Movement
public void SetFacing(Vector3 spot)
{
TransportPathTransform transform = new TransportPathTransform(unit, args.TransformForTransport);
TransportPathTransform transform = new(unit, args.TransformForTransport);
Vector3 finalSpot = transform.Calc(spot);
args.facing.f = new Vector3(finalSpot.X, finalSpot.Y, finalSpot.Z);
args.facing.type = MonsterMoveType.FacingSpot;
@@ -307,7 +307,7 @@ namespace Game.Movement
public Vector3[] Path() { return args.path; }
public MoveSplineInitArgs args = new MoveSplineInitArgs();
public MoveSplineInitArgs args = new();
Unit unit;
}
+2 -2
View File
@@ -38,8 +38,8 @@ namespace Game.Movement
}
public Vector3[] path;
public FacingInfo facing = new FacingInfo();
public MoveSplineFlag flags = new MoveSplineFlag();
public FacingInfo facing = new();
public MoveSplineFlag flags = new();
public int path_Idx_offset;
public float velocity;
public float parabolic_amplitude;
+4 -4
View File
@@ -296,13 +296,13 @@ namespace Game.Movement
return i;
}
private static readonly Matrix4 s_catmullRomCoeffs = new Matrix4(-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 Matrix4 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 Matrix4 s_Bezier3Coeffs = new Matrix4(-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);
private static readonly Matrix4 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);
void C_Evaluate(Span<Vector3> vertice, float t, Matrix4 matr, out Vector3 result)
{
Vector4 tvec = new Vector4(t * t * t, t * t, t, 1.0f);
Vector4 tvec = new(t * t * t, t * t, t, 1.0f);
Vector4 weights = (tvec * matr);
result = vertice[0] * weights[0] + vertice[1] * weights[1]
@@ -310,7 +310,7 @@ namespace Game.Movement
}
void C_Evaluate_Derivative(Span<Vector3> vertice, float t, Matrix4 matr, out Vector3 result)
{
Vector4 tvec = new Vector4(3.0f * t * t, 2.0f * t, 1.0f, 0.0f);
Vector4 tvec = new(3.0f * t * t, 2.0f * t, 1.0f, 0.0f);
Vector4 weights = (tvec * matr);
result = vertice[0] * weights[0] + vertice[1] * weights[1]
+5 -5
View File
@@ -52,7 +52,7 @@ namespace Game
GridDefines.NormalizeMapCoord(ref x);
GridDefines.NormalizeMapCoord(ref y);
WaypointNode waypoint = new WaypointNode();
WaypointNode waypoint = new();
waypoint.id = result.Read<uint>(1);
waypoint.x = x;
waypoint.y = y;
@@ -94,7 +94,7 @@ namespace Game
if (result.IsEmpty())
return;
List<WaypointNode> values = new List<WaypointNode>();
List<WaypointNode> values = new();
do
{
float x = result.Read<float>(1);
@@ -105,7 +105,7 @@ namespace Game
GridDefines.NormalizeMapCoord(ref x);
GridDefines.NormalizeMapCoord(ref y);
WaypointNode waypoint = new WaypointNode();
WaypointNode waypoint = new();
waypoint.id = result.Read<uint>(0);
waypoint.x = x;
waypoint.y = y;
@@ -135,7 +135,7 @@ namespace Game
return _waypointStore.LookupByKey(id);
}
Dictionary<uint, WaypointPath> _waypointStore = new Dictionary<uint, WaypointPath>();
Dictionary<uint, WaypointPath> _waypointStore = new();
}
public class WaypointNode
@@ -171,7 +171,7 @@ namespace Game
nodes = _nodes;
}
public List<WaypointNode> nodes = new List<WaypointNode>();
public List<WaypointNode> nodes = new();
public uint id;
}