AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Movement::MoveSpline Class Reference

#include "MoveSpline.h"

Public Types

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

Public Member Functions

int32 timeElapsed () const
 
int32 timePassed () const
 
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
 
bool isWalking () const
 
Vector3 FinalDestination () const
 
Vector3 CurrentDestination () const
 
int32 currentPathIdx () const
 
bool HasAnimation () const
 
uint8 GetAnimationType () const
 
std::string ToString () const
 
bool HasStarted () const
 

Public Attributes

bool onTransport
 

Protected Member Functions

void init_spline (const MoveSplineInitArgs &args)
 
const MySpline::ControlArraygetPath () 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
 

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 PacketBuilder
 

Detailed Description

Member Typedef Documentation

◆ MySpline

Member Enumeration Documentation

◆ UpdateResult

Enumerator
Result_None 
Result_Arrived 
Result_NextCycle 
Result_NextSegment 
Result_JustArrived 
44 {
45 Result_None = 0x01,
46 Result_Arrived = 0x02,
47 Result_NextCycle = 0x04,
48 Result_NextSegment = 0x08,
49 Result_JustArrived = 0x10,
50 };
@ Result_NextSegment
Definition: MoveSpline.h:48
@ Result_Arrived
Definition: MoveSpline.h:46
@ Result_JustArrived
Definition: MoveSpline.h:49
@ Result_NextCycle
Definition: MoveSpline.h:47
@ Result_None
Definition: MoveSpline.h:45

Constructor & Destructor Documentation

◆ MoveSpline()

Movement::MoveSpline::MoveSpline ( )
192 : m_Id(0), time_passed(0),
194 onTransport(false)
195 {
196 splineflags.done = true;
197 }
int32 time_passed
Definition: MoveSpline.h:61
int32 effect_start_time
Definition: MoveSpline.h:67
float vertical_acceleration
Definition: MoveSpline.h:65
int32 point_Idx
Definition: MoveSpline.h:68
uint32 m_Id
Definition: MoveSpline.h:57
MoveSplineFlag splineflags
Definition: MoveSpline.h:59
bool onTransport
Definition: MoveSpline.h:127
float initialOrientation
Definition: MoveSpline.h:66
int32 point_Idx_offset
Definition: MoveSpline.h:69
bool done
Definition: MoveSplineFlag.h:116

References Movement::MoveSplineFlag::done, and splineflags.

Member Function Documentation

◆ _currentSplineIdx()

int32 Movement::MoveSpline::_currentSplineIdx ( ) const
inline
87{ return point_Idx; }

References point_Idx.

◆ _Finalize()

void Movement::MoveSpline::_Finalize ( )
311 {
312 splineflags.done = true;
313 point_Idx = spline.last() - 1;
315 }
MySpline spline
Definition: MoveSpline.h:53
int32 Duration() const
Definition: MoveSpline.h:85
index_type last() const
Definition: Spline.h:107

References Movement::MoveSplineFlag::done, Duration(), Movement::SplineBase::last(), point_Idx, spline, splineflags, and time_passed.

Referenced by _updateState().

◆ _Interrupt()

void Movement::MoveSpline::_Interrupt ( )
inline
89{ splineflags.done = true; }

References Movement::MoveSplineFlag::done, and splineflags.

Referenced by Unit::DisableSpline().

◆ _Spline()

MySpline const & Movement::MoveSpline::_Spline ( ) const
inline
86{ return spline; }

References spline.

◆ _updateState()

MoveSpline::UpdateResult Movement::MoveSpline::_updateState ( int32 ms_time_diff)
protected

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

245 {
246 if (Finalized())
247 {
248 ms_time_diff = 0;
249 return Result_Arrived;
250 }
251
252 UpdateResult result = Result_None;
253
254 int32 minimal_diff = std::min(ms_time_diff, segment_time_elapsed());
255 if (minimal_diff < 0)
256 minimal_diff = 0;
257
258 ASSERT(minimal_diff >= 0);
259 time_passed += minimal_diff;
260 ms_time_diff -= minimal_diff;
261
263 {
264 ++point_Idx;
265 if (point_Idx < spline.last())
266 {
267 result = Result_NextSegment;
268 }
269 else
270 {
271 if (spline.isCyclic())
272 {
276 }
277 else
278 {
279 _Finalize();
280 ms_time_diff = 0;
282 }
283 }
284 }
285
286 return result;
287 }
#define ASSERT
Definition: Errors.h:68
std::int32_t int32
Definition: Define.h:103
Definition: UpdateFetcher.h:30
int32 next_timestamp() const
Definition: MoveSpline.h:79
void _Finalize()
Definition: MoveSpline.cpp:310
bool Finalized() const
Definition: MoveSpline.h:116
UpdateResult
Definition: MoveSpline.h:44
int32 segment_time_elapsed() const
Definition: MoveSpline.h:80
bool isCyclic() const
Definition: Spline.h:111
index_type first() const
Definition: Spline.h:106

