More refactoring of code.

This commit is contained in:
hondacrx
2019-09-23 21:41:13 -04:00
parent 2418715800
commit 570aebce26
176 changed files with 2261 additions and 2265 deletions
@@ -52,7 +52,7 @@ namespace Game.Movement
_getPoint(owner, out x, out y, out z);
Position mypos = owner.GetPosition();
bool isInLOS = Global.VMapMgr.isInLineOfSight(PhasingHandler.GetTerrainMapId(owner.GetPhaseShift(), owner.GetMap(), mypos.posX, mypos.posY), mypos.posX, mypos.posY, mypos.posZ + 2.0f, x, y, z + 2.0f, ModelIgnoreFlags.Nothing);
bool isInLOS = Global.VMapMgr.IsInLineOfSight(PhasingHandler.GetTerrainMapId(owner.GetPhaseShift(), owner.GetMap(), mypos.posX, mypos.posY), mypos.posX, mypos.posY, mypos.posZ + 2.0f, x, y, z + 2.0f, ModelIgnoreFlags.Nothing);
if (!isInLOS)
{
@@ -59,7 +59,7 @@ namespace Game.AI
MoveSplineInit init = new MoveSplineInit(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))
if (owner.GetMotionMaster().Empty() || !owner.GetMotionMaster().Top().GetResetPosition(owner, out x, out y, out z))
{
owner.GetHomePosition(out x, out y, out z, out o);
init.SetFacing(o);
@@ -27,7 +27,7 @@ namespace Game.Movement
return MovementGeneratorType.Idle;
}
public bool isActive { get; set; }
public bool IsActive { get; set; }
public override void Reset(Unit owner)
{
@@ -33,7 +33,7 @@ namespace Game.Movement
public abstract MovementGeneratorType GetMovementGeneratorType();
public virtual void unitSpeedChanged() { }
public virtual void UnitSpeedChanged() { }
// used by Evade code for select point to evade with expected restart default movement
public virtual bool GetResetPosition(Unit u, out float x, out float y, out float z)
@@ -48,7 +48,7 @@ namespace Game.Movement
public override void Initialize(Unit owner)
{
DoInitialize((T)owner);
isActive = true;
IsActive = true;
}
public override void Finalize(Unit owner)
{
@@ -63,7 +63,7 @@ namespace Game.Movement
return DoUpdate((T)owner, time_diff);
}
public bool isActive { get; set; }
public bool IsActive { get; set; }
public abstract void DoInitialize(T owner);
public abstract void DoFinalize(T owner);
@@ -71,21 +71,21 @@ namespace Game.Movement
public abstract bool DoUpdate(T owner, uint time_diff);
}
public class FollowerReference : Reference<Unit, TargetedMovementGeneratorBase>
public class FollowerReference : Reference<Unit, ITargetedMovementGeneratorBase>
{
public override void targetObjectBuildLink()
public override void TargetObjectBuildLink()
{
getTarget().AddFollower(this);
GetTarget().AddFollower(this);
}
public override void targetObjectDestroyLink()
public override void TargetObjectDestroyLink()
{
getTarget().RemoveFollower(this);
GetTarget().RemoveFollower(this);
}
public override void sourceObjectDestroyLink()
public override void SourceObjectDestroyLink()
{
GetSource().stopFollowing();
GetSource().StopFollowing();
}
}
}
@@ -174,7 +174,7 @@ namespace Game.Movement
// Check both start and end points, if they're both in water, then we can *safely* let the creature move
for (uint i = 0; i < _pathPoints.Length; ++i)
{
ZLiquidStatus status = _sourceUnit.GetMap().getLiquidStatus(_sourceUnit.GetPhaseShift(), _pathPoints[i].X, _pathPoints[i].Y, _pathPoints[i].Z, MapConst.MapAllLiquidTypes);
ZLiquidStatus status = _sourceUnit.GetMap().GetLiquidStatus(_sourceUnit.GetPhaseShift(), _pathPoints[i].X, _pathPoints[i].Y, _pathPoints[i].Z, MapConst.MapAllLiquidTypes);
// One of the points is not in the water, cancel movement.
if (status == ZLiquidStatus.NoWater)
{
@@ -839,7 +839,7 @@ namespace Game.Movement
NavTerrainFlag GetNavTerrain(float x, float y, float z)
{
LiquidData data;
ZLiquidStatus liquidStatus = _sourceUnit.GetMap().getLiquidStatus(_sourceUnit.GetPhaseShift(), x, y, z, MapConst.MapAllLiquidTypes, out data);
ZLiquidStatus liquidStatus = _sourceUnit.GetMap().GetLiquidStatus(_sourceUnit.GetPhaseShift(), x, y, z, MapConst.MapAllLiquidTypes, out data);
if (liquidStatus == ZLiquidStatus.NoWater)
return NavTerrainFlag.Ground;
@@ -123,7 +123,7 @@ namespace Game.Movement
unit.ToCreature().GetAI().MovementInform(MovementGeneratorType.Point, (uint)id);
}
public override void unitSpeedChanged()
public override void UnitSpeedChanged()
{
i_recalculateSpeed = true;
}
@@ -164,7 +164,7 @@ namespace Game.Movement
else
return new SplineChainResumeInfo();
}
return new SplineChainResumeInfo(_id, _chain, _walk, (byte)(_nextIndex - 1), (byte)(me.MoveSpline._currentSplineIdx()), _msToNext);
return new SplineChainResumeInfo(_id, _chain, _walk, (byte)(_nextIndex - 1), (byte)(me.MoveSpline.CurrentSplineIdx()), _msToNext);
}
public override void Reset(Unit owner) { }
@@ -22,26 +22,26 @@ using System;
namespace Game.Movement
{
public interface TargetedMovementGeneratorBase
public interface ITargetedMovementGeneratorBase
{
FollowerReference reftarget { get; set; }
void stopFollowing();
FollowerReference Reftarget { get; set; }
void StopFollowing();
}
public abstract class TargetedMovementGeneratorMedium<T> : MovementGeneratorMedium<T>, TargetedMovementGeneratorBase where T : Unit
public abstract class TargetedMovementGeneratorMedium<T> : MovementGeneratorMedium<T>, ITargetedMovementGeneratorBase where T : Unit
{
public FollowerReference reftarget { get; set; }
public Unit target
public FollowerReference Reftarget { get; set; }
public Unit Target
{
get { return reftarget.getTarget(); }
get { return Reftarget.GetTarget(); }
}
public void stopFollowing() { }
public void StopFollowing() { }
protected TargetedMovementGeneratorMedium(Unit _target, float _offset = 0, float _angle = 0)
{
reftarget = new FollowerReference();
reftarget.link(_target, this);
Reftarget = new FollowerReference();
Reftarget.Link(_target, this);
recheckDistance = new TimeTrackerSmall();
offset = _offset;
angle = _angle;
@@ -51,7 +51,7 @@ namespace Game.Movement
public override bool DoUpdate(T owner, uint time_diff)
{
if (!reftarget.isValid() || !target.IsInWorld)
if (!Reftarget.IsValid() || !Target.IsInWorld)
return false;
if (owner == null || !owner.IsAlive())
@@ -86,7 +86,7 @@ namespace Game.Movement
//More distance let have better performance, less distance let have more sensitive reaction at target move.
float allowed_dist = 0.0f;// owner.GetCombatReach() + WorldConfig.GetFloatValue(WorldCfg.RateTargetPosRecalculationRange);
if (owner.IsPet() && (owner.GetCharmerOrOwnerGUID() == target.GetGUID()))
if (owner.IsPet() && (owner.GetCharmerOrOwnerGUID() == Target.GetGUID()))
allowed_dist = 1.0f; // pet following owner
else
allowed_dist = owner.GetCombatReach() + WorldConfig.GetFloatValue(WorldCfg.RateTargetPosRecalculationRange);
@@ -102,14 +102,14 @@ namespace Game.Movement
// First check distance
if (owner.IsTypeId(TypeId.Unit) && (owner.ToCreature().CanFly() || owner.ToCreature().CanSwim()))
targetMoved = !target.IsWithinDist3d(dest.X, dest.Y, dest.Z, allowed_dist);
targetMoved = !Target.IsWithinDist3d(dest.X, dest.Y, dest.Z, allowed_dist);
else
targetMoved = !target.IsWithinDist2d(dest.X, dest.Y, allowed_dist);
targetMoved = !Target.IsWithinDist2d(dest.X, dest.Y, allowed_dist);
// then, if the target is in range, check also Line of Sight.
if (!targetMoved)
targetMoved = !target.IsWithinLOSInMap(owner);
targetMoved = !Target.IsWithinLOSInMap(owner);
}
if (recalculateTravel || targetMoved)
@@ -118,8 +118,8 @@ namespace Game.Movement
if (owner.MoveSpline.Finalized())
{
MovementInform(owner);
if (angle == 0.0f && !owner.HasInArc(0.01f, target))
owner.SetInFront(target);
if (angle == 0.0f && !owner.HasInArc(0.01f, Target))
owner.SetInFront(Target);
if (!targetReached)
{
@@ -131,14 +131,14 @@ namespace Game.Movement
return true;
}
public override void unitSpeedChanged()
public override void UnitSpeedChanged()
{
recalculateTravel = true;
}
public void _setTargetLocation(T owner, bool updateDestination)
{
if (!reftarget.isValid() || !target.IsInWorld)
if (!Reftarget.IsValid() || !Target.IsInWorld)
return;
if (owner.HasUnitState(UnitState.NotMove))
@@ -147,7 +147,7 @@ namespace Game.Movement
if (owner.IsMovementPreventedByCasting())
return;
if (owner.IsTypeId(TypeId.Unit) && !target.IsInAccessiblePlaceFor(owner.ToCreature()))
if (owner.IsTypeId(TypeId.Unit) && !Target.IsInAccessiblePlaceFor(owner.ToCreature()))
{
owner.ToCreature().SetCannotReachTarget(true);
return;
@@ -161,11 +161,11 @@ namespace Game.Movement
{
if (offset == 0)
{
if (target.IsWithinDistInMap(owner, SharedConst.ContactDistance))
if (Target.IsWithinDistInMap(owner, SharedConst.ContactDistance))
return;
// to nearest contact position
target.GetContactPoint(owner, out x, out y, out z);
Target.GetContactPoint(owner, out x, out y, out z);
}
else
{
@@ -178,7 +178,7 @@ namespace Game.Movement
// be (GetCombatReach() + i_offset) away.
// Only applies when i_target is pet's owner otherwise pets and mobs end up
// doing a "dance" while fighting
if (owner.IsPet() && target.IsTypeId(TypeId.Player))
if (owner.IsPet() && Target.IsTypeId(TypeId.Player))
{
dist = 1.0f;// target.GetCombatReach();
size = 1.0f;// target.GetCombatReach() - target.GetObjectSize();
@@ -189,11 +189,11 @@ namespace Game.Movement
size = owner.GetObjectSize();
}
if (target.IsWithinDistInMap(owner, dist))
if (Target.IsWithinDistInMap(owner, dist))
return;
// to at i_offset distance from target and i_angle from target facing
target.GetClosePoint(out x, out y, out z, size, offset, angle);
Target.GetClosePoint(out x, out y, out z, size, offset, angle);
}
}
else
@@ -235,7 +235,7 @@ namespace Game.Movement
// Using the same condition for facing target as the one that is used for SetInFront on movement end
// - applies to ChaseMovementGenerator mostly
if (angle == 0.0f)
init.SetFacing(target);
init.SetFacing(Target);
init.Launch();
}
@@ -302,7 +302,7 @@ namespace Game.Movement
public override bool _lostTarget(T u)
{
return u.GetVictim() != target;
return u.GetVictim() != Target;
}
public override void _clearUnitStateMove(T u)
{
@@ -318,8 +318,8 @@ namespace Game.Movement
public override void _reachTarget(T owner)
{
_clearUnitStateMove(owner);
if (owner.IsWithinMeleeRange(target))
owner.Attack(target, true);
if (owner.IsWithinMeleeRange(Target))
owner.Attack(Target, true);
if (owner.IsTypeId(TypeId.Unit))
owner.ToCreature().SetCannotReachTarget(false);
}
@@ -329,7 +329,7 @@ namespace Game.Movement
{
// Pass back the GUIDLow of the target. If it is pet's owner then PetAI will handle
if (unit.ToCreature().GetAI() != null)
unit.ToCreature().GetAI().MovementInform(MovementGeneratorType.Chase, (uint)target.GetGUID().GetCounter());
unit.ToCreature().GetAI().MovementInform(MovementGeneratorType.Chase, (uint)Target.GetGUID().GetCounter());
}
}
}
@@ -376,21 +376,21 @@ namespace Game.Movement
// Pass back the GUIDLow of the target. If it is pet's owner then PetAI will handle
if (unit.ToCreature().GetAI() != null)
unit.ToCreature().GetAI().MovementInform(MovementGeneratorType.Follow, (uint)target.GetGUID().GetCounter());
unit.ToCreature().GetAI().MovementInform(MovementGeneratorType.Follow, (uint)Target.GetGUID().GetCounter());
}
public override bool EnableWalking()
{
if (typeof(T) == typeof(Player))
return false;
else
return reftarget.isValid() && target.IsWalking();
return Reftarget.IsValid() && Target.IsWalking();
}
public override void _updateSpeed(T owner)
{
if (owner.IsTypeId(TypeId.Player))
return;
if (!owner.IsPet() || !owner.IsInWorld || !reftarget.isValid() && target.GetGUID() != owner.GetOwnerGUID())
if (!owner.IsPet() || !owner.IsInWorld || !Reftarget.IsValid() && Target.GetGUID() != owner.GetOwnerGUID())
return;
owner.UpdateSpeed(UnitMoveType.Run);
@@ -360,7 +360,7 @@ namespace Game.Movement
if (owner.m_taxi.Empty())
{
owner.GetHostileRefManager().setOnlineOfflineState(true);
owner.GetHostileRefManager().SetOnlineOfflineState(true);
// update z position to ground and orientation for landing point
// this prevent cheating with landing point at lags
// when client side flight end early in comparison server side
@@ -374,7 +374,7 @@ namespace Game.Movement
public override void DoReset(Player owner)
{
owner.GetHostileRefManager().setOnlineOfflineState(false);
owner.GetHostileRefManager().SetOnlineOfflineState(false);
owner.AddUnitState(UnitState.InFlight);
owner.AddUnitFlag(UnitFlags.RemoveClientControl | UnitFlags.TaxiFlight);
@@ -397,7 +397,7 @@ namespace Game.Movement
public override bool DoUpdate(Player player, uint time_diff)
{
uint pointId = (uint)player.MoveSpline.currentPathIdx();
uint pointId = (uint)player.MoveSpline.CurrentPathIdx();
if (pointId > i_currentNode)
{
bool departureEvent = true;
+41 -41
View File
@@ -47,10 +47,10 @@ namespace Game.Movement
public void Initialize()
{
while (!empty())
while (!Empty())
{
IMovementGenerator curr = top();
pop();
IMovementGenerator curr = Top();
Pop();
if (curr != null)
DirectDelete(curr);
}
@@ -77,10 +77,10 @@ namespace Game.Movement
if (_owner.HasUnitState(UnitState.Root | UnitState.Stunned))
return;
Cypher.Assert(!empty());
Cypher.Assert(!Empty());
_cleanFlag |= MMCleanFlag.Update;
bool isMoveGenUpdateSuccess = top().Update(_owner, diff);
bool isMoveGenUpdateSuccess = Top().Update(_owner, diff);
_cleanFlag &= ~MMCleanFlag.Update;
if (!isMoveGenUpdateSuccess)
@@ -114,12 +114,12 @@ namespace Game.Movement
_expireList = null;
if (empty())
if (Empty())
Initialize();
else if (NeedInitTop())
InitTop();
else if (Convert.ToBoolean(_cleanFlag & MMCleanFlag.Reset))
top().Reset(_owner);
Top().Reset(_owner);
_cleanFlag &= ~MMCleanFlag.Reset;
}
@@ -140,10 +140,10 @@ namespace Game.Movement
public MovementGeneratorType GetCurrentMovementGeneratorType()
{
if (empty())
if (Empty())
return MovementGeneratorType.Idle;
return top().GetMovementGeneratorType();
return Top().GetMovementGeneratorType();
}
public MovementGeneratorType GetMotionSlotType(MovementSlot slot)
@@ -160,12 +160,12 @@ namespace Game.Movement
return _slot[slot];
}
public void propagateSpeedChange()
public void PropagateSpeedChange()
{
for (int i = 0; i <= _top; ++i)
{
if (_slot[i] != null)
_slot[i].unitSpeedChanged();
_slot[i].UnitSpeedChanged();
}
}
@@ -186,7 +186,7 @@ namespace Game.Movement
public void MoveIdle()
{
if (empty() || !IsStatic(top()))
if (Empty() || !IsStatic(Top()))
StartMovement(staticIdleMovement, MovementSlot.Idle);
}
@@ -357,7 +357,7 @@ namespace Game.Movement
float x, y, z;
float moveTimeHalf = (float)(speedZ / gravity);
float dist = 2 * moveTimeHalf * speedXY;
float max_height = -MoveSpline.computeFallElevation(moveTimeHalf, false, -speedZ);
float max_height = -MoveSpline.ComputeFallElevation(moveTimeHalf, false, -speedZ);
_owner.GetNearPoint(_owner, out x, out y, out z, _owner.GetObjectSize(), dist, _owner.GetAngle(srcX, srcY) + MathFunctions.PI);
@@ -400,7 +400,7 @@ namespace Game.Movement
return;
float moveTimeHalf = (float)(speedZ / gravity);
float max_height = -MoveSpline.computeFallElevation(moveTimeHalf, false, -speedZ);
float max_height = -MoveSpline.ComputeFallElevation(moveTimeHalf, false, -speedZ);
MoveSplineInit init = new MoveSplineInit(_owner);
init.MoveTo(x, y, z, false);
@@ -611,19 +611,19 @@ namespace Game.Movement
StartMovement(new RotateMovementGenerator(time, direction), MovementSlot.Active);
}
void pop()
void Pop()
{
if (empty())
if (Empty())
return;
_slot[_top] = null;
while (!empty() && top() == null)
while (!Empty() && Top() == null)
--_top;
}
bool NeedInitTop()
{
if (empty())
if (Empty())
return false;
return _initialize[_top];
@@ -631,7 +631,7 @@ namespace Game.Movement
void InitTop()
{
top().Initialize(_owner);
Top().Initialize(_owner);
_initialize[_top] = false;
}
@@ -663,29 +663,29 @@ namespace Game.Movement
void DirectClean(bool reset)
{
while (size() > 1)
while (Size() > 1)
{
IMovementGenerator curr = top();
pop();
IMovementGenerator curr = Top();
Pop();
if (curr != null)
DirectDelete(curr);
}
if (empty())
if (Empty())
return;
if (NeedInitTop())
InitTop();
else if (reset)
top().Reset(_owner);
Top().Reset(_owner);
}
void DelayedClean()
{
while (size() > 1)
while (Size() > 1)
{
IMovementGenerator curr = top();
pop();
IMovementGenerator curr = Top();
Pop();
if (curr != null)
DelayedDelete(curr);
}
@@ -693,34 +693,34 @@ namespace Game.Movement
void DirectExpire(bool reset)
{
if (size() > 1)
if (Size() > 1)
{
IMovementGenerator curr = top();
pop();
IMovementGenerator curr = Top();
Pop();
DirectDelete(curr);
}
while (!empty() && top() == null)//not sure this will work
while (!Empty() && Top() == null)//not sure this will work
--_top;
if (empty())
if (Empty())
Initialize();
else if (NeedInitTop())
InitTop();
else if (reset)
top().Reset(_owner);
Top().Reset(_owner);
}
void DelayedExpire()
{
if (size() > 1)
if (Size() > 1)
{
IMovementGenerator curr = top();
pop();
IMovementGenerator curr = Top();
Pop();
DelayedDelete(curr);
}
while (!empty() && top() == null)
while (!Empty() && Top() == null)
--_top;
}
@@ -740,13 +740,13 @@ namespace Game.Movement
_expireList.Add(curr);
}
public bool empty() { return (_top < 0); }
public bool Empty() { return (_top < 0); }
int size() { return _top + 1; }
int Size() { return _top + 1; }
public IMovementGenerator top()
public IMovementGenerator Top()
{
Cypher.Assert(!empty());
Cypher.Assert(!Empty());
return _slot[_top];
}
+65 -65
View File
@@ -54,20 +54,20 @@ namespace Game.Movement
splineIsFacingOnly = args.path.Length == 2 && args.facing.type != MonsterMoveType.Normal && ((args.path[1] - args.path[0]).GetLength() < 0.1f);
// Check if its a stop spline
if (args.flags.hasFlag(SplineFlag.Done))
if (args.flags.HasFlag(SplineFlag.Done))
{
spline.clear();
spline.Clear();
return;
}
init_spline(args);
InitSpline(args);
// init parabolic / animation
// spline initialized, duration known and i able to compute parabolic acceleration
if (args.flags.hasFlag(SplineFlag.Parabolic | SplineFlag.Animation | SplineFlag.FadeObject))
if (args.flags.HasFlag(SplineFlag.Parabolic | SplineFlag.Animation | SplineFlag.FadeObject))
{
effect_start_time = (int)(Duration() * args.time_perc);
if (args.flags.hasFlag(SplineFlag.Parabolic) && effect_start_time < Duration())
if (args.flags.HasFlag(SplineFlag.Parabolic) && effect_start_time < Duration())
{
float f_duration = (float)TimeSpan.FromMilliseconds(Duration() - effect_start_time).TotalSeconds;
vertical_acceleration = args.parabolic_amplitude * 8.0f / (f_duration * f_duration);
@@ -75,77 +75,77 @@ namespace Game.Movement
}
}
void init_spline(MoveSplineInitArgs args)
void InitSpline(MoveSplineInitArgs args)
{
Spline.EvaluationMode[] modes = new Spline.EvaluationMode[2] { Spline.EvaluationMode.Linear, Spline.EvaluationMode.Catmullrom };
if (args.flags.hasFlag(SplineFlag.Cyclic))
if (args.flags.HasFlag(SplineFlag.Cyclic))
{
spline.init_cyclic_spline(args.path, args.path.Length, modes[Convert.ToInt32(args.flags.isSmooth())], 0);
spline.InitCyclicSpline(args.path, args.path.Length, modes[Convert.ToInt32(args.flags.IsSmooth())], 0);
}
else
{
spline.Init_Spline(args.path, args.path.Length, modes[Convert.ToInt32(args.flags.isSmooth())]);
spline.InitSpline(args.path, args.path.Length, modes[Convert.ToInt32(args.flags.IsSmooth())]);
}
// init spline timestamps
if (splineflags.hasFlag(SplineFlag.Falling))
if (splineflags.HasFlag(SplineFlag.Falling))
{
FallInitializer init = new FallInitializer(spline.getPoint(spline.first()).Z);
spline.initLengths(init);
FallInitializer init = new FallInitializer(spline.GetPoint(spline.First()).Z);
spline.InitLengths(init);
}
else
{
CommonInitializer init = new CommonInitializer(args.velocity);
spline.initLengths(init);
spline.InitLengths(init);
}
// TODO: what to do in such cases? problem is in input data (all points are at same coords)
if (spline.length() < 1)
if (spline.Length() < 1)
{
Log.outError(LogFilter.Unit, "MoveSpline.init_spline: zero length spline, wrong input data?");
spline.set_length(spline.last(), spline.isCyclic() ? 1000 : 1);
spline.Set_length(spline.Last(), spline.IsCyclic() ? 1000 : 1);
}
point_Idx = spline.first();
point_Idx = spline.First();
}
public int currentPathIdx()
public int CurrentPathIdx()
{
int point = point_Idx_offset + point_Idx - spline.first() + (Finalized() ? 1 : 0);
if (isCyclic())
point = point % (spline.last() - spline.first());
int point = point_Idx_offset + point_Idx - spline.First() + (Finalized() ? 1 : 0);
if (IsCyclic())
point = point % (spline.Last() - spline.First());
return point;
}
public Vector3[] getPath() { return spline.getPoints(); }
public int timePassed() { return time_passed; }
public Vector3[] GetPath() { return spline.GetPoints(); }
public int TimePassed() { return time_passed; }
public int Duration() { return spline.length(); }
public int _currentSplineIdx() { return point_Idx; }
public int Duration() { return spline.Length(); }
public int CurrentSplineIdx() { return point_Idx; }
public uint GetId() { return m_Id; }
public bool Finalized() { return splineflags.hasFlag(SplineFlag.Done); }
public bool Finalized() { return splineflags.HasFlag(SplineFlag.Done); }
void _Finalize()
{
splineflags.SetUnsetFlag(SplineFlag.Done);
point_Idx = spline.last() - 1;
point_Idx = spline.Last() - 1;
time_passed = Duration();
}
public Vector4 computePosition(int time_point, int point_index)
public Vector4 ComputePosition(int time_point, int point_index)
{
float u = 1.0f;
int seg_time = spline.length(point_index, point_index + 1);
int seg_time = spline.Length(point_index, point_index + 1);
if (seg_time > 0)
u = (time_point - spline.length(point_index)) / (float)seg_time;
u = (time_point - spline.Length(point_index)) / (float)seg_time;
Vector3 c;
float orientation = initialOrientation;
spline.Evaluate_Percent(point_index, u, out c);
if (splineflags.hasFlag(SplineFlag.Parabolic))
computeParabolicElevation(time_point, ref c.Z);
else if (splineflags.hasFlag(SplineFlag.Falling))
computeFallElevation(time_point, ref c.Z);
if (splineflags.HasFlag(SplineFlag.Parabolic))
ComputeParabolicElevation(time_point, ref c.Z);
else if (splineflags.HasFlag(SplineFlag.Falling))
ComputeFallElevation(time_point, ref c.Z);
if (splineflags.hasFlag(SplineFlag.Done) && facing.type != MonsterMoveType.Normal)
if (splineflags.HasFlag(SplineFlag.Done) && facing.type != MonsterMoveType.Normal)
{
if (facing.type == MonsterMoveType.FacingAngle)
orientation = facing.angle;
@@ -155,14 +155,14 @@ namespace Game.Movement
}
else
{
if (!splineflags.hasFlag(SplineFlag.OrientationFixed | SplineFlag.Falling | SplineFlag.Unknown0))
if (!splineflags.HasFlag(SplineFlag.OrientationFixed | SplineFlag.Falling | SplineFlag.Unknown0))
{
Vector3 hermite;
spline.Evaluate_Derivative(point_Idx, u, out hermite);
orientation = (float)Math.Atan2(hermite.Y, hermite.X);
}
if (splineflags.hasFlag(SplineFlag.Backward))
if (splineflags.HasFlag(SplineFlag.Backward))
orientation = orientation - (float)Math.PI;
}
@@ -170,27 +170,27 @@ namespace Game.Movement
}
public Vector4 ComputePosition()
{
return computePosition(time_passed, point_Idx);
return ComputePosition(time_passed, point_Idx);
}
public Vector4 ComputePosition(int time_offset)
{
int time_point = time_passed + time_offset;
if (time_point >= Duration())
return computePosition(Duration(), spline.last() - 1);
return ComputePosition(Duration(), spline.Last() - 1);
if (time_point <= 0)
return computePosition(0, spline.first());
return ComputePosition(0, spline.First());
// find point_index where spline.length(point_index) < time_point < spline.length(point_index + 1)
int point_index = point_Idx;
while (time_point >= spline.length(point_index + 1))
while (time_point >= spline.Length(point_index + 1))
++point_index;
while (time_point < spline.length(point_index))
while (time_point < spline.Length(point_index))
--point_index;
return computePosition(time_point, point_index);
return ComputePosition(time_point, point_index);
}
public void computeParabolicElevation(int time_point, ref float el)
public void ComputeParabolicElevation(int time_point, ref float el)
{
if (time_point > effect_start_time)
{
@@ -202,13 +202,13 @@ namespace Game.Movement
el += (t_durationf - t_passedf) * 0.5f * vertical_acceleration * t_passedf;
}
}
public void computeFallElevation(int time_point, ref float el)
public void ComputeFallElevation(int time_point, ref float el)
{
float z_now = spline.getPoint(spline.first()).Z - computeFallElevation(MSToSec((uint)time_point), false);
float z_now = spline.GetPoint(spline.First()).Z - ComputeFallElevation(MSToSec((uint)time_point), false);
float final_z = FinalDestination().Z;
el = Math.Max(z_now, final_z);
}
public static float computeFallElevation(float t_passed, bool isSafeFall, float start_velocity = 0.0f)
public static float ComputeFallElevation(float t_passed, bool isSafeFall, float start_velocity = 0.0f)
{
float termVel;
float result;
@@ -241,14 +241,14 @@ namespace Game.Movement
}
public void Interrupt() { splineflags.SetUnsetFlag(SplineFlag.Done); }
public void updateState(int difftime)
public void UpdateState(int difftime)
{
do
{
_updateState(ref difftime);
UpdateState(ref difftime);
} while (difftime > 0);
}
UpdateResult _updateState(ref int ms_time_diff)
UpdateResult UpdateState(ref int ms_time_diff)
{
if (Finalized())
{
@@ -257,22 +257,22 @@ namespace Game.Movement
}
UpdateResult result = UpdateResult.None;
int minimal_diff = Math.Min(ms_time_diff, segment_time_elapsed());
int minimal_diff = Math.Min(ms_time_diff, SegmentTimeElapsed());
time_passed += minimal_diff;
ms_time_diff -= minimal_diff;
if (time_passed >= next_timestamp())
if (time_passed >= NextTimestamp())
{
++point_Idx;
if (point_Idx < spline.last())
if (point_Idx < spline.Last())
{
result = UpdateResult.NextSegment;
}
else
{
if (spline.isCyclic())
if (spline.IsCyclic())
{
point_Idx = spline.first();
point_Idx = spline.First();
time_passed = time_passed % Duration();
result = UpdateResult.NextCycle;
}
@@ -287,12 +287,12 @@ namespace Game.Movement
return result;
}
int next_timestamp() { return spline.length(point_Idx + 1); }
int segment_time_elapsed() { return next_timestamp() - time_passed; }
public bool isCyclic() { return splineflags.hasFlag(SplineFlag.Cyclic); }
public bool isFalling() { return splineflags.hasFlag(SplineFlag.Falling); }
public bool Initialized() { return !spline.empty(); }
public Vector3 FinalDestination() { return Initialized() ? spline.getPoint(spline.last()) : new Vector3(); }
int NextTimestamp() { return spline.Length(point_Idx + 1); }
int SegmentTimeElapsed() { return NextTimestamp() - time_passed; }
public bool IsCyclic() { return splineflags.HasFlag(SplineFlag.Cyclic); }
public bool IsFalling() { return splineflags.HasFlag(SplineFlag.Falling); }
public bool Initialized() { return !spline.Empty(); }
public Vector3 FinalDestination() { return Initialized() ? spline.GetPoint(spline.Last()) : new Vector3(); }
#region Fields
public MoveSplineInitArgs InitArgs;
@@ -311,7 +311,7 @@ namespace Game.Movement
public Optional<SpellEffectExtraData> spell_effect_extra;
#endregion
public class CommonInitializer : Initializer
public class CommonInitializer : IInitializer
{
public CommonInitializer(float _velocity)
{
@@ -326,7 +326,7 @@ namespace Game.Movement
return time;
}
}
public class FallInitializer : Initializer
public class FallInitializer : IInitializer
{
public FallInitializer(float startelevation)
{
@@ -335,10 +335,10 @@ namespace Game.Movement
float startElevation;
public int SetGetTime(Spline s, int i)
{
return (int)(computeFallTime(startElevation - s.getPoint(i + 1).Z, false) * 1000.0f);
return (int)(ComputeFallTime(startElevation - s.GetPoint(i + 1).Z, false) * 1000.0f);
}
float computeFallTime(float path_length, bool isSafeFall)
float ComputeFallTime(float path_length, bool isSafeFall)
{
if (path_length < 0.0f)
return 0.0f;
@@ -370,7 +370,7 @@ namespace Game.Movement
NextSegment = 0x08
}
}
public interface Initializer
public interface IInitializer
{
int SetGetTime(Spline s, int i);
}
+5 -5
View File
@@ -26,12 +26,12 @@ namespace Game.Movement
public MoveSplineFlag(SplineFlag f) { Flags = f; }
public MoveSplineFlag(MoveSplineFlag f) { Flags = f.Flags; }
public bool isSmooth() { return Flags.HasAnyFlag(SplineFlag.Catmullrom); }
public bool isLinear() { return !isSmooth(); }
public bool IsSmooth() { return Flags.HasAnyFlag(SplineFlag.Catmullrom); }
public bool IsLinear() { return !IsSmooth(); }
public byte getAnimTier() { return animTier; }
public bool hasAllFlags(SplineFlag f) { return (Flags & f) == f; }
public bool hasFlag(SplineFlag f) { return (Flags & f) != 0; }
public byte GetAnimTier() { return animTier; }
public bool HasAllFlags(SplineFlag f) { return (Flags & f) == f; }
public bool HasFlag(SplineFlag f) { return (Flags & f) != 0; }
public void SetUnsetFlag(SplineFlag f, bool Set = true)
{
+1 -1
View File
@@ -103,7 +103,7 @@ namespace Game.Movement
move_spline.onTransport = !unit.GetTransGUID().IsEmpty();
MovementFlag moveFlags = unit.m_movementInfo.GetMovementFlags();
if (!args.flags.hasFlag(SplineFlag.Backward))
if (!args.flags.HasFlag(SplineFlag.Backward))
moveFlags = (moveFlags & ~MovementFlag.Backward) | MovementFlag.Forward;
else
moveFlags = (moveFlags & ~MovementFlag.Forward) | MovementFlag.Backward;
+3 -3
View File
@@ -54,15 +54,15 @@ namespace Game.Movement
// Returns true to show that the arguments were configured correctly and MoveSpline initialization will succeed.
public bool Validate(Unit unit)
{
Func<bool, bool> CHECK = exp =>
bool CHECK(bool exp)
{
if (!(exp))
if (!exp)
{
Log.outError(LogFilter.Misc, "MoveSplineInitArgs::Validate: expression '{0}' failed for {1} Entry: {2}", exp.ToString(), unit.GetGUID().ToString(), unit.GetEntry());
return false;
}
return true;
};
}
if (!CHECK(path.Length > 1))
return false;
+23 -23
View File
@@ -25,18 +25,18 @@ namespace Game.Movement
{
public class Spline
{
public int getPointCount() { return points.Length; }
public Vector3 getPoint(int i) { return points[i]; }
public Vector3[] getPoints() { return points; }
public int GetPointCount() { return points.Length; }
public Vector3 GetPoint(int i) { return points[i]; }
public Vector3[] GetPoints() { return points; }
public void clear()
public void Clear()
{
Array.Clear(points, 0, points.Length);
}
public int first() { return index_lo; }
public int last() { return index_hi; }
public int First() { return index_lo; }
public int Last() { return index_hi; }
public bool isCyclic() { return _cyclic;}
public bool IsCyclic() { return _cyclic;}
#region Evaluate
public void Evaluate_Percent(int Idx, float u, out Vector3 c)
@@ -75,18 +75,18 @@ namespace Game.Movement
#endregion
#region Init
public void init_spline_custom(SplineRawInitializer initializer)
public void InitSplineCustom(SplineRawInitializer initializer)
{
initializer.Initialize(ref m_mode, ref _cyclic, ref points, ref index_lo, ref index_hi);
}
public void init_cyclic_spline(Vector3[] controls, int count, EvaluationMode m, int cyclic_point)
public void InitCyclicSpline(Vector3[] controls, int count, EvaluationMode m, int cyclic_point)
{
m_mode = m;
_cyclic = true;
Init_Spline(controls, count, m);
InitSpline(controls, count, m);
}
public void Init_Spline(Span<Vector3> controls, int count, EvaluationMode m)
public void InitSpline(Span<Vector3> controls, int count, EvaluationMode m)
{
m_mode = m;
_cyclic = false;
@@ -261,16 +261,16 @@ namespace Game.Movement
}
#endregion
public void computeIndex(float t, ref int index, ref float u)
public void ComputeIndex(float t, ref int index, ref float u)
{
//ASSERT(t >= 0.f && t <= 1.f);
int length_ = (int)(t * length());
index = computeIndexInBounds(length_);
int length_ = (int)(t * Length());
index = ComputeIndexInBounds(length_);
//ASSERT(index < index_hi);
u = (length_ - length(index)) / (float)length(index, index + 1);
u = (length_ - Length(index)) / (float)Length(index, index + 1);
}
int computeIndexInBounds(int length_)
int ComputeIndexInBounds(int length_)
{
// Temporary disabled: causes infinite loop with t = 1.f
/*
@@ -317,15 +317,15 @@ namespace Game.Movement
+ vertice[2] * weights[2] + vertice[3] * weights[3];
}
public int length() { return lengths[index_hi];}
public int Length() { return lengths[index_hi];}
public int length(int first, int last) { return lengths[last] - lengths[first]; }
public int Length(int first, int last) { return lengths[last] - lengths[first]; }
public int length(int Idx) { return lengths[Idx]; }
public int Length(int Idx) { return lengths[Idx]; }
public void set_length(int i, int length) { lengths[i] = length; }
public void Set_length(int i, int length) { lengths[i] = length; }
public void initLengths(Initializer cacher)
public void InitLengths(IInitializer cacher)
{
int i = index_lo;
Array.Resize(ref lengths, index_hi+1);
@@ -341,7 +341,7 @@ namespace Game.Movement
}
}
public void initLengths()
public void InitLengths()
{
int i = index_lo;
int length = 0;
@@ -353,7 +353,7 @@ namespace Game.Movement
}
}
public bool empty() { return index_lo == index_hi;}
public bool Empty() { return index_lo == index_hi;}
int[] lengths = new int[0];
Vector3[] points = new Vector3[0];