diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index f9d85375b..62febb33d 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -192,11 +192,6 @@ namespace MWScript { } - bool InterpreterContext::menuMode() - { - return MWBase::Environment::get().getWindowManager()->isGuiMode(); - } - int InterpreterContext::getGlobalShort (const std::string& name) const { return MWBase::Environment::get().getWorld()->getGlobalInt (name); @@ -425,11 +420,6 @@ namespace MWScript } } - float InterpreterContext::getSecondsPassed() const - { - return MWBase::Environment::get().getFrameDuration(); - } - int InterpreterContext::getMemberShort (const std::string& id, const std::string& name, bool global) const { diff --git a/apps/openmw/mwscript/interpretercontext.hpp b/apps/openmw/mwscript/interpretercontext.hpp index 7e9f09cdb..e7c2790ce 100644 --- a/apps/openmw/mwscript/interpretercontext.hpp +++ b/apps/openmw/mwscript/interpretercontext.hpp @@ -77,8 +77,6 @@ namespace MWScript virtual void report (const std::string& message); ///< By default, do nothing. - virtual bool menuMode(); - virtual int getGlobalShort (const std::string& name) const; virtual int getGlobalLong (const std::string& name) const; @@ -124,8 +122,6 @@ namespace MWScript void executeActivation(MWWorld::Ptr ptr, MWWorld::Ptr actor); ///< Execute the activation action for this ptr. If ptr is mActivated, mark activation as handled. - virtual float getSecondsPassed() const; - virtual int getMemberShort (const std::string& id, const std::string& name, bool global) const; virtual int getMemberLong (const std::string& id, const std::string& name, bool global) const; diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 915b3221c..89bf44701 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -12,6 +12,8 @@ #include #include +#include + #include #include @@ -78,6 +80,33 @@ namespace MWScript { namespace Misc { + class OpMenuMode : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + runtime.push (MWBase::Environment::get().getWindowManager()->isGuiMode()); + } + }; + + class OpRandom : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + Interpreter::Type_Integer limit = runtime[0].mInteger; + runtime.pop(); + + if (limit<0) + throw std::runtime_error ( + "random: argument out of range (Don't be so negative!)"); + + runtime.push (static_cast(::Misc::Rng::rollDice(limit))); // [o, limit) + } + }; + template class OpStartScript : public Interpreter::Opcode0 { @@ -116,6 +145,16 @@ namespace MWScript } }; + class OpGetSecondsPassed : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + runtime.push (MWBase::Environment::get().getFrameDuration()); + } + }; + template class OpEnable : public Interpreter::Opcode0 { @@ -1530,10 +1569,13 @@ namespace MWScript void installOpcodes (Interpreter::Interpreter& interpreter) { + interpreter.installSegment5 (Compiler::Misc::opcodeMenuMode, new OpMenuMode); + interpreter.installSegment5 (Compiler::Misc::opcodeRandom, new OpRandom); interpreter.installSegment5 (Compiler::Misc::opcodeScriptRunning, new OpScriptRunning); interpreter.installSegment5 (Compiler::Misc::opcodeStartScript, new OpStartScript); interpreter.installSegment5 (Compiler::Misc::opcodeStartScriptExplicit, new OpStartScript); interpreter.installSegment5 (Compiler::Misc::opcodeStopScript, new OpStopScript); + interpreter.installSegment5 (Compiler::Misc::opcodeGetSecondsPassed, new OpGetSecondsPassed); interpreter.installSegment5 (Compiler::Misc::opcodeEnable, new OpEnable); interpreter.installSegment5 (Compiler::Misc::opcodeEnableExplicit, new OpEnable); interpreter.installSegment5 (Compiler::Misc::opcodeDisable, new OpDisable); diff --git a/components/compiler/exprparser.cpp b/components/compiler/exprparser.cpp index 8e8f063bb..8c8fe640e 100644 --- a/components/compiler/exprparser.cpp +++ b/components/compiler/exprparser.cpp @@ -434,43 +434,6 @@ namespace Compiler mNextOperand = false; return true; } - else if (keyword==Scanner::K_menumode) - { - start(); - - mTokenLoc = loc; - - Generator::menuMode (mCode); - mOperands.push_back ('l'); - - mNextOperand = false; - return true; - } - else if (keyword==Scanner::K_random) - { - start(); - - mTokenLoc = loc; - parseArguments ("l", scanner); - - Generator::random (mCode); - mOperands.push_back ('f'); - - mNextOperand = false; - return true; - } - else if (keyword==Scanner::K_getsecondspassed) - { - start(); - - mTokenLoc = loc; - - Generator::getSecondsPassed (mCode); - mOperands.push_back ('f'); - - mNextOperand = false; - return true; - } else { // check for custom extensions diff --git a/components/compiler/extensions0.cpp b/components/compiler/extensions0.cpp index 02a68d891..c67af29c2 100644 --- a/components/compiler/extensions0.cpp +++ b/components/compiler/extensions0.cpp @@ -241,9 +241,12 @@ namespace Compiler { void registerExtensions (Extensions& extensions) { + extensions.registerFunction ("menumode", 'l', "", opcodeMenuMode); + extensions.registerFunction ("random", 'f', "l", opcodeRandom); extensions.registerFunction ("scriptrunning", 'l', "c", opcodeScriptRunning); extensions.registerInstruction ("startscript", "c", opcodeStartScript, opcodeStartScriptExplicit); extensions.registerInstruction ("stopscript", "c", opcodeStopScript); + extensions.registerFunction ("getsecondspassed", 'f', "", opcodeGetSecondsPassed); extensions.registerInstruction ("enable", "", opcodeEnable, opcodeEnableExplicit); extensions.registerInstruction ("disable", "", opcodeDisable, opcodeDisableExplicit); extensions.registerFunction ("getdisabled", 'l', "x", opcodeGetDisabled, opcodeGetDisabledExplicit); diff --git a/components/compiler/generator.cpp b/components/compiler/generator.cpp index c16df660c..2787488c2 100644 --- a/components/compiler/generator.cpp +++ b/components/compiler/generator.cpp @@ -222,11 +222,6 @@ namespace code.push_back (Compiler::Generator::segment5 (37)); } - void opMenuMode (Compiler::Generator::CodeContainer& code) - { - code.push_back (Compiler::Generator::segment5 (38)); - } - void opStoreGlobalShort (Compiler::Generator::CodeContainer& code) { code.push_back (Compiler::Generator::segment5 (39)); @@ -286,16 +281,6 @@ namespace { code.push_back (Compiler::Generator::segment5 (global ? 70 : 64)); } - - void opRandom (Compiler::Generator::CodeContainer& code) - { - code.push_back (Compiler::Generator::segment5 (45)); - } - - void opGetSecondsPassed (Compiler::Generator::CodeContainer& code) - { - code.push_back (Compiler::Generator::segment5 (50)); - } } namespace Compiler @@ -590,11 +575,6 @@ namespace Compiler } } - void menuMode (CodeContainer& code) - { - opMenuMode (code); - } - void assignToGlobal (CodeContainer& code, Literals& literals, char localType, const std::string& name, const CodeContainer& value, char valueType) { @@ -751,15 +731,5 @@ namespace Compiler assert (0); } } - - void random (CodeContainer& code) - { - opRandom (code); - } - - void getSecondsPassed (CodeContainer& code) - { - opGetSecondsPassed (code); - } } } diff --git a/components/compiler/generator.hpp b/components/compiler/generator.hpp index f4386f605..55bba2a75 100644 --- a/components/compiler/generator.hpp +++ b/components/compiler/generator.hpp @@ -91,8 +91,6 @@ namespace Compiler void compare (CodeContainer& code, char op, char valueType1, char valueType2); - void menuMode (CodeContainer& code); - void assignToGlobal (CodeContainer& code, Literals& literals, char localType, const std::string& name, const CodeContainer& value, char valueType); @@ -106,10 +104,6 @@ namespace Compiler void fetchMember (CodeContainer& code, Literals& literals, char memberType, const std::string& name, const std::string& id, bool global); ///< \param global Member of a global script instead of a script of a reference. - - void random (CodeContainer& code); - - void getSecondsPassed (CodeContainer& code); } } diff --git a/components/compiler/lineparser.cpp b/components/compiler/lineparser.cpp index eaa833800..326b5f9f6 100644 --- a/components/compiler/lineparser.cpp +++ b/components/compiler/lineparser.cpp @@ -433,18 +433,6 @@ namespace Compiler return true; } - if (mAllowExpression) - { - if (keyword==Scanner::K_getsquareroot || keyword==Scanner::K_menumode || - keyword==Scanner::K_random || keyword==Scanner::K_getsecondspassed) - { - scanner.putbackKeyword (keyword, loc); - parseExpression (scanner, loc); - mState = EndState; - return true; - } - } - return Parser::parseKeyword (keyword, loc, scanner); } diff --git a/components/compiler/opcodes.hpp b/components/compiler/opcodes.hpp index 72e3cea89..363e8bb85 100644 --- a/components/compiler/opcodes.hpp +++ b/components/compiler/opcodes.hpp @@ -201,9 +201,12 @@ namespace Compiler namespace Misc { + const int opcodeMenuMode = 38; + const int opcodeRandom = 45; const int opcodeScriptRunning = 46; const int opcodeStartScript = 47; const int opcodeStopScript = 48; + const int opcodeGetSecondsPassed = 50; const int opcodeEnable = 51; const int opcodeDisable = 52; const int opcodeGetDisabled = 53; diff --git a/components/compiler/scanner.cpp b/components/compiler/scanner.cpp index 2be679cd2..9f2865868 100644 --- a/components/compiler/scanner.cpp +++ b/components/compiler/scanner.cpp @@ -266,9 +266,6 @@ namespace Compiler "messagebox", "set", "to", "getsquareroot", - "menumode", - "random", - "getsecondspassed", 0 }; diff --git a/components/compiler/scanner.hpp b/components/compiler/scanner.hpp index 973761898..b6321a92d 100644 --- a/components/compiler/scanner.hpp +++ b/components/compiler/scanner.hpp @@ -208,10 +208,7 @@ namespace Compiler K_return, K_messagebox, K_set, K_to, - K_getsquareroot, - K_menumode, - K_random, - K_getsecondspassed + K_getsquareroot }; enum special diff --git a/components/compiler/stringparser.cpp b/components/compiler/stringparser.cpp index a9974297d..1bacf7941 100644 --- a/components/compiler/stringparser.cpp +++ b/components/compiler/stringparser.cpp @@ -63,9 +63,7 @@ namespace Compiler keyword==Scanner::K_elseif || keyword==Scanner::K_while || keyword==Scanner::K_endwhile || keyword==Scanner::K_return || keyword==Scanner::K_messagebox || keyword==Scanner::K_set || - keyword==Scanner::K_to || keyword==Scanner::K_getsquareroot || - keyword==Scanner::K_menumode || keyword==Scanner::K_random || - keyword==Scanner::K_getsecondspassed) + keyword==Scanner::K_to || keyword==Scanner::K_getsquareroot) { return parseName (loc.mLiteral, loc, scanner); } diff --git a/components/interpreter/context.hpp b/components/interpreter/context.hpp index 30744dcec..862018bdc 100644 --- a/components/interpreter/context.hpp +++ b/components/interpreter/context.hpp @@ -35,8 +35,6 @@ namespace Interpreter virtual void report (const std::string& message) = 0; - virtual bool menuMode() = 0; - virtual int getGlobalShort (const std::string& name) const = 0; virtual int getGlobalLong (const std::string& name) const = 0; @@ -79,8 +77,6 @@ namespace Interpreter virtual std::string getCurrentCellName() const = 0; - virtual float getSecondsPassed() const = 0; - virtual int getMemberShort (const std::string& id, const std::string& name, bool global) const = 0; virtual int getMemberLong (const std::string& id, const std::string& name, bool global) const = 0; diff --git a/components/interpreter/installopcodes.cpp b/components/interpreter/installopcodes.cpp index dfaabe325..afee36bc2 100644 --- a/components/interpreter/installopcodes.cpp +++ b/components/interpreter/installopcodes.cpp @@ -95,9 +95,6 @@ namespace Interpreter // misc interpreter.installSegment3 (0, new OpMessageBox); - interpreter.installSegment5 (38, new OpMenuMode); - interpreter.installSegment5 (45, new OpRandom); - interpreter.installSegment5 (50, new OpGetSecondsPassed); interpreter.installSegment5 (58, new OpReport); } } diff --git a/components/interpreter/miscopcodes.hpp b/components/interpreter/miscopcodes.hpp index e1b1843ef..07bd84ec9 100644 --- a/components/interpreter/miscopcodes.hpp +++ b/components/interpreter/miscopcodes.hpp @@ -11,7 +11,6 @@ #include "runtime.hpp" #include "defines.hpp" -#include #include namespace Interpreter @@ -168,44 +167,6 @@ namespace Interpreter } }; - class OpMenuMode : public Opcode0 - { - public: - - virtual void execute (Runtime& runtime) - { - runtime.push (runtime.getContext().menuMode()); - } - }; - - class OpRandom : public Opcode0 - { - public: - - virtual void execute (Runtime& runtime) - { - Type_Integer limit = runtime[0].mInteger; - - if (limit<0) - throw std::runtime_error ( - "random: argument out of range (Don't be so negative!)"); - - runtime[0].mFloat = static_cast(Misc::Rng::rollDice(limit)); // [o, limit) - } - }; - - class OpGetSecondsPassed : public Opcode0 - { - public: - - virtual void execute (Runtime& runtime) - { - Type_Float duration = runtime.getContext().getSecondsPassed(); - - runtime.push (duration); - } - }; - } #endif