- updated pathfinder to randomize better the pathfinder refresh rate in an attempt to have better performance when we have lots of units

This commit is contained in:
Mark Vejvoda 2011-06-24 19:40:47 +00:00
parent 7344250c5c
commit d0d31e4bfe
2 changed files with 16 additions and 5 deletions

View File

@ -45,7 +45,8 @@ int PathFinder::pathFindNodesMax = 1500;
const int PathFinder::pathFindRefresh = 10; const int PathFinder::pathFindRefresh = 10;
const int PathFinder::pathFindBailoutRadius = 20; const int PathFinder::pathFindBailoutRadius = 20;
const int PathFinder::pathFindExtendRefreshForNodeCount = 25; const int PathFinder::pathFindExtendRefreshForNodeCount = 25;
const int PathFinder::pathFindExtendRefreshNodeCount = 40; const int PathFinder::pathFindExtendRefreshNodeCountMin = 20;
const int PathFinder::pathFindExtendRefreshNodeCountMax = 60;
PathFinder::PathFinder() { PathFinder::PathFinder() {
for(int i = 0; i < GameConstants::maxPlayers; ++i) { for(int i = 0; i < GameConstants::maxPlayers; ++i) {
@ -54,6 +55,11 @@ PathFinder::PathFinder() {
map=NULL; map=NULL;
} }
int PathFinder::getPathFindExtendRefreshNodeCount(int factionIndex) {
int refreshNodeCount = factions[factionIndex].random.randRange(PathFinder::pathFindExtendRefreshNodeCountMin,PathFinder::pathFindExtendRefreshNodeCountMax);
return refreshNodeCount;
}
PathFinder::PathFinder(const Map *map) { PathFinder::PathFinder(const Map *map) {
for(int i = 0; i < GameConstants::maxPlayers; ++i) { for(int i = 0; i < GameConstants::maxPlayers; ++i) {
factions.push_back(FactionState()); factions.push_back(FactionState());
@ -451,7 +457,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
} }
if(i < pathFindRefresh || if(i < pathFindRefresh ||
(factions[unit->getFactionIndex()].precachedPath[unit->getId()].size() >= pathFindExtendRefreshForNodeCount && i < pathFindExtendRefreshNodeCount)) { (factions[unit->getFactionIndex()].precachedPath[unit->getId()].size() >= pathFindExtendRefreshForNodeCount &&
i < getPathFindExtendRefreshNodeCount(unit->getFactionIndex()))) {
if(map->aproxCanMove(unit, lastPos, nodePos) == false) { if(map->aproxCanMove(unit, lastPos, nodePos) == false) {
canMoveToCells = false; canMoveToCells = false;
break; break;
@ -474,7 +481,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
} }
if(i < pathFindRefresh || if(i < pathFindRefresh ||
(factions[unit->getFactionIndex()].precachedPath[unit->getId()].size() >= pathFindExtendRefreshForNodeCount && i < pathFindExtendRefreshNodeCount)) { (factions[unit->getFactionIndex()].precachedPath[unit->getId()].size() >= pathFindExtendRefreshForNodeCount &&
i < getPathFindExtendRefreshNodeCount(unit->getFactionIndex()))) {
path->add(nodePos); path->add(nodePos);
} }
//else if(tryLastPathCache == false) { //else if(tryLastPathCache == false) {
@ -927,7 +935,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
} }
else { else {
if(i < pathFindRefresh || if(i < pathFindRefresh ||
(whileLoopCount >= pathFindExtendRefreshForNodeCount && i < pathFindExtendRefreshNodeCount)) { (whileLoopCount >= pathFindExtendRefreshForNodeCount &&
i < getPathFindExtendRefreshNodeCount(unit->getFactionIndex()))) {
path->add(nodePos); path->add(nodePos);
} }
//else if(tryLastPathCache == false) { //else if(tryLastPathCache == false) {

View File

@ -87,7 +87,8 @@ public:
static const int pathFindRefresh; static const int pathFindRefresh;
static const int pathFindBailoutRadius; static const int pathFindBailoutRadius;
static const int pathFindExtendRefreshForNodeCount; static const int pathFindExtendRefreshForNodeCount;
static const int pathFindExtendRefreshNodeCount; static const int pathFindExtendRefreshNodeCountMin;
static const int pathFindExtendRefreshNodeCountMax;
private: private:
@ -117,6 +118,7 @@ private:
bool processNode(Unit *unit, Node *node,const Vec2i finalPos, int i, int j, bool &nodeLimitReached, int maxNodeCount); bool processNode(Unit *unit, Node *node,const Vec2i finalPos, int i, int j, bool &nodeLimitReached, int maxNodeCount);
void processNearestFreePos(const Vec2i &finalPos, int i, int j, int size, Field field, int teamIndex,Vec2i unitPos, Vec2i &nearestPos, float &nearestDist); void processNearestFreePos(const Vec2i &finalPos, int i, int j, int size, Field field, int teamIndex,Vec2i unitPos, Vec2i &nearestPos, float &nearestDist);
int getPathFindExtendRefreshNodeCount(int factionIndex);
}; };
}}//end namespace }}//end namespace