1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 18:35:20 +00:00

Pass the ESM reader list to CellStore constructor

This commit is contained in:
scrawl 2015-12-06 18:03:55 +01:00
parent 3dcefd17fc
commit 811df1e97b
3 changed files with 39 additions and 27 deletions

View File

@ -23,7 +23,7 @@ MWWorld::CellStore *MWWorld::Cells::getCellStore (const ESM::Cell *cell)
if (result==mInteriors.end())
{
result = mInteriors.insert (std::make_pair (lowerName, CellStore (cell))).first;
result = mInteriors.insert (std::make_pair (lowerName, CellStore (cell, mStore, mReader))).first;
}
return &result->second;
@ -36,7 +36,7 @@ MWWorld::CellStore *MWWorld::Cells::getCellStore (const ESM::Cell *cell)
if (result==mExteriors.end())
{
result = mExteriors.insert (std::make_pair (
std::make_pair (cell->getGridX(), cell->getGridY()), CellStore (cell))).first;
std::make_pair (cell->getGridX(), cell->getGridY()), CellStore (cell, mStore, mReader))).first;
}
@ -70,7 +70,7 @@ MWWorld::Ptr MWWorld::Cells::getPtrAndCache (const std::string& name, CellStore&
void MWWorld::Cells::writeCell (ESM::ESMWriter& writer, CellStore& cell) const
{
if (cell.getState()!=CellStore::State_Loaded)
cell.load (mStore, mReader);
cell.load ();
ESM::CellState cellState;
@ -114,13 +114,13 @@ MWWorld::CellStore *MWWorld::Cells::getExterior (int x, int y)
}
result = mExteriors.insert (std::make_pair (
std::make_pair (x, y), CellStore (cell))).first;
std::make_pair (x, y), CellStore (cell, mStore, mReader))).first;
}
if (result->second.getState()!=CellStore::State_Loaded)
{
// Multiple plugin support for landscape data is much easier than for references. The last plugin wins.
result->second.load (mStore, mReader);
result->second.load ();
}
return &result->second;
@ -135,12 +135,12 @@ MWWorld::CellStore *MWWorld::Cells::getInterior (const std::string& name)
{
const ESM::Cell *cell = mStore.get<ESM::Cell>().find(lowerName);
result = mInteriors.insert (std::make_pair (lowerName, CellStore (cell))).first;
result = mInteriors.insert (std::make_pair (lowerName, CellStore (cell, mStore, mReader))).first;
}
if (result->second.getState()!=CellStore::State_Loaded)
{
result->second.load (mStore, mReader);
result->second.load ();
}
return &result->second;
@ -158,13 +158,13 @@ MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name, CellStore& cell,
bool searchInContainers)
{
if (cell.getState()==CellStore::State_Unloaded)
cell.preload (mStore, mReader);
cell.preload ();
if (cell.getState()==CellStore::State_Preloaded)
{
if (cell.hasId (name))
{
cell.load (mStore, mReader);
cell.load ();
}
else
return Ptr();
@ -333,7 +333,7 @@ bool MWWorld::Cells::readRecord (ESM::ESMReader& reader, uint32_t type,
cellStore->readFog(reader);
if (cellStore->getState()!=CellStore::State_Loaded)
cellStore->load (mStore, mReader);
cellStore->load ();
cellStore->readReferences (reader, contentFileMap);

View File

@ -284,8 +284,8 @@ namespace MWWorld
functor.merge();
}
CellStore::CellStore (const ESM::Cell *cell)
: mCell (cell), mState (State_Unloaded), mHasState (false), mLastRespawn(0,0)
CellStore::CellStore (const ESM::Cell *cell, const MWWorld::ESMStore& esmStore, std::vector<ESM::ESMReader>& readerList)
: mStore(esmStore), mReader(readerList), mCell (cell), mState (State_Unloaded), mHasState (false), mLastRespawn(0,0)
{
mWaterLevel = cell->mWater;
}
@ -382,14 +382,14 @@ namespace MWWorld
return mMergedRefs.size();
}
void CellStore::load (const MWWorld::ESMStore &store, std::vector<ESM::ESMReader> &esm)
void CellStore::load ()
{
if (mState!=State_Loaded)
{
if (mState==State_Preloaded)
mIds.clear();
loadRefs (store, esm);
loadRefs ();
mState = State_Loaded;
@ -399,18 +399,20 @@ namespace MWWorld
}
}
void CellStore::preload (const MWWorld::ESMStore &store, std::vector<ESM::ESMReader> &esm)
void CellStore::preload ()
{
if (mState==State_Unloaded)
{
listRefs (store, esm);
listRefs ();
mState = State_Preloaded;
}
}
void CellStore::listRefs(const MWWorld::ESMStore &store, std::vector<ESM::ESMReader> &esm)
void CellStore::listRefs()
{
std::vector<ESM::ESMReader>& esm = mReader;
assert (mCell);
if (mCell->mContextList.empty())
@ -462,8 +464,10 @@ namespace MWWorld
std::sort (mIds.begin(), mIds.end());
}
void CellStore::loadRefs(const MWWorld::ESMStore &store, std::vector<ESM::ESMReader> &esm)
void CellStore::loadRefs()
{
std::vector<ESM::ESMReader>& esm = mReader;
assert (mCell);
if (mCell->mContextList.empty())
@ -490,7 +494,7 @@ namespace MWWorld
continue;
}
loadRef (ref, deleted, store);
loadRef (ref, deleted);
}
}
@ -499,7 +503,7 @@ namespace MWWorld
{
ESM::CellRef &ref = const_cast<ESM::CellRef&>(*it);
loadRef (ref, false, store);
loadRef (ref, false);
}
updateMergedRefs();
@ -530,10 +534,12 @@ namespace MWWorld
return Ptr();
}
void CellStore::loadRef (ESM::CellRef& ref, bool deleted, const ESMStore& store)
void CellStore::loadRef (ESM::CellRef& ref, bool deleted)
{
Misc::StringUtils::toLower (ref.mRefID);
const MWWorld::ESMStore& store = mStore;
switch (store.find (ref.mRefID))
{
case ESM::REC_ACTI: mActivators.load(ref, deleted, store); break;

View File

@ -60,6 +60,9 @@ namespace MWWorld
private:
const MWWorld::ESMStore& mStore;
std::vector<ESM::ESMReader>& mReader;
// Even though fog actually belongs to the player and not cells,
// it makes sense to store it here since we need it once for each cell.
// Note this is NULL until the cell is explored to save some memory
@ -177,7 +180,10 @@ namespace MWWorld
template <typename T>
LiveCellRefBase* insert(const LiveCellRef<T>* ref);
CellStore (const ESM::Cell *cell_);
/// @param readerList The readers to use for loading of the cell on-demand.
CellStore (const ESM::Cell *cell_,
const MWWorld::ESMStore& store,
std::vector<ESM::ESMReader>& readerList);
const ESM::Cell *getCell() const;
@ -210,10 +216,10 @@ namespace MWWorld
int count() const;
///< Return total number of references, including deleted ones.
void load (const MWWorld::ESMStore &store, std::vector<ESM::ESMReader> &esm);
void load ();
///< Load references from content file.
void preload (const MWWorld::ESMStore &store, std::vector<ESM::ESMReader> &esm);
void preload ();
///< Build ID list from content file.
/// Call functor (ref) for each reference. functor must return a bool. Returning
@ -267,11 +273,11 @@ namespace MWWorld
private:
/// Run through references and store IDs
void listRefs(const MWWorld::ESMStore &store, std::vector<ESM::ESMReader> &esm);
void listRefs();
void loadRefs(const MWWorld::ESMStore &store, std::vector<ESM::ESMReader> &esm);
void loadRefs();
void loadRef (ESM::CellRef& ref, bool deleted, const ESMStore& store);
void loadRef (ESM::CellRef& ref, bool deleted);
///< Make case-adjustments to \a ref and insert it into the respective container.
///
/// Invalid \a ref objects are silently dropped.