1 USING: accessors combinators fry game.input game.loop generic kernel math
2 parser sequences ui ui.gadgets ui.gadgets.worlds ui.gestures threads
6 TUPLE: game-world < world
8 { tick-slice float initial: 0.0 } ;
10 GENERIC: tick-interval-micros ( world -- micros )
13 swap >>tick-slice relayout-1 yield ;
15 M: game-world begin-world
17 dup [ tick-interval-micros ] [ ] bi <game-loop> [ >>game-loop ] keep start-loop
20 M: game-world end-world
21 [ [ stop-loop ] when* f ] change-game-loop
25 TUPLE: game-attributes < world-attributes
26 { tick-interval-micros fixnum read-only } ;
28 : verify-game-attributes ( attributes -- )
29 world-class>> { f world } member?
30 [ "GAME: must be given a custom world-class" throw ] when ;
32 : define-game-tick-interval-micros ( attributes -- )
33 [ world-class>> \ tick-interval-micros create-method ]
34 [ tick-interval-micros>> '[ drop _ ] ] bi
37 : define-game-methods ( attributes -- )
39 [ verify-game-attributes ]
40 [ define-game-tick-interval-micros ]
43 : define-game ( word attributes -- )
44 [ [ ] define-main-window ]
45 [ nip define-game-methods ] 2bi ;
49 game-attributes parse-main-window-attributes