Switch path stuff to vectors

This should be more CPU cache friendly compared to lists so should
be faster. (profiling looked promising)
This commit is contained in:
Michael Cook (mackal) 2014-12-17 01:52:00 -05:00
parent 5099010840
commit a14f8058da
7 changed files with 39 additions and 38 deletions

View File

@ -1,5 +1,8 @@
EQEMu Changelog (Started on Sept 24, 2003 15:50)
-------------------------------------------------------
== 12/17/2014 ==
demonstar55: Use vectors for route stuff, should be more CPU cache friendly so faster
== 12/15/2014 ==
Trevius: (RoF+) Implemented the 6th Augment Slot for Items.
Trevius: Player Corpses now saved attuned settings for Items.

View File

@ -5714,7 +5714,7 @@ void Client::Handle_OP_FindPersonRequest(const EQApplicationPacket *app)
}
else
{
std::list<int> pathlist = zone->pathing->FindRoute(Start, End);
std::vector<int> pathlist = zone->pathing->FindRoute(Start, End);
if (pathlist.size() == 0)
{
@ -5753,7 +5753,7 @@ void Client::Handle_OP_FindPersonRequest(const EQApplicationPacket *app)
p.z = GetZ();
points.push_back(p);
for (std::list<int>::iterator Iterator = pathlist.begin(); Iterator != pathlist.end(); ++Iterator)
for (auto Iterator = pathlist.begin(); Iterator != pathlist.end(); ++Iterator)
{
if ((*Iterator) == -1) // Teleporter
{

View File

@ -2636,7 +2636,7 @@ void EntityList::FindPathsToAllNPCs()
while (it != npc_list.end()) {
Map::Vertex Node0 = zone->pathing->GetPathNodeCoordinates(0, false);
Map::Vertex Dest(it->second->GetX(), it->second->GetY(), it->second->GetZ());
std::list<int> Route = zone->pathing->FindRoute(Node0, Dest);
std::vector<int> Route = zone->pathing->FindRoute(Node0, Dest);
if (Route.size() == 0)
printf("Unable to find a route to %s\n", it->second->GetName());
else

View File

@ -158,7 +158,7 @@ void Mob::CalculateNewFearpoint()
Map::Vertex CurrentPosition(GetX(), GetY(), GetZ());
std::list<int> Route = zone->pathing->FindRoute(CurrentPosition, Loc);
std::vector<int> Route = zone->pathing->FindRoute(CurrentPosition, Loc);
if(Route.size() > 0)
{

View File

@ -1225,7 +1225,7 @@ protected:
Map::Vertex PathingLastPosition;
int PathingLoopCount;
int PathingLastNodeVisited;
std::list<int> Route;
std::vector<int> Route;
LOSType PathingLOSState;
Timer *PathingLOSCheckTimer;
Timer *PathingRouteUpdateTimerShort;

View File

@ -205,15 +205,15 @@ Map::Vertex PathManager::GetPathNodeCoordinates(int NodeNumber, bool BestZ)
}
std::list<int> PathManager::FindRoute(int startID, int endID)
std::vector<int> PathManager::FindRoute(int startID, int endID)
{
_log(PATHING__DEBUG, "FindRoute from node %i to %i", startID, endID);
memset(ClosedListFlag, 0, sizeof(int) * Head.PathNodeCount);
std::list<AStarNode> OpenList, ClosedList;
std::vector<AStarNode> OpenList, ClosedList;
std::list<int>Route;
std::vector<int>Route;
AStarNode AStarEntry, CurrentNode;
@ -235,7 +235,7 @@ std::list<int> PathManager::FindRoute(int startID, int endID)
ClosedListFlag[CurrentNode.PathNodeID] = true;
OpenList.pop_front();
OpenList.erase(OpenList.begin());
for(int i = 0; i < PATHNODENEIGHBOURS; ++i)
{
@ -251,7 +251,7 @@ std::list<int> PathManager::FindRoute(int startID, int endID)
Route.push_back(endID);
std::list<AStarNode>::iterator RouteIterator;
std::vector<AStarNode>::iterator RouteIterator;
while(CurrentNode.PathNodeID != startID)
{
@ -300,7 +300,7 @@ std::list<int> PathManager::FindRoute(int startID, int endID)
bool AlreadyInOpenList = false;
std::list<AStarNode>::iterator OpenListIterator, InsertionPoint = OpenList.end();
std::vector<AStarNode>::iterator OpenListIterator, InsertionPoint = OpenList.end();
for(OpenListIterator = OpenList.begin(); OpenListIterator != OpenList.end(); ++OpenListIterator)
{
@ -350,11 +350,11 @@ bool SortPathNodesByDistance(PathNodeSortStruct n1, PathNodeSortStruct n2)
return n1.Distance < n2.Distance;
}
std::list<int> PathManager::FindRoute(Map::Vertex Start, Map::Vertex End)
std::vector<int> PathManager::FindRoute(Map::Vertex Start, Map::Vertex End)
{
_log(PATHING__DEBUG, "FindRoute(%8.3f, %8.3f, %8.3f, %8.3f, %8.3f, %8.3f)", Start.x, Start.y, Start.z, End.x, End.y, End.z);
std::list<int> noderoute;
std::vector<int> noderoute;
float CandidateNodeRangeXY = RuleR(Pathing, CandidateNodeRangeXY);
@ -365,7 +365,7 @@ std::list<int> PathManager::FindRoute(Map::Vertex Start, Map::Vertex End)
//
int ClosestPathNodeToStart = -1;
std::list<PathNodeSortStruct> SortedByDistance;
std::vector<PathNodeSortStruct> SortedByDistance;
PathNodeSortStruct TempNode;
@ -382,9 +382,9 @@ std::list<int> PathManager::FindRoute(Map::Vertex Start, Map::Vertex End)
}
}
SortedByDistance.sort(SortPathNodesByDistance);
std::sort(SortedByDistance.begin(), SortedByDistance.end(), SortPathNodesByDistance);
for(std::list<PathNodeSortStruct>::iterator Iterator = SortedByDistance.begin(); Iterator != SortedByDistance.end(); ++Iterator)
for(auto Iterator = SortedByDistance.begin(); Iterator != SortedByDistance.end(); ++Iterator)
{
_log(PATHING__DEBUG, "Checking Reachability of Node %i from Start Position.", PathNodes[(*Iterator).id].id);
@ -420,9 +420,9 @@ std::list<int> PathManager::FindRoute(Map::Vertex Start, Map::Vertex End)
}
}
SortedByDistance.sort(SortPathNodesByDistance);
std::sort(SortedByDistance.begin(), SortedByDistance.end(), SortPathNodesByDistance);
for(std::list<PathNodeSortStruct>::iterator Iterator = SortedByDistance.begin(); Iterator != SortedByDistance.end(); ++Iterator)
for(auto Iterator = SortedByDistance.begin(); Iterator != SortedByDistance.end(); ++Iterator)
{
_log(PATHING__DEBUG, "Checking Reachability of Node %i from End Position.", PathNodes[(*Iterator).id].id);
_log(PATHING__DEBUG, " (%8.3f, %8.3f, %8.3f) to (%8.3f, %8.3f, %8.3f)",
@ -456,7 +456,7 @@ std::list<int> PathManager::FindRoute(Map::Vertex Start, Map::Vertex End)
{
int CulledNodes = 0;
std::list<int>::iterator First, Second;
std::vector<int>::iterator First, Second;
while((noderoute.size() >= 2) && (CulledNodes < NodesToAttemptToCull))
{
@ -487,7 +487,7 @@ std::list<int> PathManager::FindRoute(Map::Vertex Start, Map::Vertex End)
{
int CulledNodes = 0;
std::list<int>::iterator First, Second;
std::vector<int>::iterator First, Second;
while((noderoute.size() >= 2) && (CulledNodes < NodesToAttemptToCull))
{
@ -611,7 +611,7 @@ void PathManager::MeshTest()
if(j == i)
continue;
std::list<int> Route = FindRoute(PathNodes[i].id, PathNodes[j].id);
std::vector<int> Route = FindRoute(PathNodes[i].id, PathNodes[j].id);
if(Route.size() == 0)
{
@ -638,7 +638,7 @@ void PathManager::SimpleMeshTest()
for(uint32 j = 1; j < Head.PathNodeCount; ++j)
{
std::list<int> Route = FindRoute(PathNodes[0].id, PathNodes[j].id);
std::vector<int> Route = FindRoute(PathNodes[0].id, PathNodes[j].id);
if(Route.size() == 0)
{
@ -695,7 +695,7 @@ Map::Vertex Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &
}
NodeLoc = zone->pathing->GetPathNodeCoordinates(Route.front());
Route.pop_front();
Route.erase(Route.begin());
++PathingTraversedNodes;
@ -784,7 +784,7 @@ Map::Vertex Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &
}
// We are on the same route, no LOS (or not checking this time, so pop off the node we just reached
//
Route.pop_front();
Route.erase(Route.begin());
++PathingTraversedNodes;
@ -798,7 +798,7 @@ Map::Vertex Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &
if(NextNode == -1)
{
// -1 indicates a teleport to the next node
Route.pop_front();
Route.erase(Route.begin());
if(Route.size() == 0)
{
@ -814,7 +814,7 @@ Map::Vertex Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &
mlog(PATHING__DEBUG, " TELEPORTED to %8.3f, %8.3f, %8.3f\n", NodeLoc.x, NodeLoc.y, NodeLoc.z);
Route.pop_front();
Route.erase(Route.begin());
if(Route.size() == 0)
return To;
@ -962,7 +962,7 @@ Map::Vertex Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &
PathingLastNodeVisited = Route.front();
Route.pop_front();
Route.erase(Route.begin());
++PathingTraversedNodes;
@ -975,7 +975,7 @@ Map::Vertex Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &
if(NextNode == -1)
{
// -1 indicates a teleport to the next node
Route.pop_front();
Route.erase(Route.begin());
if(Route.size() == 0)
{
@ -991,7 +991,7 @@ Map::Vertex Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &
mlog(PATHING__DEBUG, " TELEPORTED to %8.3f, %8.3f, %8.3f\n", NodeLoc.x, NodeLoc.y, NodeLoc.z);
Route.pop_front();
Route.erase(Route.begin());
if(Route.size() == 0)
return To;
@ -1103,7 +1103,7 @@ int PathManager::FindNearestPathNode(Map::Vertex Position)
int ClosestPathNodeToStart = -1;
std::list<PathNodeSortStruct> SortedByDistance;
std::vector<PathNodeSortStruct> SortedByDistance;
PathNodeSortStruct TempNode;
@ -1120,9 +1120,9 @@ int PathManager::FindNearestPathNode(Map::Vertex Position)
}
}
SortedByDistance.sort(SortPathNodesByDistance);
std::sort(SortedByDistance.begin(), SortedByDistance.end(), SortPathNodesByDistance);
for(std::list<PathNodeSortStruct>::iterator Iterator = SortedByDistance.begin(); Iterator != SortedByDistance.end(); ++Iterator)
for(auto Iterator = SortedByDistance.begin(); Iterator != SortedByDistance.end(); ++Iterator)
{
_log(PATHING__DEBUG, "Checking Reachability of Node %i from Start Position.", PathNodes[(*Iterator).id].id);
@ -1262,9 +1262,7 @@ void Mob::PrintRoute()
printf("Route is : ");
std::list<int>::iterator Iterator;
for(Iterator = Route.begin(); Iterator !=Route.end(); ++Iterator)
for(auto Iterator = Route.begin(); Iterator !=Route.end(); ++Iterator)
{
printf("%i, ", (*Iterator));
}

View File

@ -3,7 +3,7 @@
#include "map.h"
#include <list>
#include <vector>
class Client;
class Mob;
@ -60,8 +60,8 @@ public:
static PathManager *LoadPathFile(const char *ZoneName);
bool loadPaths(FILE *fp);
void PrintPathing();
std::list<int> FindRoute(Map::Vertex Start, Map::Vertex End);
std::list<int> FindRoute(int startID, int endID);
std::vector<int> FindRoute(Map::Vertex Start, Map::Vertex End);
std::vector<int> FindRoute(int startID, int endID);
Map::Vertex GetPathNodeCoordinates(int NodeNumber, bool BestZ = true);
bool CheckLosFN(Map::Vertex a, Map::Vertex b);