References _Finalize(), ASSERT, Duration(), Finalized(), Movement::SplineBase::first(), Movement::SplineBase::isCyclic(), Movement::SplineBase::last(), next_timestamp(), point_Idx, Result_Arrived, Result_JustArrived, Result_NextCycle, Result_NextSegment, Result_None, segment_time_elapsed(), spline, and time_passed.

Referenced by updateState().

◆ computeFallElevation()

void Movement::MoveSpline::computeFallElevation ( float &  el) const
protected
82 {
84 float final_z = FinalDestination().z;
85 el = std::max(z_now, final_z);
86 }
float computeFallElevation(float t_passed, bool isSafeFall, float start_velocity=0.0f)
Definition: MovementUtil.cpp:60
float MSToSec(uint32 ms)
Definition: MovementTypedefs.h:41
Vector3 FinalDestination() const
Definition: MoveSpline.h:120
const Vector3 & getPoint(index_type i) const
Definition: Spline.h:116

References Movement::computeFallElevation(), FinalDestination(), Movement::SplineBase::first(), Movement::SplineBase::getPoint(), Movement::MSToSec(), spline, and time_passed.

Referenced by ComputePosition().

◆ computeParabolicElevation()

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

References Duration(), effect_start_time, Movement::MSToSec(), time_passed, and vertical_acceleration.

Referenced by ComputePosition().

◆ ComputePosition()

Location Movement::MoveSpline::ComputePosition ( ) const
27 {
29
30 float u = 1.f;
31 int32 seg_time = spline.length(point_Idx, point_Idx + 1);
32 if (seg_time > 0)
33 u = (time_passed - spline.length(point_Idx)) / (float)seg_time;
34 Location c;
35 c.orientation = initialOrientation;
37
39 ;// MoveSplineFlag::Animation disables falling or parabolic movement
40 else if (splineflags.parabolic)
42 else if (splineflags.falling)
44
46 {
48 c.orientation = facing.angle;
49 else if (splineflags.final_point)
50 c.orientation = std::atan2(facing.f.y - c.y, facing.f.x - c.x);
51 //nothing to do for MoveSplineFlag::Final_Target flag
52 }
53 else
54 {
56 {
57 Vector3 hermite;
59 c.orientation = std::atan2(hermite.y, hermite.x);
60 }
61
63 c.orientation = -c.orientation;
64 }
65 return c;
66 }
void computeFallElevation(float &el) const
Definition: MoveSpline.cpp:81
bool Initialized() const
Definition: MoveSpline.h:93
FacingInfo facing
Definition: MoveSpline.h:55
void computeParabolicElevation(float &el) const
Definition: MoveSpline.cpp:68
bool parabolic
Definition: MoveSplineFlag.h:119
bool final_point
Definition: MoveSplineFlag.h:123
bool animation
Definition: MoveSplineFlag.h:129
bool isFacing() const
Definition: MoveSplineFlag.h:90
bool hasFlag(uint32 f) const
Definition: MoveSplineFlag.h:94
bool final_angle
Definition: MoveSplineFlag.h:125
@ OrientationFixed
Definition: MoveSplineFlag.h:45
@ Falling
Definition: MoveSplineFlag.h:40
bool orientationInversed
Definition: MoveSplineFlag.h:135
bool falling
Definition: MoveSplineFlag.h:117
struct Movement::FacingInfo::@299 f
float x
Definition: MoveSplineInitArgs.h:34
float angle
Definition: MoveSplineInitArgs.h:37
float y
Definition: MoveSplineInitArgs.h:34
length_type length() const
Definition: Spline.h:200
void evaluate_derivative(float t, Vector3 &hermite) const
Definition: SplineImpl.h:28
void evaluate_percent(float t, Vector3 &c) const
Definition: SplineImpl.h:20
Definition: zone_shadowmoon_valley.cpp:839
float y
Definition: zone_shadowmoon_valley.cpp:840
float z
Definition: zone_shadowmoon_valley.cpp:840
float x
Definition: zone_shadowmoon_valley.cpp:840

