try to see if this improves pathfidner performance

This commit is contained in:
Mark Vejvoda 2013-11-09 20:44:37 +00:00
parent ba3e5a6030
commit 273abcde75
2 changed files with 19 additions and 9 deletions

View File

@ -97,11 +97,10 @@ void PathFinder::clearCaches() {
for(int factionIndex = 0; factionIndex < GameConstants::maxPlayers; ++factionIndex) { for(int factionIndex = 0; factionIndex < GameConstants::maxPlayers; ++factionIndex) {
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
FactionState &faction = factions.getFactionState(factionIndex); FactionState &faction = factions.getFactionState(factionIndex);
MutexSafeWrapper safeMutex(faction.getMutex(),mutexOwnerId); MutexSafeWrapper safeMutex(faction.getMutexPreCache(),mutexOwnerId);
faction.precachedTravelState.clear(); faction.precachedTravelState.clear();
faction.precachedPath.clear(); faction.precachedPath.clear();
faction.badCellList.clear();
} }
} }
@ -110,11 +109,10 @@ void PathFinder::clearUnitPrecache(Unit *unit) {
int factionIndex = unit->getFactionIndex(); int factionIndex = unit->getFactionIndex();
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
FactionState &faction = factions.getFactionState(factionIndex); FactionState &faction = factions.getFactionState(factionIndex);
MutexSafeWrapper safeMutex(faction.getMutex(),mutexOwnerId); MutexSafeWrapper safeMutex(faction.getMutexPreCache(),mutexOwnerId);
faction.precachedTravelState[unit->getId()] = tsImpossible; faction.precachedTravelState[unit->getId()] = tsImpossible;
faction.precachedPath[unit->getId()].clear(); faction.precachedPath[unit->getId()].clear();
faction.badCellList.clear();
} }
} }
@ -123,7 +121,7 @@ void PathFinder::removeUnitPrecache(Unit *unit) {
int factionIndex = unit->getFactionIndex(); int factionIndex = unit->getFactionIndex();
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
FactionState &faction = factions.getFactionState(factionIndex); FactionState &faction = factions.getFactionState(factionIndex);
MutexSafeWrapper safeMutex(faction.getMutex(),mutexOwnerId); MutexSafeWrapper safeMutex(faction.getMutexPreCache(),mutexOwnerId);
if(faction.precachedTravelState.find(unit->getId()) != faction.precachedTravelState.end()) { if(faction.precachedTravelState.find(unit->getId()) != faction.precachedTravelState.end()) {
faction.precachedTravelState.erase(unit->getId()); faction.precachedTravelState.erase(unit->getId());
@ -451,13 +449,14 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
int factionIndex = unit->getFactionIndex(); int factionIndex = unit->getFactionIndex();
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
FactionState &faction = factions.getFactionState(factionIndex); FactionState &faction = factions.getFactionState(factionIndex);
MutexSafeWrapper safeMutex(faction.getMutex(),mutexOwnerId); MutexSafeWrapper safeMutexPreCache(faction.getMutexPreCache(),mutexOwnerId);
if(faction.precachedPath[unit->getId()].size() <= 0) { if(faction.precachedPath[unit->getId()].size() <= 0) {
throw megaglest_runtime_error("factions[unit->getFactionIndex()].precachedPath[unit->getId()].size() <= 0!"); throw megaglest_runtime_error("factions[unit->getFactionIndex()].precachedPath[unit->getId()].size() <= 0!");
} }
pos = faction.precachedPath[unit->getId()][0]; pos = faction.precachedPath[unit->getId()][0];
safeMutexPreCache.ReleaseLock();
codeLocation = "39"; codeLocation = "39";
} }

View File

@ -89,25 +89,37 @@ public:
class FactionState { class FactionState {
protected: protected:
Mutex *factionMutex; Mutex *factionMutex;
Mutex *factionMutexPrecache;
public: public:
FactionState() : factionMutex(new Mutex()) { FactionState() :
//factionMutex(new Mutex()),
factionMutex(NULL),
factionMutexPrecache(new Mutex) {
openPosList.clear(); openPosList.clear();
openNodesList.clear(); openNodesList.clear();
closedNodesList.clear(); closedNodesList.clear();
nodePool.clear(); nodePool.clear();
nodePoolCount = 0; nodePoolCount = 0;
useMaxNodeCount = 0; useMaxNodeCount = 0;
precachedTravelState.clear(); precachedTravelState.clear();
precachedPath.clear(); precachedPath.clear();
badCellList.clear();
} }
~FactionState() { ~FactionState() {
delete factionMutex; delete factionMutex;
factionMutex = NULL; factionMutex = NULL;
delete factionMutexPrecache;
factionMutexPrecache = NULL;
} }
Mutex * getMutex() { Mutex * getMutex() {
return factionMutex; return factionMutex;
} }
Mutex * getMutexPreCache() {
return factionMutexPrecache;
}
std::map<Vec2i, bool> openPosList; std::map<Vec2i, bool> openPosList;
std::map<float, Nodes> openNodesList; std::map<float, Nodes> openNodesList;
std::map<float, Nodes> closedNodesList; std::map<float, Nodes> closedNodesList;
@ -119,7 +131,6 @@ public:
std::map<int,TravelState> precachedTravelState; std::map<int,TravelState> precachedTravelState;
std::map<int,std::vector<Vec2i> > precachedPath; std::map<int,std::vector<Vec2i> > precachedPath;
std::map<int,std::map<Field,BadUnitNodeList> > badCellList;
}; };
class FactionStateManager { class FactionStateManager {