mirror of https://github.com/OpenMW/openmw.git
implemented global script execution
parent
530caac39b
commit
4482884eb5
@ -0,0 +1,41 @@
|
||||
|
||||
#include "globalscripts.hpp"
|
||||
#include "interpretercontext.hpp"
|
||||
#include "scriptmanager.hpp"
|
||||
|
||||
namespace MWScript
|
||||
{
|
||||
GlobalScripts::GlobalScripts (const ESMS::ESMStore& store, ScriptManager& scriptManager)
|
||||
: mStore (store), mScriptManager (scriptManager)
|
||||
{
|
||||
addScript ("Main");
|
||||
}
|
||||
|
||||
void GlobalScripts::addScript (const std::string& name)
|
||||
{
|
||||
if (mScripts.find (name)==mScripts.end())
|
||||
if (const ESM::Script *script = mStore.scripts.find (name))
|
||||
{
|
||||
Locals locals;
|
||||
|
||||
locals.configure (*script);
|
||||
|
||||
mScripts.insert (std::make_pair (name, locals));
|
||||
}
|
||||
}
|
||||
|
||||
void GlobalScripts::run (MWWorld::Environment& environment)
|
||||
{
|
||||
std::map<std::string, Locals>::iterator iter = mScripts.begin();
|
||||
|
||||
while (iter!=mScripts.end())
|
||||
{
|
||||
MWScript::InterpreterContext interpreterContext (environment,
|
||||
&iter->second, MWWorld::Ptr());
|
||||
mScriptManager.run (iter->first, interpreterContext);
|
||||
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
#ifndef GAME_SCRIPT_GLOBALSCRIPTS_H
|
||||
#define GAME_SCRIPT_GLOBALSCRIPTS_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "locals.hpp"
|
||||
|
||||
namespace ESMS
|
||||
{
|
||||
struct ESMStore;
|
||||
}
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class Environment;
|
||||
}
|
||||
|
||||
namespace MWScript
|
||||
{
|
||||
class ScriptManager;
|
||||
|
||||
class GlobalScripts
|
||||
{
|
||||
const ESMS::ESMStore& mStore;
|
||||
ScriptManager& mScriptManager;
|
||||
std::map<std::string, Locals> mScripts;
|
||||
|
||||
public:
|
||||
|
||||
GlobalScripts (const ESMS::ESMStore& store, ScriptManager& scriptManager);
|
||||
|
||||
void addScript (const std::string& name);
|
||||
|
||||
void run (MWWorld::Environment& environment);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -0,0 +1,24 @@
|
||||
#ifndef GAME_WORLD_INVIRONMENT_H
|
||||
#define GAME_WORLD_INVIRONMENT_H
|
||||
|
||||
namespace MWSound
|
||||
{
|
||||
class SoundManager;
|
||||
}
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class World;
|
||||
|
||||
///< Collection of script-accessable sub-systems
|
||||
struct Environment
|
||||
{
|
||||
Environment() : mWorld (0), mSoundManager (0) {}
|
||||
|
||||
World *mWorld;
|
||||
MWSound::SoundManager *mSoundManager;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue