Skip to content

Commit

Permalink
[9829] Avoid redundent data copy in transport waypoints generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirMangos committed May 3, 2010
1 parent 77d6af7 commit de87dab
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 34 deletions.
61 changes: 28 additions & 33 deletions src/game/Transports.cpp
Expand Up @@ -185,18 +185,13 @@ bool Transport::Create(uint32 guidlow, uint32 mapid, float x, float y, float z,

struct keyFrame
{
keyFrame(float _x, float _y, float _z, uint32 _mapid, int _actionflag, int _delay)
explicit keyFrame(TaxiPathNodeEntry const& _node) : node(&_node),
distSinceStop(-1.0f), distUntilStop(-1.0f), distFromPrev(-1.0f), tFrom(0.0f), tTo(0.0f)
{
x = _x; y = _y; z = _z; mapid = _mapid; actionflag = _actionflag; delay = _delay; distFromPrev = -1; distSinceStop = -1; distUntilStop = -1;
tFrom = 0; tTo = 0;
}

float x;
float y;
float z;
uint32 mapid;
int actionflag;
int delay;
TaxiPathNodeEntry const* node;

float distSinceStop;
float distUntilStop;
float distFromPrev;
Expand All @@ -220,9 +215,9 @@ bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids)
TaxiPathNodeEntry const& node_i = path[i];
if (node_i.mapid == path[i+1].mapid)
{
keyFrame k(node_i.x, node_i.y, node_i.z, node_i.mapid, node_i.actionFlag, node_i.delay);
keyFrame k(node_i);
keyFrames.push_back(k);
mapids.insert(k.mapid);
mapids.insert(k.node->mapid);
}
else
{
Expand All @@ -240,26 +235,26 @@ bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids)

// first cell is arrived at by teleportation :S
keyFrames[0].distFromPrev = 0;
if (keyFrames[0].actionflag == 2)
if (keyFrames[0].node->actionFlag == 2)
{
lastStop = 0;
}

// find the rest of the distances between key points
for (size_t i = 1; i < keyFrames.size(); ++i)
{
if ((keyFrames[i].actionflag == 1) || (keyFrames[i].mapid != keyFrames[i-1].mapid))
if ((keyFrames[i].node->actionFlag == 1) || (keyFrames[i].node->mapid != keyFrames[i-1].node->mapid))
{
keyFrames[i].distFromPrev = 0;
}
else
{
keyFrames[i].distFromPrev =
sqrt(pow(keyFrames[i].x - keyFrames[i - 1].x, 2) +
pow(keyFrames[i].y - keyFrames[i - 1].y, 2) +
pow(keyFrames[i].z - keyFrames[i - 1].z, 2));
sqrt(pow(keyFrames[i].node->x - keyFrames[i - 1].node->x, 2) +
pow(keyFrames[i].node->y - keyFrames[i - 1].node->y, 2) +
pow(keyFrames[i].node->z - keyFrames[i - 1].node->z, 2));
}
if (keyFrames[i].actionflag == 2)
if (keyFrames[i].node->actionFlag == 2)
{
// remember first stop frame
if(firstStop == -1)
Expand All @@ -272,7 +267,7 @@ bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids)
for (size_t i = 0; i < keyFrames.size(); ++i)
{
int j = (i + lastStop) % keyFrames.size();
if (keyFrames[j].actionflag == 2)
if (keyFrames[j].node->actionFlag == 2)
tmpDist = 0;
else
tmpDist += keyFrames[j].distFromPrev;
Expand All @@ -284,7 +279,7 @@ bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids)
int j = (i + (firstStop+1)) % keyFrames.size();
tmpDist += keyFrames[(j + 1) % keyFrames.size()].distFromPrev;
keyFrames[j].distUntilStop = tmpDist;
if (keyFrames[j].actionflag == 2)
if (keyFrames[j].node->actionFlag == 2)
tmpDist = 0;
}

Expand Down Expand Up @@ -312,14 +307,14 @@ bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids)
// speed = max(30, t) (remember x = 0.5s^2, and when accelerating, a = 1 unit/s^2
int t = 0;
bool teleport = false;
if (keyFrames[keyFrames.size() - 1].mapid != keyFrames[0].mapid)
if (keyFrames[keyFrames.size() - 1].node->mapid != keyFrames[0].node->mapid)
teleport = true;

