Add support for application.frameRate

This commit is contained in:
Joshua Granick
2015-05-14 16:29:31 -07:00
parent 2ebbb58493
commit cb87783f2b
8 changed files with 171 additions and 19 deletions

View File

@@ -74,6 +74,15 @@ namespace lime {
}
value lime_application_set_frame_rate (value application, value frameRate) {
Application* app = (Application*)(intptr_t)val_float (application);
app->SetFrameRate (val_number (frameRate));
return alloc_null ();
}
value lime_application_update (value application) {
Application* app = (Application*)(intptr_t)val_float (application);
@@ -992,6 +1001,7 @@ namespace lime {
DEFINE_PRIM (lime_application_exec, 1);
DEFINE_PRIM (lime_application_init, 1);
DEFINE_PRIM (lime_application_quit, 1);
DEFINE_PRIM (lime_application_set_frame_rate, 2);
DEFINE_PRIM (lime_application_update, 1);
DEFINE_PRIM (lime_audio_load, 1);
DEFINE_PRIM (lime_font_get_ascender, 1);

View File

@@ -27,6 +27,8 @@ namespace lime {
currentApplication = this;
framePeriod = 1000.0 / 60.0;
#ifdef EMSCRIPTEN
emscripten_cancel_main_loop ();
emscripten_set_main_loop (UpdateFrame, 0, 0);
@@ -203,7 +205,6 @@ namespace lime {
void SDLApplication::Init () {
framePeriod = 1000.0 / 60.0;
active = true;
lastUpdate = SDL_GetTicks ();
nextUpdate = lastUpdate;
@@ -441,6 +442,21 @@ namespace lime {
}
void SDLApplication::SetFrameRate (double frameRate) {
if (frameRate > 0) {
framePeriod = 1000.0 / frameRate;
} else {
framePeriod = 1000.0;
}
}
static SDL_TimerID timerID = 0;
bool timerActive = false;
bool firstTime = true;

View File

@@ -28,6 +28,7 @@ namespace lime {
virtual int Exec ();
virtual void Init ();
virtual int Quit ();
virtual void SetFrameRate (double frameRate);
virtual bool Update ();
void RegisterWindow (SDLWindow *window);