aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-08-22 10:23:06 +0800
committerchai <chaifix@163.com>2018-08-22 10:23:06 +0800
commit95df5cf921f57bfeac0d819994210dfcc2dcad14 (patch)
treedc389b9f9b97cdad305f0ce74ced8703c77ac7e1 /src
parentb32c7b47c5de92ff03b68b4fc80edec439b6d117 (diff)
*update
Diffstat (limited to 'src')
-rw-r--r--src/lua/modules/embed/boot.lua.h100
1 files changed, 49 insertions, 51 deletions
diff --git a/src/lua/modules/embed/boot.lua.h b/src/lua/modules/embed/boot.lua.h
index a269df8..5ce20a7 100644
--- a/src/lua/modules/embed/boot.lua.h
+++ b/src/lua/modules/embed/boot.lua.h
@@ -8,25 +8,30 @@ jin.filesystem.mount(jin._argv[2])
-- Config game
-------------------------------------------------------------------------
-local conf = {}
+jin.conf = {}
if jin.filesystem.exist("config.lua") then
- conf = require "config"
+ jin.conf = require "config"
end
-conf.width = conf.width or 576
-conf.height = conf.height or 448
-conf.fps = conf.fps or 60
-conf.vsync = conf.vsync or false
-conf.title = conf.title or ("jin v" .. jin.version())
-conf.resizable = conf.resizable or false
-conf.fullscreen = conf.fullscreen or false
+jin.conf.width = jin.conf.width or 576
+jin.conf.height = jin.conf.height or 448
+jin.conf.FPS = jin.conf.FPS or 60
+jin.conf.vsync = jin.conf.vsync or false
+jin.conf.title = jin.conf.title or ("jin v" .. jin.version())
+jin.conf.resizable = jin.conf.resizable or false
+jin.conf.fullscreen = jin.conf.fullscreen or false
+jin.conf.lockFPS = jin.conf.lockFPS or false
-------------------------------------------------------------------------
-- Initialize sub systems
-------------------------------------------------------------------------
-jin.graphics.init(conf)
+jin.graphics.init(jin.conf)
jin.audio.init()
+-------------------------------------------------------------------------
+-- Default game loop
+-------------------------------------------------------------------------
+
local function call(func, ...)
if func then
return func(...)
@@ -45,12 +50,11 @@ end
function jin.core.run()
call(jin.core.onLoad)
+ local dt = 0
local previous = jin.time.second()
- local SEC_PER_UPDATE = 1 / conf.fps
- local dt = SEC_PER_UPDATE
- local running = true
+ local current = previous
-- TODO: д¼¼ӦøƵʵ
- while(jin.core.running()) do
+ while jin.core.running() do
for _, e in pairs(jin.event.poll()) do
if e.type == "keydown" then
jin.keyboard.set(e.key, true)
@@ -58,45 +62,26 @@ function jin.core.run()
jin.keyboard.set(e.key, false)
end
call(jin.core.onEvent, e)
- running = jin.core.running()
- if not running then break end
end
- if not running then break end
-
- call(jin.core.onUpdate, dt)
- jin.graphics.unbindCanvas()
- jin.graphics.clear()
- jin.graphics.setColor()
- jin.graphics.setFont()
- call(jin.core.onDraw)
- jin.graphics.present()
-
- local current = jin.time.second()
+ previous = current
+ current = jin.time.second()
dt = current - previous
- local wait = SEC_PER_UPDATE - dt
- previous = previous + SEC_PER_UPDATE
- if wait > 0 then
- dt = SEC_PER_UPDATE
- jin.time.sleep(wait)
- else
- previous = current
- end
- end
-end
-local function onError(msg)
- local tab = ' '
- print("Error:\n" .. msg)
- function jin.core.onEvent(e)
- if e.type == 'quit' then
- jin.core.stop()
- end
- end
- local ww, wh = jin.graphics.getSize()
- function jin.core.onDraw()
- jin.graphics.write("Error: ", 10, 10, 30, 3, 30)
- jin.graphics.write(msg, 10, 50)
+ call(jin.core.onUpdate, dt)
+
+ if jin.graphics then
+ jin.graphics.unbindCanvas()
+ jin.graphics.clear()
+ jin.graphics.setColor()
+ jin.graphics.setFont()
+ call(jin.core.onDraw)
+ jin.graphics.present()
+ end
+
+ if jin.time then
+ jin.time.sleep(0.001)
+ end
end
end
@@ -161,6 +146,21 @@ jin.nogame = {
-- Boot jin
-------------------------------------------------------------------------
+local function onError(msg)
+ local tab = ' '
+ print("Error:\n" .. msg)
+ function jin.core.onEvent(e)
+ if e.type == 'quit' then
+ jin.core.stop()
+ end
+ end
+ local ww, wh = jin.graphics.getSize()
+ function jin.core.onDraw()
+ jin.graphics.write("Error: ", 10, 10, 30, 3, 30)
+ jin.graphics.write(msg, 10, 50)
+ end
+end
+
local function boot()
if jin.filesystem.exist("main.lua") then
-- require main game script
@@ -171,10 +171,8 @@ local function boot()
jin.core.setHandler(jin.nogame)
jin.core.run()
end
- -- quit subsystems
jin.graphics.destroy()
jin.audio.destroy()
- -- exit whole game
jin.core.quit()
end