Skip to content

Commit

Permalink
[11911] Use mmaps for Spline Movement
Browse files Browse the repository at this point in the history
  • Loading branch information
sixsixnine authored and Schmoozerd committed Feb 6, 2012
1 parent 5350d88 commit 162d2ba
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 25 deletions.
28 changes: 22 additions & 6 deletions src/game/Path.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
#define MANGOSSERVER_PATH_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>
Expand All @@ -34,8 +36,22 @@ class Path
size_t size() const { return i_nodes.size(); }
bool empty() const { return i_nodes.empty(); }
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 erase(uint32 idx) { i_nodes.erase(i_nodes.begin()+idx); }

float GetTotalLength(uint32 start, uint32 end) const
{
Expand Down Expand Up @@ -76,9 +92,9 @@ class Path
void set(size_t idx, PathElem elem) { i_nodes[idx] = elem; }

protected:
std::vector<PathElem> i_nodes;
std::deque<PathElem> i_nodes;
};

typedef Path<SimplePathNode> SimplePath;
typedef Path<PathNode> PointPath;

#endif
4 changes: 2 additions & 2 deletions src/game/SpellEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8686,7 +8686,7 @@ void Spell::EffectCharge(SpellEffectIndex /*eff_idx*/)
((Creature *)unitTarget)->StopMoving();

// 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
if (unitTarget != m_caster && !IsPositiveSpell(m_spellInfo->Id))
Expand All @@ -8711,7 +8711,7 @@ void Spell::EffectCharge2(SpellEffectIndex /*eff_idx*/)
return;

// 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
if (unitTarget && unitTarget != m_caster && !IsPositiveSpell(m_spellInfo->Id))
Expand Down
4 changes: 2 additions & 2 deletions src/game/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
init.MoveTo(x,y,z);
init.MoveTo(x,y,z, generatePath, forceDestination);
init.SetVelocity(speed);
init.Launch();
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
void SendSpellMiss(Unit *target, uint32 spellID, SpellMissInfo missInfo);

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
// if used additional args in ... part then floats must explicitly casted to double
void SendHeartBeat();
Expand Down
3 changes: 2 additions & 1 deletion src/game/movement/MoveSpline.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ namespace Movement
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 Duration() const { return spline.length();}
int32 timeElapsed() const { return Duration() - time_passed;}
int32 timePassed() const { return time_passed;}

Expand Down Expand Up @@ -121,6 +120,8 @@ namespace Movement
const Vector3 CurrentDestination() const { return Initialized() ? spline.getPoint(point_Idx+1) : Vector3();}
int32 currentPathIdx() const;

int32 Duration() const { return spline.length();}

std::string ToString() const;
};
}
Expand Down
6 changes: 4 additions & 2 deletions src/game/movement/MoveSplineInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace Movement
return MOVE_RUN;
}

void MoveSplineInit::Launch()
int32 MoveSplineInit::Launch()
{
MoveSpline& move_spline = *unit.movespline;

Expand Down Expand Up @@ -82,7 +82,7 @@ namespace Movement
args.velocity = unit.GetSpeed(SelectSpeedType(moveFlags));

if (!args.Validate())
return;
return 0;

unit.m_movementInfo.SetMovementFlags((MovementFlags)moveFlags);
move_spline.Initialize(args);
Expand All @@ -91,6 +91,8 @@ namespace Movement
data << unit.GetPackGUID();
PacketBuilder::WriteMonsterMove(move_spline, data);
unit.SendMessageToSet(&data,true);

return move_spline.Duration();
}

MoveSplineInit::MoveSplineInit(Unit& m) : unit(m)
Expand Down
31 changes: 21 additions & 10 deletions src/game/movement/MoveSplineInit.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define MANGOSSERVER_MOVESPLINEINIT_H

#include "MoveSplineInitArgs.h"
#include "../PathFinder.h"

class Unit;

Expand All @@ -41,9 +42,10 @@ namespace Movement

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
* @param amplitude - the maximum height of parabola, value could be negative and positive
Expand Down Expand Up @@ -72,8 +74,8 @@ namespace Movement

/* Initializes simple A to B mition, A is current unit's position, B is destination
*/
void MoveTo(const Vector3& destination);
void MoveTo(float x, float y, float z);
void MoveTo(const Vector3& destination, bool generatePath = false, bool forceDestination = false);
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
* Needed for waypoint movement where path splitten into parts
Expand Down Expand Up @@ -133,17 +135,26 @@ namespace Movement
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);
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;
args.path.resize(2);
args.path[1] = dest;
if(generatePath)
{
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)
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11910"
#define REVISION_NR "11911"
#endif // __REVISION_NR_H__

0 comments on commit 162d2ba

Please sign in to comment.