try to see if this improves pathfidner performance
This commit is contained in:
parent
ba3e5a6030
commit
273abcde75
|
@ -97,11 +97,10 @@ void PathFinder::clearCaches() {
|
|||
for(int factionIndex = 0; factionIndex < GameConstants::maxPlayers; ++factionIndex) {
|
||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||
FactionState &faction = factions.getFactionState(factionIndex);
|
||||
MutexSafeWrapper safeMutex(faction.getMutex(),mutexOwnerId);
|
||||
MutexSafeWrapper safeMutex(faction.getMutexPreCache(),mutexOwnerId);
|
||||
|
||||
faction.precachedTravelState.clear();
|
||||
faction.precachedPath.clear();
|
||||
faction.badCellList.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,11 +109,10 @@ void PathFinder::clearUnitPrecache(Unit *unit) {
|
|||
int factionIndex = unit->getFactionIndex();
|
||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||
FactionState &faction = factions.getFactionState(factionIndex);
|
||||
MutexSafeWrapper safeMutex(faction.getMutex(),mutexOwnerId);
|
||||
MutexSafeWrapper safeMutex(faction.getMutexPreCache(),mutexOwnerId);
|
||||
|
||||
faction.precachedTravelState[unit->getId()] = tsImpossible;
|
||||
faction.precachedPath[unit->getId()].clear();
|
||||
faction.badCellList.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,7 +121,7 @@ void PathFinder::removeUnitPrecache(Unit *unit) {
|
|||
int factionIndex = unit->getFactionIndex();
|
||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||
FactionState &faction = factions.getFactionState(factionIndex);
|
||||
MutexSafeWrapper safeMutex(faction.getMutex(),mutexOwnerId);
|
||||
MutexSafeWrapper safeMutex(faction.getMutexPreCache(),mutexOwnerId);
|
||||
|
||||
if(faction.precachedTravelState.find(unit->getId()) != faction.precachedTravelState.end()) {
|
||||
faction.precachedTravelState.erase(unit->getId());
|
||||
|
@ -451,13 +449,14 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
|
|||
int factionIndex = unit->getFactionIndex();
|
||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||
FactionState &faction = factions.getFactionState(factionIndex);
|
||||
MutexSafeWrapper safeMutex(faction.getMutex(),mutexOwnerId);
|
||||
MutexSafeWrapper safeMutexPreCache(faction.getMutexPreCache(),mutexOwnerId);
|
||||
|
||||
if(faction.precachedPath[unit->getId()].size() <= 0) {
|
||||
throw megaglest_runtime_error("factions[unit->getFactionIndex()].precachedPath[unit->getId()].size() <= 0!");
|
||||
}
|
||||
|
||||
pos = faction.precachedPath[unit->getId()][0];
|
||||
safeMutexPreCache.ReleaseLock();
|
||||
|
||||
codeLocation = "39";
|
||||
}
|
||||
|
|
|
@ -89,25 +89,37 @@ public:
|
|||
class FactionState {
|
||||
protected:
|
||||
Mutex *factionMutex;
|
||||
Mutex *factionMutexPrecache;
|
||||
public:
|
||||
FactionState() : factionMutex(new Mutex()) {
|
||||
FactionState() :
|
||||
//factionMutex(new Mutex()),
|
||||
factionMutex(NULL),
|
||||
factionMutexPrecache(new Mutex) {
|
||||
|
||||
openPosList.clear();
|
||||
openNodesList.clear();
|
||||
closedNodesList.clear();
|
||||
nodePool.clear();
|
||||
nodePoolCount = 0;
|
||||
useMaxNodeCount = 0;
|
||||
|
||||
precachedTravelState.clear();
|
||||
precachedPath.clear();
|
||||
badCellList.clear();
|
||||
}
|
||||
~FactionState() {
|
||||
delete factionMutex;
|
||||
factionMutex = NULL;
|
||||
|
||||
delete factionMutexPrecache;
|
||||
factionMutexPrecache = NULL;
|
||||
}
|
||||
Mutex * getMutex() {
|
||||
return factionMutex;
|
||||
}
|
||||
Mutex * getMutexPreCache() {
|
||||
return factionMutexPrecache;
|
||||
}
|
||||
|
||||
std::map<Vec2i, bool> openPosList;
|
||||
std::map<float, Nodes> openNodesList;
|
||||
std::map<float, Nodes> closedNodesList;
|
||||
|
@ -119,7 +131,6 @@ public:
|
|||
|
||||
std::map<int,TravelState> precachedTravelState;
|
||||
std::map<int,std::vector<Vec2i> > precachedPath;
|
||||
std::map<int,std::map<Field,BadUnitNodeList> > badCellList;
|
||||
};
|
||||
|
||||
class FactionStateManager {
|
||||
|
|
Loading…
Reference in New Issue