capitalex revidoval tento gist . Přejít na revizi
1 file changed, 100 insertions
main-loop.nv(vytvořil soubor)
@@ -0,0 +1,100 @@ | |||
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 |
Novější
Starší