- attempt to improve pathfinder performance and lengthen max nodes to 900

This commit is contained in:
Mark Vejvoda 2011-04-26 21:51:18 +00:00
parent 962aee539f
commit 47ef05ceed
6 changed files with 62 additions and 10 deletions

View File

@ -41,10 +41,11 @@ const int PathFinder::maxFreeSearchRadius = 10;
//const int PathFinder::pathFindNodesMax= 400;
int PathFinder::pathFindNodesAbsoluteMax = 900;
int PathFinder::pathFindNodesMax = 300;
int PathFinder::pathFindNodesMax = 2000;
const int PathFinder::pathFindRefresh = 10;
const int PathFinder::pathFindBailoutRadius = 20;
const int PathFinder::pathFindExtendRefreshForNodeCount = 25;
const int PathFinder::pathFindExtendRefreshNodeCount = 40;
PathFinder::PathFinder() {
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
@ -447,7 +448,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
throw runtime_error("Pathfinder invalid node path position = " + nodePos.getString() + " i = " + intToStr(i));
}
if(i < pathFindRefresh) {
if(i < pathFindRefresh ||
(factions[unit->getFactionIndex()].precachedPath[unit->getId()].size() >= pathFindExtendRefreshForNodeCount && i < pathFindExtendRefreshNodeCount)) {
if(map->aproxCanMove(unit, lastPos, nodePos) == false) {
canMoveToCells = false;
break;
@ -469,7 +471,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
throw runtime_error("Pathfinder invalid node path position = " + nodePos.getString() + " i = " + intToStr(i));
}
if(i < pathFindRefresh) {
if(i < pathFindRefresh ||
(factions[unit->getFactionIndex()].precachedPath[unit->getId()].size() >= pathFindExtendRefreshForNodeCount && i < pathFindExtendRefreshNodeCount)) {
path->add(nodePos);
}
//else if(tryLastPathCache == false) {
@ -921,7 +924,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
factions[unit->getFactionIndex()].precachedPath[unit->getId()].push_back(nodePos);
}
else {
if(i < pathFindRefresh) {
if(i < pathFindRefresh ||
(whileLoopCount >= pathFindExtendRefreshForNodeCount && i < pathFindExtendRefreshNodeCount)) {
path->add(nodePos);
}
//else if(tryLastPathCache == false) {

View File

@ -86,6 +86,8 @@ public:
static const int maxFreeSearchRadius;
static const int pathFindRefresh;
static const int pathFindBailoutRadius;
static const int pathFindExtendRefreshForNodeCount;
static const int pathFindExtendRefreshNodeCount;
private:

View File

@ -38,6 +38,7 @@
#include "cache_manager.h"
#include <iterator>
#include "core_data.h"
//#include "unicode/uclean.h"
// For gcc backtrace on crash!
#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
@ -1980,6 +1981,15 @@ int glestMain(int argc, char** argv) {
disableBacktrace = true;
}
// UErrorCode status = U_ZERO_ERROR;
// u_init(&status);
// if (U_SUCCESS(status)) {
// printf("everything is OK\n");
// }
// else {
// printf("error %s opening resource\n", u_errorName(status));
// }
const int knownArgCount = sizeof(GAME_ARGS) / sizeof(GAME_ARGS[0]);
for(int idx = 1; idx < argc; ++idx) {
if( hasCommandArgument(knownArgCount, (char **)&GAME_ARGS[0], argv[idx], NULL, 0, true) == false) {
@ -2326,12 +2336,14 @@ int glestMain(int argc, char** argv) {
if(foundParamIndIndex < 0) {
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_SHOW_PATH_CRC]),&foundParamIndIndex);
}
string paramValue = argv[foundParamIndIndex];
vector<string> paramPartTokens;
Tokenize(paramValue,paramPartTokens,"=");
if(paramPartTokens.size() >= 3 && paramPartTokens[1].length() > 0) {
string itemName = paramPartTokens[1];
string itemNameFilter = paramPartTokens[2];
//printf("\n\nitemName [%s] itemNameFilter [%s]\n",itemName.c_str(),itemNameFilter.c_str());
int32 crcValue = getFolderTreeContentsCheckSumRecursively(itemName, itemNameFilter, NULL, true);
printf("CRC value for path [%s] filter [%s] is [%d]\n",itemName.c_str(),itemNameFilter.c_str(),crcValue);

View File

@ -247,7 +247,7 @@ void Faction::init(
texture->load(data_path + "data/core/faction_textures/faction"+intToStr(startLocationIndex)+".tga");
if( game->getGameSettings()->getPathFinderType() == pfBasic &&
Config::getInstance().getBool("EnableFactionWorkerThreads","false") == true) {
Config::getInstance().getBool("EnableFactionWorkerThreads","true") == true) {
if(workerThread != NULL) {
workerThread->signalQuit();
if(workerThread->shutdownAndWait() == true) {

View File

@ -2099,7 +2099,7 @@ void Unit::setLastPathfindFailedFrameToCurrentFrame() {
bool Unit::isLastPathfindFailedFrameWithinCurrentFrameTolerance() const {
static const bool enablePathfinderEnlargeMaxNodes = Config::getInstance().getBool("EnablePathfinderEnlargeMaxNodes","false");
bool result = !enablePathfinderEnlargeMaxNodes;
bool result = enablePathfinderEnlargeMaxNodes;
if(enablePathfinderEnlargeMaxNodes) {
const int MIN_FRAME_ELAPSED_RETRY = 960;
result = (getFrameCount() - lastPathfindFailedFrame >= MIN_FRAME_ELAPSED_RETRY);

View File

@ -706,7 +706,19 @@ bool Map::canMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2, std::m
}
}
}
if(unit == NULL || unit->isBadHarvestPos(pos2) == true) {
bool isBadHarvestPos = false;
if(unit != NULL) {
Command *command= unit->getCurrCommand();
if(command != NULL) {
const HarvestCommandType *hct = dynamic_cast<const HarvestCommandType*>(command->getCommandType());
if(hct != NULL && unit->isBadHarvestPos(pos2) == true) {
isBadHarvestPos = true;
}
}
}
if(unit == NULL || isBadHarvestPos == true) {
if(lookupCache != NULL) {
(*lookupCache)[pos1][pos2][size][field]=false;
}
@ -777,7 +789,18 @@ bool Map::aproxCanMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2, s
}
}
if(unit == NULL || unit->isBadHarvestPos(pos2) == true) {
bool isBadHarvestPos = false;
if(unit != NULL) {
Command *command= unit->getCurrCommand();
if(command != NULL) {
const HarvestCommandType *hct = dynamic_cast<const HarvestCommandType*>(command->getCommandType());
if(hct != NULL && unit->isBadHarvestPos(pos2) == true) {
isBadHarvestPos = true;
}
}
}
if(unit == NULL || isBadHarvestPos == true) {
if(lookupCache != NULL) {
(*lookupCache)[pos1][pos2][teamIndex][size][field]=false;
}
@ -819,7 +842,18 @@ bool Map::aproxCanMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2, s
}
}
if(unit == NULL || unit->isBadHarvestPos(pos2) == true) {
bool isBadHarvestPos = false;
if(unit != NULL) {
Command *command= unit->getCurrCommand();
if(command != NULL) {
const HarvestCommandType *hct = dynamic_cast<const HarvestCommandType*>(command->getCommandType());
if(hct != NULL && unit->isBadHarvestPos(pos2) == true) {
isBadHarvestPos = true;
}
}
}
if(unit == NULL || isBadHarvestPos == true) {
if(lookupCache != NULL) {
(*lookupCache)[pos1][pos2][teamIndex][size][field]=false;
}