TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Movement::MoveSpline Class Reference

#include <MoveSpline.h>

Public Types

enum  UpdateResult { Result_None = 0x01, Result_Arrived = 0x02, Result_NextCycle = 0x04, Result_NextSegment = 0x08 }
 
typedef Spline< int32MySpline
 

Public Member Functions

int32 Duration () const
 
MySpline const_Spline () const
 
int32 _currentSplineIdx () const
 
void _Finalize ()
 
void _Interrupt ()
 
void Initialize (const MoveSplineInitArgs &)
 
bool Initialized () const
 
 MoveSpline ()
 
template<class UpdateHandler >
void updateState (int32 difftime, UpdateHandler &handler)
 
void updateState (int32 difftime)
 
Location ComputePosition () const
 
uint32 GetId () const
 
bool Finalized () const
 
bool isCyclic () const
 
bool isFalling () const
 
Vector3 constFinalDestination () const
 
Vector3 constCurrentDestination () const
 
int32 currentPathIdx () const
 
std::string ToString () const
 

Public Attributes

bool onTransport
 

Protected Member Functions

void init_spline (const MoveSplineInitArgs &args)
 
MySpline::ControlArray constgetPath () const
 
void computeParabolicElevation (float &el) const
 
void computeFallElevation (float &el) const
 
UpdateResult _updateState (int32 &ms_time_diff)
 ============================================================================================ More...
 
int32 next_timestamp () const
 
int32 segment_time_elapsed () const
 
int32 timeElapsed () const
 
int32 timePassed () const
 

Protected Attributes

MySpline spline
 
FacingInfo facing
 
uint32 m_Id
 
MoveSplineFlag splineflags
 
int32 time_passed
 
float vertical_acceleration
 
float initialOrientation
 
int32 effect_start_time
 
int32 point_Idx
 
int32 point_Idx_offset
 

Friends

class WorldPackets::Movement::CommonMovement
 
class WorldPackets::Movement::MonsterMove
 

Member Typedef Documentation

Member Enumeration Documentation

Enumerator
Result_None 
Result_Arrived 
Result_NextCycle 
Result_NextSegment 
58  {
59  Result_None = 0x01,
60  Result_Arrived = 0x02,
61  Result_NextCycle = 0x04,
62  Result_NextSegment = 0x08
63  };
Definition: MoveSpline.h:60
Definition: MoveSpline.h:61
Definition: MoveSpline.h:59
Definition: MoveSpline.h:62

Constructor & Destructor Documentation

Movement::MoveSpline::MoveSpline ( )
191  : m_Id(0), time_passed(0),
193  onTransport(false)
194 {
195  splineflags.done = true;
196 }
int32 time_passed
Definition: MoveSpline.h:74
bool done
Definition: MoveSplineFlag.h:114
uint32 m_Id
Definition: MoveSpline.h:70
MoveSplineFlag splineflags
Definition: MoveSpline.h:72
int32 point_Idx
Definition: MoveSpline.h:81
bool onTransport
Definition: MoveSpline.h:136
float initialOrientation
Definition: MoveSpline.h:79
float vertical_acceleration
Definition: MoveSpline.h:78
int32 effect_start_time
Definition: MoveSpline.h:80
int32 point_Idx_offset
Definition: MoveSpline.h:82

Member Function Documentation

int32 Movement::MoveSpline::_currentSplineIdx ( ) const
inline
100 { return point_Idx; }
int32 point_Idx
Definition: MoveSpline.h:81
void Movement::MoveSpline::_Finalize ( )
306 {
307  splineflags.done = true;
308  point_Idx = spline.last() - 1;
309  time_passed = Duration();
310 }
int32 time_passed
Definition: MoveSpline.h:74
bool done
Definition: MoveSplineFlag.h:114
MoveSplineFlag splineflags
Definition: MoveSpline.h:72
int32 point_Idx
Definition: MoveSpline.h:81
int32 Duration() const
Definition: MoveSpline.h:98
MySpline spline
Definition: MoveSpline.h:66
void Movement::MoveSpline::_Interrupt ( )
inline
102 { splineflags.done = true; }
bool done
Definition: MoveSplineFlag.h:114
MoveSplineFlag splineflags
Definition: MoveSpline.h:72

+ Here is the caller graph for this function:

MySpline const& Movement::MoveSpline::_Spline ( ) const
inline
99 { return spline; }
MySpline spline
Definition: MoveSpline.h:66
MoveSpline::UpdateResult Movement::MoveSpline::_updateState ( int32 ms_time_diff)
protected

============================================================================================

