- more performance improvements for resource cache logic (try to avoid repetitive caching logic when it was already done once)

This commit is contained in:
Mark Vejvoda 2010-10-25 22:02:36 +00:00
parent d07cd76459
commit 8bbbe403ad
3 changed files with 17 additions and 12 deletions

View File

@ -359,7 +359,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
} }
}//while }//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; Node *lastNode= node;

View File

@ -700,21 +700,25 @@ void Faction::removeResourceTargetFromCache(const Vec2i &pos) {
} }
void Faction::addCloseResourceTargetToCache(const Vec2i &pos) { void Faction::addCloseResourceTargetToCache(const Vec2i &pos) {
const Map *map = world->getMap(); if(cachedCloseResourceTargetLookupList.find(pos) == cachedCloseResourceTargetLookupList.end()) {
const int harvestDistance = 5; const Map *map = world->getMap();
for(int j = -harvestDistance; j <= harvestDistance; ++j) { const int harvestDistance = 5;
for(int k = -harvestDistance; k <= harvestDistance; ++k) { for(int j = -harvestDistance; j <= harvestDistance; ++j) {
Vec2i newPos = pos + Vec2i(j,k); for(int k = -harvestDistance; k <= harvestDistance; ++k) {
if(isResourceTargetInCache(newPos) == false) { Vec2i newPos = pos + Vec2i(j,k);
if(map->isInside(newPos.x, newPos.y)) { if(isResourceTargetInCache(newPos) == false) {
Resource *r = map->getSurfaceCell(map->toSurfCoords(newPos))->getResource(); if(map->isInside(newPos.x, newPos.y)) {
if(r != NULL) { Resource *r = map->getSurfaceCell(map->toSurfCoords(newPos))->getResource();
//addResourceTargetToCache(newPos); if(r != NULL) {
cacheResourceTargetList[newPos] = 1; //addResourceTargetToCache(newPos);
cacheResourceTargetList[newPos] = 1;
}
} }
} }
} }
} }
cachedCloseResourceTargetLookupList[pos] = true;
} }
} }

View File

@ -85,6 +85,7 @@ private:
std::map<Vec2i, std::vector<FactionPathSuccessCache> > successfulPathFinderTargetList; std::map<Vec2i, std::vector<FactionPathSuccessCache> > successfulPathFinderTargetList;
std::map<Vec2i,int> cacheResourceTargetList; std::map<Vec2i,int> cacheResourceTargetList;
std::map<Vec2i,bool> cachedCloseResourceTargetLookupList;
time_t lastResourceTargettListPurge; time_t lastResourceTargettListPurge;
public: public: