Skip to content

Commit

Permalink
Optimization for wp path generation
Browse files Browse the repository at this point in the history
  • Loading branch information
DomGries authored and cyberium committed May 29, 2020
1 parent 38b6514 commit b37b59a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/game/MotionGenerators/WaypointMovementGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,17 @@ uint32 WaypointMovementGenerator<Creature>::BuildIntPath(PointsArray& path, Crea
float creatureSpeed = creature.GetSpeed(speedType);

bool onTheGround = !creature.IsFlying() && !creature.IsSwimming();
float dist = (endPos - startPos).magnitude();
if (dist >= MinimumDistance)
// cache offset for direction
const Vector3 offset = endPos - startPos;
const float distance = offset.magnitude();
if (distance >= MinimumDistance)
{
// compute direction to end position
Vector3 direction = (endPos - startPos).unit();
Vector3 direction = offset * (1.f / distance);
direction *= TerrainStep; // add wanted step size

// total points that will be processed (only intermediates points and stop 2 yard before the end)
uint32 totalPoints = uint32((dist - 2) / TerrainStep);
uint32 totalPoints = uint32((distance - 2) / TerrainStep);

Vector3 currPos = startPos; // computed position (start position + step in desired direction)
Vector3 lastPos = startPos; // previous position in the loop
Expand Down Expand Up @@ -371,7 +373,7 @@ uint32 WaypointMovementGenerator<Creature>::BuildIntPath(PointsArray& path, Crea

path.push_back(endPos);
// add last point to end point travel time
travelTime = dist / creatureSpeed * 1000;
travelTime = distance / creatureSpeed * 1000;

return travelTime;
}
Expand Down

0 comments on commit b37b59a

Please sign in to comment.