Merge branch 'master' of git://factorcode.org/git/factor

db4
Doug Coleman 2009-05-15 19:40:30 -05:00
commit 7c1f4e8839
9 changed files with 77 additions and 41 deletions

View File

@ -11,7 +11,10 @@ SINGLETON: gvim
HOOK: gvim-path io-backend ( -- path ) HOOK: gvim-path io-backend ( -- path )
M: gvim vim-command ( file line -- string ) 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 gvim vim-editor set-global

View File

@ -3,11 +3,9 @@ namespaces prettyprint editors make ;
IN: editors.macvim IN: editors.macvim
: macvim-location ( file line -- ) : macvim ( file line -- )
drop drop
[ "open" , "-a" , "MacVim", , ] { } make [ "open" , "-a" , "MacVim", , ] { } make
try-process ; run-detached drop ;
[ macvim-location ] edit-hook set-global
[ macvim ] edit-hook set-global

View File

@ -25,7 +25,7 @@ IN: editors.scite
number>string "-goto:" prepend , number>string "-goto:" prepend ,
] { } make ; ] { } make ;
: scite-location ( file line -- ) : scite ( file line -- )
scite-command run-detached drop ; scite-command run-detached drop ;
[ scite-location ] edit-hook set-global [ scite ] edit-hook set-global

View File

@ -2,9 +2,9 @@ USING: definitions io.launcher kernel math math.parser parser
namespaces prettyprint editors make ; namespaces prettyprint editors make ;
IN: editors.textedit IN: editors.textedit
: textedit-location ( file line -- ) : textedit ( file line -- )
drop drop
[ "open" , "-a" , "TextEdit", , ] { } make [ "open" , "-a" , "TextEdit", , ] { } make
try-process ; run-detached drop ;
[ textedit-location ] edit-hook set-global [ textedit ] edit-hook set-global

View File

@ -1,10 +1,9 @@
USING: definitions io.launcher kernel math math.parser parser USING: definitions io.launcher kernel math math.parser parser
namespaces prettyprint editors make ; namespaces prettyprint editors make ;
IN: editors.textmate IN: editors.textmate
: textmate-location ( file line -- ) : textmate ( file line -- )
[ "mate" , "-a" , "-l" , number>string , , ] { } make [ "mate" , "-a" , "-l" , number>string , , ] { } make
try-process ; run-detached drop ;
[ textmate-location ] edit-hook set-global [ textmate ] edit-hook set-global

View File

@ -3,7 +3,7 @@ USING: definitions editors help help.markup help.syntax io io.files
IN: editors.vim IN: editors.vim
ARTICLE: { "vim" "vim" } "Vim support" 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 $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 } ":" "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 { $code

View File

@ -4,7 +4,6 @@ make ;
IN: editors.vim IN: editors.vim
SYMBOL: vim-path SYMBOL: vim-path
SYMBOL: vim-editor SYMBOL: vim-editor
HOOK: vim-command vim-editor ( file line -- array ) HOOK: vim-command vim-editor ( file line -- array )
@ -12,12 +11,13 @@ SINGLETON: vim
M: vim vim-command M: vim vim-command
[ [
vim-path get , swap , "+" swap number>string append , vim-path get ,
[ , ] [ number>string "+" prepend , ] bi*
] { } make ; ] { } make ;
: vim-location ( file line -- ) : vim ( file line -- )
vim-command try-process ; vim-command run-detached drop ;
"vim" vim-path set-global "vim" vim-path set-global
[ vim-location ] edit-hook set-global [ vim ] edit-hook set-global
vim vim-editor set-global \ vim vim-editor set-global

View File

