only report the axes actually on the device

db4
U-VICTORIA\Administrator 2008-07-23 21:35:29 -07:00
parent 73758b10c1
commit ce1eda2fcd
1 changed files with 22 additions and 18 deletions

View File

@ -189,6 +189,7 @@ TUPLE: window-rect < rect window-loc ;
[ com-release f ] change-at ; [ com-release f ] change-at ;
M: dinput-game-input-backend open-game-input M: dinput-game-input-backend open-game-input
+dinput+ get-global [ "game-input already open" throw ] when
create-dinput create-dinput
create-device-change-window create-device-change-window
find-keyboard find-keyboard
@ -234,25 +235,27 @@ M: dinput-game-input-backend instance-id
: >slider ( long -- float ) : >slider ( long -- float )
65535.0 /f ; 65535.0 /f ;
: >pov ( long -- symbol ) : >pov ( long -- symbol )
dup HEX: FFFF and HEX: FFFF = dup HEX: FFFF bitand HEX: FFFF =
[ drop pov-neutral ] [ drop pov-neutral ]
[ 4500 + 9000 /i pov-values nth ] if ; [ 4500 + 9000 /i pov-values nth ] if ;
: >buttons ( alien -- array ) : >buttons ( alien length -- array )
128 memory>byte-array >keys ; memory>byte-array >keys ;
: <controller-state> ( DIJOYSTATE2 -- controller-state ) : (fill-if) ( controller-state DIJOYSTATE2 ? quot -- )
! XXX only transfer elements that are present on device [ drop ] compose [ 2drop ] if ; inline
: fill-controller-state ( controller-state DIJOYSTATE2 -- controller-state )
{ {
[ DIJOYSTATE2-lX >axis ] [ over x>> [ DIJOYSTATE2-lX >axis >>x ] (fill-if) ]
[ DIJOYSTATE2-lY >axis ] [ over y>> [ DIJOYSTATE2-lY >axis >>y ] (fill-if) ]
[ DIJOYSTATE2-lZ >axis ] [ over z>> [ DIJOYSTATE2-lZ >axis >>z ] (fill-if) ]
[ DIJOYSTATE2-lRx >axis ] [ over rx>> [ DIJOYSTATE2-lRx >axis >>rx ] (fill-if) ]
[ DIJOYSTATE2-lRy >axis ] [ over ry>> [ DIJOYSTATE2-lRy >axis >>ry ] (fill-if) ]
[ DIJOYSTATE2-lRz >axis ] [ over rz>> [ DIJOYSTATE2-lRz >axis >>rz ] (fill-if) ]
[ DIJOYSTATE2-rglSlider *long >slider ] [ over slider>> [ DIJOYSTATE2-rglSlider *long >slider >>slider ] (fill-if) ]
[ DIJOYSTATE2-rgdwPOV *uint >pov ] [ over pov>> [ DIJOYSTATE2-rgdwPOV *uint >pov >>pov ] (fill-if) ]
[ DIJOYSTATE2-rgbButtons >buttons ] [ DIJOYSTATE2-rgbButtons over buttons>> length >buttons >>buttons ]
} cleave controller-state boa ; } 2cleave ;
: <keyboard-state> ( byte-array -- keyboard-state ) : <keyboard-state> ( byte-array -- keyboard-state )
>keys keyboard-state boa ; >keys keyboard-state boa ;
@ -263,9 +266,10 @@ M: dinput-game-input-backend instance-id
[ IDirectInputDevice8W::GetDeviceState ole32-error ] keep ; [ IDirectInputDevice8W::GetDeviceState ole32-error ] keep ;
M: dinput-game-input-backend read-controller M: dinput-game-input-backend read-controller
handle>> [ handle>> [ +controller-devices+ get at clone ] [
"DIJOYSTATE2" heap-size get-device-state [ "DIJOYSTATE2" heap-size get-device-state ]
] with-acquisition <controller-state> ; with-acquisition
] bi fill-controller-state ;
M: dinput-game-input-backend calibrate-controller M: dinput-game-input-backend calibrate-controller
handle>> f 0 IDirectInputDevice8W::RunControlPanel ole32-error ; handle>> f 0 IDirectInputDevice8W::RunControlPanel ole32-error ;