mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 17:26:38 +00:00 
			
		
		
		
	Issue #19: More local script related cleanup
This commit is contained in:
		
							parent
							
								
									896b7da23d
								
							
						
					
					
						commit
						8bebae17aa
					
				
					 6 changed files with 61 additions and 28 deletions
				
			
		|  | @ -70,7 +70,7 @@ void OMW::Engine::executeLocalScripts() | |||
|             break; | ||||
|     } | ||||
| 
 | ||||
|     mEnvironment.mWorld->getLocalScripts().setIgnore (MWWorld::Ptr()); | ||||
|     localScripts.setIgnore (MWWorld::Ptr()); | ||||
| } | ||||
| 
 | ||||
| bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) | ||||
|  |  | |||
|  | @ -1,6 +1,26 @@ | |||
| 
 | ||||
| #include "localscripts.hpp" | ||||
| 
 | ||||
| namespace | ||||
| { | ||||
|     template<typename T> | ||||
|     void listCellScripts (MWWorld::LocalScripts& localScripts, | ||||
|         ESMS::CellRefList<T, MWWorld::RefData>& cellRefList,  MWWorld::Ptr::CellStore *cell) | ||||
|     { | ||||
|         for (typename ESMS::CellRefList<T, MWWorld::RefData>::List::iterator iter ( | ||||
|             cellRefList.list.begin()); | ||||
|             iter!=cellRefList.list.end(); ++iter) | ||||
|         { | ||||
|             if (!iter->base->script.empty() && iter->mData.getCount()) | ||||
|             { | ||||
|                 localScripts.add (iter->base->script, MWWorld::Ptr (&*iter, cell)); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| MWWorld::LocalScripts::LocalScripts (const ESMS::ESMStore& store) : mStore (store) {} | ||||
| 
 | ||||
| void MWWorld::LocalScripts::setIgnore (const Ptr& ptr) | ||||
| { | ||||
|     mIgnore = ptr; | ||||
|  | @ -39,7 +59,33 @@ std::pair<std::string, MWWorld::Ptr> MWWorld::LocalScripts::getNext() | |||
| 
 | ||||
| void MWWorld::LocalScripts::add (const std::string& scriptName, const Ptr& ptr) | ||||
| { | ||||
|     mScripts.push_back (std::make_pair (scriptName, ptr)); | ||||
|     if (const ESM::Script *script = mStore.scripts.find (scriptName)) | ||||
|     { | ||||
|         ptr.getRefData().setLocals (*script); | ||||
| 
 | ||||
|         mScripts.push_back (std::make_pair (scriptName, ptr)); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void MWWorld::LocalScripts::addCell (Ptr::CellStore *cell) | ||||
| { | ||||
|     listCellScripts (*this, cell->activators, cell); | ||||
|     listCellScripts (*this, cell->potions, cell); | ||||
|     listCellScripts (*this, cell->appas, cell); | ||||
|     listCellScripts (*this, cell->armors, cell); | ||||
|     listCellScripts (*this, cell->books, cell); | ||||
|     listCellScripts (*this, cell->clothes, cell); | ||||
|     listCellScripts (*this, cell->containers, cell); | ||||
|     listCellScripts (*this, cell->creatures, cell); | ||||
|     listCellScripts (*this, cell->doors, cell); | ||||
|     listCellScripts (*this, cell->ingreds, cell); | ||||
|     listCellScripts (*this, cell->lights, cell); | ||||
|     listCellScripts (*this, cell->lockpicks, cell); | ||||
|     listCellScripts (*this, cell->miscItems, cell); | ||||
|     listCellScripts (*this, cell->npcs, cell); | ||||
|     listCellScripts (*this, cell->probes, cell); | ||||
|     listCellScripts (*this, cell->repairs, cell); | ||||
|     listCellScripts (*this, cell->weapons, cell); | ||||
| } | ||||
| 
 | ||||
| void MWWorld::LocalScripts::clear() | ||||
|  |  | |||
|  | @ -6,6 +6,11 @@ | |||
| 
 | ||||
| #include "ptr.hpp" | ||||
| 
 | ||||
| namespace ESMS | ||||
| { | ||||
|     struct ESMStore; | ||||
| } | ||||
| 
 | ||||
| namespace MWWorld | ||||
| { | ||||
|     /// \brief List of active local scripts
 | ||||
|  | @ -14,9 +19,12 @@ namespace MWWorld | |||
|             std::list<std::pair<std::string, Ptr> > mScripts; | ||||
|             std::list<std::pair<std::string, Ptr> >::iterator mIter; | ||||
|             MWWorld::Ptr mIgnore; | ||||
|             const ESMS::ESMStore& mStore; | ||||
| 
 | ||||
|         public: | ||||
| 
 | ||||
|             LocalScripts (const ESMS::ESMStore& store); | ||||
| 
 | ||||
|             void setIgnore (const Ptr& ptr); | ||||
|             ///< Mark a single reference for ignoring during iteration over local scripts (will revoke
 | ||||
|             /// previous ignores).
 | ||||
|  | @ -33,6 +41,9 @@ namespace MWWorld | |||
|             void add (const std::string& scriptName, const Ptr& ptr); | ||||
|             ///< Add script to collection of active local scripts.
 | ||||
| 
 | ||||
|             void addCell (Ptr::CellStore *cell); | ||||
|             ///< Add all local scripts in a cell.
 | ||||
| 
 | ||||
|             void clear(); | ||||
|             ///< Clear active local scripts collection.
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -68,7 +68,7 @@ namespace MWWorld | |||
|     void Scene::loadCell (Ptr::CellStore *cell, MWRender::CellRender *render) | ||||
|     { | ||||
|         // register local scripts
 | ||||
|         mWorld->insertInteriorScripts (*cell); | ||||
|         mWorld->getLocalScripts().addCell (cell); | ||||
| 
 | ||||
|         // This connects the cell data with the rendering scene.
 | ||||
|         std::pair<CellRenderCollection::iterator, bool> result = | ||||
|  |  | |||
|  | @ -66,28 +66,6 @@ namespace | |||
| 
 | ||||
| namespace MWWorld | ||||
| { | ||||
| 
 | ||||
|     void World::insertInteriorScripts (ESMS::CellStore<RefData>& cell) | ||||
|     { | ||||
|         listCellScripts (mStore, cell.activators, mLocalScripts, &cell); | ||||
|         listCellScripts (mStore, cell.potions, mLocalScripts, &cell); | ||||
|         listCellScripts (mStore, cell.appas, mLocalScripts, &cell); | ||||
|         listCellScripts (mStore, cell.armors, mLocalScripts, &cell); | ||||
|         listCellScripts (mStore, cell.books, mLocalScripts, &cell); | ||||
|         listCellScripts (mStore, cell.clothes, mLocalScripts, &cell); | ||||
|         listCellScripts (mStore, cell.containers, mLocalScripts, &cell); | ||||
|         listCellScripts (mStore, cell.creatures, mLocalScripts, &cell); | ||||
|         listCellScripts (mStore, cell.doors, mLocalScripts, &cell); | ||||
|         listCellScripts (mStore, cell.ingreds, mLocalScripts, &cell); | ||||
|         listCellScripts (mStore, cell.lights, mLocalScripts, &cell); | ||||
|         listCellScripts (mStore, cell.lockpicks, mLocalScripts, &cell); | ||||
|         listCellScripts (mStore, cell.miscItems, mLocalScripts, &cell); | ||||
|         listCellScripts (mStore, cell.npcs, mLocalScripts, &cell); | ||||
|         listCellScripts (mStore, cell.probes, mLocalScripts, &cell); | ||||
|         listCellScripts (mStore, cell.repairs, mLocalScripts, &cell); | ||||
|         listCellScripts (mStore, cell.weapons, mLocalScripts, &cell); | ||||
|     } | ||||
| 
 | ||||
|     Ptr World::getPtrViaHandle (const std::string& handle, Ptr::CellStore& cell) | ||||
|     { | ||||
|         if (ESMS::LiveCellRef<ESM::Activator, RefData> *ref = | ||||
|  | @ -198,7 +176,7 @@ namespace MWWorld | |||
|         const Files::Collections& fileCollections, | ||||
|         const std::string& master, const boost::filesystem::path& resDir, | ||||
|         bool newGame, Environment& environment, const std::string& encoding) | ||||
|     : mScene (renderer,physEng), mPlayer (0), mGlobalVariables (0), | ||||
|     : mScene (renderer,physEng), mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), | ||||
|       mSky (false), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this) | ||||
|     { | ||||
|         mPhysEngine = physEng; | ||||
|  |  | |||
|  | @ -107,8 +107,6 @@ namespace MWWorld | |||
| 
 | ||||
|             Ptr::CellStore *getInterior (const std::string& name); | ||||
| 
 | ||||
|             void insertInteriorScripts (ESMS::CellStore<RefData>& cell); | ||||
| 
 | ||||
|             void adjustSky(); | ||||
| 
 | ||||
|             MWWorld::Player& getPlayer(); | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue