mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 07:56:38 +00:00 
			
		
		
		
	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<std::string, int> mIds; | ||||||
|         std::map<int, StoreBase *> mStores; |         std::map<int, StoreBase *> mStores; | ||||||
| 
 | 
 | ||||||
|  |         unsigned int mDynamicCount; | ||||||
|  | 
 | ||||||
|     public: |     public: | ||||||
|         /// \todo replace with SharedIterator<StoreBase>
 |         /// \todo replace with SharedIterator<StoreBase>
 | ||||||
|         typedef std::map<int, StoreBase *>::const_iterator iterator; |         typedef std::map<int, StoreBase *>::const_iterator iterator; | ||||||
|  | @ -90,6 +92,7 @@ namespace MWWorld | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         ESMStore() |         ESMStore() | ||||||
|  |           : mDynamicCount(0) | ||||||
|         { |         { | ||||||
|             mStores[ESM::REC_ACTI] = &mActivators; |             mStores[ESM::REC_ACTI] = &mActivators; | ||||||
|             mStores[ESM::REC_ALCH] = &mPotions; |             mStores[ESM::REC_ALCH] = &mPotions; | ||||||
|  | @ -142,8 +145,32 @@ namespace MWWorld | ||||||
|         const Store<T> &get() const { |         const Store<T> &get() const { | ||||||
|             throw std::runtime_error("Storage for this type not exist"); |             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 <> |     template <> | ||||||
|     inline const Store<ESM::Activator> &ESMStore::get<ESM::Activator>() const { |     inline const Store<ESM::Activator> &ESMStore::get<ESM::Activator>() const { | ||||||
|         return mActivators; |         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& master, const boost::filesystem::path& resDir, const boost::filesystem::path& cacheDir, bool newGame, | ||||||
|         const std::string& encoding, std::map<std::string,std::string> fallbackMap) |         const std::string& encoding, std::map<std::string,std::string> fallbackMap) | ||||||
|     : mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), |     : mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), | ||||||
|       mSky (true), mNextDynamicRecord (0), mCells (mStore, mEsm), |       mSky (true), mCells (mStore, mEsm), | ||||||
|       mNumFacing(0) |       mNumFacing(0) | ||||||
|     { |     { | ||||||
|         mPhysics = new PhysicsSystem(renderer); |         mPhysics = new PhysicsSystem(renderer); | ||||||
|  | @ -779,92 +779,25 @@ namespace MWWorld | ||||||
| 
 | 
 | ||||||
|     std::pair<std::string, const ESM::Potion *> World::createRecord (const ESM::Potion& record) |     std::pair<std::string, const ESM::Potion *> World::createRecord (const ESM::Potion& record) | ||||||
|     { |     { | ||||||
|     /*
 |         const ESM::Potion *ptr = mStore.insert(record); | ||||||
|         /// \todo Rewrite the ESMStore so that a dynamic 2nd ESMStore can be attached to it.
 |         return std::make_pair(ptr->mId, ptr); | ||||||
|         /// 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); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     std::pair<std::string, const ESM::Class *> World::createRecord (const ESM::Class& record) |     std::pair<std::string, const ESM::Class *> World::createRecord (const ESM::Class& record) | ||||||
|     { |     { | ||||||
|     /*
 |         const ESM::Class *ptr = mStore.insert(record); | ||||||
|         /// \todo See function above.
 |         return std::make_pair(ptr->mId, ptr); | ||||||
|         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); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     std::pair<std::string, const ESM::Spell *> World::createRecord (const ESM::Spell& record) |     std::pair<std::string, const ESM::Spell *> World::createRecord (const ESM::Spell& record) | ||||||
|     { |     { | ||||||
|     /*
 |         const ESM::Spell *ptr = mStore.insert(record); | ||||||
|         /// \todo See function above.
 |         return std::make_pair(ptr->mId, ptr); | ||||||
|         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::Cell *World::createRecord (const ESM::Cell& record) |     const ESM::Cell *World::createRecord (const ESM::Cell& record) | ||||||
|     { |     { | ||||||
|     /*
 |         return mStore.insert(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; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     void World::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode, |     void World::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode, | ||||||
|  |  | ||||||
|  | @ -60,7 +60,6 @@ namespace MWWorld | ||||||
|             MWWorld::Globals *mGlobalVariables; |             MWWorld::Globals *mGlobalVariables; | ||||||
|             MWWorld::PhysicsSystem *mPhysics; |             MWWorld::PhysicsSystem *mPhysics; | ||||||
|             bool mSky; |             bool mSky; | ||||||
|             int mNextDynamicRecord; |  | ||||||
| 
 | 
 | ||||||
|             Cells mCells; |             Cells mCells; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue