implemented global script execution

pull/7/head
Marc Zinnschlag 15 years ago
parent 530caac39b
commit 4482884eb5

@ -38,14 +38,18 @@ set(GAMESCRIPT
apps/openmw/mwscript/scriptmanager.cpp apps/openmw/mwscript/scriptmanager.cpp
apps/openmw/mwscript/interpretercontext.cpp apps/openmw/mwscript/interpretercontext.cpp
apps/openmw/mwscript/cellextensions.cpp apps/openmw/mwscript/cellextensions.cpp
apps/openmw/mwscript/extensions.cpp) apps/openmw/mwscript/extensions.cpp
apps/openmw/mwscript/globalscripts.cpp
)
set(GAMESCRIPT_HEADER set(GAMESCRIPT_HEADER
apps/openmw/mwscript/locals.hpp apps/openmw/mwscript/locals.hpp
apps/openmw/mwscript/scriptmanager.hpp apps/openmw/mwscript/scriptmanager.hpp
apps/openmw/mwscript/compilercontext.hpp apps/openmw/mwscript/compilercontext.hpp
apps/openmw/mwscript/interpretercontext.hpp apps/openmw/mwscript/interpretercontext.hpp
apps/openmw/mwscript/cellextensions.hpp apps/openmw/mwscript/cellextensions.hpp
apps/openmw/mwscript/extensions.hpp) apps/openmw/mwscript/extensions.hpp
apps/openmw/mwscript/globalscripts.hpp
)
source_group(apps\\openmw\\mwscript FILES ${GAMESCRIPT} ${GAMESCRIPT_HEADER}) source_group(apps\\openmw\\mwscript FILES ${GAMESCRIPT} ${GAMESCRIPT_HEADER})
set(GAMESOUND set(GAMESOUND
@ -61,7 +65,9 @@ set(GAMEWORLD
set(GAMEWORLD_HEADER set(GAMEWORLD_HEADER
apps/openmw/mwworld/refdata.hpp apps/openmw/mwworld/refdata.hpp
apps/openmw/mwworld/world.hpp apps/openmw/mwworld/world.hpp
apps/openmw/mwworld/ptr.hpp) apps/openmw/mwworld/ptr.hpp
apps/openmw/mwworld/environment.hpp
)
source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER}) source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER})

