mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Merge remote-tracking branch 'scrawl/localscripts'
This commit is contained in:
commit
11a4a31bfd
@ -69,11 +69,9 @@ void OMW::Engine::executeLocalScripts()
|
||||
MWWorld::LocalScripts& localScripts = mEnvironment.getWorld()->getLocalScripts();
|
||||
|
||||
localScripts.startIteration();
|
||||
|
||||
while (!localScripts.isFinished())
|
||||
std::pair<std::string, MWWorld::Ptr> script;
|
||||
while (localScripts.getNext(script))
|
||||
{
|
||||
std::pair<std::string, MWWorld::Ptr> script = localScripts.getNext();
|
||||
|
||||
MWScript::InterpreterContext interpreterContext (
|
||||
&script.second.getRefData().getLocals(), script.second);
|
||||
mEnvironment.getScriptManager()->run (script.first, interpreterContext);
|
||||
|
@ -76,32 +76,20 @@ void MWWorld::LocalScripts::startIteration()
|
||||
mIter = mScripts.begin();
|
||||
}
|
||||
|
||||
bool MWWorld::LocalScripts::isFinished() const
|
||||
bool MWWorld::LocalScripts::getNext(std::pair<std::string, Ptr>& script)
|
||||
{
|
||||
if (mIter==mScripts.end())
|
||||
return true;
|
||||
|
||||
if (!mIgnore.isEmpty() && mIter->second==mIgnore)
|
||||
while (mIter!=mScripts.end())
|
||||
{
|
||||
std::list<std::pair<std::string, Ptr> >::iterator iter = mIter;
|
||||
return ++iter==mScripts.end();
|
||||
std::list<std::pair<std::string, Ptr> >::iterator iter = mIter++;
|
||||
if (mIgnore.isEmpty() || iter->second!=mIgnore)
|
||||
{
|
||||
script = *iter;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::pair<std::string, MWWorld::Ptr> MWWorld::LocalScripts::getNext()
|
||||
{
|
||||
assert (!isFinished());
|
||||
|
||||
std::list<std::pair<std::string, Ptr> >::iterator iter = mIter++;
|
||||
|
||||
if (mIgnore.isEmpty() || iter->second!=mIgnore)
|
||||
return *iter;
|
||||
|
||||
return getNext();
|
||||
}
|
||||
|
||||
void MWWorld::LocalScripts::add (const std::string& scriptName, const Ptr& ptr)
|
||||
{
|
||||
if (const ESM::Script *script = mStore.get<ESM::Script>().search (scriptName))
|
||||
@ -110,6 +98,14 @@ void MWWorld::LocalScripts::add (const std::string& scriptName, const Ptr& ptr)
|
||||
{
|
||||
ptr.getRefData().setLocals (*script);
|
||||
|
||||
for (std::list<std::pair<std::string, Ptr> >::iterator iter = mScripts.begin(); iter!=mScripts.end(); ++iter)
|
||||
if (iter->second==ptr)
|
||||
{
|
||||
std::cout << "warning, tried to add local script twice for " << ptr.getCellRef().getRefId() << std::endl;
|
||||
remove(ptr);
|
||||
break;
|
||||
}
|
||||
|
||||
mScripts.push_back (std::make_pair (scriptName, ptr));
|
||||
}
|
||||
catch (const std::exception& exception)
|
||||
|
@ -31,11 +31,9 @@ namespace MWWorld
|
||||
void startIteration();
|
||||
///< Set the iterator to the begin of the script list.
|
||||
|
||||
bool isFinished() const;
|
||||
///< Is iteration finished?
|
||||
|
||||
std::pair<std::string, Ptr> getNext();
|
||||
///< Get next local script (must not be called if isFinished())
|
||||
bool getNext(std::pair<std::string, Ptr>& script);
|
||||
///< Get next local script
|
||||
/// @return Did we get a script?
|
||||
|
||||
void add (const std::string& scriptName, const Ptr& ptr);
|
||||
///< Add script to collection of active local scripts.
|
||||
|
Loading…
x
Reference in New Issue
Block a user