From 7673be6d0fb9a2083d63d421a0e30c886270a372 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Sun, 26 Apr 2015 12:18:23 +1000 Subject: [PATCH] Loading of moved refs complete. --- apps/opencs/model/world/data.cpp | 6 +++--- apps/opencs/model/world/refcollection.cpp | 19 ++++++++++++------- apps/opencs/model/world/refcollection.hpp | 2 +- components/esm/loadcell.cpp | 18 ------------------ 4 files changed, 16 insertions(+), 29 deletions(-) diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 91fa556ab..f4ae78ae7 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -3,7 +3,6 @@ #include #include -#include #include @@ -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; } diff --git a/apps/opencs/model/world/refcollection.cpp b/apps/opencs/model/world/refcollection.cpp index bd4cf918c..c94ec1dc4 100644 --- a/apps/opencs/model/world/refcollection.cpp +++ b/apps/opencs/model/world/refcollection.cpp @@ -2,6 +2,7 @@ #include "refcollection.hpp" #include +#include #include #include @@ -12,8 +13,10 @@ #include "record.hpp" void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool base, - std::map& cache, CSMDoc::Messages& messages) + std::map >& cache, const std::string& origCellId, + CSMDoc::Messages& messages) { + std::string cellid = origCellId; Record 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::iterator iter = cache.find (ref.mRefNum); + std::map::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 { diff --git a/apps/opencs/model/world/refcollection.hpp b/apps/opencs/model/world/refcollection.hpp index 46572752e..82ec2f390 100644 --- a/apps/opencs/model/world/refcollection.hpp +++ b/apps/opencs/model/world/refcollection.hpp @@ -27,7 +27,7 @@ namespace CSMWorld {} void load (ESM::ESMReader& reader, int cellIndex, bool base, - std::map& cache, + std::map >& cache, const std::string& cellid, CSMDoc::Messages& messages); ///< Load a sequence of references. diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index aed56f415..0f8897c48 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -3,7 +3,6 @@ #include #include #include -#include // FIXME: debugging only #include @@ -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);