]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/game/input/dinput/dinput.factor
factor: trim using lists
[factor.git] / basis / game / input / dinput / dinput.factor
old mode 100755 (executable)
new mode 100644 (file)
index f38b608..a600e6c
@@ -1,13 +1,11 @@
 USING: accessors alien alien.c-types alien.data alien.strings
-arrays assocs byte-arrays combinators combinators.short-circuit
-continuations game.input game.input.dinput.keys-array
-io.encodings.utf16 io.encodings.utf16n kernel locals math
-math.bitwise math.rectangles namespaces parser sequences shuffle
-specialized-arrays ui.backend.windows vectors windows.com
-windows.directx.dinput windows.directx.dinput.constants
-windows.kernel32 windows.messages windows.ole32 windows.errors
-windows.user32 classes.struct ;
-FROM: namespaces => change-global ;
+arrays assocs byte-arrays classes.struct combinators
+combinators.short-circuit game.input
+game.input.dinput.keys-array kernel math math.bitwise
+math.rectangles namespaces sequences specialized-arrays
+ui.backend.windows vectors windows.com windows.directx.dinput
+windows.directx.dinput.constants windows.errors windows.kernel32
+windows.messages windows.ole32 windows.user32 ;
 SPECIALIZED-ARRAY: DIDEVICEOBJECTDATA
 IN: game.input.dinput
 
@@ -24,7 +22,7 @@ SYMBOLS: +dinput+ +keyboard-device+ +keyboard-state+
 
 : create-dinput ( -- )
     f GetModuleHandle DIRECTINPUT_VERSION IDirectInput8W-iid
-    f void* <ref> [ f DirectInput8Create ole32-error ] keep void* deref
+    f void* <ref> [ f DirectInput8Create check-ole32-error ] keep void* deref
     +dinput+ set-global ;
 
 : delete-dinput ( -- )
@@ -32,17 +30,17 @@ SYMBOLS: +dinput+ +keyboard-device+ +keyboard-state+
 
 : device-for-guid ( guid -- device )
     +dinput+ get-global swap f void* <ref>
-    [ f IDirectInput8W::CreateDevice ole32-error ] keep void* deref ;
+    [ f IDirectInput8W::CreateDevice check-ole32-error ] keep void* deref ;
 
 : set-coop-level ( device -- )
     +device-change-window+ get-global DISCL_BACKGROUND DISCL_NONEXCLUSIVE bitor
-    IDirectInputDevice8W::SetCooperativeLevel ole32-error ; inline
+    IDirectInputDevice8W::SetCooperativeLevel check-ole32-error ; inline
 
 : set-data-format ( device format-symbol -- )
-    get-global IDirectInputDevice8W::SetDataFormat ole32-error ; inline
+    get-global IDirectInputDevice8W::SetDataFormat check-ole32-error ; inline
 
 : <buffer-size-diprop> ( size -- DIPROPDWORD )
