diff options
Diffstat (limited to 'src/libjin')
-rw-r--r-- | src/libjin/Core/Game.cpp | 8 | ||||
-rw-r--r-- | src/libjin/Core/Game.h | 2 | ||||
-rw-r--r-- | src/libjin/Graphics/Drawable.h | 2 | ||||
-rw-r--r-- | src/libjin/core/game.cpp | 8 | ||||
-rw-r--r-- | src/libjin/core/game.h | 2 |
5 files changed, 18 insertions, 4 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 diff --git a/src/libjin/Graphics/Drawable.h b/src/libjin/Graphics/Drawable.h index c05d8a4..0b96379 100644 --- a/src/libjin/Graphics/Drawable.h +++ b/src/libjin/Graphics/Drawable.h @@ -8,6 +8,7 @@ namespace jin { namespace graphics { + class Drawable { public: @@ -51,6 +52,7 @@ namespace graphics float* vertCoord; }; + } // render } // jin 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 |