[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:
Ambal 2010-12-27 22:16:19 +02:00
parent 72b1d30a1c
commit b11820593c
39 changed files with 284 additions and 149 deletions

View file

@ -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();
}
}