diff options
Diffstat (limited to 'src/lua/embed/boot.lua.h')
-rw-r--r-- | src/lua/embed/boot.lua.h | 130 |
1 files changed, 72 insertions, 58 deletions
diff --git a/src/lua/embed/boot.lua.h b/src/lua/embed/boot.lua.h index 13368d6..212a1e5 100644 --- a/src/lua/embed/boot.lua.h +++ b/src/lua/embed/boot.lua.h @@ -1,11 +1,28 @@ /* boot.lua */ static const char* boot_lua = R"( --- Set game root directory jin.args[2] = jin.args[2] or '.' jin.filesystem.init() jin.filesystem.mount(jin.args[2]) +------------------------------------------------------------------------- +-- Config game +------------------------------------------------------------------------- + jin.config = {} +if jin.filesystem.exist("config.lua") then + xpcall(function()jin.config = require "config" end, function()end) +end +jin.config.width = jin.config.width or 580 +jin.config.height = jin.config.height or 450 +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 + +------------------------------------------------------------------------- +-- Default game loop +------------------------------------------------------------------------- local function call(func, ...) if func then @@ -13,20 +30,9 @@ local function call(func, ...) end end -local function open_sub_systems() - jin.audio.init() - jin.graphics.init(jin.config) -end - -local function close_sub_systems() - jin.audio.destroy() - jin.graphics.destroy() -end - --- Default game loop function jin.core.run() - call(jin.core.onLoad) jin.graphics.reset() + call(jin.core.onLoad) local dt = 0 local previous = jin.time.second() local current = previous @@ -50,52 +56,12 @@ function jin.core.run() end end -local function noGame() - jin.core.onLoad = nil - jin.core.onEvent = function(e) - if e.type == "Quit" then - jin.core.stop() - end - end - jin.core.onUpdate = nil - jin.core.onDraw = function() - jin.graphics.print("No game", 5, 5) - end -end - -local function main() - -- Load config file - if jin.filesystem.exist("config.lua") then - jin.config = require "config" - end - jin.config.width = jin.config.width or 580 - jin.config.height = jin.config.height or 450 - 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 - - -- Load game source. - if jin.filesystem.exist("main.lua") then - call(function() require"main" end) - else - call(noGame) - end - - open_sub_systems() - - call(jin.core.run) - - close_sub_systems() - - -- Quit - jin.core.quit() -end +------------------------------------------------------------------------- +-- Boot game +------------------------------------------------------------------------- -- Display error message. local function onError(msg) - open_sub_systems() local err = "Error:\n" .. msg .. "\n" .. debug.traceback() jin.graphics.reset() jin.graphics.setClearColor(100, 100, 100, 255) @@ -110,9 +76,57 @@ local function onError(msg) end jin.time.sleep(0.001) end - close_sub_systems() end -xpcall(main, onError) +-- No game screen. +local function noGame() + jin.graphics.reset() + jin.graphics.reset() + jin.graphics.setClearColor(100, 100, 100, 255) + jin.graphics.clear() + jin.graphics.print("No Game", 5, 5) + jin.graphics.present() + while jin.core.running() do + for _, e in pairs(jin.event.poll()) do + if e.type == "Quit" then + jin.core.stop() + end + end + jin.time.sleep(0.001) + end +end + +local function boot() + if jin.filesystem.exist("main.lua") then + call(function() + require"main" + jin.core.run() + end) + else + noGame() + end +end + +------------------------------------------------------------------------- +-- Initialize sub systems +------------------------------------------------------------------------- + +jin.audio.init() +jin.graphics.init(jin.config) + +xpcall(boot, onError) + +------------------------------------------------------------------------- +-- Destroy sub-systems +------------------------------------------------------------------------- + +jin.graphics.destroy() +jin.audio.destroy() + +------------------------------------------------------------------------- +-- Quit game +------------------------------------------------------------------------- + +jin.core.quit() )";
\ No newline at end of file |