diff --git a/source/glest_game/ai/path_finder.cpp b/source/glest_game/ai/path_finder.cpp index b67b519b..3ddbf8f1 100644 --- a/source/glest_game/ai/path_finder.cpp +++ b/source/glest_game/ai/path_finder.cpp @@ -359,7 +359,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout } }//while - if(chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld, openNodes.empty() = %d, pathFound = %d, nodeLimitReached = %d, unit = %s\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),openNodes.empty(),pathFound,nodeLimitReached,unit->getFullName().c_str()); + if(chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld, openNodes.size() = %d, pathFound = %d, nodeLimitReached = %d, unit = %s\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),openNodes.size(),pathFound,nodeLimitReached,unit->getFullName().c_str()); Node *lastNode= node; diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index 93e93444..66067625 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -700,21 +700,25 @@ void Faction::removeResourceTargetFromCache(const Vec2i &pos) { } void Faction::addCloseResourceTargetToCache(const Vec2i &pos) { - const Map *map = world->getMap(); - const int harvestDistance = 5; - for(int j = -harvestDistance; j <= harvestDistance; ++j) { - for(int k = -harvestDistance; k <= harvestDistance; ++k) { - Vec2i newPos = pos + Vec2i(j,k); - if(isResourceTargetInCache(newPos) == false) { - if(map->isInside(newPos.x, newPos.y)) { - Resource *r = map->getSurfaceCell(map->toSurfCoords(newPos))->getResource(); - if(r != NULL) { - //addResourceTargetToCache(newPos); - cacheResourceTargetList[newPos] = 1; + if(cachedCloseResourceTargetLookupList.find(pos) == cachedCloseResourceTargetLookupList.end()) { + const Map *map = world->getMap(); + const int harvestDistance = 5; + for(int j = -harvestDistance; j <= harvestDistance; ++j) { + for(int k = -harvestDistance; k <= harvestDistance; ++k) { + Vec2i newPos = pos + Vec2i(j,k); + if(isResourceTargetInCache(newPos) == false) { + if(map->isInside(newPos.x, newPos.y)) { + Resource *r = map->getSurfaceCell(map->toSurfCoords(newPos))->getResource(); + if(r != NULL) { + //addResourceTargetToCache(newPos); + cacheResourceTargetList[newPos] = 1; + } } } } } + + cachedCloseResourceTargetLookupList[pos] = true; } } diff --git a/source/glest_game/type_instances/faction.h b/source/glest_game/type_instances/faction.h index b7e032ab..3c9dd4bb 100644 --- a/source/glest_game/type_instances/faction.h +++ b/source/glest_game/type_instances/faction.h @@ -85,6 +85,7 @@ private: std::map > successfulPathFinderTargetList; std::map cacheResourceTargetList; + std::map cachedCloseResourceTargetLookupList; time_t lastResourceTargettListPurge; public: