changed implementation functions for container serialisation from free functions to member functions (will need some polymorphism later)

actorid
Marc Zinnschlag 11 years ago
parent dd674566a2
commit bcc5894e2d

@ -57,42 +57,43 @@ namespace
return MWWorld::Ptr(); return MWWorld::Ptr();
} }
}
template<typename T> template<typename T>
void getState (MWWorld::CellRefList<T>& collection, const ESM::ObjectState& state) void MWWorld::ContainerStore::getState (CellRefList<T>& collection, const ESM::ObjectState& state)
{ {
if (!MWWorld::LiveCellRef<T>::checkState (state)) if (!LiveCellRef<T>::checkState (state))
return; // not valid anymore with current content files -> skip return; // not valid anymore with current content files -> skip
const T *record = MWBase::Environment::get().getWorld()->getStore(). const T *record = MWBase::Environment::get().getWorld()->getStore().
get<T>().search (state.mRef.mRefID); get<T>().search (state.mRef.mRefID);
if (!record) if (!record)
return; return;
MWWorld::LiveCellRef<T> ref (record); LiveCellRef<T> ref (record);
ref.load (state); ref.load (state);
ref.mRef.mRefNum.mContentFile = -1; ref.mRef.mRefNum.mContentFile = -1;
collection.mList.push_back (ref); collection.mList.push_back (ref);
} }
template<typename T> template<typename T>
void storeState (const MWWorld::LiveCellRef<T>& ref, ESM::ObjectState& state) void MWWorld::ContainerStore::storeState (const LiveCellRef<T>& ref, ESM::ObjectState& state)
{ const
ref.save (state); {
} ref.save (state);
}
template<typename T> template<typename T>
void storeStates (const MWWorld::CellRefList<T>& collection, void MWWorld::ContainerStore::storeStates (const CellRefList<T>& collection,
std::vector<std::pair<ESM::ObjectState, std::pair<unsigned int, int> > >& states) std::vector<std::pair<ESM::ObjectState, std::pair<unsigned int, int> > >& states) const
{
for (typename CellRefList<T>::List::const_iterator iter (collection.mList.begin());
iter!=collection.mList.end(); ++iter)
{ {
for (typename MWWorld::CellRefList<T>::List::const_iterator iter (collection.mList.begin()); ESM::ObjectState state;
iter!=collection.mList.end(); ++iter) storeState (*iter, state);
{ states.push_back (std::make_pair (state, std::make_pair (T::sRecordId, -1)));
ESM::ObjectState state;
storeState (*iter, state);
states.push_back (std::make_pair (state, std::make_pair (T::sRecordId, -1)));
}
} }
} }

@ -57,6 +57,17 @@ namespace MWWorld
ContainerStoreIterator addImp (const Ptr& ptr, int count); ContainerStoreIterator addImp (const Ptr& ptr, int count);
void addInitialItem (const std::string& id, const std::string& owner, const std::string& faction, int count, bool topLevel=true); void addInitialItem (const std::string& id, const std::string& owner, const std::string& faction, int count, bool topLevel=true);
template<typename T>
void getState (CellRefList<T>& collection, const ESM::ObjectState& state);
template<typename T>
void storeState (const LiveCellRef<T>& ref, ESM::ObjectState& state) const;
template<typename T>
void storeStates (const CellRefList<T>& collection,
std::vector<std::pair<ESM::ObjectState, std::pair<unsigned int, int> > >& states)
const;
public: public:
ContainerStore(); ContainerStore();

Loading…
Cancel
Save