From 049b0e66e0e63e5ac9c9ebdb837c371964ae856b Mon Sep 17 00:00:00 2001 From: Mark Siewert Date: Tue, 25 Dec 2012 20:27:30 +0100 Subject: [PATCH] - Restore ability to generate references in the same cell from multiple plugins - Disable some code related to deleting entries in the store so that it builds again --- apps/openmw/mwworld/cellstore.cpp | 2 -- apps/openmw/mwworld/esmstore.cpp | 2 ++ apps/openmw/mwworld/store.hpp | 48 +++++++++++++++---------------- components/esm/loadcell.cpp | 1 - 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index ff8368dd1..ba8f5aa61 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -83,8 +83,6 @@ namespace MWWorld // Load references from all plugins that do something with this cell. for (size_t i = 0; i < mCell->mContextList.size(); i++) { - if (mCell->mContextList.size() > 1) - std::cout << "number of lists " << mCell->mContextList.size() << std::endl; // Reopen the ESM reader and seek to the right position. int index = mCell->mContextList.at(i).index; mCell->restore (esm[index], i); diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index 564126797..b1b9b1534 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -87,12 +87,14 @@ void ESMStore::load(ESM::ESMReader &esm) // ... unless it got deleted! This means that the following record // has been deleted, and trying to load it using standard assumptions // on the structure will (probably) fail. + /* if (esm.isNextSub("DELE")) { esm.skipRecord(); all.erase(id); it->second->remove(id); continue; } + */ it->second->load(esm, id); if (n.val==ESM::REC_DIAL) { diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index d4d632eff..fd3e9c59c 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -371,15 +371,15 @@ namespace MWWorld } }; - std::vector mInt; - std::vector mExt; + typedef std::map DynamicInt; + typedef std::map, ESM::Cell> DynamicExt; + + DynamicInt mInt; + DynamicExt mExt; std::vector mSharedInt; std::vector mSharedExt; - typedef std::map DynamicInt; - typedef std::map, ESM::Cell> DynamicExt; - DynamicInt mDynamicInt; DynamicExt mDynamicExt; @@ -401,11 +401,10 @@ namespace MWWorld ESM::Cell cell; cell.mName = StringUtils::lowerCase(id); - std::vector::const_iterator it = - std::lower_bound(mInt.begin(), mInt.end(), cell, RecordCmp()); + std::map::const_iterator it = mInt.find(cell.mName); - if (it != mInt.end() && StringUtils::ciEqual(it->mName, id)) { - return &(*it); + if (it != mInt.end() && StringUtils::ciEqual(it->second.mName, id)) { + return &(it->second); } DynamicInt::const_iterator dit = mDynamicInt.find(cell.mName); @@ -420,14 +419,12 @@ namespace MWWorld ESM::Cell cell; cell.mData.mX = x, cell.mData.mY = y; - std::vector::const_iterator it = - std::lower_bound(mExt.begin(), mExt.end(), cell, ExtCmp()); - - if (it != mExt.end() && it->mData.mX == x && it->mData.mY == y) { - return &(*it); + std::pair key(x, y); + std::map, ESM::Cell>::const_iterator it = mExt.find(key); + if (it != mExt.end()) { + return &(it->second); } - std::pair key(x, y); DynamicExt::const_iterator dit = mDynamicExt.find(key); if (dit != mDynamicExt.end()) { return &dit->second; @@ -457,18 +454,20 @@ namespace MWWorld } void setUp() { - typedef std::vector::iterator Iterator; + //typedef std::vector::iterator Iterator; + typedef std::map, ESM::Cell>::iterator ExtIterator; + typedef std::map::iterator IntIterator; - std::sort(mInt.begin(), mInt.end(), RecordCmp()); + //std::sort(mInt.begin(), mInt.end(), RecordCmp()); mSharedInt.reserve(mInt.size()); - for (Iterator it = mInt.begin(); it != mInt.end(); ++it) { - mSharedInt.push_back(&(*it)); + for (IntIterator it = mInt.begin(); it != mInt.end(); ++it) { + mSharedInt.push_back(&(it->second)); } - std::sort(mExt.begin(), mExt.end(), ExtCmp()); + //std::sort(mExt.begin(), mExt.end(), ExtCmp()); mSharedExt.reserve(mExt.size()); - for (Iterator it = mExt.begin(); it != mExt.end(); ++it) { - mSharedExt.push_back(&(*it)); + for (ExtIterator it = mExt.begin(); it != mExt.end(); ++it) { + mSharedExt.push_back(&(it->second)); } } @@ -497,14 +496,13 @@ namespace MWWorld // have new cell replace old cell *oldcell = *cell; } else - mInt.push_back(*cell); + mInt[cell->mName] = *cell; delete cell; } else { // Store exterior cells by grid position, try to merge with existing parent data. ESM::Cell *oldcell = const_cast(search(cell->getGridX(), cell->getGridY())); - std::cout << "setup - " << oldcell << " " << cell->getGridX() << " " << cell->getGridY() << std::endl; if (oldcell) { // push the new references on the list of references to manage oldcell->mContextList.push_back(cell->mContextList.at(0)); @@ -513,7 +511,7 @@ namespace MWWorld // have new cell replace old cell *oldcell = *cell; } else - mExt.push_back(*cell); + mExt[std::make_pair(cell->mData.mX, cell->mData.mY)] = *cell; delete cell; } } diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index 0158af70a..b7f27b08d 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -201,7 +201,6 @@ bool Cell::getNextRef(ESMReader &esm, CellRef &ref) ref.mRefnum &= 0x00ffffff; // delete old plugin ID const ESM::ESMReader::MasterList &masters = esm.getMasters(); global = masters[local-1].index + 1; - std::cout << "moved ref: " << local << " " << global << std::endl; ref.mRefnum |= global << 24; // insert global plugin ID } else