Skip to content

Commit

Permalink
Core/Common: Merge TimeTrackerSmall with TimeTracker
Browse files Browse the repository at this point in the history
  • Loading branch information
Carbenium committed Aug 1, 2020
1 parent e555163 commit 228696b
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 70 deletions.
2 changes: 1 addition & 1 deletion src/common/Collision/DynamicTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct DynTreeImpl : public ParentTree/*, public Intersectable*/
}
}

TimeTrackerSmall rebalance_timer;
TimeTracker rebalance_timer;
int unbalanced_times;
};

Expand Down
60 changes: 10 additions & 50 deletions src/common/Utilities/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,81 +115,41 @@ struct IntervalTimer
struct TimeTracker
{
public:

TimeTracker(time_t expiry)
: i_expiryTime(expiry)
{
}

void Update(time_t diff)
{
i_expiryTime -= diff;
}

bool Passed() const
{
return i_expiryTime <= 0;
}

void Reset(time_t interval)
{
i_expiryTime = interval;
}

time_t GetExpiry() const
{
return i_expiryTime;
}

private:

time_t i_expiryTime;
};

struct TimeTrackerSmall
{
public:

TimeTrackerSmall(int32 expiry = 0)
: i_expiryTime(expiry)
{
}

TimeTrackerSmall(Milliseconds expiry) : i_expiryTime(expiry.count()) { }
TimeTracker(int32 expiry = 0) : _expiryTime(expiry) { }
TimeTracker(Milliseconds expiry) : _expiryTime(expiry) { }

void Update(int32 diff)
{
i_expiryTime -= diff;
Update(Milliseconds(diff));
}

void Update(Milliseconds diff)
{
Update(diff.count());
_expiryTime -= diff;
}

bool Passed() const
{
return i_expiryTime <= 0;
return _expiryTime <= 0s;
}

void Reset(int32 interval)
void Reset(int32 expiry)
{
i_expiryTime = interval;
Reset(Milliseconds(expiry));
}

void Reset(Milliseconds expiry)
{
Reset(expiry.count());
_expiryTime = expiry;
}

Milliseconds GetExpiry() const
{
return Milliseconds(i_expiryTime);
return _expiryTime;
}

private:

int32 i_expiryTime;
Milliseconds _expiryTime;
};

struct PeriodicTimer
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Player/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -2425,7 +2425,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>

bool m_needsZoneUpdate;

TimeTrackerSmall m_groupUpdateTimer;
TimeTracker m_groupUpdateTimer;

private:
// internal common parts for CanStore/StoreItem functions
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Transport/Transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class TC_GAME_API Transport : public GameObject, public TransportBase

KeyFrameVec::const_iterator _currentFrame;
KeyFrameVec::const_iterator _nextFrame;
TimeTrackerSmall _positionChangeTimer;
TimeTracker _positionChangeTimer;
bool _isMoving;
bool _pendingStop;

Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Unit/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,7 @@ class TC_GAME_API Unit : public WorldObject

uint32 m_state; // Even derived shouldn't modify
uint32 m_lastManaUse; // msecs
TimeTrackerSmall m_splineSyncTimer;
TimeTracker m_splineSyncTimer;

DiminishingReturn m_Diminishing[DIMINISHING_MAX];

Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Groups/Group.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,6 @@ class TC_GAME_API Group
uint32 m_maxEnchantingLevel;
uint32 m_dbStoreId; // Represents the ID used in database (Can be reused by other groups if group was disbanded)
bool m_isLeaderOffline;
TimeTrackerSmall m_leaderOfflineTimer;
TimeTracker m_leaderOfflineTimer;
};
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ChaseMovementGenerator : public MovementGenerator, public AbstractFollower

std::unique_ptr<PathGenerator> _path;
Optional<Position> _lastTargetPosition;
TimeTrackerSmall _rangeCheckTimer;
TimeTracker _rangeCheckTimer;
bool _movingTowards = true;
bool _mutualChase = true;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class FollowMovementGenerator : public MovementGenerator, public AbstractFollowe
float const _range;
ChaseAngle const _angle;