243 {
244  if (Finalized())
245  {
246  ms_time_diff = 0;
247  return Result_Arrived;
248  }
249 
250  UpdateResult result = Result_None;
251 
252  int32 minimal_diff = std::min(ms_time_diff, segment_time_elapsed());
253  ASSERT(minimal_diff >= 0);
254  time_passed += minimal_diff;
255  ms_time_diff -= minimal_diff;
256 
257  if (time_passed >= next_timestamp())
258  {
259  ++point_Idx;
260  if (point_Idx < spline.last())
261  {
262  result = Result_NextSegment;
263  }
264  else
265  {
266  if (spline.isCyclic())
267  {
268  point_Idx = spline.first();
270  result = Result_NextCycle;
271  }
272  else
273  {
274  _Finalize();
275  ms_time_diff = 0;
276  result = Result_Arrived;
277  }
278  }
279  }
280 
281  return result;
282 }
int32 time_passed
Definition: MoveSpline.h:74
int32 segment_time_elapsed() const
Definition: MoveSpline.h:93
int32 point_Idx
Definition: MoveSpline.h:81
T min(const T &x, const T &y)
Definition: g3dmath.h:305
Definition: MoveSpline.h:60
Definition: DBUpdater.h:44
Definition: MoveSpline.h:61
int32_t int32
Definition: Define.h:146
bool Finalized() const
Definition: MoveSpline.h:129
int32 Duration() const
Definition: MoveSpline.h:98
Definition: MoveSpline.h:59
Definition: MoveSpline.h:62
#define ASSERT
Definition: Errors.h:55
int32 next_timestamp() const
Definition: MoveSpline.h:92
MySpline spline
Definition: MoveSpline.h:66
void _Finalize()
Definition: MoveSpline.cpp:305

+ Here is the call graph for this function:

void Movement::MoveSpline::computeFallElevation ( float &  el) const
protected
83 {
84  float z_now = spline.getPoint(spline.first()).z - Movement::computeFallElevation(MSToSec(time_passed), false);
85  float final_z = FinalDestination().z;
86  el = std::max(z_now, final_z);
87 }
int32 time_passed
Definition: MoveSpline.h:74
T max(const T &x, const T &y)
Definition: g3dmath.h:320
float MSToSec(uint32 ms)
Definition: MovementTypedefs.h:48
G3D::int16 z
Definition: Vector3int16.h:46
Vector3 const & FinalDestination() const
Definition: MoveSpline.h:132
float z
Definition: Vector3.h:62
float computeFallElevation(float t_passed, bool isSafeFall, float start_velocity=0.0f)
Definition: MovementUtil.cpp:59
MySpline spline
Definition: MoveSpline.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Movement::MoveSpline::computeParabolicElevation ( float &  el) const
protected
70 {
72  {
73  float t_passedf = MSToSec(time_passed - effect_start_time);
74  float t_durationf = MSToSec(Duration() - effect_start_time); //client use not modified duration here
75 
76  // -a*x*x + bx + c:
77  //(dur * v3->z_acceleration * dt)/2 - (v3->z_acceleration * dt * dt)/2 + Z;
78  el += (t_durationf - t_passedf) * 0.5f * vertical_acceleration * t_passedf;
79  }
80 }
int32 time_passed
Definition: MoveSpline.h:74
float MSToSec(uint32 ms)
Definition: MovementTypedefs.h:48
float vertical_acceleration
Definition: MoveSpline.h:78
int32 Duration() const
Definition: MoveSpline.h:98
int32 effect_start_time
Definition: MoveSpline.h:80

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Location Movement::MoveSpline::ComputePosition ( ) const
28 {
30 
31  float u = 1.f;
32  int32 seg_time = spline.length(point_Idx, point_Idx+1);
33  if (seg_time > 0)
34  u = (time_passed - spline.length(point_Idx)) / (float)seg_time;
35  Location c;
36  c.orientation = initialOrientation;
38 
40  ;// MoveSplineFlag::Animation disables falling or parabolic movement
41  else if (splineflags.parabolic)
43  else if (splineflags.falling)
45 
47  {
49  c.orientation = facing.angle;
50  else if (splineflags.final_point)
51  c.orientation = std::atan2(facing.f.y - c.y, facing.f.x - c.x);
52  //nothing to do for MoveSplineFlag::Final_Target flag
53  }
54  else
55  {
57  {
58  Vector3 hermite;
60  c.orientation = std::atan2(hermite.y, hermite.x);
61  }
62 
64  c.orientation = -c.orientation;
65  }
66  return c;
67 }
Definition: MoveSplineFlag.h:42
float x
Definition: Vector3.h:62
int32 time_passed
Definition: MoveSpline.h:74
bool done
Definition: MoveSplineFlag.h:114
Definition: MoveSplineFlag.h:38
bool parabolic
Definition: MoveSplineFlag.h:135
bool falling
Definition: MoveSplineFlag.h:115
bool orientationInversed
Definition: MoveSplineFlag.h:128
Definition: MoveSplineFlag.h:35
void evaluate_percent(float t, Vector3 &c) const
Definition: SplineImpl.h:21
MoveSplineFlag splineflags
Definition: MoveSpline.h:72
bool animation
Definition: MoveSplineFlag.h:134
int32 point_Idx
Definition: MoveSpline.h:81
bool Initialized() const
Definition: MoveSpline.h:106
float y
Definition: Vector3.h:62
bool final_point
Definition: MoveSplineFlag.h:136
void computeParabolicElevation(float &el) const
Definition: MoveSpline.cpp:69
G3D::Vector3 f
Definition: MoveSplineInitArgs.h:34
bool isFacing() const
Definition: MoveSplineFlag.h:86
length_type length() const
Definition: Spline.h:199
void computeFallElevation(float &el) const
Definition: MoveSpline.cpp:82
float initialOrientation
Definition: MoveSpline.h:79
int32_t int32
Definition: Define.h:146
float angle
Definition: MoveSplineInitArgs.h:36
static Position Location[]
Definition: boss_skadi.cpp:46
#define ASSERT
Definition: Errors.h:55
FacingInfo facing
Definition: MoveSpline.h:68
bool hasFlag(uint32 f) const
Definition: MoveSplineFlag.h:90
MySpline spline
Definition: MoveSpline.h:66
void evaluate_derivative(float t, Vector3 &hermite) const
Definition: SplineImpl.h:29
bool final_angle
Definition: MoveSplineFlag.h:138

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Vector3 const& Movement::MoveSpline::CurrentDestination ( ) const
inline
133 { return Initialized() ? spline.getPoint(point_Idx + 1) : Vector3::zero(); }
int32 point_Idx
Definition: MoveSpline.h:81
bool Initialized() const
Definition: MoveSpline.h:106
static const Vector3 & zero()
Definition: Vector3.cpp:119
MySpline spline
Definition: MoveSpline.h:66