References Movement::FacingInfo::angle, Movement::MoveSplineFlag::animation, ASSERT, computeFallElevation(), computeParabolicElevation(), Movement::MoveSplineFlag::done, Movement::Spline< length_type >::evaluate_derivative(), Movement::Spline< length_type >::evaluate_percent(), Movement::FacingInfo::f, facing, Movement::MoveSplineFlag::Falling, Movement::MoveSplineFlag::falling, Movement::MoveSplineFlag::final_angle, Movement::MoveSplineFlag::final_point, Movement::MoveSplineFlag::hasFlag(), Initialized(), initialOrientation, Movement::MoveSplineFlag::isFacing(), Movement::Spline< length_type >::length(), Movement::Location::orientation, Movement::MoveSplineFlag::OrientationFixed, Movement::MoveSplineFlag::orientationInversed, Movement::MoveSplineFlag::parabolic, point_Idx, spline, splineflags, time_passed, Movement::FacingInfo::x, and Movement::FacingInfo::y.

Referenced by Movement::MoveSplineInit::Launch(), Movement::MoveSplineInit::Stop(), and Unit::UpdateSplinePosition().

◆ CurrentDestination()

Vector3 Movement::MoveSpline::CurrentDestination ( ) const
inline
121{ return Initialized() ? spline.getPoint(point_Idx + 1) : Vector3(); }

References Movement::SplineBase::getPoint(), Initialized(), point_Idx, and spline.

◆ currentPathIdx()

int32 Movement::MoveSpline::currentPathIdx ( ) const
318 {
319 int32 point = point_Idx_offset + point_Idx - spline.first() + (int)Finalized();
320 if (isCyclic())
321 point = point % (spline.last() - spline.first());
322 return point;
323 }
bool isCyclic() const
Definition: MoveSpline.h:117

References Finalized(), Movement::SplineBase::first(), isCyclic(), Movement::SplineBase::last(), point_Idx, point_Idx_offset, and spline.

Referenced by FlightPathMovementGenerator::DoUpdate(), SplineHandler::operator()(), and ToString().

◆ Duration()

◆ FinalDestination()

◆ Finalized()

◆ GetAnimationType()

uint8 Movement::MoveSpline::GetAnimationType ( ) const
inline
125{ return splineflags.animId; }
uint8 animId
Definition: MoveSplineFlag.h:115

References Movement::MoveSplineFlag::animId, and splineflags.

Referenced by Unit::UpdateSplineMovement().

◆ GetId()

uint32 Movement::MoveSpline::GetId ( ) const
inline

◆ getPath()

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

References Movement::SplineBase::getPoints(), and spline.

Referenced by Movement::PacketBuilder::WriteCreate().

◆ HasAnimation()

bool Movement::MoveSpline::HasAnimation ( ) const
inline

◆ HasStarted()

bool Movement::MoveSpline::HasStarted ( ) const
inline
130 {
131 return time_passed > 0;
132 }

References time_passed.

Referenced by Unit::StopMoving().

