mirror of
https://github.com/mangosfour/server.git
synced 2025-12-27 10:37:02 +00:00
[10924] Send time diff between Update() calls for object - should help with mob respawn on inactive grids etc. Based on patches by VladimirMangos and cipherCOM. All issues from previous patches should be finally fixed now.
Signed-off-by: Ambal <pogrebniak@gala.net>
This commit is contained in:
parent
72b1d30a1c
commit
b11820593c
39 changed files with 284 additions and 149 deletions
|
|
@ -186,7 +186,7 @@ bool DatabaseMysql::_Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **p
|
|||
// guarded block for thread-safe mySQL request
|
||||
ACE_Guard<ACE_Thread_Mutex> query_connection_guard(mMutex);
|
||||
|
||||
uint32 _s = getMSTime();
|
||||
uint32 _s = WorldTimer::getMSTime();
|
||||
|
||||
if(mysql_query(mMysql, sql))
|
||||
{
|
||||
|
|
@ -196,7 +196,7 @@ bool DatabaseMysql::_Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **p
|
|||
}
|
||||
else
|
||||
{
|
||||
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", getMSTimeDiff(_s,getMSTime()), sql );
|
||||
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", WorldTimer::getMSTimeDiff(_s,WorldTimer::getMSTime()), sql );
|
||||
}
|
||||
|
||||
*pResult = mysql_store_result(mMysql);
|
||||
|
|
@ -290,7 +290,7 @@ bool DatabaseMysql::DirectExecute(const char* sql)
|
|||
// guarded block for thread-safe mySQL request
|
||||
ACE_Guard<ACE_Thread_Mutex> query_connection_guard(mMutex);
|
||||
|
||||
uint32 _s = getMSTime();
|
||||
uint32 _s = WorldTimer::getMSTime();
|
||||
|
||||
if(mysql_query(mMysql, sql))
|
||||
{
|
||||
|
|
@ -300,7 +300,7 @@ bool DatabaseMysql::DirectExecute(const char* sql)
|
|||
}
|
||||
else
|
||||
{
|
||||
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", getMSTimeDiff(_s,getMSTime()), sql );
|
||||
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", WorldTimer::getMSTimeDiff(_s,WorldTimer::getMSTime()), sql );
|
||||
}
|
||||
// end guarded block
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,20 +22,44 @@
|
|||
#include "Common.h"
|
||||
#include <ace/OS_NS_sys_time.h>
|
||||
|
||||
inline uint32 getMSTime()
|
||||
class WorldTimer
|
||||
{
|
||||
static const ACE_Time_Value ApplicationStartTime = ACE_OS::gettimeofday();
|
||||
return (ACE_OS::gettimeofday() - ApplicationStartTime).msec();
|
||||
}
|
||||
public:
|
||||
|
||||
inline uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
|
||||
{
|
||||
// getMSTime() have limited data range and this is case when it overflow in this tick
|
||||
if (oldMSTime > newMSTime)
|
||||
return (uint32(0xFFFFFFFF) - oldMSTime) + newMSTime;
|
||||
else
|
||||
return newMSTime - oldMSTime;
|
||||
}
|
||||
//get current server time
|
||||
static uint32 getMSTime();
|
||||
|
||||
//get time difference between two timestamps
|
||||
static inline uint32 getMSTimeDiff(const uint32& oldMSTime, const uint32& newMSTime)
|
||||
{
|
||||
if (oldMSTime > newMSTime)
|
||||
{
|
||||
const uint32 diff_1 = (uint32(0xFFFFFFFF) - oldMSTime) + newMSTime;
|
||||
const uint32 diff_2 = oldMSTime - newMSTime;
|
||||
|
||||
return std::min(diff_1, diff_2);
|
||||
}
|
||||
|
||||
return newMSTime - oldMSTime;
|
||||
}
|
||||
|
||||
//get last world tick time
|
||||
static MANGOS_DLL_SPEC uint32 tickTime();
|
||||
//get previous world tick time
|
||||
static MANGOS_DLL_SPEC uint32 tickPrevTime();
|
||||
//tick world timer
|
||||
static MANGOS_DLL_SPEC uint32 tick();
|
||||
|
||||
private:
|
||||
WorldTimer();
|
||||
WorldTimer(const WorldTimer& );
|
||||
|
||||
//analogue to getMSTime() but it persists m_SystemTickTime
|
||||
static uint32 getMSTime_internal(bool savetime = false);
|
||||
|
||||
static MANGOS_DLL_SPEC uint32 m_iTime;
|
||||
static MANGOS_DLL_SPEC uint32 m_iPrevTime;
|
||||
};
|
||||
|
||||
class IntervalTimer
|
||||
{
|
||||
|
|
@ -118,4 +142,4 @@ struct ShortTimeTracker
|
|||
int32 i_expiryTime;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "Util.h"
|
||||
#include "Timer.h"
|
||||
|
||||
#include "utf8cpp/utf8.h"
|
||||
#include "mersennetwister/MersenneTwister.h"
|
||||
|
|
@ -26,6 +27,60 @@
|
|||
typedef ACE_TSS<MTRand> MTRandTSS;
|
||||
static MTRandTSS mtRand;
|
||||
|
||||
static uint64 g_SystemTickTime = ACE_OS::gettimeofday().get_msec();
|
||||
|
||||
uint32 WorldTimer::m_iTime = 0;
|
||||
uint32 WorldTimer::m_iPrevTime = 0;
|
||||
|
||||
uint32 WorldTimer::tickTime() { return m_iTime; }
|
||||
uint32 WorldTimer::tickPrevTime() { return m_iPrevTime; }
|
||||
|
||||
uint32 WorldTimer::tick()
|
||||
{
|
||||
//save previous world tick time
|
||||
m_iPrevTime = m_iTime;
|
||||
|
||||
//get the new one and don't forget to persist current system time in m_SystemTickTime
|
||||
m_iTime = WorldTimer::getMSTime_internal(true);
|
||||
|
||||
//return tick diff
|
||||
return getMSTimeDiff(m_iPrevTime, m_iTime);
|
||||
}
|
||||
|
||||
uint32 WorldTimer::getMSTime()
|
||||
{
|
||||
return getMSTime_internal();
|
||||
}
|
||||
|
||||
uint32 WorldTimer::getMSTime_internal(bool savetime /*= false*/)
|
||||
{
|
||||
//get current time
|
||||
const uint64 currTime = ACE_OS::gettimeofday().get_msec();
|
||||
//calculate time diff between two world ticks
|
||||
//special case: curr_time < old_time - we suppose that our time has not ticked at all
|
||||
//this should be constant value otherwise it is possible that our time can start ticking backwards until next world tick!!!
|
||||
uint32 diff = 0;
|
||||
//regular case: curr_time >= old_time
|
||||
if(currTime >= g_SystemTickTime)
|
||||
diff = uint32(currTime - g_SystemTickTime);
|
||||
|
||||
//reset last system time value
|
||||
if(savetime)
|
||||
g_SystemTickTime = currTime;
|
||||
|
||||
//lets calculate current world time
|
||||
uint32 iRes = m_iTime;
|
||||
//normalize world time
|
||||
const uint32 tmp = uint32(0xFFFFFFFF) - iRes;
|
||||
if(tmp < diff)
|
||||
iRes = diff - tmp;
|
||||
else
|
||||
iRes += diff;
|
||||
|
||||
return iRes;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int32 irand (int32 min, int32 max)
|
||||
{
|
||||
return int32 (mtRand->randInt (max - min)) + min;
|
||||
|
|
@ -492,4 +547,4 @@ void hexEncodeByteArray(uint8* bytes, uint32 arrayLen, std::string& result)
|
|||
}
|
||||
}
|
||||
result = ss.str();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "10923"
|
||||
#define REVISION_NR "10924"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue