aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorxinef1 <w.szyszko2@gmail.com>2017-03-02 02:19:25 +0100
committerariel- <ariel-@users.noreply.github.com>2017-03-01 22:19:25 -0300
commit7567cafec84080d26ea513242a1f540a823b8f9d (patch)
treef6f37a7cc4d06db0dbb0e08a01f8a18cf47ac955 /src
parent7011aabb56f061fc889ec42ce32b7605ceb35b53 (diff)
Ensure that all actions are compared to fixed point in time (ie. world update start) (#18910)
- Actions will not be dependent on processing moment - Increased GameObjects cooldown resolution to milliseconds, fixes arming time of traps to be exactly one second and not something from range (1000, 1999) - Created GameTime namespace and UpdateTime class and moved there some code out of world
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Achievements/AchievementMgr.cpp3
-rw-r--r--src/server/game/AuctionHouse/AuctionHouseMgr.cpp5
-rw-r--r--src/server/game/AuctionHouseBot/AuctionHouseBot.cpp3
-rw-r--r--src/server/game/Battlegrounds/Battleground.cpp5
-rw-r--r--src/server/game/Battlegrounds/BattlegroundQueue.cpp13
-rw-r--r--src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp5
-rw-r--r--src/server/game/Entities/Creature/Creature.cpp5
-rw-r--r--src/server/game/Entities/DynamicObject/DynamicObject.cpp3
-rw-r--r--src/server/game/Entities/GameObject/GameObject.cpp25
-rw-r--r--src/server/game/Entities/GameObject/GameObject.h2
-rw-r--r--src/server/game/Entities/Object/Object.cpp3
-rw-r--r--src/server/game/Entities/Player/Player.cpp19
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp15
-rw-r--r--src/server/game/Handlers/BattleGroundHandler.cpp5
-rw-r--r--src/server/game/Handlers/CharacterHandler.cpp3
-rw-r--r--src/server/game/Handlers/MiscHandler.cpp3
-rw-r--r--src/server/game/Handlers/MovementHandler.cpp3
-rw-r--r--src/server/game/Maps/MapScripts.cpp7
-rw-r--r--src/server/game/Spells/Spell.cpp7
-rw-r--r--src/server/game/Spells/SpellEffects.cpp2
-rw-r--r--src/server/game/Spells/SpellHistory.cpp23
-rw-r--r--src/server/game/Spells/SpellHistory.h4
-rw-r--r--src/server/game/Time/GameTime.cpp68
-rw-r--r--src/server/game/Time/GameTime.h48
-rw-r--r--src/server/game/Time/UpdateTime.cpp135
-rw-r--r--src/server/game/Time/UpdateTime.h74
-rw-r--r--src/server/game/Warden/Warden.cpp4
-rw-r--r--src/server/game/Warden/WardenMac.cpp4
-rw-r--r--src/server/game/Warden/WardenWin.cpp8
-rw-r--r--src/server/game/Weather/Weather.cpp4
-rw-r--r--src/server/game/World/World.cpp108
-rw-r--r--src/server/game/World/World.h21
-rw-r--r--src/server/scripts/Commands/cs_server.cpp8
-rw-r--r--src/server/scripts/Events/fireworks_show.cpp3
-rw-r--r--src/server/scripts/Northrend/IcecrownCitadel/icecrown_citadel.cpp2
-rw-r--r--src/server/scripts/Northrend/Naxxramas/boss_four_horsemen.cpp3
-rw-r--r--src/server/scripts/Northrend/Nexus/Nexus/boss_magus_telestra.cpp3
-rw-r--r--src/server/scripts/Northrend/Ulduar/Ulduar/boss_ignis.cpp3
-rw-r--r--src/server/scripts/Spells/spell_druid.cpp9
-rw-r--r--src/server/scripts/Spells/spell_generic.cpp5
-rw-r--r--src/server/scripts/Spells/spell_paladin.cpp3
-rw-r--r--src/server/scripts/World/areatrigger_scripts.cpp9
-rw-r--r--src/server/scripts/World/duel_reset.cpp3
-rw-r--r--src/server/scripts/World/go_scripts.cpp3
44 files changed, 495 insertions, 196 deletions
diff --git a/src/server/game/Achievements/AchievementMgr.cpp b/src/server/game/Achievements/AchievementMgr.cpp
index 6fd2037cf51..c2f09360562 100644
--- a/src/server/game/Achievements/AchievementMgr.cpp
+++ b/src/server/game/Achievements/AchievementMgr.cpp
@@ -27,6 +27,7 @@
#include "DBCEnums.h"
#include "DisableMgr.h"
#include "GameEventMgr.h"
+#include "GameTime.h"
#include "GridNotifiersImpl.h"
#include "Guild.h"
#include "GuildMgr.h"
@@ -412,7 +413,7 @@ bool AchievementCriteriaData::Meets(uint32 criteria_id, Player const* source, Un
birthday_tm.tm_year += birthday_login.nth_birthday;
time_t birthday = mktime(&birthday_tm);
- time_t now = sWorld->GetGameTime();
+ time_t now = GameTime::GetGameTime();
return now <= birthday + DAY && now >= birthday;
}
case ACHIEVEMENT_CRITERIA_DATA_TYPE_S_KNOWN_TITLE:
diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp
index bd736b24993..0fbcb67bb38 100644
--- a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp
+++ b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp
@@ -32,6 +32,7 @@
#include "Language.h"
#include "Log.h"
#include "CharacterCache.h"
+#include "GameTime.h"
enum eAuctionHouse
{
@@ -589,7 +590,7 @@ bool AuctionHouseObject::RemoveAuction(AuctionEntry* auction)
void AuctionHouseObject::Update()
{
- time_t curTime = sWorld->GetGameTime();
+ time_t curTime = GameTime::GetGameTime();
///- Handle expired auctions
// If storage is empty, no need to update. next == NULL in this case.
@@ -684,7 +685,7 @@ void AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player
int loc_idx = player->GetSession()->GetSessionDbLocaleIndex();
int locdbc_idx = player->GetSession()->GetSessionDbcLocale();
- time_t curTime = sWorld->GetGameTime();
+ time_t curTime = GameTime::GetGameTime();
PlayerGetAllThrottleMap::const_iterator itr = GetAllThrottleMap.find(player->GetGUID());
time_t throttleTime = itr != GetAllThrottleMap.end() ? itr->second : curTime;
diff --git a/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp b/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp
index 10013738c73..5643465212b 100644
--- a/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp
+++ b/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp
@@ -25,6 +25,7 @@
#include "AuctionHouseBot.h"
#include "AuctionHouseBotBuyer.h"
#include "AuctionHouseBotSeller.h"
+#include "GameTime.h"
AuctionBotConfig* AuctionBotConfig::instance()
{
@@ -494,7 +495,7 @@ void AuctionHouseBot::Rebuild(bool all)
for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = auctionHouse->GetAuctionsBegin(); itr != auctionHouse->GetAuctionsEnd(); ++itr)
if (!itr->second->owner || sAuctionBotConfig->IsBotChar(itr->second->owner)) // ahbot auction
if (all || itr->second->bid == 0) // expire now auction if no bid or forced
- itr->second->expire_time = sWorld->GetGameTime();
+ itr->second->expire_time = GameTime::GetGameTime();
}
}
diff --git a/src/server/game/Battlegrounds/Battleground.cpp b/src/server/game/Battlegrounds/Battleground.cpp
index 84a539bfaaa..6a2275ed415 100644
--- a/src/server/game/Battlegrounds/Battleground.cpp
+++ b/src/server/game/Battlegrounds/Battleground.cpp
@@ -34,6 +34,7 @@
#include "Util.h"
#include "WorldPacket.h"
#include "Transport.h"
+#include "GameTime.h"
namespace Trinity
{
@@ -309,7 +310,7 @@ inline void Battleground::_ProcessOfflineQueue()
BattlegroundPlayerMap::iterator itr = m_Players.find(*(m_OfflineQueue.begin()));
if (itr != m_Players.end())
{
- if (itr->second.OfflineRemoveTime <= sWorld->GetGameTime())
+ if (itr->second.OfflineRemoveTime <= GameTime::GetGameTime())
{
if (isBattleground() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_TRACK_DESERTERS) &&
(GetStatus() == STATUS_IN_PROGRESS || GetStatus() == STATUS_WAIT_JOIN))
@@ -1132,7 +1133,7 @@ void Battleground::EventPlayerLoggedOut(Player* player)
// player is correct pointer, it is checked in WorldSession::LogoutPlayer()
m_OfflineQueue.push_back(player->GetGUID());
- m_Players[guid].OfflineRemoveTime = sWorld->GetGameTime() + MAX_OFFLINE_TIME;
+ m_Players[guid].OfflineRemoveTime = GameTime::GetGameTime() + MAX_OFFLINE_TIME;
if (GetStatus() == STATUS_IN_PROGRESS)
{
// drop flag and handle other cleanups
diff --git a/src/server/game/Battlegrounds/BattlegroundQueue.cpp b/src/server/game/Battlegrounds/BattlegroundQueue.cpp
index 46d3c7e4b80..7643e1d3f5e 100644
--- a/src/server/game/Battlegrounds/BattlegroundQueue.cpp
+++ b/src/server/game/Battlegrounds/BattlegroundQueue.cpp
@@ -21,6 +21,7 @@
#include "BattlegroundMgr.h"
#include "BattlegroundQueue.h"
#include "Chat.h"
+#include "GameTime.h"
#include "Group.h"
#include "Log.h"
#include "Language.h"
@@ -138,7 +139,7 @@ GroupQueueInfo* BattlegroundQueue::AddGroup(Player* leader, Group* grp, Battlegr
ginfo->ArenaTeamId = arenateamid;
ginfo->IsRated = isRated;
ginfo->IsInvitedToBGInstanceGUID = 0;
- ginfo->JoinTime = getMSTime();
+ ginfo->JoinTime = GameTime::GetGameTimeMS();
ginfo->RemoveInviteTime = 0;
ginfo->Team = leader->GetTeam();
ginfo->ArenaTeamRating = ArenaRating;
@@ -156,7 +157,7 @@ GroupQueueInfo* BattlegroundQueue::AddGroup(Player* leader, Group* grp, Battlegr
index++;
TC_LOG_DEBUG("bg.battleground", "Adding Group to BattlegroundQueue bgTypeId : %u, bracket_id : %u, index : %u", BgTypeId, bracketId, index);
- uint32 lastOnlineTime = getMSTime();
+ uint32 lastOnlineTime = GameTime::GetGameTimeMS();
//announce world (this don't need mutex)
if (isRated && sWorld->getBoolConfig(CONFIG_ARENA_QUEUE_ANNOUNCER_ENABLE))
@@ -233,7 +234,7 @@ GroupQueueInfo* BattlegroundQueue::AddGroup(Player* leader, Group* grp, Battlegr
void BattlegroundQueue::PlayerInvitedToBGUpdateAverageWaitTime(GroupQueueInfo* ginfo, BattlegroundBracketId bracket_id)
{
- uint32 timeInQueue = getMSTimeDiff(ginfo->JoinTime, getMSTime());
+ uint32 timeInQueue = getMSTimeDiff(ginfo->JoinTime, GameTime::GetGameTimeMS());
uint8 team_index = TEAM_ALLIANCE; //default set to TEAM_ALLIANCE - or non rated arenas!
if (!ginfo->ArenaType)
{
@@ -444,7 +445,7 @@ bool BattlegroundQueue::InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg,
if (bg->isArena() && bg->isRated())
bg->SetArenaTeamIdForTeam(ginfo->Team, ginfo->ArenaTeamId);
- ginfo->RemoveInviteTime = getMSTime() + INVITE_ACCEPT_WAIT_TIME;
+ ginfo->RemoveInviteTime = GameTime::GetGameTimeMS() + INVITE_ACCEPT_WAIT_TIME;
// loop through the players
for (std::map<ObjectGuid, PlayerQueueInfo*>::iterator itr = ginfo->Players.begin(); itr != ginfo->Players.end(); ++itr)
@@ -637,7 +638,7 @@ bool BattlegroundQueue::CheckPremadeMatch(BattlegroundBracketId bracket_id, uint
// this could be 2 cycles but i'm checking only first team in queue - it can cause problem -
// if first is invited to BG and seconds timer expired, but we can ignore it, because players have only 80 seconds to click to enter bg
// and when they click or after 80 seconds the queue info is removed from queue
- uint32 time_before = getMSTime() - sWorld->getIntConfig(CONFIG_BATTLEGROUND_PREMADE_GROUP_WAIT_FOR_MATCH);
+ uint32 time_before = GameTime::GetGameTimeMS() - sWorld->getIntConfig(CONFIG_BATTLEGROUND_PREMADE_GROUP_WAIT_FOR_MATCH);
for (uint32 i = 0; i < BG_TEAMS_COUNT; i++)
{
if (!m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE + i].empty())
@@ -918,7 +919,7 @@ void BattlegroundQueue::BattlegroundQueueUpdate(uint32 /*diff*/, BattlegroundTyp
// the discard time is current_time - time_to_discard, teams that joined after that, will have their ratings taken into account
// else leave the discard time on 0, this way all ratings will be discarded
// this has to be signed value - when the server starts, this value would be negative and thus overflow
- int32 discardTime = getMSTime() - sBattlegroundMgr->GetRatingDiscardTimer();
+ int32 discardTime = GameTime::GetGameTimeMS() - sBattlegroundMgr->GetRatingDiscardTimer();
// we need to find 2 teams which will play next game
GroupsQueueType::iterator itr_teams[BG_TEAMS_COUNT];
diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp
index 6defebe1c59..95bb66f66d7 100644
--- a/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp
+++ b/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp
@@ -18,6 +18,7 @@
#include "BattlegroundSA.h"
#include "GameObject.h"
+#include "GameTime.h"
#include "Language.h"
#include "ObjectMgr.h"
#include "Player.h"
@@ -985,11 +986,11 @@ void BattlegroundSA::UpdateDemolisherSpawns()
// Demolisher is not in list
if (DemoliserRespawnList.find(i) == DemoliserRespawnList.end())
{
- DemoliserRespawnList[i] = getMSTime()+30000;
+ DemoliserRespawnList[i] = GameTime::GetGameTimeMS()+30000;
}
else
{
- if (DemoliserRespawnList[i] < getMSTime())
+ if (DemoliserRespawnList[i] < GameTime::GetGameTimeMS())
{
Demolisher->Relocate(BG_SA_NpcSpawnlocs[i]);
Demolisher->Respawn();
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index f25d3f63fb3..cbbaf917417 100644
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -26,6 +26,7 @@
#include "DatabaseEnv.h"
#include "Formulas.h"
#include "GameEventMgr.h"
+#include "GameTime.h"
#include "GossipDef.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
@@ -2332,7 +2333,7 @@ bool Creature::CanCreatureAttack(Unit const* victim, bool /*force*/) const
return true;
// don't check distance to home position if recently damaged, this should include taunt auras
- if (!isWorldBoss() && (GetLastDamagedTime() > sWorld->GetGameTime() || HasAuraType(SPELL_AURA_MOD_TAUNT)))
+ if (!isWorldBoss() && (GetLastDamagedTime() > GameTime::GetGameTime() || HasAuraType(SPELL_AURA_MOD_TAUNT)))
return true;
}
@@ -3087,7 +3088,7 @@ void Creature::ReleaseFocus(Spell const* focusSpell, bool withDelay)
ClearUnitState(UNIT_STATE_CANNOT_TURN);
m_focusSpell = nullptr;
- m_focusDelay = (!IsPet() && withDelay) ? getMSTime() : 0; // don't allow re-target right away to prevent visual bugs
+ m_focusDelay = (!IsPet() && withDelay) ? GameTime::GetGameTimeMS() : 0; // don't allow re-target right away to prevent visual bugs
}
void Creature::StartPickPocketRefillTimer()
diff --git a/src/server/game/Entities/DynamicObject/DynamicObject.cpp b/src/server/game/Entities/DynamicObject/DynamicObject.cpp
index 1fbe47bf640..b9be22478f6 100644
--- a/src/server/game/Entities/DynamicObject/DynamicObject.cpp
+++ b/src/server/game/Entities/DynamicObject/DynamicObject.cpp
@@ -21,6 +21,7 @@
#include "World.h"
#include "ObjectAccessor.h"
#include "DatabaseEnv.h"
+#include "GameTime.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "ScriptMgr.h"
@@ -103,7 +104,7 @@ bool DynamicObject::CreateDynamicObject(ObjectGuid::LowType guidlow, Unit* caste
SetByteValue(DYNAMICOBJECT_BYTES, 0, type);
SetUInt32Value(DYNAMICOBJECT_SPELLID, spellId);
SetFloatValue(DYNAMICOBJECT_RADIUS, radius);
- SetUInt32Value(DYNAMICOBJECT_CASTTIME, getMSTime());
+ SetUInt32Value(DYNAMICOBJECT_CASTTIME, GameTime::GetGameTimeMS());
if (IsWorldObject())
setActive(true); //must before add to map to be put in world container
diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp
index 301f78d8d0e..3869c72c73f 100644
--- a/src/server/game/Entities/GameObject/GameObject.cpp
+++ b/src/server/game/Entities/GameObject/GameObject.cpp
@@ -21,6 +21,7 @@
#include "CellImpl.h"
#include "CreatureAISelector.h"
#include "GameObjectModel.h"
+#include "GameTime.h"
#include "GridNotifiersImpl.h"
#include "Group.h"
#include "GroupMgr.h"
@@ -395,10 +396,10 @@ void GameObject::Update(uint32 diff)
// Bombs
if (goInfo->trap.type == 2)
// Hardcoded tooltip value
- m_cooldownTime = time(NULL) + 10;
+ m_cooldownTime = GameTime::GetGameTimeMS() + 10 * IN_MILLISECONDS;
else if (Unit* owner = GetOwner())
if (owner->IsInCombat())
- m_cooldownTime = time(NULL) + goInfo->trap.startDelay;
+ m_cooldownTime = GameTime::GetGameTimeMS() + goInfo->trap.startDelay * IN_MILLISECONDS;
SetLootState(GO_READY);
break;
@@ -550,7 +551,7 @@ void GameObject::Update(uint32 diff)
GameObjectTemplate const* goInfo = GetGOInfo();
if (goInfo->type == GAMEOBJECT_TYPE_TRAP)
{
- if (m_cooldownTime >= time(NULL))
+ if (GameTime::GetGameTimeMS() < m_cooldownTime)
break;
// Type 2 (bomb) does not need to be triggered by a unit and despawns after casting its spell.
@@ -617,16 +618,14 @@ void GameObject::Update(uint32 diff)
{
case GAMEOBJECT_TYPE_DOOR:
case GAMEOBJECT_TYPE_BUTTON:
- if (m_cooldownTime && (m_cooldownTime < time(NULL)))
+ if (m_cooldownTime && GameTime::GetGameTimeMS() >= m_cooldownTime)
ResetDoorOrButton();
break;
case GAMEOBJECT_TYPE_GOOBER:
- if (m_cooldownTime < time(NULL))
+ if (GameTime::GetGameTimeMS() >= m_cooldownTime)
{
RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_IN_USE);
-
SetLootState(GO_JUST_DEACTIVATED);
- m_cooldownTime = 0;
}
break;
case GAMEOBJECT_TYPE_CHEST:
@@ -659,7 +658,7 @@ void GameObject::Update(uint32 diff)
CastSpell(target, goInfo->trap.spellId);
// Template value or 4 seconds
- m_cooldownTime = time(NULL) + (goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4));
+ m_cooldownTime = GameTime::GetGameTimeMS() + (goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4)) * IN_MILLISECONDS;
if (goInfo->trap.type == 1)
SetLootState(GO_JUST_DEACTIVATED);
@@ -1205,7 +1204,7 @@ void GameObject::UseDoorOrButton(uint32 time_to_restore, bool alternative /* = f
SwitchDoorOrButton(true, alternative);
SetLootState(GO_ACTIVATED, user);
- m_cooldownTime = time_to_restore ? (time(NULL) + time_to_restore) : 0;
+ m_cooldownTime = GameTime::GetGameTimeMS() + time_to_restore;
}
void GameObject::SetGoArtKit(uint8 kit)
@@ -1263,10 +1262,10 @@ void GameObject::Use(Unit* user)
// If cooldown data present in template
if (uint32 cooldown = GetGOInfo()->GetCooldown())
{
- if (m_cooldownTime > sWorld->GetGameTime())
+ if (GameTime::GetGameTimeMS() < m_cooldownTime)
return;
- m_cooldownTime = sWorld->GetGameTime() + cooldown;
+ m_cooldownTime = GameTime::GetGameTimeMS() + cooldown * IN_MILLISECONDS;
}
switch (GetGoType())
@@ -1293,7 +1292,7 @@ void GameObject::Use(Unit* user)
if (goInfo->trap.spellId)
CastSpell(user, goInfo->trap.spellId);
- m_cooldownTime = time(NULL) + (goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4)); // template or 4 seconds
+ m_cooldownTime = GameTime::GetGameTimeMS() + (goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4)) * IN_MILLISECONDS; // template or 4 seconds
if (goInfo->trap.type == 1) // Deactivate after trigger
SetLootState(GO_JUST_DEACTIVATED);
@@ -1440,7 +1439,7 @@ void GameObject::Use(Unit* user)
else
SetGoState(GO_STATE_ACTIVE);
- m_cooldownTime = time(NULL) + info->GetAutoCloseTime();
+ m_cooldownTime = GameTime::GetGameTimeMS() + info->GetAutoCloseTime();
// cast this spell later if provided
spellId = info->goober.spellId;
diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h
index 08dd5039f07..4ef0c9c2e5f 100644
--- a/src/server/game/Entities/GameObject/GameObject.h
+++ b/src/server/game/Entities/GameObject/GameObject.h
@@ -518,7 +518,7 @@ struct GameObjectTemplate
case GAMEOBJECT_TYPE_AREADAMAGE: autoCloseTime = areadamage.autoCloseTime; break;
default: break;
}
- return autoCloseTime / IN_MILLISECONDS; // prior to 3.0.3, conversion was / 0x10000;
+ return autoCloseTime; // prior to 3.0.3, conversion was / 0x10000;
}
uint32 GetLootId() const
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp
index 0267229d198..a9a2425748f 100644
--- a/src/server/game/Entities/Object/Object.cpp
+++ b/src/server/game/Entities/Object/Object.cpp
@@ -43,6 +43,7 @@
#include "MovementPacketBuilder.h"
#include "BattlefieldMgr.h"
#include "Battleground.h"
+#include "GameTime.h"
Object::Object() : m_PackGUID(sizeof(uint64)+1)
{
@@ -461,7 +462,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const
if (go && go->ToTransport())
*data << uint32(go->GetGOValue()->Transport.PathProgress);
else
- *data << uint32(getMSTime());
+ *data << uint32(GameTime::GetGameTimeMS());
}
// 0x80
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index 4fa6c929810..0e18bffc92e 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -40,6 +40,7 @@
#include "DisableMgr.h"
#include "Formulas.h"
#include "GameEventMgr.h"
+#include "GameTime.h"
#include "GossipDef.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
@@ -1223,7 +1224,7 @@ void Player::Update(uint32 p_time)
_cinematicMgr->m_cinematicDiff += p_time;
if (_cinematicMgr->m_cinematicCamera && _cinematicMgr->m_activeCinematicCameraId && GetMSTimeDiffToNow(_cinematicMgr->m_lastCinematicCheck) > CINEMATIC_UPDATEDIFF)
{
- _cinematicMgr->m_lastCinematicCheck = getMSTime();
+ _cinematicMgr->m_lastCinematicCheck = GameTime::GetGameTimeMS();
_cinematicMgr->UpdateCinematicLocation(p_time);
}
@@ -3919,7 +3920,7 @@ uint32 Player::ResetTalentsCost() const
return 10*GOLD;
else
{
- uint64 months = (sWorld->GetGameTime() - m_resetTalentsTime)/MONTH;
+ uint64 months = (GameTime::GetGameTime() - m_resetTalentsTime)/MONTH;
if (months > 0)
{
// This cost will be reduced by a rate of 5 gold per month
@@ -18476,10 +18477,10 @@ void Player::_LoadQuestStatus(PreparedQueryResult result)
{
AddTimedQuest(quest_id);
- if (quest_time <= sWorld->GetGameTime())
+ if (quest_time <= GameTime::GetGameTime())
questStatusData.Timer = 1;
else
- questStatusData.Timer = uint32((quest_time - sWorld->GetGameTime()) * IN_MILLISECONDS);
+ questStatusData.Timer = uint32((quest_time - GameTime::GetGameTime()) * IN_MILLISECONDS);
}
else
quest_time = 0;
@@ -19902,7 +19903,7 @@ void Player::_SaveQuestStatus(SQLTransaction& trans)
stmt->setUInt32(index++, statusItr->first);
stmt->setUInt8(index++, uint8(statusItr->second.Status));
stmt->setBool(index++, statusItr->second.Explored);
- stmt->setUInt32(index++, uint32(statusItr->second.Timer / IN_MILLISECONDS+ sWorld->GetGameTime()));
+ stmt->setUInt32(index++, uint32(statusItr->second.Timer / IN_MILLISECONDS+ GameTime::GetGameTime()));
for (uint8 i = 0; i < 4; i++)
stmt->setUInt16(index++, statusItr->second.CreatureOrGOCount[i]);
@@ -22633,7 +22634,7 @@ void Player::SendInitialPacketsBeforeAddToMap()
SendEquipmentSetList();
data.Initialize(SMSG_LOGIN_SETTIMESPEED, 4 + 4 + 4);
- data.AppendPackedTime(sWorld->GetGameTime());
+ data.AppendPackedTime(GameTime::GetGameTime());
data << float(0.01666667f); // game speed
data << uint32(0); // added in 3.1.2
GetSession()->SendPacket(&data);
@@ -22772,7 +22773,7 @@ void Player::ApplyEquipCooldown(Item* pItem)
if (pItem->GetTemplate()->Flags & ITEM_FLAG_NO_EQUIP_COOLDOWN)
return;
- std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
+ std::chrono::steady_clock::time_point now = GameTime::GetGameTimeSteadyPoint();
for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i)
{
_Spell const& spellData = pItem->GetTemplate()->Spells[i];
@@ -26088,7 +26089,7 @@ void Player::ResetTimeSync()
m_timeSyncCounter = 0;
m_timeSyncTimer = 0;
m_timeSyncClient = 0;
- m_timeSyncServer = getMSTime();
+ m_timeSyncServer = GameTime::GetGameTimeMS();
}
void Player::SendTimeSync()
@@ -26099,7 +26100,7 @@ void Player::SendTimeSync()
// Schedule next sync in 10 sec
m_timeSyncTimer = 10000;
- m_timeSyncServer = getMSTime();
+ m_timeSyncServer = GameTime::GetGameTimeMS();
}
void Player::SetReputation(uint32 factionentry, uint32 value)
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index 8651d9c24f4..4449ed39a17 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -31,6 +31,7 @@
#include "CreatureGroups.h"
#include "Creature.h"
#include "Formulas.h"
+#include "GameTime.h"
#include "GridNotifiersImpl.h"
#include "Group.h"
#include "InstanceSaveMgr.h"
@@ -867,7 +868,7 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam
{
// Part of Evade mechanics. DoT's and Thorns / Retribution Aura do not contribute to this
if (damagetype != DOT && damage > 0 && !victim->GetOwnerGUID().IsPlayer() && (!spellProto || !spellProto->HasAura(SPELL_AURA_DAMAGE_SHIELD)))
- victim->ToCreature()->SetLastDamagedTime(sWorld->GetGameTime() + MAX_AGGRO_RESET_TIME);
+ victim->ToCreature()->SetLastDamagedTime(GameTime::GetGameTime() + MAX_AGGRO_RESET_TIME);
victim->AddThreat(this, float(damage), damageSchoolMask, spellProto);
}
@@ -8578,7 +8579,7 @@ void Unit::Mount(uint32 mount, uint32 VehicleId, uint32 creatureEntry)
WorldPacket data(SMSG_MOVE_SET_COLLISION_HGT, GetPackGUID().size() + 4 + 4);
data << GetPackGUID();
- data << uint32(sWorld->GetGameTime()); // Packet counter
+ data << uint32(GameTime::GetGameTime()); // Packet counter
data << player->GetCollisionHeight(true);
player->GetSession()->SendPacket(&data);
}
@@ -8598,7 +8599,7 @@ void Unit::Dismount()
{
WorldPacket data(SMSG_MOVE_SET_COLLISION_HGT, GetPackGUID().size() + 4 + 4);
data << GetPackGUID();
- data << uint32(sWorld->GetGameTime()); // Packet counter
+ data << uint32(GameTime::GetGameTime()); // Packet counter
data << thisPlayer->GetCollisionHeight(false);
thisPlayer->GetSession()->SendPacket(&data);
}
@@ -10013,7 +10014,7 @@ void Unit::ApplyDiminishingAura(DiminishingGroup group, bool apply)
// Remember time after last aura from group removed
if (!diminish.stack)
- diminish.hitTime = getMSTime();
+ diminish.hitTime = GameTime::GetGameTimeMS();
}
}
@@ -11220,7 +11221,7 @@ void Unit::ProcSkillsAndReactives(bool isVictim, Unit* procTarget, uint32 typeMa
void Unit::GetProcAurasTriggeredOnEvent(AuraApplicationProcContainer& aurasTriggeringProc, AuraApplicationList* procAuras, ProcEventInfo& eventInfo)
{
- std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
+ std::chrono::steady_clock::time_point now = GameTime::GetGameTimeSteadyPoint();
// use provided list of auras which can proc
if (procAuras)
@@ -11821,7 +11822,7 @@ float Unit::GetAPMultiplier(WeaponAttackType attType, bool normalized) const
bool Unit::IsUnderLastManaUseEffect() const
{
- return getMSTimeDiff(m_lastManaUse, getMSTime()) < 5000;
+ return getMSTimeDiff(m_lastManaUse, GameTime::GetGameTimeMS()) < 5000;
}
void Unit::SetContestedPvP(Player* attackedPlayer)
@@ -13779,7 +13780,7 @@ void Unit::BuildMovementPacket(ByteBuffer *data) const
{
*data << uint32(GetUnitMovementFlags()); // movement flags
*data << uint16(GetExtraUnitMovementFlags()); // 2.3.0
- *data << uint32(getMSTime()); // time / counter
+ *data << uint32(GameTime::GetGameTimeMS()); // time / counter
*data << GetPositionX();
*data << GetPositionY();
*data << GetPositionZMinusOffset();
diff --git a/src/server/game/Handlers/BattleGroundHandler.cpp b/src/server/game/Handlers/BattleGroundHandler.cpp
index 386f52eb455..ba5cb325098 100644
--- a/src/server/game/Handlers/BattleGroundHandler.cpp
+++ b/src/server/game/Handlers/BattleGroundHandler.cpp
@@ -27,6 +27,7 @@
#include "BattlegroundMgr.h"
#include "Battleground.h"
#include "Chat.h"
+#include "GameTime.h"
#include "Language.h"
#include "Log.h"
#include "Player.h"
@@ -577,7 +578,7 @@ void WorldSession::HandleBattlefieldStatusOpcode(WorldPacket & /*recvData*/)
bg = sBattlegroundMgr->GetBattleground(ginfo.IsInvitedToBGInstanceGUID, bgTypeId);
if (!bg)
continue;
- uint32 remainingTime = getMSTimeDiff(getMSTime(), ginfo.RemoveInviteTime);
+ uint32 remainingTime = getMSTimeDiff(GameTime::GetGameTimeMS(), ginfo.RemoveInviteTime);
// send status invited to Battleground
sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bg, i, STATUS_WAIT_JOIN, remainingTime, 0, arenaType, 0);
SendPacket(&data);
@@ -595,7 +596,7 @@ void WorldSession::HandleBattlefieldStatusOpcode(WorldPacket & /*recvData*/)
uint32 avgTime = bgQueue.GetAverageQueueWaitTime(&ginfo, bracketEntry->GetBracketId());
// send status in Battleground Queue
- sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bg, i, STATUS_WAIT_QUEUE, avgTime, getMSTimeDiff(ginfo.JoinTime, getMSTime()), arenaType, 0);
+ sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bg, i, STATUS_WAIT_QUEUE, avgTime, getMSTimeDiff(ginfo.JoinTime, GameTime::GetGameTimeMS()), arenaType, 0);
SendPacket(&data);
}
}
diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp
index e55131c5946..15b408cd87d 100644
--- a/src/server/game/Handlers/CharacterHandler.cpp
+++ b/src/server/game/Handlers/CharacterHandler.cpp
@@ -25,6 +25,7 @@
#include "Chat.h"
#include "Common.h"
#include "DatabaseEnv.h"
+#include "GameTime.h"
#include "Group.h"
#include "Guild.h"
#include "GuildMgr.h"
@@ -860,7 +861,7 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder* holder)
LoginDatabase.Execute(stmt);
- pCurrChar->SetInGameTime(getMSTime());
+ pCurrChar->SetInGameTime(GameTime::GetGameTimeMS());
// announce group about member online (must be after add to player list to receive announce to self)
if (Group* group = pCurrChar->GetGroup())
diff --git a/src/server/game/Handlers/MiscHandler.cpp b/src/server/game/Handlers/MiscHandler.cpp
index daf6dea438b..3f408be545a 100644
--- a/src/server/game/Handlers/MiscHandler.cpp
+++ b/src/server/game/Handlers/MiscHandler.cpp
@@ -23,6 +23,7 @@
#include "Opcodes.h"
#include "Log.h"
#include "Player.h"
+#include "GameTime.h"
#include "GossipDef.h"
#include "World.h"
#include "ObjectMgr.h"
@@ -1253,7 +1254,7 @@ void WorldSession::HandleTimeSyncResp(WorldPacket& recvData)
TC_LOG_DEBUG("network", "Time sync received: counter %u, client ticks %u, time since last sync %u", counter, clientTicks, clientTicks - _player->m_timeSyncClient);
- uint32 ourTicks = clientTicks + (getMSTime() - _player->m_timeSyncServer);
+ uint32 ourTicks = clientTicks + (GameTime::GetGameTimeMS() - _player->m_timeSyncServer);
// diff should be small
TC_LOG_DEBUG("network", "Our ticks: %u, diff %u, latency %u", ourTicks, ourTicks - clientTicks, GetLatency());
diff --git a/src/server/game/Handlers/MovementHandler.cpp b/src/server/game/Handlers/MovementHandler.cpp
index d9e30ad79e9..c3cf39488ff 100644
--- a/src/server/game/Handlers/MovementHandler.cpp
+++ b/src/server/game/Handlers/MovementHandler.cpp
@@ -30,6 +30,7 @@
#include "InstanceSaveMgr.h"
#include "ObjectMgr.h"
#include "Vehicle.h"
+#include "GameTime.h"
#define MOVEMENT_PACKET_TIME_DELAY 0
@@ -358,7 +359,7 @@ void WorldSession::HandleMovementOpcodes(WorldPacket& recvData)
plrMover->SetInWater(!plrMover->IsInWater() || plrMover->GetBaseMap()->IsUnderWater(movementInfo.pos.GetPositionX(), movementInfo.pos.GetPositionY(), movementInfo.pos.GetPositionZ()));
}
- uint32 mstime = getMSTime();
+ uint32 mstime = GameTime::GetGameTimeMS();
/*----------------------*/
if (m_clientTimeDelay == 0)
m_clientTimeDelay = mstime - movementInfo.time;
diff --git a/src/server/game/Maps/MapScripts.cpp b/src/server/game/Maps/MapScripts.cpp
index 2b606f32875..f5c8cd971b9 100644
--- a/src/server/game/Maps/MapScripts.cpp
+++ b/src/server/game/Maps/MapScripts.cpp
@@ -17,6 +17,7 @@
*/
#include "CellImpl.h"
+#include "GameTime.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "GossipDef.h"
@@ -55,7 +56,7 @@ void Map::ScriptsStart(ScriptMapMap const& scripts, uint32 id, Object* source, O
sa.ownerGUID = ownerGUID;
sa.script = &iter->second;
- m_scriptSchedule.insert(ScriptScheduleMap::value_type(time_t(sWorld->GetGameTime() + iter->first), sa));
+ m_scriptSchedule.insert(ScriptScheduleMap::value_type(time_t(GameTime::GetGameTime() + iter->first), sa));
if (iter->first == 0)
immedScript = true;
@@ -85,7 +86,7 @@ void Map::ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* sou
sa.ownerGUID = ownerGUID;
sa.script = &script;
- m_scriptSchedule.insert(ScriptScheduleMap::value_type(time_t(sWorld->GetGameTime() + delay), sa));
+ m_scriptSchedule.insert(ScriptScheduleMap::value_type(time_t(GameTime::GetGameTime() + delay), sa));
sMapMgr->IncreaseScheduledScriptsCount();
@@ -285,7 +286,7 @@ void Map::ScriptsProcess()
///- Process overdue queued scripts
ScriptScheduleMap::iterator iter = m_scriptSchedule.begin();
// ok as multimap is a *sorted* associative container
- while (!m_scriptSchedule.empty() && (iter->first <= sWorld->GetGameTime()))
+ while (!m_scriptSchedule.empty() && (iter->first <= GameTime::GetGameTime()))
{
ScriptAction const& step = iter->second;
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp
index 0121db50ff5..be5b7531313 100644
--- a/src/server/game/Spells/Spell.cpp
+++ b/src/server/game/Spells/Spell.cpp
@@ -20,6 +20,7 @@
#include "DatabaseEnv.h"
#include "WorldPacket.h"
#include "WorldSession.h"
+#include "GameTime.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "Opcodes.h"
@@ -2224,7 +2225,7 @@ void Spell::DoAllEffectOnTarget(TargetInfo* target)
if (unit->IsAlive() != target->alive)
return;
- if (getState() == SPELL_STATE_DELAYED && !m_spellInfo->IsPositive() && (getMSTime() - target->timeDelay) <= unit->m_lastSanctuaryTime)
+ if (getState() == SPELL_STATE_DELAYED && !m_spellInfo->IsPositive() && (GameTime::GetGameTimeMS() - target->timeDelay) <= unit->m_lastSanctuaryTime)
return; // No missinfo in that case
// Get original caster (if exist) and calculate damage/healing from him data
@@ -3988,7 +3989,7 @@ void Spell::SendSpellGo()
data << uint8(m_cast_count); // pending spell cast?
data << uint32(m_spellInfo->Id); // spellId
data << uint32(castFlags); // cast flags
- data << uint32(getMSTime()); // timestamp
+ data << uint32(GameTime::GetGameTimeMS()); // timestamp
WriteSpellGoTargets(&data);
@@ -4473,7 +4474,7 @@ void Spell::TakePower()
// Set the five second timer
if (powerType == POWER_MANA && m_powerCost > 0)
- m_caster->SetLastManaUse(getMSTime());
+ m_caster->SetLastManaUse(GameTime::GetGameTimeMS());
}
void Spell::TakeAmmo()
diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp
index e93b95c028e..e8ff2ced069 100644
--- a/src/server/game/Spells/SpellEffects.cpp
+++ b/src/server/game/Spells/SpellEffects.cpp
@@ -3991,7 +3991,7 @@ void Spell::EffectSanctuary(SpellEffIndex /*effIndex*/)
++itr;
}
- unitTarget->m_lastSanctuaryTime = getMSTime();
+ unitTarget->m_lastSanctuaryTime = GameTime::GetGameTimeMS();
// Vanish allows to remove all threat and cast regular stealth so other spells can be used
if (m_caster->GetTypeId() == TYPEID_PLAYER
diff --git a/src/server/game/Spells/SpellHistory.cpp b/src/server/game/Spells/SpellHistory.cpp
index a3c30f02329..599314e2ec4 100644
--- a/src/server/game/Spells/SpellHistory.cpp
+++ b/src/server/game/Spells/SpellHistory.cpp
@@ -21,7 +21,6 @@
#include "Player.h"
#include "SpellInfo.h"
#include "Spell.h"
-#include "World.h"
#include "Opcodes.h"
SpellHistory::Clock::duration const SpellHistory::InfinityCooldownDelay = std::chrono::duration_cast<SpellHistory::Clock::duration>(std::chrono::seconds(MONTH));
@@ -137,7 +136,7 @@ void SpellHistory::SaveToDB(SQLTransaction& trans)
void SpellHistory::Update()
{
- Clock::time_point now = Clock::now();
+ Clock::time_point now = GameTime::GetGameTimeSystemPoint();
for (auto itr = _categoryCooldowns.begin(); itr != _categoryCooldowns.end();)
{
if (itr->second->CategoryEnd < now)
@@ -199,7 +198,7 @@ bool SpellHistory::IsReady(SpellInfo const* spellInfo, uint32 itemId /*= 0*/, bo
template<>
void SpellHistory::WritePacket<Pet>(WorldPacket& packet) const
{
- Clock::time_point now = Clock::now();
+ Clock::time_point now = GameTime::GetGameTimeSystemPoint();
uint8 cooldownsCount = _spellCooldowns.size();
packet << uint8(cooldownsCount);
@@ -236,7 +235,7 @@ void SpellHistory::WritePacket<Pet>(WorldPacket& packet) const
template<>
void SpellHistory::WritePacket<Player>(WorldPacket& packet) const
{
- Clock::time_point now = Clock::now();
+ Clock::time_point now = GameTime::GetGameTimeSystemPoint();
Clock::time_point infTime = now + InfinityCooldownDelayCheck;
packet << uint16(_spellCooldowns.size());
@@ -286,7 +285,7 @@ void SpellHistory::StartCooldown(SpellInfo const* spellInfo, uint32 itemId, Spel
GetCooldownDurations(spellInfo, itemId, &cooldown, &categoryId, &categoryCooldown);
- Clock::time_point curTime = Clock::now();
+ Clock::time_point curTime = GameTime::GetGameTimeSystemPoint();
Clock::time_point catrecTime;
Clock::time_point recTime;
bool needsCooldownPacket = false;
@@ -409,7 +408,7 @@ void SpellHistory::ModifyCooldown(uint32 spellId, int32 cooldownModMs)
if (!cooldownModMs || itr == _spellCooldowns.end())
return;
- Clock::time_point now = Clock::now();
+ Clock::time_point now = GameTime::GetGameTimeSystemPoint();
Clock::duration offset = std::chrono::duration_cast<Clock::duration>(std::chrono::milliseconds(cooldownModMs));
if (itr->second.CooldownEnd + offset > now)
itr->second.CooldownEnd += offset;
@@ -503,7 +502,7 @@ uint32 SpellHistory::GetRemainingCooldown(SpellInfo const* spellInfo) const
end = catItr->second->CategoryEnd;
}
- Clock::time_point now = Clock::now();
+ Clock::time_point now = GameTime::GetGameTimeSystemPoint();
if (end < now)
return 0;
@@ -513,7 +512,7 @@ uint32 SpellHistory::GetRemainingCooldown(SpellInfo const* spellInfo) const
void SpellHistory::LockSpellSchool(SpellSchoolMask schoolMask, uint32 lockoutTime)
{
- Clock::time_point now = Clock::now();
+ Clock::time_point now = GameTime::GetGameTimeSystemPoint();
Clock::time_point lockoutEnd = now + std::chrono::duration_cast<Clock::duration>(std::chrono::milliseconds(lockoutTime));
for (uint32 i = 0; i < MAX_SPELL_SCHOOL; ++i)
if (SpellSchoolMask(1 << i) & schoolMask)
@@ -570,7 +569,7 @@ void SpellHistory::LockSpellSchool(SpellSchoolMask schoolMask, uint32 lockoutTim
bool SpellHistory::IsSchoolLocked(SpellSchoolMask schoolMask) const
{
- Clock::time_point now = Clock::now();
+ Clock::time_point now = GameTime::GetGameTimeSystemPoint();
for (uint32 i = 0; i < MAX_SPELL_SCHOOL; ++i)
if (SpellSchoolMask(1 << i) & schoolMask)
if (_schoolLockouts[i] > now)
@@ -582,12 +581,12 @@ bool SpellHistory::IsSchoolLocked(SpellSchoolMask schoolMask) const
bool SpellHistory::HasGlobalCooldown(SpellInfo const* spellInfo) const
{
auto itr = _globalCooldowns.find(spellInfo->StartRecoveryCategory);
- return itr != _globalCooldowns.end() && itr->second > Clock::now();
+ return itr != _globalCooldowns.end() && itr->second > GameTime::GetGameTimeSystemPoint();
}
void SpellHistory::AddGlobalCooldown(SpellInfo const* spellInfo, uint32 duration)
{
- _globalCooldowns[spellInfo->StartRecoveryCategory] = Clock::now() + std::chrono::duration_cast<Clock::duration>(std::chrono::milliseconds(duration));
+ _globalCooldowns[spellInfo->StartRecoveryCategory] = GameTime::GetGameTimeSystemPoint() + std::chrono::duration_cast<Clock::duration>(std::chrono::milliseconds(duration));
}
void SpellHistory::CancelGlobalCooldown(SpellInfo const* spellInfo)
@@ -709,7 +708,7 @@ void SpellHistory::RestoreCooldownStateAfterDuel()
for (auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end(); ++itr)
{
- Clock::time_point now = Clock::now();
+ Clock::time_point now = GameTime::GetGameTimeSystemPoint();
uint32 cooldownDuration = itr->second.CooldownEnd > now ? std::chrono::duration_cast<std::chrono::milliseconds>(itr->second.CooldownEnd - now).count() : 0;
// cooldownDuration must be between 0 and 10 minutes in order to avoid any visual bugs
diff --git a/src/server/game/Spells/SpellHistory.h b/src/server/game/Spells/SpellHistory.h
index 8911c4fe7aa..ed1ba883c5b 100644
--- a/src/server/game/Spells/SpellHistory.h
+++ b/src/server/game/Spells/SpellHistory.h
@@ -21,7 +21,7 @@
#include "SharedDefines.h"
#include "QueryResult.h"
#include "Transaction.h"
-#include <chrono>
+#include "GameTime.h"
#include <deque>
class Item;
@@ -76,7 +76,7 @@ public:
template<class Type, class Period>
void AddCooldown(uint32 spellId, uint32 itemId, std::chrono::duration<Type, Period> cooldownDuration)
{
- Clock::time_point now = Clock::now();
+ Clock::time_point now = GameTime::GetGameTimeSystemPoint();
AddCooldown(spellId, itemId, now + std::chrono::duration_cast<Clock::duration>(cooldownDuration), 0, now);
}
diff --git a/src/server/game/Time/GameTime.cpp b/src/server/game/Time/GameTime.cpp
new file mode 100644
index 00000000000..8884d4612be
--- /dev/null
+++ b/src/server/game/Time/GameTime.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
+
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "GameTime.h"
+#include "Timer.h"
+
+namespace GameTime
+{
+ time_t const StartTime = time(nullptr);
+
+ time_t GameTime = 0;
+ uint32 GameMSTime = 0;
+
+ std::chrono::system_clock::time_point GameTimeSystemPoint = std::chrono::system_clock::time_point::min();
+ std::chrono::steady_clock::time_point GameTimeSteadyPoint = std::chrono::steady_clock::time_point::min();
+
+ time_t GetStartTime()
+ {
+ return StartTime;
+ }
+
+ time_t GetGameTime()
+ {
+ return GameTime;
+ }
+
+ uint32 GetGameTimeMS()
+ {
+ return GameMSTime;
+ }
+
+ std::chrono::system_clock::time_point GetGameTimeSystemPoint()
+ {
+ return GameTimeSystemPoint;
+ }
+
+ std::chrono::steady_clock::time_point GetGameTimeSteadyPoint()
+ {
+ return GameTimeSteadyPoint;
+ }
+
+ uint32 GetUptime()
+ {
+ return uint32(GameTime - StartTime);
+ }
+
+ void UpdateGameTimers()
+ {
+ GameTime = time(nullptr);
+ GameMSTime = getMSTime();
+ GameTimeSystemPoint = std::chrono::system_clock::now();
+ GameTimeSteadyPoint = std::chrono::steady_clock::now();
+ }
+}
diff --git a/src/server/game/Time/GameTime.h b/src/server/game/Time/GameTime.h
new file mode 100644
index 00000000000..2b130962a02
--- /dev/null
+++ b/src/server/game/Time/GameTime.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GAMETIME_H
+#define __GAMETIME_H
+
+#include "Define.h"
+
+#include <chrono>
+
+namespace GameTime
+{
+ // Server start time
+ time_t GetStartTime();
+
+ // Current server time (unix) in seconds
+ time_t GetGameTime();
+
+ // Milliseconds since server start
+ uint32 GetGameTimeMS();
+
+ /// Current chrono system_clock time point
+ std::chrono::system_clock::time_point GetGameTimeSystemPoint();
+
+ /// Current chrono steady_clock time point
+ std::chrono::steady_clock::time_point GetGameTimeSteadyPoint();
+
+ /// Uptime (in secs)
+ uint32 GetUptime();
+
+ void UpdateGameTimers();
+};
+
+#endif
diff --git a/src/server/game/Time/UpdateTime.cpp b/src/server/game/Time/UpdateTime.cpp
new file mode 100644
index 00000000000..1cc9fd1c507
--- /dev/null
+++ b/src/server/game/Time/UpdateTime.cpp
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
+
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "UpdateTime.h"
+#include "Timer.h"
+#include "Config.h"
+#include "Log.h"
+
+// create instance
+WorldUpdateTime sWorldUpdateTime;
+
+UpdateTime::UpdateTime()
+{
+ _averageUpdateTime = 0;
+ _totalUpdateTime = 0;
+ _updateTimeTableIndex = 0;
+ _maxUpdateTime = 0;
+ _maxUpdateTimeOfLastTable = 0;
+ _maxUpdateTimeOfCurrentTable = 0;
+
+ _updateTimeDataTable = { };
+}
+
+uint32 UpdateTime::GetAverageUpdateTime() const
+{
+ return _averageUpdateTime;
+}
+
+uint32 UpdateTime::GetTimeWeightedAverageUpdateTime() const
+{
+ uint32 sum = 0, weightsum = 0;
+ for (uint32 diff : _updateTimeDataTable)
+ {
+ sum += diff * diff;
+ weightsum += diff;
+ }
+ return sum / weightsum;
+}
+
+uint32 UpdateTime::GetMaxUpdateTime() const
+{
+ return _maxUpdateTime;
+}
+
+uint32 UpdateTime::GetMaxUpdateTimeOfCurrentTable() const
+{
+ return std::max(_maxUpdateTimeOfCurrentTable, _maxUpdateTimeOfLastTable);
+}
+
+uint32 UpdateTime::GetLastUpdateTime() const
+{
+ return _updateTimeDataTable[_updateTimeTableIndex != 0 ? _updateTimeTableIndex - 1 : _updateTimeDataTable.size() - 1];
+}
+
+void UpdateTime::UpdateWithDiff(uint32 diff)
+{
+ _totalUpdateTime = _totalUpdateTime - _updateTimeDataTable[_updateTimeTableIndex] + diff;
+ _updateTimeDataTable[_updateTimeTableIndex] = diff;
+
+ if (diff > _maxUpdateTime)
+ _maxUpdateTime = diff;
+
+ if (diff > _maxUpdateTimeOfCurrentTable)
+ _maxUpdateTimeOfCurrentTable = diff;
+
+ if (++_updateTimeTableIndex >= _updateTimeDataTable.size())
+ {
+ _updateTimeTableIndex = 0;
+ _maxUpdateTimeOfLastTable = _maxUpdateTimeOfCurrentTable;
+ _maxUpdateTimeOfCurrentTable = 0;
+ }
+
+ if (_updateTimeDataTable[_updateTimeDataTable.size() - 1])
+ _averageUpdateTime = _totalUpdateTime / _updateTimeDataTable.size();
+ else if (_updateTimeTableIndex)
+ _averageUpdateTime = _totalUpdateTime / _updateTimeTableIndex;
+}
+
+void UpdateTime::RecordUpdateTimeReset()
+{
+ _recordedTime = getMSTime();
+}
+
+void UpdateTime::_RecordUpdateTimeDuration(std::string const& text, uint32 minUpdateTime)
+{
+ uint32 thisTime = getMSTime();
+ uint32 diff = getMSTimeDiff(_recordedTime, thisTime);
+
+ if (diff > minUpdateTime)
+ TC_LOG_INFO("misc", "Recored Update Time of %s: %u.", text.c_str(), diff);
+
+ _recordedTime = thisTime;
+}
+
+void WorldUpdateTime::LoadFromConfig()
+{
+ _recordUpdateTimeInverval = sConfigMgr->GetIntDefault("RecordUpdateTimeDiffInterval", 60000);
+ _recordUpdateTimeMin = sConfigMgr->GetIntDefault("MinRecordUpdateTimeDiff", 100);
+}
+
+void WorldUpdateTime::SetRecordUpdateTimeInterval(uint32 t)
+{
+ _recordUpdateTimeInverval = t;
+}
+
+void WorldUpdateTime::RecordUpdateTime(uint32 gameTimeMs, uint32 diff, uint32 sessionCount)
+{
+ if (_recordUpdateTimeInverval > 0 && diff > _recordUpdateTimeMin)
+ {
+ if (getMSTimeDiff(_lastRecordTime, gameTimeMs) > _recordUpdateTimeInverval)
+ {
+ TC_LOG_DEBUG("misc", "Update time diff: %u. Players online: %u.", GetAverageUpdateTime(), sessionCount);
+ _lastRecordTime = gameTimeMs;
+ }
+ }
+}
+
+void WorldUpdateTime::RecordUpdateTimeDuration(std::string const& text)
+{
+ _RecordUpdateTimeDuration(text, _recordUpdateTimeMin);
+}
diff --git a/src/server/game/Time/UpdateTime.h b/src/server/game/Time/UpdateTime.h
new file mode 100644
index 00000000000..32ddf49c8a4
--- /dev/null
+++ b/src/server/game/Time/UpdateTime.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __UPDATETIME_H
+#define __UPDATETIME_H
+
+#include "Define.h"
+
+#define AVG_DIFF_COUNT 500
+
+class TC_GAME_API UpdateTime
+{
+ using DiffTableArray = std::array<uint32, AVG_DIFF_COUNT>;
+
+ public:
+ uint32 GetAverageUpdateTime() const;
+ uint32 GetTimeWeightedAverageUpdateTime() const;
+ uint32 GetMaxUpdateTime() const;
+ uint32 GetMaxUpdateTimeOfCurrentTable() const;
+ uint32 GetLastUpdateTime() const;
+
+ void UpdateWithDiff(uint32 diff);
+
+ void RecordUpdateTimeReset();
+
+ protected:
+ UpdateTime();
+
+ void _RecordUpdateTimeDuration(std::string const& text, uint32 minUpdateTime);
+
+ private:
+ DiffTableArray _updateTimeDataTable;
+ uint32 _averageUpdateTime;
+ uint32 _totalUpdateTime;
+ uint32 _updateTimeTableIndex;
+ uint32 _maxUpdateTime;
+ uint32 _maxUpdateTimeOfLastTable;
+ uint32 _maxUpdateTimeOfCurrentTable;
+
+ uint32 _recordedTime;
+};
+
+class WorldUpdateTime : public UpdateTime
+{
+ public:
+ WorldUpdateTime() : UpdateTime(), _recordUpdateTimeInverval(0), _recordUpdateTimeMin(0), _lastRecordTime(0) { }
+ void LoadFromConfig();
+ void SetRecordUpdateTimeInterval(uint32 t);
+ void RecordUpdateTime(uint32 gameTimeMs, uint32 diff, uint32 sessionCount);
+ void RecordUpdateTimeDuration(std::string const& text);
+
+ private:
+ uint32 _recordUpdateTimeInverval;
+ uint32 _recordUpdateTimeMin;
+ uint32 _lastRecordTime;
+};
+
+TC_GAME_API extern WorldUpdateTime sWorldUpdateTime;
+
+#endif
diff --git a/src/server/game/Warden/Warden.cpp b/src/server/game/Warden/Warden.cpp
index 8149257c1e4..fae8198e092 100644
--- a/src/server/game/Warden/Warden.cpp
+++ b/src/server/game/Warden/Warden.cpp
@@ -22,7 +22,7 @@
#include "Log.h"
#include "Opcodes.h"
#include "ByteBuffer.h"
-#include "World.h"
+#include "GameTime.h"
#include "Util.h"
#include "Warden.h"
#include "AccountMgr.h"
@@ -95,7 +95,7 @@ void Warden::Update()
{
if (_initialized)
{
- uint32 currentTimestamp = getMSTime();
+ uint32 currentTimestamp = GameTime::GetGameTimeMS();
uint32 diff = currentTimestamp - _previousTimestamp;
_previousTimestamp = currentTimestamp;
diff --git a/src/server/game/Warden/WardenMac.cpp b/src/server/game/Warden/WardenMac.cpp
index 1866116b758..12391db498b 100644
--- a/src/server/game/Warden/WardenMac.cpp
+++ b/src/server/game/Warden/WardenMac.cpp
@@ -23,7 +23,7 @@
#include "Log.h"
#include "Opcodes.h"
#include "ByteBuffer.h"
-#include "World.h"
+#include "GameTime.h"
#include "Player.h"
#include "Util.h"
#include "WardenMac.h"
@@ -185,7 +185,7 @@ void WardenMac::HandleHashResult(ByteBuffer &buff)
_initialized = true;
- _previousTimestamp = getMSTime();
+ _previousTimestamp = GameTime::GetGameTimeMS();
}
void WardenMac::RequestData()
diff --git a/src/server/game/Warden/WardenWin.cpp b/src/server/game/Warden/WardenWin.cpp
index b549c552e6d..3336b4c01ba 100644
--- a/src/server/game/Warden/WardenWin.cpp
+++ b/src/server/game/Warden/WardenWin.cpp
@@ -25,7 +25,7 @@
#include "Opcodes.h"
#include "ByteBuffer.h"
#include "Database/DatabaseEnv.h"
-#include "World.h"
+#include "GameTime.h"
#include "Player.h"
#include "Util.h"
#include "WardenWin.h"
@@ -166,7 +166,7 @@ void WardenWin::HandleHashResult(ByteBuffer &buff)
_initialized = true;
- _previousTimestamp = getMSTime();
+ _previousTimestamp = GameTime::GetGameTimeMS();
}
void WardenWin::RequestData()
@@ -180,7 +180,7 @@ void WardenWin::RequestData()
if (_otherChecksTodo.empty())
_otherChecksTodo.assign(sWardenCheckMgr->OtherChecksIdPool.begin(), sWardenCheckMgr->OtherChecksIdPool.end());
- _serverTicks = getMSTime();
+ _serverTicks = GameTime::GetGameTimeMS();
uint16 id;
uint8 type;
@@ -354,7 +354,7 @@ void WardenWin::HandleData(ByteBuffer &buff)
uint32 newClientTicks;
buff >> newClientTicks;
- uint32 ticksNow = getMSTime();
+ uint32 ticksNow = GameTime::GetGameTimeMS();
uint32 ourTicks = newClientTicks + (ticksNow - _serverTicks);
TC_LOG_DEBUG("warden", "ServerTicks %u", ticksNow); // Now
diff --git a/src/server/game/Weather/Weather.cpp b/src/server/game/Weather/Weather.cpp
index b989af67ec5..91125282496 100644
--- a/src/server/game/Weather/Weather.cpp
+++ b/src/server/game/Weather/Weather.cpp
@@ -23,7 +23,7 @@
#include "Weather.h"
#include "WorldPacket.h"
#include "Player.h"
-#include "World.h"
+#include "GameTime.h"
#include "Log.h"
#include "Util.h"
#include "ScriptMgr.h"
@@ -91,7 +91,7 @@ bool Weather::ReGenerate()
//78 days between January 1st and March 20nd; 365/4=91 days by season
// season source http://aa.usno.navy.mil/data/docs/EarthSeasons.html
- time_t gtime = sWorld->GetGameTime();
+ time_t gtime = GameTime::GetGameTime();
struct tm ltime;
localtime_r(&gtime, &ltime);
uint32 season = ((ltime.tm_yday - 78 + 365)/91)%4;
diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp
index a93cacea238..c3c21b2ba4e 100644
--- a/src/server/game/World/World.cpp
+++ b/src/server/game/World/World.cpp
@@ -71,6 +71,8 @@
#include "WorldSession.h"
#include "M2Stores.h"
#include "WhoListStorage.h"
+#include "GameTime.h"
+#include "UpdateTime.h"
TC_GAME_API std::atomic<bool> World::m_stopEvent(false);
TC_GAME_API uint8 World::m_ExitCode = SHUTDOWN_EXIT_CODE;
@@ -93,8 +95,7 @@ World::World()
m_allowMovement = true;
m_ShutdownMask = 0;
m_ShutdownTimer = 0;
- m_gameTime = time(NULL);
- m_startTime = m_gameTime;
+
m_maxActiveSessionCount = 0;
m_maxQueuedSessionCount = 0;
m_PlayerCount = 0;
@@ -110,10 +111,6 @@ World::World()
mail_timer = 0;
mail_timer_expires = 0;
- m_updateTime = 0;
- m_updateTimeSum = 0;
- m_updateTimeCount = 0;
- m_currentTime = 0;
m_isClosed = false;
@@ -403,6 +400,9 @@ void World::LoadConfigSettings(bool reload)
sMetric->LoadFromConfigs();
}
+ // load update time related configs
+ sWorldUpdateTime.LoadFromConfig();
+
///- Read the player limit and the Message of the day from the config file
SetPlayerAmountLimit(sConfigMgr->GetIntDefault("PlayerLimit", 100));
SetMotd(sConfigMgr->GetStringDefault("Motd", "Welcome to a Trinity Core Server."));
@@ -1250,8 +1250,6 @@ void World::LoadConfigSettings(bool reload)
m_bool_configs[CONFIG_SHOW_KICK_IN_WORLD] = sConfigMgr->GetBoolDefault("ShowKickInWorld", false);
m_bool_configs[CONFIG_SHOW_MUTE_IN_WORLD] = sConfigMgr->GetBoolDefault("ShowMuteInWorld", false);
m_bool_configs[CONFIG_SHOW_BAN_IN_WORLD] = sConfigMgr->GetBoolDefault("ShowBanInWorld", false);
- m_int_configs[CONFIG_INTERVAL_LOG_UPDATE] = sConfigMgr->GetIntDefault("RecordUpdateTimeDiffInterval", 60000);
- m_int_configs[CONFIG_MIN_LOG_UPDATE] = sConfigMgr->GetIntDefault("MinRecordUpdateTimeDiff", 100);
m_int_configs[CONFIG_NUMTHREADS] = sConfigMgr->GetIntDefault("MapUpdate.Threads", 1);
m_int_configs[CONFIG_MAX_RESULTS_LOOKUP_COMMANDS] = sConfigMgr->GetIntDefault("Command.LookupMaxResults", 0);
@@ -1859,11 +1857,10 @@ void World::SetInitialWorldSettings()
///- Initialize game time and timers
TC_LOG_INFO("server.loading", "Initialize game time and timers");
- m_gameTime = time(NULL);
- m_startTime = m_gameTime;
+ GameTime::UpdateGameTimers();
LoginDatabase.PExecute("INSERT INTO uptime (realmid, starttime, uptime, revision) VALUES(%u, %u, 0, '%s')",
- realm.Id.Realm, uint32(m_startTime), GitRevision::GetFullVersion()); // One-time query
+ realm.Id.Realm, uint32(GameTime::GetStartTime()), GitRevision::GetFullVersion()); // One-time query
m_timers[WUPDATE_WEATHERS].SetInterval(1*IN_MILLISECONDS);
m_timers[WUPDATE_AUCTIONS].SetInterval(MINUTE*IN_MILLISECONDS);
@@ -1891,7 +1888,8 @@ void World::SetInitialWorldSettings()
//one second is 1000 -(tested on win system)
/// @todo Get rid of magic numbers
tm localTm;
- localtime_r(&m_gameTime, &localTm);
+ time_t gameTime = GameTime::GetGameTime();
+ localtime_r(&gameTime, &localTm);
mail_timer = ((((localTm.tm_hour + 20) % 24)* HOUR * IN_MILLISECONDS) / m_timers[WUPDATE_AUCTIONS].GetInterval());
//1440
mail_timer_expires = ((DAY * IN_MILLISECONDS) / (m_timers[WUPDATE_AUCTIONS].GetInterval()));
@@ -2032,28 +2030,6 @@ void World::DetectDBCLang()
TC_LOG_INFO("server.loading", "Using %s DBC Locale as default. All available DBC locales: %s", localeNames[m_defaultDbcLocale], availableLocalsStr.empty() ? "<none>" : availableLocalsStr.c_str());
}
-void World::ResetTimeDiffRecord()
-{
- if (m_updateTimeCount != 1)
- return;
-
- m_currentTime = getMSTime();
-}
-
-void World::RecordTimeDiff(std::string const& text)
-{
- if (m_updateTimeCount != 1)
- return;
-
- uint32 thisTime = getMSTime();
- uint32 diff = getMSTimeDiff(m_currentTime, thisTime);
-
- if (diff > m_int_configs[CONFIG_MIN_LOG_UPDATE])
- TC_LOG_INFO("misc", "Difftime %s: %u.", text.c_str(), diff);
-
- m_currentTime = thisTime;
-}
-
void World::LoadAutobroadcasts()
{
uint32 oldMSTime = getMSTime();
@@ -2091,22 +2067,14 @@ void World::LoadAutobroadcasts()
/// Update the World !
void World::Update(uint32 diff)
{
- m_updateTime = diff;
+ ///- Update the game time and check for shutdown time
+ _UpdateGameTime();
+ time_t currentGameTime = GameTime::GetGameTime();
- if (m_int_configs[CONFIG_INTERVAL_LOG_UPDATE] && diff > m_int_configs[CONFIG_MIN_LOG_UPDATE])
- {
- if (m_updateTimeSum > m_int_configs[CONFIG_INTERVAL_LOG_UPDATE])
- {
- TC_LOG_DEBUG("misc", "Update time diff: %u. Players online: %u.", m_updateTimeSum / m_updateTimeCount, GetActiveSessionCount());
- m_updateTimeSum = m_updateTime;
- m_updateTimeCount = 1;
- }
- else
- {
- m_updateTimeSum += m_updateTime;
- ++m_updateTimeCount;
- }
- }
+ sWorldUpdateTime.UpdateWithDiff(diff);
+
+ // Record update if recording set in log and diff is greater then minimum set in log
+ sWorldUpdateTime.RecordUpdateTime(GameTime::GetGameTimeMS(), diff, GetActiveSessionCount());
///- Update the different timers
for (int i = 0; i < WUPDATE_COUNT; ++i)
@@ -2124,28 +2092,25 @@ void World::Update(uint32 diff)
sWhoListStorageMgr->Update();
}
- ///- Update the game time and check for shutdown time
- _UpdateGameTime();
-
/// Handle daily quests reset time
- if (m_gameTime > m_NextDailyQuestReset)
+ if (currentGameTime > m_NextDailyQuestReset)
{
ResetDailyQuests();
InitDailyQuestResetTime(false);
}
/// Handle weekly quests reset time
- if (m_gameTime > m_NextWeeklyQuestReset)
+ if (currentGameTime > m_NextWeeklyQuestReset)
ResetWeeklyQuests();
/// Handle monthly quests reset time
- if (m_gameTime > m_NextMonthlyQuestReset)
+ if (currentGameTime > m_NextMonthlyQuestReset)
ResetMonthlyQuests();
- if (m_gameTime > m_NextRandomBGReset)
+ if (currentGameTime > m_NextRandomBGReset)
ResetRandomBG();
- if (m_gameTime > m_NextGuildReset)
+ if (currentGameTime > m_NextGuildReset)
ResetGuildCap();
/// <ul><li> Handle auctions when the timer has passed
@@ -2187,9 +2152,9 @@ void World::Update(uint32 diff)
}
/// <li> Handle session updates when the timer has passed
- ResetTimeDiffRecord();
+ sWorldUpdateTime.RecordUpdateTimeReset();
UpdateSessions(diff);
- RecordTimeDiff("UpdateSessions");
+ sWorldUpdateTime.RecordUpdateTimeDuration("UpdateSessions");
/// <li> Handle weather updates when the timer has passed
if (m_timers[WUPDATE_WEATHERS].Passed())
@@ -2201,7 +2166,7 @@ void World::Update(uint32 diff)
/// <li> Update uptime table
if (m_timers[WUPDATE_UPTIME].Passed())
{
- uint32 tmpDiff = uint32(m_gameTime - m_startTime);
+ uint32 tmpDiff = GameTime::GetUptime();
uint32 maxOnlinePlayers = GetMaxPlayerCount();
m_timers[WUPDATE_UPTIME].Reset();
@@ -2211,7 +2176,7 @@ void World::Update(uint32 diff)
stmt->setUInt32(0, tmpDiff);
stmt->setUInt16(1, uint16(maxOnlinePlayers));
stmt->setUInt32(2, realm.Id.Realm);
- stmt->setUInt32(3, uint32(m_startTime));
+ stmt->setUInt32(3, uint32(GameTime::GetStartTime()));
LoginDatabase.Execute(stmt);
}
@@ -2235,9 +2200,9 @@ void World::Update(uint32 diff)
/// <li> Handle all other objects
///- Update objects when the timer has passed (maps, transport, creatures, ...)
- ResetTimeDiffRecord();
+ sWorldUpdateTime.RecordUpdateTimeReset();
sMapMgr->Update(diff);
- RecordTimeDiff("UpdateMapMgr");
+ sWorldUpdateTime.RecordUpdateTimeDuration("UpdateMapMgr");
if (sWorld->getBoolConfig(CONFIG_AUTOBROADCAST))
{
@@ -2249,13 +2214,13 @@ void World::Update(uint32 diff)
}
sBattlegroundMgr->Update(diff);
- RecordTimeDiff("UpdateBattlegroundMgr");
+ sWorldUpdateTime.RecordUpdateTimeDuration("UpdateBattlegroundMgr");
sOutdoorPvPMgr->Update(diff);
- RecordTimeDiff("UpdateOutdoorPvPMgr");
+ sWorldUpdateTime.RecordUpdateTimeDuration("UpdateOutdoorPvPMgr");
sBattlefieldMgr->Update(diff);
- RecordTimeDiff("BattlefieldMgr");
+ sWorldUpdateTime.RecordUpdateTimeDuration("BattlefieldMgr");
///- Delete all characters which have been deleted X days before
if (m_timers[WUPDATE_DELETECHARS].Passed())
@@ -2265,11 +2230,11 @@ void World::Update(uint32 diff)
}
sLFGMgr->Update(diff);
- RecordTimeDiff("UpdateLFGMgr");
+ sWorldUpdateTime.RecordUpdateTimeDuration("UpdateLFGMgr");
// execute callbacks from sql queries that were queued recently
ProcessQueryCallbacks();
- RecordTimeDiff("ProcessQueryCallbacks");
+ sWorldUpdateTime.RecordUpdateTimeDuration("ProcessQueryCallbacks");
///- Erase corpses once every 20 minutes
if (m_timers[WUPDATE_CORPSES].Passed())
@@ -2698,9 +2663,10 @@ bool World::RemoveBanCharacter(std::string const& name)
void World::_UpdateGameTime()
{
///- update the time
- time_t thisTime = time(NULL);
- uint32 elapsed = uint32(thisTime - m_gameTime);
- m_gameTime = thisTime;
+ time_t lastGameTime = GameTime::GetGameTime();
+ GameTime::UpdateGameTimers();
+
+ uint32 elapsed = uint32(GameTime::GetGameTime() - lastGameTime);
///- if there is a shutdown timer
if (!IsStopped() && m_ShutdownTimer > 0 && elapsed > 0)
diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h
index 8a1c3773653..b7434890399 100644
--- a/src/server/game/World/World.h
+++ b/src/server/game/World/World.h
@@ -317,8 +317,6 @@ enum WorldIntConfigs
CONFIG_PVP_TOKEN_MAP_TYPE,
CONFIG_PVP_TOKEN_ID,
CONFIG_PVP_TOKEN_COUNT,
- CONFIG_INTERVAL_LOG_UPDATE,
- CONFIG_MIN_LOG_UPDATE,
CONFIG_ENABLE_SINFO_LOGIN,
CONFIG_PLAYER_ALLOW_COMMANDS,
CONFIG_NUMTHREADS,
@@ -632,16 +630,6 @@ class TC_GAME_API World
/// Get the path where data (dbc, maps) are stored on disk
std::string const& GetDataPath() const { return m_dataPath; }
- /// When server started?
- time_t const& GetStartTime() const { return m_startTime; }
- /// What time is it?
- time_t const& GetGameTime() const { return m_gameTime; }
- /// Uptime (in secs)
- uint32 GetUptime() const { return uint32(m_gameTime - m_startTime); }
- /// Update time
- uint32 GetUpdateTime() const { return m_updateTime; }
- void SetRecordDiffInterval(int32 t) { if (t >= 0) m_int_configs[CONFIG_INTERVAL_LOG_UPDATE] = (uint32)t; }
-
/// Next daily quests and random bg reset time
time_t GetNextDailyQuestsResetTime() const { return m_NextDailyQuestReset; }
time_t GetNextWeeklyQuestsResetTime() const { return m_NextWeeklyQuestReset; }
@@ -761,9 +749,6 @@ class TC_GAME_API World
void LoadDBVersion();
char const* GetDBVersion() const { return m_DBVersion.c_str(); }
- void ResetTimeDiffRecord();
- void RecordTimeDiff(std::string const& text);
-
void LoadAutobroadcasts();
void UpdateAreaDependentAuras();
@@ -778,6 +763,7 @@ class TC_GAME_API World
protected:
void _UpdateGameTime();
+
// callback for UpdateRealmCharacters
void _UpdateRealmCharCount(PreparedQueryResult resultCharCount);
@@ -804,14 +790,9 @@ class TC_GAME_API World
bool m_isClosed;
- time_t m_startTime;
- time_t m_gameTime;
IntervalTimer m_timers[WUPDATE_COUNT];
time_t mail_timer;
time_t mail_timer_expires;
- uint32 m_updateTime, m_updateTimeSum;
- uint32 m_updateTimeCount;
- uint32 m_currentTime;
SessionMap m_sessions;
typedef std::unordered_map<uint32, time_t> DisconnectMap;
diff --git a/src/server/scripts/Commands/cs_server.cpp b/src/server/scripts/Commands/cs_server.cpp
index 285ac4e3e96..50b9b37031f 100644
--- a/src/server/scripts/Commands/cs_server.cpp
+++ b/src/server/scripts/Commands/cs_server.cpp
@@ -30,6 +30,8 @@ EndScriptData */
#include "ScriptMgr.h"
#include "GitRevision.h"
#include "Util.h"
+#include "GameTime.h"
+#include "UpdateTime.h"
class server_commandscript : public CommandScript
{
@@ -108,8 +110,8 @@ public:
uint32 queuedClientsNum = sWorld->GetQueuedSessionCount();
uint32 maxActiveClientsNum = sWorld->GetMaxActiveSessionCount();
uint32 maxQueuedClientsNum = sWorld->GetMaxQueuedSessionCount();
- std::string uptime = secsToTimeString(sWorld->GetUptime());
- uint32 updateTime = sWorld->GetUpdateTime();
+ std::string uptime = secsToTimeString(GameTime::GetUptime());
+ uint32 updateTime = sWorldUpdateTime.GetLastUpdateTime();
handler->SendSysMessage(GitRevision::GetFullVersion());
handler->PSendSysMessage(LANG_CONNECTED_PLAYERS, playersNum, maxPlayersNum);
@@ -304,7 +306,7 @@ public:
if (newTime < 0)
return false;
- sWorld->SetRecordDiffInterval(newTime);
+ sWorldUpdateTime.SetRecordUpdateTimeInterval(newTime);
printf("Record diff every %i ms\n", newTime);
return true;
diff --git a/src/server/scripts/Events/fireworks_show.cpp b/src/server/scripts/Events/fireworks_show.cpp
index 85858fa569d..97c0e33b944 100644
--- a/src/server/scripts/Events/fireworks_show.cpp
+++ b/src/server/scripts/Events/fireworks_show.cpp
@@ -19,6 +19,7 @@
#include "GameObjectAI.h"
#include "CreatureAIImpl.h"
#include "GameEventMgr.h"
+#include "GameTime.h"
enum FireworksShowTypeObjects
{
@@ -792,7 +793,7 @@ public:
{
_events.Update(diff);
- time_t time = sWorld->GetGameTime();
+ time_t time = GameTime::GetGameTime();
tm localTm;
localtime_r(&time, &localTm);
diff --git a/src/server/scripts/Northrend/IcecrownCitadel/icecrown_citadel.cpp b/src/server/scripts/Northrend/IcecrownCitadel/icecrown_citadel.cpp
index 733c381271f..186920ad07c 100644
--- a/src/server/scripts/Northrend/IcecrownCitadel/icecrown_citadel.cpp
+++ b/src/server/scripts/Northrend/IcecrownCitadel/icecrown_citadel.cpp
@@ -1837,7 +1837,7 @@ class spell_icc_sprit_alarm : public SpellScriptLoader
}
if (GameObject* trap = GetCaster()->FindNearestGameObject(trapId, 5.0f))
- trap->SetRespawnTime(trap->GetGOInfo()->GetAutoCloseTime());
+ trap->SetRespawnTime(trap->GetGOInfo()->GetAutoCloseTime() / IN_MILLISECONDS);
std::list<Creature*> wards;
GetCaster()->GetCreatureListWithEntryInGrid(wards, NPC_DEATHBOUND_WARD, 150.0f);
diff --git a/src/server/scripts/Northrend/Naxxramas/boss_four_horsemen.cpp b/src/server/scripts/Northrend/Naxxramas/boss_four_horsemen.cpp
index 3db0b1d4fca..c80f4e2bbea 100644
--- a/src/server/scripts/Northrend/Naxxramas/boss_four_horsemen.cpp
+++ b/src/server/scripts/Northrend/Naxxramas/boss_four_horsemen.cpp
@@ -16,6 +16,7 @@
*/
#include "Player.h"
+#include "GameTime.h"
#include "ScriptMgr.h"
#include "ScriptedCreature.h"
#include "SpellScript.h"
@@ -327,7 +328,7 @@ struct boss_four_horsemen_baseAI : public BossAI
}
Talk(SAY_DEATH);
- _timeDied = getMSTime();
+ _timeDied = GameTime::GetGameTimeMS();
for (Horseman boss : horsemen)
{
if (Creature* cBoss = getHorsemanHandle(boss))
diff --git a/src/server/scripts/Northrend/Nexus/Nexus/boss_magus_telestra.cpp b/src/server/scripts/Northrend/Nexus/Nexus/boss_magus_telestra.cpp
index d6309982d81..26a427dbbe6 100644
--- a/src/server/scripts/Northrend/Nexus/Nexus/boss_magus_telestra.cpp
+++ b/src/server/scripts/Northrend/Nexus/Nexus/boss_magus_telestra.cpp
@@ -17,6 +17,7 @@
*/
#include "GameEventMgr.h"
+#include "GameTime.h"
#include "ScriptMgr.h"
#include "ScriptedCreature.h"
#include "nexus.h"
@@ -167,7 +168,7 @@ public:
while (time[i] != 0)
++i;
- time[i] = sWorld->GetGameTime();
+ time[i] = GameTime::GetGameTime();
if (i == 2 && (time[2] - time[1] < 5) && (time[1] - time[0] < 5))
++splitPersonality;
}
diff --git a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_ignis.cpp b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_ignis.cpp
index 30d6aa65ec5..164f6c814ca 100644
--- a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_ignis.cpp
+++ b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_ignis.cpp
@@ -15,6 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "GameTime.h"
#include "ScriptMgr.h"
#include "ScriptedCreature.h"
#include "SpellScript.h"
@@ -194,7 +195,7 @@ class boss_ignis : public CreatureScript
me->RemoveAuraFromStack(SPELL_STRENGHT);
// Shattered Achievement
- time_t secondKill = sWorld->GetGameTime();
+ time_t secondKill = GameTime::GetGameTime();
if ((secondKill - _firstConstructKill) < 5)
_shattered = true;
_firstConstructKill = secondKill;
diff --git a/src/server/scripts/Spells/spell_druid.cpp b/src/server/scripts/Spells/spell_druid.cpp
index 7e406b86635..812cc20a971 100644
--- a/src/server/scripts/Spells/spell_druid.cpp
+++ b/src/server/scripts/Spells/spell_druid.cpp
@@ -22,6 +22,7 @@
*/
#include "Player.h"
+#include "GameTime.h"
#include "ScriptMgr.h"
#include "SpellScript.h"
#include "SpellAuraEffects.h"
@@ -234,7 +235,7 @@ class spell_dru_eclipse : public SpellScriptLoader
if (!spellInfo || !(spellInfo->SpellFamilyFlags[0] & 4)) // Starfire
return false;
- return _solarProcCooldownEnd <= std::chrono::steady_clock::now();
+ return _solarProcCooldownEnd <= GameTime::GetGameTimeSteadyPoint();
}
bool CheckLunar(AuraEffect const* /*aurEff*/, ProcEventInfo& eventInfo)
@@ -247,14 +248,14 @@ class spell_dru_eclipse : public SpellScriptLoader
if (!roll_chance_i(60))
return false;
- return _lunarProcCooldownEnd <= std::chrono::steady_clock::now();
+ return _lunarProcCooldownEnd <= GameTime::GetGameTimeSteadyPoint();
}
void ProcSolar(AuraEffect const* aurEff, ProcEventInfo& eventInfo)
{
PreventDefaultAction();
- _solarProcCooldownEnd = std::chrono::steady_clock::now() + Seconds(30);
+ _solarProcCooldownEnd = GameTime::GetGameTimeSteadyPoint() + Seconds(30);
eventInfo.GetActor()->CastSpell(eventInfo.GetActor(), SPELL_DRUID_ECLIPSE_SOLAR_PROC, TRIGGERED_FULL_MASK, nullptr, aurEff);
}
@@ -262,7 +263,7 @@ class spell_dru_eclipse : public SpellScriptLoader
{
PreventDefaultAction();
- _lunarProcCooldownEnd = std::chrono::steady_clock::now() + Seconds(30);
+ _lunarProcCooldownEnd = GameTime::GetGameTimeSteadyPoint() + Seconds(30);
eventInfo.GetActor()->CastSpell(eventInfo.GetActor(), SPELL_DRUID_ECLIPSE_LUNAR_PROC, TRIGGERED_FULL_MASK, nullptr, aurEff);
}
diff --git a/src/server/scripts/Spells/spell_generic.cpp b/src/server/scripts/Spells/spell_generic.cpp
index effb3fb9b5c..0a5890f4a5d 100644
--- a/src/server/scripts/Spells/spell_generic.cpp
+++ b/src/server/scripts/Spells/spell_generic.cpp
@@ -23,6 +23,7 @@
*/
#include "ScriptMgr.h"
+#include "GameTime.h"
#include "Battleground.h"
#include "Cell.h"
#include "CellImpl.h"
@@ -3570,7 +3571,7 @@ class spell_gen_turkey_marker : public SpellScriptLoader
void OnApply(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/)
{
// store stack apply times, so we can pop them while they expire
- _applyTimes.push_back(getMSTime());
+ _applyTimes.push_back(GameTime::GetGameTimeMS());
Unit* target = GetTarget();
// on stack 15 cast the achievement crediting spell
@@ -3584,7 +3585,7 @@ class spell_gen_turkey_marker : public SpellScriptLoader
return;
// pop stack if it expired for us
- if (_applyTimes.front() + GetMaxDuration() < getMSTime())
+ if (_applyTimes.front() + GetMaxDuration() < GameTime::GetGameTimeMS())
ModStackAmount(-1, AURA_REMOVE_BY_EXPIRE);
}
diff --git a/src/server/scripts/Spells/spell_paladin.cpp b/src/server/scripts/Spells/spell_paladin.cpp
index 6dc6681a7a1..20d632b3c2a 100644
--- a/src/server/scripts/Spells/spell_paladin.cpp
+++ b/src/server/scripts/Spells/spell_paladin.cpp
@@ -22,6 +22,7 @@
*/
#include "Player.h"
+#include "GameTime.h"
#include "ScriptMgr.h"
#include "SpellScript.h"
#include "SpellAuraEffects.h"
@@ -1988,7 +1989,7 @@ class spell_pal_sacred_shield_dummy : public SpellScriptLoader
if (!caster)
return;
- std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
+ std::chrono::steady_clock::time_point now = GameTime::GetGameTimeSteadyPoint();
if (_cooldownEnd > now)
return;
diff --git a/src/server/scripts/World/areatrigger_scripts.cpp b/src/server/scripts/World/areatrigger_scripts.cpp
index 72ae363c743..a3fb056ba8f 100644
--- a/src/server/scripts/World/areatrigger_scripts.cpp
+++ b/src/server/scripts/World/areatrigger_scripts.cpp
@@ -35,6 +35,7 @@ at_brewfest
at_area_52_entrance
EndContentData */
+#include "GameTime.h"
#include "ScriptMgr.h"
#include "ScriptedCreature.h"
#include "Player.h"
@@ -314,7 +315,7 @@ class AreaTrigger_at_brewfest : public AreaTriggerScript
{
uint32 triggerId = trigger->id;
// Second trigger happened too early after first, skip for now
- if (sWorld->GetGameTime() - _triggerTimes[triggerId] < AREATRIGGER_TALK_COOLDOWN)
+ if (GameTime::GetGameTime() - _triggerTimes[triggerId] < AREATRIGGER_TALK_COOLDOWN)
return false;
switch (triggerId)
@@ -331,7 +332,7 @@ class AreaTrigger_at_brewfest : public AreaTriggerScript
break;
}
- _triggerTimes[triggerId] = sWorld->GetGameTime();
+ _triggerTimes[triggerId] = GameTime::GetGameTime();
return false;
}
@@ -371,7 +372,7 @@ class AreaTrigger_at_area_52_entrance : public AreaTriggerScript
return false;
uint32 triggerId = trigger->id;
- if (sWorld->GetGameTime() - _triggerTimes[trigger->id] < SUMMON_COOLDOWN)
+ if (GameTime::GetGameTime() - _triggerTimes[trigger->id] < SUMMON_COOLDOWN)
return false;
switch (triggerId)
@@ -400,7 +401,7 @@ class AreaTrigger_at_area_52_entrance : public AreaTriggerScript
player->SummonCreature(NPC_SPOTLIGHT, x, y, z, 0.0f, TEMPSUMMON_TIMED_DESPAWN, 5000);
player->AddAura(SPELL_A52_NEURALYZER, player);
- _triggerTimes[trigger->id] = sWorld->GetGameTime();
+ _triggerTimes[trigger->id] = GameTime::GetGameTime();
return false;
}
diff --git a/src/server/scripts/World/duel_reset.cpp b/src/server/scripts/World/duel_reset.cpp
index d792a1cb47f..3d8692780b6 100644
--- a/src/server/scripts/World/duel_reset.cpp
+++ b/src/server/scripts/World/duel_reset.cpp
@@ -15,6 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "GameTime.h"
#include "ScriptMgr.h"
#include "Player.h"
#include "Pet.h"
@@ -103,7 +104,7 @@ class DuelResetScript : public PlayerScript
// remove cooldowns on spells that have < 10 min CD > 30 sec and has no onHold
player->GetSpellHistory()->ResetCooldowns([](SpellHistory::CooldownStorageType::iterator itr) -> bool
{
- SpellHistory::Clock::time_point now = SpellHistory::Clock::now();
+ SpellHistory::Clock::time_point now = GameTime::GetGameTimeSystemPoint();
uint32 cooldownDuration = itr->second.CooldownEnd > now ? std::chrono::duration_cast<std::chrono::milliseconds>(itr->second.CooldownEnd - now).count() : 0;
SpellInfo const* spellInfo = sSpellMgr->AssertSpellInfo(itr->first);
return spellInfo->RecoveryTime < 10 * MINUTE * IN_MILLISECONDS
diff --git a/src/server/scripts/World/go_scripts.cpp b/src/server/scripts/World/go_scripts.cpp
index e237b3d7286..ccdde9eb799 100644
--- a/src/server/scripts/World/go_scripts.cpp
+++ b/src/server/scripts/World/go_scripts.cpp
@@ -53,6 +53,7 @@ EndContentData */
#include "Player.h"
#include "WorldSession.h"
#include "GameEventMgr.h"
+#include "GameTime.h"
/*######
## go_cat_figurine
@@ -1644,7 +1645,7 @@ public:
{
if (eventId == GAME_EVENT_HOURLY_BELLS && start)
{
- time_t time = sWorld->GetGameTime();
+ time_t time = GameTime::GetGameTime();
tm localTm;
localtime_r(&time, &localTm);
uint8 _rings = (localTm.tm_hour - 1) % 12 + 1;