capitalex revised this gist . Go to revision
1 file changed, 557 insertions
generated-text-input.lua(file created)
@@ -0,0 +1,557 @@ | |||
1 | + | local min, max, huge = math.min, math.max, math.huge | |
2 | + | local machine = {} | |
3 | + | ||
4 | + | machine.counters = { | |
5 | + | ["update scene state"] = 0, | |
6 | + | ["draw scene"] = 0, | |
7 | + | ["present current frame"] = 0, | |
8 | + | ["sleep for 1ms"] = 0, | |
9 | + | ["next cycle"] = 0, | |
10 | + | ["updating scene"] = 0, | |
11 | + | ["@present"] = 0, | |
12 | + | ["@sleep"] = 0, | |
13 | + | ["@quit"] = 0, | |
14 | + | ["@poll inputs"] = 0, | |
15 | + | ["@quit love"] = 0, | |
16 | + | ["@text received"] = 0, | |
17 | + | ["@clear screen"] = 0, | |
18 | + | ["@backspace was pressed"] = 0, | |
19 | + | ["@draw buffer"] = 0, | |
20 | + | ["@new line was pressed"] = 0, | |
21 | + | ["@is backspace pressed"] = 0, | |
22 | + | ["@is new line pressed"] = 0, | |
23 | + | ["@is left arrow pressed"] = 0, | |
24 | + | ["@down arrow was pressed"] = 0, | |
25 | + | ["@is up arrow pressed"] = 0, | |
26 | + | ["@up arrow was pressed"] = 0, | |
27 | + | ["@is right arrow pressed"] = 0, | |
28 | + | ["@right arrow was pressed"] = 0, | |
29 | + | ["@push text"] = 0, | |
30 | + | ["@pop text"] = 0, | |
31 | + | ["@break text"] = 0, | |
32 | + | ["@draw cursor"] = 0, | |
33 | + | ["@move cursor left"] = 0, | |
34 | + | ["@move cursor up"] = 0, | |
35 | + | ["@exit code"] = 0, | |
36 | + | ["@move cursor down"] = 0, | |
37 | + | ["@move cursor right"] = 0, | |
38 | + | ["push text to buffer"] = 0, | |
39 | + | ["pop text from buffer"] = 0, | |
40 | + | ["break text"] = 0, | |
41 | + | ["move cursor left"] = 0, | |
42 | + | ["move cursor up"] = 0, | |
43 | + | ["move cursor down"] = 0, | |
44 | + | ["move cursor right"] = 0, | |
45 | + | ["@text input"] = 0, | |
46 | + | ["drawing scene"] = 0, | |
47 | + | ["draw buffer"] = 0, | |
48 | + | ["draw cursor"] = 0, | |
49 | + | ["@left arrow was pressed"] = 0, | |
50 | + | ["handling inputs"] = 0, | |
51 | + | ["handle text edit"] = 0, | |
52 | + | ["handle cursor motion"] = 0, | |
53 | + | ["run main loop"] = 1, | |
54 | + | ["handle text input"] = 0, | |
55 | + | ["handle backspace"] = 0, | |
56 | + | ["handle new line"] = 0, | |
57 | + | ["check for text input event"] = 0, | |
58 | + | ["push received text to buffer"] = 0, | |
59 | + | ["back character from buffer"] = 0, | |
60 | + | ["then pop text from buffer"] = 0, | |
61 | + | ["insert new line"] = 0, | |
62 | + | ["@is down arrow pressed"] = 0, | |
63 | + | ["move cursor"] = 0, | |
64 | + | ["@step timer"] = 0, | |
65 | + | ["poll inputs"] = 0, | |
66 | + | ["handle inputs"] = 0, | |
67 | + | ["run current frame"] = 0, | |
68 | + | ["step timer"] = 0, | |
69 | + | ["clear the screen"] = 0, | |
70 | + | } | |
71 | + | ||
72 | + | function machine.on_poll_inputs(counters) | |
73 | + | end | |
74 | + | ||
75 | + | function machine.on_quit_love(counters) | |
76 | + | end | |
77 | + | ||
78 | + | function machine.on_step_timer(counters) | |
79 | + | end | |
80 | + | ||
81 | + | function machine.on_clear_screen(counters) | |
82 | + | end | |
83 | + | ||
84 | + | function machine.on_present(counters) | |
85 | + | end | |
86 | + | ||
87 | + | function machine.on_sleep(counters, sleep) | |
88 | + | end | |
89 | + | ||
90 | + | function machine.on_text_input(counters) | |
91 | + | end | |
92 | + | ||
93 | + | function machine.on_draw_buffer(counters) | |
94 | + | end | |
95 | + | ||
96 | + | function machine.on_is_backspace_pressed(counters) | |
97 | + | end | |
98 | + | ||
99 | + | function machine.on_is_new_line_pressed(counters) | |
100 | + | end | |
101 | + | ||
102 | + | function machine.on_is_left_arrow_pressed(counters) | |
103 | + | end | |
104 | + | ||
105 | + | function machine.on_is_up_arrow_pressed(counters) | |
106 | + | end | |
107 | + | ||
108 | + | function machine.on_is_down_arrow_pressed(counters) | |
109 | + | end | |
110 | + | ||
111 | + | function machine.on_is_right_arrow_pressed(counters) | |
112 | + | end | |
113 | + | ||
114 | + | function machine.on_push_text(counters) | |
115 | + | end | |
116 | + | ||
117 | + | function machine.on_pop_text(counters) | |
118 | + | end | |
119 | + | ||
120 | + | function machine.on_break_text(counters) | |
121 | + | end | |
122 | + | ||
123 | + | function machine.on_draw_cursor(counters) | |
124 | + | end | |
125 | + | ||
126 | + | function machine.on_move_cursor_left(counters) | |
127 | + | end | |
128 | + | ||
129 | + | function machine.on_move_cursor_up(counters) | |
130 | + | end | |
131 | + | ||
132 | + | function machine.on_move_cursor_down(counters) | |
133 | + | end | |
134 | + | ||
135 | + | function machine.on_move_cursor_right(counters) | |
136 | + | end | |
137 | + | ||
138 | + | function match(self, counters) | |
139 | + | if counters["@poll inputs"] > 0 then | |
140 | + | self.on_poll_inputs(counters) | |
141 | + | counters["@poll inputs"] = 0 | |
142 | + | return true | |
143 | + | end | |
144 | + | if counters["@quit love"] > 0 then | |
145 | + | counters["@exit code"] = 0 | |
146 | + | self.on_quit_love(counters) | |
147 | + | counters["@quit love"] = 0 | |
148 | + | return true | |
149 | + | end | |
150 | + | if counters["@step timer"] > 0 then | |
151 | + | self.on_step_timer(counters) | |
152 | + | counters["@step timer"] = 0 | |
153 | + | return true | |
154 | + | end | |
155 | + | if counters["@clear screen"] > 0 then | |
156 | + | self.on_clear_screen(counters) | |
157 | + | counters["@clear screen"] = 0 | |
158 | + | return true | |
159 | + | end | |
160 | + | if counters["@present"] > 0 then | |
161 | + | self.on_present(counters) | |
162 | + | counters["@present"] = 0 | |
163 | + | return true | |
164 | + | end | |
165 | + | if counters["@sleep"] > 0 then | |
166 | + | self.on_sleep(counters, counters["@sleep"]) | |
167 | + | counters["@sleep"] = 0 | |
168 | + | return true | |
169 | + | end | |
170 | + | if counters["@text input"] > 0 then | |
171 | + | counters["@text received"] = 0 | |
172 | + | self.on_text_input(counters) | |
173 | + | counters["@text input"] = 0 | |
174 | + | return true | |
175 | + | end | |
176 | + | if counters["@draw buffer"] > 0 then | |
177 | + | self.on_draw_buffer(counters) | |
178 | + | counters["@draw buffer"] = 0 | |
179 | + | return true | |
180 | + | end | |
181 | + | if counters["@is backspace pressed"] > 0 then | |
182 | + | counters["@backspace was pressed"] = 0 | |
183 | + | self.on_is_backspace_pressed(counters) | |
184 | + | counters["@is backspace pressed"] = 0 | |
185 | + | return true | |
186 | + | end | |
187 | + | if counters["@is new line pressed"] > 0 then | |
188 | + | counters["@new line was pressed"] = 0 | |
189 | + | self.on_is_new_line_pressed(counters) | |
190 | + | counters["@is new line pressed"] = 0 | |
191 | + | return true | |
192 | + | end | |
193 | + | if counters["@is left arrow pressed"] > 0 then | |
194 | + | counters["@left arrow was pressed"] = 0 | |
195 | + | self.on_is_left_arrow_pressed(counters) | |
196 | + | counters["@is left arrow pressed"] = 0 | |
197 | + | return true | |
198 | + | end | |
199 | + | if counters["@is up arrow pressed"] > 0 then | |
200 | + | counters["@up arrow was pressed"] = 0 | |
201 | + | self.on_is_up_arrow_pressed(counters) | |
202 | + | counters["@is up arrow pressed"] = 0 | |
203 | + | return true | |
204 | + | end | |
205 | + | if counters["@is down arrow pressed"] > 0 then | |
206 | + | counters["@down arrow was pressed"] = 0 | |
207 | + | self.on_is_down_arrow_pressed(counters) | |
208 | + | counters["@is down arrow pressed"] = 0 | |
209 | + | return true | |
210 | + | end | |
211 | + | if counters["@is right arrow pressed"] > 0 then | |
212 | + | counters["@right arrow was pressed"] = 0 | |
213 | + | self.on_is_right_arrow_pressed(counters) | |
214 | + | counters["@is right arrow pressed"] = 0 | |
215 | + | return true | |
216 | + | end | |
217 | + | if counters["@push text"] > 0 then | |
218 | + | self.on_push_text(counters) | |
219 | + | counters["@push text"] = 0 | |
220 | + | return true | |
221 | + | end | |
222 | + | if counters["@pop text"] > 0 then | |
223 | + | self.on_pop_text(counters) | |
224 | + | counters["@pop text"] = 0 | |
225 | + | return true | |
226 | + | end | |
227 | + | if counters["@break text"] > 0 then | |
228 | + | self.on_break_text(counters) | |
229 | + | counters["@break text"] = 0 | |
230 | + | return true | |
231 | + | end | |
232 | + | if counters["@draw cursor"] > 0 then | |
233 | + | self.on_draw_cursor(counters) | |
234 | + | counters["@draw cursor"] = 0 | |
235 | + | return true | |
236 | + | end | |
237 | + | if counters["@move cursor left"] > 0 then | |
238 | + | self.on_move_cursor_left(counters) | |
239 | + | counters["@move cursor left"] = 0 | |
240 | + | return true | |
241 | + | end | |
242 | + | if counters["@move cursor up"] > 0 then | |
243 | + | self.on_move_cursor_up(counters) | |
244 | + | counters["@move cursor up"] = 0 | |
245 | + | return true | |
246 | + | end | |
247 | + | if counters["@move cursor down"] > 0 then | |
248 | + | self.on_move_cursor_down(counters) | |
249 | + | counters["@move cursor down"] = 0 | |
250 | + | return true | |
251 | + | end | |
252 | + | if counters["@move cursor right"] > 0 then | |
253 | + | self.on_move_cursor_right(counters) | |
254 | + | counters["@move cursor right"] = 0 | |
255 | + | return true | |
256 | + | end | |
257 | + | if counters["push text to buffer"] > 0 then | |
258 | + | acc = counters["push text to buffer"] | |
259 | + | counters["push text to buffer"] = max(counters["push text to buffer"] - acc, 0) | |
260 | + | counters["@push text"] = counters["@push text"] + acc * 1 | |
261 | + | return true | |
262 | + | end | |
263 | + | if counters["pop text from buffer"] > 0 then | |
264 | + | acc = counters["pop text from buffer"] | |
265 | + | counters["pop text from buffer"] = max(counters["pop text from buffer"] - acc, 0) | |
266 | + | counters["@pop text"] = counters["@pop text"] + acc * 1 | |
267 | + | return true | |
268 | + | end | |
269 | + | if counters["break text"] > 0 then | |
270 | + | acc = counters["break text"] | |
271 | + | counters["break text"] = max(counters["break text"] - acc, 0) | |
272 | + | counters["@break text"] = counters["@break text"] + acc * 1 | |
273 | + | return true | |
274 | + | end | |
275 | + | if counters["move cursor left"] > 0 then | |
276 | + | acc = counters["move cursor left"] | |
277 | + | counters["move cursor left"] = max(counters["move cursor left"] - acc, 0) | |
278 | + | counters["@move cursor left"] = counters["@move cursor left"] + acc * 1 | |
279 | + | return true | |
280 | + | end | |
281 | + | if counters["move cursor up"] > 0 then | |
282 | + | acc = counters["move cursor up"] | |
283 | + | counters["move cursor up"] = max(counters["move cursor up"] - acc, 0) | |
284 | + | counters["@move cursor up"] = counters["@move cursor up"] + acc * 1 | |
285 | + | return true | |
286 | + | end | |
287 | + | if counters["move cursor down"] > 0 then | |
288 | + | acc = counters["move cursor down"] | |
289 | + | counters["move cursor down"] = max(counters["move cursor down"] - acc, 0) | |
290 | + | counters["@move cursor down"] = counters["@move cursor down"] + acc * 1 | |
291 | + | return true | |
292 | + | end | |
293 | + | if counters["move cursor right"] > 0 then | |
294 | + | acc = counters["move cursor right"] | |
295 | + | counters["move cursor right"] = max(counters["move cursor right"] - acc, 0) | |
296 | + | counters["@move cursor right"] = counters["@move cursor right"] + acc * 1 | |
297 | + | return true | |
298 | + | end | |
299 | + | if counters["drawing scene"] > 0 then | |
300 | + | acc = counters["drawing scene"] | |
301 | + | counters["drawing scene"] = max(counters["drawing scene"] - acc, 0) | |
302 | + | counters["draw cursor"] = counters["draw cursor"] + acc * 1 | |
303 | + | counters["draw buffer"] = counters["draw buffer"] + acc * 1 | |
304 | + | return true | |
305 | + | end | |
306 | + | if counters["draw buffer"] > 0 then | |
307 | + | acc = counters["draw buffer"] | |
308 | + | counters["draw buffer"] = max(counters["draw buffer"] - acc, 0) | |
309 | + | counters["@draw buffer"] = counters["@draw buffer"] + acc * 1 | |
310 | + | return true | |
311 | + | end | |
312 | + | if counters["draw cursor"] > 0 then | |
313 | + | acc = counters["draw cursor"] | |
314 | + | counters["draw cursor"] = max(counters["draw cursor"] - acc, 0) | |
315 | + | counters["@draw cursor"] = counters["@draw cursor"] + acc * 1 | |
316 | + | return true | |
317 | + | end | |
318 | + | if counters["handling inputs"] > 0 then | |
319 | + | acc = counters["handling inputs"] | |
320 | + | counters["handling inputs"] = max(counters["handling inputs"] - acc, 0) | |
321 | + | counters["handle cursor motion"] = counters["handle cursor motion"] + acc * 1 | |
322 | + | counters["handle text edit"] = counters["handle text edit"] + acc * 1 | |
323 | + | return true | |
324 | + | end | |
325 | + | if counters["handle text edit"] > 0 then | |
326 | + | acc = counters["handle text edit"] | |
327 | + | counters["handle text edit"] = max(counters["handle text edit"] - acc, 0) | |
328 | + | counters["handle text input"] = counters["handle text input"] + acc * 1 | |
329 | + | counters["handle backspace"] = counters["handle backspace"] + acc * 1 | |
330 | + | counters["handle new line"] = counters["handle new line"] + acc * 1 | |
331 | + | return true | |
332 | + | end | |
333 | + | if counters["handle text input"] > 0 then | |
334 | + | acc = counters["handle text input"] | |
335 | + | counters["handle text input"] = max(counters["handle text input"] - acc, 0) | |
336 | + | counters["push received text to buffer"] = counters["push received text to buffer"] + acc * 1 | |
337 | + | counters["check for text input event"] = counters["check for text input event"] + acc * 1 | |
338 | + | return true | |
339 | + | end | |
340 | + | if counters["check for text input event"] > 0 then | |
341 | + | acc = counters["check for text input event"] | |
342 | + | counters["check for text input event"] = max(counters["check for text input event"] - acc, 0) | |
343 | + | counters["@text input"] = counters["@text input"] + acc * 1 | |
344 | + | return true | |
345 | + | end | |
346 | + | if counters["push received text to buffer"] > 0 and counters["@text received"] > 0 then | |
347 | + | local acc = huge | |
348 | + | acc = min(acc, counters["push received text to buffer"]) | |
349 | + | acc = min(acc, counters["@text received"]) | |
350 | + | counters["push received text to buffer"] = max(counters["push received text to buffer"] - acc, 0) | |
351 | + | counters["@text received"] = max(counters["@text received"] - acc, 0) | |
352 | + | counters["handle text input"] = counters["handle text input"] + acc * 1 | |
353 | + | counters["move cursor right"] = counters["move cursor right"] + acc * 1 | |
354 | + | counters["push text to buffer"] = counters["push text to buffer"] + acc * 1 | |
355 | + | return true | |
356 | + | end | |
357 | + | if counters["push received text to buffer"] > 0 then | |
358 | + | acc = counters["push received text to buffer"] | |
359 | + | counters["push received text to buffer"] = max(counters["push received text to buffer"] - acc, 0) | |
360 | + | return true | |
361 | + | end | |
362 | + | if counters["handle backspace"] > 0 then | |
363 | + | acc = counters["handle backspace"] | |
364 | + | counters["handle backspace"] = max(counters["handle backspace"] - acc, 0) | |
365 | + | counters["back character from buffer"] = counters["back character from buffer"] + acc * 1 | |
366 | + | counters["@is backspace pressed"] = counters["@is backspace pressed"] + acc * 1 | |
367 | + | return true | |
368 | + | end | |
369 | + | if counters["back character from buffer"] > 0 and counters["@backspace was pressed"] > 0 then | |
370 | + | local acc = huge | |
371 | + | acc = min(acc, counters["@backspace was pressed"]) | |
372 | + | acc = min(acc, counters["back character from buffer"]) | |
373 | + | counters["back character from buffer"] = max(counters["back character from buffer"] - acc, 0) | |
374 | + | counters["@backspace was pressed"] = max(counters["@backspace was pressed"] - acc, 0) | |
375 | + | counters["then pop text from buffer"] = counters["then pop text from buffer"] + acc * 1 | |
376 | + | counters["move cursor left"] = counters["move cursor left"] + acc * 1 | |
377 | + | return true | |
378 | + | end | |
379 | + | if counters["then pop text from buffer"] > 0 then | |
380 | + | acc = counters["then pop text from buffer"] | |
381 | + | counters["then pop text from buffer"] = max(counters["then pop text from buffer"] - acc, 0) | |
382 | + | counters["pop text from buffer"] = counters["pop text from buffer"] + acc * 1 | |
383 | + | return true | |
384 | + | end | |
385 | + | if counters["back character from buffer"] > 0 then | |
386 | + | acc = counters["back character from buffer"] | |
387 | + | counters["back character from buffer"] = max(counters["back character from buffer"] - acc, 0) | |
388 | + | return true | |
389 | + | end | |
390 | + | if counters["handle new line"] > 0 then | |
391 | + | acc = counters["handle new line"] | |
392 | + | counters["handle new line"] = max(counters["handle new line"] - acc, 0) | |
393 | + | counters["insert new line"] = counters["insert new line"] + acc * 1 | |
394 | + | counters["@is new line pressed"] = counters["@is new line pressed"] + acc * 1 | |
395 | + | return true | |
396 | + | end | |
397 | + | if counters["insert new line"] > 0 and counters["@new line was pressed"] > 0 then | |
398 | + | local acc = huge | |
399 | + | acc = min(acc, counters["@new line was pressed"]) | |
400 | + | acc = min(acc, counters["insert new line"]) | |
401 | + | counters["insert new line"] = max(counters["insert new line"] - acc, 0) | |
402 | + | counters["@new line was pressed"] = max(counters["@new line was pressed"] - acc, 0) | |
403 | + | counters["break text"] = counters["break text"] + acc * 1 | |
404 | + | return true | |
405 | + | end | |
406 | + | if counters["insert new line"] > 0 then | |
407 | + | acc = counters["insert new line"] | |
408 | + | counters["insert new line"] = max(counters["insert new line"] - acc, 0) | |
409 | + | return true | |
410 | + | end | |
411 | + | if counters["handle cursor motion"] > 0 then | |
412 | + | acc = counters["handle cursor motion"] | |
413 | + | counters["handle cursor motion"] = max(counters["handle cursor motion"] - acc, 0) | |
414 | + | counters["@is up arrow pressed"] = counters["@is up arrow pressed"] + acc * 1 | |
415 | + | counters["@is down arrow pressed"] = counters["@is down arrow pressed"] + acc * 1 | |
416 | + | counters["@is right arrow pressed"] = counters["@is right arrow pressed"] + acc * 1 | |
417 | + | counters["move cursor"] = counters["move cursor"] + acc * 1 | |
418 | + | counters["@is left arrow pressed"] = counters["@is left arrow pressed"] + acc * 1 | |
419 | + | return true | |
420 | + | end | |
421 | + | if counters["move cursor"] > 0 and counters["@left arrow was pressed"] > 0 then | |
422 | + | local acc = huge | |
423 | + | acc = min(acc, counters["@left arrow was pressed"]) | |
424 | + | acc = min(acc, counters["move cursor"]) | |
425 | + | counters["move cursor"] = max(counters["move cursor"] - acc, 0) | |
426 | + | counters["@left arrow was pressed"] = max(counters["@left arrow was pressed"] - acc, 0) | |
427 | + | counters["move cursor left"] = counters["move cursor left"] + acc * 1 | |
428 | + | counters["move cursor"] = counters["move cursor"] + acc * 1 | |
429 | + | return true | |
430 | + | end | |
431 | + | if counters["move cursor"] > 0 and counters["@up arrow was pressed"] > 0 then | |
432 | + | local acc = huge | |
433 | + | acc = min(acc, counters["@up arrow was pressed"]) | |
434 | + | acc = min(acc, counters["move cursor"]) | |
435 | + | counters["move cursor"] = max(counters["move cursor"] - acc, 0) | |
436 | + | counters["@up arrow was pressed"] = max(counters["@up arrow was pressed"] - acc, 0) | |
437 | + | counters["move cursor up"] = counters["move cursor up"] + acc * 1 | |
438 | + | counters["move cursor"] = counters["move cursor"] + acc * 1 | |
439 | + | return true | |
440 | + | end | |
441 | + | if counters["move cursor"] > 0 and counters["@down arrow was pressed"] > 0 then | |
442 | + | local acc = huge | |
443 | + | acc = min(acc, counters["@down arrow was pressed"]) | |
444 | + | acc = min(acc, counters["move cursor"]) | |
445 | + | counters["move cursor"] = max(counters["move cursor"] - acc, 0) | |
446 | + | counters["@down arrow was pressed"] = max(counters["@down arrow was pressed"] - acc, 0) | |
447 | + | counters["move cursor down"] = counters["move cursor down"] + acc * 1 | |
448 | + | counters["move cursor"] = counters["move cursor"] + acc * 1 | |
449 | + | return true | |
450 | + | end | |
451 | + | if counters["move cursor"] > 0 and counters["@right arrow was pressed"] > 0 then | |
452 | + | local acc = huge | |
453 | + | acc = min(acc, counters["@right arrow was pressed"]) | |
454 | + | acc = min(acc, counters["move cursor"]) | |
455 | + | counters["move cursor"] = max(counters["move cursor"] - acc, 0) | |
456 | + | counters["@right arrow was pressed"] = max(counters["@right arrow was pressed"] - acc, 0) | |
457 | + | counters["move cursor right"] = counters["move cursor right"] + acc * 1 | |
458 | + | counters["move cursor"] = counters["move cursor"] + acc * 1 | |
459 | + | return true | |
460 | + | end | |
461 | + | if counters["move cursor"] > 0 then | |
462 | + | acc = counters["move cursor"] | |
463 | + | counters["move cursor"] = max(counters["move cursor"] - acc, 0) | |
464 | + | return true | |
465 | + | end | |
466 | + | if counters["run main loop"] > 0 then | |
467 | + | acc = counters["run main loop"] | |
468 | + | counters["run main loop"] = max(counters["run main loop"] - acc, 0) | |
469 | + | counters["handle inputs"] = counters["handle inputs"] + acc * 1 | |
470 | + | counters["run current frame"] = counters["run current frame"] + acc * 1 | |
471 | + | counters["poll inputs"] = counters["poll inputs"] + acc * 1 | |
472 | + | return true | |
473 | + | end | |
474 | + | if counters["poll inputs"] > 0 then | |
475 | + | acc = counters["poll inputs"] | |
476 | + | counters["poll inputs"] = max(counters["poll inputs"] - acc, 0) | |
477 | + | counters["@poll inputs"] = counters["@poll inputs"] + acc * 1 | |
478 | + | return true | |
479 | + | end | |
480 | + | if counters["handle inputs"] > 0 then | |
481 | + | acc = counters["handle inputs"] | |
482 | + | counters["handle inputs"] = max(counters["handle inputs"] - acc, 0) | |
483 | + | counters["handling inputs"] = counters["handling inputs"] + acc * 1 | |
484 | + | return true | |
485 | + | end | |
486 | + | if counters["run current frame"] > 0 and counters["@quit"] > 0 then | |
487 | + | local acc = huge | |
488 | + | acc = min(acc, counters["@quit"]) | |
489 | + | acc = min(acc, counters["run current frame"]) | |
490 | + | counters["run current frame"] = max(counters["run current frame"] - acc, 0) | |
491 | + | counters["@quit"] = max(counters["@quit"] - acc, 0) | |
492 | + | counters["@quit love"] = counters["@quit love"] + acc * 1 | |
493 | + | return true | |
494 | + | end | |
495 | + | if counters["run current frame"] > 0 then | |
496 | + | acc = counters["run current frame"] | |
497 | + | counters["run current frame"] = max(counters["run current frame"] - acc, 0) | |
498 | + | counters["update scene state"] = counters["update scene state"] + acc * 1 | |
499 | + | counters["draw scene"] = counters["draw scene"] + acc * 1 | |
500 | + | counters["present current frame"] = counters["present current frame"] + acc * 1 | |
501 | + | counters["sleep for 1ms"] = counters["sleep for 1ms"] + acc * 1 | |
502 | + | counters["next cycle"] = counters["next cycle"] + acc * 1 | |
503 | + | counters["step timer"] = counters["step timer"] + acc * 1 | |
504 | + | counters["clear the screen"] = counters["clear the screen"] + acc * 1 | |
505 | + | return true | |
506 | + | end | |
507 | + | if counters["step timer"] > 0 then | |
508 | + | acc = counters["step timer"] | |
509 | + | counters["step timer"] = max(counters["step timer"] - acc, 0) | |
510 | + | counters["@step timer"] = counters["@step timer"] + acc * 1 | |
511 | + | return true | |
512 | + | end | |
513 | + | if counters["clear the screen"] > 0 then | |
514 | + | acc = counters["clear the screen"] | |
515 | + | counters["clear the screen"] = max(counters["clear the screen"] - acc, 0) | |
516 | + | counters["@clear screen"] = counters["@clear screen"] + acc * 1 | |
517 | + | return true | |
518 | + | end | |
519 | + | if counters["update scene state"] > 0 then | |
520 | + | acc = counters["update scene state"] | |
521 | + | counters["update scene state"] = max(counters["update scene state"] - acc, 0) | |
522 | + | counters["updating scene"] = counters["updating scene"] + acc * 1 | |
523 | + | return true | |
524 | + | end | |
525 | + | if counters["draw scene"] > 0 then | |
526 | + | acc = counters["draw scene"] | |
527 | + | counters["draw scene"] = max(counters["draw scene"] - acc, 0) | |
528 | + | counters["drawing scene"] = counters["drawing scene"] + acc * 1 | |
529 | + | return true | |
530 | + | end | |
531 | + | if counters["present current frame"] > 0 then | |
532 | + | acc = counters["present current frame"] | |
533 | + | counters["present current frame"] = max(counters["present current frame"] - acc, 0) | |
534 | + | counters["@present"] = counters["@present"] + acc * 1 | |
535 | + | return true | |
536 | + | end | |
537 | + | if counters["sleep for 1ms"] > 0 then | |
538 | + | acc = counters["sleep for 1ms"] | |
539 | + | counters["sleep for 1ms"] = max(counters["sleep for 1ms"] - acc, 0) | |
540 | + | counters["@sleep"] = counters["@sleep"] + acc * 1 | |
541 | + | return true | |
542 | + | end | |
543 | + | if counters["next cycle"] > 0 then | |
544 | + | acc = counters["next cycle"] | |
545 | + | counters["next cycle"] = max(counters["next cycle"] - acc, 0) | |
546 | + | counters["run main loop"] = counters["run main loop"] + acc * 1 | |
547 | + | return true | |
548 | + | end | |
549 | + | return false | |
550 | + | end | |
551 | + | ||
552 | + | function machine:run() | |
553 | + | local counters = self.counters | |
554 | + | while match(self, counters) do end | |
555 | + | end | |
556 | + | ||
557 | + | return machine |
Newer
Older