@ -13,18 +13,21 @@
#include "mwscript/compilercontext.hpp" #include "mwscript/compilercontext.hpp"
#include "mwscript/interpretercontext.hpp" #include "mwscript/interpretercontext.hpp"
#include "mwscript/extensions.hpp" #include "mwscript/extensions.hpp"
#include "mwscript/globalscripts.hpp"
#include "mwsound/soundmanager.hpp" #include "mwsound/soundmanager.hpp"
#include "mwworld/world.hpp" #include "mwworld/world.hpp"
#include "mwworld/ptr.hpp" #include "mwworld/ptr.hpp"
#include "mwworld/environment.hpp"
void OMW::Engine::executeLocalScripts() void OMW::Engine::executeLocalScripts()
{ {
for (MWWorld::World::ScriptList::const_iterator iter (mWorld->getLocalScripts().begin()); for (MWWorld::World::ScriptList::const_iterator iter (
iter!=mWorld->getLocalScripts().end(); ++iter) mEnvironment.mWorld->getLocalScripts().begin());
iter!=mEnvironment.mWorld->getLocalScripts().end(); ++iter)
{ {
MWScript::InterpreterContext interpreterContext (*mWorld, *mSoundManager, MWScript::InterpreterContext interpreterContext (mEnvironment,
&iter->second.getRefData().getLocals(), MWWorld::Ptr (iter->second)); &iter->second.getRefData().getLocals(), MWWorld::Ptr (iter->second));
mScriptManager->run (iter->first, interpreterContext); mScriptManager->run (iter->first, interpreterContext);
} }
@ -37,6 +40,9 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt)
// local scripts // local scripts
executeLocalScripts(); executeLocalScripts();
// global scripts
mGlobalScripts->run (mEnvironment);
return true; return true;
} }
@ -57,7 +63,7 @@ void OMW::Engine::processCommands()
} }
OMW::Engine::Engine() OMW::Engine::Engine()
: mWorld(NULL), mDebug (false), mVerboseScripts (false), mSoundManager (0), mScriptManager (0), : mDebug (false), mVerboseScripts (false), mScriptManager (0), mGlobalScripts (0),
mScriptContext (0) mScriptContext (0)
{ {
mspCommandServer.reset( mspCommandServer.reset(
@ -67,8 +73,9 @@ OMW::Engine::Engine()
OMW::Engine::~Engine() OMW::Engine::~Engine()
{ {
// mspCommandServer->stop(); // mspCommandServer->stop();
delete mWorld; delete mEnvironment.mWorld;
delete mSoundManager; delete mEnvironment.mSoundManager;
delete mGlobalScripts;
delete mScriptManager; delete mScriptManager;
delete mScriptContext; delete mScriptContext;
} }
@ -143,7 +150,7 @@ void OMW::Engine::enableVerboseScripts()
void OMW::Engine::go() void OMW::Engine::go()
{ {
assert (!mWorld); assert (!mEnvironment.mWorld);
assert (!mDataDir.empty()); assert (!mDataDir.empty());
assert (!mCellName.empty()); assert (!mCellName.empty());
assert (!mMaster.empty()); assert (!mMaster.empty());
@ -167,22 +174,24 @@ void OMW::Engine::go()
loadBSA(); loadBSA();
// Create the world // Create the world
mWorld = new MWWorld::World (mOgre, mDataDir, mMaster, mCellName); mEnvironment.mWorld = new MWWorld::World (mOgre, mDataDir, mMaster, mCellName);
mSoundManager = new MWSound::SoundManager; mEnvironment.mSoundManager = new MWSound::SoundManager;
MWScript::registerExtensions (mExtensions); MWScript::registerExtensions (mExtensions);
mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full); mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full);
mScriptContext->setExtensions (&mExtensions); mScriptContext->setExtensions (&mExtensions);
mScriptManager = new MWScript::ScriptManager (mWorld->getStore(), mVerboseScripts, mScriptManager = new MWScript::ScriptManager (mEnvironment.mWorld->getStore(), mVerboseScripts,
*mScriptContext); *mScriptContext);
mGlobalScripts = new MWScript::GlobalScripts (mEnvironment.mWorld->getStore(), *mScriptManager);
std::cout << "Setting up input system\n"; std::cout << "Setting up input system\n";
// Sets up the input system // Sets up the input system
MWInput::MWInputManager input(mOgre, mWorld->getPlayerPos(), mDebug); MWInput::MWInputManager input(mOgre, mEnvironment.mWorld->getPlayerPos(), mDebug);
// Launch the console server // Launch the console server
std::cout << "Starting command server on port " << kCommandServerPort << std::endl; std::cout << "Starting command server on port " << kCommandServerPort << std::endl;

@ -13,6 +13,8 @@
#include <components/commandserver/command.hpp> #include <components/commandserver/command.hpp>
#include <components/compiler/extensions.hpp> #include <components/compiler/extensions.hpp>
#include "mwworld/environment.hpp"
namespace Compiler namespace Compiler
{ {
class Context; class Context;
@ -21,6 +23,7 @@ namespace Compiler
namespace MWScript namespace MWScript
{ {
class ScriptManager; class ScriptManager;
class GlobalScripts;
} }
namespace MWSound namespace MWSound
@ -45,15 +48,15 @@ namespace OMW
Render::OgreRenderer mOgre; Render::OgreRenderer mOgre;
std::string mCellName; std::string mCellName;
std::string mMaster; std::string mMaster;
MWWorld::World *mWorld;
bool mDebug; bool mDebug;
bool mVerboseScripts; bool mVerboseScripts;
TsDeque<OMW::Command> mCommandQueue; TsDeque<OMW::Command> mCommandQueue;
std::auto_ptr<OMW::CommandServer::Server> mspCommandServer; std::auto_ptr<OMW::CommandServer::Server> mspCommandServer;
MWSound::SoundManager *mSoundManager; MWWorld::Environment mEnvironment;
MWScript::ScriptManager *mScriptManager; MWScript::ScriptManager *mScriptManager;
MWScript::GlobalScripts *mGlobalScripts;
Compiler::Extensions mExtensions; Compiler::Extensions mExtensions;
Compiler::Context *mScriptContext; Compiler::Context *mScriptContext;

@ -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

@ -9,9 +9,9 @@
namespace MWScript namespace MWScript
{ {
InterpreterContext::InterpreterContext (MWWorld::World& world, InterpreterContext::InterpreterContext (const MWWorld::Environment& environment,
MWSound::SoundManager& soundManager, MWScript::Locals *locals, MWWorld::Ptr reference) MWScript::Locals *locals, MWWorld::Ptr reference)
: mWorld (world), mSoundManager (soundManager), mLocals (locals), mReference (reference) : mEnvironment (environment), mLocals (locals), mReference (reference)
{} {}
int InterpreterContext::getLocalShort (int index) const int InterpreterContext::getLocalShort (int index) const
@ -73,12 +73,12 @@ namespace MWScript
MWWorld::World& InterpreterContext::getWorld() MWWorld::World& InterpreterContext::getWorld()
{ {
return mWorld; return *mEnvironment.mWorld;
} }
MWSound::SoundManager& InterpreterContext::getSoundManager() MWSound::SoundManager& InterpreterContext::getSoundManager()
{ {
return mSoundManager; return *mEnvironment.mSoundManager;
} }
MWWorld::Ptr InterpreterContext::getReference() MWWorld::Ptr InterpreterContext::getReference()

@ -4,6 +4,7 @@
#include <components/interpreter/context.hpp> #include <components/interpreter/context.hpp>
#include "../mwworld/ptr.hpp" #include "../mwworld/ptr.hpp"
#include "../mwworld/environment.hpp"
namespace MWWorld namespace MWWorld
{ {
@ -20,15 +21,14 @@ namespace MWScript
struct Locals; struct Locals;
class InterpreterContext : public Interpreter::Context class InterpreterContext : public Interpreter::Context
{ {
MWWorld::World& mWorld; MWWorld::Environment mEnvironment;
MWSound::SoundManager& mSoundManager;
Locals *mLocals; Locals *mLocals;
MWWorld::Ptr mReference; MWWorld::Ptr mReference;
public: public:
InterpreterContext (MWWorld::World& world, MWSound::SoundManager& soundManager, InterpreterContext (const MWWorld::Environment& environment,
MWScript::Locals *locals, MWWorld::Ptr reference); MWScript::Locals *locals, MWWorld::Ptr reference);
///< The ownership of \a locals is not transferred. 0-pointer allowed. ///< The ownership of \a locals is not transferred. 0-pointer allowed.

@ -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…
Cancel
Save