[9808] Simplify TaxiPathNodes data use, specially for transport case.

This commit is contained in:
VladimirMangos 2010-04-29 19:41:30 +04:00
parent de3192b2f5
commit 4910add486
8 changed files with 29 additions and 92 deletions

View file

@ -150,7 +150,7 @@ TaxiMask sOldContinentsNodesMask;
TaxiPathSetBySource sTaxiPathSetBySource; TaxiPathSetBySource sTaxiPathSetBySource;
DBCStorage <TaxiPathEntry> sTaxiPathStore(TaxiPathEntryfmt); DBCStorage <TaxiPathEntry> sTaxiPathStore(TaxiPathEntryfmt);
// DBC used only for initialization sTaxiPathNodeStore at startup. // DBC store data but sTaxiPathNodesByPath used for fast access to entries (it's not owner pointed data).
TaxiPathNodesByPath sTaxiPathNodesByPath; TaxiPathNodesByPath sTaxiPathNodesByPath;
static DBCStorage <TaxiPathNodeEntry> sTaxiPathNodeStore(TaxiPathNodeEntryfmt); static DBCStorage <TaxiPathNodeEntry> sTaxiPathNodeStore(TaxiPathNodeEntryfmt);
@ -547,11 +547,10 @@ void LoadDBCStores(const std::string& dataPath)
sTaxiPathNodesByPath.resize(pathCount); // 0 and some other indexes not used sTaxiPathNodesByPath.resize(pathCount); // 0 and some other indexes not used
for(uint32 i = 1; i < sTaxiPathNodesByPath.size(); ++i) for(uint32 i = 1; i < sTaxiPathNodesByPath.size(); ++i)
sTaxiPathNodesByPath[i].resize(pathLength[i]); sTaxiPathNodesByPath[i].resize(pathLength[i]);
// fill data // fill data (pointers to sTaxiPathNodeStore elements
for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i) for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i)) if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
sTaxiPathNodesByPath[entry->path][entry->index] = TaxiPathNode(entry->mapid,entry->x,entry->y,entry->z,entry->actionFlag,entry->delay); sTaxiPathNodesByPath[entry->path][entry->index] = entry;
sTaxiPathNodeStore.Clear();
// Initialize global taxinodes mask // Initialize global taxinodes mask
// include existed nodes that have at least single not spell base (scripted) path // include existed nodes that have at least single not spell base (scripted) path

View file

@ -1846,19 +1846,7 @@ struct TaxiPathBySourceAndDestination
typedef std::map<uint32,TaxiPathBySourceAndDestination> TaxiPathSetForSource; typedef std::map<uint32,TaxiPathBySourceAndDestination> TaxiPathSetForSource;
typedef std::map<uint32,TaxiPathSetForSource> TaxiPathSetBySource; typedef std::map<uint32,TaxiPathSetForSource> TaxiPathSetBySource;
struct TaxiPathNode typedef std::vector<TaxiPathNodeEntry const*> TaxiPathNodeList;
{
TaxiPathNode() : mapid(0), x(0),y(0),z(0),actionFlag(0),delay(0) {}
TaxiPathNode(uint32 _mapid, float _x, float _y, float _z, uint32 _actionFlag, uint32 _delay) : mapid(_mapid), x(_x),y(_y),z(_z),actionFlag(_actionFlag),delay(_delay) {}
uint32 mapid;
float x;
float y;
float z;
uint32 actionFlag;
uint32 delay;
};
typedef std::vector<TaxiPathNode> TaxiPathNodeList;
typedef std::vector<TaxiPathNodeList> TaxiPathNodesByPath; typedef std::vector<TaxiPathNodeList> TaxiPathNodesByPath;
#define TaxiMaskSize 12 #define TaxiMaskSize 12

View file

@ -5231,31 +5231,11 @@ void ObjectMgr::GetTaxiPathNodes( uint32 path, Path &pathnodes, std::vector<uint
for(size_t i = 0; i < nodeList.size(); ++i) for(size_t i = 0; i < nodeList.size(); ++i)
{ {
pathnodes[ i ].x = nodeList[i].x; pathnodes[ i ].x = nodeList[i]->x;
pathnodes[ i ].y = nodeList[i].y; pathnodes[ i ].y = nodeList[i]->y;
pathnodes[ i ].z = nodeList[i].z; pathnodes[ i ].z = nodeList[i]->z;
mapIds[i] = nodeList[i].mapid; mapIds[i] = nodeList[i]->mapid;
}
}
void ObjectMgr::GetTransportPathNodes( uint32 path, TransportPath &pathnodes )
{
if(path >= sTaxiPathNodesByPath.size())
return;
TaxiPathNodeList& nodeList = sTaxiPathNodesByPath[path];
pathnodes.Resize(nodeList.size());
for(size_t i = 0; i < nodeList.size(); ++i)
{
pathnodes[ i ].mapid = nodeList[i].mapid;
pathnodes[ i ].x = nodeList[i].x;
pathnodes[ i ].y = nodeList[i].y;
pathnodes[ i ].z = nodeList[i].z;
pathnodes[ i ].actionFlag = nodeList[i].actionFlag;
pathnodes[ i ].delay = nodeList[i].delay;
} }
} }

View file

