aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Movement
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
parent3367dd5be93b8e63dce41fe6e303aa8ec41a43db (diff)
parent89ec90753914ae89b2dbbc7a343cd8a667410af3 (diff)
Merge branch 'master' of github.com:TrinityCore/TrinityCore into 4.3.4
Diffstat (limited to 'src/server/game/Movement')
-rw-r--r--src/server/game/Movement/PathGenerator.cpp34
-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
9 files changed, 54 insertions, 69 deletions
diff --git a/src/server/game/Movement/PathGenerator.cpp b/src/server/game/Movement/PathGenerator.cpp
index 6ef93402606..ed30b59f0ec 100644
--- a/src/server/game/Movement/PathGenerator.cpp
+++ b/src/server/game/Movement/PathGenerator.cpp
@@ -97,7 +97,7 @@ dtPolyRef PathGenerator::GetPathPolyByPosition(dtPolyRef const* polyPath, uint32
for (uint32 i = 0; i < polyPathSize; ++i)
{
float closestPoint[VERTEX_SIZE];
- if (DT_SUCCESS != _navMeshQuery->closestPointOnPoly(polyPath[i], point, closestPoint))
+ if (dtStatusFailed(_navMeshQuery->closestPointOnPoly(polyPath[i], point, closestPoint)))
continue;
float d = dtVdist2DSqr(point, closestPoint);
@@ -132,8 +132,7 @@ dtPolyRef PathGenerator::GetPolyByLocation(float const* point, float* distance)
// first try with low search box
float extents[VERTEX_SIZE] = {3.0f, 5.0f, 3.0f}; // bounds of poly search area
float closestPoint[VERTEX_SIZE] = {0.0f, 0.0f, 0.0f};
- dtStatus result = _navMeshQuery->findNearestPoly(point, extents, &_filter, &polyRef, closestPoint);
- if (DT_SUCCESS == result && polyRef != INVALID_POLYREF)
+ if (dtStatusSucceed(_navMeshQuery->findNearestPoly(point, extents, &_filter, &polyRef, closestPoint)) && polyRef != INVALID_POLYREF)
{
*distance = dtVdist(closestPoint, point);
return polyRef;
@@ -141,9 +140,10 @@ dtPolyRef PathGenerator::GetPolyByLocation(float const* point, float* distance)
// still nothing ..
// try with bigger search box
- extents[1] = 200.0f;
- result = _navMeshQuery->findNearestPoly(point, extents, &_filter, &polyRef, closestPoint);
- if (DT_SUCCESS == result && polyRef != INVALID_POLYREF)
+ // Note that the extent should not overlap more than 128 polygons in the navmesh (see dtNavMeshQuery::findNearestPoly)
+ extents[1] = 50.0f;
+
+ if (dtStatusSucceed(_navMeshQuery->findNearestPoly(point, extents, &_filter, &polyRef, closestPoint)) && polyRef != INVALID_POLYREF)
{
*distance = dtVdist(closestPoint, point);
return polyRef;
@@ -228,7 +228,7 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
{
float closestPoint[VERTEX_SIZE];
// we may want to use closestPointOnPolyBoundary instead
- if (DT_SUCCESS == _navMeshQuery->closestPointOnPoly(endPoly, endPoint, closestPoint))
+ if (dtStatusSucceed(_navMeshQuery->closestPointOnPoly(endPoly, endPoint, closestPoint)))
{
dtVcopy(endPoint, closestPoint);
SetActualEndPosition(G3D::Vector3(endPoint[2], endPoint[0], endPoint[1]));
@@ -319,13 +319,13 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
// we need any point on our suffix start poly to generate poly-path, so we need last poly in prefix data
float suffixEndPoint[VERTEX_SIZE];
- if (DT_SUCCESS != _navMeshQuery->closestPointOnPoly(suffixStartPoly, endPoint, suffixEndPoint))
+ if (dtStatusFailed(_navMeshQuery->closestPointOnPoly(suffixStartPoly, endPoint, suffixEndPoint)))
{
// we can hit offmesh connection as last poly - closestPointOnPoly() don't like that
// try to recover by using prev polyref
--prefixPolyLength;
suffixStartPoly = _pathPolyRefs[prefixPolyLength-1];
- if (DT_SUCCESS != _navMeshQuery->closestPointOnPoly(suffixStartPoly, endPoint, suffixEndPoint))
+ if (dtStatusFailed(_navMeshQuery->closestPointOnPoly(suffixStartPoly, endPoint, suffixEndPoint)))
{
// suffixStartPoly is still invalid, error state
BuildShortcut();
@@ -346,7 +346,7 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
(int*)&suffixPolyLength,
MAX_PATH_LENGTH-prefixPolyLength); // max number of polygons in output path
- if (!suffixPolyLength || dtResult != DT_SUCCESS)
+ if (!suffixPolyLength || dtStatusFailed(dtResult))
{
// this is probably an error state, but we'll leave it
// and hopefully recover on the next Update
@@ -380,7 +380,7 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
(int*)&_polyLength,
MAX_PATH_LENGTH); // max number of polygons in output path
- if (!_polyLength || dtResult != DT_SUCCESS)
+ if (!_polyLength || dtStatusFailed(dtResult))
{
// only happens if we passed bad data to findPath(), or navmesh is messed up
TC_LOG_ERROR(LOG_FILTER_MAPS, "%u's Path Build failed: 0 length path", _sourceUnit->GetGUIDLow());
@@ -430,7 +430,7 @@ void PathGenerator::BuildPointPath(const float *startPoint, const float *endPoin
_pointPathLimit); // maximum number of points
}
- if (pointCount < 2 || dtResult != DT_SUCCESS)
+ if (pointCount < 2 || dtStatusFailed(dtResult))
{
// only happens if pass bad data to findStraightPath or navmesh is broken
// single point paths can be generated here
@@ -577,7 +577,7 @@ bool PathGenerator::HaveTile(const G3D::Vector3& p) const
if (tx < 0 || ty < 0)
return false;
- return (_navMesh->getTileAt(tx, ty) != NULL);
+ return (_navMesh->getTileAt(tx, ty, 0) != NULL);
}
uint32 PathGenerator::FixupCorridor(dtPolyRef* path, uint32 npath, uint32 maxPath, dtPolyRef const* visited, uint32 nvisited)
@@ -637,7 +637,7 @@ bool PathGenerator::GetSteerTarget(float const* startPos, float const* endPos,
uint32 nsteerPath = 0;
dtStatus dtResult = _navMeshQuery->findStraightPath(startPos, endPos, path, pathSize,
steerPath, steerPathFlags, steerPathPolys, (int*)&nsteerPath, MAX_STEER_POINTS);
- if (!nsteerPath || DT_SUCCESS != dtResult)
+ if (!nsteerPath || dtStatusFailed(dtResult))
return false;
// Find vertex far enough to steer to.
@@ -674,10 +674,10 @@ dtStatus PathGenerator::FindSmoothPath(float const* startPos, float const* endPo
uint32 npolys = polyPathSize;
float iterPos[VERTEX_SIZE], targetPos[VERTEX_SIZE];
- if (DT_SUCCESS != _navMeshQuery->closestPointOnPolyBoundary(polys[0], startPos, iterPos))
+ if (dtStatusFailed(_navMeshQuery->closestPointOnPolyBoundary(polys[0], startPos, iterPos)))
return DT_FAILURE;
- if (DT_SUCCESS != _navMeshQuery->closestPointOnPolyBoundary(polys[npolys-1], endPos, targetPos))
+ if (dtStatusFailed(_navMeshQuery->closestPointOnPolyBoundary(polys[npolys-1], endPos, targetPos)))
return DT_FAILURE;
dtVcopy(&smoothPath[nsmoothPath*VERTEX_SIZE], iterPos);
@@ -756,7 +756,7 @@ dtStatus PathGenerator::FindSmoothPath(float const* startPos, float const* endPo
// Handle the connection.
float startPos[VERTEX_SIZE], endPos[VERTEX_SIZE];
- if (DT_SUCCESS == _navMesh->getOffMeshConnectionPolyEndPoints(prevRef, polyRef, startPos, endPos))
+ if (dtStatusSucceed(_navMesh->getOffMeshConnectionPolyEndPoints(prevRef, polyRef, startPos, endPos)))
{
if (nsmoothPath < maxSmoothPathSize)
{
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[] =