- more performance improvements for resource cache logic (try to avoid repetitive caching logic when it was already done once)
This commit is contained in:
parent
d07cd76459
commit
8bbbe403ad
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -85,6 +85,7 @@ private:
|
|||
|
||||
std::map<Vec2i, std::vector<FactionPathSuccessCache> > successfulPathFinderTargetList;
|
||||
std::map<Vec2i,int> cacheResourceTargetList;
|
||||
std::map<Vec2i,bool> cachedCloseResourceTargetLookupList;
|
||||
time_t lastResourceTargettListPurge;
|
||||
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue