refactor(Core/Travel): Drop dead zone-index machinery + isEqual + cropUselessLink(single) (-124 lines)

This commit is contained in:
bash 2026-05-31 16:41:11 +02:00
parent 36a4b2a431
commit c9dfee19d6
2 changed files with 1 additions and 123 deletions

View File

@ -425,11 +425,6 @@ bool TravelNode::isUselessLink(TravelNode* farNode)
return false;
}
void TravelNode::cropUselessLink(TravelNode* farNode)
{
if (isUselessLink(farNode))
removeLinkTo(farNode);
}
bool TravelNode::cropUselessLinks()
{
@ -477,28 +472,6 @@ bool TravelNode::cropUselessLinks()
}
bool TravelNode::isEqual(TravelNode* compareNode)
{
if (!hasLinkTo(compareNode))
return false;
if (!compareNode->hasLinkTo(this))
return false;
for (auto& node : TravelNodeMap::instance().getNodes())
{
if (node == this || node == compareNode)
continue;
if (node->hasLinkTo(this) != node->hasLinkTo(compareNode))
return false;
if (hasLinkTo(node) != compareNode->hasLinkTo(node))
return false;
}
return true;
}
void TravelNode::print([[maybe_unused]] bool printFailed)
{
@ -2120,7 +2093,6 @@ void TravelNodeMap::generateAll()
hasToSave = true;
saveNodeStore();
BuildZoneIndex();
PrecomputeReachability();
}
@ -2145,7 +2117,6 @@ void TravelNodeMap::Init()
saveNodeStore();
}
BuildZoneIndex();
PrecomputeReachability();
}
@ -2745,85 +2716,6 @@ std::vector<uint32> TravelNodeMap::BuildPath(uint32 fromNode, uint32 toNode,
return path;
}
void TravelNodeMap::BuildZoneIndex()
{
m_zoneIndex.clear();
m_mapIndex.clear();
for (auto* node : nodes)
{
if (!node)
continue;
WorldPosition* pos = node->getPosition();
uint32 mapId = pos->GetMapId();
m_mapIndex[mapId].push_back(node);
uint32 zoneId = sMapMgr->GetZoneId(PHASEMASK_NORMAL, *pos);
if (zoneId)
m_zoneIndex[zoneId].push_back(node);
}
}
TravelNode* TravelNodeMap::GetNearestNodeInZone(WorldPosition pos, uint32 zoneId)
{
auto it = m_zoneIndex.find(zoneId);
if (it == m_zoneIndex.end() || it->second.empty())
return GetNearestNodeOnMap(pos); // Fallback to map-wide
TravelNode* bestNode = nullptr;
float bestDist = FLT_MAX;
for (auto* node : it->second)
{
if (!node || node->GetMapId() != pos.GetMapId())
continue;
float dist = node->fDist(pos);
if (dist < bestDist)
{
bestDist = dist;
bestNode = node;
}
}
if (!bestNode)
return GetNearestNodeOnMap(pos);
return bestNode;
}
std::vector<TravelNode*> const& TravelNodeMap::GetNodesInZone(uint32 zoneId) const
{
static std::vector<TravelNode*> const empty;
auto it = m_zoneIndex.find(zoneId);
if (it == m_zoneIndex.end())
return empty;
return it->second;
}
TravelNode* TravelNodeMap::GetNearestNodeOnMap(WorldPosition pos)
{
auto it = m_mapIndex.find(pos.GetMapId());
if (it == m_mapIndex.end() || it->second.empty())
return nullptr;
TravelNode* bestNode = nullptr;
float bestDist = FLT_MAX;
for (auto* node : it->second)
{
if (!node)
continue;
float d = node->fDist(pos);
if (d < bestDist)
{
bestDist = d;
bestNode = node;
}
}
return bestNode;
}
void TravelNodeMap::PrecomputeReachability()

View File

@ -93,7 +93,7 @@ enum class TravelNodePathType : uint8
areaTrigger = 2,
transport = 3,
flightPath = 4,
// value 5 reserved (was teleportSpell — removed)
// teleportSpell = 5 // maybe someday
staticPortal = 6
};
@ -353,11 +353,8 @@ public:
}
void removeLinkTo(TravelNode* node, bool removePaths = false);
bool isEqual(TravelNode* compareNode);
// Removes links to other nodes that can also be reached by passing another node.
bool isUselessLink(TravelNode* farNode);
void cropUselessLink(TravelNode* farNode);
bool cropUselessLinks();
// Returns all nodes that can be reached from this node.
@ -704,16 +701,8 @@ public:
void InitTaxiGraph();
std::vector<uint32> FindTaxiPath(uint32 fromNode, uint32 toNode);
void BuildZoneIndex();
void PrecomputeReachability();
TravelNode* GetNearestNodeInZone(WorldPosition pos, uint32 zoneId);
TravelNode* GetNearestNodeOnMap(WorldPosition pos);
// All nodes registered to a zone (post-BuildZoneIndex). Returns an
// empty static vector for unknown zones.
std::vector<TravelNode*> const& GetNodesInZone(uint32 zoneId) const;
// Resolve a full TravelPath from botPos to destination. Returns an
// empty TravelPath if no graph route + mmap stitch is reachable;
// the caller is then expected to fall back to a single-point path.
@ -754,9 +743,6 @@ private:
std::vector<TravelNode*> nodes;
std::unordered_map<uint32, std::vector<TravelNode*>> m_zoneIndex;
std::unordered_map<uint32, std::vector<TravelNode*>> m_mapIndex;
std::vector<std::pair<uint32, WorldPosition>> mapOffsets;
bool hasToSave = false;