[11911] Use mmaps for Spline Movement

This commit is contained in:
sixsixnine 2012-01-29 23:45:21 +01:00 committed by Schmoozerd
parent df3a5f2808
commit e738c27714
8 changed files with 55 additions and 25 deletions

View file

@ -20,11 +20,13 @@
#define MANGOSSERVER_PATH_H #define MANGOSSERVER_PATH_H
#include "Common.h" #include "Common.h"
#include <vector> #include <deque>
struct SimplePathNode struct PathNode
{ {
float x,y,z; PathNode(): x(0.0f), y(0.0f), z(0.0f) { }
PathNode(float _x, float _y, float _z): x(_x), y(_y), z(_z) { }
float x, y, z;
}; };
template<typename PathElem, typename PathNode = PathElem> template<typename PathElem, typename PathNode = PathElem>
@ -34,8 +36,22 @@ class Path
size_t size() const { return i_nodes.size(); } size_t size() const { return i_nodes.size(); }
bool empty() const { return i_nodes.empty(); } bool empty() const { return i_nodes.empty(); }
void resize(unsigned int sz) { i_nodes.resize(sz); } void resize(unsigned int sz) { i_nodes.resize(sz); }
void crop(unsigned int start, unsigned int end)
{
while(start && !i_nodes.empty())
{
i_nodes.pop_front();
--start;
}
while(end && !i_nodes.empty())
{
i_nodes.pop_back();
--end;
}
}
void clear() { i_nodes.clear(); } void clear() { i_nodes.clear(); }
void erase(uint32 idx) { i_nodes.erase(i_nodes.begin()+idx); }
float GetTotalLength(uint32 start, uint32 end) const float GetTotalLength(uint32 start, uint32 end) const
{ {
@ -76,9 +92,9 @@ class Path
void set(size_t idx, PathElem elem) { i_nodes[idx] = elem; } void set(size_t idx, PathElem elem) { i_nodes[idx] = elem; }
protected: protected:
std::vector<PathElem> i_nodes; std::deque<PathElem> i_nodes;
}; };
typedef Path<SimplePathNode> SimplePath; typedef Path<PathNode> PointPath;
#endif #endif

View file

@ -8686,7 +8686,7 @@ void Spell::EffectCharge(SpellEffectIndex /*eff_idx*/)
((Creature *)unitTarget)->StopMoving(); ((Creature *)unitTarget)->StopMoving();
// Only send MOVEMENTFLAG_WALK_MODE, client has strange issues with other move flags // Only send MOVEMENTFLAG_WALK_MODE, client has strange issues with other move flags
m_caster->MonsterMoveWithSpeed(x, y, z, 24.f); m_caster->MonsterMoveWithSpeed(x, y, z, 24.f, true, true);
// not all charge effects used in negative spells // not all charge effects used in negative spells
if (unitTarget != m_caster && !IsPositiveSpell(m_spellInfo->Id)) if (unitTarget != m_caster && !IsPositiveSpell(m_spellInfo->Id))
@ -8711,7 +8711,7 @@ void Spell::EffectCharge2(SpellEffectIndex /*eff_idx*/)
return; return;
// Only send MOVEMENTFLAG_WALK_MODE, client has strange issues with other move flags // Only send MOVEMENTFLAG_WALK_MODE, client has strange issues with other move flags
m_caster->MonsterMoveWithSpeed(x, y, z, 24.f); m_caster->MonsterMoveWithSpeed(x, y, z, 24.f, true, true);
// not all charge effects used in negative spells // not all charge effects used in negative spells
if (unitTarget && unitTarget != m_caster && !IsPositiveSpell(m_spellInfo->Id)) if (unitTarget && unitTarget != m_caster && !IsPositiveSpell(m_spellInfo->Id))

View file

@ -10522,10 +10522,10 @@ void Unit::NearTeleportTo( float x, float y, float z, float orientation, bool ca
} }
} }
void Unit::MonsterMoveWithSpeed(float x, float y, float z, float speed) void Unit::MonsterMoveWithSpeed(float x, float y, float z, float speed, bool generatePath, bool forceDestination)
{ {
Movement::MoveSplineInit init(*this); Movement::MoveSplineInit init(*this);
init.MoveTo(x,y,z); init.MoveTo(x,y,z, generatePath, forceDestination);
init.SetVelocity(speed); init.SetVelocity(speed);
init.Launch(); init.Launch();
} }

View file

@ -1412,7 +1412,7 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
void SendSpellMiss(Unit *target, uint32 spellID, SpellMissInfo missInfo); void SendSpellMiss(Unit *target, uint32 spellID, SpellMissInfo missInfo);
void NearTeleportTo(float x, float y, float z, float orientation, bool casting = false); void NearTeleportTo(float x, float y, float z, float orientation, bool casting = false);
void MonsterMoveWithSpeed(float x, float y, float z, float speed); void MonsterMoveWithSpeed(float x, float y, float z, float speed, bool generatePath = false, bool forceDestination = false);
// recommend use MonsterMove/MonsterMoveWithSpeed for most case that correctly work with movegens // recommend use MonsterMove/MonsterMoveWithSpeed for most case that correctly work with movegens
// if used additional args in ... part then floats must explicitly casted to double // if used additional args in ... part then floats must explicitly casted to double
void SendHeartBeat(); void SendHeartBeat();

View file

