mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 05:56:38 +00:00 
			
		
		
		
	This should be much safer. Don't use recursion. Don't fail if mIgnore happens to be in the list twice. Don't rely on preconditions / assertions.
This commit is contained in:
		
							parent
							
								
									187d2bccda
								
							
						
					
					
						commit
						cc3563359e
					
				
					 3 changed files with 13 additions and 29 deletions
				
			
		|  | @ -69,11 +69,9 @@ void OMW::Engine::executeLocalScripts() | ||||||
|     MWWorld::LocalScripts& localScripts = mEnvironment.getWorld()->getLocalScripts(); |     MWWorld::LocalScripts& localScripts = mEnvironment.getWorld()->getLocalScripts(); | ||||||
| 
 | 
 | ||||||
|     localScripts.startIteration(); |     localScripts.startIteration(); | ||||||
| 
 |     std::pair<std::string, MWWorld::Ptr> script; | ||||||
|     while (!localScripts.isFinished()) |     while (localScripts.getNext(script)) | ||||||
|     { |     { | ||||||
|         std::pair<std::string, MWWorld::Ptr> script = localScripts.getNext(); |  | ||||||
| 
 |  | ||||||
|         MWScript::InterpreterContext interpreterContext ( |         MWScript::InterpreterContext interpreterContext ( | ||||||
|             &script.second.getRefData().getLocals(), script.second); |             &script.second.getRefData().getLocals(), script.second); | ||||||
|         mEnvironment.getScriptManager()->run (script.first, interpreterContext); |         mEnvironment.getScriptManager()->run (script.first, interpreterContext); | ||||||
|  |  | ||||||
|  | @ -76,30 +76,18 @@ void MWWorld::LocalScripts::startIteration() | ||||||
|     mIter = mScripts.begin(); |     mIter = mScripts.begin(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool MWWorld::LocalScripts::isFinished() const | bool MWWorld::LocalScripts::getNext(std::pair<std::string, Ptr>& script) | ||||||
| { | { | ||||||
|     if (mIter==mScripts.end()) |     while (mIter!=mScripts.end()) | ||||||
|         return true; |  | ||||||
| 
 |  | ||||||
|     if (!mIgnore.isEmpty() && mIter->second==mIgnore) |  | ||||||
|     { |     { | ||||||
|         std::list<std::pair<std::string, Ptr> >::iterator iter = mIter; |  | ||||||
|         return ++iter==mScripts.end(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return false; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| std::pair<std::string, MWWorld::Ptr> MWWorld::LocalScripts::getNext() |  | ||||||
| { |  | ||||||
|     assert (!isFinished()); |  | ||||||
| 
 |  | ||||||
|         std::list<std::pair<std::string, Ptr> >::iterator iter = mIter++; |         std::list<std::pair<std::string, Ptr> >::iterator iter = mIter++; | ||||||
| 
 |  | ||||||
|         if (mIgnore.isEmpty() || iter->second!=mIgnore) |         if (mIgnore.isEmpty() || iter->second!=mIgnore) | ||||||
|         return *iter; |         { | ||||||
| 
 |             script = *iter; | ||||||
|     return getNext(); |             return true; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     return false; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void MWWorld::LocalScripts::add (const std::string& scriptName, const Ptr& ptr) | void MWWorld::LocalScripts::add (const std::string& scriptName, const Ptr& ptr) | ||||||
|  |  | ||||||
|  | @ -31,11 +31,9 @@ namespace MWWorld | ||||||
|             void startIteration(); |             void startIteration(); | ||||||
|             ///< Set the iterator to the begin of the script list.
 |             ///< Set the iterator to the begin of the script list.
 | ||||||
| 
 | 
 | ||||||
|             bool isFinished() const; |             bool getNext(std::pair<std::string, Ptr>& script); | ||||||
|             ///< Is iteration finished?
 |             ///< Get next local script
 | ||||||
| 
 |             /// @return Did we get a script?
 | ||||||
|             std::pair<std::string, Ptr> getNext(); |  | ||||||
|             ///< Get next local script (must not be called if isFinished())
 |  | ||||||
| 
 | 
 | ||||||
|             void add (const std::string& scriptName, const Ptr& ptr); |             void add (const std::string& scriptName, const Ptr& ptr); | ||||||
|             ///< Add script to collection of active local scripts.
 |             ///< Add script to collection of active local scripts.
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue