aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Game/Game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/Game/Game.cpp')
-rw-r--r--src/libjin/Game/Game.cpp32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/libjin/Game/Game.cpp b/src/libjin/Game/Game.cpp
index 3f905f2..6dc75ce 100644
--- a/src/libjin/Game/Game.cpp
+++ b/src/libjin/Game/Game.cpp
@@ -26,30 +26,26 @@ namespace core
const int MS_PER_UPDATE = 1000.0f / FPS;
_running = true;
Event e;
- int previous = getMilliSecond();
- int dt = MS_PER_UPDATE;
+ int current = getMilliSecond();
+ int previous = current;
+ int dt = 0;
while (_running)
{
while (jin::input::pollEvent(&e))
{
- if (_onEvent != nullptr)
- _onEvent(&e);
- if (!_running) goto quitloop;
+ if (_onEvent != nullptr)
+ _onEvent(&e);
+ if (!_running)
+ goto quitloop;
}
- if (_onUpdate != nullptr) _onUpdate(dt);
- if (_onDraw != nullptr) _onDraw();
- wnd->swapBuffers();
- const int current = getMilliSecond();
+ previous = current;
+ current = getMilliSecond();
dt = current - previous;
- const int wait = MS_PER_UPDATE - (current - previous);
- previous += MS_PER_UPDATE;
- if (wait > 0)
- {
- sleep(wait);
- dt = MS_PER_UPDATE;
- }
- else
- previous = current;
+ if (_onUpdate != nullptr)
+ _onUpdate(dt);
+ if (_onDraw != nullptr)
+ _onDraw();
+ wnd->swapBuffers();
}
quitloop:;
}