main-loop.nv
· 2.4 KiB · Text
Bruto
Playground
|_| Ports for reading and writing events
|#state|
{ event_args = {}
, dt = 0
}
|#port, on start polling, needs, @start polling|
|#port body, on start polling, Lua|
love.event.pump()
self.state.event_iter = love.event.poll()
|#port, on poll input, needs, @poll input|
, @event keypressed
, @event keyreleased
, @event mousemoved
, @event mouse pressed
, @no events left
|#port body, on poll input, Lua|
local name, a, b, c, d, e, f = self.state.event_iter()
if name then
local counter = "@event " .. name
if counters[counter] then
counters[counter] = 1
self.state.event_args[1] = a
self.state.event_args[2] = b
self.state.event_args[3] = c
self.state.event_args[4] = d
self.state.event_args[5] = e
self.state.event_args[6] = f
end
else
counters["@no events left"] = 1
end
|#port, on quit love, needs, @quit love|
@exit code
|#port body, on quit love, Lua|
counters["@exit code"] = self.state.event_args[1] or
|#port, on step timer, needs, @step timer|
|#port body, on step timer, Lua|
self.state.dt = love.timer.step()
|#port, on clear screen, needs, @clear screen|
|#port body, on clear screen, Lua|
love.graphics.origin()
love.graphics.clear(love.graphics.getBackgroundColor())
|#port, on present, needs, @present|
|#port body, on present, Lua|
love.graphics.present()
|#port, on sleep, needs, @sleep, takes, @ms|
|#port body, on sleep, Lua|
love.timer.sleep(ms / 1000)
|_| Dummy event handlers
|handling input|
|updating scene|
|drawing scene|
|_| The main application loop
|run main loop|
, start polling inputs
, poll input
, handle input
, run current frame
|start polling inputs|
, @start polling
|poll input|
, @poll input
|handle input, @no events left|
|handle input|
, handling input
, poll input
, handle input
|run current frame, @event quit|
, @quit love
|run current frame|
, step timer
, clear the screen
, update scene state
, draw scene
, present current frame
, sleep for 1ms
, next cycle
| step timer | @step timer
| clear the screen | @clear screen
| update scene state | updating scene
| draw scene | drawing scene
| present current frame | @present
| sleep for 1ms | @ms
| next cycle | run main loop
1 | |_| Ports for reading and writing events |
2 | |#state| |
3 | { event_args = {} |
4 | , dt = 0 |
5 | } |
6 | |
7 | |#port, on start polling, needs, @start polling| |
8 | |#port body, on start polling, Lua| |
9 | love.event.pump() |
10 | self.state.event_iter = love.event.poll() |
11 | |
12 | |#port, on poll input, needs, @poll input| |
13 | , @event keypressed |
14 | , @event keyreleased |
15 | , @event mousemoved |
16 | , @event mouse pressed |
17 | , @no events left |
18 | |#port body, on poll input, Lua| |
19 | local name, a, b, c, d, e, f = self.state.event_iter() |
20 | if name then |
21 | local counter = "@event " .. name |
22 | if counters[counter] then |
23 | counters[counter] = 1 |
24 | self.state.event_args[1] = a |
25 | self.state.event_args[2] = b |
26 | self.state.event_args[3] = c |
27 | self.state.event_args[4] = d |
28 | self.state.event_args[5] = e |
29 | self.state.event_args[6] = f |
30 | end |
31 | else |
32 | counters["@no events left"] = 1 |
33 | end |
34 | |
35 | |#port, on quit love, needs, @quit love| |
36 | @exit code |
37 | |#port body, on quit love, Lua| |
38 | counters["@exit code"] = self.state.event_args[1] or |
39 | |
40 | |#port, on step timer, needs, @step timer| |
41 | |#port body, on step timer, Lua| |
42 | self.state.dt = love.timer.step() |
43 | |
44 | |#port, on clear screen, needs, @clear screen| |
45 | |#port body, on clear screen, Lua| |
46 | love.graphics.origin() |
47 | love.graphics.clear(love.graphics.getBackgroundColor()) |
48 | |
49 | |#port, on present, needs, @present| |
50 | |#port body, on present, Lua| |
51 | love.graphics.present() |
52 | |
53 | |#port, on sleep, needs, @sleep, takes, @ms| |
54 | |#port body, on sleep, Lua| |
55 | love.timer.sleep(ms / 1000) |
56 | |
57 | |_| Dummy event handlers |
58 | |handling input| |
59 | |updating scene| |
60 | |drawing scene| |
61 | |
62 | |_| The main application loop |
63 | |run main loop| |
64 | , start polling inputs |
65 | , poll input |
66 | , handle input |
67 | , run current frame |
68 | |
69 | |start polling inputs| |
70 | , @start polling |
71 | |
72 | |poll input| |
73 | , @poll input |
74 | |
75 | |handle input, @no events left| |
76 | |
77 | |handle input| |
78 | , handling input |
79 | , poll input |
80 | , handle input |
81 | |
82 | |run current frame, @event quit| |
83 | , @quit love |
84 | |
85 | |run current frame| |
86 | , step timer |
87 | , clear the screen |
88 | , update scene state |
89 | , draw scene |
90 | , present current frame |
91 | , sleep for 1ms |
92 | , next cycle |
93 | |
94 | | step timer | @step timer |
95 | | clear the screen | @clear screen |
96 | | update scene state | updating scene |
97 | | draw scene | drawing scene |
98 | | present current frame | @present |
99 | | sleep for 1ms | @ms |
100 | | next cycle | run main loop |
101 |