From ca2408073e5fb3f596af1a1b99f8639a6710d1cb Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sun, 28 Nov 2010 03:35:44 +0000 Subject: [PATCH] - disabled more caching to determine if any of these caches cause out of synch --- source/glest_game/ai/path_finder.cpp | 4 ++-- source/glest_game/world/unit_updater.cpp | 26 +++++++++++++----------- source/glest_game/world/unit_updater.h | 12 +++++------ 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/source/glest_game/ai/path_finder.cpp b/source/glest_game/ai/path_finder.cpp index 00df0162..0a1744cd 100644 --- a/source/glest_game/ai/path_finder.cpp +++ b/source/glest_game/ai/path_finder.cpp @@ -102,7 +102,7 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu unit->setCurrentUnitTitle(szBuf); } - unit->getFaction()->addCachedPath(finalPos,unit); + //unit->getFaction()->addCachedPath(finalPos,unit); return tsArrived; } else { @@ -169,7 +169,7 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu case tsArrived: if(ts == tsArrived) { - unit->getFaction()->addCachedPath(finalPos,unit); + //unit->getFaction()->addCachedPath(finalPos,unit); } // The unit is stuck (not only blocked but unable to go anywhere for a while) diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 9cd6e0f5..0ffd9ad8 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -53,7 +53,7 @@ UnitUpdater::UnitUpdater() { this->scriptManager= NULL; this->routePlanner = NULL; this->pathFinder = NULL; - UnitRangeCellsLookupItemCacheTimerCount = 0; + //UnitRangeCellsLookupItemCacheTimerCount = 0; } void UnitUpdater::init(Game *game){ @@ -67,7 +67,7 @@ void UnitUpdater::init(Game *game){ this->scriptManager= game->getScriptManager(); this->routePlanner = NULL; this->pathFinder = NULL; - UnitRangeCellsLookupItemCacheTimerCount = 0; + //UnitRangeCellsLookupItemCacheTimerCount = 0; switch(this->game->getGameSettings()->getPathFinderType()) { case pfBasic: @@ -83,7 +83,7 @@ void UnitUpdater::init(Game *game){ } UnitUpdater::~UnitUpdater() { - UnitRangeCellsLookupItemCache.clear(); + //UnitRangeCellsLookupItemCache.clear(); delete pathFinder; pathFinder = NULL; @@ -1464,6 +1464,7 @@ bool UnitUpdater::attackableOnRange(const Unit *unit, Unit **rangedPtr, const At return unitOnRange(unit, range, rangedPtr, ast); } +/* bool UnitUpdater::findCachedCellsEnemies(Vec2i center, int range, int size, vector &enemies, const AttackSkillType *ast, const Unit *unit, const Unit *commandTarget) { @@ -1490,6 +1491,7 @@ bool UnitUpdater::findCachedCellsEnemies(Vec2i center, int range, int size, vect return result; } +*/ void UnitUpdater::findEnemiesForCell(const AttackSkillType *ast, Cell *cell, const Unit *unit, const Unit *commandTarget,vector &enemies) { @@ -1534,12 +1536,12 @@ bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr, Vec2f floatCenter = unit->getFloatCenteredPos(); bool foundInCache = true; - if(findCachedCellsEnemies(center,range,size,enemies,ast, - unit,commandTarget) == false) { + //if(findCachedCellsEnemies(center,range,size,enemies,ast, + // unit,commandTarget) == false) { foundInCache = false; //nearby cells - UnitRangeCellsLookupItem cacheItem; + //UnitRangeCellsLookupItem cacheItem; for(int i=center.x-range; igetCell(i,j); findEnemiesForCell(ast,cell,unit,commandTarget,enemies); - cacheItem.rangeCellList.push_back(cell); + //cacheItem.rangeCellList.push_back(cell); } } } // Ok update our caches with the latest info - if(cacheItem.rangeCellList.size() > 0) { - cacheItem.UnitRangeCellsLookupItemCacheTimerCountIndex = UnitRangeCellsLookupItemCacheTimerCount++; - UnitRangeCellsLookupItemCache[center][size][range] = cacheItem; - } - } + //if(cacheItem.rangeCellList.size() > 0) { + // cacheItem.UnitRangeCellsLookupItemCacheTimerCountIndex = UnitRangeCellsLookupItemCacheTimerCount++; + // UnitRangeCellsLookupItemCache[center][size][range] = cacheItem; + //} + //} //attack enemies that can attack first for(int i = 0; i< enemies.size(); ++i) { diff --git a/source/glest_game/world/unit_updater.h b/source/glest_game/world/unit_updater.h index 923fac9a..59997815 100644 --- a/source/glest_game/world/unit_updater.h +++ b/source/glest_game/world/unit_updater.h @@ -71,14 +71,14 @@ private: Game *game; RandomGen random; - std::map > > UnitRangeCellsLookupItemCache; + //std::map > > UnitRangeCellsLookupItemCache; //std::map ExploredCellsLookupItemCacheTimer; - int UnitRangeCellsLookupItemCacheTimerCount; + //int UnitRangeCellsLookupItemCacheTimerCount; - bool findCachedCellsEnemies(Vec2i center, int range, - int size, vector &enemies, - const AttackSkillType *ast, const Unit *unit, - const Unit *commandTarget); + //bool findCachedCellsEnemies(Vec2i center, int range, + // int size, vector &enemies, + // const AttackSkillType *ast, const Unit *unit, + // const Unit *commandTarget); void findEnemiesForCell(const AttackSkillType *ast, Cell *cell, const Unit *unit, const Unit *commandTarget,vector &enemies);