added GetSecondsPassed

actorid
Marc Zinnschlag 15 years ago
parent f5a70abd4b
commit 9d73718ec1

@ -115,6 +115,11 @@ namespace SAInterpreter
return 0; return 0;
} }
float Context::getSecondsPassed() const
{
return 0;
}
void Context::report() void Context::report()
{ {
std::size_t i = 0; std::size_t i = 0;

@ -60,6 +60,8 @@ namespace SAInterpreter
virtual float getDistance (const std::string& name); virtual float getDistance (const std::string& name);
virtual float getSecondsPassed() const;
void report(); void report();
///< Write state to std::cout ///< Write state to std::cout
}; };

@ -35,6 +35,8 @@ void OMW::Engine::executeLocalScripts()
bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt) bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt)
{ {
mEnvironment.mFrameDuration = evt.timeSinceLastFrame;
// console // console
processCommands(); processCommands();

@ -159,6 +159,11 @@ namespace MWScript
return false; return false;
} }
float InterpreterContext::getSecondsPassed() const
{
return mEnvironment.mFrameDuration;
}
MWWorld::World& InterpreterContext::getWorld() MWWorld::World& InterpreterContext::getWorld()
{ {
return *mEnvironment.mWorld; return *mEnvironment.mWorld;

@ -70,6 +70,8 @@ namespace MWScript
virtual float getDistance (const std::string& name); virtual float getDistance (const std::string& name);
virtual bool hasBeenActivated() const; virtual bool hasBeenActivated() const;
virtual float getSecondsPassed() const;
MWWorld::World& getWorld(); MWWorld::World& getWorld();

@ -18,11 +18,12 @@ namespace MWWorld
///< Collection of script-accessable sub-systems ///< Collection of script-accessable sub-systems
struct Environment struct Environment
{ {
Environment() : mWorld (0), mSoundManager (0), mGlobalScripts (0) {} Environment() : mWorld (0), mSoundManager (0), mGlobalScripts (0), mFrameDuration (0) {}
World *mWorld; World *mWorld;
MWSound::SoundManager *mSoundManager; MWSound::SoundManager *mSoundManager;
MWScript::GlobalScripts *mGlobalScripts; MWScript::GlobalScripts *mGlobalScripts;
float mFrameDuration;
}; };
} }

@ -31,7 +31,7 @@ namespace Compiler
} }
virtual char getGlobalType (const std::string& name) const = 0; 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.
}; };
} }

@ -337,8 +337,16 @@ namespace Compiler
mNextOperand = false; mNextOperand = false;
return true; return true;
} }
else if (keyword==Scanner::K_getsecondspassed)
{
mTokenLoc = loc;
Generator::getSecondsPassed (mCode);
mOperands.push_back ('f');
mNextOperand = false;
return true;
}
else else
{ {
// check for custom extensions // check for custom extensions

@ -279,6 +279,11 @@ namespace
{ {
code.push_back (Compiler::Generator::segment5 (49)); code.push_back (Compiler::Generator::segment5 (49));
} }
void opGetSecondsPassed (Compiler::Generator::CodeContainer& code)
{
code.push_back (Compiler::Generator::segment5 (50));
}
} }
namespace Compiler namespace Compiler
@ -675,6 +680,11 @@ namespace Compiler
{ {
opGetDistance (code); opGetDistance (code);
} }
void getSecondsPassed (CodeContainer& code)
{
opGetSecondsPassed (code);
}
} }
} }

@ -108,6 +108,8 @@ namespace Compiler
void stopScript (CodeContainer& code); void stopScript (CodeContainer& code);
void getDistance (CodeContainer& code); void getDistance (CodeContainer& code);
void getSecondsPassed (CodeContainer& code);
} }
} }

@ -246,6 +246,7 @@ namespace Compiler
"random", "random",
"startscript", "stopscript", "scriptrunning", "startscript", "stopscript", "scriptrunning",
"getdistance", "getdistance",
"getsecondspassed",
0 0
}; };

@ -52,7 +52,8 @@ namespace Compiler
K_menumode, K_menumode,
K_random, K_random,
K_startscript, K_stopscript, K_scriptrunning, K_startscript, K_stopscript, K_scriptrunning,
K_getdistance K_getdistance,
K_getsecondspassed
}; };
enum special enum special

@ -54,6 +54,8 @@ namespace Interpreter
virtual void stopScript (const std::string& name) = 0; virtual void stopScript (const std::string& name) = 0;
virtual float getDistance (const std::string& name) = 0; virtual float getDistance (const std::string& name) = 0;
virtual float getSecondsPassed() const = 0;
}; };
} }

@ -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 47: start script stack[0] and pop
op 48: stop 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] 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 opcodes 33554432-67108863 reserved for extensions

@ -88,6 +88,7 @@ namespace Interpreter
interpreter.installSegment3 (0, new OpMessageBox); interpreter.installSegment3 (0, new OpMessageBox);
interpreter.installSegment5 (38, new OpMenuMode); interpreter.installSegment5 (38, new OpMenuMode);
interpreter.installSegment5 (45, new OpRandom); interpreter.installSegment5 (45, new OpRandom);
interpreter.installSegment5 (50, new OpGetSecondsPassed);
// script control // script control
interpreter.installSegment5 (46, new OpScriptRunning); interpreter.installSegment5 (46, new OpScriptRunning);

@ -116,8 +116,20 @@ namespace Interpreter
Type_Integer value = static_cast<Type_Integer> (r*limit); // [o, limit) Type_Integer value = static_cast<Type_Integer> (r*limit); // [o, limit)
runtime[0] = *reinterpret_cast<Type_Data *> (&value); runtime[0] = *reinterpret_cast<Type_Data *> (&value);
} }
}; };
class OpGetSecondsPassed : public Opcode0
{
public:
virtual void execute (Runtime& runtime)
{
float duration = runtime.getContext().getSecondsPassed();
runtime.push (*reinterpret_cast<Type_Data *> (&duration));
}
};
} }
#endif #endif

Loading…
Cancel
Save