make open-game-input and close-game-input do reference counting. update demos to show this
parent
2ec754e77f
commit
ba213bdc34
|
@ -27,10 +27,10 @@ ARTICLE: "game-input" "Game controller input"
|
|||
{ $subsection mouse-state } ;
|
||||
|
||||
HELP: open-game-input
|
||||
{ $description "Initializes the game input interface. An exception will be thrown if the initialization fails. If the game input interface is already opened, nothing happens." } ;
|
||||
{ $description "Initializes the game input interface. An exception will be thrown if the initialization fails. Calls to open-game-input are reference counted; each call to open-game-input needs a corresponding call to close-game-input to close the game input interface." } ;
|
||||
|
||||
HELP: close-game-input
|
||||
{ $description "Closes the game input interface, releasing any allocated resources. Once this word is called, any remaining " { $link controller } " objects are invalid. If the game input interface is not opened, nothing happens." } ;
|
||||
{ $description "Closes the game input interface, releasing any allocated resources. Once this word is called, any remaining " { $link controller } " objects are invalid." } ;
|
||||
|
||||
HELP: game-input-opened?
|
||||
{ $values { "?" "a boolean" } }
|
||||
|
|
|
@ -1,34 +1,57 @@
|
|||
USING: arrays accessors continuations kernel system
|
||||
USING: arrays accessors continuations kernel math system
|
||||
sequences namespaces init vocabs vocabs.loader combinators ;
|
||||
IN: game-input
|
||||
|
||||
SYMBOLS: game-input-backend game-input-opened ;
|
||||
|
||||
game-input-opened [ 0 ] initialize
|
||||
|
||||
HOOK: (open-game-input) game-input-backend ( -- )
|
||||
HOOK: (close-game-input) game-input-backend ( -- )
|
||||
HOOK: (reset-game-input) game-input-backend ( -- )
|
||||
|
||||
HOOK: get-controllers game-input-backend ( -- sequence )
|
||||
|
||||
HOOK: product-string game-input-backend ( controller -- string )
|
||||
HOOK: product-id game-input-backend ( controller -- id )
|
||||
HOOK: instance-id game-input-backend ( controller -- id )
|
||||
|
||||
HOOK: read-controller game-input-backend ( controller -- controller-state )
|
||||
HOOK: calibrate-controller game-input-backend ( controller -- )
|
||||
|
||||
HOOK: read-keyboard game-input-backend ( -- keyboard-state )
|
||||
|
||||
HOOK: read-mouse game-input-backend ( -- mouse-state )
|
||||
|
||||
HOOK: reset-mouse game-input-backend ( -- )
|
||||
|
||||
: game-input-opened? ( -- ? )
|
||||
game-input-opened get ;
|
||||
game-input-opened get zero? not ;
|
||||
|
||||
<PRIVATE
|
||||
|
||||
M: f (reset-game-input) ;
|
||||
|
||||
: reset-game-input ( -- )
|
||||
game-input-opened off
|
||||
(reset-game-input) ;
|
||||
|
||||
[ reset-game-input ] "game-input" add-init-hook
|
||||
|
||||
PRIVATE>
|
||||
|
||||
ERROR: game-input-not-open ;
|
||||
|
||||
: open-game-input ( -- )
|
||||
game-input-opened? [
|
||||
(open-game-input)
|
||||
game-input-opened on
|
||||
] unless ;
|
||||
] unless
|
||||
game-input-opened [ 1+ ] change-global
|
||||
reset-mouse ;
|
||||
: close-game-input ( -- )
|
||||
game-input-opened [
|
||||
dup zero? [ game-input-not-open ] when
|
||||
1-
|
||||
] change-global
|
||||
game-input-opened? [
|
||||
(close-game-input)
|
||||
reset-game-input
|
||||
|
@ -48,12 +71,6 @@ SYMBOLS:
|
|||
pov-up pov-up-right pov-right pov-down-right
|
||||
pov-down pov-down-left pov-left pov-up-left ;
|
||||
|
||||
HOOK: get-controllers game-input-backend ( -- sequence )
|
||||
|
||||
HOOK: product-string game-input-backend ( controller -- string )
|
||||
HOOK: product-id game-input-backend ( controller -- id )
|
||||
HOOK: instance-id game-input-backend ( controller -- id )
|
||||
|
||||
: find-controller-products ( product-id -- sequence )
|
||||
get-controllers [ product-id = ] with filter ;
|
||||
: find-controller-instance ( product-id instance-id -- controller/f )
|
||||
|
@ -63,25 +80,16 @@ HOOK: instance-id game-input-backend ( controller -- id )
|
|||
[ instance-id = ] 2bi* and
|
||||
] with with find nip ;
|
||||
|
||||
HOOK: read-controller game-input-backend ( controller -- controller-state )
|
||||
HOOK: calibrate-controller game-input-backend ( controller -- )
|
||||
|
||||
TUPLE: keyboard-state keys ;
|
||||
|
||||
M: keyboard-state clone
|
||||
call-next-method dup keys>> clone >>keys ;
|
||||
|
||||
HOOK: read-keyboard game-input-backend ( -- keyboard-state )
|
||||
|
||||
TUPLE: mouse-state dx dy scroll-dx scroll-dy buttons ;
|
||||
|
||||
M: mouse-state clone
|
||||
call-next-method dup buttons>> clone >>buttons ;
|
||||
|
||||
HOOK: read-mouse game-input-backend ( -- mouse-state )
|
||||
|
||||
HOOK: reset-mouse game-input-backend ( -- )
|
||||
|
||||
{
|
||||
{ [ os windows? ] [ "game-input.dinput" require ] }
|
||||
{ [ os macosx? ] [ "game-input.iokit" require ] }
|
||||
|
|
|
@ -162,18 +162,19 @@ M: key-caps-gadget pref-dim* drop KEYBOARD-SIZE ;
|
|||
relayout-1 ;
|
||||
|
||||
M: key-caps-gadget graft*
|
||||
open-game-input
|
||||
dup '[ _ update-key-caps-state ] FREQUENCY every >>alarm
|
||||
drop ;
|
||||
|
||||
M: key-caps-gadget ungraft*
|
||||
alarm>> [ cancel-alarm ] when* ;
|
||||
alarm>> [ cancel-alarm ] when*
|
||||
close-game-input ;
|
||||
|
||||
M: key-caps-gadget handle-gesture
|
||||
drop [ key-down? ] [ key-up? ] bi or not ;
|
||||
|
||||
: key-caps ( -- )
|
||||
[
|
||||
open-game-input
|
||||
<key-caps-gadget> { 5 5 } <border> "Key Caps" open-window
|
||||
] with-ui ;
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ IN: terrain
|
|||
|
||||
CONSTANT: FOV $[ 2.0 sqrt 1+ ]
|
||||
CONSTANT: NEAR-PLANE $[ 1.0 1024.0 / ]
|
||||
CONSTANT: FAR-PLANE 1.0
|
||||
CONSTANT: FAR-PLANE 2.0
|
||||
CONSTANT: EYE-START { 0.5 0.5 1.2 }
|
||||
CONSTANT: TICK-LENGTH $[ 1000 30 /i ]
|
||||
CONSTANT: MOUSE-SCALE $[ 1.0 10.0 / ]
|
||||
|
@ -126,8 +126,8 @@ M: terrain-world draw*
|
|||
GL_TEXTURE_2D GL_TEXTURE0 bind-texture-unit
|
||||
GL_TEXTURE_2D GL_TEXTURE_MIN_FILTER GL_LINEAR glTexParameteri
|
||||
GL_TEXTURE_2D GL_TEXTURE_MAG_FILTER GL_LINEAR glTexParameteri
|
||||
GL_TEXTURE_2D GL_TEXTURE_WRAP_S GL_CLAMP glTexParameteri
|
||||
GL_TEXTURE_2D GL_TEXTURE_WRAP_T GL_CLAMP glTexParameteri ;
|
||||
GL_TEXTURE_2D GL_TEXTURE_WRAP_S GL_CLAMP_TO_EDGE glTexParameteri
|
||||
GL_TEXTURE_2D GL_TEXTURE_WRAP_T GL_CLAMP_TO_EDGE glTexParameteri ;
|
||||
|
||||
M: terrain-world begin-world
|
||||
"2.0" { "GL_ARB_vertex_buffer_object" "GL_ARB_shader_objects" }
|
||||
|
@ -146,10 +146,11 @@ M: terrain-world begin-world
|
|||
>>terrain-program
|
||||
vertex-array >vertex-buffer >>terrain-vertex-buffer
|
||||
TICK-LENGTH over <game-loop> [ >>game-loop ] keep start-loop
|
||||
reset-mouse
|
||||
open-game-input
|
||||
drop ;
|
||||
|
||||
M: terrain-world end-world
|
||||
close-game-input
|
||||
{
|
||||
[ game-loop>> stop-loop ]
|
||||
[ terrain-vertex-buffer>> delete-gl-buffer ]
|
||||
|
@ -177,7 +178,6 @@ M: terrain-world pref-dim* drop { 640 480 } ;
|
|||
|
||||
: terrain-window ( -- )
|
||||
[
|
||||
open-game-input
|
||||
f T{ world-attributes
|
||||
{ world-class terrain-world }
|
||||
{ title "Terrain" }
|
||||
|
|
Loading…
Reference in New Issue