1 USING: arrays accessors continuations kernel system
2 sequences namespaces init vocabs vocabs.loader combinators ;
5 SYMBOLS: game-input-backend game-input-opened ;
7 HOOK: (open-game-input) game-input-backend ( -- )
8 HOOK: (close-game-input) game-input-backend ( -- )
9 HOOK: (reset-game-input) game-input-backend ( -- )
11 : game-input-opened? ( -- ? )
12 game-input-opened get ;
16 M: f (reset-game-input) ;
18 : reset-game-input ( -- )
22 [ reset-game-input ] "game-input" add-init-hook
26 : open-game-input ( -- )
31 : close-game-input ( -- )
37 : with-game-input ( quot -- )
38 open-game-input [ close-game-input ] [ ] cleanup ;
40 TUPLE: controller handle ;
41 TUPLE: controller-state x y z rx ry rz slider pov buttons ;
43 M: controller-state clone
44 call-next-method dup buttons>> clone >>buttons ;
48 pov-up pov-up-right pov-right pov-down-right
49 pov-down pov-down-left pov-left pov-up-left ;
51 HOOK: get-controllers game-input-backend ( -- sequence )
53 HOOK: product-string game-input-backend ( controller -- string )
54 HOOK: product-id game-input-backend ( controller -- id )
55 HOOK: instance-id game-input-backend ( controller -- id )
57 : find-controller-products ( product-id -- sequence )
58 get-controllers [ product-id = ] with filter ;
59 : find-controller-instance ( product-id instance-id -- controller/f )
63 [ instance-id = ] 2bi* and
64 ] with with find nip ;
66 HOOK: read-controller game-input-backend ( controller -- controller-state )
67 HOOK: calibrate-controller game-input-backend ( controller -- )
69 TUPLE: keyboard-state keys ;
71 M: keyboard-state clone
72 call-next-method dup keys>> clone >>keys ;
74 HOOK: read-keyboard game-input-backend ( -- keyboard-state )
77 { [ os windows? ] [ "game-input.dinput" require ] }
78 { [ os macosx? ] [ "game-input.iokit" require ] }