Loading of moved refs complete.

test
cc9cii 10 years ago
parent 74b98f7178
commit 7673be6d0f

@ -3,7 +3,6 @@
#include <stdexcept>
#include <algorithm>
#include <iostream>
#include <QAbstractItemModel>
@ -866,11 +865,12 @@ bool CSMWorld::Data::continueLoading (CSMDoc::Messages& messages)
if (index < 0 || index >= mCells.getSize())
{
// log an error and continue loading the refs to the last loaded cell
std::cerr << "Logic error: cell index out of bounds" << std::endl;
CSMWorld::UniversalId id (CSMWorld::UniversalId::Type_None);
messages.add (id, "Logic error: cell index out of bounds");
index = mCells.getSize()-1;
}
std::string cellId = Misc::StringUtils::lowerCase (mCells.getId (index));
mRefs.load (*mReader, index, mBase, mRefLoadCache[cellId], messages);
mRefs.load (*mReader, index, mBase, mRefLoadCache, cellId, messages);
break;
}

@ -2,6 +2,7 @@
#include "refcollection.hpp"
#include <sstream>
#include <iostream>
#include <components/misc/stringops.hpp>
#include <components/esm/loadcell.hpp>
@ -12,8 +13,10 @@
#include "record.hpp"
void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool base,
std::map<ESM::RefNum, std::string>& cache, CSMDoc::Messages& messages)
std::map<std::string, std::map<ESM::RefNum, std::string> >& cache, const std::string& origCellId,
CSMDoc::Messages& messages)
{
std::string cellid = origCellId;
Record<Cell> cell = mCells.getRecord (cellIndex);
Cell& cell2 = base ? cell.mBase : cell.mModified;
@ -73,18 +76,20 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool
std::cerr << "Position: #" << index.first << " " << index.second
<<", Target #"<< mref.mTarget[0] << " " << mref.mTarget[1] << std::endl;
}
// FIXME: need to transfer the ref to the new cell
// transfer the ref to the new cell
cellid = ref.mCell;
}
}
}
else
ref.mCell = cell2.mId;
std::map<ESM::RefNum, std::string>::iterator iter = cache.find (ref.mRefNum);
std::map<ESM::RefNum, std::string>::iterator iter = cache[cellid].find (ref.mRefNum);
if (deleted)
{
if (iter==cache.end())
if (iter==cache[cellid].end())
{
CSMWorld::UniversalId id (CSMWorld::UniversalId::Type_Cell,
mCells.getId (cellIndex));
@ -101,7 +106,7 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool
if (record.mState==RecordBase::State_BaseOnly)
{
removeRows (index, 1);
cache.erase (iter);
cache[cellid].erase (iter);
}
else
{
@ -112,7 +117,7 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool
continue;
}
if (iter==cache.end())
if (iter==cache[cellid].end())
{
// new reference
ref.mId = getNewId();
@ -123,7 +128,7 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool
appendRecord (record);
cache.insert (std::make_pair (ref.mRefNum, ref.mId));
cache[cellid].insert (std::make_pair (ref.mRefNum, ref.mId));
}
else
{

@ -27,7 +27,7 @@ namespace CSMWorld
{}
void load (ESM::ESMReader& reader, int cellIndex, bool base,
std::map<ESM::RefNum, std::string>& cache,
std::map<std::string, std::map<ESM::RefNum, std::string> >& cache, const std::string& cellid,
CSMDoc::Messages& messages);
///< Load a sequence of references.

@ -3,7 +3,6 @@
#include <string>
#include <sstream>
#include <list>
#include <iostream> // FIXME: debugging only
#include <boost/concept_check.hpp>
@ -174,7 +173,6 @@ bool Cell::getNextRef(ESMReader &esm, CellRef &ref, bool& deleted, bool ignoreMo
// TODO: Try and document reference numbering, I don't think this has been done anywhere else.
if (!esm.hasMoreSubs())
return false;
//bool print = false; // FIXME: debugging only
// NOTE: We should not need this check. It is a safety check until we have checked
// more plugins, and how they treat these moved references.
@ -184,9 +182,6 @@ bool Cell::getNextRef(ESMReader &esm, CellRef &ref, bool& deleted, bool ignoreMo
{
esm.getHT (mref->mRefNum.mIndex);
esm.getHNOT (mref->mTarget, "CNDT");
//std::cout << "index " + std::to_string(mref->mRefNum.mIndex) + " target " <<
//std::to_string(mref->mTarget[0]) + ", " + std::to_string(mref->mTarget[1]) << std::endl;
//print = true; // FIXME: debugging only
adjustRefNum (mref->mRefNum, esm);
}
else
@ -199,19 +194,6 @@ bool Cell::getNextRef(ESMReader &esm, CellRef &ref, bool& deleted, bool ignoreMo
ref.load (esm);
#if 0
// FIXME: debugging only
if (print &&
((int)std::floor(ref.mPos.pos[0]/8192) != mref->mTarget[0] ||
(int)std::floor(ref.mPos.pos[1]/8192) != mref->mTarget[1]))
{
std::cout << ref.mRefID <<
", " + std::to_string((int)std::floor(ref.mPos.pos[0]/8192)) <<
", " + std::to_string((int)std::floor(ref.mPos.pos[1]/8192)) <<
", Z: " +std::to_string(ref.mPos.pos[2]) << std::endl;
}
#endif
// Identify references belonging to a parent file and adapt the ID accordingly.
adjustRefNum (ref.mRefNum, esm);

Loading…
Cancel
Save