◆ init_spline()

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)
123 {
125 if (args.flags.cyclic)
126 {
127 uint32 cyclic_point = 0;
128 // MoveSplineFlag::Enter_Cycle support dropped
129 //if (splineflags & SPLINEFLAG_ENTER_CYCLE)
130 //cyclic_point = 1; // shouldn't be modified, came from client
131 spline.init_cyclic_spline(&args.path[0], args.path.size(), modes[args.flags.isSmooth()], cyclic_point);
132 }
133 else
134 {
135 spline.init_spline(&args.path[0], args.path.size(), modes[args.flags.isSmooth()]);
136 }
137
138 // init spline timestamps
140 {
141 FallInitializer init(spline.getPoint(spline.first()).z);
142 spline.initLengths(init);
143 }
144 else
145 {
146 CommonInitializer init(args.velocity);
147 spline.initLengths(init);
148 }
149
152 {
153 spline.set_length(spline.last(), spline.isCyclic() ? 1000 : 1);
154 }
156 }
std::uint32_t uint32
Definition: Define.h:107
@ minimal_duration
Definition: MoveSpline.cpp:105
EvaluationMode
Definition: Spline.h:35
@ ModeCatmullrom
Definition: Spline.h:37
@ ModeLinear
Definition: Spline.h:36
void init_spline(const Vector3 *controls, index_type count, EvaluationMode m)
Definition: Spline.h:173
void init_cyclic_spline(const Vector3 *controls, index_type count, EvaluationMode m, index_type cyclic_point)
Definition: Spline.h:174
void set_length(index_type i, length_type length)
Definition: Spline.h:205
void initLengths()
Definition: SplineImpl.h:78

References Movement::MoveSplineFlag::cyclic, Movement::MoveSplineFlag::falling, Movement::SplineBase::first(), Movement::MoveSplineInitArgs::flags, Movement::SplineBase::getPoint(), Movement::Spline< length_type >::init_cyclic_spline(), Movement::Spline< length_type >::init_spline(), Movement::Spline< length_type >::initLengths(), Movement::SplineBase::isCyclic(), Movement::MoveSplineFlag::isSmooth(), Movement::SplineBase::last(), Movement::Spline< length_type >::length(), Movement::minimal_duration, Movement::SplineBase::ModeCatmullrom, Movement::SplineBase::ModeLinear, Movement::MoveSplineInitArgs::path, point_Idx, Movement::Spline< length_type >::set_length(), spline, splineflags, and Movement::MoveSplineInitArgs::velocity.

Referenced by Initialize().

◆ Initialize()

void Movement::MoveSpline::Initialize ( const MoveSplineInitArgs args)
159 {
160 splineflags = args.flags;
161 facing = args.facing;
162 m_Id = args.splineId;
163 point_Idx_offset = args.path_Idx_offset;
164 initialOrientation = args.initialOrientation;
165
166 time_passed = 0;
169
170 // Check if its a stop spline
171 if (args.flags.done)
172 {
173 spline.clear();
174 return;
175 }
176
177 init_spline(args);
178
179 // init parabolic / animation
180 // spline initialized, duration known and i able to compute parabolic acceleration
182 {
183 effect_start_time = Duration() * args.time_perc;
184 if (args.flags.parabolic && effect_start_time < Duration())
185 {
186 float f_duration = MSToSec(Duration() - effect_start_time);
187 vertical_acceleration = args.parabolic_amplitude * 8.f / (f_duration * f_duration);
188 }
189 }
190 }
void init_spline(const MoveSplineInitArgs &args)
Definition: MoveSpline.cpp:122
@ Parabolic
Definition: MoveSplineFlag.h:42
@ Animation
Definition: MoveSplineFlag.h:52
void clear()
Definition: SplineImpl.h:90

References Movement::MoveSplineFlag::Animation, Movement::Spline< length_type >::clear(), Movement::MoveSplineFlag::done, Duration(), effect_start_time, facing, Movement::MoveSplineInitArgs::facing, Movement::MoveSplineInitArgs::flags, init_spline(), initialOrientation, Movement::MoveSplineInitArgs::initialOrientation, m_Id, Movement::MSToSec(), Movement::MoveSplineFlag::Parabolic, Movement::MoveSplineFlag::parabolic, Movement::MoveSplineInitArgs::parabolic_amplitude, Movement::MoveSplineInitArgs::path_Idx_offset, point_Idx_offset, spline, splineflags, Movement::MoveSplineInitArgs::splineId, time_passed, Movement::MoveSplineInitArgs::time_perc, and vertical_acceleration.

Referenced by Movement::MoveSplineInit::Launch(), and Movement::MoveSplineInit::Stop().

◆ Initialized()

◆ isCyclic()

bool Movement::MoveSpline::isCyclic ( ) const
inline

◆ isFalling()

bool Movement::MoveSpline::isFalling ( ) const
inline

◆ isWalking()

bool Movement::MoveSpline::isWalking ( ) const
inline
119{ return splineflags.walkmode; }
bool walkmode
Definition: MoveSplineFlag.h:120

