Skip to content

Instantly share code, notes, and snippets.

@terryjsmith
Created September 15, 2016 00:01
Show Gist options
  • Save terryjsmith/5c3d2946eb3b6deee7cf4c5bff889fa6 to your computer and use it in GitHub Desktop.
Save terryjsmith/5c3d2946eb3b6deee7cf4c5bff889fa6 to your computer and use it in GitHub Desktop.
float ScriptTime::m_delta = 0;
ScriptTime::ScriptTime() {
m_delta = 0;
}
ScriptTime::~ScriptTime() {
}
void ScriptTime::Initialize(v8::Isolate* isolate, v8::Local<v8::Context> context) {
StartTemplate(isolate);
SetGlobalName("Time");
AddVariable("deltaTime", GetDelta);
EndTemplate(context);
}
v8::Local<v8::Value> ScriptTime::GetDelta(v8::Isolate* isolate) {
return(v8::Number::New(isolate, m_delta));
}
/**
* Create a global "Time" variable
*/
class ScriptTime : public ScriptGlobal<ScriptTime> {
public:
ScriptTime();
~ScriptTime();
/**
* Initialize our variable in JS namespace
*/
static void Initialize(v8::Isolate* isolate, v8::Local<v8::Context> context);
/**
* Set our time delta
*/
static void SetDelta(float delta) { m_delta = delta; }
/**
* Accessor functions
*/
static v8::Local<v8::Value> GetDelta(v8::Isolate* isolate);
protected:
static float m_delta;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment