From d0d31e4bfee7c36ff5f94ddefbb6284979a62a14 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 24 Jun 2011 19:40:47 +0000 Subject: [PATCH] - updated pathfinder to randomize better the pathfinder refresh rate in an attempt to have better performance when we have lots of units --- source/glest_game/ai/path_finder.cpp | 17 +++++++++++++---- source/glest_game/ai/path_finder.h | 4 +++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/source/glest_game/ai/path_finder.cpp b/source/glest_game/ai/path_finder.cpp index 0818a0db..65fe9519 100644 --- a/source/glest_game/ai/path_finder.cpp +++ b/source/glest_game/ai/path_finder.cpp @@ -45,7 +45,8 @@ int PathFinder::pathFindNodesMax = 1500; const int PathFinder::pathFindRefresh = 10; const int PathFinder::pathFindBailoutRadius = 20; const int PathFinder::pathFindExtendRefreshForNodeCount = 25; -const int PathFinder::pathFindExtendRefreshNodeCount = 40; +const int PathFinder::pathFindExtendRefreshNodeCountMin = 20; +const int PathFinder::pathFindExtendRefreshNodeCountMax = 60; PathFinder::PathFinder() { for(int i = 0; i < GameConstants::maxPlayers; ++i) { @@ -54,6 +55,11 @@ PathFinder::PathFinder() { map=NULL; } +int PathFinder::getPathFindExtendRefreshNodeCount(int factionIndex) { + int refreshNodeCount = factions[factionIndex].random.randRange(PathFinder::pathFindExtendRefreshNodeCountMin,PathFinder::pathFindExtendRefreshNodeCountMax); + return refreshNodeCount; +} + PathFinder::PathFinder(const Map *map) { for(int i = 0; i < GameConstants::maxPlayers; ++i) { factions.push_back(FactionState()); @@ -451,7 +457,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout } 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) { canMoveToCells = false; break; @@ -474,7 +481,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout } 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); } //else if(tryLastPathCache == false) { @@ -927,7 +935,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout } else { if(i < pathFindRefresh || - (whileLoopCount >= pathFindExtendRefreshForNodeCount && i < pathFindExtendRefreshNodeCount)) { + (whileLoopCount >= pathFindExtendRefreshForNodeCount && + i < getPathFindExtendRefreshNodeCount(unit->getFactionIndex()))) { path->add(nodePos); } //else if(tryLastPathCache == false) { diff --git a/source/glest_game/ai/path_finder.h b/source/glest_game/ai/path_finder.h index de6d06ba..b3e322f2 100644 --- a/source/glest_game/ai/path_finder.h +++ b/source/glest_game/ai/path_finder.h @@ -87,7 +87,8 @@ public: static const int pathFindRefresh; static const int pathFindBailoutRadius; static const int pathFindExtendRefreshForNodeCount; - static const int pathFindExtendRefreshNodeCount; + static const int pathFindExtendRefreshNodeCountMin; + static const int pathFindExtendRefreshNodeCountMax; private: @@ -117,6 +118,7 @@ private: 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); + int getPathFindExtendRefreshNodeCount(int factionIndex); }; }}//end namespace