blob: 030a1510cf380151dfedc41bd2302a962c0c63e3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
local function call(func, ...)
if func then
return func(...)
end
end
function jin.core.run()
call(jin.core.onLoad)
local dt = 0
local previous = jin.time.second()
local current = previous
-- TODO: 重写,事件处理事件应该高频率调用
while jin.core.running() do
for _, e in pairs(jin.event.poll()) do
if e.type == "keydown" then
jin.keyboard.set(e.key, true)
elseif e.type == "keyup" then
jin.keyboard.set(e.key, false)
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()
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
|