TimeTrackerSmall _checkTimer;
TimeTracker _checkTimer;
std::unique_ptr<PathGenerator> _path;
Optional<Position> _lastTargetPosition;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class FormationMovementGenerator : public MovementGeneratorMedium<Creature, Form
bool _hasPredictedDestination;

Position _lastLeaderPosition;
TimeTrackerSmall _nextMoveTimer;
TimeTracker _nextMoveTimer;
};

#endif // TRINITY_FORMATIONMOVEMENTGENERATOR_H
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class GenericMovementGenerator : public MovementGenerator
Movement::MoveSplineInit _splineInit;
MovementGeneratorType _type;
uint32 _pointId;
TimeTrackerSmall _duration;
TimeTracker _duration;
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class WaypointMovementGenerator<Creature> : public MovementGeneratorMedium<Creat
return false;
}

TimeTrackerSmall _nextMoveTime;
TimeTracker _nextMoveTime;
uint32 _pathId;
bool _repeating;
bool _loadedFromDB;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ struct npc_wisp_invis : public ScriptedAI
}

private:
TimeTrackerSmall _timer;
TimeTracker _timer;
uint32 _creatureType;
uint32 _firstSpell;
uint32 _secondSpell;
Expand Down Expand Up @@ -429,7 +429,7 @@ struct npc_head : public ScriptedAI
}

TaskScheduler _scheduler;
TimeTrackerSmall _laughTimer;
TimeTracker _laughTimer;
ObjectGuid _bodyGUID;
uint32 _phase;
bool _withBody;
Expand Down Expand Up @@ -808,7 +808,7 @@ struct boss_headless_horseman : public ScriptedAI

InstanceScript* _instance;
TaskScheduler _scheduler;
TimeTrackerSmall _laughTimer;
TimeTracker _laughTimer;
ObjectGuid _headGUID;
uint32 _phase;
uint32 _id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ struct boss_high_inquisitor_fairbanks : public BossAI
}

private:
TimeTrackerSmall _healTimer;
TimeTracker _healTimer;
bool _powerWordShield;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ struct boss_scarlet_commander_mograine : public BossAI
}

private:
TimeTrackerSmall _killYellTimer;
TimeTracker _killYellTimer;
bool _fakeDeath;
bool _canDie;
};
Expand Down Expand Up @@ -428,7 +428,7 @@ struct boss_high_inquisitor_whitemane : public ScriptedAI
InstanceScript* _instance;
EventMap _events;
TaskScheduler _scheduler;
TimeTrackerSmall _killYellTimer;
TimeTracker _killYellTimer;
bool _ressurectionInProgress;
bool _canDie;
};
Expand Down
8 changes: 4 additions & 4 deletions tests/common/test-Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

#include "Timer.h"

TEST_CASE("TimerTrackerSmall: Check if time passed")
TEST_CASE("TimeTracker: Check if time passed")
{
TimeTrackerSmall tracker(1000 /*ms*/);
TimeTracker tracker(1000 /*ms*/);
REQUIRE_FALSE(tracker.Passed());
REQUIRE(tracker.GetExpiry() == 1s);

Expand All @@ -39,9 +39,9 @@ TEST_CASE("TimerTrackerSmall: Check if time passed")
REQUIRE(tracker.GetExpiry() == -500ms);
}

TEST_CASE("TimerTrackerSmall: Reset timer")
TEST_CASE("TimeTracker: Reset timer")
{
TimeTrackerSmall tracker(1000 /*ms*/);
TimeTracker tracker(1000 /*ms*/);
REQUIRE_FALSE(tracker.Passed());
REQUIRE(tracker.GetExpiry() == 1s);

Expand Down

0 comments on commit 228696b

Please sign in to comment.