diff --git a/apps/mwinterpreter/context.cpp b/apps/mwinterpreter/context.cpp index 712c369e4..5d27a8fe3 100644 --- a/apps/mwinterpreter/context.cpp +++ b/apps/mwinterpreter/context.cpp @@ -115,6 +115,11 @@ namespace SAInterpreter return 0; } + float Context::getSecondsPassed() const + { + return 0; + } + void Context::report() { std::size_t i = 0; diff --git a/apps/mwinterpreter/context.hpp b/apps/mwinterpreter/context.hpp index 7920da5b9..e9535e918 100644 --- a/apps/mwinterpreter/context.hpp +++ b/apps/mwinterpreter/context.hpp @@ -60,6 +60,8 @@ namespace SAInterpreter virtual float getDistance (const std::string& name); + virtual float getSecondsPassed() const; + void report(); ///< Write state to std::cout }; diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 30cae5897..e9c9a7074 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -35,6 +35,8 @@ void OMW::Engine::executeLocalScripts() bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt) { + mEnvironment.mFrameDuration = evt.timeSinceLastFrame; + // console processCommands(); diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index a2f6663f3..d8a800597 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -159,6 +159,11 @@ namespace MWScript return false; } + float InterpreterContext::getSecondsPassed() const + { + return mEnvironment.mFrameDuration; + } + MWWorld::World& InterpreterContext::getWorld() { return *mEnvironment.mWorld; diff --git a/apps/openmw/mwscript/interpretercontext.hpp b/apps/openmw/mwscript/interpretercontext.hpp index 21fb35d04..c12554dec 100644 --- a/apps/openmw/mwscript/interpretercontext.hpp +++ b/apps/openmw/mwscript/interpretercontext.hpp @@ -70,6 +70,8 @@ namespace MWScript virtual float getDistance (const std::string& name); virtual bool hasBeenActivated() const; + + virtual float getSecondsPassed() const; MWWorld::World& getWorld(); diff --git a/apps/openmw/mwworld/environment.hpp b/apps/openmw/mwworld/environment.hpp index b208d95a2..1d8a59c9e 100644 --- a/apps/openmw/mwworld/environment.hpp +++ b/apps/openmw/mwworld/environment.hpp @@ -18,11 +18,12 @@ namespace MWWorld ///< Collection of script-accessable sub-systems struct Environment { - Environment() : mWorld (0), mSoundManager (0), mGlobalScripts (0) {} + Environment() : mWorld (0), mSoundManager (0), mGlobalScripts (0), mFrameDuration (0) {} World *mWorld; MWSound::SoundManager *mSoundManager; MWScript::GlobalScripts *mGlobalScripts; + float mFrameDuration; }; } diff --git a/components/compiler/context.hpp b/components/compiler/context.hpp index 1dfdf6afe..b34297cce 100644 --- a/components/compiler/context.hpp +++ b/components/compiler/context.hpp @@ -31,7 +31,7 @@ namespace Compiler } virtual char getGlobalType (const std::string& name) const = 0; - ///< 'l: long, 's': short, 'f': float, ' ': does not exist. + ///< 'l: long, 's': short, 'f': float, ' ': does not exist. }; } diff --git a/components/compiler/exprparser.cpp b/components/compiler/exprparser.cpp index 6d3415e22..fdf8feedf 100644 --- a/components/compiler/exprparser.cpp +++ b/components/compiler/exprparser.cpp @@ -337,8 +337,16 @@ namespace Compiler mNextOperand = false; return true; } - - + else if (keyword==Scanner::K_getsecondspassed) + { + mTokenLoc = loc; + + Generator::getSecondsPassed (mCode); + mOperands.push_back ('f'); + + mNextOperand = false; + return true; + } else { // check for custom extensions diff --git a/components/compiler/generator.cpp b/components/compiler/generator.cpp index 05b311724..27448e37d 100644 --- a/components/compiler/generator.cpp +++ b/components/compiler/generator.cpp @@ -279,6 +279,11 @@ namespace { code.push_back (Compiler::Generator::segment5 (49)); } + + void opGetSecondsPassed (Compiler::Generator::CodeContainer& code) + { + code.push_back (Compiler::Generator::segment5 (50)); + } } namespace Compiler @@ -675,6 +680,11 @@ namespace Compiler { opGetDistance (code); } + + void getSecondsPassed (CodeContainer& code) + { + opGetSecondsPassed (code); + } } } diff --git a/components/compiler/generator.hpp b/components/compiler/generator.hpp index c03ac7caf..3df789f61 100644 --- a/components/compiler/generator.hpp +++ b/components/compiler/generator.hpp @@ -108,6 +108,8 @@ namespace Compiler void stopScript (CodeContainer& code); void getDistance (CodeContainer& code); + + void getSecondsPassed (CodeContainer& code); } } diff --git a/components/compiler/scanner.cpp b/components/compiler/scanner.cpp index 25c536151..8899d561c 100644 --- a/components/compiler/scanner.cpp +++ b/components/compiler/scanner.cpp @@ -246,6 +246,7 @@ namespace Compiler "random", "startscript", "stopscript", "scriptrunning", "getdistance", + "getsecondspassed", 0 }; diff --git a/components/compiler/scanner.hpp b/components/compiler/scanner.hpp index e8f2b3d26..9e6e6a7d1 100644 --- a/components/compiler/scanner.hpp +++ b/components/compiler/scanner.hpp @@ -52,7 +52,8 @@ namespace Compiler K_menumode, K_random, K_startscript, K_stopscript, K_scriptrunning, - K_getdistance + K_getdistance, + K_getsecondspassed }; enum special diff --git a/components/interpreter/context.hpp b/components/interpreter/context.hpp index 91302a944..a8f0eaf8b 100644 --- a/components/interpreter/context.hpp +++ b/components/interpreter/context.hpp @@ -54,6 +54,8 @@ namespace Interpreter virtual void stopScript (const std::string& name) = 0; virtual float getDistance (const std::string& name) = 0; + + virtual float getSecondsPassed() const = 0; }; } diff --git a/components/interpreter/docs/vmformat.txt b/components/interpreter/docs/vmformat.txt index d45906a4c..12225e865 100644 --- a/components/interpreter/docs/vmformat.txt +++ b/components/interpreter/docs/vmformat.txt @@ -108,6 +108,7 @@ op 46: replace stack[0] with 1, if global script stack[0] is running, 0 else op 47: start script stack[0] and pop op 48: stop script stack[0] and pop op 49: replace stack[0] with distance between implicit reference and a reference of ID stack[0] -opcodes 50-33554431 unused +op 50: push frame duration (float) +opcodes 51-33554431 unused opcodes 33554432-67108863 reserved for extensions diff --git a/components/interpreter/installopcodes.cpp b/components/interpreter/installopcodes.cpp index 186ee7587..302812ad6 100644 --- a/components/interpreter/installopcodes.cpp +++ b/components/interpreter/installopcodes.cpp @@ -88,6 +88,7 @@ namespace Interpreter interpreter.installSegment3 (0, new OpMessageBox); interpreter.installSegment5 (38, new OpMenuMode); interpreter.installSegment5 (45, new OpRandom); + interpreter.installSegment5 (50, new OpGetSecondsPassed); // script control interpreter.installSegment5 (46, new OpScriptRunning); diff --git a/components/interpreter/miscopcodes.hpp b/components/interpreter/miscopcodes.hpp index 36061247d..17acb72db 100644 --- a/components/interpreter/miscopcodes.hpp +++ b/components/interpreter/miscopcodes.hpp @@ -116,8 +116,20 @@ namespace Interpreter Type_Integer value = static_cast (r*limit); // [o, limit) runtime[0] = *reinterpret_cast (&value); - } + } }; + + class OpGetSecondsPassed : public Opcode0 + { + public: + + virtual void execute (Runtime& runtime) + { + float duration = runtime.getContext().getSecondsPassed(); + + runtime.push (*reinterpret_cast (&duration)); + } + }; } #endif