From e6e3c76c1f2829537d368501a74af0646f5559d4 Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 24 Aug 2018 19:03:02 +0800 Subject: *update --- src/lua/modules/embed/boot.lua.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/lua/modules/embed/boot.lua.h') diff --git a/src/lua/modules/embed/boot.lua.h b/src/lua/modules/embed/boot.lua.h index d84ca21..4f8ed94 100644 --- a/src/lua/modules/embed/boot.lua.h +++ b/src/lua/modules/embed/boot.lua.h @@ -14,10 +14,11 @@ if jin.filesystem.exist("config.lua") then end jin.config.width = jin.config.width or 576 jin.config.height = jin.config.height or 448 -jin.config.vsync = jin.config.vsync or false +jin.config.vsync = jin.config.vsync or true jin.config.title = jin.config.title or ("jin v" .. jin.version()) jin.config.resizable = jin.config.resizable or false jin.config.fullscreen = jin.config.fullscreen or false +jin.config.fps = jin.config.fps or 60 ------------------------------------------------------------------------- -- Initialize sub systems @@ -51,6 +52,7 @@ function jin.core.run() local dt = 0 local previous = jin.time.second() local current = previous + local SECOND_PER_FRAME = 1/jin.config.fps while jin.core.running() do for _, e in pairs(jin.event.poll()) do if e.type == "keydown" then @@ -60,25 +62,23 @@ function jin.core.run() end call(jin.core.onEvent, e) end - previous = current current = jin.time.second() - dt = current - previous - - call(jin.core.onUpdate, dt) - - if jin.graphics then - jin.graphics.unbindCanvas() + dt = dt + current - previous + local refresh = false + while dt > SECOND_PER_FRAME do + call(jin.core.onUpdate, SECOND_PER_FRAME) + dt = dt - SECOND_PER_FRAME + refresh = true + end + if refresh and jin.graphics then jin.graphics.clear() - jin.graphics.setColor() - jin.graphics.setFont() call(jin.core.onDraw) jin.graphics.present() - end - + end if jin.time then jin.time.sleep(0.001) - end + end end end -- cgit v1.1-26-g67d0