From 4159cfcc7bce7c9fe073c5dbf22d9482f0f1a9df Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Mon, 1 Mar 2010 23:29:26 -0800 Subject: [PATCH] game.input.*: factor out callback implementations to separate words so they optimize --- basis/game/input/dinput/dinput.factor | 38 ++++++++++++---------- basis/game/input/iokit/iokit.factor | 47 ++++++++++++++------------- 2 files changed, 45 insertions(+), 40 deletions(-) diff --git a/basis/game/input/dinput/dinput.factor b/basis/game/input/dinput/dinput.factor index a95dbd06c3..7eae826aa5 100755 --- a/basis/game/input/dinput/dinput.factor +++ b/basis/game/input/dinput/dinput.factor @@ -92,21 +92,22 @@ SYMBOLS: +dinput+ +keyboard-device+ +keyboard-state+ +dinput+ get swap device-guid IDirectInput8W::GetDeviceStatus S_OK = ; +: (find-device-axes-callback) ( lpddoi pvRef -- BOOL ) + +controller-devices+ get at + swap guidType>> { + { [ dup GUID_XAxis = ] [ drop 0.0 >>x ] } + { [ dup GUID_YAxis = ] [ drop 0.0 >>y ] } + { [ dup GUID_ZAxis = ] [ drop 0.0 >>z ] } + { [ dup GUID_RxAxis = ] [ drop 0.0 >>rx ] } + { [ dup GUID_RyAxis = ] [ drop 0.0 >>ry ] } + { [ dup GUID_RzAxis = ] [ drop 0.0 >>rz ] } + { [ dup GUID_Slider = ] [ drop 0.0 >>slider ] } + [ drop ] + } cond drop + DIENUM_CONTINUE ; + : find-device-axes-callback ( -- alien ) - [ ! ( lpddoi pvRef -- BOOL ) - +controller-devices+ get at - swap guidType>> { - { [ dup GUID_XAxis = ] [ drop 0.0 >>x ] } - { [ dup GUID_YAxis = ] [ drop 0.0 >>y ] } - { [ dup GUID_ZAxis = ] [ drop 0.0 >>z ] } - { [ dup GUID_RxAxis = ] [ drop 0.0 >>rx ] } - { [ dup GUID_RyAxis = ] [ drop 0.0 >>ry ] } - { [ dup GUID_RzAxis = ] [ drop 0.0 >>rz ] } - { [ dup GUID_Slider = ] [ drop 0.0 >>slider ] } - [ drop ] - } cond drop - DIENUM_CONTINUE - ] LPDIENUMDEVICEOBJECTSCALLBACKW ; + [ (find-device-axes-callback) ] LPDIENUMDEVICEOBJECTSCALLBACKW ; : find-device-axes ( device controller-state -- controller-state ) swap [ +controller-devices+ get set-at ] 2keep @@ -139,11 +140,12 @@ SYMBOLS: +dinput+ +keyboard-device+ +keyboard-state+ [ device-guid +controller-guids+ get delete-at ] [ com-release ] tri ; +: (find-controller-callback) ( lpddi pvRef -- BOOL ) + drop guidInstance>> add-controller + DIENUM_CONTINUE ; + : find-controller-callback ( -- alien ) - [ ! ( lpddi pvRef -- BOOL ) - drop guidInstance>> add-controller - DIENUM_CONTINUE - ] LPDIENUMDEVICESCALLBACKW ; inline + [ (find-controller-callback) ] LPDIENUMDEVICESCALLBACKW ; : find-controllers ( -- ) +dinput+ get DI8DEVCLASS_GAMECTRL find-controller-callback diff --git a/basis/game/input/iokit/iokit.factor b/basis/game/input/iokit/iokit.factor index efc586e1ef..45ed67dc22 100644 --- a/basis/game/input/iokit/iokit.factor +++ b/basis/game/input/iokit/iokit.factor @@ -251,33 +251,36 @@ M: iokit-game-input-backend reset-mouse 2dup length > [ set-length ] [ 2drop ] if ; +:: (device-matched-callback) ( context result sender device -- ) + { + { [ device mouse-device? ] [ device ?add-mouse-buttons ] } + { [ device controller-device? ] [ + device + device +controller-states+ get set-at + ] } + [ ] + } cond ; + : device-matched-callback ( -- alien ) - [| context result sender device | - { - { [ device controller-device? ] [ - device - device +controller-states+ get set-at - ] } - { [ device mouse-device? ] [ device ?add-mouse-buttons ] } - [ ] - } cond - ] IOHIDDeviceCallback ; + [ (device-matched-callback) ] IOHIDDeviceCallback ; + +:: (device-removed-callback) ( context result sender device -- ) + device +controller-states+ get delete-at ; : device-removed-callback ( -- alien ) - [| context result sender device | - device +controller-states+ get delete-at - ] IOHIDDeviceCallback ; + [ (device-removed-callback) ] IOHIDDeviceCallback ; + +:: (device-input-callback) ( context result sender value -- ) + { + { [ sender mouse-device? ] [ +mouse-state+ get value record-mouse ] } + { [ sender controller-device? ] [ + sender +controller-states+ get at value record-controller + ] } + [ +keyboard-state+ get value record-keyboard ] + } cond ; : device-input-callback ( -- alien ) - [| context result sender value | - { - { [ sender controller-device? ] [ - sender +controller-states+ get at value record-controller - ] } - { [ sender mouse-device? ] [ +mouse-state+ get value record-mouse ] } - [ +keyboard-state+ get value record-keyboard ] - } cond - ] IOHIDValueCallback ; + [ (device-input-callback) ] IOHIDValueCallback ; : initialize-variables ( manager -- ) +hid-manager+ set-global