1 ! (c)2009 Joe Groff bsd license
2 USING: accessors combinators fry game.input game.loop generic kernel math
3 parser sequences ui ui.gadgets ui.gadgets.worlds ui.gestures threads
7 TUPLE: game-world < world
9 { tick-slice float initial: 0.0 } ;
11 GENERIC: tick-interval-micros ( world -- micros )
13 GENERIC: begin-game-world ( world -- )
14 M: object begin-game-world drop ;
16 GENERIC: end-game-world ( world -- )
17 M: object end-game-world drop ;
20 swap >>tick-slice relayout-1 yield ;
22 M: game-world begin-world
25 dup [ tick-interval-micros ] [ ] bi <game-loop> [ >>game-loop ] keep start-loop
28 M: game-world end-world
29 [ [ stop-loop ] when* f ] change-game-loop
33 TUPLE: game-attributes < world-attributes
34 { tick-interval-micros fixnum read-only } ;
38 : verify-game-attributes ( attributes -- )
41 world-class>> { f world } member?
42 [ "GAME: must be given a custom world-class" throw ] when
45 tick-interval-micros>> 0 <=
46 [ "GAME: must be given a nonzero tick-interval-micros" throw ] when
50 : define-game-tick-interval-micros ( attributes -- )
51 [ world-class>> \ tick-interval-micros create-method ]
52 [ tick-interval-micros>> '[ drop _ ] ] bi
55 : define-game-methods ( attributes -- )
57 [ verify-game-attributes ]
58 [ define-game-tick-interval-micros ]
61 : define-game ( word attributes quot -- )
62 [ define-main-window ]
63 [ drop nip define-game-methods ] 3bi ;
69 game-attributes parse-main-window-attributes