@ -12,10 +12,11 @@ SYMBOLS: +hid-manager+ +keyboard-state+ +mouse-state+ +controller-states+ ;
iokit-game-input-backend game-input-backend set-global iokit-game-input-backend game-input-backend set-global
: hid-manager-matching ( matching-seq -- alien ) : make-hid-manager ( -- alien )
f 0 IOHIDManagerCreate f 0 IOHIDManagerCreate ;
[ swap >plist IOHIDManagerSetDeviceMatchingMultiple ]
keep ; : set-hid-manager-matching ( alien matching-seq -- )
>plist IOHIDManagerSetDeviceMatchingMultiple ;
: devices-from-hid-manager ( manager -- vector ) : devices-from-hid-manager ( manager -- vector )
[ [
@ -85,9 +86,6 @@ CONSTANT: hat-switch-matching-hash
: ?hat-switch ( device -- ? ) : ?hat-switch ( device -- ? )
hat-switch-matching-hash ?axis ; hat-switch-matching-hash ?axis ;
: hid-manager-matching-game-devices ( -- alien )
game-devices-matching-seq hid-manager-matching ;
: device-property ( device key -- value ) : device-property ( device key -- value )
<NSString> IOHIDDeviceGetProperty [ plist> ] [ f ] if* ; <NSString> IOHIDDeviceGetProperty [ plist> ] [ f ] if* ;
: element-property ( element key -- value ) : element-property ( element key -- value )
@ -288,12 +286,13 @@ M: iokit-game-input-backend reset-mouse
256 <bit-array> +keyboard-state+ set-global ; 256 <bit-array> +keyboard-state+ set-global ;
M: iokit-game-input-backend (open-game-input) M: iokit-game-input-backend (open-game-input)
hid-manager-matching-game-devices { make-hid-manager {
[ initialize-variables ] [ initialize-variables ]
[ device-matched-callback f IOHIDManagerRegisterDeviceMatchingCallback ] [ device-matched-callback f IOHIDManagerRegisterDeviceMatchingCallback ]
[ device-removed-callback f IOHIDManagerRegisterDeviceRemovalCallback ] [ device-removed-callback f IOHIDManagerRegisterDeviceRemovalCallback ]
[ device-input-callback f IOHIDManagerRegisterInputValueCallback ] [ device-input-callback f IOHIDManagerRegisterInputValueCallback ]
[ 0 IOHIDManagerOpen mach-error ] [ 0 IOHIDManagerOpen mach-error ]
[ game-devices-matching-seq set-hid-manager-matching ]
[ [
CFRunLoopGetMain CFRunLoopDefaultMode CFRunLoopGetMain CFRunLoopDefaultMode
IOHIDManagerScheduleWithRunLoop IOHIDManagerScheduleWithRunLoop

View File

@ -6,13 +6,15 @@ opengl.shaders opengl.textures opengl.textures.private
sequences sequences.product specialized-arrays.float sequences sequences.product specialized-arrays.float
terrain.generation terrain.shaders ui ui.gadgets terrain.generation terrain.shaders ui ui.gadgets
ui.gadgets.worlds ui.pixel-formats game-worlds method-chains 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 IN: terrain
CONSTANT: FOV $[ 2.0 sqrt 1+ ] CONSTANT: FOV $[ 2.0 sqrt 1+ ]
CONSTANT: NEAR-PLANE $[ 1.0 1024.0 / ] CONSTANT: NEAR-PLANE $[ 1.0 1024.0 / ]
CONSTANT: FAR-PLANE 2.0 CONSTANT: FAR-PLANE 2.0
CONSTANT: PLAYER-START-LOCATION { 0.5 0.51 0.5 } 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: PLAYER-HEIGHT $[ 1.0 256.0 / ]
CONSTANT: GRAVITY $[ 1.0 4096.0 / ] CONSTANT: GRAVITY $[ 1.0 4096.0 / ]
CONSTANT: JUMP $[ 1.0 1024.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 * ] CONSTANT: terrain-vertex-row-length $[ 512 1 + 2 * ]
TUPLE: player TUPLE: player
location yaw pitch velocity velocity-modifier ; location yaw pitch velocity velocity-modifier
reverse-time ;
TUPLE: terrain-world < game-world TUPLE: terrain-world < game-world
player player
sky-image sky-texture sky-program sky-image sky-texture sky-program
terrain terrain-segment terrain-texture terrain-program terrain terrain-segment terrain-texture terrain-program
terrain-vertex-buffer ; terrain-vertex-buffer
history ;
: <player> ( -- 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 M: terrain-world tick-length
drop 1000 30 /i ; drop 1000 30 /i ;
@ -140,12 +152,17 @@ terrain-world H{
:: handle-input ( world -- ) :: handle-input ( world -- )
world player>> :> player world player>> :> player
read-keyboard keys>> :> keys read-keyboard keys>> :> keys
key-left-shift keys nth [
{ 2.0 1.0 2.0 } player (>>velocity-modifier) key-left-shift keys nth
] when VELOCITY-MODIFIER-FAST VELOCITY-MODIFIER-NORMAL ? player (>>velocity-modifier)
key-left-shift keys nth [
{ 1.0 1.0 1.0 } player (>>velocity-modifier) {
] unless [ 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-w keys nth [ player walk-forward ] when
key-s keys nth [ player walk-backward ] when key-s keys nth [ player walk-backward ] when
@ -199,11 +216,30 @@ terrain-world H{
: scaled-velocity ( player -- velocity ) : scaled-velocity ( player -- velocity )
[ velocity>> ] [ velocity-modifier>> ] bi v* ; [ 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 [ apply-friction apply-gravity ] change-velocity
dup scaled-velocity [ v+ [ terrain-segment>> ] dip collide ] curry with change-location dup scaled-velocity [ v+ [ terrain-segment>> ] dip collide ] curry with change-location
drop ; drop ;
: tick-player ( world player -- )
dup reverse-time>> [
tick-player-reverse
] [
tick-player-forward
] if ;
M: terrain-world tick* M: terrain-world tick*
[ dup focused?>> [ handle-input ] [ drop ] if ] [ dup focused?>> [ handle-input ] [ drop ] if ]
[ dup player>> tick-player ] bi ; [ dup player>> tick-player ] bi ;
@ -226,7 +262,8 @@ BEFORE: terrain-world begin-world
GL_DEPTH_TEST glEnable GL_DEPTH_TEST glEnable
GL_TEXTURE_2D glEnable GL_TEXTURE_2D glEnable
GL_VERTEX_ARRAY glEnableClientState 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> >>player
V{ } clone >>history
<perlin-noise-table> 0.01 0.01 <scale> { 512 512 } perlin-noise-image <perlin-noise-table> 0.01 0.01 <scale> { 512 512 } perlin-noise-image
[ >>sky-image ] keep [ >>sky-image ] keep
make-texture [ set-texture-parameters ] keep >>sky-texture make-texture [ set-texture-parameters ] keep >>sky-texture