- clear pathfinder precache for units when they die to free memory sooner
This commit is contained in:
parent
8059c064a3
commit
c58f338d1b
|
@ -85,6 +85,17 @@ void PathFinder::clearUnitPrecache(Unit *unit) {
|
|||
factions[unit->getFactionIndex()].precachedPath[unit->getId()].clear();
|
||||
}
|
||||
|
||||
void PathFinder::removeUnitPrecache(Unit *unit) {
|
||||
if(factions.size() > unit->getFactionIndex()) {
|
||||
if(factions[unit->getFactionIndex()].precachedTravelState.find(unit->getId()) != factions[unit->getFactionIndex()].precachedTravelState.end()) {
|
||||
factions[unit->getFactionIndex()].precachedTravelState.erase(unit->getId());
|
||||
}
|
||||
if(factions[unit->getFactionIndex()].precachedPath.find(unit->getId()) != factions[unit->getFactionIndex()].precachedPath.end()) {
|
||||
factions[unit->getFactionIndex()].precachedPath.erase(unit->getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStuck, int frameIndex) {
|
||||
//printf("PathFinder::findPath...\n");
|
||||
|
||||
|
|
|
@ -101,6 +101,7 @@ public:
|
|||
void init(const Map *map);
|
||||
TravelState findPath(Unit *unit, const Vec2i &finalPos, bool *wasStuck=NULL,int frameIndex=-1);
|
||||
void clearUnitPrecache(Unit *unit);
|
||||
void removeUnitPrecache(Unit *unit);
|
||||
|
||||
private:
|
||||
TravelState aStar(Unit *unit, const Vec2i &finalPos, bool inBailout, int frameIndex);
|
||||
|
|
|
@ -988,14 +988,16 @@ void Unit::kill() {
|
|||
clearCommands();
|
||||
|
||||
UnitUpdater *unitUpdater = game->getWorld()->getUnitUpdater();
|
||||
unitUpdater->clearUnitPrecache(this);
|
||||
//unitUpdater->clearUnitPrecache(this);
|
||||
unitUpdater->removeUnitPrecache(this);
|
||||
}
|
||||
|
||||
void Unit::undertake() {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to undertake unit id = %d [%s] [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->id, this->getFullName().c_str(),this->getDesc().c_str());
|
||||
|
||||
UnitUpdater *unitUpdater = game->getWorld()->getUnitUpdater();
|
||||
unitUpdater->clearUnitPrecache(this);
|
||||
//unitUpdater->clearUnitPrecache(this);
|
||||
unitUpdater->removeUnitPrecache(this);
|
||||
|
||||
livingUnits.erase(id);
|
||||
livingUnitsp.erase(this);
|
||||
|
|
|
@ -89,6 +89,12 @@ void UnitUpdater::clearUnitPrecache(Unit *unit) {
|
|||
}
|
||||
}
|
||||
|
||||
void UnitUpdater::removeUnitPrecache(Unit *unit) {
|
||||
if(pathFinder != NULL) {
|
||||
pathFinder->removeUnitPrecache(unit);
|
||||
}
|
||||
}
|
||||
|
||||
UnitUpdater::~UnitUpdater() {
|
||||
//UnitRangeCellsLookupItemCache.clear();
|
||||
|
||||
|
|
|
@ -113,6 +113,7 @@ public:
|
|||
void updateMorph(Unit *unit, int frameIndex);
|
||||
|
||||
void clearUnitPrecache(Unit *unit);
|
||||
void removeUnitPrecache(Unit *unit);
|
||||
|
||||
unsigned int getAttackWarningCount() const { return attackWarnings.size(); }
|
||||
std::pair<bool,Unit *> unitBeingAttacked(const Unit *unit);
|
||||
|
|
Loading…
Reference in New Issue