forked from teamnwah/openmw-tes3coop
move record insertion to ESMStore
This commit is contained in:
parent
dccc157f4c
commit
9f1733a415
3 changed files with 35 additions and 76 deletions
|
@ -67,6 +67,8 @@ namespace MWWorld
|
|||
std::map<std::string, int> mIds;
|
||||
std::map<int, StoreBase *> mStores;
|
||||
|
||||
unsigned int mDynamicCount;
|
||||
|
||||
public:
|
||||
/// \todo replace with SharedIterator<StoreBase>
|
||||
typedef std::map<int, StoreBase *>::const_iterator iterator;
|
||||
|
@ -90,6 +92,7 @@ namespace MWWorld
|
|||
}
|
||||
|
||||
ESMStore()
|
||||
: mDynamicCount(0)
|
||||
{
|
||||
mStores[ESM::REC_ACTI] = &mActivators;
|
||||
mStores[ESM::REC_ALCH] = &mPotions;
|
||||
|
@ -142,8 +145,32 @@ namespace MWWorld
|
|||
const Store<T> &get() const {
|
||||
throw std::runtime_error("Storage for this type not exist");
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T *insert(const T &x) {
|
||||
Store<T> &store = const_cast<Store<T> &>(get<T>());
|
||||
T record = x;
|
||||
|
||||
std::ostringstream id;
|
||||
id << "$dynamic" << mDynamicCount++;
|
||||
record.mId = id.str();
|
||||
|
||||
T *ptr = store.insert(record);
|
||||
for (iterator it = mStores.begin(); it != mStores.end(); ++it) {
|
||||
if (it->second == &store) {
|
||||
mIds[ptr->mId] = it->first;
|
||||
}
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <>
|
||||
inline ESM::Cell *ESMStore::insert<ESM::Cell>(const ESM::Cell &cell) {
|
||||
return mCells.insert(cell);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline const Store<ESM::Activator> &ESMStore::get<ESM::Activator>() const {
|
||||
return mActivators;
|
||||
|
|
|
@ -170,7 +170,7 @@ namespace MWWorld
|
|||
const std::string& master, const boost::filesystem::path& resDir, const boost::filesystem::path& cacheDir, bool newGame,
|
||||
const std::string& encoding, std::map<std::string,std::string> fallbackMap)
|
||||
: mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0),
|
||||
mSky (true), mNextDynamicRecord (0), mCells (mStore, mEsm),
|
||||
mSky (true), mCells (mStore, mEsm),
|
||||
mNumFacing(0)
|
||||
{
|
||||
mPhysics = new PhysicsSystem(renderer);
|
||||
|
@ -779,92 +779,25 @@ namespace MWWorld
|
|||
|
||||
std::pair<std::string, const ESM::Potion *> World::createRecord (const ESM::Potion& record)
|
||||
{
|
||||
/*
|
||||
/// \todo Rewrite the ESMStore so that a dynamic 2nd ESMStore can be attached to it.
|
||||
/// This function should then insert the record into the 2nd store (the code for this
|
||||
/// should also be moved to the ESMStore class). It might be a good idea to review
|
||||
/// the STL-container usage of the ESMStore before the rewrite.
|
||||
|
||||
std::ostringstream stream;
|
||||
stream << "$dynamic" << mNextDynamicRecord++;
|
||||
|
||||
ESM::Potion record2 (record);
|
||||
record2.mId = stream.str();
|
||||
|
||||
const ESM::Potion *created =
|
||||
&mStore.potions.list.insert (std::make_pair (stream.str(), record2)).first->second;
|
||||
|
||||
mStore.all.insert (std::make_pair (stream.str(), ESM::REC_ALCH));
|
||||
|
||||
return std::make_pair (stream.str(), created);
|
||||
*/
|
||||
std::string id = "";
|
||||
const ESM::Potion *ptr = 0;
|
||||
return std::make_pair(id, ptr);
|
||||
const ESM::Potion *ptr = mStore.insert(record);
|
||||
return std::make_pair(ptr->mId, ptr);
|
||||
}
|
||||
|
||||
std::pair<std::string, const ESM::Class *> World::createRecord (const ESM::Class& record)
|
||||
{
|
||||
/*
|
||||
/// \todo See function above.
|
||||
std::ostringstream stream;
|
||||
stream << "$dynamic" << mNextDynamicRecord++;
|
||||
|
||||
const ESM::Class *created =
|
||||
&mStore.classes.list.insert (std::make_pair (stream.str(), record)).first->second;
|
||||
|
||||
mStore.all.insert (std::make_pair (stream.str(), ESM::REC_CLAS));
|
||||
|
||||
return std::make_pair (stream.str(), created);
|
||||
*/
|
||||
std::string id = "";
|
||||
const ESM::Class *ptr = 0;
|
||||
return std::make_pair(id, ptr);
|
||||
const ESM::Class *ptr = mStore.insert(record);
|
||||
return std::make_pair(ptr->mId, ptr);
|
||||
}
|
||||
|
||||
std::pair<std::string, const ESM::Spell *> World::createRecord (const ESM::Spell& record)
|
||||
{
|
||||
/*
|
||||
/// \todo See function above.
|
||||
std::ostringstream stream;
|
||||
stream << "$dynamic" << mNextDynamicRecord++;
|
||||
|
||||
const ESM::Spell *created =
|
||||
&mStore.spells.list.insert (std::make_pair (stream.str(), record)).first->second;
|
||||
|
||||
mStore.all.insert (std::make_pair (stream.str(), ESM::REC_SPEL));
|
||||
|
||||
return std::make_pair (stream.str(), created);
|
||||
*/
|
||||
std::string id = "";
|
||||
const ESM::Spell *ptr = 0;
|
||||
return std::make_pair(id, ptr);
|
||||
const ESM::Spell *ptr = mStore.insert(record);
|
||||
return std::make_pair(ptr->mId, ptr);
|
||||
}
|
||||
|
||||
const ESM::Cell *World::createRecord (const ESM::Cell& record)
|
||||
{
|
||||
/*
|
||||
if (record.mData.mFlags & ESM::Cell::Interior)
|
||||
{
|
||||
if (mStore.cells.searchInt (record.mName))
|
||||
throw std::runtime_error ("failed creating interior cell");
|
||||
|
||||
ESM::Cell *cell = new ESM::Cell (record);
|
||||
mStore.cells.intCells.insert (std::make_pair (record.mName, cell));
|
||||
return cell;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mStore.cells.searchExt (record.mData.mX, record.mData.mY))
|
||||
throw std::runtime_error ("failed creating exterior cell");
|
||||
|
||||
ESM::Cell *cell = new ESM::Cell (record);
|
||||
mStore.cells.extCells.insert (
|
||||
std::make_pair (std::make_pair (record.mData.mX, record.mData.mY), cell));
|
||||
return cell;
|
||||
}
|
||||
*/
|
||||
return 0;
|
||||
return mStore.insert(record);
|
||||
}
|
||||
|
||||
void World::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode,
|
||||
|
|
|
@ -60,7 +60,6 @@ namespace MWWorld
|
|||
MWWorld::Globals *mGlobalVariables;
|
||||
MWWorld::PhysicsSystem *mPhysics;
|
||||
bool mSky;
|
||||
int mNextDynamicRecord;
|
||||
|
||||
Cells mCells;
|
||||
|
||||
|
|
Loading…
Reference in a new issue