aboutsummaryrefslogtreecommitdiff
path: root/src/script/embed/boot.lua.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/embed/boot.lua.h')
-rw-r--r--src/script/embed/boot.lua.h95
1 files changed, 55 insertions, 40 deletions
diff --git a/src/script/embed/boot.lua.h b/src/script/embed/boot.lua.h
index bd2574a..822e1cf 100644
--- a/src/script/embed/boot.lua.h
+++ b/src/script/embed/boot.lua.h
@@ -1,8 +1,5 @@
/* boot.lua */
static const char* boot_lua = R"(
---[[
- program entry
-]]
local function _onEvent(e)
-- update keyboard status
@@ -44,24 +41,38 @@ if jin._argv[3] == '-d' then
end
function jin.core.run()
- local now = jin.time.second()
+ local load = jin.core.load
+ local running = jin.core.running
+ local second = jin.time.second
+ local sleep = jin.time.sleep
+ local poll = jin.event.poll
+ local unbind = jin.graphics.unbind
+ local clear = jin.graphics.clear
+ local color = jin.graphics.color
+ local study = jin.graphics.study
+ local onDraw = jin.core.onDraw
+ local onUpdate = jin.core.onUpdate
+ local present = jin.graphics.present
+
+ if load then
+ load()
+ end
+
+ local now = second()
local last = now
local fsec = 1/conf.fps
- -- for loading resources
- if jin.core.load then
- jin.core.load()
- end
local dt = 0
- while(jin.core.running()) do
+
+ while(running()) do
-- frame controle
last = now
- now = jin.time.second()
+ now = second()
if (now - last) < fsec then
- jin.time.sleep(fsec - now + last)
+ sleep(fsec - now + last)
end
-- handle events
- for _, e in pairs(jin.event.poll()) do
+ for _, e in pairs(poll()) do
if _onEvent then
_onEvent(e)
end
@@ -72,29 +83,28 @@ function jin.core.run()
if dt < fsec then
dt = fsec
end
- if jin.core.onUpdate then
- jin.core.onUpdate(dt)
+ if onUpdate then
+ onUpdate(dt)
end
-- bind to default render buffer
- jin.graphics.bind()
- jin.graphics.clear()
- jin.graphics.color()
- jin.graphics.study()
+ unbind()
+ clear()
+ color()
+ study()
-- custom drawing
- if jin.core.onDraw then
- jin.core.onDraw()
+ if onDraw then
+ onDraw()
end
-- render debug window
if jin.debug.status() then
jin.debug.render()
- end
+ end
-- swap window buffer
- jin.graphics.present()
-
+ present()
end
end
@@ -113,23 +123,28 @@ local function onError(msg)
end
end
-if jin.filesystem.exist("main.lua") then
- -- require main game script
- xpcall(function() require"main" end, onError)
- jin.core.run()
-else
- -- no game
- function jin.core.onEvent(e)
- if e.type == 'quit' then
- jin.core.quit()
+local function main()
+ if jin.filesystem.exist("main.lua") then
+ -- require main game script
+ xpcall(function() require"main" end, onError)
+ jin.core.run()
+ else
+ -- no game
+ function jin.core.onEvent(e)
+ if e.type == 'quit' then
+ jin.core.quit()
+ end
end
+ function jin.core.onDraw()
+ jin.graphics.clear(111, 134, 125, 255)
+ local ww, wh = jin.graphics.size()
+ local fw, fh = jin.graphics.box("no game", 20, 1, 20)
+ jin.graphics.write("no game", ww /2 - fw / 2, wh * 2/3, 16, 1, 18)
+ end
+ jin.core.run()
end
- function jin.core.onDraw()
- jin.graphics.clear(111, 134, 125, 255)
- local ww, wh = jin.graphics.size()
- local fw, fh = jin.graphics.box("no game", 20, 1, 20)
- jin.graphics.write("no game", ww /2 - fw / 2, wh * 2/3, 16, 1, 18)
- end
- jin.core.run()
-end
+end
+
+main()
+
)";