Core/Common: Merge TimeTrackerSmall with TimeTracker

Port From (https://github.com/TrinityCore/TrinityCore/commit/8809d54ca2daa230b1439f012c8b10ee88d6beae)
This commit is contained in:
hondacrx
2022-03-02 14:06:04 -05:00
parent 7631b1c387
commit 712dd7b9de
18 changed files with 52 additions and 82 deletions
+14 -44
View File
@@ -339,79 +339,49 @@ public static class Time
} }
} }
public class TimeTrackerSmall public class TimeTracker
{ {
public TimeTrackerSmall(int expiry = 0) public TimeTracker(uint expiry = 0)
{ {
i_expiryTime = expiry; _expiryTime = TimeSpan.FromMilliseconds(expiry);
} }
public TimeTrackerSmall(TimeSpan expiry = default) public TimeTracker(TimeSpan expiry)
{ {
i_expiryTime = (int)expiry.TotalMilliseconds; _expiryTime = expiry;
} }
public void Update(int diff) public void Update(uint diff)
{ {
i_expiryTime -= diff; Update(TimeSpan.FromMilliseconds(diff));
} }
public void Update(TimeSpan diff) public void Update(TimeSpan diff)
{ {
Update((int)diff.TotalMilliseconds); _expiryTime -= diff;
} }
public bool Passed() public bool Passed()
{ {
return i_expiryTime <= 0; return _expiryTime <= TimeSpan.Zero;
} }
public void Reset(int interval) public void Reset(uint expiry)
{ {
i_expiryTime = interval; Reset(TimeSpan.FromMilliseconds(expiry));
} }
public void Reset(TimeSpan expiry) public void Reset(TimeSpan expiry)
{ {
Reset((int)expiry.TotalMilliseconds); _expiryTime = expiry;
} }
public TimeSpan GetExpiry() public TimeSpan GetExpiry()
{ {
return TimeSpan.FromMilliseconds(i_expiryTime); return _expiryTime;
} }
int i_expiryTime; TimeSpan _expiryTime;
}
public class TimeTracker
{
public TimeTracker(long expiry = 0)
{
i_expiryTime = expiry;
}
public void Update(long diff)
{
i_expiryTime -= diff;
}
public bool Passed()
{
return i_expiryTime <= 0;
}
public void Reset(long interval)
{
i_expiryTime = interval;
}
public long GetExpiry()
{
return i_expiryTime;
}
long i_expiryTime;
} }
public class IntervalTimer public class IntervalTimer
+3 -3
View File
@@ -179,7 +179,7 @@ namespace Game.Collision
{ {
public DynTreeImpl() public DynTreeImpl()
{ {
rebalance_timer = new TimeTrackerSmall(200); rebalance_timer = new TimeTracker(200);
unbalanced_times = 0; unbalanced_times = 0;
} }
@@ -206,7 +206,7 @@ namespace Game.Collision
if (Empty()) if (Empty())
return; return;
rebalance_timer.Update((int)difftime); rebalance_timer.Update(difftime);
if (rebalance_timer.Passed()) if (rebalance_timer.Passed())
{ {
rebalance_timer.Reset(200); rebalance_timer.Reset(200);
@@ -215,7 +215,7 @@ namespace Game.Collision
} }
} }
TimeTrackerSmall rebalance_timer; TimeTracker rebalance_timer;
int unbalanced_times; int unbalanced_times;
} }
} }
+1 -1
View File
@@ -241,7 +241,7 @@ namespace Game.Entities
float[] m_powerFraction = new float[(int)PowerType.MaxPerClass]; float[] m_powerFraction = new float[(int)PowerType.MaxPerClass];
int[] m_MirrorTimer = new int[3]; int[] m_MirrorTimer = new int[3];
TimeTrackerSmall m_groupUpdateTimer; TimeTracker m_groupUpdateTimer;
ulong m_GuildIdInvited; ulong m_GuildIdInvited;
DeclinedName _declinedname; DeclinedName _declinedname;
+1 -1
View File
@@ -612,7 +612,7 @@ namespace Game.Entities
} }
// group update // group update
m_groupUpdateTimer.Update((int)diff); m_groupUpdateTimer.Update(diff);
if (m_groupUpdateTimer.Passed()) if (m_groupUpdateTimer.Passed())
{ {
SendUpdateToOutOfRangeGroupMembers(); SendUpdateToOutOfRangeGroupMembers();
+3 -3
View File
@@ -152,7 +152,7 @@ namespace Game.Entities
public override void Update(uint diff) public override void Update(uint diff)
{ {
int positionUpdateDelay = 200; uint positionUpdateDelay = 200;
if (GetAI() != null) if (GetAI() != null)
GetAI().UpdateAI(diff); GetAI().UpdateAI(diff);
@@ -236,7 +236,7 @@ namespace Game.Entities
} }
// Set position // Set position
_positionChangeTimer.Update((int)diff); _positionChangeTimer.Update(diff);
if (_positionChangeTimer.Passed()) if (_positionChangeTimer.Passed())
{ {
_positionChangeTimer.Reset(positionUpdateDelay); _positionChangeTimer.Reset(positionUpdateDelay);
@@ -805,7 +805,7 @@ namespace Game.Entities
KeyFrame _currentFrame; KeyFrame _currentFrame;
int _nextFrame; int _nextFrame;
TimeTrackerSmall _positionChangeTimer = new(); TimeTracker _positionChangeTimer = new();
bool _isMoving; bool _isMoving;
bool _pendingStop; bool _pendingStop;
+1 -1
View File
@@ -41,7 +41,7 @@ namespace Game.Entities
public MoveSpline MoveSpline { get; set; } public MoveSpline MoveSpline { get; set; }
MotionMaster i_motionMaster; MotionMaster i_motionMaster;
public uint m_movementCounter; //< Incrementing counter used in movement packets public uint m_movementCounter; //< Incrementing counter used in movement packets
TimeTrackerSmall splineSyncTimer; TimeTracker splineSyncTimer;
MovementForces _movementForces; MovementForces _movementForces;
PositionUpdateInfo _positionUpdateInfo; PositionUpdateInfo _positionUpdateInfo;
protected Unit m_unitMovedByMe; // only ever set for players, and only for direct client control protected Unit m_unitMovedByMe; // only ever set for players, and only for direct client control
+1 -1
View File
@@ -1708,7 +1708,7 @@ namespace Game.Entities
if (MoveSpline.IsCyclic()) if (MoveSpline.IsCyclic())
{ {
splineSyncTimer.Update((int)diff); splineSyncTimer.Update(diff);
if (splineSyncTimer.Passed()) if (splineSyncTimer.Passed())
{ {
splineSyncTimer.Reset(5000); // Retail value, do not change splineSyncTimer.Reset(5000); // Retail value, do not change
+1 -1
View File
@@ -87,7 +87,7 @@ namespace Game.Entities
m_serverSideVisibility.SetValue(ServerSideVisibilityType.Ghost, GhostVisibilityType.Alive); m_serverSideVisibility.SetValue(ServerSideVisibilityType.Ghost, GhostVisibilityType.Alive);
splineSyncTimer = new TimeTrackerSmall(); splineSyncTimer = new TimeTracker();
m_unitData = new UnitData(); m_unitData = new UnitData();
} }
+2 -2
View File
@@ -48,7 +48,7 @@ namespace Game.Groups
{ {
if (_isLeaderOffline) if (_isLeaderOffline)
{ {
_leaderOfflineTimer.Update((int)diff); _leaderOfflineTimer.Update(diff);
if (_leaderOfflineTimer.Passed()) if (_leaderOfflineTimer.Passed())
{ {
SelectNewPartyOrRaidLeader(); SelectNewPartyOrRaidLeader();
@@ -2752,7 +2752,7 @@ namespace Game.Groups
uint m_maxEnchantingLevel; uint m_maxEnchantingLevel;
uint m_dbStoreId; uint m_dbStoreId;
bool _isLeaderOffline; bool _isLeaderOffline;
TimeTrackerSmall _leaderOfflineTimer = new(); TimeTracker _leaderOfflineTimer = new();
// Ready Check // Ready Check
bool m_readyCheckStarted; bool m_readyCheckStarted;
+3 -3
View File
@@ -33,7 +33,7 @@ namespace Game.Maps
public GridInfo(long expiry, bool unload = true) public GridInfo(long expiry, bool unload = true)
{ {
i_timer = new TimeTracker((int)expiry); i_timer = new TimeTracker((uint)expiry);
vis_Update = new PeriodicTimer(0, RandomHelper.IRand(0, 1000)); vis_Update = new PeriodicTimer(0, RandomHelper.IRand(0, 1000));
i_unloadActiveLockCount = 0; i_unloadActiveLockCount = 0;
i_unloadExplicitLock = !unload; i_unloadExplicitLock = !unload;
@@ -71,12 +71,12 @@ namespace Game.Maps
public void ResetTimeTracker(long interval) public void ResetTimeTracker(long interval)
{ {
i_timer.Reset(interval); i_timer.Reset((uint)interval);
} }
public void UpdateTimeTracker(long diff) public void UpdateTimeTracker(long diff)
{ {
i_timer.Update(diff); i_timer.Update((uint)diff);
} }
public PeriodicTimer GetRelocationTimer() public PeriodicTimer GetRelocationTimer()
@@ -24,14 +24,14 @@ namespace Game.Movement
{ {
class ChaseMovementGenerator : MovementGenerator class ChaseMovementGenerator : MovementGenerator
{ {
static int RANGE_CHECK_INTERVAL = 100; // time (ms) until we attempt to recalculate static uint RANGE_CHECK_INTERVAL = 100; // time (ms) until we attempt to recalculate
ChaseRange? _range; ChaseRange? _range;
ChaseAngle? _angle; ChaseAngle? _angle;
PathGenerator _path; PathGenerator _path;
Position _lastTargetPosition; Position _lastTargetPosition;
TimeTrackerSmall _rangeCheckTimer; TimeTracker _rangeCheckTimer;
bool _movingTowards = true; bool _movingTowards = true;
bool _mutualChase = true; bool _mutualChase = true;
@@ -97,7 +97,7 @@ namespace Game.Movement
ChaseAngle? angle = mutualChase ? null : _angle; ChaseAngle? angle = mutualChase ? null : _angle;
// periodically check if we're already in the expected range... // periodically check if we're already in the expected range...
_rangeCheckTimer.Update((int)diff); _rangeCheckTimer.Update(diff);
if (_rangeCheckTimer.Passed()) if (_rangeCheckTimer.Passed())
{ {
_rangeCheckTimer.Reset(RANGE_CHECK_INTERVAL); _rangeCheckTimer.Reset(RANGE_CHECK_INTERVAL);
@@ -109,7 +109,7 @@ namespace Game.Movement
MoveSplineInit init = new(owner); MoveSplineInit init = new(owner);
init.MovebyPath(_path.GetPath()); init.MovebyPath(_path.GetPath());
init.SetWalk(true); init.SetWalk(true);
int traveltime = init.Launch(); uint traveltime = (uint)init.Launch();
_timer.Reset(traveltime + RandomHelper.URand(800, 1500)); _timer.Reset(traveltime + RandomHelper.URand(800, 1500));
} }
@@ -151,7 +151,7 @@ namespace Game.Movement
MoveSplineInit init = new(owner); MoveSplineInit init = new(owner);
init.MovebyPath(_path.GetPath()); init.MovebyPath(_path.GetPath());
init.SetWalk(false); init.SetWalk(false);
int traveltime = init.Launch(); uint traveltime = (uint)init.Launch();
_timer.Reset(traveltime + RandomHelper.URand(800, 1500)); _timer.Reset(traveltime + RandomHelper.URand(800, 1500));
} }
@@ -24,13 +24,13 @@ namespace Game.Movement
{ {
public class FollowMovementGenerator : MovementGenerator public class FollowMovementGenerator : MovementGenerator
{ {
static int CHECK_INTERVAL = 100; static uint CHECK_INTERVAL = 100;
static float FOLLOW_RANGE_TOLERANCE = 1.0f; static float FOLLOW_RANGE_TOLERANCE = 1.0f;
float _range; float _range;
ChaseAngle _angle; ChaseAngle _angle;
TimeTrackerSmall _checkTimer; TimeTracker _checkTimer;
PathGenerator _path; PathGenerator _path;
Position _lastTargetPosition; Position _lastTargetPosition;
@@ -86,7 +86,7 @@ namespace Game.Movement
return true; return true;
} }
_checkTimer.Update((int)diff); _checkTimer.Update(diff);
if (_checkTimer.Passed()) if (_checkTimer.Passed())
{ {
_checkTimer.Reset(CHECK_INTERVAL); _checkTimer.Reset(CHECK_INTERVAL);
@@ -25,7 +25,7 @@ namespace Game.Movement
{ {
AbstractFollower _abstractFollower; AbstractFollower _abstractFollower;
static int FORMATION_MOVEMENT_INTERVAL = 1200; // sniffed (3 batch update cycles) static uint FORMATION_MOVEMENT_INTERVAL = 1200; // sniffed (3 batch update cycles)
float _range; float _range;
float _angle; float _angle;
uint _point1; uint _point1;
@@ -34,7 +34,7 @@ namespace Game.Movement
bool _hasPredictedDestination; bool _hasPredictedDestination;
Position _lastLeaderPosition; Position _lastLeaderPosition;
TimeTrackerSmall _nextMoveTimer = new(); TimeTracker _nextMoveTimer = new();
public FormationMovementGenerator(Unit leader, float range, float angle, uint point1, uint point2) public FormationMovementGenerator(Unit leader, float range, float angle, uint point1, uint point2)
{ {
@@ -128,7 +128,7 @@ namespace Game.Movement
return true; return true;
} }
_nextMoveTimer.Update((int)diff); _nextMoveTimer.Update(diff);
if (_nextMoveTimer.Passed()) if (_nextMoveTimer.Passed())
{ {
_nextMoveTimer.Reset(FORMATION_MOVEMENT_INTERVAL); _nextMoveTimer.Reset(FORMATION_MOVEMENT_INTERVAL);
@@ -25,7 +25,7 @@ namespace Game.Movement
MoveSplineInit _splineInit; MoveSplineInit _splineInit;
MovementGeneratorType _type; MovementGeneratorType _type;
uint _pointId; uint _pointId;
TimeTrackerSmall _duration; TimeTracker _duration;
uint _arrivalSpellId; uint _arrivalSpellId;
ObjectGuid _arrivalSpellTargetGuid; ObjectGuid _arrivalSpellTargetGuid;
@@ -57,7 +57,7 @@ namespace Game.Movement
RemoveFlag(MovementGeneratorFlags.InitializationPending | MovementGeneratorFlags.Deactivated); RemoveFlag(MovementGeneratorFlags.InitializationPending | MovementGeneratorFlags.Deactivated);
AddFlag(MovementGeneratorFlags.Initialized); AddFlag(MovementGeneratorFlags.Initialized);
_duration.Reset(_splineInit.Launch()); _duration.Reset((uint)_splineInit.Launch());
} }
public override void Reset(Unit owner) public override void Reset(Unit owner)
@@ -72,7 +72,7 @@ namespace Game.Movement
// Cyclic splines never expire, so update the duration only if it's not cyclic // Cyclic splines never expire, so update the duration only if it's not cyclic
if (!owner.MoveSpline.IsCyclic()) if (!owner.MoveSpline.IsCyclic())
_duration.Update((int)diff); _duration.Update(diff);
if (_duration.Passed() || owner.MoveSpline.Finalized()) if (_duration.Passed() || owner.MoveSpline.Finalized())
{ {
@@ -188,7 +188,7 @@ namespace Game.Movement
MoveSplineInit init = new(owner); MoveSplineInit init = new(owner);
init.MovebyPath(_path.GetPath()); init.MovebyPath(_path.GetPath());
init.SetWalk(walk); init.SetWalk(walk);
int splineDuration = init.Launch(); uint splineDuration = (uint)init.Launch();
--_wanderSteps; --_wanderSteps;
if (_wanderSteps != 0) // Creature has yet to do steps before pausing if (_wanderSteps != 0) // Creature has yet to do steps before pausing
@@ -27,7 +27,7 @@ namespace Game.Movement
{ {
public WaypointMovementGenerator(uint pathId = 0, bool repeating = true) public WaypointMovementGenerator(uint pathId = 0, bool repeating = true)
{ {
_nextMoveTime = new TimeTrackerSmall(0); _nextMoveTime = new TimeTracker(0);
_pathId = pathId; _pathId = pathId;
_repeating = repeating; _repeating = repeating;
_loadedFromDB = true; _loadedFromDB = true;
@@ -40,7 +40,7 @@ namespace Game.Movement
public WaypointMovementGenerator(WaypointPath path, bool repeating = true) public WaypointMovementGenerator(WaypointPath path, bool repeating = true)
{ {
_nextMoveTime = new TimeTrackerSmall(0); _nextMoveTime = new TimeTracker(0);
_repeating = repeating; _repeating = repeating;
_path = path; _path = path;
@@ -59,7 +59,7 @@ namespace Game.Movement
return; return;
AddFlag(MovementGeneratorFlags.TimedPaused); AddFlag(MovementGeneratorFlags.TimedPaused);
_nextMoveTime.Reset((int)timer); _nextMoveTime.Reset(timer);
RemoveFlag(MovementGeneratorFlags.Paused); RemoveFlag(MovementGeneratorFlags.Paused);
} }
else else
@@ -73,7 +73,7 @@ namespace Game.Movement
public override void Resume(uint overrideTimer = 0) public override void Resume(uint overrideTimer = 0)
{ {
if (overrideTimer != 0) if (overrideTimer != 0)
_nextMoveTime.Reset((int)overrideTimer); _nextMoveTime.Reset(overrideTimer);
if (_nextMoveTime.Passed()) if (_nextMoveTime.Passed())
_nextMoveTime.Reset(1); // Needed so that Update does not behave as if node was reached _nextMoveTime.Reset(1); // Needed so that Update does not behave as if node was reached
@@ -251,7 +251,7 @@ namespace Game.Movement
if (waypoint.delay != 0) if (waypoint.delay != 0)
{ {
owner.ClearUnitState(UnitState.RoamingMove); owner.ClearUnitState(UnitState.RoamingMove);
_nextMoveTime.Reset((int)waypoint.delay); _nextMoveTime.Reset(waypoint.delay);
} }
if (waypoint.eventId != 0 && RandomHelper.URand(0, 99) < waypoint.eventChance) if (waypoint.eventId != 0 && RandomHelper.URand(0, 99) < waypoint.eventChance)
@@ -398,7 +398,7 @@ namespace Game.Movement
bool UpdateTimer(uint diff) bool UpdateTimer(uint diff)
{ {
_nextMoveTime.Update((int)diff); _nextMoveTime.Update(diff);
if (_nextMoveTime.Passed()) if (_nextMoveTime.Passed())
{ {
_nextMoveTime.Reset(0); _nextMoveTime.Reset(0);
@@ -411,7 +411,7 @@ namespace Game.Movement
public override void UnitSpeedChanged() { AddFlag(MovementGeneratorFlags.SpeedUpdatePending); } public override void UnitSpeedChanged() { AddFlag(MovementGeneratorFlags.SpeedUpdatePending); }
TimeTrackerSmall _nextMoveTime; TimeTracker _nextMoveTime;
uint _pathId; uint _pathId;
bool _repeating; bool _repeating;
bool _loadedFromDB; bool _loadedFromDB;