References splineflags, and Movement::MoveSplineFlag::walkmode.

Referenced by FollowMovementGenerator< T >::DoUpdate(), and GetVelocity().

◆ next_timestamp()

int32 Movement::MoveSpline::next_timestamp ( ) const
inlineprotected

◆ segment_time_elapsed()

int32 Movement::MoveSpline::segment_time_elapsed ( ) const
inlineprotected
80{ return next_timestamp() - time_passed; }

References next_timestamp(), and time_passed.

Referenced by _updateState().

◆ timeElapsed()

int32 Movement::MoveSpline::timeElapsed ( ) const
inline
83{ return Duration() - time_passed; } // xinef: moved to public for waypoint movegen

References Duration(), and time_passed.

◆ timePassed()

int32 Movement::MoveSpline::timePassed ( ) const
inline
84{ return time_passed; } // xinef: moved to public for waypoint movegen

References time_passed.

Referenced by Movement::PacketBuilder::WriteCreate().

◆ ToString()

std::string Movement::MoveSpline::ToString ( ) const
290 {
291 std::stringstream str;
292 str << "MoveSpline" << std::endl;
293 str << "spline Id: " << GetId() << std::endl;
294 str << "flags: " << splineflags.ToString() << std::endl;
296 str << "facing angle: " << facing.angle;
297 else if (splineflags.final_target)
298 str << "facing target: " << facing.target;
299 else if (splineflags.final_point)
300 str << "facing point: " << facing.f.x << " " << facing.f.y << " " << facing.f.z;
301 str << std::endl;
302 str << "time passed: " << time_passed << std::endl;
303 str << "total time: " << Duration() << std::endl;
304 str << "spline point Id: " << point_Idx << std::endl;
305 str << "path point Id: " << currentPathIdx() << std::endl;
306 str << spline.ToString();
307 return str.str();
308 }
uint32 GetId() const
Definition: MoveSpline.h:115
int32 currentPathIdx() const
Definition: MoveSpline.cpp:317
std::string ToString() const
Definition: MovementUtil.cpp:188
bool final_target
Definition: MoveSplineFlag.h:124
uint64 target
Definition: MoveSplineInitArgs.h:36
float z
Definition: MoveSplineInitArgs.h:34
std::string ToString() const
Definition: Spline.cpp:291

References Movement::FacingInfo::angle, currentPathIdx(), Duration(), Movement::FacingInfo::f, facing, Movement::MoveSplineFlag::final_angle, Movement::MoveSplineFlag::final_point, Movement::MoveSplineFlag::final_target, GetId(), point_Idx, spline, splineflags, Movement::FacingInfo::target, time_passed, Movement::MoveSplineFlag::ToString(), Movement::SplineBase::ToString(), Movement::FacingInfo::x, Movement::FacingInfo::y, and Movement::FacingInfo::z.

◆ updateState() [1/2]

void Movement::MoveSpline::updateState ( int32  difftime)
inline
107 {
109 do _updateState(difftime);
110 while (difftime > 0);
111 }
UpdateResult _updateState(int32 &ms_time_diff)
============================================================================================
Definition: MoveSpline.cpp:244

References _updateState(), ASSERT, and Initialized().

◆ updateState() [2/2]

template<class UpdateHandler >
void Movement::MoveSpline::updateState ( int32  difftime,
UpdateHandler &  handler 
)
inline
99 {
101 do
102 handler(_updateState(difftime));
103 while (difftime > 0);
104 }

References _updateState(), ASSERT, and Initialized().

Referenced by Unit::UpdateSplineMovement().

Friends And Related Function Documentation

◆ PacketBuilder

friend class PacketBuilder
friend

Member Data Documentation

◆ effect_start_time

◆ facing

◆ initialOrientation

float Movement::MoveSpline::initialOrientation
protected

Referenced by ComputePosition(), and Initialize().

◆ m_Id

uint32 Movement::MoveSpline::m_Id
protected

Referenced by GetId(), and Initialize().

◆ onTransport

◆ point_Idx

◆ point_Idx_offset

int32 Movement::MoveSpline::point_Idx_offset
protected

Referenced by currentPathIdx(), and Initialize().

◆ spline

◆ splineflags

◆ time_passed

◆ vertical_acceleration

float Movement::MoveSpline::vertical_acceleration
protected