mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-29 16:43:47 +00:00
Revert "feat(core): Ensure that all actions are compared to fixed point in time (#1236) (#1458)" (#1471)
This reverts commit 51b8773528.
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-GPL2
|
||||
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*/
|
||||
|
||||
#include "GameTime.h"
|
||||
#include "Timer.h"
|
||||
|
||||
namespace GameTime
|
||||
{
|
||||
time_t const StartTime = time(nullptr);
|
||||
|
||||
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();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-GPL2
|
||||
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*/
|
||||
|
||||
#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
|
||||
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-GPL2
|
||||
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*/
|
||||
|
||||
#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)
|
||||
sLog->outError("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)
|
||||
{
|
||||
sLog->outError("Update time diff: %u. Players online: %u.", GetAverageUpdateTime(), sessionCount);
|
||||
_lastRecordTime = gameTimeMs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WorldUpdateTime::RecordUpdateTimeDuration(std::string const& text)
|
||||
{
|
||||
_RecordUpdateTimeDuration(text, _recordUpdateTimeMin);
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-GPL2
|
||||
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*/
|
||||
|
||||
#ifndef __UPDATETIME_H
|
||||
#define __UPDATETIME_H
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "Define.h"
|
||||
|
||||
#define AVG_DIFF_COUNT 500
|
||||
|
||||
class 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;
|
||||
};
|
||||
|
||||
extern WorldUpdateTime sWorldUpdateTime;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user