diff options
Diffstat (limited to 'src/lua/modules/embed')
-rw-r--r-- | src/lua/modules/embed/boot.lua.h | 42 | ||||
-rw-r--r-- | src/lua/modules/embed/embed.h | 18 |
2 files changed, 25 insertions, 35 deletions
diff --git a/src/lua/modules/embed/boot.lua.h b/src/lua/modules/embed/boot.lua.h index 4f8ed94..cc71102 100644 --- a/src/lua/modules/embed/boot.lua.h +++ b/src/lua/modules/embed/boot.lua.h @@ -37,16 +37,6 @@ local function call(func, ...) end end -jin.core.setHandler = function(handler) - if handler == nil then - return - end - jin.core.onLoad = handler.onLoad - jin.core.onEvent = handler.onEvent - jin.core.onUpdate = handler.onUpdate - jin.core.onDraw = handler.onDraw -end - function jin.core.run() call(jin.core.onLoad) local dt = 0 @@ -64,21 +54,12 @@ function jin.core.run() end previous = current current = jin.time.second() - 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() - call(jin.core.onDraw) - jin.graphics.present() - end - if jin.time then - jin.time.sleep(0.001) - end + dt = current - previous + call(jin.core.onUpdate, dt) + call(jin.graphics.clear) + call(jin.core.onDraw) + call(jin.graphics.present) + call(jin.time.sleep, 0.001) end end @@ -86,6 +67,16 @@ end -- No game handler ------------------------------------------------------------------------- +jin.core.setHandler = function(handler) + if handler == nil then + return + end + jin.core.onLoad = handler.onLoad + jin.core.onEvent = handler.onEvent + jin.core.onUpdate = handler.onUpdate + jin.core.onDraw = handler.onDraw +end + jin.nogame = { cs = 64, sw = jin.graphics.getWidth(), @@ -108,6 +99,7 @@ jin.nogame = { end end, onUpdate = function(dt) + print(dt) local nogame = jin.nogame nogame.t = nogame.t + dt * nogame.speed if nogame.t > nogame.ww2 then diff --git a/src/lua/modules/embed/embed.h b/src/lua/modules/embed/embed.h index 18ed1d8..6393454 100644 --- a/src/lua/modules/embed/embed.h +++ b/src/lua/modules/embed/embed.h @@ -7,9 +7,6 @@ namespace jin namespace embed { - /** - * embed lua script to context. - */ #define embed(L, script, name)\ if(luax_loadbuffer(L, script, strlen(script), name) == 0)\ lua_call(L, 0, 0); @@ -32,18 +29,19 @@ namespace embed // embed scripts const jin_Embed scripts[] = { - { "graphics.lua", graphics_lua }, - { "keyboard.lua", keyboard_lua }, - { "mouse.lua", mouse_lua }, - { "boot.lua", boot_lua }, - { 0, 0 } + { "graphics.lua", graphics_lua }, + { "keyboard.lua", keyboard_lua }, + { "mouse.lua", mouse_lua }, + { "boot.lua", boot_lua }, + { 0, 0 } }; // load all emebd lua scripts for (int i = 0; scripts[i].file; ++i) embed(L, scripts[i].source, scripts[i].file); } -} -} + +} // embed +} // jin #endif
\ No newline at end of file |