WayPoint pos(keyFrames[0].mapid, keyFrames[0].x, keyFrames[0].y, keyFrames[0].z, teleport);
WayPoint pos(keyFrames[0].node->mapid, keyFrames[0].node->x, keyFrames[0].node->y, keyFrames[0].node->z, teleport);
m_WayPoints[0] = pos;
t += keyFrames[0].delay * 1000;
t += keyFrames[0].node->delay * 1000;

uint32 cM = keyFrames[0].mapid;
uint32 cM = keyFrames[0].node->mapid;
for (size_t i = 0; i < keyFrames.size() - 1; ++i)
{
float d = 0;
Expand All @@ -337,19 +332,19 @@ bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids)
if (d > 0)
{
float newX, newY, newZ;
newX = keyFrames[i].x + (keyFrames[i + 1].x - keyFrames[i].x) * d / keyFrames[i + 1].distFromPrev;
newY = keyFrames[i].y + (keyFrames[i + 1].y - keyFrames[i].y) * d / keyFrames[i + 1].distFromPrev;
newZ = keyFrames[i].z + (keyFrames[i + 1].z - keyFrames[i].z) * d / keyFrames[i + 1].distFromPrev;
newX = keyFrames[i].node->x + (keyFrames[i + 1].node->x - keyFrames[i].node->x) * d / keyFrames[i + 1].distFromPrev;
newY = keyFrames[i].node->y + (keyFrames[i + 1].node->y - keyFrames[i].node->y) * d / keyFrames[i + 1].distFromPrev;
newZ = keyFrames[i].node->z + (keyFrames[i + 1].node->z - keyFrames[i].node->z) * d / keyFrames[i + 1].distFromPrev;

bool teleport = false;
if (keyFrames[i].mapid != cM)
if (keyFrames[i].node->mapid != cM)
{
teleport = true;
cM = keyFrames[i].mapid;
cM = keyFrames[i].node->mapid;
}

// sLog.outString("T: %d, D: %f, x: %f, y: %f, z: %f", t, d, newX, newY, newZ);
WayPoint pos(keyFrames[i].mapid, newX, newY, newZ, teleport);
WayPoint pos(keyFrames[i].node->mapid, newX, newY, newZ, teleport);
if (teleport)
m_WayPoints[t] = pos;
}
Expand Down Expand Up @@ -389,20 +384,20 @@ bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids)
t += (long)keyFrames[i + 1].tTo % 100;

bool teleport = false;
if ((keyFrames[i + 1].actionflag == 1) || (keyFrames[i + 1].mapid != keyFrames[i].mapid))
if ((keyFrames[i + 1].node->actionFlag == 1) || (keyFrames[i + 1].node->mapid != keyFrames[i].node->mapid))
{
teleport = true;
cM = keyFrames[i + 1].mapid;
cM = keyFrames[i + 1].node->mapid;
}

WayPoint pos(keyFrames[i + 1].mapid, keyFrames[i + 1].x, keyFrames[i + 1].y, keyFrames[i + 1].z, teleport);
WayPoint pos(keyFrames[i + 1].node->mapid, keyFrames[i + 1].node->x, keyFrames[i + 1].node->y, keyFrames[i + 1].node->z, teleport);

// sLog.outString("T: %d, x: %f, y: %f, z: %f, t:%d", t, pos.x, pos.y, pos.z, teleport);

//if (teleport)
m_WayPoints[t] = pos;

t += keyFrames[i + 1].delay * 1000;
t += keyFrames[i + 1].node->delay * 1000;
// sLog.outString("------");
}

Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9828"
#define REVISION_NR "9829"
#endif // __REVISION_NR_H__

0 comments on commit de87dab

Please sign in to comment.