diff options
Diffstat (limited to 'src/libjin/core')
-rw-r--r-- | src/libjin/core/game.cpp | 8 | ||||
-rw-r--r-- | src/libjin/core/game.h | 2 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/libjin/core/game.cpp b/src/libjin/core/game.cpp index 4509478..ffd8015 100644 --- a/src/libjin/core/game.cpp +++ b/src/libjin/core/game.cpp @@ -25,6 +25,7 @@ namespace core _running = true; Event e; int previous = getMilliSecond(); + float dt = MS_PER_UPDATE / 1000.0f; while (_running) { while (jin::input::pollEvent(&e)) @@ -32,13 +33,18 @@ namespace core SAFECALL(_onEvent, &e); if (!_running) goto stoploop; } - SAFECALL(_onUpdate); + SAFECALL(_onUpdate, dt); SAFECALL(_onDraw); + wnd->swapBuffers(); const int current = getMilliSecond(); + dt = (current - previous) / 1000.0f; const int wait = MS_PER_UPDATE - (current - previous); previous += MS_PER_UPDATE; if (wait > 0) + { sleep(wait); + dt = MS_PER_UPDATE / 1000.0f; + } else previous = current; } diff --git a/src/libjin/core/game.h b/src/libjin/core/game.h index 31825ba..090e7c6 100644 --- a/src/libjin/core/game.h +++ b/src/libjin/core/game.h @@ -17,7 +17,7 @@ namespace core public: typedef void(*onEvent)(jin::input::Event* e); - typedef void(*onUpdate)(); + typedef void(*onUpdate)(float dt); typedef void(*onDraw)(); struct Setting : SettingBase |