From e66058efea36a8c3b07e204002095db08a7182c9 Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 7 Oct 2018 16:18:25 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9=E6=B8=B8=E6=88=8F=E4=B8=BB=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libjin/Game/Game.cpp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'src') 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:; } -- cgit v1.1-26-g67d0