diff options
author | Treeston <treeston.mmoc@gmail.com> | 2020-07-14 01:35:25 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2022-01-23 21:36:03 +0100 |
commit | d11c3807b32d51e48ed4557972a627f6366956d9 (patch) | |
tree | 3a551793088ff8b7d1475cc1045fbab811b94188 | |
parent | dfc1f08bd84503f6023d033396fc33d356220a62 (diff) |
Core/Time: Rename GetGameTime{System, Steady}Point methods
The names are a bit unhandy. Rename them (shorter but still meaningful).
GetGameTimeSystemPoint() -> GetSystemTime()
GetGameTimeSteadyPoint() -> Now()
Also add 2 new typedefs:
typedef std::chrono::steady_clock::time_point TimePoint;
typedef std::chrono::system_clock::time_point SystemTimePoint;
Closes #25042
(cherry picked from commit 896b68d5c297b06587645caebc98b704978ecaa7)
28 files changed, 107 insertions, 103 deletions
diff --git a/src/common/Metric/Metric.h b/src/common/Metric/Metric.h index d46e0566130..5e843139354 100644 --- a/src/common/Metric/Metric.h +++ b/src/common/Metric/Metric.h @@ -19,8 +19,8 @@ #define METRIC_H__ #include "Define.h" +#include "Duration.h" #include "MPSCQueue.h" -#include <chrono> #include <functional> #include <iosfwd> #include <memory> @@ -48,7 +48,7 @@ typedef std::pair<std::string, std::string> MetricTag; struct MetricData { std::string Category; - std::chrono::system_clock::time_point Timestamp; + SystemTimePoint Timestamp; MetricDataType Type; std::vector<MetricTag> Tags; diff --git a/src/common/Utilities/Duration.h b/src/common/Utilities/Duration.h index ca71902bc6f..7eb349e6d85 100644 --- a/src/common/Utilities/Duration.h +++ b/src/common/Utilities/Duration.h @@ -32,6 +32,10 @@ typedef std::chrono::minutes Minutes; /// Hours shorthand typedef. typedef std::chrono::hours Hours; +/// time_point shorthand typedefs +typedef std::chrono::steady_clock::time_point TimePoint; +typedef std::chrono::system_clock::time_point SystemTimePoint; + /// Makes std::chrono_literals globally available. using namespace std::chrono_literals; diff --git a/src/common/Utilities/Timer.h b/src/common/Utilities/Timer.h index 4abd6cc8ca1..a197c5cfbb4 100644 --- a/src/common/Utilities/Timer.h +++ b/src/common/Utilities/Timer.h @@ -19,9 +19,9 @@ #define TRINITY_TIMER_H #include "Define.h" -#include <chrono> +#include "Duration.h" -inline std::chrono::steady_clock::time_point GetApplicationStartTime() +inline TimePoint GetApplicationStartTime() { using namespace std::chrono; @@ -46,7 +46,7 @@ inline uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime) return newMSTime - oldMSTime; } -inline uint32 getMSTimeDiff(uint32 oldMSTime, std::chrono::steady_clock::time_point newTime) +inline uint32 getMSTimeDiff(uint32 oldMSTime, TimePoint newTime) { using namespace std::chrono; diff --git a/src/server/game/Achievements/AchievementMgr.cpp b/src/server/game/Achievements/AchievementMgr.cpp index 1f66c00786f..cbc73da75e5 100644 --- a/src/server/game/Achievements/AchievementMgr.cpp +++ b/src/server/game/Achievements/AchievementMgr.cpp @@ -1081,17 +1081,17 @@ bool AchievementGlobalMgr::IsRealmCompleted(AchievementEntry const* achievement) if (itr == _allCompletedAchievements.end()) return false; - if (itr->second == std::chrono::system_clock::time_point::min()) + if (itr->second == SystemTimePoint ::min()) return false; - if (itr->second == std::chrono::system_clock::time_point::max()) + if (itr->second == SystemTimePoint::max()) return true; // Allow completing the realm first kill for entire minute after first person did it // it may allow more than one group to achieve it (highly unlikely) // but apparently this is how blizz handles it as well if (achievement->Flags & ACHIEVEMENT_FLAG_REALM_FIRST_KILL) - return (std::chrono::system_clock::now() - itr->second) > Minutes(1); + return (GameTime::GetSystemTime() - itr->second) > Minutes(1); return true; } @@ -1101,7 +1101,7 @@ void AchievementGlobalMgr::SetRealmCompleted(AchievementEntry const* achievement if (IsRealmCompleted(achievement)) return; - _allCompletedAchievements[achievement->ID] = std::chrono::system_clock::now(); + _allCompletedAchievements[achievement->ID] = GameTime::GetSystemTime(); } //========================================================== @@ -1148,7 +1148,7 @@ void AchievementGlobalMgr::LoadCompletedAchievements() // instead the only potential race will happen on value associated with the key for (AchievementEntry const* achievement : sAchievementStore) if (achievement->Flags & (ACHIEVEMENT_FLAG_REALM_FIRST_REACH | ACHIEVEMENT_FLAG_REALM_FIRST_KILL)) - _allCompletedAchievements[achievement->ID] = std::chrono::system_clock::time_point::min(); + _allCompletedAchievements[achievement->ID] = SystemTimePoint::min(); QueryResult result = CharacterDatabase.Query("SELECT achievement FROM character_achievement GROUP BY achievement"); @@ -1176,7 +1176,7 @@ void AchievementGlobalMgr::LoadCompletedAchievements() continue; } else if (achievement->Flags & (ACHIEVEMENT_FLAG_REALM_FIRST_REACH | ACHIEVEMENT_FLAG_REALM_FIRST_KILL)) - _allCompletedAchievements[achievementId] = std::chrono::system_clock::time_point::max(); + _allCompletedAchievements[achievementId] = SystemTimePoint::max(); } while (result->NextRow()); diff --git a/src/server/game/Achievements/AchievementMgr.h b/src/server/game/Achievements/AchievementMgr.h index 29443a21055..478518f3626 100644 --- a/src/server/game/Achievements/AchievementMgr.h +++ b/src/server/game/Achievements/AchievementMgr.h @@ -167,9 +167,9 @@ private: std::unordered_map<uint32, std::vector<AchievementEntry const*>> _achievementListByReferencedId; // store realm first achievements - // std::chrono::system_clock::time_point::min() is a placeholder value for realm firsts not yet completed - // std::chrono::system_clock::time_point::max() is a value assigned to realm firsts complete before worldserver started - std::unordered_map<uint32 /*achievementId*/, std::chrono::system_clock::time_point /*completionTime*/> _allCompletedAchievements; + // SystemTimePoint::min() is a placeholder value for realm firsts not yet completed + // SystemTimePoint::max() is a value assigned to realm firsts complete before worldserver started + std::unordered_map<uint32 /*achievementId*/, SystemTimePoint /*completionTime*/> _allCompletedAchievements; std::unordered_map<uint32, AchievementReward> _achievementRewards; std::unordered_map<uint32, AchievementRewardLocale> _achievementRewardLocales; diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp index 21979199d7b..be9845258de 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp @@ -224,7 +224,7 @@ void AuctionPosting::BuildAuctionItem(WorldPackets::AuctionHouse::AuctionItem* a } // all (not optional<>) - auctionItem->DurationLeft = uint32(std::max(std::chrono::duration_cast<Milliseconds>(EndTime - GameTime::GetGameTimeSystemPoint()).count(), Milliseconds::zero().count())); + auctionItem->DurationLeft = uint32(std::max(std::chrono::duration_cast<Milliseconds>(EndTime - GameTime::GetSystemTime()).count(), Milliseconds::zero().count())); auctionItem->DeleteReason = 0; // SMSG_AUCTION_LIST_ITEMS_RESULT (only if owned) @@ -403,7 +403,7 @@ private: AuctionHouseMgr::AuctionHouseMgr() : mHordeAuctions(6), mAllianceAuctions(2), mNeutralAuctions(1), mGoblinAuctions(7), _replicateIdGenerator(0) { - _playerThrottleObjectsCleanupTime = GameTime::GetGameTimeSteadyPoint() + Hours(1); + _playerThrottleObjectsCleanupTime = GameTime::Now() + Hours(1); } AuctionHouseMgr::~AuctionHouseMgr() @@ -728,7 +728,7 @@ void AuctionHouseMgr::PendingAuctionProcess(Player* player) { PendingAuctionInfo const& pendingAuction = *itrAH; if (AuctionPosting* auction = GetAuctionsById(pendingAuction.AuctionHouseId)->GetAuction(pendingAuction.AuctionId)) - auction->EndTime = GameTime::GetGameTimeSystemPoint(); + auction->EndTime = GameTime::GetSystemTime(); CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_AUCTION_EXPIRATION); stmt->setUInt32(0, uint32(GameTime::GetGameTime())); @@ -771,7 +771,7 @@ void AuctionHouseMgr::UpdatePendingAuctions() for (PendingAuctionInfo const& pendingAuction : itr->second.Auctions) { if (AuctionPosting* auction = GetAuctionsById(pendingAuction.AuctionHouseId)->GetAuction(pendingAuction.AuctionId)) - auction->EndTime = GameTime::GetGameTimeSystemPoint(); + auction->EndTime = GameTime::GetSystemTime(); CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_AUCTION_EXPIRATION); stmt->setUInt32(0, uint32(GameTime::GetGameTime())); @@ -791,7 +791,7 @@ void AuctionHouseMgr::Update() mNeutralAuctions.Update(); mGoblinAuctions.Update(); - std::chrono::steady_clock::time_point now = GameTime::GetGameTimeSteadyPoint(); + TimePoint now = GameTime::Now(); if (now >= _playerThrottleObjectsCleanupTime) { for (auto itr = _playerThrottleObjects.begin(); itr != _playerThrottleObjects.end();) @@ -813,7 +813,7 @@ uint32 AuctionHouseMgr::GenerateReplicationId() AuctionThrottleResult AuctionHouseMgr::CheckThrottle(Player* player, bool addonTainted, AuctionCommand command /*= AuctionCommand::SellItem*/) { - std::chrono::steady_clock::time_point now = GameTime::GetGameTimeSteadyPoint(); + TimePoint now = GameTime::Now(); auto itr = _playerThrottleObjects.emplace(std::piecewise_construct, std::forward_as_tuple(player->GetGUID()), std::forward_as_tuple()); if (itr.second || now > itr.first->second.PeriodEnd) { @@ -1113,8 +1113,8 @@ void AuctionHouseObject::RemoveAuction(CharacterDatabaseTransaction trans, Aucti void AuctionHouseObject::Update() { - std::chrono::system_clock::time_point curTime = GameTime::GetGameTimeSystemPoint(); - std::chrono::steady_clock::time_point curTimeSteady = GameTime::GetGameTimeSteadyPoint(); + SystemTimePoint curTime = GameTime::GetSystemTime(); + TimePoint curTimeSteady = GameTime::Now(); ///- Handle expired auctions // Clear expired throttled players @@ -1517,7 +1517,7 @@ void AuctionHouseObject::BuildListAuctionItems(WorldPackets::AuctionHouse::Aucti void AuctionHouseObject::BuildReplicate(WorldPackets::AuctionHouse::AuctionReplicateResponse& replicateResponse, Player* player, uint32 global, uint32 cursor, uint32 tombstone, uint32 count) { - std::chrono::steady_clock::time_point curTime = GameTime::GetGameTimeSteadyPoint(); + TimePoint curTime = GameTime::Now(); auto throttleItr = _replicateThrottleMap.find(player->GetGUID()); if (throttleItr != _replicateThrottleMap.end()) @@ -1598,7 +1598,7 @@ CommodityQuote const* AuctionHouseObject::CreateCommodityQuote(Player* player, u CommodityQuote* quote = &_commodityQuotes[player->GetGUID()]; quote->TotalPrice = totalPrice; quote->Quantity = quantity; - quote->ValidTo = GameTime::GetGameTimeSteadyPoint() + 30s; + quote->ValidTo = GameTime::Now() + 30s; return quote; } diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.h b/src/server/game/AuctionHouse/AuctionHouseMgr.h index 7f70898d3f8..5b7fa258979 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.h +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.h @@ -237,8 +237,8 @@ struct AuctionPosting uint64 BuyoutOrUnitPrice = 0; uint64 Deposit = 0; uint64 BidAmount = 0; - std::chrono::system_clock::time_point StartTime = std::chrono::system_clock::time_point::min(); - std::chrono::system_clock::time_point EndTime = std::chrono::system_clock::time_point::min(); + SystemTimePoint StartTime = SystemTimePoint::min(); + SystemTimePoint EndTime = SystemTimePoint::min(); GuidUnorderedSet BidderHistory; @@ -255,7 +255,7 @@ struct CommodityQuote { uint64 TotalPrice = 0; uint32 Quantity = 0; - std::chrono::steady_clock::time_point ValidTo = std::chrono::steady_clock::time_point::min(); + TimePoint ValidTo = TimePoint::min(); }; struct AuctionThrottleResult @@ -277,7 +277,7 @@ public: uint32 Global = 0; uint32 Cursor = 0; uint32 Tombstone = 0; - std::chrono::steady_clock::time_point NextAllowedReplication = std::chrono::steady_clock::time_point::min(); + TimePoint NextAllowedReplication = TimePoint::min(); bool IsReplicationInProgress() const { return Cursor != Tombstone && Global != 0; } }; @@ -407,7 +407,7 @@ class TC_GAME_API AuctionHouseMgr struct PlayerThrottleObject { - std::chrono::steady_clock::time_point PeriodEnd; + TimePoint PeriodEnd; uint8 QueriesRemaining = 100; }; @@ -418,7 +418,7 @@ class TC_GAME_API AuctionHouseMgr uint32 _replicateIdGenerator; std::unordered_map<ObjectGuid, PlayerThrottleObject> _playerThrottleObjects; - std::chrono::steady_clock::time_point _playerThrottleObjectsCleanupTime; + TimePoint _playerThrottleObjectsCleanupTime; }; #define sAuctionMgr AuctionHouseMgr::instance() diff --git a/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp b/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp index b93a979033c..403562c998c 100644 --- a/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp +++ b/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp @@ -507,7 +507,7 @@ void AuctionHouseBot::Rebuild(bool all) for (auto itr = auctionHouse->GetAuctionsBegin(); itr != auctionHouse->GetAuctionsEnd(); ++itr) if (itr->second.Owner.IsEmpty() || sAuctionBotConfig->IsBotChar(itr->second.Owner)) // ahbot auction if (all || itr->second.BidAmount == 0) // expire now auction if no bid or forced - itr->second.EndTime = GameTime::GetGameTimeSystemPoint(); + itr->second.EndTime = GameTime::GetSystemTime(); } } diff --git a/src/server/game/AuctionHouseBot/AuctionHouseBotSeller.cpp b/src/server/game/AuctionHouseBot/AuctionHouseBotSeller.cpp index be9c501923e..18381c4d4b0 100644 --- a/src/server/game/AuctionHouseBot/AuctionHouseBotSeller.cpp +++ b/src/server/game/AuctionHouseBot/AuctionHouseBotSeller.cpp @@ -899,7 +899,7 @@ void AuctionBotSeller::AddNewAuctions(SellerConfiguration& config) auction.MinBid = bidPrice; auction.BuyoutOrUnitPrice = buyoutPrice; - auction.StartTime = GameTime::GetGameTimeSystemPoint(); + auction.StartTime = GameTime::GetSystemTime(); auction.EndTime = auction.StartTime + Hours(urand(config.GetMinTime(), config.GetMaxTime())); auctionHouse->AddAuction(trans, std::move(auction)); diff --git a/src/server/game/Battlegrounds/Battleground.cpp b/src/server/game/Battlegrounds/Battleground.cpp index 05e63758917..252ac94c6c9 100644 --- a/src/server/game/Battlegrounds/Battleground.cpp +++ b/src/server/game/Battlegrounds/Battleground.cpp @@ -1077,7 +1077,7 @@ void Battleground::AddPlayer(Player* player) { Milliseconds duration(GetElapsedTime() - BG_START_DELAY_2M); pvpMatchInitialize.Duration = std::chrono::duration_cast<Seconds>(duration); - pvpMatchInitialize.StartTime = GameTime::GetGameTimeSystemPoint() - duration; + pvpMatchInitialize.StartTime = GameTime::GetSystemTime() - duration; } pvpMatchInitialize.ArenaFaction = player->GetBGTeam() == HORDE ? PVP_TEAM_HORDE : PVP_TEAM_ALLIANCE; pvpMatchInitialize.BattlemasterListID = GetTypeID(); diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index c187baebbb7..f6673e64aa1 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -24671,7 +24671,7 @@ void Player::ApplyEquipCooldown(Item* pItem) if (pItem->GetTemplate()->HasFlag(ITEM_FLAG_NO_EQUIP_COOLDOWN)) return; - std::chrono::steady_clock::time_point now = GameTime::GetGameTimeSteadyPoint(); + TimePoint now = GameTime::Now(); for (ItemEffectEntry const* effectData : pItem->GetEffects()) { SpellInfo const* effectSpellInfo = sSpellMgr->GetSpellInfo(effectData->SpellID, DIFFICULTY_NONE); diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 583edc58015..d69608485fb 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -9718,7 +9718,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 = GameTime::GetGameTimeSteadyPoint(); + TimePoint now = GameTime::Now(); // use provided list of auras which can proc if (procAuras) diff --git a/src/server/game/Handlers/AuctionHouseHandler.cpp b/src/server/game/Handlers/AuctionHouseHandler.cpp index e5d0c4b51ab..758e0989af0 100644 --- a/src/server/game/Handlers/AuctionHouseHandler.cpp +++ b/src/server/game/Handlers/AuctionHouseHandler.cpp @@ -182,7 +182,7 @@ void WorldSession::HandleAuctionGetCommodityQuote(WorldPackets::AuctionHouse::Au { commodityQuoteResult.TotalPrice = quote->TotalPrice; commodityQuoteResult.Quantity = quote->Quantity; - commodityQuoteResult.QuoteDuration = std::chrono::duration_cast<Milliseconds>(quote->ValidTo - GameTime::GetGameTimeSteadyPoint()); + commodityQuoteResult.QuoteDuration = std::chrono::duration_cast<Milliseconds>(quote->ValidTo - GameTime::Now()); } commodityQuoteResult.ItemID = getCommodityQuote.ItemID; @@ -695,7 +695,7 @@ void WorldSession::HandleAuctionSellCommodity(WorldPackets::AuctionHouse::Auctio auction.OwnerAccount = GetAccountGUID(); auction.BuyoutOrUnitPrice = sellCommodity.UnitPrice; auction.Deposit = deposit; - auction.StartTime = GameTime::GetGameTimeSystemPoint(); + auction.StartTime = GameTime::GetSystemTime(); auction.EndTime = auction.StartTime + auctionTime; // keep track of what was cloned to undo/modify counts later @@ -890,7 +890,7 @@ void WorldSession::HandleAuctionSellItem(WorldPackets::AuctionHouse::AuctionSell auction.BuyoutOrUnitPrice = sellItem.BuyoutPrice; auction.Deposit = deposit; auction.BidAmount = sellItem.MinBid; - auction.StartTime = GameTime::GetGameTimeSystemPoint(); + auction.StartTime = GameTime::GetSystemTime(); auction.EndTime = auction.StartTime + auctionTime; if (HasPermission(rbac::RBAC_PERM_LOG_GM_TRADE)) diff --git a/src/server/game/Handlers/GuildHandler.cpp b/src/server/game/Handlers/GuildHandler.cpp index 1e4cf28ed9e..8c82e3ae0e7 100644 --- a/src/server/game/Handlers/GuildHandler.cpp +++ b/src/server/game/Handlers/GuildHandler.cpp @@ -550,7 +550,7 @@ void WorldSession::HandleRequestGuildRewardsList(WorldPackets::Guild::RequestGui std::vector<GuildReward> const& rewards = sGuildMgr->GetGuildRewards(); WorldPackets::Guild::GuildRewardList rewardList; - rewardList.Version = GameTime::GetGameTimeSystemPoint(); + rewardList.Version = GameTime::GetSystemTime(); rewardList.RewardItems.reserve(rewards.size()); for (uint32 i = 0; i < rewards.size(); i++) diff --git a/src/server/game/Handlers/MiscHandler.cpp b/src/server/game/Handlers/MiscHandler.cpp index 06dc63a9e00..07b23c7d6db 100644 --- a/src/server/game/Handlers/MiscHandler.cpp +++ b/src/server/game/Handlers/MiscHandler.cpp @@ -1058,7 +1058,7 @@ void WorldSession::HandleGuildSetFocusedAchievement(WorldPackets::Achievement::G void WorldSession::HandleServerTimeOffsetRequest(WorldPackets::Misc::ServerTimeOffsetRequest& /*request*/) { WorldPackets::Misc::ServerTimeOffset response; - response.Time = GameTime::GetGameTimeSystemPoint(); + response.Time = GameTime::GetSystemTime(); SendPacket(response.Write()); } diff --git a/src/server/game/Handlers/QueryHandler.cpp b/src/server/game/Handlers/QueryHandler.cpp index eca0a1e7556..4bfb1962c89 100644 --- a/src/server/game/Handlers/QueryHandler.cpp +++ b/src/server/game/Handlers/QueryHandler.cpp @@ -60,7 +60,7 @@ void WorldSession::HandleQueryTimeOpcode(WorldPackets::Query::QueryTime& /*query void WorldSession::SendQueryTimeResponse() { WorldPackets::Query::QueryTimeResponse queryTimeResponse; - queryTimeResponse.CurrentTime = GameTime::GetGameTimeSystemPoint(); + queryTimeResponse.CurrentTime = GameTime::GetSystemTime(); SendPacket(queryTimeResponse.Write()); } diff --git a/src/server/game/Server/Packets/MiscPackets.h b/src/server/game/Server/Packets/MiscPackets.h index 80a38dbbc94..373c756c11a 100644 --- a/src/server/game/Server/Packets/MiscPackets.h +++ b/src/server/game/Server/Packets/MiscPackets.h @@ -183,7 +183,7 @@ namespace WorldPackets void Read() override; - std::chrono::steady_clock::time_point GetReceivedTime() const { return _worldPacket.GetReceivedTime(); } + TimePoint GetReceivedTime() const { return _worldPacket.GetReceivedTime(); } uint32 ClientTime = 0; // Client ticks in ms uint32 SequenceIndex = 0; // Same index as in request diff --git a/src/server/game/Server/Packets/PacketUtilities.h b/src/server/game/Server/Packets/PacketUtilities.h index 3bb3443ff06..3be2bf786a9 100644 --- a/src/server/game/Server/Packets/PacketUtilities.h +++ b/src/server/game/Server/Packets/PacketUtilities.h @@ -205,7 +205,7 @@ namespace WorldPackets public: Timestamp() = default; Timestamp(time_t value) : _value(value) { } - Timestamp(std::chrono::system_clock::time_point const& systemTime) : _value(std::chrono::system_clock::to_time_t(systemTime)) { } + Timestamp(SystemTimePoint const& systemTime) : _value(std::chrono::system_clock::to_time_t(systemTime)) { } Timestamp& operator=(time_t value) { @@ -213,7 +213,7 @@ namespace WorldPackets return *this; } - Timestamp& operator=(std::chrono::system_clock::time_point const& systemTime) + Timestamp& operator=(SystemTimePoint const& systemTime) { _value = std::chrono::system_clock::to_time_t(systemTime); return *this; diff --git a/src/server/game/Server/WorldPacket.h b/src/server/game/Server/WorldPacket.h index cb9565b1fd3..240db0ea91c 100644 --- a/src/server/game/Server/WorldPacket.h +++ b/src/server/game/Server/WorldPacket.h @@ -20,7 +20,7 @@ #include "ByteBuffer.h" #include "Opcodes.h" -#include <chrono> +#include "Duration.h" class WorldPacket : public ByteBuffer { @@ -86,13 +86,13 @@ class WorldPacket : public ByteBuffer ConnectionType GetConnection() const { return _connection; } - std::chrono::steady_clock::time_point GetReceivedTime() const { return m_receivedTime; } - void SetReceiveTime(std::chrono::steady_clock::time_point receivedTime) { m_receivedTime = receivedTime; } + TimePoint GetReceivedTime() const { return m_receivedTime; } + void SetReceiveTime(TimePoint receivedTime) { m_receivedTime = receivedTime; } protected: uint32 m_opcode; ConnectionType _connection; - std::chrono::steady_clock::time_point m_receivedTime; // only set for a specific set of opcodes, for performance reasons. + TimePoint m_receivedTime; // only set for a specific set of opcodes, for performance reasons. }; #endif diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index bb5e07a637c..3d41abb2d2a 100644 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -881,7 +881,7 @@ void WorldSession::SendAccountDataTimes(ObjectGuid playerGuid, uint32 mask) { WorldPackets::ClientConfig::AccountDataTimes accountDataTimes; accountDataTimes.PlayerGuid = playerGuid; - accountDataTimes.ServerTime = GameTime::GetGameTimeSystemPoint(); + accountDataTimes.ServerTime = GameTime::GetSystemTime(); for (uint32 i = 0; i < NUM_ACCOUNT_DATA_TYPES; ++i) if (mask & (1 << i)) accountDataTimes.AccountTimes[i] = GetAccountData(AccountDataType(i))->Time; diff --git a/src/server/game/Server/WorldSocket.h b/src/server/game/Server/WorldSocket.h index a24b9fa92e9..0bf75b8300f 100644 --- a/src/server/game/Server/WorldSocket.h +++ b/src/server/game/Server/WorldSocket.h @@ -28,7 +28,7 @@ #include "WorldPacketCrypt.h" #include "MPSCQueue.h" #include <array> -#include <chrono> +#include <boost/asio/ip/tcp.hpp> #include <functional> #include <mutex> @@ -158,7 +158,7 @@ private: SessionKey _sessionKey; std::array<uint8, 16> _encryptKey; - std::chrono::steady_clock::time_point _LastPingTime; + TimePoint _LastPingTime; uint32 _OverSpeedPings; std::mutex _worldSessionLock; diff --git a/src/server/game/Spells/Auras/SpellAuras.cpp b/src/server/game/Spells/Auras/SpellAuras.cpp index 5af4acd8481..899dd94f526 100644 --- a/src/server/game/Spells/Auras/SpellAuras.cpp +++ b/src/server/game/Spells/Auras/SpellAuras.cpp @@ -459,8 +459,8 @@ m_castItemLevel(createInfo.CastItemLevel), m_spellVisual({ createInfo.Caster ? c m_applyTime(GameTime::GetGameTime()), m_owner(createInfo._owner), m_timeCla(0), m_updateTargetMapInterval(0), m_casterLevel(createInfo.Caster ? createInfo.Caster->GetLevel() : m_spellInfo->SpellLevel), m_procCharges(0), m_stackAmount(1), m_isRemoved(false), m_isSingleTarget(false), m_isUsingCharges(false), m_dropEvent(nullptr), -m_procCooldown(std::chrono::steady_clock::time_point::min()), -m_lastProcAttemptTime(std::chrono::steady_clock::now() - Seconds(10)), m_lastProcSuccessTime(std::chrono::steady_clock::now() - Seconds(120)) +m_procCooldown(TimePoint::min()), +m_lastProcAttemptTime(GameTime::Now() - Seconds(10)), m_lastProcSuccessTime(GameTime::Now() - Seconds(120)) { for (SpellPowerEntry const* power : m_spellInfo->PowerCosts) if (power && (power->ManaPerSecond != 0 || power->PowerPctPerSecond > 0.0f)) @@ -1713,22 +1713,22 @@ bool Aura::CanStackWith(Aura const* existingAura) const return true; } -bool Aura::IsProcOnCooldown(std::chrono::steady_clock::time_point now) const +bool Aura::IsProcOnCooldown(TimePoint now) const { return m_procCooldown > now; } -void Aura::AddProcCooldown(std::chrono::steady_clock::time_point cooldownEnd) +void Aura::AddProcCooldown(TimePoint cooldownEnd) { m_procCooldown = cooldownEnd; } void Aura::ResetProcCooldown() { - m_procCooldown = std::chrono::steady_clock::now(); + m_procCooldown = GameTime::Now(); } -void Aura::PrepareProcToTrigger(AuraApplication* aurApp, ProcEventInfo& eventInfo, std::chrono::steady_clock::time_point now) +void Aura::PrepareProcToTrigger(AuraApplication* aurApp, ProcEventInfo& eventInfo, TimePoint now) { bool prepare = CallScriptPrepareProcHandlers(aurApp, eventInfo); if (!prepare) @@ -1755,7 +1755,7 @@ void Aura::PrepareProcToTrigger(AuraApplication* aurApp, ProcEventInfo& eventInf SetLastProcSuccessTime(now); } -uint32 Aura::GetProcEffectMask(AuraApplication* aurApp, ProcEventInfo& eventInfo, std::chrono::steady_clock::time_point now) const +uint32 Aura::GetProcEffectMask(AuraApplication* aurApp, ProcEventInfo& eventInfo, TimePoint now) const { SpellProcEntry const* procEntry = sSpellMgr->GetSpellProcEntry(GetSpellInfo()); // only auras with spell proc entry can trigger proc @@ -1937,7 +1937,7 @@ float Aura::CalcPPMProcChance(Unit* actor) const float ppm = m_spellInfo->CalcProcPPM(actor, GetCastItemLevel()); float averageProcInterval = 60.0f / ppm; - std::chrono::steady_clock::time_point currentTime = GameTime::GetGameTimeSteadyPoint(); + TimePoint currentTime = GameTime::Now(); float secondsSinceLastAttempt = std::min(std::chrono::duration_cast<FSeconds>(currentTime - m_lastProcAttemptTime).count(), 10.0f); float secondsSinceLastProc = std::min(std::chrono::duration_cast<FSeconds>(currentTime - m_lastProcSuccessTime).count(), 1000.0f); diff --git a/src/server/game/Spells/Auras/SpellAuras.h b/src/server/game/Spells/Auras/SpellAuras.h index 0c1bb5b4f32..675c0e159f1 100644 --- a/src/server/game/Spells/Auras/SpellAuras.h +++ b/src/server/game/Spells/Auras/SpellAuras.h @@ -246,18 +246,18 @@ class TC_GAME_API Aura bool CheckAreaTarget(Unit* target); bool CanStackWith(Aura const* existingAura) const; - bool IsProcOnCooldown(std::chrono::steady_clock::time_point now) const; - void AddProcCooldown(std::chrono::steady_clock::time_point cooldownEnd); + bool IsProcOnCooldown(TimePoint now) const; + void AddProcCooldown(TimePoint cooldownEnd); void ResetProcCooldown(); bool IsUsingCharges() const { return m_isUsingCharges; } void SetUsingCharges(bool val) { m_isUsingCharges = val; } - void PrepareProcToTrigger(AuraApplication* aurApp, ProcEventInfo& eventInfo, std::chrono::steady_clock::time_point now); - uint32 GetProcEffectMask(AuraApplication* aurApp, ProcEventInfo& eventInfo, std::chrono::steady_clock::time_point now) const; + void PrepareProcToTrigger(AuraApplication* aurApp, ProcEventInfo& eventInfo, TimePoint now); + uint32 GetProcEffectMask(AuraApplication* aurApp, ProcEventInfo& eventInfo, TimePoint now) const; float CalcProcChance(SpellProcEntry const& procEntry, ProcEventInfo& eventInfo) const; void TriggerProcOnEvent(uint32 procEffectMask, AuraApplication* aurApp, ProcEventInfo& eventInfo); float CalcPPMProcChance(Unit* actor) const; - void SetLastProcAttemptTime(std::chrono::steady_clock::time_point lastProcAttemptTime) { m_lastProcAttemptTime = lastProcAttemptTime; } - void SetLastProcSuccessTime(std::chrono::steady_clock::time_point lastProcSuccessTime) { m_lastProcSuccessTime = lastProcSuccessTime; } + void SetLastProcAttemptTime(TimePoint lastProcAttemptTime) { m_lastProcAttemptTime = lastProcAttemptTime; } + void SetLastProcSuccessTime(TimePoint lastProcSuccessTime) { m_lastProcSuccessTime = lastProcSuccessTime; } // AuraScript void LoadScripts(); @@ -341,9 +341,9 @@ class TC_GAME_API Aura ChargeDropEvent* m_dropEvent; - std::chrono::steady_clock::time_point m_procCooldown; - std::chrono::steady_clock::time_point m_lastProcAttemptTime; - std::chrono::steady_clock::time_point m_lastProcSuccessTime; + TimePoint m_procCooldown; + TimePoint m_lastProcAttemptTime; + TimePoint m_lastProcSuccessTime; private: std::vector<AuraApplication*> _removedApplications; diff --git a/src/server/game/Spells/SpellHistory.cpp b/src/server/game/Spells/SpellHistory.cpp index 669564017ea..cdb088a2903 100644 --- a/src/server/game/Spells/SpellHistory.cpp +++ b/src/server/game/Spells/SpellHistory.cpp @@ -212,7 +212,7 @@ void SpellHistory::SaveToDB(CharacterDatabaseTransaction& trans) void SpellHistory::Update() { - Clock::time_point now = GameTime::GetGameTimePoint<Clock>(); + Clock::time_point now = GameTime::GetTime<Clock>(); for (auto itr = _categoryCooldowns.begin(); itr != _categoryCooldowns.end();) { if (itr->second->CategoryEnd < now) @@ -295,7 +295,7 @@ void SpellHistory::WritePacket(WorldPackets::Spells::SendSpellHistory* sendSpell { sendSpellHistory->Entries.reserve(_spellCooldowns.size()); - Clock::time_point now = GameTime::GetGameTimePoint<Clock>(); + Clock::time_point now = GameTime::GetTime<Clock>(); for (auto const& p : _spellCooldowns) { WorldPackets::Spells::SpellHistoryEntry historyEntry; @@ -330,7 +330,7 @@ void SpellHistory::WritePacket(WorldPackets::Spells::SendSpellCharges* sendSpell { sendSpellCharges->Entries.reserve(_categoryCharges.size()); - Clock::time_point now = GameTime::GetGameTimePoint<Clock>(); + Clock::time_point now = GameTime::GetTime<Clock>(); for (auto const& p : _categoryCharges) { if (!p.second.empty()) @@ -351,7 +351,7 @@ void SpellHistory::WritePacket(WorldPackets::Spells::SendSpellCharges* sendSpell template<> void SpellHistory::WritePacket(WorldPackets::Pet::PetSpells* petSpells) const { - Clock::time_point now = GameTime::GetGameTimePoint<Clock>(); + Clock::time_point now = GameTime::GetTime<Clock>(); petSpells->Cooldowns.reserve(_spellCooldowns.size()); for (auto const& p : _spellCooldowns) @@ -403,7 +403,7 @@ void SpellHistory::StartCooldown(SpellInfo const* spellInfo, uint32 itemId, Spel Duration cooldown = Duration::zero(); Duration categoryCooldown = Duration::zero(); - Clock::time_point curTime = GameTime::GetGameTimePoint<Clock>(); + Clock::time_point curTime = GameTime::GetTime<Clock>(); Clock::time_point catrecTime; Clock::time_point recTime; bool needsCooldownPacket = false; @@ -573,7 +573,7 @@ void SpellHistory::ModifySpellCooldown(uint32 spellId, Duration offset, bool wit if (!offset.count() || itr == _spellCooldowns.end()) return; - Clock::time_point now = GameTime::GetGameTimePoint<Clock>(); + Clock::time_point now = GameTime::GetTime<Clock>(); itr->second.CooldownEnd += offset; @@ -696,7 +696,7 @@ SpellHistory::Duration SpellHistory::GetRemainingCooldown(SpellInfo const* spell end = catItr->second->CategoryEnd; } - Clock::time_point now = GameTime::GetGameTimePoint<Clock>(); + Clock::time_point now = GameTime::GetTime<Clock>(); if (end < now) return Duration::zero(); @@ -713,7 +713,7 @@ SpellHistory::Duration SpellHistory::GetRemainingCategoryCooldown(uint32 categor end = catItr->second->CategoryEnd; - Clock::time_point now = GameTime::GetGameTimePoint<Clock>(); + Clock::time_point now = GameTime::GetTime<Clock>(); if (end < now) return Duration::zero(); @@ -728,7 +728,7 @@ SpellHistory::Duration SpellHistory::GetRemainingCategoryCooldown(SpellInfo cons void SpellHistory::LockSpellSchool(SpellSchoolMask schoolMask, Duration lockoutTime) { - Clock::time_point now = GameTime::GetGameTimePoint<Clock>(); + Clock::time_point now = GameTime::GetTime<Clock>(); Clock::time_point lockoutEnd = now + lockoutTime; for (uint32 i = 0; i < MAX_SPELL_SCHOOL; ++i) if (SpellSchoolMask(1 << i) & schoolMask) @@ -784,7 +784,7 @@ void SpellHistory::LockSpellSchool(SpellSchoolMask schoolMask, Duration lockoutT bool SpellHistory::IsSchoolLocked(SpellSchoolMask schoolMask) const { - Clock::time_point now = GameTime::GetGameTimePoint<Clock>(); + Clock::time_point now = GameTime::GetTime<Clock>(); for (uint32 i = 0; i < MAX_SPELL_SCHOOL; ++i) if (SpellSchoolMask(1 << i) & schoolMask) if (_schoolLockouts[i] > now) @@ -804,7 +804,7 @@ bool SpellHistory::ConsumeCharge(uint32 chargeCategoryId) Clock::time_point recoveryStart; std::deque<ChargeEntry>& charges = _categoryCharges[chargeCategoryId]; if (charges.empty()) - recoveryStart = GameTime::GetGameTimePoint<Clock>(); + recoveryStart = GameTime::GetTime<Clock>(); else recoveryStart = charges.back().RechargeEnd; @@ -825,7 +825,7 @@ void SpellHistory::ModifyChargeRecoveryTime(uint32 chargeCategoryId, Duration co if (itr == _categoryCharges.end() || itr->second.empty()) return; - Clock::time_point now = GameTime::GetGameTimePoint<Clock>(); + Clock::time_point now = GameTime::GetTime<Clock>(); for (ChargeEntry& entry : itr->second) { @@ -1047,7 +1047,7 @@ void SpellHistory::RestoreCooldownStateAfterDuel() for (auto const& c : _spellCooldowns) { - Clock::time_point now = GameTime::GetGameTimePoint<Clock>(); + Clock::time_point now = GameTime::GetTime<Clock>(); uint32 cooldownDuration = uint32(c.second.CooldownEnd > now ? std::chrono::duration_cast<Milliseconds>(c.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 04b5793cf20..5aea2d26702 100644 --- a/src/server/game/Spells/SpellHistory.h +++ b/src/server/game/Spells/SpellHistory.h @@ -99,7 +99,7 @@ public: void AddCooldown(uint32 spellId, uint32 itemId, Duration cooldownDuration) { - Clock::time_point now = GameTime::GetGameTimePoint<Clock>(); + Clock::time_point now = GameTime::GetTime<Clock>(); AddCooldown(spellId, itemId, now + cooldownDuration, 0, now); } diff --git a/src/server/game/Time/GameTime.cpp b/src/server/game/Time/GameTime.cpp index 141d353627b..399be3196b3 100644 --- a/src/server/game/Time/GameTime.cpp +++ b/src/server/game/Time/GameTime.cpp @@ -26,8 +26,8 @@ namespace GameTime time_t GameTime = time(nullptr); 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(); + SystemTimePoint GameTimeSystemPoint = SystemTimePoint::min(); + TimePoint GameTimeSteadyPoint = TimePoint::min(); tm DateTime; @@ -46,32 +46,32 @@ namespace GameTime return GameMSTime; } - std::chrono::system_clock::time_point GetGameTimeSystemPoint() + SystemTimePoint GetSystemTime() { return GameTimeSystemPoint; } - std::chrono::steady_clock::time_point GetGameTimeSteadyPoint() + TimePoint Now() { return GameTimeSteadyPoint; } template<typename Clock> - typename Clock::time_point GetGameTimePoint() + typename Clock::time_point GetTime() { static_assert(!std::is_same<Clock, Clock>::value, "Missing specialization for GetGameTimePoint"); } template<> - TC_GAME_API std::chrono::system_clock::time_point GetGameTimePoint<std::chrono::system_clock>() + TC_GAME_API SystemTimePoint GetTime<std::chrono::system_clock>() { - return GetGameTimeSystemPoint(); + return GetSystemTime(); } template<> - TC_GAME_API std::chrono::steady_clock::time_point GetGameTimePoint<std::chrono::steady_clock>() + TC_GAME_API TimePoint GetTime<std::chrono::steady_clock>() { - return GetGameTimeSteadyPoint(); + return Now(); } uint32 GetUptime() diff --git a/src/server/game/Time/GameTime.h b/src/server/game/Time/GameTime.h index e24c5955fd2..4229872e016 100644 --- a/src/server/game/Time/GameTime.h +++ b/src/server/game/Time/GameTime.h @@ -19,7 +19,7 @@ #define __GAMETIME_H #include "Define.h" -#include <chrono> +#include "Duration.h" namespace GameTime { @@ -33,14 +33,14 @@ namespace GameTime TC_GAME_API uint32 GetGameTimeMS(); /// Current chrono system_clock time point - TC_GAME_API std::chrono::system_clock::time_point GetGameTimeSystemPoint(); + TC_GAME_API SystemTimePoint GetSystemTime(); /// Current chrono steady_clock time point - TC_GAME_API std::chrono::steady_clock::time_point GetGameTimeSteadyPoint(); + TC_GAME_API TimePoint Now(); /// Current chrono Clock time point template<typename Clock> - typename Clock::time_point GetGameTimePoint(); + typename Clock::time_point GetTime(); /// Uptime (in secs) TC_GAME_API uint32 GetUptime(); diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_icecrown_gunship_battle.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_icecrown_gunship_battle.cpp index 6017fc7c126..377c7b4f6b3 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_icecrown_gunship_battle.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_icecrown_gunship_battle.cpp @@ -848,7 +848,7 @@ class npc_high_overlord_saurfang_igb : public CreatureScript _controller.SetTransport(creature->GetTransport()); me->SetRegenerateHealth(false); me->m_CombatDistance = 70.0f; - _firstMageCooldown = GameTime::GetGameTimeSteadyPoint() + 60s; + _firstMageCooldown = GameTime::Now() + 60s; _axethrowersYellCooldown = time_t(0); _rocketeersYellCooldown = time_t(0); } @@ -858,7 +858,7 @@ class npc_high_overlord_saurfang_igb : public CreatureScript ScriptedAI::InitializeAI(); _events.Reset(); - _firstMageCooldown = GameTime::GetGameTimeSteadyPoint() + 60s; + _firstMageCooldown = GameTime::Now() + 60s; _axethrowersYellCooldown = time_t(0); _rocketeersYellCooldown = time_t(0); } @@ -910,7 +910,7 @@ class npc_high_overlord_saurfang_igb : public CreatureScript } else if (action == ACTION_SPAWN_MAGE) { - std::chrono::steady_clock::time_point now = GameTime::GetGameTimeSteadyPoint(); + TimePoint now = GameTime::Now(); if (_firstMageCooldown > now) _events.ScheduleEvent(EVENT_SUMMON_MAGE, std::chrono::duration_cast<Milliseconds>(_firstMageCooldown - now)); else @@ -1087,7 +1087,7 @@ class npc_high_overlord_saurfang_igb : public CreatureScript EventMap _events; PassengerController _controller; InstanceScript* _instance; - std::chrono::steady_clock::time_point _firstMageCooldown; + TimePoint _firstMageCooldown; time_t _axethrowersYellCooldown; time_t _rocketeersYellCooldown; }; @@ -1112,7 +1112,7 @@ class npc_muradin_bronzebeard_igb : public CreatureScript _controller.SetTransport(creature->GetTransport()); me->SetRegenerateHealth(false); me->m_CombatDistance = 70.0f; - _firstMageCooldown = GameTime::GetGameTimeSteadyPoint() + 60s; + _firstMageCooldown = GameTime::Now() + 60s; _riflemanYellCooldown = time_t(0); _mortarYellCooldown = time_t(0); } @@ -1122,7 +1122,7 @@ class npc_muradin_bronzebeard_igb : public CreatureScript ScriptedAI::InitializeAI(); _events.Reset(); - _firstMageCooldown = GameTime::GetGameTimeSteadyPoint() + 60s; + _firstMageCooldown = GameTime::Now() + 60s; _riflemanYellCooldown = time_t(0); _mortarYellCooldown = time_t(0); } @@ -1174,7 +1174,7 @@ class npc_muradin_bronzebeard_igb : public CreatureScript } else if (action == ACTION_SPAWN_MAGE) { - std::chrono::steady_clock::time_point now = GameTime::GetGameTimeSteadyPoint(); + TimePoint now = GameTime::Now(); if (_firstMageCooldown > now) _events.ScheduleEvent(EVENT_SUMMON_MAGE, std::chrono::duration_cast<Milliseconds>(_firstMageCooldown - now)); else @@ -1355,7 +1355,7 @@ class npc_muradin_bronzebeard_igb : public CreatureScript EventMap _events; PassengerController _controller; InstanceScript* _instance; - std::chrono::steady_clock::time_point _firstMageCooldown; + TimePoint _firstMageCooldown; time_t _riflemanYellCooldown; time_t _mortarYellCooldown; }; |