[9829] Avoid redundent data copy in transport waypoints generation.

This commit is contained in:
VladimirMangos 2010-05-03 13:35:53 +04:00
parent 577812ff6e
commit e54c919adb
2 changed files with 29 additions and 34 deletions

View file

@ -185,18 +185,13 @@ bool Transport::Create(uint32 guidlow, uint32 mapid, float x, float y, float z,
struct keyFrame 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; TaxiPathNodeEntry const* node;
float y;
float z;
uint32 mapid;
int actionflag;
int delay;
float distSinceStop; float distSinceStop;
float distUntilStop; float distUntilStop;
float distFromPrev; float distFromPrev;
@ -220,9 +215,9 @@ bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids)
TaxiPathNodeEntry const& node_i = path[i]; TaxiPathNodeEntry const& node_i = path[i];
if (node_i.mapid == path[i+1].mapid) 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); keyFrames.push_back(k);
mapids.insert(k.mapid); mapids.insert(k.node->mapid);
} }
else else
{ {
@ -240,7 +235,7 @@ bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids)
// first cell is arrived at by teleportation :S // first cell is arrived at by teleportation :S
keyFrames[0].distFromPrev = 0; keyFrames[0].distFromPrev = 0;
if (keyFrames[0].actionflag == 2) if (keyFrames[0].node->actionFlag == 2)
{ {
lastStop = 0; lastStop = 0;
} }
@ -248,18 +243,18 @@ bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids)
// find the rest of the distances between key points // find the rest of the distances between key points
for (size_t i = 1; i < keyFrames.size(); ++i) 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; keyFrames[i].distFromPrev = 0;
} }
else else
{ {
keyFrames[i].distFromPrev = keyFrames[i].distFromPrev =
sqrt(pow(keyFrames[i].x - keyFrames[i - 1].x, 2) + sqrt(pow(keyFrames[i].node->x - keyFrames[i - 1].node->x, 2) +
pow(keyFrames[i].y - keyFrames[i - 1].y, 2) + pow(keyFrames[i].node->y - keyFrames[i - 1].node->y, 2) +
pow(keyFrames[i].z - keyFrames[i - 1].z, 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 // remember first stop frame
if(firstStop == -1) if(firstStop == -1)
@ -272,7 +267,7 @@ bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids)
for (size_t i = 0; i < keyFrames.size(); ++i) for (size_t i = 0; i < keyFrames.size(); ++i)
{ {
int j = (i + lastStop) % keyFrames.size(); int j = (i + lastStop) % keyFrames.size();
if (keyFrames[j].actionflag == 2) if (keyFrames[j].node->actionFlag == 2)
tmpDist = 0; tmpDist = 0;
else else
tmpDist += keyFrames[j].distFromPrev; tmpDist += keyFrames[j].distFromPrev;
@ -284,7 +279,7 @@ bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids)
int j = (i + (firstStop+1)) % keyFrames.size(); int j = (i + (firstStop+1)) % keyFrames.size();
tmpDist += keyFrames[(j + 1) % keyFrames.size()].distFromPrev; tmpDist += keyFrames[(j + 1) % keyFrames.size()].distFromPrev;
keyFrames[j].distUntilStop = tmpDist; keyFrames[j].distUntilStop = tmpDist;
if (keyFrames[j].actionflag == 2) if (keyFrames[j].node->actionFlag == 2)
tmpDist = 0; tmpDist = 0;
} }
@ -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 // speed = max(30, t) (remember x = 0.5s^2, and when accelerating, a = 1 unit/s^2
int t = 0; int t = 0;
bool teleport = false; 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; 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; 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) for (size_t i = 0; i < keyFrames.size() - 1; ++i)
{ {
float d = 0; float d = 0;
@ -337,19 +332,19 @@ bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids)
if (d > 0) if (d > 0)
{ {
float newX, newY, newZ; float newX, newY, newZ;
newX = keyFrames[i].x + (keyFrames[i + 1].x - keyFrames[i].x) * 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].y + (keyFrames[i + 1].y - keyFrames[i].y) * 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].z + (keyFrames[i + 1].z - keyFrames[i].z) * 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; bool teleport = false;
if (keyFrames[i].mapid != cM) if (keyFrames[i].node->mapid != cM)
{ {
teleport = true; 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); // 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) if (teleport)
m_WayPoints[t] = pos; m_WayPoints[t] = pos;
} }
@ -389,20 +384,20 @@ bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids)
t += (long)keyFrames[i + 1].tTo % 100; t += (long)keyFrames[i + 1].tTo % 100;
bool teleport = false; 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; 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); // sLog.outString("T: %d, x: %f, y: %f, z: %f, t:%d", t, pos.x, pos.y, pos.z, teleport);
//if (teleport) //if (teleport)
m_WayPoints[t] = pos; m_WayPoints[t] = pos;
t += keyFrames[i + 1].delay * 1000; t += keyFrames[i + 1].node->delay * 1000;
// sLog.outString("------"); // sLog.outString("------");
} }

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 "9828" #define REVISION_NR "9829"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__