aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Movement/Spline
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2013-06-18 21:04:31 +0200
committerShauren <shauren.trinity@gmail.com>2013-06-18 21:04:31 +0200
commitf517467817207a75cbe395ec96de2dceb0cac5da (patch)
tree80457050fd0d460565895aba21ba285cbf323f86 /src/server/game/Movement/Spline
parent3367dd5be93b8e63dce41fe6e303aa8ec41a43db (diff)
parent89ec90753914ae89b2dbbc7a343cd8a667410af3 (diff)
Merge branch 'master' of github.com:TrinityCore/TrinityCore into 4.3.4
Diffstat (limited to 'src/server/game/Movement/Spline')
-rw-r--r--src/server/game/Movement/Spline/MoveSpline.cpp17
-rw-r--r--src/server/game/Movement/Spline/MoveSpline.h19
-rw-r--r--src/server/game/Movement/Spline/MoveSplineFlag.h3
-rw-r--r--src/server/game/Movement/Spline/MoveSplineInit.cpp2
-rw-r--r--src/server/game/Movement/Spline/MoveSplineInit.h2
-rw-r--r--src/server/game/Movement/Spline/MoveSplineInitArgs.h9
-rw-r--r--src/server/game/Movement/Spline/MovementTypedefs.h4
-rw-r--r--src/server/game/Movement/Spline/MovementUtil.cpp33
8 files changed, 37 insertions, 52 deletions
diff --git a/src/server/game/Movement/Spline/MoveSpline.cpp b/src/server/game/Movement/Spline/MoveSpline.cpp
index 02be702d3c2..1a35271c8c6 100644
--- a/src/server/game/Movement/Spline/MoveSpline.cpp
+++ b/src/server/game/Movement/Spline/MoveSpline.cpp
@@ -23,10 +23,6 @@
namespace Movement{
-extern float computeFallTime(float path_length, bool isSafeFall);
-extern float computeFallElevation(float time_passed, bool isSafeFall, float start_velocy);
-extern float computeFallElevation(float time_passed);
-
Location MoveSpline::ComputePosition() const
{
ASSERT(Initialized());
@@ -84,12 +80,9 @@ void MoveSpline::computeParabolicElevation(float& el) const
void MoveSpline::computeFallElevation(float& el) const
{
- float z_now = spline.getPoint(spline.first()).z - Movement::computeFallElevation(MSToSec(time_passed));
+ float z_now = spline.getPoint(spline.first()).z - Movement::computeFallElevation(MSToSec(time_passed), false);
float final_z = FinalDestination().z;
- if (z_now < final_z)
- el = final_z;
- else
- el = z_now;
+ el = std::max(z_now, final_z);
}
inline uint32 computeDuration(float length, float velocity)
@@ -160,7 +153,7 @@ void MoveSpline::init_spline(const MoveSplineInitArgs& args)
point_Idx = spline.first();
}
-void MoveSpline::Initialize(const MoveSplineInitArgs& args)
+void MoveSpline::Initialize(MoveSplineInitArgs const& args)
{
splineflags = args.flags;
facing = args.facing;
@@ -168,7 +161,6 @@ void MoveSpline::Initialize(const MoveSplineInitArgs& args)
point_Idx_offset = args.path_Idx_offset;
initialOrientation = args.initialOrientation;
- onTransport = false;
time_passed = 0;
vertical_acceleration = 0.f;
effect_start_time = 0;
@@ -196,7 +188,8 @@ void MoveSpline::Initialize(const MoveSplineInitArgs& args)
}
MoveSpline::MoveSpline() : m_Id(0), time_passed(0),
- vertical_acceleration(0.f), initialOrientation(0.f), effect_start_time(0), point_Idx(0), point_Idx_offset(0)
+ vertical_acceleration(0.f), initialOrientation(0.f), effect_start_time(0), point_Idx(0), point_Idx_offset(0),
+ onTransport(false)
{
splineflags.done = true;
}
diff --git a/src/server/game/Movement/Spline/MoveSpline.h b/src/server/game/Movement/Spline/MoveSpline.h
index a76c552079b..75ea89bee81 100644
--- a/src/server/game/Movement/Spline/MoveSpline.h
+++ b/src/server/game/Movement/Spline/MoveSpline.h
@@ -49,6 +49,7 @@ namespace Movement
Result_NextSegment = 0x08
};
friend class PacketBuilder;
+
protected:
MySpline spline;
@@ -69,30 +70,30 @@ namespace Movement
int32 point_Idx_offset;
void init_spline(const MoveSplineInitArgs& args);
- protected:
- const MySpline::ControlArray& getPath() const { return spline.getPoints(); }
+ protected:
+ MySpline::ControlArray const& getPath() const { return spline.getPoints(); }
void computeParabolicElevation(float& el) const;
void computeFallElevation(float& el) const;
UpdateResult _updateState(int32& ms_time_diff);
- int32 next_timestamp() const { return spline.length(point_Idx+1); }
- int32 segment_time_elapsed() const { return next_timestamp()-time_passed; }
+ int32 next_timestamp() const { return spline.length(point_Idx + 1); }
+ int32 segment_time_elapsed() const { return next_timestamp() - time_passed; }
int32 timeElapsed() const { return Duration() - time_passed; }
int32 timePassed() const { return time_passed; }
public:
int32 Duration() const { return spline.length(); }
- const MySpline& _Spline() const { return spline; }
+ MySpline const& _Spline() const { return spline; }
int32 _currentSplineIdx() const { return point_Idx; }
void _Finalize();
- void _Interrupt() { splineflags.done = true;}
+ void _Interrupt() { splineflags.done = true; }
public:
void Initialize(const MoveSplineInitArgs&);
bool Initialized() const { return !spline.empty(); }
- explicit MoveSpline();
+ MoveSpline();
template<class UpdateHandler>
void updateState(int32 difftime, UpdateHandler& handler)
@@ -116,8 +117,8 @@ namespace Movement
bool Finalized() const { return splineflags.done; }
bool isCyclic() const { return splineflags.cyclic; }
bool isFalling() const { return splineflags.falling; }
- const Vector3 FinalDestination() const { return Initialized() ? spline.getPoint(spline.last()) : Vector3(); }
- const Vector3 CurrentDestination() const { return Initialized() ? spline.getPoint(point_Idx+1) : Vector3(); }
+ Vector3 FinalDestination() const { return Initialized() ? spline.getPoint(spline.last()) : Vector3(); }
+ Vector3 CurrentDestination() const { return Initialized() ? spline.getPoint(point_Idx + 1) : Vector3(); }
int32 currentPathIdx() const;
bool onTransport;
diff --git a/src/server/game/Movement/Spline/MoveSplineFlag.h b/src/server/game/Movement/Spline/MoveSplineFlag.h
index 08e73c0344b..f86ce6431ed 100644
--- a/src/server/game/Movement/Spline/MoveSplineFlag.h
+++ b/src/server/game/Movement/Spline/MoveSplineFlag.h
@@ -104,7 +104,8 @@ namespace Movement
void EnableAnimation(uint8 anim) { raw() = (raw() & ~(Mask_Animations | Falling | Parabolic | FallingSlow)) | Animation | (anim & Mask_Animations); }
void EnableParabolic() { raw() = (raw() & ~(Mask_Animations | Falling | Animation | FallingSlow)) | Parabolic; }
- void EnableFalling() { raw() = (raw() & ~(Mask_Animations | Parabolic | Animation)) | Falling; }
+ void EnableFlying() { raw() = (raw() & ~(Falling)) | Flying; }
+ void EnableFalling() { raw() = (raw() & ~(Mask_Animations | Parabolic | Animation | Flying)) | Falling; }
void EnableCatmullRom() { raw() = (raw() & ~SmoothGroundPath) | Catmullrom; }
void EnableFacingPoint() { raw() = (raw() & ~Mask_Final_Facing) | Final_Point; }
void EnableFacingAngle() { raw() = (raw() & ~Mask_Final_Facing) | Final_Angle; }
diff --git a/src/server/game/Movement/Spline/MoveSplineInit.cpp b/src/server/game/Movement/Spline/MoveSplineInit.cpp
index 9cc1dbb3f43..65af02360e6 100644
--- a/src/server/game/Movement/Spline/MoveSplineInit.cpp
+++ b/src/server/game/Movement/Spline/MoveSplineInit.cpp
@@ -98,6 +98,8 @@ namespace Movement
uint32 moveFlagsForSpeed = moveFlags;
if (args.flags.walkmode)
moveFlagsForSpeed |= MOVEMENTFLAG_WALKING;
+ else
+ moveFlagsForSpeed &= ~MOVEMENTFLAG_WALKING;
args.velocity = unit->GetSpeed(SelectSpeedType(moveFlagsForSpeed));
}
diff --git a/src/server/game/Movement/Spline/MoveSplineInit.h b/src/server/game/Movement/Spline/MoveSplineInit.h
index 1eaf1011a2c..c968f660f58 100644
--- a/src/server/game/Movement/Spline/MoveSplineInit.h
+++ b/src/server/game/Movement/Spline/MoveSplineInit.h
@@ -157,7 +157,7 @@ namespace Movement
Unit* unit;
};
- inline void MoveSplineInit::SetFly() { args.flags.flying = true; }
+ inline void MoveSplineInit::SetFly() { args.flags.EnableFlying(); }
inline void MoveSplineInit::SetWalk(bool enable) { args.flags.walkmode = enable; }
inline void MoveSplineInit::SetSmooth() { args.flags.EnableCatmullRom(); }
inline void MoveSplineInit::SetUncompressed() { args.flags.uncompressedPath = true; }
diff --git a/src/server/game/Movement/Spline/MoveSplineInitArgs.h b/src/server/game/Movement/Spline/MoveSplineInitArgs.h
index 4a086094c3f..474541cbf15 100644
--- a/src/server/game/Movement/Spline/MoveSplineInitArgs.h
+++ b/src/server/game/Movement/Spline/MoveSplineInitArgs.h
@@ -30,9 +30,9 @@ namespace Movement
union FacingInfo
{
- struct{
+ struct {
float x, y, z;
- }f;
+ } f;
uint64 target;
float angle;
@@ -43,8 +43,8 @@ namespace Movement
struct MoveSplineInitArgs
{
- MoveSplineInitArgs(size_t path_capacity = 16) : path_Idx_offset(0),
- velocity(0.f), parabolic_amplitude(0.f), time_perc(0.f), splineId(0), initialOrientation(0.f),
+ MoveSplineInitArgs(size_t path_capacity = 16) : path_Idx_offset(0), velocity(0.f),
+ parabolic_amplitude(0.f), time_perc(0.f), splineId(0), initialOrientation(0.f),
HasVelocity(false), TransformForTransport(true)
{
path.reserve(path_capacity);
@@ -64,6 +64,7 @@ namespace Movement
/** Returns true to show that the arguments were configured correctly and MoveSpline initialization will succeed. */
bool Validate(Unit* unit) const;
+
private:
bool _checkPathBounds() const;
};
diff --git a/src/server/game/Movement/Spline/MovementTypedefs.h b/src/server/game/Movement/Spline/MovementTypedefs.h
index f044d249fcb..1a0f3d54d27 100644
--- a/src/server/game/Movement/Spline/MovementTypedefs.h
+++ b/src/server/game/Movement/Spline/MovementTypedefs.h
@@ -44,6 +44,9 @@ namespace Movement
return ms / 1000.f;
}
+ float computeFallTime(float path_length, bool isSafeFall);
+ float computeFallElevation(float t_passed, bool isSafeFall, float start_velocity = 0.0f);
+
#ifndef static_assert
#define CONCAT(x, y) CONCAT1 (x, y)
#define CONCAT1(x, y) x##y
@@ -75,7 +78,6 @@ namespace Movement
typedef counter<uint32, 0xFFFFFFFF> UInt32Counter;
extern double gravity;
- extern float computeFallElevation(float t_passed, bool isSafeFall, float start_velocity);
extern UInt32Counter splineIdGen;
extern std::string MovementFlags_ToString(uint32 flags);
extern std::string MovementFlagsExtra_ToString(uint32 flags);
diff --git a/src/server/game/Movement/Spline/MovementUtil.cpp b/src/server/game/Movement/Spline/MovementUtil.cpp
index aaa575c752f..ee47a5ebedc 100644
--- a/src/server/game/Movement/Spline/MovementUtil.cpp
+++ b/src/server/game/Movement/Spline/MovementUtil.cpp
@@ -30,8 +30,9 @@ namespace Movement
float terminalSafefallVelocity = 7.0f;
const float terminal_length = float(terminalVelocity * terminalVelocity) / (2.0f * gravity);
- const float terminal_safefall_length = (terminalSafefallVelocity * terminalSafefallVelocity) / (2.0f * gravity);
- const float terminalFallTime = float(terminalVelocity / gravity); // the time that needed to reach terminalVelocity
+ const float terminal_safeFall_length = (terminalSafefallVelocity * terminalSafefallVelocity) / (2.0f * gravity);
+ const float terminal_fallTime = float(terminalVelocity / gravity); // the time that needed to reach terminalVelocity
+ const float terminal_safeFall_fallTime = float(terminalSafefallVelocity / gravity); // the time that needed to reach terminalVelocity with safefall
float computeFallTime(float path_length, bool isSafeFall)
{
@@ -41,15 +42,15 @@ namespace Movement
float time;
if (isSafeFall)
{
- if (path_length >= terminal_safefall_length)
- time = (path_length - terminal_safefall_length) / terminalSafefallVelocity + terminalSafefallVelocity / gravity;
+ if (path_length >= terminal_safeFall_length)
+ time = (path_length - terminal_safeFall_length) / terminalSafefallVelocity + terminal_safeFall_fallTime;
else
time = sqrtf(2.0f * path_length / gravity);
}
else
{
if (path_length >= terminal_length)
- time = (path_length - terminal_length) / terminalVelocity + terminalFallTime;
+ time = (path_length - terminal_length) / terminalVelocity + terminal_fallTime;
else
time = sqrtf(2.0f * path_length / gravity);
}
@@ -57,7 +58,7 @@ namespace Movement
return time;
}
- float computeFallElevation(float t_passed, bool isSafeFall, float start_velocity)
+ float computeFallElevation(float t_passed, bool isSafeFall, float start_velocity /*= 0.0f*/)
{
float termVel;
float result;
@@ -70,11 +71,11 @@ namespace Movement
if (start_velocity > termVel)
start_velocity = termVel;
- float terminal_time = terminalFallTime - start_velocity / gravity; // the time that needed to reach terminalVelocity
+ float terminal_time = (isSafeFall ? terminal_safeFall_fallTime : terminal_fallTime) - start_velocity / gravity; // the time that needed to reach terminalVelocity
if (t_passed > terminal_time)
{
- result = terminalVelocity * (t_passed - terminal_time) +
+ result = termVel * (t_passed - terminal_time) +
start_velocity * terminal_time +
gravity * terminal_time * terminal_time*0.5f;
}
@@ -84,22 +85,6 @@ namespace Movement
return result;
}
- float computeFallElevation(float t_passed)
- {
- float result;
-
- if (t_passed > terminalFallTime)
- {
- //result = terminalVelocity * (t_passed - terminal_time) + gravity*terminal_time*terminal_time*0.5f;
- // simplified view:
- result = terminalVelocity * (t_passed - terminalFallTime) + terminal_length;
- }
- else
- result = t_passed * t_passed * gravity * 0.5f;
-
- return result;
- }
-
#define STR(x) #x
char const* g_MovementFlag_names[] =