diff --git a/source/glest_game/ai/path_finder.cpp b/source/glest_game/ai/path_finder.cpp index 7002311d5..743038dc1 100644 --- a/source/glest_game/ai/path_finder.cpp +++ b/source/glest_game/ai/path_finder.cpp @@ -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"; } diff --git a/source/glest_game/ai/path_finder.h b/source/glest_game/ai/path_finder.h index 33cd3edbe..e1659320a 100644 --- a/source/glest_game/ai/path_finder.h +++ b/source/glest_game/ai/path_finder.h @@ -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 openPosList; std::map openNodesList; std::map closedNodesList; @@ -119,7 +131,6 @@ public: std::map precachedTravelState; std::map > precachedPath; - std::map > badCellList; }; class FactionStateManager {