mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-03 17:54:06 +00:00
keep track of which cells have state that needs to be saved
This commit is contained in:
parent
bfcd768078
commit
9b18e01507
@ -66,8 +66,11 @@ MWWorld::Ptr MWWorld::Cells::getPtrAndCache (const std::string& name, CellStore&
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void MWWorld::Cells::writeCell (ESM::ESMWriter& writer, const CellStore& cell) const
|
||||
void MWWorld::Cells::writeCell (ESM::ESMWriter& writer, CellStore& cell) const
|
||||
{
|
||||
if (cell.getState()!=CellStore::State_Loaded)
|
||||
cell.load (mStore, mReader);
|
||||
|
||||
ESM::CellState cellState;
|
||||
|
||||
cell.saveState (cellState);
|
||||
@ -79,17 +82,6 @@ void MWWorld::Cells::writeCell (ESM::ESMWriter& writer, const CellStore& cell) c
|
||||
writer.endRecord (ESM::REC_CSTA);
|
||||
}
|
||||
|
||||
bool MWWorld::Cells::hasState (const CellStore& cellStore) const
|
||||
{
|
||||
if (cellStore.getState()==CellStore::State_Loaded)
|
||||
return true;
|
||||
|
||||
if (cellStore.getCell()->mData.mFlags & ESM::Cell::Interior)
|
||||
return cellStore.getCell()->mData.mFlags & ESM::Cell::HasWater;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
MWWorld::Cells::Cells (const MWWorld::ESMStore& store, std::vector<ESM::ESMReader>& reader)
|
||||
: mStore (store), mReader (reader),
|
||||
mIdCache (40, std::pair<std::string, CellStore *> ("", (CellStore*)0)), /// \todo make cache size configurable
|
||||
@ -274,12 +266,12 @@ int MWWorld::Cells::countSavedGameRecords() const
|
||||
|
||||
for (std::map<std::string, CellStore>::const_iterator iter (mInteriors.begin());
|
||||
iter!=mInteriors.end(); ++iter)
|
||||
if (hasState (iter->second))
|
||||
if (iter->second.hasState())
|
||||
++count;
|
||||
|
||||
for (std::map<std::pair<int, int>, CellStore>::const_iterator iter (mExteriors.begin());
|
||||
iter!=mExteriors.end(); ++iter)
|
||||
if (hasState (iter->second))
|
||||
if (iter->second.hasState())
|
||||
++count;
|
||||
|
||||
return count;
|
||||
@ -287,14 +279,14 @@ int MWWorld::Cells::countSavedGameRecords() const
|
||||
|
||||
void MWWorld::Cells::write (ESM::ESMWriter& writer) const
|
||||
{
|
||||
for (std::map<std::pair<int, int>, CellStore>::const_iterator iter (mExteriors.begin());
|
||||
for (std::map<std::pair<int, int>, CellStore>::iterator iter (mExteriors.begin());
|
||||
iter!=mExteriors.end(); ++iter)
|
||||
if (hasState (iter->second))
|
||||
if (iter->second.hasState())
|
||||
writeCell (writer, iter->second);
|
||||
|
||||
for (std::map<std::string, CellStore>::const_iterator iter (mInteriors.begin());
|
||||
for (std::map<std::string, CellStore>::iterator iter (mInteriors.begin());
|
||||
iter!=mInteriors.end(); ++iter)
|
||||
if (hasState (iter->second))
|
||||
if (iter->second.hasState())
|
||||
writeCell (writer, iter->second);
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,8 @@ namespace MWWorld
|
||||
{
|
||||
const MWWorld::ESMStore& mStore;
|
||||
std::vector<ESM::ESMReader>& mReader;
|
||||
std::map<std::string, CellStore> mInteriors;
|
||||
std::map<std::pair<int, int>, CellStore> mExteriors;
|
||||
mutable std::map<std::string, CellStore> mInteriors;
|
||||
mutable std::map<std::pair<int, int>, CellStore> mExteriors;
|
||||
std::vector<std::pair<std::string, CellStore *> > mIdCache;
|
||||
std::size_t mIdCacheIndex;
|
||||
|
||||
@ -36,10 +36,7 @@ namespace MWWorld
|
||||
|
||||
Ptr getPtrAndCache (const std::string& name, CellStore& cellStore);
|
||||
|
||||
void writeCell (ESM::ESMWriter& writer, const CellStore& cell) const;
|
||||
|
||||
bool hasState (const CellStore& cellStore) const;
|
||||
///< Check if cell has state that needs to be included in a saved game file.
|
||||
void writeCell (ESM::ESMWriter& writer, CellStore& cell) const;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -141,7 +141,7 @@ namespace MWWorld
|
||||
}
|
||||
|
||||
CellStore::CellStore (const ESM::Cell *cell)
|
||||
: mCell (cell), mState (State_Unloaded)
|
||||
: mCell (cell), mState (State_Unloaded), mHasState (false)
|
||||
{
|
||||
mWaterLevel = cell->mWater;
|
||||
}
|
||||
@ -156,6 +156,11 @@ namespace MWWorld
|
||||
return mState;
|
||||
}
|
||||
|
||||
bool CellStore::hasState() const
|
||||
{
|
||||
return mHasState;
|
||||
}
|
||||
|
||||
bool CellStore::hasId (const std::string& id) const
|
||||
{
|
||||
if (mState==State_Unloaded)
|
||||
@ -170,6 +175,10 @@ namespace MWWorld
|
||||
|
||||
Ptr CellStore::search (const std::string& id)
|
||||
{
|
||||
bool oldState = mHasState;
|
||||
|
||||
mHasState = true;
|
||||
|
||||
if (LiveCellRef<ESM::Activator> *ref = mActivators.find (id))
|
||||
return Ptr (ref, this);
|
||||
|
||||
@ -230,11 +239,17 @@ namespace MWWorld
|
||||
if (LiveCellRef<ESM::Weapon> *ref = mWeapons.find (id))
|
||||
return Ptr (ref, this);
|
||||
|
||||
mHasState = oldState;
|
||||
|
||||
return Ptr();
|
||||
}
|
||||
|
||||
Ptr CellStore::searchViaHandle (const std::string& handle)
|
||||
{
|
||||
bool oldState = mHasState;
|
||||
|
||||
mHasState = true;
|
||||
|
||||
if (LiveCellRef<ESM::Activator> *ref = mActivators.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
@ -295,6 +310,8 @@ namespace MWWorld
|
||||
if (LiveCellRef<ESM::Weapon> *ref = mWeapons.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
mHasState = oldState;
|
||||
|
||||
return Ptr();
|
||||
}
|
||||
|
||||
@ -306,6 +323,7 @@ namespace MWWorld
|
||||
void CellStore::setWaterLevel (float level)
|
||||
{
|
||||
mWaterLevel = level;
|
||||
mHasState = true;
|
||||
}
|
||||
|
||||
int CellStore::count() const
|
||||
@ -437,6 +455,10 @@ namespace MWWorld
|
||||
|
||||
Ptr CellStore::searchInContainer (const std::string& id)
|
||||
{
|
||||
bool oldState = mHasState;
|
||||
|
||||
mHasState = true;
|
||||
|
||||
if (Ptr ptr = searchInContainerList (mContainers, id))
|
||||
return ptr;
|
||||
|
||||
@ -446,6 +468,8 @@ namespace MWWorld
|
||||
if (Ptr ptr = searchInContainerList (mNpcs, id))
|
||||
return ptr;
|
||||
|
||||
mHasState = oldState;
|
||||
|
||||
return Ptr();
|
||||
}
|
||||
|
||||
@ -486,6 +510,8 @@ namespace MWWorld
|
||||
|
||||
void CellStore::loadState (const ESM::CellState& state)
|
||||
{
|
||||
mHasState = true;
|
||||
|
||||
if (mCell->mData.mFlags & ESM::Cell::Interior && mCell->mData.mFlags & ESM::Cell::HasWater)
|
||||
mWaterLevel = state.mWaterLevel;
|
||||
|
||||
@ -529,6 +555,8 @@ namespace MWWorld
|
||||
void CellStore::readReferences (ESM::ESMReader& reader,
|
||||
const std::map<int, int>& contentFileMap)
|
||||
{
|
||||
mHasState = true;
|
||||
|
||||
while (reader.isNextSub ("OBJE"))
|
||||
{
|
||||
unsigned int id = 0;
|
||||
|
@ -31,6 +31,7 @@ namespace MWWorld
|
||||
|
||||
const ESM::Cell *mCell;
|
||||
State mState;
|
||||
bool mHasState;
|
||||
std::vector<std::string> mIds;
|
||||
float mWaterLevel;
|
||||
|
||||
@ -63,6 +64,9 @@ namespace MWWorld
|
||||
|
||||
State getState() const;
|
||||
|
||||
bool hasState() const;
|
||||
///< Does this cell have state that needs to be stored in a saved game file?
|
||||
|
||||
bool hasId (const std::string& id) const;
|
||||
///< May return true for deleted IDs when in preload state. Will return false, if cell is
|
||||
/// unloaded.
|
||||
@ -95,6 +99,8 @@ namespace MWWorld
|
||||
template<class Functor>
|
||||
bool forEach (Functor& functor)
|
||||
{
|
||||
mHasState = true;
|
||||
|
||||
return
|
||||
forEachImp (functor, mActivators) &&
|
||||
forEachImp (functor, mPotions) &&
|
||||
@ -165,120 +171,140 @@ namespace MWWorld
|
||||
template<>
|
||||
inline CellRefList<ESM::Activator>& CellStore::get<ESM::Activator>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mActivators;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Potion>& CellStore::get<ESM::Potion>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mPotions;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Apparatus>& CellStore::get<ESM::Apparatus>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mAppas;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Armor>& CellStore::get<ESM::Armor>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mArmors;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Book>& CellStore::get<ESM::Book>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mBooks;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Clothing>& CellStore::get<ESM::Clothing>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mClothes;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Container>& CellStore::get<ESM::Container>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mContainers;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Creature>& CellStore::get<ESM::Creature>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mCreatures;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Door>& CellStore::get<ESM::Door>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mDoors;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Ingredient>& CellStore::get<ESM::Ingredient>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mIngreds;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::CreatureLevList>& CellStore::get<ESM::CreatureLevList>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mCreatureLists;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::ItemLevList>& CellStore::get<ESM::ItemLevList>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mItemLists;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Light>& CellStore::get<ESM::Light>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mLights;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Lockpick>& CellStore::get<ESM::Lockpick>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mLockpicks;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Miscellaneous>& CellStore::get<ESM::Miscellaneous>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mMiscItems;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::NPC>& CellStore::get<ESM::NPC>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mNpcs;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Probe>& CellStore::get<ESM::Probe>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mProbes;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Repair>& CellStore::get<ESM::Repair>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mRepairs;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Static>& CellStore::get<ESM::Static>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mStatics;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Weapon>& CellStore::get<ESM::Weapon>()
|
||||
{
|
||||
mHasState = true;
|
||||
return mWeapons;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user