+ Here is the call graph for this function:

int32 Movement::MoveSpline::currentPathIdx ( ) const
313 {
314  int32 point = point_Idx_offset + point_Idx - spline.first() + (int)Finalized();
315  if (isCyclic())
316  point = point % (spline.last()-spline.first());
317  return point;
318 }
int32 point_Idx
Definition: MoveSpline.h:81
int32_t int32
Definition: Define.h:146
bool Finalized() const
Definition: MoveSpline.h:129
int32 point_Idx_offset
Definition: MoveSpline.h:82
MySpline spline
Definition: MoveSpline.h:66
bool isCyclic() const
Definition: MoveSpline.h:130
int32 Movement::MoveSpline::Duration ( ) const
inline
98 { return spline.length(); }
length_type length() const
Definition: Spline.h:199
MySpline spline
Definition: MoveSpline.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Vector3 const& Movement::MoveSpline::FinalDestination ( ) const
inline
132 { return Initialized() ? spline.getPoint(spline.last()) : Vector3::zero(); }
bool Initialized() const
Definition: MoveSpline.h:106
static const Vector3 & zero()
Definition: Vector3.cpp:119
MySpline spline
Definition: MoveSpline.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Movement::MoveSpline::Finalized ( ) const
inline
129 { return splineflags.done; }
bool done
Definition: MoveSplineFlag.h:114
MoveSplineFlag splineflags
Definition: MoveSpline.h:72

+ Here is the caller graph for this function:

uint32 Movement::MoveSpline::GetId ( void  ) const
inline
128 { return m_Id; }
uint32 m_Id
Definition: MoveSpline.h:70

+ Here is the caller graph for this function:

MySpline::ControlArray const& Movement::MoveSpline::getPath ( ) const
inlineprotected
87 { return spline.getPoints(); }
MySpline spline
Definition: MoveSpline.h:66

+ Here is the caller graph for this function:

