Merge branch 'master' of git://factorcode.org/git/factor
commit
61fdb6f435
|
@ -52,6 +52,9 @@ GENERIC: (eql?) ( obj1 obj2 -- ? )
|
||||||
|
|
||||||
M: integer (eql?) = ;
|
M: integer (eql?) = ;
|
||||||
|
|
||||||
|
M: float (eql?)
|
||||||
|
over float? [ fp-bitwise= ] [ 2drop f ] if ;
|
||||||
|
|
||||||
M: sequence (eql?)
|
M: sequence (eql?)
|
||||||
over sequence? [
|
over sequence? [
|
||||||
2dup [ length ] bi@ =
|
2dup [ length ] bi@ =
|
||||||
|
|
|
@ -15,6 +15,7 @@ $nl
|
||||||
"Iterating over elements:"
|
"Iterating over elements:"
|
||||||
{ $subsection dlist-each }
|
{ $subsection dlist-each }
|
||||||
{ $subsection dlist-find }
|
{ $subsection dlist-find }
|
||||||
|
{ $subsection dlist-filter }
|
||||||
{ $subsection dlist-any? }
|
{ $subsection dlist-any? }
|
||||||
"Deleting a node matching a predicate:"
|
"Deleting a node matching a predicate:"
|
||||||
{ $subsection delete-node-if* }
|
{ $subsection delete-node-if* }
|
||||||
|
@ -40,6 +41,11 @@ HELP: dlist-find
|
||||||
"This operation is O(n)."
|
"This operation is O(n)."
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
HELP: dlist-filter
|
||||||
|
{ $values { "dlist" { $link dlist } } { "quot" quotation } { "dlist" { $link dlist } } }
|
||||||
|
{ $description "Applies the quotation to each element of the " { $link dlist } " in turn, removing the corresponding nodes if the quotation returns " { $link f } "." }
|
||||||
|
{ $side-effects { "dlist" } } ;
|
||||||
|
|
||||||
HELP: dlist-any?
|
HELP: dlist-any?
|
||||||
{ $values { "dlist" { $link dlist } } { "quot" quotation } { "?" "a boolean" } }
|
{ $values { "dlist" { $link dlist } } { "quot" quotation } { "?" "a boolean" } }
|
||||||
{ $description "Just like " { $link dlist-find } " except it doesn't return the object." }
|
{ $description "Just like " { $link dlist-find } " except it doesn't return the object." }
|
||||||
|
|
|
@ -79,3 +79,8 @@ IN: dlists.tests
|
||||||
[ V{ f 3 1 f } ] [ <dlist> 1 over push-front 3 over push-front f over push-front f over push-back dlist>seq ] unit-test
|
[ V{ f 3 1 f } ] [ <dlist> 1 over push-front 3 over push-front f over push-front f over push-back dlist>seq ] unit-test
|
||||||
|
|
||||||
[ V{ } ] [ <dlist> dlist>seq ] unit-test
|
[ V{ } ] [ <dlist> dlist>seq ] unit-test
|
||||||
|
|
||||||
|
[ V{ 0 2 4 } ] [ <dlist> { 0 1 2 3 4 } over push-all-back [ even? ] dlist-filter dlist>seq ] unit-test
|
||||||
|
[ V{ 2 4 } ] [ <dlist> { 1 2 3 4 } over push-all-back [ even? ] dlist-filter dlist>seq ] unit-test
|
||||||
|
[ V{ 2 4 } ] [ <dlist> { 1 2 3 4 5 } over push-all-back [ even? ] dlist-filter dlist>seq ] unit-test
|
||||||
|
[ V{ 0 2 4 } ] [ <dlist> { 0 1 2 3 4 5 } over push-all-back [ even? ] dlist-filter dlist>seq ] unit-test
|
||||||
|
|
|
@ -95,7 +95,7 @@ M: dlist pop-front* ( dlist -- )
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
[ empty-dlist ] unless*
|
[ empty-dlist ] unless*
|
||||||
[ f ] change-next drop
|
next>>
|
||||||
f over set-prev-when
|
f over set-prev-when
|
||||||
] change-front drop
|
] change-front drop
|
||||||
] keep
|
] keep
|
||||||
|
@ -108,7 +108,7 @@ M: dlist pop-back* ( dlist -- )
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
[ empty-dlist ] unless*
|
[ empty-dlist ] unless*
|
||||||
[ f ] change-prev drop
|
prev>>
|
||||||
f over set-next-when
|
f over set-next-when
|
||||||
] change-back drop
|
] change-back drop
|
||||||
] keep
|
] keep
|
||||||
|
@ -157,6 +157,9 @@ M: dlist clear-deque ( dlist -- )
|
||||||
|
|
||||||
: 1dlist ( obj -- dlist ) <dlist> [ push-front ] keep ;
|
: 1dlist ( obj -- dlist ) <dlist> [ push-front ] keep ;
|
||||||
|
|
||||||
|
: dlist-filter ( dlist quot -- dlist )
|
||||||
|
over [ '[ dup obj>> @ [ drop ] [ _ delete-node ] if ] dlist-each-node ] keep ; inline
|
||||||
|
|
||||||
M: dlist clone
|
M: dlist clone
|
||||||
<dlist> [ '[ _ push-back ] dlist-each ] keep ;
|
<dlist> [ '[ _ push-back ] dlist-each ] keep ;
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,13 @@ HELP: pdiff
|
||||||
{ $description "Finds the derivative of " { $snippet "p" } "." } ;
|
{ $description "Finds the derivative of " { $snippet "p" } "." } ;
|
||||||
|
|
||||||
HELP: polyval
|
HELP: polyval
|
||||||
{ $values { "p" "a polynomial" } { "x" number } { "p[x]" number } }
|
{ $values { "x" number } { "p" "a polynomial" } { "p[x]" number } }
|
||||||
{ $description "Evaluate " { $snippet "p" } " with the input " { $snippet "x" } "." }
|
{ $description "Evaluate " { $snippet "p" } " with the input " { $snippet "x" } "." }
|
||||||
{ $examples { $example "USING: math.polynomials prettyprint ;" "{ 1 0 1 } 2 polyval ." "5" } } ;
|
{ $examples { $example "USING: math.polynomials prettyprint ;" "2 { 1 0 1 } polyval ." "5" } } ;
|
||||||
|
|
||||||
|
HELP: polyval*
|
||||||
|
{ $values { "p" "a literal polynomial" } }
|
||||||
|
{ $description "Macro version of " { $link polyval } ". Evaluates the literal polynomial " { $snippet "p" } " at the value off the top of the stack." }
|
||||||
|
{ $examples { $example "USING: math.polynomials prettyprint ;" "2 { 1 0 1 } polyval* ." "5" } } ;
|
||||||
|
|
||||||
|
{ polyval polyval* } related-words
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2008 Doug Coleman.
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays kernel make math math.order math.vectors sequences
|
USING: arrays kernel make math math.order math.vectors sequences
|
||||||
splitting vectors ;
|
splitting vectors macros combinators ;
|
||||||
IN: math.polynomials
|
IN: math.polynomials
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
@ -80,6 +80,12 @@ PRIVATE>
|
||||||
: pdiff ( p -- p' )
|
: pdiff ( p -- p' )
|
||||||
dup length v* { 0 } ?head drop ;
|
dup length v* { 0 } ?head drop ;
|
||||||
|
|
||||||
: polyval ( p x -- p[x] )
|
: polyval ( x p -- p[x] )
|
||||||
[ dup length ] dip powers v. ;
|
[ length swap powers ] [ nip ] 2bi v. ;
|
||||||
|
|
||||||
|
MACRO: polyval* ( p -- )
|
||||||
|
reverse
|
||||||
|
[ 1 tail [ \ * swap \ + [ ] 3sequence ] map ]
|
||||||
|
[ first \ drop swap [ ] 2sequence ] bi
|
||||||
|
prefix \ cleave [ ] 2sequence ;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Slava Pestov
|
|
@ -0,0 +1,7 @@
|
||||||
|
! Copyright (C) 2009 Slava Pestov.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: accessors math.rectangles kernel prettyprint.custom prettyprint.backend ;
|
||||||
|
IN: math.rectangles.prettyprint
|
||||||
|
|
||||||
|
M: rect pprint*
|
||||||
|
\ RECT: [ [ loc>> ] [ dim>> ] bi [ pprint* ] bi@ ] pprint-prefix ;
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2008, 2009 Slava Pestov.
|
! Copyright (C) 2008, 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel arrays sequences math math.vectors accessors
|
USING: kernel arrays sequences math math.vectors accessors
|
||||||
parser prettyprint.custom prettyprint.backend ;
|
parser ;
|
||||||
IN: math.rectangles
|
IN: math.rectangles
|
||||||
|
|
||||||
TUPLE: rect { loc initial: { 0 0 } } { dim initial: { 0 0 } } ;
|
TUPLE: rect { loc initial: { 0 0 } } { dim initial: { 0 0 } } ;
|
||||||
|
@ -10,9 +10,6 @@ TUPLE: rect { loc initial: { 0 0 } } { dim initial: { 0 0 } } ;
|
||||||
|
|
||||||
SYNTAX: RECT: scan-object scan-object <rect> parsed ;
|
SYNTAX: RECT: scan-object scan-object <rect> parsed ;
|
||||||
|
|
||||||
M: rect pprint*
|
|
||||||
\ RECT: [ [ loc>> ] [ dim>> ] bi [ pprint* ] bi@ ] pprint-prefix ;
|
|
||||||
|
|
||||||
: <zero-rect> ( -- rect ) rect new ; inline
|
: <zero-rect> ( -- rect ) rect new ; inline
|
||||||
|
|
||||||
: point>rect ( loc -- rect ) { 0 0 } <rect> ; inline
|
: point>rect ( loc -- rect ) { 0 0 } <rect> ; inline
|
||||||
|
@ -64,3 +61,7 @@ M: rect contains-point?
|
||||||
[ [ loc>> ] dip (>>loc) ]
|
[ [ loc>> ] dip (>>loc) ]
|
||||||
[ [ dim>> ] dip (>>dim) ]
|
[ [ dim>> ] dip (>>dim) ]
|
||||||
2bi ; inline
|
2bi ; inline
|
||||||
|
|
||||||
|
USING: vocabs vocabs.loader ;
|
||||||
|
|
||||||
|
"prettyprint" vocab [ "math.rectangles.prettyprint" require ] when
|
|
@ -41,6 +41,13 @@ IN: math.vectors
|
||||||
: set-axis ( u v axis -- w )
|
: set-axis ( u v axis -- w )
|
||||||
[ [ zero? 2over ? ] dip swap nth ] map-index 2nip ;
|
[ [ zero? 2over ? ] dip swap nth ] map-index 2nip ;
|
||||||
|
|
||||||
|
: 2tetra@ ( p q r s t u v w quot -- )
|
||||||
|
dup [ [ 2bi@ ] curry 4dip ] dip 2bi@ ; inline
|
||||||
|
|
||||||
|
: trilerp ( aaa baa aba bba aab bab abb bbb {t,u,v} -- a_tuv )
|
||||||
|
[ first lerp ] [ second lerp ] [ third lerp ] tri-curry
|
||||||
|
[ 2tetra@ ] [ 2bi@ ] [ call ] tri* ;
|
||||||
|
|
||||||
: bilerp ( aa ba ab bb {t,u} -- a_tu )
|
: bilerp ( aa ba ab bb {t,u} -- a_tu )
|
||||||
[ first lerp ] [ second lerp ] bi-curry
|
[ first lerp ] [ second lerp ] bi-curry
|
||||||
[ 2bi@ ] [ call ] bi* ;
|
[ 2bi@ ] [ call ] bi* ;
|
||||||
|
@ -72,3 +79,6 @@ HINTS: v. { array array } ;
|
||||||
|
|
||||||
HINTS: vlerp { array array array } ;
|
HINTS: vlerp { array array array } ;
|
||||||
HINTS: vnlerp { array array object } ;
|
HINTS: vnlerp { array array object } ;
|
||||||
|
|
||||||
|
HINTS: bilerp { object object object object array } ;
|
||||||
|
HINTS: trilerp { object object object object object object object object array } ;
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
USING: accessors arrays hashtables kernel models math namespaces
|
USING: accessors arrays hashtables kernel models math namespaces
|
||||||
make sequences quotations math.vectors combinators sorting
|
make sequences quotations math.vectors combinators sorting
|
||||||
binary-search vectors dlists deques models threads
|
binary-search vectors dlists deques models threads
|
||||||
concurrency.flags math.order math.rectangles fry locals
|
concurrency.flags math.order math.rectangles fry locals ;
|
||||||
prettyprint.backend prettyprint.custom ;
|
|
||||||
IN: ui.gadgets
|
IN: ui.gadgets
|
||||||
|
|
||||||
! Values for orientation slot
|
! Values for orientation slot
|
||||||
|
@ -28,9 +27,6 @@ interior
|
||||||
boundary
|
boundary
|
||||||
model ;
|
model ;
|
||||||
|
|
||||||
! Don't print gadgets with RECT: syntax
|
|
||||||
M: gadget pprint* pprint-tuple ;
|
|
||||||
|
|
||||||
M: gadget equal? 2drop f ;
|
M: gadget equal? 2drop f ;
|
||||||
|
|
||||||
M: gadget hashcode* nip [ [ \ gadget counter ] unless* ] change-id id>> ;
|
M: gadget hashcode* nip [ [ \ gadget counter ] unless* ] change-id id>> ;
|
||||||
|
@ -397,3 +393,7 @@ M: f request-focus-on 2drop ;
|
||||||
|
|
||||||
: focus-path ( gadget -- seq )
|
: focus-path ( gadget -- seq )
|
||||||
[ focus>> ] follow ;
|
[ focus>> ] follow ;
|
||||||
|
|
||||||
|
USING: vocabs vocabs.loader ;
|
||||||
|
|
||||||
|
"prettyprint" vocab [ "ui.gadgets.prettyprint" require ] when
|
|
@ -0,0 +1 @@
|
||||||
|
Slava Pestov
|
|
@ -0,0 +1,7 @@
|
||||||
|
! Copyright (C) 2009 Slava Pestov.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: ui.gadgets prettyprint.backend prettyprint.custom ;
|
||||||
|
IN: ui.gadgets.prettyprint
|
||||||
|
|
||||||
|
! Don't print gadgets with RECT: syntax
|
||||||
|
M: gadget pprint* pprint-tuple ;
|
|
@ -163,7 +163,7 @@ M: hi-tag-dispatch-engine compile-engine
|
||||||
|
|
||||||
: build-fast-hash ( methods -- buckets )
|
: build-fast-hash ( methods -- buckets )
|
||||||
>alist V{ } clone [ hashcode 1array ] distribute-buckets
|
>alist V{ } clone [ hashcode 1array ] distribute-buckets
|
||||||
[ compile-engines* >alist >array ] map ;
|
[ compile-engines* >alist { } join ] map ;
|
||||||
|
|
||||||
M: echelon-dispatch-engine compile-engine
|
M: echelon-dispatch-engine compile-engine
|
||||||
dup n>> 0 = [
|
dup n>> 0 = [
|
||||||
|
|
|
@ -274,7 +274,7 @@ HELP: fp-nan-payload
|
||||||
{ $description "If " { $snippet "x" } " is an IEEE Not-a-Number value, returns the payload encoded in the value. Returns " { $link f } " if " { $snippet "x" } " is not a " { $link float } "." } ;
|
{ $description "If " { $snippet "x" } " is an IEEE Not-a-Number value, returns the payload encoded in the value. Returns " { $link f } " if " { $snippet "x" } " is not a " { $link float } "." } ;
|
||||||
|
|
||||||
HELP: <fp-nan>
|
HELP: <fp-nan>
|
||||||
{ $values { "payload" integer } { "float" float } }
|
{ $values { "payload" integer } { "nan" float } }
|
||||||
{ $description "Constructs an IEEE Not-a-Number value with a payload of " { $snippet "payload" } "." }
|
{ $description "Constructs an IEEE Not-a-Number value with a payload of " { $snippet "payload" } "." }
|
||||||
{ $notes "A " { $snippet "payload" } " of " { $snippet "0" } " will construct an Infinity value." } ;
|
{ $notes "A " { $snippet "payload" } " of " { $snippet "0" } " will construct an Infinity value." } ;
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,8 @@ TUPLE: complex { real real read-only } { imaginary real read-only } ;
|
||||||
|
|
||||||
UNION: number real complex ;
|
UNION: number real complex ;
|
||||||
|
|
||||||
|
: fp-bitwise= ( x y -- ? ) [ double>bits ] bi@ = ; inline
|
||||||
|
|
||||||
GENERIC: fp-special? ( x -- ? )
|
GENERIC: fp-special? ( x -- ? )
|
||||||
GENERIC: fp-nan? ( x -- ? )
|
GENERIC: fp-nan? ( x -- ? )
|
||||||
GENERIC: fp-qnan? ( x -- ? )
|
GENERIC: fp-qnan? ( x -- ? )
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
USING: accessors game-input game-loop kernel math ui.gadgets
|
||||||
|
ui.gadgets.worlds ui.gestures ;
|
||||||
|
IN: game-worlds
|
||||||
|
|
||||||
|
TUPLE: game-world < world
|
||||||
|
game-loop
|
||||||
|
{ tick-slice float initial: 0.0 } ;
|
||||||
|
|
||||||
|
GENERIC: tick-length ( world -- millis )
|
||||||
|
|
||||||
|
M: game-world draw*
|
||||||
|
swap >>tick-slice draw-world ;
|
||||||
|
|
||||||
|
M: game-world begin-world
|
||||||
|
dup [ tick-length ] [ ] bi <game-loop> [ >>game-loop ] keep start-loop
|
||||||
|
drop
|
||||||
|
open-game-input ;
|
||||||
|
|
||||||
|
M: game-world end-world
|
||||||
|
close-game-input
|
||||||
|
[ [ stop-loop ] when* f ] change-game-loop
|
||||||
|
drop ;
|
||||||
|
|
||||||
|
M: game-world focusable-child* drop t ;
|
||||||
|
|
|
@ -17,6 +17,8 @@ CONSTANT: identity-transform T{ affine-transform f { 1.0 0.0 } { 0.0 1.0 } { 0.0
|
||||||
[ drop origin>> ] 2tri
|
[ drop origin>> ] 2tri
|
||||||
v+ v+ ;
|
v+ v+ ;
|
||||||
|
|
||||||
|
: <identity> ( -- a )
|
||||||
|
{ 1.0 0.0 } { 0.0 1.0 } { 0.0 0.0 } <affine-transform> ;
|
||||||
: <translation> ( origin -- a )
|
: <translation> ( origin -- a )
|
||||||
[ { 1.0 0.0 } { 0.0 1.0 } ] dip <affine-transform> ;
|
[ { 1.0 0.0 } { 0.0 1.0 } ] dip <affine-transform> ;
|
||||||
: <rotation> ( theta -- transform )
|
: <rotation> ( theta -- transform )
|
||||||
|
|
|
@ -1,61 +1,60 @@
|
||||||
USING: byte-arrays combinators fry images kernel locals math
|
USING: byte-arrays combinators fry images kernel locals math
|
||||||
math.affine-transforms math.functions math.order
|
math.affine-transforms math.functions math.order
|
||||||
math.polynomials math.vectors random random.mersenne-twister
|
math.polynomials math.vectors random random.mersenne-twister
|
||||||
sequences sequences.product ;
|
sequences sequences.product hints arrays sequences.private
|
||||||
|
combinators.short-circuit math.private ;
|
||||||
IN: noise
|
IN: noise
|
||||||
|
|
||||||
: <perlin-noise-table> ( -- table )
|
: <perlin-noise-table> ( -- table )
|
||||||
256 iota >byte-array randomize dup append ;
|
256 iota >byte-array randomize dup append ; inline
|
||||||
|
|
||||||
: with-seed ( seed quot -- )
|
: with-seed ( seed quot -- )
|
||||||
[ <mersenne-twister> ] dip with-random ; inline
|
[ <mersenne-twister> ] dip with-random ; inline
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: fade ( point -- point' )
|
: (fade) ( x y z -- x' y' z' )
|
||||||
{ 0.0 0.0 0.0 10.0 -15.0 6.0 } swap [ polyval ] with map ;
|
[ { 0.0 0.0 0.0 10.0 -15.0 6.0 } polyval* ] tri@ ;
|
||||||
|
|
||||||
:: grad ( hash gradients -- gradient )
|
HINTS: (fade) { float float float } ;
|
||||||
hash 8 bitand zero? [ gradients first ] [ gradients second ] if
|
|
||||||
|
: fade ( point -- point' )
|
||||||
|
first3 (fade) 3array ; inline
|
||||||
|
|
||||||
|
:: grad ( hash x y z -- gradient )
|
||||||
|
hash 8 bitand zero? [ x ] [ y ] if
|
||||||
:> u
|
:> u
|
||||||
hash 12 bitand zero?
|
hash 12 bitand zero?
|
||||||
[ gradients second ]
|
[ y ] [ hash 13 bitand 12 = [ x ] [ z ] if ] if
|
||||||
[ hash 13 bitand 12 = [ gradients first ] [ gradients third ] if ] if
|
|
||||||
:> v
|
:> v
|
||||||
|
|
||||||
hash 1 bitand zero? [ u ] [ u neg ] if
|
hash 1 bitand zero? [ u ] [ u neg ] if
|
||||||
hash 2 bitand zero? [ v ] [ v neg ] if + ;
|
hash 2 bitand zero? [ v ] [ v neg ] if + ;
|
||||||
|
|
||||||
|
HINTS: grad { fixnum float float float } ;
|
||||||
|
|
||||||
: unit-cube ( point -- cube )
|
: unit-cube ( point -- cube )
|
||||||
[ floor >fixnum 256 mod ] map ;
|
[ floor >fixnum 256 rem ] map ;
|
||||||
|
|
||||||
:: hashes ( table cube -- aaa baa aba bba aab bab abb bbb )
|
:: hashes ( table x y z -- aaa baa aba bba aab bab abb bbb )
|
||||||
cube first :> x
|
x table nth-unsafe y fixnum+fast :> a
|
||||||
cube second :> y
|
x 1 fixnum+fast table nth-unsafe y fixnum+fast :> b
|
||||||
cube third :> z
|
|
||||||
x table nth y + :> a
|
|
||||||
x 1 + table nth y + :> b
|
|
||||||
|
|
||||||
a table nth z + :> aa
|
a table nth-unsafe z fixnum+fast :> aa
|
||||||
b table nth z + :> ba
|
b table nth-unsafe z fixnum+fast :> ba
|
||||||
a 1 + table nth z + :> ab
|
a 1 fixnum+fast table nth-unsafe z fixnum+fast :> ab
|
||||||
b 1 + table nth z + :> bb
|
b 1 fixnum+fast table nth-unsafe z fixnum+fast :> bb
|
||||||
|
|
||||||
aa table nth
|
aa table nth-unsafe
|
||||||
ba table nth
|
ba table nth-unsafe
|
||||||
ab table nth
|
ab table nth-unsafe
|
||||||
bb table nth
|
bb table nth-unsafe
|
||||||
aa 1 + table nth
|
aa 1 fixnum+fast table nth-unsafe
|
||||||
ba 1 + table nth
|
ba 1 fixnum+fast table nth-unsafe
|
||||||
ab 1 + table nth
|
ab 1 fixnum+fast table nth-unsafe
|
||||||
bb 1 + table nth ;
|
bb 1 fixnum+fast table nth-unsafe ; inline
|
||||||
|
|
||||||
:: 2tetra@ ( p q r s t u v w quot -- )
|
HINTS: hashes { byte-array fixnum fixnum fixnum } ;
|
||||||
p q quot call
|
|
||||||
r s quot call
|
|
||||||
t u quot call
|
|
||||||
v w quot call
|
|
||||||
; inline
|
|
||||||
|
|
||||||
: >byte-map ( floats -- bytes )
|
: >byte-map ( floats -- bytes )
|
||||||
[ 255.0 * >fixnum ] B{ } map-as ;
|
[ 255.0 * >fixnum ] B{ } map-as ;
|
||||||
|
@ -63,26 +62,33 @@ IN: noise
|
||||||
: >image ( bytes dim -- image )
|
: >image ( bytes dim -- image )
|
||||||
swap [ L f ] dip image boa ;
|
swap [ L f ] dip image boa ;
|
||||||
|
|
||||||
PRIVATE>
|
:: perlin-noise-unsafe ( table point -- value )
|
||||||
|
|
||||||
:: perlin-noise ( table point -- value )
|
|
||||||
point unit-cube :> cube
|
point unit-cube :> cube
|
||||||
point dup vfloor v- :> gradients
|
point dup vfloor v- :> gradients
|
||||||
gradients fade :> faded
|
gradients fade :> faded
|
||||||
|
|
||||||
table cube hashes {
|
table cube first3 hashes {
|
||||||
[ gradients grad ]
|
[ gradients first3 grad ]
|
||||||
[ gradients { -1.0 0.0 0.0 } v+ grad ]
|
[ gradients first3 [ 1.0 - ] [ ] [ ] tri* grad ]
|
||||||
[ gradients { 0.0 -1.0 0.0 } v+ grad ]
|
[ gradients first3 [ ] [ 1.0 - ] [ ] tri* grad ]
|
||||||
[ gradients { -1.0 -1.0 0.0 } v+ grad ]
|
[ gradients first3 [ 1.0 - ] [ 1.0 - ] [ ] tri* grad ]
|
||||||
[ gradients { 0.0 0.0 -1.0 } v+ grad ]
|
[ gradients first3 [ ] [ ] [ 1.0 - ] tri* grad ]
|
||||||
[ gradients { -1.0 0.0 -1.0 } v+ grad ]
|
[ gradients first3 [ 1.0 - ] [ ] [ 1.0 - ] tri* grad ]
|
||||||
[ gradients { 0.0 -1.0 -1.0 } v+ grad ]
|
[ gradients first3 [ ] [ 1.0 - ] [ 1.0 - ] tri* grad ]
|
||||||
[ gradients { -1.0 -1.0 -1.0 } v+ grad ]
|
[ gradients first3 [ 1.0 - ] [ 1.0 - ] [ 1.0 - ] tri* grad ]
|
||||||
} spread
|
} spread
|
||||||
[ faded first lerp ] 2tetra@
|
faded trilerp ;
|
||||||
[ faded second lerp ] 2bi@
|
|
||||||
faded third lerp ;
|
ERROR: invalid-perlin-noise-table table ;
|
||||||
|
|
||||||
|
: validate-table ( table -- table )
|
||||||
|
dup { [ byte-array? ] [ length 512 >= ] } 1&&
|
||||||
|
[ invalid-perlin-noise-table ] unless ;
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
|
: perlin-noise ( table point -- value )
|
||||||
|
[ validate-table ] dip perlin-noise-unsafe ; inline
|
||||||
|
|
||||||
: normalize-0-1 ( sequence -- sequence' )
|
: normalize-0-1 ( sequence -- sequence' )
|
||||||
[ supremum ] [ infimum [ - ] keep ] [ ] tri
|
[ supremum ] [ infimum [ - ] keep ] [ ] tri
|
||||||
|
@ -92,7 +98,8 @@ PRIVATE>
|
||||||
[ 0.0 max 1.0 min ] map ;
|
[ 0.0 max 1.0 min ] map ;
|
||||||
|
|
||||||
: perlin-noise-map ( table transform dim -- map )
|
: perlin-noise-map ( table transform dim -- map )
|
||||||
[ iota ] map [ a.v 0.0 suffix perlin-noise ] with with product-map ;
|
[ validate-table ] 2dip
|
||||||
|
[ iota ] map [ a.v 0.0 suffix perlin-noise-unsafe ] with with product-map ;
|
||||||
|
|
||||||
: perlin-noise-byte-map ( table transform dim -- map )
|
: perlin-noise-byte-map ( table transform dim -- map )
|
||||||
perlin-noise-map normalize-0-1 >byte-map ;
|
perlin-noise-map normalize-0-1 >byte-map ;
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
USING: accessors arrays combinators game-input
|
USING: accessors arrays combinators game-input game-loop
|
||||||
game-input.scancodes game-loop grouping kernel literals locals
|
game-input.scancodes grouping kernel literals locals
|
||||||
math math.constants math.functions math.matrices math.order
|
math math.constants math.functions math.matrices math.order
|
||||||
math.vectors opengl opengl.capabilities opengl.gl
|
math.vectors opengl opengl.capabilities opengl.gl
|
||||||
opengl.shaders opengl.textures opengl.textures.private
|
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 ;
|
ui.gadgets.worlds ui.pixel-formats game-worlds method-chains ;
|
||||||
IN: terrain
|
IN: terrain
|
||||||
|
|
||||||
CONSTANT: FOV $[ 2.0 sqrt 1+ ]
|
CONSTANT: FOV $[ 2.0 sqrt 1+ ]
|
||||||
|
@ -15,7 +15,6 @@ CONSTANT: PLAYER-START-LOCATION { 0.5 0.51 0.5 }
|
||||||
CONSTANT: PLAYER-HEIGHT $[ 3.0 1024.0 / ]
|
CONSTANT: PLAYER-HEIGHT $[ 3.0 1024.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 / ]
|
||||||
CONSTANT: TICK-LENGTH $[ 1000 30 /i ]
|
|
||||||
CONSTANT: MOUSE-SCALE $[ 1.0 10.0 / ]
|
CONSTANT: MOUSE-SCALE $[ 1.0 10.0 / ]
|
||||||
CONSTANT: MOVEMENT-SPEED $[ 1.0 16384.0 / ]
|
CONSTANT: MOVEMENT-SPEED $[ 1.0 16384.0 / ]
|
||||||
CONSTANT: FRICTION 0.95
|
CONSTANT: FRICTION 0.95
|
||||||
|
@ -28,11 +27,13 @@ CONSTANT: terrain-vertex-row-length $[ 512 1 + 2 * ]
|
||||||
TUPLE: player
|
TUPLE: player
|
||||||
location yaw pitch velocity ;
|
location yaw pitch velocity ;
|
||||||
|
|
||||||
TUPLE: terrain-world < world
|
TUPLE: terrain-world < game-world
|
||||||
player
|
player
|
||||||
terrain terrain-segment terrain-texture terrain-program
|
terrain terrain-segment terrain-texture terrain-program
|
||||||
terrain-vertex-buffer
|
terrain-vertex-buffer ;
|
||||||
game-loop ;
|
|
||||||
|
M: terrain-world tick-length
|
||||||
|
drop 1000 30 /i ;
|
||||||
|
|
||||||
: frustum ( dim -- -x x -y y near far )
|
: frustum ( dim -- -x x -y y near far )
|
||||||
dup first2 min v/n
|
dup first2 min v/n
|
||||||
|
@ -137,8 +138,11 @@ TUPLE: terrain-world < world
|
||||||
: apply-gravity ( velocity -- velocity' )
|
: apply-gravity ( velocity -- velocity' )
|
||||||
1 over [ GRAVITY - ] change-nth ;
|
1 over [ GRAVITY - ] change-nth ;
|
||||||
|
|
||||||
|
: clamp-coords ( coords dim -- coords' )
|
||||||
|
[ { 0 0 } vmax ] dip { 2 2 } v- vmin ;
|
||||||
|
|
||||||
:: pixel-indices ( coords dim -- indices )
|
:: pixel-indices ( coords dim -- indices )
|
||||||
coords vfloor [ >integer ] map :> floor-coords
|
coords vfloor [ >integer ] map dim clamp-coords :> floor-coords
|
||||||
floor-coords first2 dim first * + :> base-index
|
floor-coords first2 dim first * + :> base-index
|
||||||
base-index dim first + :> next-row-index
|
base-index dim first + :> next-row-index
|
||||||
|
|
||||||
|
@ -171,9 +175,6 @@ 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 ;
|
||||||
|
|
||||||
M: terrain-world draw*
|
|
||||||
nip draw-world ;
|
|
||||||
|
|
||||||
: set-heightmap-texture-parameters ( texture -- )
|
: set-heightmap-texture-parameters ( texture -- )
|
||||||
GL_TEXTURE_2D GL_TEXTURE0 bind-texture-unit
|
GL_TEXTURE_2D GL_TEXTURE0 bind-texture-unit
|
||||||
GL_TEXTURE_2D GL_TEXTURE_MIN_FILTER GL_LINEAR glTexParameteri
|
GL_TEXTURE_2D GL_TEXTURE_MIN_FILTER GL_LINEAR glTexParameteri
|
||||||
|
@ -181,7 +182,7 @@ M: terrain-world draw*
|
||||||
GL_TEXTURE_2D GL_TEXTURE_WRAP_S GL_CLAMP_TO_EDGE 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 ;
|
GL_TEXTURE_2D GL_TEXTURE_WRAP_T GL_CLAMP_TO_EDGE glTexParameteri ;
|
||||||
|
|
||||||
M: terrain-world begin-world
|
BEFORE: terrain-world begin-world
|
||||||
"2.0" { "GL_ARB_vertex_buffer_object" "GL_ARB_shader_objects" }
|
"2.0" { "GL_ARB_vertex_buffer_object" "GL_ARB_shader_objects" }
|
||||||
require-gl-version-or-extensions
|
require-gl-version-or-extensions
|
||||||
GL_DEPTH_TEST glEnable
|
GL_DEPTH_TEST glEnable
|
||||||
|
@ -195,14 +196,10 @@ M: terrain-world begin-world
|
||||||
terrain-vertex-shader terrain-pixel-shader <simple-gl-program>
|
terrain-vertex-shader terrain-pixel-shader <simple-gl-program>
|
||||||
>>terrain-program
|
>>terrain-program
|
||||||
vertex-array >vertex-buffer >>terrain-vertex-buffer
|
vertex-array >vertex-buffer >>terrain-vertex-buffer
|
||||||
TICK-LENGTH over <game-loop> [ >>game-loop ] keep start-loop
|
|
||||||
open-game-input
|
|
||||||
drop ;
|
drop ;
|
||||||
|
|
||||||
M: terrain-world end-world
|
AFTER: terrain-world end-world
|
||||||
close-game-input
|
|
||||||
{
|
{
|
||||||
[ game-loop>> stop-loop ]
|
|
||||||
[ terrain-vertex-buffer>> delete-gl-buffer ]
|
[ terrain-vertex-buffer>> delete-gl-buffer ]
|
||||||
[ terrain-program>> delete-gl-program ]
|
[ terrain-program>> delete-gl-program ]
|
||||||
[ terrain-texture>> delete-texture ]
|
[ terrain-texture>> delete-texture ]
|
||||||
|
@ -224,7 +221,6 @@ M: terrain-world draw-world*
|
||||||
] with-gl-program ]
|
] with-gl-program ]
|
||||||
tri gl-error ;
|
tri gl-error ;
|
||||||
|
|
||||||
M: terrain-world focusable-child* drop t ;
|
|
||||||
M: terrain-world pref-dim* drop { 640 480 } ;
|
M: terrain-world pref-dim* drop { 640 480 } ;
|
||||||
|
|
||||||
: terrain-window ( -- )
|
: terrain-window ( -- )
|
||||||
|
|
|
@ -8,15 +8,14 @@ cell megamorphic_cache_misses;
|
||||||
|
|
||||||
static cell search_lookup_alist(cell table, cell klass)
|
static cell search_lookup_alist(cell table, cell klass)
|
||||||
{
|
{
|
||||||
array *pairs = untag<array>(table);
|
array *elements = untag<array>(table);
|
||||||
fixnum index = array_capacity(pairs) - 1;
|
fixnum index = array_capacity(elements) - 2;
|
||||||
while(index >= 0)
|
while(index >= 0)
|
||||||
{
|
{
|
||||||
array *pair = untag<array>(array_nth(pairs,index));
|
if(array_nth(elements,index) == klass)
|
||||||
if(array_nth(pair,0) == klass)
|
return array_nth(elements,index + 1);
|
||||||
return array_nth(pair,1);
|
|
||||||
else
|
else
|
||||||
index--;
|
index -= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return F;
|
return F;
|
||||||
|
|
Loading…
Reference in New Issue