forked from mirror/openmw-tes3mp
implemented dialogue scripts
This commit is contained in:
parent
65756db49e
commit
69f0ec99f1
6 changed files with 60 additions and 22 deletions
|
@ -60,7 +60,7 @@ void OMW::Engine::executeLocalScripts()
|
||||||
|
|
||||||
MWScript::InterpreterContext interpreterContext (mEnvironment,
|
MWScript::InterpreterContext interpreterContext (mEnvironment,
|
||||||
&script.second.getRefData().getLocals(), script.second);
|
&script.second.getRefData().getLocals(), script.second);
|
||||||
mScriptManager->run (script.first, interpreterContext);
|
mEnvironment.mScriptManager->run (script.first, interpreterContext);
|
||||||
|
|
||||||
if (mEnvironment.mWorld->hasCellChanged())
|
if (mEnvironment.mWorld->hasCellChanged())
|
||||||
break;
|
break;
|
||||||
|
@ -183,7 +183,6 @@ OMW::Engine::Engine(Files::ConfigurationManager& configurationManager)
|
||||||
, mCompileAll (false)
|
, mCompileAll (false)
|
||||||
, mReportFocus (false)
|
, mReportFocus (false)
|
||||||
, mFocusTDiff (0)
|
, mFocusTDiff (0)
|
||||||
, mScriptManager (0)
|
|
||||||
, mScriptContext (0)
|
, mScriptContext (0)
|
||||||
, mFSStrict (false)
|
, mFSStrict (false)
|
||||||
, mCfgMgr(configurationManager)
|
, mCfgMgr(configurationManager)
|
||||||
|
@ -200,7 +199,7 @@ OMW::Engine::~Engine()
|
||||||
delete mEnvironment.mMechanicsManager;
|
delete mEnvironment.mMechanicsManager;
|
||||||
delete mEnvironment.mDialogueManager;
|
delete mEnvironment.mDialogueManager;
|
||||||
delete mEnvironment.mJournal;
|
delete mEnvironment.mJournal;
|
||||||
delete mScriptManager;
|
delete mEnvironment.mScriptManager;
|
||||||
delete mScriptContext;
|
delete mScriptContext;
|
||||||
delete mOgre;
|
delete mOgre;
|
||||||
}
|
}
|
||||||
|
@ -350,11 +349,11 @@ void OMW::Engine::go()
|
||||||
mEnvironment);
|
mEnvironment);
|
||||||
mScriptContext->setExtensions (&mExtensions);
|
mScriptContext->setExtensions (&mExtensions);
|
||||||
|
|
||||||
mScriptManager = new MWScript::ScriptManager (mEnvironment.mWorld->getStore(), mVerboseScripts,
|
mEnvironment.mScriptManager = new MWScript::ScriptManager (mEnvironment.mWorld->getStore(),
|
||||||
*mScriptContext);
|
mVerboseScripts, *mScriptContext);
|
||||||
|
|
||||||
mEnvironment.mGlobalScripts = new MWScript::GlobalScripts (mEnvironment.mWorld->getStore(),
|
mEnvironment.mGlobalScripts = new MWScript::GlobalScripts (mEnvironment.mWorld->getStore(),
|
||||||
*mScriptManager);
|
*mEnvironment.mScriptManager);
|
||||||
|
|
||||||
// Create game mechanics system
|
// Create game mechanics system
|
||||||
mEnvironment.mMechanicsManager = new MWMechanics::MechanicsManager (mEnvironment);
|
mEnvironment.mMechanicsManager = new MWMechanics::MechanicsManager (mEnvironment);
|
||||||
|
@ -395,7 +394,7 @@ void OMW::Engine::go()
|
||||||
// scripts
|
// scripts
|
||||||
if (mCompileAll)
|
if (mCompileAll)
|
||||||
{
|
{
|
||||||
std::pair<int, int> result = mScriptManager->compileAll();
|
std::pair<int, int> result = mEnvironment.mScriptManager->compileAll();
|
||||||
|
|
||||||
if (result.first)
|
if (result.first)
|
||||||
std::cout
|
std::cout
|
||||||
|
@ -437,7 +436,7 @@ void OMW::Engine::activate()
|
||||||
if (!script.empty())
|
if (!script.empty())
|
||||||
{
|
{
|
||||||
mEnvironment.mWorld->getLocalScripts().setIgnore (ptr);
|
mEnvironment.mWorld->getLocalScripts().setIgnore (ptr);
|
||||||
mScriptManager->run (script, interpreterContext);
|
mEnvironment.mScriptManager->run (script, interpreterContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!interpreterContext.hasActivationBeenHandled())
|
if (!interpreterContext.hasActivationBeenHandled())
|
||||||
|
|
|
@ -78,10 +78,9 @@ namespace OMW
|
||||||
std::string mFocusName;
|
std::string mFocusName;
|
||||||
|
|
||||||
MWWorld::Environment mEnvironment;
|
MWWorld::Environment mEnvironment;
|
||||||
MWScript::ScriptManager *mScriptManager;
|
|
||||||
Compiler::Extensions mExtensions;
|
Compiler::Extensions mExtensions;
|
||||||
Compiler::Context *mScriptContext;
|
Compiler::Context *mScriptContext;
|
||||||
|
|
||||||
|
|
||||||
Files::Collections mFileCollections;
|
Files::Collections mFileCollections;
|
||||||
bool mFSStrict;
|
bool mFSStrict;
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "../mwscript/extensions.hpp"
|
#include "../mwscript/extensions.hpp"
|
||||||
|
#include "../mwscript/scriptmanager.hpp"
|
||||||
|
|
||||||
#include <components/compiler/exception.hpp>
|
#include <components/compiler/exception.hpp>
|
||||||
#include <components/compiler/errorhandler.hpp>
|
#include <components/compiler/errorhandler.hpp>
|
||||||
#include <components/compiler/scanner.hpp>
|
#include <components/compiler/scanner.hpp>
|
||||||
|
@ -409,7 +411,7 @@ namespace MWDialogue
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
DialogueManager::DialogueManager (MWWorld::Environment& environment) :
|
DialogueManager::DialogueManager (MWWorld::Environment& environment) :
|
||||||
mEnvironment (environment),mCompilerContext (MWScript::CompilerContext::Type_Dialgoue, environment),
|
mEnvironment (environment),mCompilerContext (MWScript::CompilerContext::Type_Dialgoue, environment),
|
||||||
mErrorStream(std::cout.rdbuf()),mErrorHandler(mErrorStream)
|
mErrorStream(std::cout.rdbuf()),mErrorHandler(mErrorStream)
|
||||||
{
|
{
|
||||||
|
@ -524,11 +526,21 @@ namespace MWDialogue
|
||||||
{
|
{
|
||||||
mErrorHandler.reset();
|
mErrorHandler.reset();
|
||||||
|
|
||||||
std::istringstream input (cmd);
|
std::istringstream input (cmd + "\n");
|
||||||
|
|
||||||
Compiler::Scanner scanner (mErrorHandler, input, mCompilerContext.getExtensions());
|
Compiler::Scanner scanner (mErrorHandler, input, mCompilerContext.getExtensions());
|
||||||
|
|
||||||
Compiler::ScriptParser parser(mErrorHandler,mCompilerContext,Compiler::Locals());//??????&mActor.getRefData().getLocals());
|
Compiler::Locals locals;
|
||||||
|
|
||||||
|
std::string actorScript = MWWorld::Class::get (mActor).getScript (mActor);
|
||||||
|
|
||||||
|
if (!actorScript.empty())
|
||||||
|
{
|
||||||
|
// grab local variables from actor's script, if available.
|
||||||
|
locals = mEnvironment.mScriptManager->getLocals (actorScript);
|
||||||
|
}
|
||||||
|
|
||||||
|
Compiler::ScriptParser parser(mErrorHandler,mCompilerContext, locals);
|
||||||
|
|
||||||
scanner.scan (parser);
|
scanner.scan (parser);
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ namespace MWScript
|
||||||
{
|
{
|
||||||
std::vector<Interpreter::Type_Code> code;
|
std::vector<Interpreter::Type_Code> code;
|
||||||
mParser.getCode (code);
|
mParser.getCode (code);
|
||||||
mScripts.insert (std::make_pair (name, code));
|
mScripts.insert (std::make_pair (name, std::make_pair (code, mParser.getLocals())));
|
||||||
|
|
||||||
// TODO sanity check on generated locals
|
// TODO sanity check on generated locals
|
||||||
|
|
||||||
|
@ -77,8 +77,7 @@ namespace MWScript
|
||||||
void ScriptManager::run (const std::string& name, Interpreter::Context& interpreterContext)
|
void ScriptManager::run (const std::string& name, Interpreter::Context& interpreterContext)
|
||||||
{
|
{
|
||||||
// compile script
|
// compile script
|
||||||
std::map<std::string, std::vector<Interpreter::Type_Code> >::iterator iter =
|
ScriptCollection::iterator iter = mScripts.find (name);
|
||||||
mScripts.find (name);
|
|
||||||
|
|
||||||
if (iter==mScripts.end())
|
if (iter==mScripts.end())
|
||||||
{
|
{
|
||||||
|
@ -86,7 +85,7 @@ namespace MWScript
|
||||||
{
|
{
|
||||||
// failed -> ignore script from now on.
|
// failed -> ignore script from now on.
|
||||||
std::vector<Interpreter::Type_Code> empty;
|
std::vector<Interpreter::Type_Code> empty;
|
||||||
mScripts.insert (std::make_pair (name, empty));
|
mScripts.insert (std::make_pair (name, std::make_pair (empty, Compiler::Locals())));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +94,7 @@ namespace MWScript
|
||||||
}
|
}
|
||||||
|
|
||||||
// execute script
|
// execute script
|
||||||
if (!iter->second.empty())
|
if (!iter->second.first.empty())
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!mOpcodesInstalled)
|
if (!mOpcodesInstalled)
|
||||||
|
@ -104,7 +103,7 @@ namespace MWScript
|
||||||
mOpcodesInstalled = true;
|
mOpcodesInstalled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
mInterpreter.run (&iter->second[0], iter->second.size(), interpreterContext);
|
mInterpreter.run (&iter->second.first[0], iter->second.first.size(), interpreterContext);
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
|
@ -113,7 +112,7 @@ namespace MWScript
|
||||||
if (mVerbose)
|
if (mVerbose)
|
||||||
std::cerr << "(" << e.what() << ")" << std::endl;
|
std::cerr << "(" << e.what() << ")" << std::endl;
|
||||||
|
|
||||||
iter->second.clear(); // don't execute again.
|
iter->second.first.clear(); // don't execute again.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,4 +131,24 @@ namespace MWScript
|
||||||
|
|
||||||
return std::make_pair (count, success);
|
return std::make_pair (count, success);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Compiler::Locals& ScriptManager::getLocals (const std::string& name)
|
||||||
|
{
|
||||||
|
ScriptCollection::iterator iter = mScripts.find (name);
|
||||||
|
|
||||||
|
if (iter==mScripts.end())
|
||||||
|
{
|
||||||
|
if (!compile (name))
|
||||||
|
{
|
||||||
|
// failed -> ignore script from now on.
|
||||||
|
std::vector<Interpreter::Type_Code> empty;
|
||||||
|
mScripts.insert (std::make_pair (name, std::make_pair (empty, Compiler::Locals())));
|
||||||
|
throw std::runtime_error ("failed to compile script " + name);
|
||||||
|
}
|
||||||
|
|
||||||
|
iter = mScripts.find (name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return iter->second.second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,11 @@ namespace MWScript
|
||||||
Interpreter::Interpreter mInterpreter;
|
Interpreter::Interpreter mInterpreter;
|
||||||
bool mOpcodesInstalled;
|
bool mOpcodesInstalled;
|
||||||
|
|
||||||
std::map<std::string, std::vector<Interpreter::Type_Code> > mScripts;
|
typedef std::pair<std::vector<Interpreter::Type_Code>, Compiler::Locals> CompiledScript;
|
||||||
|
typedef std::map<std::string, CompiledScript> ScriptCollection;
|
||||||
|
|
||||||
|
|
||||||
|
ScriptCollection mScripts;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -56,6 +60,9 @@ namespace MWScript
|
||||||
std::pair<int, int> compileAll();
|
std::pair<int, int> compileAll();
|
||||||
///< Compile all scripts
|
///< Compile all scripts
|
||||||
/// \return count, success
|
/// \return count, success
|
||||||
|
|
||||||
|
Compiler::Locals& getLocals (const std::string& name);
|
||||||
|
///< Return locals for script \a name.
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ namespace MWSound
|
||||||
namespace MWScript
|
namespace MWScript
|
||||||
{
|
{
|
||||||
class GlobalScripts;
|
class GlobalScripts;
|
||||||
|
class ScriptManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MWGui
|
namespace MWGui
|
||||||
|
@ -41,7 +42,7 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Environment()
|
Environment()
|
||||||
: mWorld (0), mSoundManager (0), mGlobalScripts (0), mWindowManager (0),
|
: mWorld (0), mSoundManager (0), mGlobalScripts (0), mScriptManager (0), mWindowManager (0),
|
||||||
mMechanicsManager (0), mDialogueManager (0), mJournal (0), mFrameDuration (0),
|
mMechanicsManager (0), mDialogueManager (0), mJournal (0), mFrameDuration (0),
|
||||||
mInputManager (0)
|
mInputManager (0)
|
||||||
{}
|
{}
|
||||||
|
@ -49,6 +50,7 @@ namespace MWWorld
|
||||||
World *mWorld;
|
World *mWorld;
|
||||||
MWSound::SoundManager *mSoundManager;
|
MWSound::SoundManager *mSoundManager;
|
||||||
MWScript::GlobalScripts *mGlobalScripts;
|
MWScript::GlobalScripts *mGlobalScripts;
|
||||||
|
MWScript::ScriptManager *mScriptManager;
|
||||||
MWGui::WindowManager *mWindowManager;
|
MWGui::WindowManager *mWindowManager;
|
||||||
MWMechanics::MechanicsManager *mMechanicsManager;
|
MWMechanics::MechanicsManager *mMechanicsManager;
|
||||||
MWDialogue::DialogueManager *mDialogueManager;
|
MWDialogue::DialogueManager *mDialogueManager;
|
||||||
|
|
Loading…
Reference in a new issue