void Movement::MoveSpline::init_spline ( const MoveSplineInitArgs args)
protected
Todo:
what to do in such cases? problem is in input data (all points are at same coords)
121 {
123  if (args.flags.cyclic)
124  {
125  uint32 cyclic_point = 0;
126  // MoveSplineFlag::Enter_Cycle support dropped
127  //if (splineflags & SPLINEFLAG_ENTER_CYCLE)
128  //cyclic_point = 1; // shouldn't be modified, came from client
129  spline.init_cyclic_spline(&args.path[0], args.path.size(), modes[args.flags.isSmooth()], cyclic_point);
130  }
131  else
132  {
133  spline.init_spline(&args.path[0], args.path.size(), modes[args.flags.isSmooth()]);
134  }
135 
136  // init spline timestamps
137  if (splineflags.falling)
138  {
139  FallInitializer init(spline.getPoint(spline.first()).z);
140  spline.initLengths(init);
141  }
142  else
143  {
144  CommonInitializer init(args.velocity);
145  spline.initLengths(init);
146  }
147 
150  {
151  TC_LOG_ERROR("misc", "MoveSpline::init_spline: zero length spline, wrong input data?");
152  spline.set_length(spline.last(), spline.isCyclic() ? 1000 : 1);
153  }
154  point_Idx = spline.first();
155 }
void init_spline(const Vector3 *controls, index_type count, EvaluationMode m)
Definition: Spline.h:172
void initLengths()
Definition: SplineImpl.h:79
bool falling
Definition: MoveSplineFlag.h:115
MoveSplineFlag splineflags
Definition: MoveSpline.h:72
EvaluationMode
Definition: Spline.h:34
int32 point_Idx
Definition: MoveSpline.h:81
Definition: Spline.h:36
G3D::int16 z
Definition: Vector3int16.h:46
length_type length() const
Definition: Spline.h:199
uint32_t uint32
Definition: Define.h:150
void init_cyclic_spline(const Vector3 *controls, index_type count, EvaluationMode m, index_type cyclic_point)
Definition: Spline.h:173
Definition: MoveSpline.cpp:105
void set_length(index_type i, length_type length)
Definition: Spline.h:204
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
MySpline spline
Definition: MoveSpline.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Movement::MoveSpline::Initialize ( const MoveSplineInitArgs args)
158 {
159  splineflags = args.flags;
160  facing = args.facing;
161  m_Id = args.splineId;
162  point_Idx_offset = args.path_Idx_offset;
163  initialOrientation = args.initialOrientation;
164 
165  time_passed = 0;
166  vertical_acceleration = 0.f;
167  effect_start_time = 0;
168 
169  // Check if its a stop spline
170  if (args.flags.done)
171  {
172  spline.clear();
173  return;
174  }
175 
176  init_spline(args);
177 
178  // init parabolic / animation
179  // spline initialized, duration known and i able to compute parabolic acceleration
181  {
182  effect_start_time = Duration() * args.time_perc;
183  if (args.flags.parabolic && effect_start_time < Duration())
184  {
185  float f_duration = MSToSec(Duration() - effect_start_time);
186  vertical_acceleration = args.parabolic_amplitude * 8.f / (f_duration * f_duration);
187  }
188  }
189 }
int32 time_passed
Definition: MoveSpline.h:74
uint32 m_Id
Definition: MoveSpline.h:70
void init_spline(const MoveSplineInitArgs &args)
Definition: MoveSpline.cpp:120
MoveSplineFlag splineflags
Definition: MoveSpline.h:72
Definition: MoveSplineFlag.h:57
float MSToSec(uint32 ms)
Definition: MovementTypedefs.h:48
float initialOrientation
Definition: MoveSpline.h:79
float vertical_acceleration
Definition: MoveSpline.h:78
Definition: MoveSplineFlag.h:58
int32 Duration() const
Definition: MoveSpline.h:98
int32 effect_start_time
Definition: MoveSpline.h:80
FacingInfo facing
Definition: MoveSpline.h:68
int32 point_Idx_offset
Definition: MoveSpline.h:82
void clear()
Definition: SplineImpl.h:91
MySpline spline
Definition: MoveSpline.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Movement::MoveSpline::Initialized ( ) const
inline
106 { return !spline.empty(); }
MySpline spline
Definition: MoveSpline.h:66

+ Here is the caller graph for this function:

bool Movement::MoveSpline::isCyclic ( ) const
inline
130 { return splineflags.cyclic; }
bool cyclic
Definition: MoveSplineFlag.h:121
MoveSplineFlag splineflags
Definition: MoveSpline.h:72

+ Here is the caller graph for this function:

bool Movement::MoveSpline::isFalling ( ) const
inline
131 { return splineflags.falling; }
bool falling
Definition: MoveSplineFlag.h:115
MoveSplineFlag splineflags
Definition: MoveSpline.h:72

+ Here is the caller graph for this function:

int32 Movement::MoveSpline::next_timestamp ( ) const
inlineprotected
92 { return spline.length(point_Idx + 1); }
int32 point_Idx
Definition: MoveSpline.h:81
length_type length() const
Definition: Spline.h:199
MySpline spline
Definition: MoveSpline.h:66

