clean up game-input.backend init so that loading a backend does not ruin the game-input-backend var and so that client code does not need to explicitly load game-input.backend itself

db4
Joe Groff 2008-07-29 19:53:00 -07:00
parent 0ed6fb0555
commit bbc3c01a8b
6 changed files with 40 additions and 14 deletions

View File

@ -1,8 +1,19 @@
USING: kernel system combinators parser ;
USING: multiline system parser combinators ;
IN: game-input.backend
<< {
{ [ os macosx? ] [ "game-input.backend.iokit" use+ ] }
{ [ os windows? ] [ "game-input.backend.dinput" use+ ] }
STRING: set-backend-for-macosx
USING: namespaces game-input.backend.iokit game-input ;
iokit-game-input-backend game-input-backend set-global
;
STRING: set-backend-for-windows
USING: namespaces game-input.backend.dinput game-input ;
dinput-game-input-backend game-input-backend set-global
;
{
{ [ os macosx? ] [ set-backend-for-macosx eval ] }
{ [ os windows? ] [ set-backend-for-windows eval ] }
{ [ t ] [ ] }
} cond >>
} cond

View File

@ -206,6 +206,13 @@ M: dinput-game-input-backend (close-game-input)
close-device-change-window
delete-dinput ;
M: dinput-game-input-backend (reset-game-input)
{
+dinput+ +keyboard-device+ +keyboard-state+
+controller-devices+ +controller-guids+
+device-change-window+ +device-change-handle+
} [ f swap set-global ] each ;
M: dinput-game-input-backend get-controllers
+controller-devices+ get
[ drop controller boa ] { } assoc>map ;
@ -278,5 +285,3 @@ M: dinput-game-input-backend read-keyboard
+keyboard-device+ get
[ +keyboard-state+ get [ keys>> underlying>> get-device-state ] keep ]
[ ] [ f ] with-acquisition ;
dinput-game-input-backend game-input-backend set-global

View File

@ -231,6 +231,10 @@ M: iokit-game-input-backend (open-game-input)
]
} cleave ;
M: iokit-game-input-backend (reset-game-input)
{ +hid-manager+ +keyboard-state+ +controller-states+ }
[ f swap set-global ] each ;
M: iokit-game-input-backend (close-game-input)
+hid-manager+ get-global [
+hid-manager+ global [
@ -271,5 +275,3 @@ M: iokit-game-input-backend read-keyboard ( -- keyboard-state )
M: iokit-game-input-backend calibrate-controller ( controller -- )
drop ;
iokit-game-input-backend game-input-backend set-global

View File

@ -1,26 +1,34 @@
USING: arrays accessors continuations kernel symbols
combinators.lib sequences namespaces init ;
combinators.lib sequences namespaces init vocabs ;
IN: game-input
SYMBOLS: game-input-backend game-input-opened ;
HOOK: (open-game-input) game-input-backend ( -- )
HOOK: (close-game-input) game-input-backend ( -- )
HOOK: (reset-game-input) game-input-backend ( -- )
: game-input-opened? ( -- ? )
game-input-opened get ;
<PRIVATE
M: f (reset-game-input) ;
: reset-game-input ( -- )
game-input-opened off ;
game-input-opened off
(reset-game-input) ;
: load-game-input-backend ( -- )
game-input-backend get
[ "game-input.backend" load-vocab drop ] unless ;
[ reset-game-input ] "game-input" add-init-hook
PRIVATE>
: open-game-input ( -- )
load-game-input-backend
game-input-opened? [
(open-game-input)
game-input-opened on

View File

@ -1,6 +1,6 @@
USING: ui ui.gadgets sequences kernel arrays math colors
ui.render math.vectors accessors fry ui.gadgets.packs game-input
game-input.backend ui.gadgets.labels ui.gadgets.borders alarms
ui.gadgets.labels ui.gadgets.borders alarms
calendar locals combinators.lib strings ui.gadgets.buttons
combinators math.parser assocs threads ;
IN: joystick-demo

View File

@ -1,4 +1,4 @@
USING: game-input game-input.backend game-input.scancodes
USING: game-input game-input.scancodes
kernel ui.gadgets ui.gadgets.buttons sequences accessors
words arrays assocs math calendar fry alarms ui
ui.gadgets.borders ui.gestures ;