@ -500,7 +500,6 @@ class ObjectMgr
void GetTaxiPath( uint32 source, uint32 destination, uint32 &path, uint32 &cost); void GetTaxiPath( uint32 source, uint32 destination, uint32 &path, uint32 &cost);
uint32 GetTaxiMountDisplayId( uint32 id, uint32 team, bool allowed_alt_team = false); uint32 GetTaxiMountDisplayId( uint32 id, uint32 team, bool allowed_alt_team = false);
void GetTaxiPathNodes( uint32 path, Path &pathnodes, std::vector<uint32>& mapIds ); void GetTaxiPathNodes( uint32 path, Path &pathnodes, std::vector<uint32>& mapIds );
void GetTransportPathNodes( uint32 path, TransportPath &pathnodes );
Quest const* GetQuestTemplate(uint32 quest_id) const Quest const* GetQuestTemplate(uint32 quest_id) const
{ {

View file

@ -18209,32 +18209,32 @@ void Player::ContinueTaxiFlight()
float distPrev = MAP_SIZE*MAP_SIZE; float distPrev = MAP_SIZE*MAP_SIZE;
float distNext = float distNext =
(nodeList[0].x-GetPositionX())*(nodeList[0].x-GetPositionX())+ (nodeList[0]->x-GetPositionX())*(nodeList[0]->x-GetPositionX())+
(nodeList[0].y-GetPositionY())*(nodeList[0].y-GetPositionY())+ (nodeList[0]->y-GetPositionY())*(nodeList[0]->y-GetPositionY())+
(nodeList[0].z-GetPositionZ())*(nodeList[0].z-GetPositionZ()); (nodeList[0]->z-GetPositionZ())*(nodeList[0]->z-GetPositionZ());
for(uint32 i = 1; i < nodeList.size(); ++i) for(uint32 i = 1; i < nodeList.size(); ++i)
{ {
TaxiPathNode const& node = nodeList[i]; TaxiPathNodeEntry const* node = nodeList[i];
TaxiPathNode const& prevNode = nodeList[i-1]; TaxiPathNodeEntry const* prevNode = nodeList[i-1];
// skip nodes at another map // skip nodes at another map
if(node.mapid != GetMapId()) if (node->mapid != GetMapId())
continue; continue;
distPrev = distNext; distPrev = distNext;
distNext = distNext =
(node.x-GetPositionX())*(node.x-GetPositionX())+ (node->x-GetPositionX())*(node->x-GetPositionX())+
(node.y-GetPositionY())*(node.y-GetPositionY())+ (node->y-GetPositionY())*(node->y-GetPositionY())+
(node.z-GetPositionZ())*(node.z-GetPositionZ()); (node->z-GetPositionZ())*(node->z-GetPositionZ());
float distNodes = float distNodes =
(node.x-prevNode.x)*(node.x-prevNode.x)+ (node->x-prevNode->x)*(node->x-prevNode->x)+
(node.y-prevNode.y)*(node.y-prevNode.y)+ (node->y-prevNode->y)*(node->y-prevNode->y)+
(node.z-prevNode.z)*(node.z-prevNode.z); (node->z-prevNode->z)*(node->z-prevNode->z);
if(distNext + distPrev < distNodes) if (distNext + distPrev < distNodes)
{ {
startNode = i; startNode = i;
break; break;

View file

@ -205,22 +205,22 @@ struct keyFrame
bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids) bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids)
{ {
TransportPath path; if (pathid >= sTaxiPathNodesByPath.size())
sObjectMgr.GetTransportPathNodes(pathid, path);
if (path.Empty())
return false; return false;
TaxiPathNodeList const& path = sTaxiPathNodesByPath[pathid];
std::vector<keyFrame> keyFrames; std::vector<keyFrame> keyFrames;
int mapChange = 0; int mapChange = 0;
mapids.clear(); mapids.clear();
for (size_t i = 1; i < path.Size() - 1; ++i) for (size_t i = 1; i < path.size() - 1; ++i)
{ {
if (mapChange == 0) if (mapChange == 0)
{ {
if ((path[i].mapid == path[i+1].mapid)) TaxiPathNodeEntry const* node_i = path[i];
if (node_i->mapid == path[i+1]->mapid)
{ {
keyFrame k(path[i].x, path[i].y, path[i].z, path[i].mapid, path[i].actionFlag, path[i].delay); keyFrame k(node_i->x, node_i->y, node_i->z, node_i->mapid, node_i->actionFlag, node_i->delay);
keyFrames.push_back(k); keyFrames.push_back(k);
mapids.insert(k.mapid); mapids.insert(k.mapid);
} }

View file

@ -25,35 +25,6 @@
#include <set> #include <set>
#include <string> #include <string>
class TransportPath
{
public:
struct PathNode
{
uint32 mapid;
float x,y,z;
uint32 actionFlag;
uint32 delay;
};
void SetLength(const unsigned int sz)
{
i_nodes.resize( sz );
}
unsigned int Size(void) const { return i_nodes.size(); }
bool Empty(void) const { return i_nodes.empty(); }
void Resize(unsigned int sz) { i_nodes.resize(sz); }
void Clear(void) { i_nodes.clear(); }
PathNode* GetNodes(void) { return static_cast<PathNode *>(&i_nodes[0]); }
PathNode& operator[](const unsigned int idx) { return i_nodes[idx]; }
const PathNode& operator()(const unsigned int idx) const { return i_nodes[idx]; }
protected:
std::vector<PathNode> i_nodes;
};
class Transport : public GameObject class Transport : public GameObject
{ {
public: public:

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 "9807" #define REVISION_NR "9808"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__