+ Here is the call graph for this function:

int32 Movement::MoveSpline::segment_time_elapsed ( ) const
inlineprotected
93 { return next_timestamp() - time_passed; }
int32 time_passed
Definition: MoveSpline.h:74
int32 next_timestamp() const
Definition: MoveSpline.h:92
int32 Movement::MoveSpline::timeElapsed ( ) const
inlineprotected
94 { return Duration() - time_passed; }
int32 time_passed
Definition: MoveSpline.h:74
int32 Duration() const
Definition: MoveSpline.h:98
int32 Movement::MoveSpline::timePassed ( ) const
inlineprotected
95 { return time_passed; }
int32 time_passed
Definition: MoveSpline.h:74

+ Here is the caller graph for this function:

std::string Movement::MoveSpline::ToString ( ) const
285 {
286  std::stringstream str;
287  str << "MoveSpline" << std::endl;
288  str << "spline Id: " << GetId() << std::endl;
289  str << "flags: " << splineflags.ToString() << std::endl;
291  str << "facing angle: " << facing.angle;
292  else if (splineflags.final_target)
293  str << "facing target: " << facing.target.ToString();
294  else if (splineflags.final_point)
295  str << "facing point: " << facing.f.x << " " << facing.f.y << " " << facing.f.z;
296  str << std::endl;
297  str << "time passed: " << time_passed << std::endl;
298  str << "total time: " << Duration() << std::endl;
299  str << "spline point Id: " << point_Idx << std::endl;
300  str << "path point Id: " << currentPathIdx() << std::endl;
301  str << spline.ToString();
302  return str.str();
303 }
ObjectGuid target
Definition: MoveSplineInitArgs.h:35
float x
Definition: Vector3.h:62
int32 currentPathIdx() const
Definition: MoveSpline.cpp:312
int32 time_passed
Definition: MoveSpline.h:74
MoveSplineFlag splineflags
Definition: MoveSpline.h:72
int32 point_Idx
Definition: MoveSpline.h:81
std::string ToString() const
Definition: MovementUtil.cpp:188
float y
Definition: Vector3.h:62
bool final_point
Definition: MoveSplineFlag.h:136
G3D::Vector3 f
Definition: MoveSplineInitArgs.h:34
float angle
Definition: MoveSplineInitArgs.h:36
int32 Duration() const
Definition: MoveSpline.h:98
float z
Definition: Vector3.h:62
uint32 GetId() const
Definition: MoveSpline.h:128
FacingInfo facing
Definition: MoveSpline.h:68
bool final_target
Definition: MoveSplineFlag.h:137
MySpline spline
Definition: MoveSpline.h:66
std::string ToString() const
Definition: ObjectGuid.cpp:99
bool final_angle
Definition: MoveSplineFlag.h:138

+ Here is the call graph for this function:

template<class UpdateHandler >
void Movement::MoveSpline::updateState ( int32  difftime,
UpdateHandler &  handler 
)
inline
112  {
113  ASSERT(Initialized());
114  do
115  handler(_updateState(difftime));
116  while (difftime > 0);
117  }
bool Initialized() const
Definition: MoveSpline.h:106
UpdateResult _updateState(int32 &ms_time_diff)
============================================================================================ ...
Definition: MoveSpline.cpp:242
#define ASSERT
Definition: Errors.h:55

+ Here is the caller graph for this function:

void Movement::MoveSpline::updateState ( int32  difftime)
inline
120  {
121  ASSERT(Initialized());
122  do _updateState(difftime);
123  while (difftime > 0);
124  }
bool Initialized() const
Definition: MoveSpline.h:106
UpdateResult _updateState(int32 &ms_time_diff)
============================================================================================ ...
Definition: MoveSpline.cpp:242
#define ASSERT
Definition: Errors.h:55

Friends And Related Function Documentation

Member Data Documentation

int32 Movement::MoveSpline::effect_start_time
protected
FacingInfo Movement::MoveSpline::facing
protected
float Movement::MoveSpline::initialOrientation
protected
uint32 Movement::MoveSpline::m_Id
protected
bool Movement::MoveSpline::onTransport
int32 Movement::MoveSpline::point_Idx
protected
int32 Movement::MoveSpline::point_Idx_offset
protected
MySpline Movement::MoveSpline::spline
protected
MoveSplineFlag Movement::MoveSpline::splineflags
protected
int32 Movement::MoveSpline::time_passed
protected
float Movement::MoveSpline::vertical_acceleration
protected

The documentation for this class was generated from the following files: