aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-07 16:18:25 +0800
committerchai <chaifix@163.com>2018-10-07 16:18:25 +0800
commite66058efea36a8c3b07e204002095db08a7182c9 (patch)
tree8ec4519d9341637725854ab252f81dde879055ea
parent090b303a88b493eca0bde51b5a454043c893b0d8 (diff)
*修改游戏主循环
-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:;
}