mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:53:51 +00:00
modified GlobalScripts data structures to accommodate targeted script data
This commit is contained in:
parent
563c2e5730
commit
8241ee59c3
2 changed files with 40 additions and 31 deletions
|
@ -15,6 +15,9 @@
|
|||
|
||||
namespace MWScript
|
||||
{
|
||||
GlobalScriptDesc::GlobalScriptDesc() : mRunning (false) {}
|
||||
|
||||
|
||||
GlobalScripts::GlobalScripts (const MWWorld::ESMStore& store)
|
||||
: mStore (store)
|
||||
{
|
||||
|
@ -23,53 +26,53 @@ namespace MWScript
|
|||
|
||||
void GlobalScripts::addScript (const std::string& name)
|
||||
{
|
||||
std::map<std::string, std::pair<bool, Locals> >::iterator iter =
|
||||
std::map<std::string, GlobalScriptDesc>::iterator iter =
|
||||
mScripts.find (::Misc::StringUtils::lowerCase (name));
|
||||
|
||||
if (iter==mScripts.end())
|
||||
{
|
||||
if (const ESM::Script *script = mStore.get<ESM::Script>().find (name))
|
||||
{
|
||||
Locals locals;
|
||||
GlobalScriptDesc desc;
|
||||
desc.mRunning = true;
|
||||
desc.mLocals.configure (*script);
|
||||
|
||||
locals.configure (*script);
|
||||
|
||||
mScripts.insert (std::make_pair (name, std::make_pair (true, locals)));
|
||||
mScripts.insert (std::make_pair (name, desc));
|
||||
}
|
||||
}
|
||||
else
|
||||
iter->second.first = true;
|
||||
iter->second.mRunning = true;
|
||||
}
|
||||
|
||||
void GlobalScripts::removeScript (const std::string& name)
|
||||
{
|
||||
std::map<std::string, std::pair<bool, Locals> >::iterator iter =
|
||||
std::map<std::string, GlobalScriptDesc>::iterator iter =
|
||||
mScripts.find (::Misc::StringUtils::lowerCase (name));
|
||||
|
||||
if (iter!=mScripts.end())
|
||||
iter->second.first = false;
|
||||
iter->second.mRunning = false;
|
||||
}
|
||||
|
||||
bool GlobalScripts::isRunning (const std::string& name) const
|
||||
{
|
||||
std::map<std::string, std::pair<bool, Locals> >::const_iterator iter =
|
||||
std::map<std::string, GlobalScriptDesc>::const_iterator iter =
|
||||
mScripts.find (::Misc::StringUtils::lowerCase (name));
|
||||
|
||||
if (iter==mScripts.end())
|
||||
return false;
|
||||
|
||||
return iter->second.first;
|
||||
return iter->second.mRunning;
|
||||
}
|
||||
|
||||
void GlobalScripts::run()
|
||||
{
|
||||
for (std::map<std::string, std::pair<bool, Locals> >::iterator iter (mScripts.begin());
|
||||
for (std::map<std::string, GlobalScriptDesc>::iterator iter (mScripts.begin());
|
||||
iter!=mScripts.end(); ++iter)
|
||||
{
|
||||
if (iter->second.first)
|
||||
if (iter->second.mRunning)
|
||||
{
|
||||
MWScript::InterpreterContext interpreterContext (
|
||||
&iter->second.second, MWWorld::Ptr());
|
||||
&iter->second.mLocals, MWWorld::Ptr());
|
||||
MWBase::Environment::get().getScriptManager()->run (iter->first, interpreterContext);
|
||||
}
|
||||
}
|
||||
|
@ -99,16 +102,16 @@ namespace MWScript
|
|||
|
||||
void GlobalScripts::write (ESM::ESMWriter& writer, Loading::Listener& progress) const
|
||||
{
|
||||
for (std::map<std::string, std::pair<bool, Locals> >::const_iterator iter (mScripts.begin());
|
||||
for (std::map<std::string, GlobalScriptDesc>::const_iterator iter (mScripts.begin());
|
||||
iter!=mScripts.end(); ++iter)
|
||||
{
|
||||
ESM::GlobalScript script;
|
||||
|
||||
script.mId = iter->first;
|
||||
|
||||
iter->second.second.write (script.mLocals, iter->first);
|
||||
iter->second.mLocals.write (script.mLocals, iter->first);
|
||||
|
||||
script.mRunning = iter->second.first ? 1 : 0;
|
||||
script.mRunning = iter->second.mRunning ? 1 : 0;
|
||||
|
||||
writer.startRecord (ESM::REC_GSCR);
|
||||
script.save (writer);
|
||||
|
@ -124,25 +127,24 @@ namespace MWScript
|
|||
ESM::GlobalScript script;
|
||||
script.load (reader);
|
||||
|
||||
std::map<std::string, std::pair<bool, Locals> >::iterator iter =
|
||||
std::map<std::string, GlobalScriptDesc>::iterator iter =
|
||||
mScripts.find (script.mId);
|
||||
|
||||
if (iter==mScripts.end())
|
||||
{
|
||||
if (const ESM::Script *scriptRecord = mStore.get<ESM::Script>().search (script.mId))
|
||||
{
|
||||
std::pair<bool, Locals> data (false, Locals());
|
||||
GlobalScriptDesc desc;
|
||||
desc.mLocals.configure (*scriptRecord);
|
||||
|
||||
data.second.configure (*scriptRecord);
|
||||
|
||||
iter = mScripts.insert (std::make_pair (script.mId, data)).first;
|
||||
iter = mScripts.insert (std::make_pair (script.mId, desc)).first;
|
||||
}
|
||||
else // script does not exist anymore
|
||||
return true;
|
||||
}
|
||||
|
||||
iter->second.first = script.mRunning!=0;
|
||||
iter->second.second.read (script.mLocals, script.mId);
|
||||
iter->second.mRunning = script.mRunning!=0;
|
||||
iter->second.mLocals.read (script.mLocals, script.mId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -153,21 +155,19 @@ namespace MWScript
|
|||
Locals& GlobalScripts::getLocals (const std::string& name)
|
||||
{
|
||||
std::string name2 = ::Misc::StringUtils::lowerCase (name);
|
||||
std::map<std::string, std::pair<bool, Locals> >::iterator iter =
|
||||
mScripts.find (name2);
|
||||
std::map<std::string, GlobalScriptDesc>::iterator iter = mScripts.find (name2);
|
||||
|
||||
if (iter==mScripts.end())
|
||||
{
|
||||
if (const ESM::Script *script = mStore.get<ESM::Script>().find (name))
|
||||
{
|
||||
Locals locals;
|
||||
GlobalScriptDesc desc;
|
||||
desc.mLocals.configure (*script);
|
||||
|
||||
locals.configure (*script);
|
||||
|
||||
iter = mScripts.insert (std::make_pair (name, std::make_pair (false, locals))).first;
|
||||
iter = mScripts.insert (std::make_pair (name, desc)).first;
|
||||
}
|
||||
}
|
||||
|
||||
return iter->second.second;
|
||||
return iter->second.mLocals;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,10 +26,19 @@ namespace MWWorld
|
|||
|
||||
namespace MWScript
|
||||
{
|
||||
struct GlobalScriptDesc
|
||||
{
|
||||
bool mRunning;
|
||||
Locals mLocals;
|
||||
std::string mId; // ID used to start targeted script (empty if not a targeted script)
|
||||
|
||||
GlobalScriptDesc();
|
||||
};
|
||||
|
||||
class GlobalScripts
|
||||
{
|
||||
const MWWorld::ESMStore& mStore;
|
||||
std::map<std::string, std::pair<bool, Locals> > mScripts; // running, local variables
|
||||
std::map<std::string, GlobalScriptDesc> mScripts;
|
||||
|
||||
public:
|
||||
|
||||
|
|
Loading…
Reference in a new issue