handle reading from unplugged devices in game-input dinput backend

db4
U-VICTORIA\Administrator 2008-07-26 12:15:23 -07:00
parent 9a0e149791
commit b6e0faae05
2 changed files with 17 additions and 13 deletions

View File

@ -3,7 +3,8 @@ symbols alien.c-types windows.ole32 namespaces assocs kernel
arrays vectors windows.kernel32 windows.com windows.dinput arrays vectors windows.kernel32 windows.com windows.dinput
shuffle windows.user32 windows.messages sequences combinators shuffle windows.user32 windows.messages sequences combinators
math.geometry.rect ui.windows accessors math windows alien math.geometry.rect ui.windows accessors math windows alien
alien.strings io.encodings.utf16 continuations byte-arrays ; alien.strings io.encodings.utf16 continuations byte-arrays
locals ;
IN: game-input.backend.dinput IN: game-input.backend.dinput
SINGLETON: dinput-game-input-backend SINGLETON: dinput-game-input-backend
@ -215,10 +216,13 @@ M: dinput-game-input-backend product-id
M: dinput-game-input-backend instance-id M: dinput-game-input-backend instance-id
handle>> device-guid ; handle>> device-guid ;
: with-acquisition ( device quot -- ) :: with-acquisition ( device acquired-quot succeeded-quot failed-quot -- result/f )
over IDirectInputDevice8W::Acquire ole32-error device IDirectInputDevice8W::Acquire succeeded? [
over [ IDirectInputDevice8W::Unacquire ole32-error ] curry device acquired-quot
[ ] cleanup ; inline [ device IDirectInputDevice8W::Unacquire ole32-error ]
[ ] cleanup
succeeded-quot call
] failed-quot if ; inline
: pov-values : pov-values
{ {
@ -264,19 +268,19 @@ M: dinput-game-input-backend instance-id
dup <byte-array> dup <byte-array>
[ IDirectInputDevice8W::GetDeviceState ole32-error ] keep ; [ IDirectInputDevice8W::GetDeviceState ole32-error ] keep ;
: (read-controller) ( handle template -- state )
clone swap [ "DIJOYSTATE2" heap-size get-device-state ]
[ fill-controller-state ] [ drop f ] with-acquisition ;
M: dinput-game-input-backend read-controller M: dinput-game-input-backend read-controller
! XXX return f if device was disconnected handle>> dup +controller-devices+ get at
handle>> [ +controller-devices+ get at clone ] [ [ (read-controller) ] [ drop f ] if* ;
[ "DIJOYSTATE2" heap-size get-device-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 ;
M: dinput-game-input-backend read-keyboard M: dinput-game-input-backend read-keyboard
+keyboard-device+ get [ +keyboard-device+ get [ 256 get-device-state ]
256 get-device-state [ <keyboard-state> ] [ f ] with-acquisition ;
] with-acquisition <keyboard-state> ;
dinput-game-input-backend game-input-backend set-global dinput-game-input-backend game-input-backend set-global

0
extra/joystick-demo/joystick-demo.factor Normal file → Executable file
View File