1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-30 13:36:42 +00:00

Support moved references (i.e. with MVRF sub-records) that do not occur at the beginning of the cell references block.

This commit is contained in:
cc9cii 2021-06-30 15:34:40 +10:00
parent df3a47187b
commit 6575b95448

View file

@ -496,21 +496,29 @@ namespace MWWorld
} }
return search(cell.mName); return search(cell.mName);
} }
// this method *must* be called right after esm.loadCell()
void Store<ESM::Cell>::handleMovedCellRefs(ESM::ESMReader& esm, ESM::Cell* cell) void Store<ESM::Cell>::handleMovedCellRefs(ESM::ESMReader& esm, ESM::Cell* cell)
{ {
//Handling MovedCellRefs, there is no way to do it inside loadcell ESM::CellRef ref;
while (esm.isNextSub("MVRF")) { ESM::MovedCellRef cMRef;
ESM::CellRef ref; cMRef.mRefNum.mIndex = 0;
ESM::MovedCellRef cMRef; bool deleted = false;
cell->getNextMVRF(esm, cMRef);
ESM::ESM_Context ctx = esm.getContext();
// Handling MovedCellRefs, there is no way to do it inside loadcell
// TODO: verify above comment
//
// Get regular moved reference data. Adapted from CellStore::loadRefs. Maybe we can optimize the following
// implementation when the oher implementation works as well.
while (cell->getNextRef(esm, ref, deleted, /*ignoreMoves*/true, &cMRef))
{
if (!cMRef.mRefNum.mIndex)
continue; // ignore refs that are not moved
ESM::Cell *cellAlt = const_cast<ESM::Cell*>(searchOrCreate(cMRef.mTarget[0], cMRef.mTarget[1])); ESM::Cell *cellAlt = const_cast<ESM::Cell*>(searchOrCreate(cMRef.mTarget[0], cMRef.mTarget[1]));
// Get regular moved reference data. Adapted from CellStore::loadRefs. Maybe we can optimize the following
// implementation when the oher implementation works as well.
bool deleted = false;
cell->getNextRef(esm, ref, deleted);
// Add data required to make reference appear in the correct cell. // 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. // We should not need to test for duplicates, as this part of the code is pre-cell merge.
cell->mMovedRefs.push_back(cMRef); cell->mMovedRefs.push_back(cMRef);
@ -521,7 +529,11 @@ namespace MWWorld
cellAlt->mLeasedRefs.emplace_back(std::move(ref), deleted); cellAlt->mLeasedRefs.emplace_back(std::move(ref), deleted);
else else
*iter = std::make_pair(std::move(ref), deleted); *iter = std::make_pair(std::move(ref), deleted);
cMRef.mRefNum.mIndex = 0;
} }
esm.restoreContext(ctx);
} }
const ESM::Cell *Store<ESM::Cell>::search(const std::string &id) const const ESM::Cell *Store<ESM::Cell>::search(const std::string &id) const
{ {