@ -78,7 +78,6 @@ namespace Movement
UpdateResult _updateState(int32& ms_time_diff); UpdateResult _updateState(int32& ms_time_diff);
int32 next_timestamp() const { return spline.length(point_Idx+1);} int32 next_timestamp() const { return spline.length(point_Idx+1);}
int32 segment_time_elapsed() const { return next_timestamp()-time_passed;} int32 segment_time_elapsed() const { return next_timestamp()-time_passed;}
int32 Duration() const { return spline.length();}
int32 timeElapsed() const { return Duration() - time_passed;} int32 timeElapsed() const { return Duration() - time_passed;}
int32 timePassed() const { return time_passed;} int32 timePassed() const { return time_passed;}
@ -121,6 +120,8 @@ namespace Movement
const Vector3 CurrentDestination() const { return Initialized() ? spline.getPoint(point_Idx+1) : Vector3();} const Vector3 CurrentDestination() const { return Initialized() ? spline.getPoint(point_Idx+1) : Vector3();}
int32 currentPathIdx() const; int32 currentPathIdx() const;
int32 Duration() const { return spline.length();}
std::string ToString() const; std::string ToString() const;
}; };
} }

View file

@ -50,7 +50,7 @@ namespace Movement
return MOVE_RUN; return MOVE_RUN;
} }
void MoveSplineInit::Launch() int32 MoveSplineInit::Launch()
{ {
MoveSpline& move_spline = *unit.movespline; MoveSpline& move_spline = *unit.movespline;
@ -82,7 +82,7 @@ namespace Movement
args.velocity = unit.GetSpeed(SelectSpeedType(moveFlags)); args.velocity = unit.GetSpeed(SelectSpeedType(moveFlags));
if (!args.Validate()) if (!args.Validate())
return; return 0;
unit.m_movementInfo.SetMovementFlags((MovementFlags)moveFlags); unit.m_movementInfo.SetMovementFlags((MovementFlags)moveFlags);
move_spline.Initialize(args); move_spline.Initialize(args);
@ -91,6 +91,8 @@ namespace Movement
data << unit.GetPackGUID(); data << unit.GetPackGUID();
PacketBuilder::WriteMonsterMove(move_spline, data); PacketBuilder::WriteMonsterMove(move_spline, data);
unit.SendMessageToSet(&data,true); unit.SendMessageToSet(&data,true);
return move_spline.Duration();
} }
MoveSplineInit::MoveSplineInit(Unit& m) : unit(m) MoveSplineInit::MoveSplineInit(Unit& m) : unit(m)

View file

@ -20,6 +20,7 @@
#define MANGOSSERVER_MOVESPLINEINIT_H #define MANGOSSERVER_MOVESPLINEINIT_H
#include "MoveSplineInitArgs.h" #include "MoveSplineInitArgs.h"
#include "../PathFinder.h"
class Unit; class Unit;
@ -41,9 +42,10 @@ namespace Movement
explicit MoveSplineInit(Unit& m); explicit MoveSplineInit(Unit& m);
/* Final pass of initialization that launches spline movement. /* Final pass of initialization that launches spline movement.
* @return duration - estimated travel time
*/ */
void Launch(); int32 Launch();
/* Adds movement by parabolic trajectory /* Adds movement by parabolic trajectory
* @param amplitude - the maximum height of parabola, value could be negative and positive * @param amplitude - the maximum height of parabola, value could be negative and positive
@ -72,8 +74,8 @@ namespace Movement
/* Initializes simple A to B mition, A is current unit's position, B is destination /* Initializes simple A to B mition, A is current unit's position, B is destination
*/ */
void MoveTo(const Vector3& destination); void MoveTo(const Vector3& destination, bool generatePath = false, bool forceDestination = false);
void MoveTo(float x, float y, float z); void MoveTo(float x, float y, float z, bool generatePath = false, bool forceDestination = false);
/* Sets Id of fisrt point of the path. When N-th path point will be done ILisener will notify that pointId + N done /* Sets Id of fisrt point of the path. When N-th path point will be done ILisener will notify that pointId + N done
* Needed for waypoint movement where path splitten into parts * Needed for waypoint movement where path splitten into parts
@ -133,17 +135,26 @@ namespace Movement
args.path.assign(controls.begin(),controls.end()); args.path.assign(controls.begin(),controls.end());
} }
inline void MoveSplineInit::MoveTo(float x, float y, float z) inline void MoveSplineInit::MoveTo(float x, float y, float z, bool generatePath, bool forceDestination)
{ {
Vector3 v(x,y,z); Vector3 v(x,y,z);
MoveTo(v); MoveTo(v, generatePath, forceDestination);
} }
inline void MoveSplineInit::MoveTo(const Vector3& dest) inline void MoveSplineInit::MoveTo(const Vector3& dest, bool generatePath, bool forceDestination)
{ {
args.path_Idx_offset = 0; if(generatePath)
args.path.resize(2); {
args.path[1] = dest; PathFinder path(&unit);
path.calculate(dest.x, dest.y, dest.z, forceDestination);
MovebyPath(path.getPath());
}
else
{
args.path_Idx_offset = 0;
args.path.resize(2);
args.path[1] = dest;
}
} }
inline void MoveSplineInit::SetParabolic(float amplitude, float time_shift) inline void MoveSplineInit::SetParabolic(float amplitude, float time_shift)

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "11910" #define REVISION_NR "11911"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__