diff --git a/CMakeLists.txt b/CMakeLists.txt index c0ce129dfc..a4be4d6041 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,13 +39,17 @@ source_group(apps\\openmw\\mwinput FILES ${GAMEINPUT} ${GAMEINPUT_HEADER}) set(GAMESCRIPT apps/openmw/mwscript/scriptmanager.cpp - apps/openmw/mwscript/interpretercontext.cpp) + apps/openmw/mwscript/interpretercontext.cpp + apps/openmw/mwscript/cellextensions.cpp + apps/openmw/mwscript/extensions.cpp) set(GAMESCRIPT_HEADER apps/openmw/mwscript/locals.hpp apps/openmw/mwscript/scriptmanager.hpp apps/openmw/mwscript/compilercontext.hpp apps/openmw/mwscript/compilercontextscript.hpp - apps/openmw/mwscript/interpretercontext.hpp) + apps/openmw/mwscript/interpretercontext.hpp + apps/openmw/mwscript/cellextensions.hpp + apps/openmw/mwscript/extensions.hpp) source_group(apps\\openmw\\mwscript FILES ${GAMESCRIPT} ${GAMESCRIPT_HEADER}) set(APPS ${GAME} ${GAMEREND} ${GAMEINPUT} ${GAMESCRIPT}) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 507cbc4537..8e7071f50c 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -11,6 +11,7 @@ #include "mwscript/scriptmanager.hpp" #include "mwscript/compilercontextscript.hpp" #include "mwscript/interpretercontext.hpp" +#include "mwscript/extensions.hpp" #include "world.hpp" @@ -161,7 +162,10 @@ void OMW::Engine::go() // Create the world mWorld = new World (mOgre, mDataDir, mMaster, mCellName); + MWScript::registerExtensions (mExtensions); + mScriptContext = new MWScript::CompilerContextScript; + mScriptContext->setExtensions (&mExtensions); mScriptManager = new MWScript::ScriptManager (mWorld->getStore(), mVerboseScripts, *mScriptContext); diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index be560a1723..406cf2358c 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -11,6 +11,7 @@ #include "components/misc/tsdeque.hpp" #include "components/commandserver/server.hpp" #include "components/commandserver/command.hpp" +#include #include "mwrender/mwscene.hpp" @@ -46,6 +47,7 @@ namespace OMW std::auto_ptr mspCommandServer; MWScript::ScriptManager *mScriptManager; + Compiler::Extensions mExtensions; Compiler::Context *mScriptContext; // not implemented diff --git a/apps/openmw/mwscript/cellextensions.cpp b/apps/openmw/mwscript/cellextensions.cpp new file mode 100644 index 0000000000..ea7f9460c4 --- /dev/null +++ b/apps/openmw/mwscript/cellextensions.cpp @@ -0,0 +1,42 @@ + +#include "cellextensions.hpp" + +#include + +#include +#include +#include + +#include "interpretercontext.hpp" + +namespace MWScript +{ + namespace Cell + { + class OpCellChanged : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + InterpreterContext& context + = static_cast (runtime.getContext()); + + runtime.push (context.cellChanged() ? 1 : 0); + } + }; + + const int opcodeCellChanged = 0x2000000; + + void registerExtensions (Compiler::Extensions& extensions) + { + extensions.registerFunction ("cellchanged", 'l', "", opcodeCellChanged); + } + + void installOpcodes (Interpreter::Interpreter& interpreter) + { + interpreter.installSegment5 (opcodeCellChanged, new OpCellChanged); + } + } +} + diff --git a/apps/openmw/mwscript/cellextensions.hpp b/apps/openmw/mwscript/cellextensions.hpp new file mode 100644 index 0000000000..4aef25d1ae --- /dev/null +++ b/apps/openmw/mwscript/cellextensions.hpp @@ -0,0 +1,27 @@ +#ifndef GAME_SCRIPT_CELLEXTENSIONS_H +#define GAME_SCRIPT_CELLEXTENSIONS_H + +namespace Compiler +{ + class Extensions; +} + +namespace Interpreter +{ + class Interpreter; +} + +namespace MWScript +{ + /// \brief cell-related script functionality + namespace Cell + { + void registerExtensions (Compiler::Extensions& extensions); + + void installOpcodes (Interpreter::Interpreter& interpreter); + } +} + +#endif + + diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt new file mode 100644 index 0000000000..cad1d3304e --- /dev/null +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -0,0 +1,26 @@ +OpenMW Extensions: + +Segment 0: +(not implemented yet) +opcodes 0x20-0x3f unused + +Segment 1: +(not implemented yet) +opcodes 0x20-0x3f unused + +Segment 2: +(not implemented yet) +opcodes 0x200-0x3ff unused + +Segment 3: +(not implemented yet) +opcodes 0x200-0x3ff unused + +Segment 4: +(not implemented yet) +opcodes 0x200-0x3ff unused + +Segment 5: +op 2000000: push 1 if cell has changed since last frame, 0 if not +opcodes 0x2000001-0x3ffffff unused + diff --git a/apps/openmw/mwscript/extensions.cpp b/apps/openmw/mwscript/extensions.cpp new file mode 100644 index 0000000000..e0fb81cd3a --- /dev/null +++ b/apps/openmw/mwscript/extensions.cpp @@ -0,0 +1,13 @@ + +#include "extensions.hpp" + +#include "cellextensions.hpp" + +namespace MWScript +{ + void registerExtensions (Compiler::Extensions& extensions) + { + Cell::registerExtensions (extensions); + } +} + diff --git a/apps/openmw/mwscript/extensions.hpp b/apps/openmw/mwscript/extensions.hpp new file mode 100644 index 0000000000..a38da03400 --- /dev/null +++ b/apps/openmw/mwscript/extensions.hpp @@ -0,0 +1,14 @@ +#ifndef GAME_SCRIPT_EXTENSIONS_H +#define GAME_SCRIPT_EXTENSIONS_H + +namespace Compiler +{ + class Extensions; +} + +namespace MWScript +{ + void registerExtensions (Compiler::Extensions& extensions); +} + +#endif diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 784cc9afaf..bbdd5e1ca8 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -5,6 +5,7 @@ #include #include "locals.hpp" +#include "../world.hpp" namespace MWScript { @@ -68,5 +69,10 @@ namespace MWScript if (!buttons.empty()) std::cerr << "error: message box buttons not supported" << std::endl; } + + bool InterpreterContext::cellChanged() + { + return mWorld.hasCellChanged(); + } } diff --git a/apps/openmw/mwscript/interpretercontext.hpp b/apps/openmw/mwscript/interpretercontext.hpp index c023b67d02..7b1c281b08 100644 --- a/apps/openmw/mwscript/interpretercontext.hpp +++ b/apps/openmw/mwscript/interpretercontext.hpp @@ -36,6 +36,8 @@ namespace MWScript virtual void messageBox (const std::string& message, const std::vector& buttons); + + virtual bool cellChanged(); }; } diff --git a/apps/openmw/mwscript/scriptmanager.cpp b/apps/openmw/mwscript/scriptmanager.cpp index 607cfc8296..fde9c93fa5 100644 --- a/apps/openmw/mwscript/scriptmanager.cpp +++ b/apps/openmw/mwscript/scriptmanager.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -39,7 +40,7 @@ namespace MWScript { std::istringstream input (script->scriptText); - Compiler::Scanner scanner (mErrorHandler, input); + Compiler::Scanner scanner (mErrorHandler, input, mCompilerContext.getExtensions()); scanner.scan (mParser); @@ -99,7 +100,7 @@ namespace MWScript try { Interpreter::Interpreter interpreter (interpreterContext); - Interpreter::installOpcodes (interpreter); + installOpcodes (interpreter); interpreter.run (&iter->second[0], iter->second.size()); } catch (...) @@ -108,5 +109,10 @@ namespace MWScript iter->second.clear(); // don't execute again. } } + + void ScriptManager::installOpcodes (Interpreter::Interpreter& interpreter) + { + Interpreter::installOpcodes (interpreter); + } } diff --git a/apps/openmw/mwscript/scriptmanager.hpp b/apps/openmw/mwscript/scriptmanager.hpp index c029d6506a..17b8cc2426 100644 --- a/apps/openmw/mwscript/scriptmanager.hpp +++ b/apps/openmw/mwscript/scriptmanager.hpp @@ -23,6 +23,7 @@ namespace Compiler namespace Interpreter { class Context; + class Interpreter; } namespace MWScript @@ -45,6 +46,8 @@ namespace MWScript Compiler::Context& compilerContext); void run (const std::string& name, Interpreter::Context& interpreterContext); + + static void installOpcodes (Interpreter::Interpreter& interpreter); }; }; diff --git a/apps/openmw/world.cpp b/apps/openmw/world.cpp index df6e0f183c..e1c90c71b5 100644 --- a/apps/openmw/world.cpp +++ b/apps/openmw/world.cpp @@ -115,4 +115,10 @@ namespace OMW { return mLocalScripts; } + + bool World::hasCellChanged() const + { + // Cell change not implemented yet. + return false; + } } diff --git a/apps/openmw/world.hpp b/apps/openmw/world.hpp index 7eed09dda8..9efd095b57 100644 --- a/apps/openmw/world.hpp +++ b/apps/openmw/world.hpp @@ -68,6 +68,9 @@ namespace OMW const ScriptList& getLocalScripts() const; ///< Names and local variable state of all local scripts in active cells. + + bool hasCellChanged() const; + ///< Has the player moved to a different cell, since the last frame? }; }