mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-20 09:17:36 +01:00
Spline movement controls movements of server-side controlled units (monster movement, taxi movement, etc). Proper implementation of effects such as charge, jump, cyclic movement will rely on it. However, need improve our states system before. Technical changes: * Added linear, catmullrom and bezier3 splines which based on client's algorthims. They can be reused for proper transport position interpolation. * Precission increased. There are no more position desync issues since client's position calculation formulas used. * Now possible to move by paths with multiple points, send whole path to client. -- Original author of research and implementation: SilverIce. Massive kudos. Original port for Trinity (ref #4629) Chaplain and Venugh With the following incremental fixes during my review: - Restore flightmaster end grid pre-loading - Fix uninitialized Creature::m_path_id - Add missing trinity_string entries for .movegens command - Fix a bug in WaypointMovementGenerator that would trigger unexpected pausing at waypoints for various amounts of time Known issues: - Errors like WaypointMovementGenerator::LoadPath creature XXX (Entry: YYYYY GUID: ZZZZZZ) doesn't have waypoint path id: 0. This is caused by bad DB data. This commit didn't "break" it. Do not forget to re-run CMake before compiling.
202 lines
4.2 KiB
C++
Executable File
202 lines
4.2 KiB
C++
Executable File
/*
|
|
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
|
|
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
*
|
|
* 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 TRINITY_TIMER_H
|
|
#define TRINITY_TIMER_H
|
|
|
|
#include "ace/OS_NS_sys_time.h"
|
|
#include "Common.h"
|
|
|
|
inline uint32 getMSTime()
|
|
{
|
|
static const ACE_Time_Value ApplicationStartTime = ACE_OS::gettimeofday();
|
|
return (ACE_OS::gettimeofday() - ApplicationStartTime).msec();
|
|
}
|
|
|
|
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 (0xFFFFFFFF - oldMSTime) + newMSTime;
|
|
else
|
|
return newMSTime - oldMSTime;
|
|
}
|
|
|
|
inline uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
|
|
{
|
|
return getMSTimeDiff(oldMSTime, getMSTime());
|
|
}
|
|
|
|
struct IntervalTimer
|
|
{
|
|
public:
|
|
|
|
IntervalTimer()
|
|
: _interval(0), _current(0)
|
|
{
|
|
}
|
|
|
|
void Update(time_t diff)
|
|
{
|
|
_current += diff;
|
|
if (_current < 0)
|
|
_current = 0;
|
|
}
|
|
|
|
bool Passed()
|
|
{
|
|
return _current >= _interval;
|
|
}
|
|
|
|
void Reset()
|
|
{
|
|
if (_current >= _interval)
|
|
_current -= _interval;
|
|
}
|
|
|
|
void SetCurrent(time_t current)
|
|
{
|
|
_current = current;
|
|
}
|
|
|
|
void SetInterval(time_t interval)
|
|
{
|
|
_interval = interval;
|
|
}
|
|
|
|
time_t GetInterval() const
|
|
{
|
|
return _interval;
|
|
}
|
|
|
|
time_t GetCurrent() const
|
|
{
|
|
return _current;
|
|
}
|
|
|
|
private:
|
|
|
|
time_t _interval;
|
|
time_t _current;
|
|
};
|
|
|
|
struct TimeTracker
|
|
{
|
|
public:
|
|
|
|
TimeTracker(time_t expiry)
|
|
: i_expiryTime(expiry)
|
|
{
|
|
}
|
|
|
|
void Update(time_t diff)
|
|
{
|
|
i_expiryTime -= diff;
|
|
}
|
|
|
|
bool Passed() const
|
|
{
|
|
return i_expiryTime <= 0;
|
|
}
|
|
|
|
void Reset(time_t interval)
|
|
{
|
|
i_expiryTime = interval;
|
|
}
|
|
|
|
time_t GetExpiry() const
|
|
{
|
|
return i_expiryTime;
|
|
}
|
|
|
|
private:
|
|
|
|
time_t i_expiryTime;
|
|
};
|
|
|
|
struct TimeTrackerSmall
|
|
{
|
|
public:
|
|
|
|
TimeTrackerSmall(uint32 expiry = 0)
|
|
: i_expiryTime(expiry)
|
|
{
|
|
}
|
|
|
|
void Update(int32 diff)
|
|
{
|
|
i_expiryTime -= diff;
|
|
}
|
|
|
|
bool Passed() const
|
|
{
|
|
return i_expiryTime <= 0;
|
|
}
|
|
|
|
void Reset(uint32 interval)
|
|
{
|
|
i_expiryTime = interval;
|
|
}
|
|
|
|
int32 GetExpiry() const
|
|
{
|
|
return i_expiryTime;
|
|
}
|
|
|
|
private:
|
|
|
|
int32 i_expiryTime;
|
|
};
|
|
|
|
struct PeriodicTimer
|
|
{
|
|
public:
|
|
|
|
PeriodicTimer(int32 period, int32 start_time)
|
|
: i_period(period), i_expireTime(start_time)
|
|
{
|
|
}
|
|
|
|
bool Update(const uint32 diff)
|
|
{
|
|
if ((i_expireTime -= diff) > 0)
|
|
return false;
|
|
|
|
i_expireTime += i_period > int32(diff) ? i_period : diff;
|
|
return true;
|
|
}
|
|
|
|
void SetPeriodic(int32 period, int32 start_time)
|
|
{
|
|
i_expireTime = start_time;
|
|
i_period = period;
|
|
}
|
|
|
|
// Tracker interface
|
|
void TUpdate(int32 diff) { i_expireTime -= diff; }
|
|
bool TPassed() const { return i_expireTime <= 0; }
|
|
void TReset(int32 diff, int32 period) { i_expireTime += period > diff ? period : diff; }
|
|
|
|
private:
|
|
|
|
int32 i_period;
|
|
int32 i_expireTime;
|
|
};
|
|
|
|
#endif
|