Implement deletion of moved references (Bug #3471)

coverity_scan^2
MiroslavR 9 years ago
parent 4ac5174d89
commit d790747389

@ -497,9 +497,11 @@ namespace MWWorld
// List moved references, from separately tracked list.
for (ESM::CellRefTracker::const_iterator it = mCell->mLeasedRefs.begin(); it != mCell->mLeasedRefs.end(); ++it)
{
const ESM::CellRef &ref = *it;
const ESM::CellRef &ref = it->first;
bool deleted = it->second;
mIds.push_back(Misc::StringUtils::lowerCase(ref.mRefID));
if (!deleted)
mIds.push_back(Misc::StringUtils::lowerCase(ref.mRefID));
}
std::sort (mIds.begin(), mIds.end());
@ -549,9 +551,10 @@ namespace MWWorld
// Load moved references, from separately tracked list.
for (ESM::CellRefTracker::const_iterator it = mCell->mLeasedRefs.begin(); it != mCell->mLeasedRefs.end(); ++it)
{
ESM::CellRef &ref = const_cast<ESM::CellRef&>(*it);
ESM::CellRef &ref = const_cast<ESM::CellRef&>(it->first);
bool deleted = it->second;
loadRef (ref, false);
loadRef (ref, deleted);
}
updateMergedRefs();

@ -513,19 +513,16 @@ namespace MWWorld
bool deleted = false;
cell->getNextRef(esm, ref, deleted);
if (!deleted)
{
// Add data required to make reference appear in the correct cell.
// We should not need to test for duplicates, as this part of the code is pre-cell merge.
cell->mMovedRefs.push_back(cMRef);
// But there may be duplicates here!
ESM::CellRefTracker::iterator iter = std::find(cellAlt->mLeasedRefs.begin(), cellAlt->mLeasedRefs.end(), ref.mRefNum);
if (iter == cellAlt->mLeasedRefs.end())
cellAlt->mLeasedRefs.push_back(ref);
else
*iter = ref;
}
// Add data required to make reference appear in the correct cell.
// We should not need to test for duplicates, as this part of the code is pre-cell merge.
cell->mMovedRefs.push_back(cMRef);
// But there may be duplicates here!
ESM::CellRefTracker::iterator iter = std::find_if(cellAlt->mLeasedRefs.begin(), cellAlt->mLeasedRefs.end(), ESM::CellRefTrackerPredicate(ref.mRefNum));
if (iter == cellAlt->mLeasedRefs.end())
cellAlt->mLeasedRefs.push_back(std::make_pair(ref, deleted));
else
*iter = std::make_pair(ref, deleted);
}
}
const ESM::Cell *Store<ESM::Cell>::search(const std::string &id) const
@ -681,7 +678,7 @@ namespace MWWorld
if (itold != oldcell->mMovedRefs.end()) {
ESM::MovedCellRef target0 = *itold;
ESM::Cell *wipecell = const_cast<ESM::Cell*>(search(target0.mTarget[0], target0.mTarget[1]));
ESM::CellRefTracker::iterator it_lease = std::find(wipecell->mLeasedRefs.begin(), wipecell->mLeasedRefs.end(), it->mRefNum);
ESM::CellRefTracker::iterator it_lease = std::find_if(wipecell->mLeasedRefs.begin(), wipecell->mLeasedRefs.end(), ESM::CellRefTrackerPredicate(it->mRefNum));
if (it_lease != wipecell->mLeasedRefs.end())
wipecell->mLeasedRefs.erase(it_lease);
else

@ -43,7 +43,15 @@ bool operator==(const MovedCellRef& ref, const RefNum& refNum);
bool operator==(const CellRef& ref, const RefNum& refNum);
typedef std::list<MovedCellRef> MovedCellRefTracker;
typedef std::list<CellRef> CellRefTracker;
typedef std::list<std::pair<CellRef, bool> > CellRefTracker;
struct CellRefTrackerPredicate
{
RefNum mRefNum;
CellRefTrackerPredicate(const RefNum& refNum) : mRefNum(refNum) {}
bool operator() (const std::pair<CellRef, bool>& refdelPair) { return refdelPair.first == mRefNum; }
};
/* Cells hold data about objects, creatures, statics (rocks, walls,
buildings) and landscape (for exterior cells). Cells frequently

Loading…
Cancel
Save