-    DIPROPDWORD <struct> [
+    DIPROPDWORD new [
         diph>>
         DIPROPDWORD heap-size  >>dwSize
         DIPROPHEADER heap-size >>dwHeaderSize
@@ -53,7 +51,7 @@ SYMBOLS: +dinput+ +keyboard-device+ +keyboard-state+
 
 : set-buffer-size ( device size -- )
     DIPROP_BUFFERSIZE swap <buffer-size-diprop>
-    IDirectInputDevice8W::SetProperty ole32-error ;
+    IDirectInputDevice8W::SetProperty check-ole32-error ;
 
 : configure-keyboard ( keyboard -- )
     [ c_dfDIKeyboard_HID set-data-format ] [ set-coop-level ] bi ;
@@ -75,16 +73,16 @@ SYMBOLS: +dinput+ +keyboard-device+ +keyboard-state+
     GUID_SysMouse device-for-guid
     [ configure-mouse ] [ +mouse-device+ set-global ] bi
     0 0 0 0 8 f <array> mouse-state boa +mouse-state+ set-global
-    MOUSE-BUFFER-SIZE <DIDEVICEOBJECTDATA-array> +mouse-buffer+ set-global ;
+    MOUSE-BUFFER-SIZE DIDEVICEOBJECTDATA <c-array> +mouse-buffer+ set-global ;
 
 : device-info ( device -- DIDEVICEIMAGEINFOW )
-    DIDEVICEINSTANCEW <struct>
+    DIDEVICEINSTANCEW new
         DIDEVICEINSTANCEW heap-size >>dwSize
-    [ IDirectInputDevice8W::GetDeviceInfo ole32-error ] keep ; inline
+    [ IDirectInputDevice8W::GetDeviceInfo check-ole32-error ] keep ; inline
 : device-caps ( device -- DIDEVCAPS )
-    DIDEVCAPS <struct>
+    DIDEVCAPS new
         DIDEVCAPS heap-size >>dwSize
-    [ IDirectInputDevice8W::GetCapabilities ole32-error ] keep ; inline
+    [ IDirectInputDevice8W::GetCapabilities check-ole32-error ] keep ; inline
 
 : device-guid ( device -- guid )
     device-info guidInstance>> ; inline
@@ -113,7 +111,7 @@ SYMBOLS: +dinput+ +keyboard-device+ +keyboard-state+
 : find-device-axes ( device controller-state -- controller-state )
     swap [ +controller-devices+ get-global set-at ] 2keep
     find-device-axes-callback over DIDFT_AXIS
-    IDirectInputDevice8W::EnumObjects ole32-error ;
+    IDirectInputDevice8W::EnumObjects check-ole32-error ;
 
 : controller-state-template ( device -- controller-state )
     controller-state new
@@ -150,7 +148,7 @@ SYMBOLS: +dinput+ +keyboard-device+ +keyboard-state+
 
 : find-controllers ( -- )
     +dinput+ get-global DI8DEVCLASS_GAMECTRL find-controller-callback
-    f DIEDFL_ATTACHEDONLY IDirectInput8W::EnumDevices ole32-error ;
+    f DIEDFL_ATTACHEDONLY IDirectInput8W::EnumDevices check-ole32-error ;
 
 : set-up-controllers ( -- )
     4 <vector> +controller-devices+ set-global
@@ -159,7 +157,7 @@ SYMBOLS: +dinput+ +keyboard-device+ +keyboard-state+
 
 : find-and-remove-detached-devices ( -- )
     +controller-devices+ get-global keys
-    [ device-attached? not ] filter
+    [ device-attached? ] reject
     [ remove-controller ] each ;
 
 : ?device-interface ( dbt-broadcast-hdr -- ? )
@@ -177,7 +175,7 @@ SYMBOLS: +dinput+ +keyboard-device+ +keyboard-state+
     <alien> DEV_BROADCAST_HDR memory>struct ;
 
 : handle-wm-devicechange ( hWnd uMsg wParam lParam -- )
-    [ 2drop ] 2dip swap {
+    2nipd swap {
         { [ dup DBT_DEVICEARRIVAL = ]         [ drop <DEV_BROADCAST_HDR> device-arrived ] }
         { [ dup DBT_DEVICEREMOVECOMPLETE = ]  [ drop <DEV_BROADCAST_HDR> device-removed ] }
         [ 2drop ]
@@ -191,7 +189,7 @@ TUPLE: window-rect < rect window-loc ;
     { 0 0 } >>dim ;
 
 : (device-notification-filter) ( -- DEV_BROADCAST_DEVICEW )
-    DEV_BROADCAST_DEVICEW <struct>
+    DEV_BROADCAST_DEVICEW new
         DEV_BROADCAST_DEVICEW heap-size >>dbcc_size
         DBT_DEVTYP_DEVICEINTERFACE >>dbcc_devicetype ;
 
@@ -245,13 +243,13 @@ M: dinput-game-input-backend (close-game-input)
     delete-dinput ;
 
 M: dinput-game-input-backend (reset-game-input)
-    global [
+    [
         {
             +dinput+ +keyboard-device+ +keyboard-state+
             +controller-devices+ +controller-guids+
             +device-change-window+ +device-change-handle+
         } [ off ] each
-    ] bind ;
+    ] with-global ;
 
 M: dinput-game-input-backend get-controllers
     +controller-devices+ get-global
@@ -259,7 +257,7 @@ M: dinput-game-input-backend get-controllers
 
 M: dinput-game-input-backend product-string
     handle>> device-info tszProductName>>
-    utf16n alien>string ;
+    alien>native-string ;
 
 M: dinput-game-input-backend product-id
     handle>> device-info guidProduct>> ;
@@ -283,7 +281,7 @@ CONSTANT: pov-values
 : >slider ( long -- float )
     65535.0 /f ; inline
 : >pov ( long -- symbol )
-    dup HEX: FFFF bitand HEX: FFFF =
+    dup 0xFFFF bitand 0xFFFF =
     [ drop pov-neutral ]
     [ 2750 + 4500 /i pov-values nth ] if ; inline
 
@@ -305,7 +303,7 @@ CONSTANT: pov-values
 
 : read-device-buffer ( device buffer count -- buffer count' )
     [ DIDEVICEOBJECTDATA heap-size ] 2dip uint <ref>
-    [ 0 IDirectInputDevice8W::GetDeviceData ole32-error ] 2keep uint deref ;
+    [ 0 IDirectInputDevice8W::GetDeviceData check-ole32-error ] 2keep uint deref ;
 
 : (fill-mouse-state) ( state DIDEVICEOBJECTDATA -- state )
     [ dwData>> 32 >signed ] [ dwOfs>> ] bi {
@@ -316,15 +314,15 @@ CONSTANT: pov-values
     } case ;
 
 : fill-mouse-state ( buffer count -- state )
-    iota [ +mouse-state+ get-global ] 2dip swap [ nth (fill-mouse-state) ] curry each ;
+    <iota> [ +mouse-state+ get-global ] 2dip swap [ nth (fill-mouse-state) ] curry each ;
 
 : get-device-state ( device DIJOYSTATE2 -- )
-    [ dup IDirectInputDevice8W::Poll ole32-error ] dip
+    [ dup IDirectInputDevice8W::Poll check-ole32-error ] dip
     [ byte-length ] keep
-    IDirectInputDevice8W::GetDeviceState ole32-error ;
+    IDirectInputDevice8W::GetDeviceState check-ole32-error ;
 
 : (read-controller) ( handle template -- state )
-    swap [ DIJOYSTATE2 <struct> [ get-device-state ] keep ]
+    swap [ DIJOYSTATE2 new [ get-device-state ] keep ]
     [ fill-controller-state ] [ drop f ] with-acquisition ;
 
 M: dinput-game-input-backend read-controller
@@ -332,7 +330,7 @@ M: dinput-game-input-backend read-controller
     [ (read-controller) ] [ drop f ] if* ;
 
 M: dinput-game-input-backend calibrate-controller
-    handle>> f 0 IDirectInputDevice8W::RunControlPanel ole32-error ;
+    handle>> f 0 IDirectInputDevice8W::RunControlPanel check-ole32-error ;
 
 M: dinput-game-input-backend read-keyboard
     +keyboard-device+ get-global