forked from teamnwah/openmw-tes3coop
implemented global script execution
This commit is contained in:
parent
530caac39b
commit
4482884eb5
8 changed files with 148 additions and 25 deletions
|
@ -38,14 +38,18 @@ set(GAMESCRIPT
|
|||
apps/openmw/mwscript/scriptmanager.cpp
|
||||
apps/openmw/mwscript/interpretercontext.cpp
|
||||
apps/openmw/mwscript/cellextensions.cpp
|
||||
apps/openmw/mwscript/extensions.cpp)
|
||||
apps/openmw/mwscript/extensions.cpp
|
||||
apps/openmw/mwscript/globalscripts.cpp
|
||||
)
|
||||
set(GAMESCRIPT_HEADER
|
||||
apps/openmw/mwscript/locals.hpp
|
||||
apps/openmw/mwscript/scriptmanager.hpp
|
||||
apps/openmw/mwscript/compilercontext.hpp
|
||||
apps/openmw/mwscript/interpretercontext.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})
|
||||
|
||||
set(GAMESOUND
|
||||
|
@ -61,7 +65,9 @@ set(GAMEWORLD
|
|||
set(GAMEWORLD_HEADER
|
||||
apps/openmw/mwworld/refdata.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})
|
||||
|
||||
|
||||
|
|
|
@ -13,18 +13,21 @@
|
|||
#include "mwscript/compilercontext.hpp"
|
||||
#include "mwscript/interpretercontext.hpp"
|
||||
#include "mwscript/extensions.hpp"
|
||||
#include "mwscript/globalscripts.hpp"
|
||||
|
||||
#include "mwsound/soundmanager.hpp"
|
||||
|
||||
#include "mwworld/world.hpp"
|
||||
#include "mwworld/ptr.hpp"
|
||||
#include "mwworld/environment.hpp"
|
||||
|
||||
void OMW::Engine::executeLocalScripts()
|
||||
{
|
||||
for (MWWorld::World::ScriptList::const_iterator iter (mWorld->getLocalScripts().begin());
|
||||
iter!=mWorld->getLocalScripts().end(); ++iter)
|
||||
for (MWWorld::World::ScriptList::const_iterator 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));
|
||||
mScriptManager->run (iter->first, interpreterContext);
|
||||
}
|
||||
|
@ -37,6 +40,9 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt)
|
|||
|
||||
// local scripts
|
||||
executeLocalScripts();
|
||||
|
||||
// global scripts
|
||||
mGlobalScripts->run (mEnvironment);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -57,7 +63,7 @@ void OMW::Engine::processCommands()
|
|||
}
|
||||
|
||||
OMW::Engine::Engine()
|
||||
: mWorld(NULL), mDebug (false), mVerboseScripts (false), mSoundManager (0), mScriptManager (0),
|
||||
: mDebug (false), mVerboseScripts (false), mScriptManager (0), mGlobalScripts (0),
|
||||
mScriptContext (0)
|
||||
{
|
||||
mspCommandServer.reset(
|
||||
|
@ -67,8 +73,9 @@ OMW::Engine::Engine()
|
|||
OMW::Engine::~Engine()
|
||||
{
|
||||
// mspCommandServer->stop();
|
||||
delete mWorld;
|
||||
delete mSoundManager;
|
||||
delete mEnvironment.mWorld;
|
||||
delete mEnvironment.mSoundManager;
|
||||
delete mGlobalScripts;
|
||||
delete mScriptManager;
|
||||
delete mScriptContext;
|
||||
}
|
||||
|
@ -143,7 +150,7 @@ void OMW::Engine::enableVerboseScripts()
|
|||
|
||||
void OMW::Engine::go()
|
||||
{
|
||||
assert (!mWorld);
|
||||
assert (!mEnvironment.mWorld);
|
||||
assert (!mDataDir.empty());
|
||||
assert (!mCellName.empty());
|
||||
assert (!mMaster.empty());
|
||||
|
@ -167,22 +174,24 @@ void OMW::Engine::go()
|
|||
loadBSA();
|
||||
|
||||
// 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);
|
||||
|
||||
mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full);
|
||||
mScriptContext->setExtensions (&mExtensions);
|
||||
|
||||
mScriptManager = new MWScript::ScriptManager (mWorld->getStore(), mVerboseScripts,
|
||||
mScriptManager = new MWScript::ScriptManager (mEnvironment.mWorld->getStore(), mVerboseScripts,
|
||||
*mScriptContext);
|
||||
|
||||
mGlobalScripts = new MWScript::GlobalScripts (mEnvironment.mWorld->getStore(), *mScriptManager);
|
||||
|
||||
std::cout << "Setting up input system\n";
|
||||
|
||||
// Sets up the input system
|
||||
MWInput::MWInputManager input(mOgre, mWorld->getPlayerPos(), mDebug);
|
||||
MWInput::MWInputManager input(mOgre, mEnvironment.mWorld->getPlayerPos(), mDebug);
|
||||
|
||||
// Launch the console server
|
||||
std::cout << "Starting command server on port " << kCommandServerPort << std::endl;
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#include <components/commandserver/command.hpp>
|
||||
#include <components/compiler/extensions.hpp>
|
||||
|
||||
#include "mwworld/environment.hpp"
|
||||
|
||||
namespace Compiler
|
||||
{
|
||||
class Context;
|
||||
|
@ -21,6 +23,7 @@ namespace Compiler
|
|||
namespace MWScript
|
||||
{
|
||||
class ScriptManager;
|
||||
class GlobalScripts;
|
||||
}
|
||||
|
||||
namespace MWSound
|
||||
|
@ -45,15 +48,15 @@ namespace OMW
|
|||
Render::OgreRenderer mOgre;
|
||||
std::string mCellName;
|
||||
std::string mMaster;
|
||||
MWWorld::World *mWorld;
|
||||
bool mDebug;
|
||||
bool mVerboseScripts;
|
||||
|
||||
TsDeque<OMW::Command> mCommandQueue;
|
||||
std::auto_ptr<OMW::CommandServer::Server> mspCommandServer;
|
||||
|
||||
MWSound::SoundManager *mSoundManager;
|
||||
MWWorld::Environment mEnvironment;
|
||||
MWScript::ScriptManager *mScriptManager;
|
||||
MWScript::GlobalScripts *mGlobalScripts;
|
||||
Compiler::Extensions mExtensions;
|
||||
Compiler::Context *mScriptContext;
|
||||
|
||||
|
|
41
apps/openmw/mwscript/globalscripts.cpp
Normal file
41
apps/openmw/mwscript/globalscripts.cpp
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
40
apps/openmw/mwscript/globalscripts.hpp
Normal file
40
apps/openmw/mwscript/globalscripts.hpp
Normal file
|
@ -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
|
||||
{
|
||||
InterpreterContext::InterpreterContext (MWWorld::World& world,
|
||||
MWSound::SoundManager& soundManager, MWScript::Locals *locals, MWWorld::Ptr reference)
|
||||
: mWorld (world), mSoundManager (soundManager), mLocals (locals), mReference (reference)
|
||||
InterpreterContext::InterpreterContext (const MWWorld::Environment& environment,
|
||||
MWScript::Locals *locals, MWWorld::Ptr reference)
|
||||
: mEnvironment (environment), mLocals (locals), mReference (reference)
|
||||
{}
|
||||
|
||||
int InterpreterContext::getLocalShort (int index) const
|
||||
|
@ -73,12 +73,12 @@ namespace MWScript
|
|||
|
||||
MWWorld::World& InterpreterContext::getWorld()
|
||||
{
|
||||
return mWorld;
|
||||
return *mEnvironment.mWorld;
|
||||
}
|
||||
|
||||
MWSound::SoundManager& InterpreterContext::getSoundManager()
|
||||
{
|
||||
return mSoundManager;
|
||||
return *mEnvironment.mSoundManager;
|
||||
}
|
||||
|
||||
MWWorld::Ptr InterpreterContext::getReference()
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <components/interpreter/context.hpp>
|
||||
|
||||
#include "../mwworld/ptr.hpp"
|
||||
#include "../mwworld/environment.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
|
@ -20,15 +21,14 @@ namespace MWScript
|
|||
struct Locals;
|
||||
|
||||
class InterpreterContext : public Interpreter::Context
|
||||
{
|
||||
MWWorld::World& mWorld;
|
||||
MWSound::SoundManager& mSoundManager;
|
||||
{
|
||||
MWWorld::Environment mEnvironment;
|
||||
Locals *mLocals;
|
||||
MWWorld::Ptr mReference;
|
||||
|
||||
public:
|
||||
|
||||
InterpreterContext (MWWorld::World& world, MWSound::SoundManager& soundManager,
|
||||
InterpreterContext (const MWWorld::Environment& environment,
|
||||
MWScript::Locals *locals, MWWorld::Ptr reference);
|
||||
///< The ownership of \a locals is not transferred. 0-pointer allowed.
|
||||
|
||||
|
|
24
apps/openmw/mwworld/environment.hpp
Normal file
24
apps/openmw/mwworld/environment.hpp
Normal file
|
@ -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 a new issue