diff --git a/source/glest_game/ai/path_finder.cpp b/source/glest_game/ai/path_finder.cpp index 60841d86..7e7470fc 100644 --- a/source/glest_game/ai/path_finder.cpp +++ b/source/glest_game/ai/path_finder.cpp @@ -370,6 +370,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout //if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + std::map > > > > moveLookupCache; + // This cache stores the units free cell movement calcs during the looping below //std::map > localCacheForUnitCellMovement; int whileLoopCount = 0; @@ -412,7 +414,9 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout // canUnitMoveToCell = iterFind->second.find(sucPos)->second; //} //else { - canUnitMoveToCell = map->aproxCanMove(unit, node->pos, sucPos); + + + canUnitMoveToCell = map->aproxCanMove(unit, node->pos, sucPos,&moveLookupCache); //if(Config::getInstance().getBool("DisableCaching","false") == false) { // localCacheForUnitCellMovement[node->pos][sucPos] = canUnitMoveToCell; //} diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index 529de8ca..48da1f25 100644 --- a/source/glest_game/world/map.cpp +++ b/source/glest_game/world/map.cpp @@ -488,53 +488,108 @@ bool Map::canMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2) const } //checks if a unit can move from between 2 cells using only visible cells (for pathfinding) -bool Map::aproxCanMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2) const{ +bool Map::aproxCanMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2, std::map > > > > *lookupCache) const { int size= unit->getType()->getSize(); int teamIndex= unit->getTeam(); Field field= unit->getCurrField(); + if(lookupCache != NULL) { + std::map > > > >::const_iterator iterFind1 = lookupCache->find(pos1); + if(iterFind1 != lookupCache->end()) { + std::map > > >::const_iterator iterFind2 = iterFind1->second.find(pos2); + if(iterFind2 != iterFind1->second.end()) { + std::map > >::const_iterator iterFind3 = iterFind2->second.find(teamIndex); + if(iterFind3 != iterFind2->second.end()) { + std::map >::const_iterator iterFind4 = iterFind3->second.find(size); + if(iterFind4 != iterFind3->second.end()) { + std::map::const_iterator iterFind5 = iterFind4->second.find(field); + if(iterFind5 != iterFind4->second.end()) { + // Found this result in the cache + return iterFind5->second; + } + } + } + } + } + } + //single cell units - if(size==1) { - if(isAproxFreeCell(pos2, field, teamIndex) == false){ + if(size == 1) { + if(isAproxFreeCell(pos2, field, teamIndex) == false) { + if(lookupCache != NULL) { + (*lookupCache)[pos1][pos2][teamIndex][size][field]=false; + } return false; } - if(pos1.x != pos2.x && pos1.y != pos2.y){ + if(pos1.x != pos2.x && pos1.y != pos2.y) { if(isAproxFreeCell(Vec2i(pos1.x, pos2.y), field, teamIndex) == false) { + if(lookupCache != NULL) { + (*lookupCache)[pos1][pos2][teamIndex][size][field]=false; + } + return false; } if(isAproxFreeCell(Vec2i(pos2.x, pos1.y), field, teamIndex) == false) { + if(lookupCache != NULL) { + (*lookupCache)[pos1][pos2][teamIndex][size][field]=false; + } + return false; } } if(unit == NULL || unit->isBadHarvestPos(pos2) == true) { + if(lookupCache != NULL) { + (*lookupCache)[pos1][pos2][teamIndex][size][field]=false; + } + return false; } + if(lookupCache != NULL) { + (*lookupCache)[pos1][pos2][teamIndex][size][field]=true; + } + return true; } - //multi cell units else { - for(int i=pos2.x; igetUnit(unit->getCurrField())!=unit) { + for(int i = pos2.x; i < pos2.x + size; ++i) { + for(int j = pos2.y; j < pos2.y + size; ++j) { + if(isInside(i, j)) { + if(getCell(i, j)->getUnit(unit->getCurrField()) != unit) { if(isAproxFreeCell(Vec2i(i, j), field, teamIndex) == false) { + if(lookupCache != NULL) { + (*lookupCache)[pos1][pos2][teamIndex][size][field]=false; + } + return false; } } } else { + + if(lookupCache != NULL) { + (*lookupCache)[pos1][pos2][teamIndex][size][field]=false; + } + return false; } } } if(unit == NULL || unit->isBadHarvestPos(pos2) == true) { + if(lookupCache != NULL) { + (*lookupCache)[pos1][pos2][teamIndex][size][field]=false; + } + return false; } + if(lookupCache != NULL) { + (*lookupCache)[pos1][pos2][teamIndex][size][field]=true; + } + return true; } } diff --git a/source/glest_game/world/map.h b/source/glest_game/world/map.h index 8123a773..1743ded9 100755 --- a/source/glest_game/world/map.h +++ b/source/glest_game/world/map.h @@ -216,7 +216,7 @@ public: bool canOccupy(const Vec2i &pos, Field field, const UnitType *ut, CardinalDir facing); //unit placement - bool aproxCanMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2) const; + bool aproxCanMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2, std::map > > > > *lookupCache=NULL) const; bool canMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2) const; void putUnitCells(Unit *unit, const Vec2i &pos); void clearUnitCells(Unit *unit, const Vec2i &pos); diff --git a/source/shared_lib/sources/util/checksum.cpp b/source/shared_lib/sources/util/checksum.cpp index 54549514..701b59a1 100644 --- a/source/shared_lib/sources/util/checksum.cpp +++ b/source/shared_lib/sources/util/checksum.cpp @@ -22,9 +22,11 @@ #include // for open() #include "util.h" +#include "platform_common.h" #include "leak_dumper.h" using namespace std; +using namespace Shared::PlatformCommon; namespace Shared{ namespace Util{ @@ -115,13 +117,14 @@ void Checksum::addFileToSum(const string &path){ FILE* file= fopen(path.c_str(), "rb"); - if(file!=NULL){ + if(file!=NULL) { addString(lastFile(path)); + bool isXMLFile = (EndsWith(path, ".xml") == true); char buf[4096]=""; /* Should be large enough. */ int bufSize = sizeof buf; - while(!feof(file)){ + while(!feof(file)) { //int8 byte= 0; //size_t readBytes = fread(&byte, 1, 1, file); @@ -129,6 +132,12 @@ void Checksum::addFileToSum(const string &path){ if(fgets(buf, bufSize, file) != NULL) { //addByte(byte); for(int i = 0; buf[i] != 0 && i < bufSize; i++) { + // Ignore Spaces in XML files as they are + // ONLY for formatting + if(isXMLFile == true && + (buf[i] == ' ' || buf[i] == '\t' || buf[i] == '\n' || buf[i] == '\r')) { + continue; + } addByte(buf[i]); } }