diff --git a/basis/editors/gvim/gvim.factor b/basis/editors/gvim/gvim.factor index 15fd52f5ee..277cd734cc 100644 --- a/basis/editors/gvim/gvim.factor +++ b/basis/editors/gvim/gvim.factor @@ -11,7 +11,10 @@ SINGLETON: gvim HOOK: gvim-path io-backend ( -- path ) M: gvim vim-command ( file line -- string ) - [ gvim-path , "+" swap number>string append , , ] { } make ; + [ + gvim-path , + number>string "+" prepend , , + ] { } make ; gvim vim-editor set-global diff --git a/basis/editors/macvim/macvim.factor b/basis/editors/macvim/macvim.factor index b5f864dcd0..c178207e49 100644 --- a/basis/editors/macvim/macvim.factor +++ b/basis/editors/macvim/macvim.factor @@ -3,11 +3,9 @@ namespaces prettyprint editors make ; IN: editors.macvim -: macvim-location ( file line -- ) +: macvim ( file line -- ) drop [ "open" , "-a" , "MacVim", , ] { } make - try-process ; - -[ macvim-location ] edit-hook set-global - + run-detached drop ; +[ macvim ] edit-hook set-global diff --git a/basis/editors/scite/scite.factor b/basis/editors/scite/scite.factor index 7e8a540b73..605b4d53aa 100644 --- a/basis/editors/scite/scite.factor +++ b/basis/editors/scite/scite.factor @@ -25,7 +25,7 @@ IN: editors.scite number>string "-goto:" prepend , ] { } make ; -: scite-location ( file line -- ) +: scite ( file line -- ) scite-command run-detached drop ; -[ scite-location ] edit-hook set-global +[ scite ] edit-hook set-global diff --git a/basis/editors/textedit/textedit.factor b/basis/editors/textedit/textedit.factor index cccc94b539..4b5f2c6886 100644 --- a/basis/editors/textedit/textedit.factor +++ b/basis/editors/textedit/textedit.factor @@ -2,9 +2,9 @@ USING: definitions io.launcher kernel math math.parser parser namespaces prettyprint editors make ; IN: editors.textedit -: textedit-location ( file line -- ) +: textedit ( file line -- ) drop [ "open" , "-a" , "TextEdit", , ] { } make - try-process ; + run-detached drop ; -[ textedit-location ] edit-hook set-global +[ textedit ] edit-hook set-global diff --git a/basis/editors/textmate/textmate.factor b/basis/editors/textmate/textmate.factor index 8bea085c7f..65395bd590 100644 --- a/basis/editors/textmate/textmate.factor +++ b/basis/editors/textmate/textmate.factor @@ -1,10 +1,9 @@ USING: definitions io.launcher kernel math math.parser parser namespaces prettyprint editors make ; - IN: editors.textmate -: textmate-location ( file line -- ) +: textmate ( file line -- ) [ "mate" , "-a" , "-l" , number>string , , ] { } make - try-process ; + run-detached drop ; -[ textmate-location ] edit-hook set-global +[ textmate ] edit-hook set-global diff --git a/basis/editors/vim/vim-docs.factor b/basis/editors/vim/vim-docs.factor index 7f527bf18f..1ec3a37061 100644 --- a/basis/editors/vim/vim-docs.factor +++ b/basis/editors/vim/vim-docs.factor @@ -3,7 +3,7 @@ USING: definitions editors help help.markup help.syntax io io.files IN: editors.vim ARTICLE: { "vim" "vim" } "Vim support" -"This module makes the " { $link edit } " word work with Vim by setting the " { $link edit-hook } " global variable to call " { $link vim-location } ". The " { $link vim-path } " variable contains the name of the vim executable. The default " { $link vim-path } " is " { $snippet "\"gvim\"" } "." +"This module makes the " { $link edit } " word work with Vim by setting the " { $link edit-hook } " global variable to call " { $link vim } ". The " { $link vim-path } " variable contains the name of the vim executable. The default " { $link vim-path } " is " { $snippet "\"gvim\"" } "." $nl "If you intend to use this module regularly, it helps to have it load during stage 2 bootstrap. On Windows, place the following example " { $snippet ".factor-boot-rc" } " in the directory returned by " { $link home } ":" { $code diff --git a/basis/editors/vim/vim.factor b/basis/editors/vim/vim.factor index f07f257888..88c8b8051e 100644 --- a/basis/editors/vim/vim.factor +++ b/basis/editors/vim/vim.factor @@ -4,7 +4,6 @@ make ; IN: editors.vim SYMBOL: vim-path - SYMBOL: vim-editor HOOK: vim-command vim-editor ( file line -- array ) @@ -12,12 +11,13 @@ SINGLETON: vim M: vim vim-command [ - vim-path get , swap , "+" swap number>string append , + vim-path get , + [ , ] [ number>string "+" prepend , ] bi* ] { } make ; -: vim-location ( file line -- ) - vim-command try-process ; +: vim ( file line -- ) + vim-command run-detached drop ; "vim" vim-path set-global -[ vim-location ] edit-hook set-global -vim vim-editor set-global +[ vim ] edit-hook set-global +\ vim vim-editor set-global diff --git a/basis/game-input/iokit/iokit.factor b/basis/game-input/iokit/iokit.factor index 32440e92b2..68ecaecc29 100755 --- a/basis/game-input/iokit/iokit.factor +++ b/basis/game-input/iokit/iokit.factor @@ -12,10 +12,11 @@ SYMBOLS: +hid-manager+ +keyboard-state+ +mouse-state+ +controller-states+ ; iokit-game-input-backend game-input-backend set-global -: hid-manager-matching ( matching-seq -- alien ) - f 0 IOHIDManagerCreate - [ swap >plist IOHIDManagerSetDeviceMatchingMultiple ] - keep ; +: make-hid-manager ( -- alien ) + f 0 IOHIDManagerCreate ; + +: set-hid-manager-matching ( alien matching-seq -- ) + >plist IOHIDManagerSetDeviceMatchingMultiple ; : devices-from-hid-manager ( manager -- vector ) [ @@ -85,9 +86,6 @@ CONSTANT: hat-switch-matching-hash : ?hat-switch ( device -- ? ) hat-switch-matching-hash ?axis ; -: hid-manager-matching-game-devices ( -- alien ) - game-devices-matching-seq hid-manager-matching ; - : device-property ( device key -- value ) IOHIDDeviceGetProperty [ plist> ] [ f ] if* ; : element-property ( element key -- value ) @@ -288,12 +286,13 @@ M: iokit-game-input-backend reset-mouse 256 +keyboard-state+ set-global ; M: iokit-game-input-backend (open-game-input) - hid-manager-matching-game-devices { + make-hid-manager { [ initialize-variables ] [ device-matched-callback f IOHIDManagerRegisterDeviceMatchingCallback ] [ device-removed-callback f IOHIDManagerRegisterDeviceRemovalCallback ] [ device-input-callback f IOHIDManagerRegisterInputValueCallback ] [ 0 IOHIDManagerOpen mach-error ] + [ game-devices-matching-seq set-hid-manager-matching ] [ CFRunLoopGetMain CFRunLoopDefaultMode IOHIDManagerScheduleWithRunLoop diff --git a/extra/terrain/terrain.factor b/extra/terrain/terrain.factor index fb326ef534..cfacfeb700 100644 --- a/extra/terrain/terrain.factor +++ b/extra/terrain/terrain.factor @@ -6,13 +6,15 @@ opengl.shaders opengl.textures opengl.textures.private sequences sequences.product specialized-arrays.float terrain.generation terrain.shaders ui ui.gadgets ui.gadgets.worlds ui.pixel-formats game-worlds method-chains -math.affine-transforms noise ui.gestures ; +math.affine-transforms noise ui.gestures combinators.short-circuit ; IN: terrain CONSTANT: FOV $[ 2.0 sqrt 1+ ] CONSTANT: NEAR-PLANE $[ 1.0 1024.0 / ] CONSTANT: FAR-PLANE 2.0 CONSTANT: PLAYER-START-LOCATION { 0.5 0.51 0.5 } +CONSTANT: VELOCITY-MODIFIER-NORMAL { 1.0 1.0 1.0 } +CONSTANT: VELOCITY-MODIFIER-FAST { 2.0 1.0 2.0 } CONSTANT: PLAYER-HEIGHT $[ 1.0 256.0 / ] CONSTANT: GRAVITY $[ 1.0 4096.0 / ] CONSTANT: JUMP $[ 1.0 1024.0 / ] @@ -28,13 +30,23 @@ CONSTANT: terrain-vertex-distance { $[ 1.0 512.0 / ] $[ 1.0 512.0 / ] } CONSTANT: terrain-vertex-row-length $[ 512 1 + 2 * ] TUPLE: player - location yaw pitch velocity velocity-modifier ; + location yaw pitch velocity velocity-modifier + reverse-time ; TUPLE: terrain-world < game-world player sky-image sky-texture sky-program terrain terrain-segment terrain-texture terrain-program - terrain-vertex-buffer ; + terrain-vertex-buffer + history ; + +: ( -- player ) + player new + PLAYER-START-LOCATION >>location + 0.0 >>yaw + 0.0 >>pitch + { 0.0 0.0 0.0 } >>velocity + VELOCITY-MODIFIER-NORMAL >>velocity-modifier ; M: terrain-world tick-length drop 1000 30 /i ; @@ -140,12 +152,17 @@ terrain-world H{ :: handle-input ( world -- ) world player>> :> player read-keyboard keys>> :> keys - key-left-shift keys nth [ - { 2.0 1.0 2.0 } player (>>velocity-modifier) - ] when - key-left-shift keys nth [ - { 1.0 1.0 1.0 } player (>>velocity-modifier) - ] unless + + key-left-shift keys nth + VELOCITY-MODIFIER-FAST VELOCITY-MODIFIER-NORMAL ? player (>>velocity-modifier) + + { + [ key-1 keys nth 1 f ? ] + [ key-2 keys nth 2 f ? ] + [ key-3 keys nth 3 f ? ] + [ key-4 keys nth 4 f ? ] + [ key-5 keys nth 10000 f ? ] + } 0|| player (>>reverse-time) key-w keys nth [ player walk-forward ] when key-s keys nth [ player walk-backward ] when @@ -199,11 +216,30 @@ terrain-world H{ : scaled-velocity ( player -- velocity ) [ velocity>> ] [ velocity-modifier>> ] bi v* ; -: tick-player ( world player -- ) +: save-history ( world player -- ) + clone swap history>> push ; + +:: tick-player-reverse ( world player -- ) + player reverse-time>> :> reverse-time + world history>> :> history + history length 0 > [ + history length reverse-time 1 - - 1 max history set-length + history pop world (>>player) + ] when ; + +: tick-player-forward ( world player -- ) + 2dup save-history [ apply-friction apply-gravity ] change-velocity dup scaled-velocity [ v+ [ terrain-segment>> ] dip collide ] curry with change-location drop ; +: tick-player ( world player -- ) + dup reverse-time>> [ + tick-player-reverse + ] [ + tick-player-forward + ] if ; + M: terrain-world tick* [ dup focused?>> [ handle-input ] [ drop ] if ] [ dup player>> tick-player ] bi ; @@ -226,7 +262,8 @@ BEFORE: terrain-world begin-world GL_DEPTH_TEST glEnable GL_TEXTURE_2D glEnable GL_VERTEX_ARRAY glEnableClientState - PLAYER-START-LOCATION 0.0 0.0 { 0.0 0.0 0.0 } { 1.0 1.0 1.0 } player boa >>player + >>player + V{ } clone >>history 0.01 0.01 { 512 512 } perlin-noise-image [ >>sky-image ] keep make-texture [ set-texture-parameters ] keep >>sky-texture