2008-07-20 21:04:47 -04:00
|
|
|
USING: arrays accessors continuations kernel symbols
|
|
|
|
combinators.lib sequences ;
|
2008-07-19 14:04:07 -04:00
|
|
|
IN: game-input
|
|
|
|
|
|
|
|
SYMBOL: game-input-backend
|
|
|
|
|
|
|
|
HOOK: open-game-input game-input-backend ( -- )
|
|
|
|
HOOK: close-game-input game-input-backend ( -- )
|
|
|
|
|
|
|
|
: with-game-input ( quot -- )
|
|
|
|
open-game-input [ close-game-input ] [ ] cleanup ;
|
|
|
|
|
|
|
|
TUPLE: controller handle ;
|
|
|
|
TUPLE: controller-state x y z rx ry rz slider pov buttons ;
|
|
|
|
|
|
|
|
M: controller-state clone
|
|
|
|
call-next-method dup buttons>> clone >>buttons ;
|
|
|
|
|
|
|
|
SYMBOLS:
|
|
|
|
pov-neutral
|
2008-07-19 18:17:12 -04:00
|
|
|
pov-up pov-up-right pov-right pov-down-right
|
|
|
|
pov-down pov-down-left pov-left pov-up-left ;
|
2008-07-19 14:04:07 -04:00
|
|
|
|
|
|
|
HOOK: get-controllers game-input-backend ( -- sequence )
|
|
|
|
|
2008-07-20 21:04:47 -04:00
|
|
|
HOOK: product-string game-input-backend ( controller -- string )
|
|
|
|
HOOK: product-id game-input-backend ( controller -- id )
|
|
|
|
HOOK: instance-id game-input-backend ( controller -- id )
|
|
|
|
|
|
|
|
: find-controller-products ( product-id -- sequence )
|
|
|
|
get-controllers [ product-id = ] with filter ;
|
|
|
|
: find-controller-instance ( product-id instance-id -- controller/f )
|
|
|
|
get-controllers [
|
|
|
|
[ product-id = ]
|
|
|
|
[ instance-id = ] bi+ bi* and
|
|
|
|
] 2with find nip ;
|
2008-07-19 14:04:07 -04:00
|
|
|
|
|
|
|
HOOK: read-controller game-input-backend ( controller -- controller-state )
|
|
|
|
HOOK: calibrate-controller game-input-backend ( controller -- )
|
|
|
|
|
|
|
|
TUPLE: keyboard-state keys ;
|
|
|
|
|
|
|
|
M: keyboard-state clone
|
|
|
|
call-next-method dup keys>> clone >>keys ;
|
|
|
|
|
|
|
|
HOOK: read-keyboard game-input-backend ( -- keyboard-state )
|