From 57ba1aff60b7b38c68a7406f40fabaf0e7120bc6 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 11 Feb 2010 16:29:48 +1300 Subject: [PATCH 01/12] compiler.tree.propagation.inlining: remove some unused words --- basis/compiler/tree/propagation/inlining/inlining.factor | 8 -------- 1 file changed, 8 deletions(-) diff --git a/basis/compiler/tree/propagation/inlining/inlining.factor b/basis/compiler/tree/propagation/inlining/inlining.factor index 634fade609..4a227cfa77 100644 --- a/basis/compiler/tree/propagation/inlining/inlining.factor +++ b/basis/compiler/tree/propagation/inlining/inlining.factor @@ -79,14 +79,6 @@ M: callable splicing-nodes splicing-body ; : inline-math-method ( #call word -- ? ) dupd inlining-math-method eliminate-dispatch ; -: inlining-math-partial ( #call word -- class/f quot/f ) - [ "derived-from" word-prop first inlining-math-method ] - [ nip 1quotation ] 2bi - [ = not ] [ drop ] 2bi and ; - -: inline-math-partial ( #call word -- ? ) - dupd inlining-math-partial eliminate-dispatch ; - ! Method body inlining SYMBOL: history From a3b74d88c9ab62dfc1d58951b9abf94015d189cb Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 11 Feb 2010 18:11:47 +1300 Subject: [PATCH 02/12] cpu.architecture: rep-length now works in deployed images --- basis/alien/c-types/c-types.factor | 3 --- basis/cpu/architecture/architecture.factor | 13 +++++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/basis/alien/c-types/c-types.factor b/basis/alien/c-types/c-types.factor index 4ff599e0d1..e2f15f5de8 100644 --- a/basis/alien/c-types/c-types.factor +++ b/basis/alien/c-types/c-types.factor @@ -554,9 +554,6 @@ M: ulonglong-2-rep rep-component-type drop ulonglong ; M: float-4-rep rep-component-type drop float ; M: double-2-rep rep-component-type drop double ; -: rep-length ( rep -- n ) - 16 swap rep-component-type heap-size /i ; foldable - : (unsigned-interval) ( bytes -- from to ) [ 0 ] dip 8 * 2^ 1 - ; foldable : unsigned-interval ( c-type -- from to ) heap-size (unsigned-interval) ; foldable : (signed-interval) ( bytes -- from to ) 8 * 1 - 2^ [ neg ] [ 1 - ] bi ; foldable diff --git a/basis/cpu/architecture/architecture.factor b/basis/cpu/architecture/architecture.factor index 734241a5d3..4d99b5a0ed 100644 --- a/basis/cpu/architecture/architecture.factor +++ b/basis/cpu/architecture/architecture.factor @@ -169,6 +169,19 @@ M: uint-scalar-rep rep-size drop 4 ; M: longlong-scalar-rep rep-size drop 8 ; M: ulonglong-scalar-rep rep-size drop 8 ; +GENERIC: rep-length ( rep -- n ) foldable + +M: char-16-rep rep-length drop 16 ; +M: uchar-16-rep rep-length drop 16 ; +M: short-8-rep rep-length drop 8 ; +M: ushort-8-rep rep-length drop 8 ; +M: int-4-rep rep-length drop 4 ; +M: uint-4-rep rep-length drop 4 ; +M: longlong-2-rep rep-length drop 2 ; +M: ulonglong-2-rep rep-length drop 2 ; +M: float-4-rep rep-length drop 4 ; +M: double-2-rep rep-length drop 2 ; + GENERIC: rep-component-type ( rep -- n ) ! Methods defined in alien.c-types From 9bcb119c8a9424d5dfb8eb4f0cd8852ab8a34143 Mon Sep 17 00:00:00 2001 From: Erik Charlebois Date: Wed, 10 Feb 2010 21:54:32 -0800 Subject: [PATCH 03/12] Bindings to the Chipmunk 2d physics library. --- extra/chipmunk/authors.txt | 1 + extra/chipmunk/chipmunk.factor | 845 ++++++++++++++++++++++++++++++++ extra/chipmunk/demo/authors.txt | 1 + extra/chipmunk/demo/demo.factor | 151 ++++++ extra/chipmunk/demo/summary.txt | 1 + extra/chipmunk/summary.txt | 1 + 6 files changed, 1000 insertions(+) create mode 100644 extra/chipmunk/authors.txt create mode 100644 extra/chipmunk/chipmunk.factor create mode 100644 extra/chipmunk/demo/authors.txt create mode 100644 extra/chipmunk/demo/demo.factor create mode 100644 extra/chipmunk/demo/summary.txt create mode 100644 extra/chipmunk/summary.txt diff --git a/extra/chipmunk/authors.txt b/extra/chipmunk/authors.txt new file mode 100644 index 0000000000..6f03a12101 --- /dev/null +++ b/extra/chipmunk/authors.txt @@ -0,0 +1 @@ +Erik Charlebois diff --git a/extra/chipmunk/chipmunk.factor b/extra/chipmunk/chipmunk.factor new file mode 100644 index 0000000000..c56e15e12e --- /dev/null +++ b/extra/chipmunk/chipmunk.factor @@ -0,0 +1,845 @@ +! Copyright (C) 2010 Erik Charlebois +! See http:// factorcode.org/license.txt for BSD license. +USING: accessors alien.c-types alien.syntax classes.struct combinators +combinators.short-circuit kernel math math.order sequences +specialized-arrays.instances.alien.c-types.void* typed +specialized-arrays locals system alien.libraries ; +IN: chipmunk + +<< "chipmunk" { + { [ os windows? ] [ "chipmunk.dll" ] } + { [ os macosx? ] [ "libchipmunk.dylib" ] } + { [ os unix? ] [ "libchipmunk.so" ] } + } cond "cdecl" add-library >> +LIBRARY: chipmunk + +! chipmunk_types.h +TYPEDEF: double cpFloat +STRUCT: cpVect + { x cpFloat } + { y cpFloat } ; +SPECIALIZED-ARRAY: cpVect + +TYPEDEF: uint cpHashValue +TYPEDEF: void* cpDataPointer +TYPEDEF: uint cpCollisionType +TYPEDEF: uint cpLayers +TYPEDEF: uint cpGroup + +CONSTANT: CP_NO_GROUP 0 +CONSTANT: CP_ALL_LAYERS HEX: ffffffff + +! cpVect.h +TYPED: cpv ( x y -- v: cpVect ) + cpVect ; inline + +TYPED: cpvzero ( -- v: cpVect ) + 0.0 0.0 cpv ; inline + +FUNCTION: cpFloat cpvlength ( cpVect v ) ; +FUNCTION: cpVect cpvslerp ( cpVect v1, cpVect v2, cpFloat t ) ; +FUNCTION: cpVect cpvslerpconst ( cpVect v1, cpVect v2, cpFloat a ) ; +FUNCTION: cpVect cpvforangle ( cpFloat a ) ; +FUNCTION: cpFloat cpvtoangle ( cpVect v ) ; +FUNCTION: char* cpvstr ( cpVect v ) ; + +TYPED: cpvadd ( v1: cpVect v2: cpVect -- v3: cpVect ) + [ [ x>> ] bi@ + ] + [ [ y>> ] bi@ + ] 2bi cpv ; inline + +TYPED: cpvneg ( v1: cpVect -- v2: cpVect ) + [ x>> ] [ y>> ] bi [ neg ] bi@ cpv ; inline + +TYPED: cpvsub ( v1: cpVect v2: cpVect -- v3: cpVect ) + [ [ x>> ] bi@ - ] + [ [ y>> ] bi@ - ] 2bi cpv ; inline + +TYPED: cpvmult ( v1: cpVect s -- v2: cpVect ) + [ swap x>> * ] + [ swap y>> * ] 2bi cpv ; inline + +TYPED: cpvdot ( v1: cpVect v2: cpVect -- s ) + [ [ x>> ] bi@ * ] + [ [ y>> ] bi@ * ] 2bi + ; inline + +TYPED: cpvcross ( v1: cpVect v2: cpVect -- s ) + [ [ x>> ] [ y>> ] bi* * ] + [ [ y>> ] [ x>> ] bi* * ] 2bi - ; inline + +TYPED: cpvperp ( v1: cpVect -- v2: cpVect ) + [ y>> neg ] [ x>> ] bi cpv ; inline + +TYPED: cpvrperp ( v1: cpVect -- v2: cpVect ) + [ y>> ] [ x>> neg ] bi cpv ; inline + +TYPED: cpvproject ( v1: cpVect v2: cpVect -- v3: cpVect ) + [ nip ] + [ cpvdot ] + [ nip dup cpvdot ] + 2tri / cpvmult ; inline + +TYPED: cpvrotate ( v1: cpVect v2: cpVect -- v3: cpVect ) + [ + [ [ x>> ] bi@ * ] + [ [ y>> ] bi@ * ] 2bi - + ] + [ + [ [ x>> ] [ y>> ] bi* * ] + [ [ y>> ] [ x>> ] bi* * ] 2bi + + ] 2bi cpv ; inline + +TYPED: cpvunrotate ( v1: cpVect v2: cpVect -- v3: cpVect ) + [ + [ [ x>> ] bi@ * ] + [ [ y>> ] bi@ * ] 2bi + + ] + [ + [ [ y>> ] [ x>> ] bi* * ] + [ [ x>> ] [ y>> ] bi* * ] 2bi - + ] 2bi cpv ; inline + +TYPED: cpvlengthsq ( v: cpVect -- s ) + dup cpvdot ; inline + +TYPED: cpvlerp ( v1: cpVect v2: cpVect s -- v3: cpVect ) + [ nip 1.0 swap - cpvmult ] + [ cpvmult nip ] 3bi cpvadd ; inline + +TYPED: cpvnormalize ( v1: cpVect -- v2: cpVect ) + dup cpvlength 1.0 swap / cpvmult ; inline + +TYPED: cpvnormalize_safe ( v1: cpVect -- v2: cpVect ) + dup [ x>> 0.0 = ] [ y>> 0.0 = ] bi and + [ drop cpvzero ] + [ cpvnormalize ] if ; inline + +TYPED: cpvclamp ( v1: cpVect len -- v2: cpVect ) + 2dup + [ dup cpvdot ] + [ sq ] 2bi* > + [ [ cpvnormalize ] dip cpvmult ] + [ drop ] if ; inline + +TYPED: cpvlerpconst ( v1: cpVect v2: cpVect d -- v3: cpVect ) + [ 2drop ] + [ [ swap cpvsub ] dip cpvclamp ] 3bi cpvadd ; inline + +TYPED: cpvdist ( v1: cpVect v2: cpVect -- dist ) + cpvsub cpvlength ; inline + +TYPED: cpvdistsq ( v1: cpVect v2: cpVect -- distsq ) + cpvsub cpvlengthsq ; inline + +TYPED: cpvnear ( v1: cpVect v2: cpVect dist -- ? ) + [ cpvdistsq ] dip sq < ; inline + +! cpBB.h +STRUCT: cpBB + { l cpFloat } + { b cpFloat } + { r cpFloat } + { t cpFloat } ; + +TYPED: cpBBNew ( l b r t -- cpbb: cpBB ) + cpBB ; inline + +TYPED: cpBBintersects ( a: cpBB b: cpBB -- ? ) + { + [ [ l>> ] [ r>> ] bi* <= ] + [ [ r>> ] [ l>> ] bi* > ] + [ [ b>> ] [ t>> ] bi* <= ] + [ [ t>> ] [ b>> ] bi* > ] + } 2&& ; inline + +TYPED: cpBBcontainsBB ( bb: cpBB other: cpBB -- ? ) + { + [ [ l>> ] bi@ < ] + [ [ r>> ] bi@ > ] + [ [ b>> ] bi@ < ] + [ [ t>> ] bi@ > ] + } 2&& ; inline + +TYPED: cpBBcontainsVect ( bb: cpBB v: cpVect -- ? ) + { + [ [ l>> ] [ x>> ] bi* < ] + [ [ r>> ] [ x>> ] bi* > ] + [ [ b>> ] [ y>> ] bi* < ] + [ [ t>> ] [ y>> ] bi* > ] + } 2&& ; inline + +TYPED: cpBBmerge ( a: cpBB b: cpBB -- c: cpBB ) + { + [ [ l>> ] bi@ min ] + [ [ b>> ] bi@ min ] + [ [ r>> ] bi@ max ] + [ [ t>> ] bi@ max ] + } 2cleave cpBBNew ; inline + +TYPED: cpBBexpand ( bb: cpBB v: cpVect -- b: cpBB ) + { + [ [ l>> ] [ x>> ] bi* min ] + [ [ b>> ] [ y>> ] bi* min ] + [ [ r>> ] [ x>> ] bi* max ] + [ [ t>> ] [ y>> ] bi* max ] + } 2cleave cpBBNew ; inline + +FUNCTION: cpVect cpBBClampVect ( cpBB bb, cpVect v ) ; +FUNCTION: cpVect cpBBWrapVect ( cpBB bb, cpVect v ) ; + +! cpBody.h +C-TYPE: cpBody +CALLBACK: void cpBodyVelocityFunc ( cpBody* body, cpVect gravity, cpFloat damping, cpFloat dt ) ; +CALLBACK: void cpBodyPositionFunc ( cpBody* body, cpFloat dt ) ; + +STRUCT: cpBody + { velocity_func cpBodyVelocityFunc } + { position_func cpBodyPositionFunc } + { m cpFloat } + { m_inv cpFloat } + { i cpFloat } + { i_inv cpFloat } + { p cpVect } + { v cpVect } + { f cpVect } + { a cpFloat } + { w cpFloat } + { t cpFloat } + { rot cpVect } + { data cpDataPointer } + { v_limit cpFloat } + { w_limit cpFloat } + { v_bias cpVect } + { w_bias cpFloat } ; + +FUNCTION: cpBody* cpBodyAlloc ( ) ; +FUNCTION: cpBody* cpBodyInit ( cpBody* body, cpFloat m, cpFloat i ) ; +FUNCTION: cpBody* cpBodyNew ( cpFloat m, cpFloat i ) ; +FUNCTION: void cpBodyDestroy ( cpBody* body ) ; +FUNCTION: void cpBodyFree ( cpBody* body ) ; +FUNCTION: void cpBodySetMass ( cpBody* body, cpFloat m ) ; +FUNCTION: void cpBodySetMoment ( cpBody* body, cpFloat i ) ; +FUNCTION: void cpBodySetAngle ( cpBody* body, cpFloat a ) ; +FUNCTION: void cpBodySlew ( cpBody* body, cpVect pos, cpFloat dt ) ; +FUNCTION: void cpBodyUpdateVelocity ( cpBody* body, cpVect gravity, cpFloat damping, cpFloat dt ) ; +FUNCTION: void cpBodyUpdatePosition ( cpBody* body, cpFloat dt ) ; + +TYPED: cpBodyLocal2World ( body: cpBody v: cpVect -- v2: cpVect ) + [ drop p>> ] + [ swap rot>> cpvrotate ] 2bi cpvadd ; inline + +TYPED: cpBodyWorld2Local ( body: cpBody v: cpVect -- v2: cpVect ) + [ swap p>> cpvsub ] + [ drop rot>> ] 2bi cpvunrotate ; inline + +TYPED: cpBodyApplyImpulse ( body: cpBody j: cpVect r: cpVect -- ) + [ + drop + [ drop dup v>> ] + [ swap m_inv>> cpvmult ] 2bi cpvadd >>v drop + ] + [ + [ 2drop dup w_bias>> ] + [ swap cpvcross [ i_inv>> ] dip * ] 3bi + >>w_bias drop + ] 3bi ; inline + +FUNCTION: void cpBodyResetForces ( cpBody* body ) ; +FUNCTION: void cpBodyApplyForce ( cpBody* body, cpVect f, cpVect r ) ; +FUNCTION: void cpApplyDampedSpring ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat rlen, cpFloat k, cpFloat dmp, cpFloat dt ) ; + +! cpArray.h +STRUCT: cpArray + { num int } + { max int } + { arr void** } ; + +CALLBACK: void cpArrayIter ( void* ptr, void* data ) ; + +FUNCTION: cpArray* cpArrayAlloc ( ) ; +FUNCTION: cpArray* cpArrayInit ( cpArray* arr, int size ) ; +FUNCTION: cpArray* cpArrayNew ( int size ) ; +FUNCTION: void cpArrayDestroy ( cpArray* arr ) ; +FUNCTION: void cpArrayFree ( cpArray* arr ) ; +FUNCTION: void cpArrayPush ( cpArray* arr, void* object ) ; +FUNCTION: void cpArrayDeleteIndex ( cpArray* arr, int idx ) ; +FUNCTION: void cpArrayDeleteObj ( cpArray* arr, void* obj ) ; +FUNCTION: void cpArrayEach ( cpArray* arr, cpArrayIter iterFunc, void* data ) ; +FUNCTION: int cpArrayContains ( cpArray* arr, void* ptr ) ; + +! cpHashSet.h +STRUCT: cpHashSetBin + { elt void* } + { hash cpHashValue } + { next cpHashSetBin* } ; + +CALLBACK: int cpHashSetEqlFunc ( void* ptr, void* elt ) ; +CALLBACK: void* cpHashSetTransFunc ( void* ptr, void* data ) ; +CALLBACK: void cpHashSetIterFunc ( void* elt, void* data ) ; +CALLBACK: int cpHashSetFilterFunc ( void* elt, void* data ) ; + +STRUCT: cpHashSet + { entries int } + { size int } + { eql cpHashSetEqlFunc } + { trans cpHashSetTransFunc } + { default_value void* } + { table cpHashSetBin** } ; + +FUNCTION: void cpHashSetDestroy ( cpHashSet* set ) ; +FUNCTION: void cpHashSetFree ( cpHashSet* set ) ; +FUNCTION: cpHashSet* cpHashSetAlloc ( ) ; +FUNCTION: cpHashSet* cpHashSetInit ( cpHashSet* set, int size, cpHashSetEqlFunc eqlFunc, cpHashSetTransFunc trans ) ; +FUNCTION: cpHashSet* cpHashSetNew ( int size, cpHashSetEqlFunc eqlFunc, cpHashSetTransFunc trans ) ; +FUNCTION: void* cpHashSetInsert ( cpHashSet* set, cpHashValue hash, void* ptr, void* data ) ; +FUNCTION: void* cpHashSetRemove ( cpHashSet* set, cpHashValue hash, void* ptr ) ; +FUNCTION: void* cpHashSetFind ( cpHashSet* set, cpHashValue hash, void* ptr ) ; +FUNCTION: void cpHashSetEach ( cpHashSet* set, cpHashSetIterFunc func, void* data ) ; +FUNCTION: void cpHashSetFilter ( cpHashSet* set, cpHashSetFilterFunc func, void* data ) ; + +! cpSpaceHash.h +STRUCT: cpHandle + { obj void* } + { retain int } + { stamp int } ; + +STRUCT: cpSpaceHashBin + { handle cpHandle* } + { next cpSpaceHashBin* } ; + +CALLBACK: cpBB cpSpaceHashBBFunc ( void* obj ) ; + +STRUCT: cpSpaceHash + { numcells int } + { celldim cpFloat } + { bbfunc cpSpaceHashBBFunc } + { handleSet cpHashSet* } + { table cpSpaceHashBin** } + { bins cpSpaceHashBin* } + { stamp int } ; + +FUNCTION: cpSpaceHash* cpSpaceHashAlloc ( ) ; +FUNCTION: cpSpaceHash* cpSpaceHashInit ( cpSpaceHash* hash, cpFloat celldim, int cells, cpSpaceHashBBFunc bbfunc ) ; +FUNCTION: cpSpaceHash* cpSpaceHashNew ( cpFloat celldim, int cells, cpSpaceHashBBFunc bbfunc ) ; +FUNCTION: void cpSpaceHashDestroy ( cpSpaceHash* hash ) ; +FUNCTION: void cpSpaceHashFree ( cpSpaceHash* hash ) ; +FUNCTION: void cpSpaceHashResize ( cpSpaceHash* hash, cpFloat celldim, int numcells ) ; +FUNCTION: void cpSpaceHashInsert ( cpSpaceHash* hash, void* obj, cpHashValue id, cpBB bb ) ; +FUNCTION: void cpSpaceHashRemove ( cpSpaceHash* hash, void* obj, cpHashValue id ) ; +CALLBACK: void cpSpaceHashIterator ( void* obj, void* data ) ; +FUNCTION: void cpSpaceHashEach ( cpSpaceHash* hash, cpSpaceHashIterator func, void* data ) ; +FUNCTION: void cpSpaceHashRehash ( cpSpaceHash* hash ) ; +FUNCTION: void cpSpaceHashRehashObject ( cpSpaceHash* hash, void* obj, cpHashValue id ) ; +CALLBACK: void cpSpaceHashQueryFunc ( void* obj1, void* obj2, void* data ) ; +FUNCTION: void cpSpaceHashPointQuery ( cpSpaceHash* hash, cpVect point, cpSpaceHashQueryFunc func, void* data ) ; +FUNCTION: void cpSpaceHashQuery ( cpSpaceHash* hash, void* obj, cpBB bb, cpSpaceHashQueryFunc func, void* data ) ; +FUNCTION: void cpSpaceHashQueryRehash ( cpSpaceHash* hash, cpSpaceHashQueryFunc func, void* data ) ; +CALLBACK: cpFloat cpSpaceHashSegmentQueryFunc ( void* obj1, void* obj2, void* data ) ; +FUNCTION: void cpSpaceHashSegmentQuery ( cpSpaceHash* hash, void* obj, cpVect a, cpVect b, cpFloat t_exit, cpSpaceHashSegmentQueryFunc func, void* data ) ; + +! cpShape.h +C-TYPE: cpShape +C-TYPE: cpShapeClass + +STRUCT: cpSegmentQueryInfo + { shape cpShape* } + { t cpFloat } + { n cpVect } ; + +C-ENUM: + CP_CIRCLE_SHAPE + CP_SEGMENT_SHAPE + CP_POLY_SHAPE + CP_NUM_SHAPES ; +TYPEDEF: int cpShapeType + +CALLBACK: cpBB cacheData_cb ( cpShape* shape, cpVect p, cpVect rot ) ; +CALLBACK: void destroy_cb ( cpShape* shape ) ; +CALLBACK: int pointQuery_cb ( cpShape* shape, cpVect p ) ; +CALLBACK: void segmentQuery_cb ( cpShape* shape, cpVect a, cpVect b, cpSegmentQueryInfo* info ) ; + +STRUCT: cpShapeClass + { type cpShapeType } + { cacheData cacheData_cb } + { destroy destroy_cb } + { pointQuery pointQuery_cb } + { segmentQuery segmentQuery_cb } ; + +STRUCT: cpShape + { klass cpShapeClass* } + { body cpBody* } + { bb cpBB } + { sensor int } + { e cpFloat } + { u cpFloat } + { surface_v cpVect } + { data cpDataPointer } + { collision_type cpCollisionType } + { group cpGroup } + { layers cpLayers } + { hashid cpHashValue } ; + +FUNCTION: cpShape* cpShapeInit ( cpShape* shape, cpShapeClass* klass, cpBody* body ) ; +FUNCTION: void cpShapeDestroy ( cpShape* shape ) ; +FUNCTION: void cpShapeFree ( cpShape* shape ) ; +FUNCTION: cpBB cpShapeCacheBB ( cpShape* shape ) ; +FUNCTION: int cpShapePointQuery ( cpShape* shape, cpVect p ) ; + +STRUCT: cpCircleShape + { shape cpShape } + { c cpVect } + { r cpFloat } + { tc cpVect } ; + +FUNCTION: cpCircleShape* cpCircleShapeAlloc ( ) ; +FUNCTION: cpCircleShape* cpCircleShapeInit ( cpCircleShape* circle, cpBody* body, cpFloat radius, cpVect offset ) ; +FUNCTION: cpShape* cpCircleShapeNew ( cpBody* body, cpFloat radius, cpVect offset ) ; + +STRUCT: cpSegmentShape + { shape cpShape } + { a cpVect } + { b cpVect } + { n cpVect } + { r cpFloat } + { ta cpVect } + { tb cpVect } + { tn cpVect } ; + +FUNCTION: cpSegmentShape* cpSegmentShapeAlloc ( ) ; +FUNCTION: cpSegmentShape* cpSegmentShapeInit ( cpSegmentShape* seg, cpBody* body, cpVect a, cpVect b, cpFloat radius ) ; +FUNCTION: cpShape* cpSegmentShapeNew ( cpBody* body, cpVect a, cpVect b, cpFloat radius ) ; +FUNCTION: void cpResetShapeIdCounter ( ) ; +FUNCTION: void cpSegmentQueryInfoPrint ( cpSegmentQueryInfo* info ) ; +FUNCTION: int cpShapeSegmentQuery ( cpShape* shape, cpVect a, cpVect b, cpSegmentQueryInfo* info ) ; + +TYPED: cpSegmentQueryHitPoint ( start: cpVect end: cpVect info: cpSegmentQueryInfo -- hit-point: cpVect ) + t>> cpvlerp ; inline + +TYPED: cpSegmentQueryHitDist ( start: cpVect end: cpVect info: cpSegmentQueryInfo -- hit-dist ) + t>> [ cpvdist ] dip * ; inline + +! cpPolyShape.h +STRUCT: cpPolyShapeAxis + { n cpVect } + { d cpFloat } ; +SPECIALIZED-ARRAY: cpPolyShapeAxis + +STRUCT: cpPolyShape + { shape cpShape } + { numVerts int } + { verts cpVect* } + { axes cpPolyShapeAxis* } + { tVerts cpVect* } + { tAxes cpPolyShapeAxis* } ; + +FUNCTION: cpPolyShape* cpPolyShapeAlloc ( ) ; +FUNCTION: cpPolyShape* cpPolyShapeInit ( cpPolyShape* poly, cpBody* body, int numVerts, cpVect* verts, cpVect offset ) ; +FUNCTION: cpShape* cpPolyShapeNew ( cpBody* body, int numVerts, cpVect* verts, cpVect offset ) ; +FUNCTION: int cpPolyValidate ( cpVect* verts, int numVerts ) ; +FUNCTION: int cpPolyShapeGetNumVerts ( cpShape* shape ) ; +FUNCTION: cpVect cpPolyShapeGetVert ( cpShape* shape, int idx ) ; + +TYPED: cpPolyShapeValueOnAxis ( poly: cpPolyShape n: cpVect d -- min-dist ) + swap rot [ numVerts>> ] [ tVerts>> swap ] bi swap + [ cpvdot ] curry [ min ] reduce swap - ; inline + +TYPED: cpPolyShapeContainsVert ( poly: cpPolyShape v: cpVect -- ? ) + swap [ numVerts>> ] [ tAxes>> swap ] bi swap + [ + [ [ n>> ] dip cpvdot ] [ drop d>> ] 2bi - + ] curry [ max ] reduce 0.0 <= ; inline + +TYPED: cpPolyShapeContainsVertPartial ( poly: cpPolyShape v: cpVect n: cpVect -- ? ) + rot [ numVerts>> ] [ tAxes>> swap ] bi -rot + [| axis v n | + axis n>> n cpvdot 0.0 < 0 + [ 0.0 ] + [ axis n>> v cpvdot axis d>> - ] + if + ] 2curry [ max ] reduce 0.0 <= ; inline + +! cpArbiter.h +C-TYPE: cpArbiter +C-TYPE: cpSpace +C-TYPE: cpCollisionHandler + +STRUCT: cpContact + { p cpVect } + { n cpVect } + { dist cpFloat } + { r1 cpVect } + { r2 cpVect } + { nMass cpFloat } + { tMass cpFloat } + { bounce cpFloat } + { jnAcc cpFloat } + { jtAcc cpFloat } + { jBias cpFloat } + { bias cpFloat } + { hash cpHashValue } ; + +FUNCTION: cpContact* cpContactInit ( cpContact* con, cpVect p, cpVect n, cpFloat dist, cpHashValue hash ) ; + +C-ENUM: + cpArbiterStateNormal + cpArbiterStateFirstColl + cpArbiterStateIgnore ; +TYPEDEF: int cpArbiterState + +STRUCT: cpArbiter + { numContacts int } + { contacts cpContact* } + { a cpShape* } + { b cpShape* } + { e cpFloat } + { u cpFloat } + { surface_vr cpVect } + { stamp int } + { handler cpCollisionHandler* } + { swappedColl char } + { state char } ; + +FUNCTION: cpArbiter* cpArbiterAlloc ( ) ; +FUNCTION: cpArbiter* cpArbiterInit ( cpArbiter* arb, cpShape* a, cpShape* b ) ; +FUNCTION: cpArbiter* cpArbiterNew ( cpShape* a, cpShape* b ) ; +FUNCTION: void cpArbiterDestroy ( cpArbiter* arb ) ; +FUNCTION: void cpArbiterFree ( cpArbiter* arb ) ; +FUNCTION: void cpArbiterUpdate ( cpArbiter* arb, cpContact* contacts, int numContacts, cpCollisionHandler* handler, cpShape* a, cpShape* b ) ; +FUNCTION: void cpArbiterPreStep ( cpArbiter* arb, cpFloat dt_inv ) ; +FUNCTION: void cpArbiterApplyCachedImpulse ( cpArbiter* arb ) ; +FUNCTION: void cpArbiterApplyImpulse ( cpArbiter* arb, cpFloat eCoef ) ; +FUNCTION: cpVect cpArbiterTotalImpulse ( cpArbiter* arb ) ; +FUNCTION: cpVect cpArbiterTotalImpulseWithFriction ( cpArbiter* arb ) ; +FUNCTION: void cpArbiterIgnore ( cpArbiter* arb ) ; + +TYPED: cpArbiterGetShapes ( arb: cpArbiter -- a: cpShape b: cpShape ) + dup swappedColl>> 0 = [ + [ a>> cpShape memory>struct ] [ b>> cpShape memory>struct ] bi + ] [ + [ b>> cpShape memory>struct ] [ a>> cpShape memory>struct ] bi + ] if ; inline + +TYPED: cpArbiterIsFirstContact ( arb: cpArbiter -- ? ) + state>> cpArbiterStateFirstColl = ; inline + +TYPED: cpArbiterGetNormal ( arb: cpArbiter i -- n: cpVect ) + [ + swap + [ numContacts>> ] + [ contacts>> swap ] bi nth cpContact memory>struct n>> + ] + [ + drop swappedColl>> 0 = [ ] [ cpvneg ] if + ] 2bi ; inline + +TYPED: cpArbiterGetPoint ( arb: cpArbiter i -- p: cpVect ) + swap + [ numContacts>> ] + [ contacts>> swap ] bi + nth cpContact memory>struct p>> ; inline + +! cpCollision.h +FUNCTION: int cpCollideShapes ( cpShape* a, cpShape* b, cpContact** arr ) ; + +! cpConstraint.h + +C-TYPE: cpConstraintClass +C-TYPE: cpConstraint + +CALLBACK: void cpConstraintPreStepFunction ( cpConstraint* constraint, cpFloat dt, cpFloat dt_inv ) ; +CALLBACK: void cpConstraintApplyImpulseFunction ( cpConstraint* constraint ) ; +CALLBACK: cpFloat cpConstraintGetImpulseFunction ( cpConstraint* constraint ) ; + +STRUCT: cpConstraintClass + { preStep cpConstraintPreStepFunction } + { applyImpulse cpConstraintApplyImpulseFunction } + { getImpulse cpConstraintGetImpulseFunction } ; + +STRUCT: cpConstraint + { klass cpConstraintClass* } + { a cpBody* } + { b cpBody* } + { maxForce cpFloat } + { biasCoef cpFloat } + { maxBias cpFloat } + { data cpDataPointer } ; + +FUNCTION: void cpConstraintDestroy ( cpConstraint* constraint ) ; +FUNCTION: void cpConstraintFree ( cpConstraint* constraint ) ; +FUNCTION: void cpConstraintCheckCast ( cpConstraint* constraint, cpConstraintClass* klass ) ; + +! cpPinJoint.h +FUNCTION: cpConstraintClass* cpPinJointGetClass ( ) ; + +STRUCT: cpPinJoint + { constraint cpConstraint } + { anchr1 cpVect } + { anchr2 cpVect } + { dist cpFloat } + { r1 cpVect } + { r2 cpVect } + { n cpVect } + { nMass cpFloat } + { jnAcc cpFloat } + { jnMax cpFloat } + { bias cpFloat } ; + +FUNCTION: cpPinJoint* cpPinJointAlloc ( ) ; +FUNCTION: cpPinJoint* cpPinJointInit ( cpPinJoint* joint, cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2 ) ; +FUNCTION: cpConstraint* cpPinJointNew ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2 ) ; + +! cpSlideJoint.h +FUNCTION: cpConstraintClass* cpSlideJointGetClass ( ) ; + +STRUCT: cpSlideJoint + { constraint cpConstraint } + { anchr1 cpVect } + { anchr2 cpVect } + { min cpFloat } + { max cpFloat } + { r1 cpVect } + { r2 cpVect } + { n cpVect } + { nMass cpFloat } + { jnAcc cpFloat } + { jnMax cpFloat } + { bias cpFloat } ; + +FUNCTION: cpSlideJoint* cpSlideJointAlloc ( ) ; +FUNCTION: cpSlideJoint* cpSlideJointInit ( cpSlideJoint* joint, cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat min, cpFloat max ) ; +FUNCTION: cpConstraint* cpSlideJointNew ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat min, cpFloat max ) ; + +! cpPivotJoint.h +FUNCTION: cpConstraintClass* cpPivotJointGetClass ( ) ; + +STRUCT: cpPivotJoint + { constraint cpConstraint } + { anchr1 cpVect } + { anchr2 cpVect } + { r1 cpVect } + { r2 cpVect } + { k1 cpVect } + { k2 cpVect } + { jAcc cpVect } + { jMaxLen cpFloat } + { bias cpVect } ; + +FUNCTION: cpPivotJoint* cpPivotJointAlloc ( ) ; +FUNCTION: cpPivotJoint* cpPivotJointInit ( cpPivotJoint* joint, cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2 ) ; +FUNCTION: cpConstraint* cpPivotJointNew ( cpBody* a, cpBody* b, cpVect pivot ) ; +FUNCTION: cpConstraint* cpPivotJointNew2 ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2 ) ; + +! cpGrooveJoint.h +FUNCTION: cpConstraintClass* cpGrooveJointGetClass ( ) ; + +STRUCT: cpGrooveJoint + { constraint cpConstraint } + { grv_n cpVect } + { grv_a cpVect } + { grv_b cpVect } + { anchr2 cpVect } + { grv_tn cpVect } + { clamp cpFloat } + { r1 cpVect } + { r2 cpVect } + { k1 cpVect } + { k2 cpVect } + { jAcc cpVect } + { jMaxLen cpFloat } + { bias cpVect } ; + +FUNCTION: cpGrooveJoint* cpGrooveJointAlloc ( ) ; +FUNCTION: cpGrooveJoint* cpGrooveJointInit ( cpGrooveJoint* joint, cpBody* a, cpBody* b, cpVect groove_a, cpVect groove_b, cpVect anchr2 ) ; +FUNCTION: cpConstraint* cpGrooveJointNew ( cpBody* a, cpBody* b, cpVect groove_a, cpVect groove_b, cpVect anchr2 ) ; + +! cpDampedSpring.h +CALLBACK: cpFloat cpDampedSpringForceFunc ( cpConstraint* spring, cpFloat dist ) ; +FUNCTION: cpConstraintClass* cpDampedSpringGetClass ( ) ; + +STRUCT: cpDampedSpring + { constraint cpConstraint } + { anchr1 cpVect } + { anchr2 cpVect } + { restLength cpFloat } + { stiffness cpFloat } + { damping cpFloat } + { springForceFunc cpDampedSpringForceFunc } + { dt cpFloat } + { target_vrn cpFloat } + { r1 cpVect } + { r2 cpVect } + { nMass cpFloat } + { n cpVect } ; + +FUNCTION: cpDampedSpring* cpDampedSpringAlloc ( ) ; +FUNCTION: cpDampedSpring* cpDampedSpringInit ( cpDampedSpring* joint, cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat restLength, cpFloat stiffness, cpFloat damping ) ; +FUNCTION: cpConstraint* cpDampedSpringNew ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat restLength, cpFloat stiffness, cpFloat damping ) ; + +! cpDampedRotarySpring.h +CALLBACK: cpFloat cpDampedRotarySpringTorqueFunc ( cpConstraint* spring, cpFloat relativeAngle ) ; +FUNCTION: cpConstraintClass* cpDampedRotarySpringGetClass ( ) ; + +STRUCT: cpDampedRotarySpring + { constraint cpConstraint } + { restAngle cpFloat } + { stiffness cpFloat } + { damping cpFloat } + { springTorqueFunc cpDampedRotarySpringTorqueFunc } + { dt cpFloat } + { target_wrn cpFloat } + { iSum cpFloat } ; + +FUNCTION: cpDampedRotarySpring* cpDampedRotarySpringAlloc ( ) ; +FUNCTION: cpDampedRotarySpring* cpDampedRotarySpringInit ( cpDampedRotarySpring* joint, cpBody* a, cpBody* b, cpFloat restAngle, cpFloat stiffness, cpFloat damping ) ; +FUNCTION: cpConstraint* cpDampedRotarySpringNew ( cpBody* a, cpBody* b, cpFloat restAngle, cpFloat stiffness, cpFloat damping ) ; + +! cpRotaryLimitJoint.h +FUNCTION: cpConstraintClass* cpRotaryLimitJointGetClass ( ) ; + +STRUCT: cpRotaryLimitJoint + { constraint cpConstraint } + { min cpFloat } + { max cpFloat } + { iSum cpFloat } + { bias cpFloat } + { jAcc cpFloat } + { jMax cpFloat } ; + +FUNCTION: cpRotaryLimitJoint* cpRotaryLimitJointAlloc ( ) ; +FUNCTION: cpRotaryLimitJoint* cpRotaryLimitJointInit ( cpRotaryLimitJoint* joint, cpBody* a, cpBody* b, cpFloat min, cpFloat max ) ; +FUNCTION: cpConstraint* cpRotaryLimitJointNew ( cpBody* a, cpBody* b, cpFloat min, cpFloat max ) ; + +! cpRatchetJoint.h +FUNCTION: cpConstraintClass* cpRatchetJointGetClass ( ) ; + +STRUCT: cpRatchetJoint + { constraint cpConstraint } + { angle cpFloat } + { phase cpFloat } + { ratchet cpFloat } + { iSum cpFloat } + { bias cpFloat } + { jAcc cpFloat } + { jMax cpFloat } ; + +FUNCTION: cpRatchetJoint* cpRatchetJointAlloc ( ) ; +FUNCTION: cpRatchetJoint* cpRatchetJointInit ( cpRatchetJoint* joint, cpBody* a, cpBody* b, cpFloat phase, cpFloat ratchet ) ; +FUNCTION: cpConstraint* cpRatchetJointNew ( cpBody* a, cpBody* b, cpFloat phase, cpFloat ratchet ) ; + +! cpGearJoint.h +FUNCTION: cpConstraintClass* cpGearJointGetClass ( ) ; + +STRUCT: cpGearJoint + { constraint cpConstraint } + { phase cpFloat } + { ratio cpFloat } + { ratio_inv cpFloat } + { iSum cpFloat } + { bias cpFloat } + { jAcc cpFloat } + { jMax cpFloat } ; + +FUNCTION: cpGearJoint* cpGearJointAlloc ( ) ; +FUNCTION: cpGearJoint* cpGearJointInit ( cpGearJoint* joint, cpBody* a, cpBody* b, cpFloat phase, cpFloat ratio ) ; +FUNCTION: cpConstraint* cpGearJointNew ( cpBody* a, cpBody* b, cpFloat phase, cpFloat ratio ) ; +FUNCTION: void cpGearJointSetRatio ( cpConstraint* constraint, cpFloat value ) ; + +! cpSimpleMotor.h +FUNCTION: cpConstraintClass* cpSimpleMotorGetClass ( ) ; + +STRUCT: cpSimpleMotor + { constraint cpConstraint } + { rate cpFloat } + { iSum cpFloat } + { jAcc cpFloat } + { jMax cpFloat } ; + +FUNCTION: cpSimpleMotor* cpSimpleMotorAlloc ( ) ; +FUNCTION: cpSimpleMotor* cpSimpleMotorInit ( cpSimpleMotor* joint, cpBody* a, cpBody* b, cpFloat rate ) ; +FUNCTION: cpConstraint* cpSimpleMotorNew ( cpBody* a, cpBody* b, cpFloat rate ) ; + +! cpSpace.h +C-TYPE: cpSpace + +CALLBACK: int cpCollisionBeginFunc ( cpArbiter* arb, cpSpace* space, void* data ) ; +CALLBACK: int cpCollisionPreSolveFunc ( cpArbiter* arb, cpSpace* space, void* data ) ; +CALLBACK: void cpCollisionPostSolveFunc ( cpArbiter* arb, cpSpace* space, void* data ) ; +CALLBACK: void cpCollisionSeparateFunc ( cpArbiter* arb, cpSpace* space, void* data ) ; + +STRUCT: cpCollisionHandler + { a cpCollisionType } + { b cpCollisionType } + { begin cpCollisionBeginFunc } + { preSolve cpCollisionPreSolveFunc } + { postSolve cpCollisionPostSolveFunc } + { separate cpCollisionSeparateFunc } + { data void* } ; + +STRUCT: cpSpace + { iterations int } + { elasticIterations int } + { gravity cpVect } + { damping cpFloat } + { stamp int } + { staticShapes cpSpaceHash* } + { activeShapes cpSpaceHash* } + { bodies cpArray* } + { arbiters cpArray* } + { contactSet cpHashSet* } + { constraints cpArray* } + { collFuncSet cpHashSet* } + { defaultHandler cpCollisionHandler } + { postStepCallbacks cpHashSet* } ; + +FUNCTION: cpSpace* cpSpaceAlloc ( ) ; +FUNCTION: cpSpace* cpSpaceInit ( cpSpace* space ) ; +FUNCTION: cpSpace* cpSpaceNew ( ) ; +FUNCTION: void cpSpaceDestroy ( cpSpace* space ) ; +FUNCTION: void cpSpaceFree ( cpSpace* space ) ; +FUNCTION: void cpSpaceFreeChildren ( cpSpace* space ) ; +FUNCTION: void cpSpaceSetDefaultCollisionHandler ( + cpSpace* space, + cpCollisionBeginFunc begin, + cpCollisionPreSolveFunc preSolve, + cpCollisionPostSolveFunc postSolve, + cpCollisionSeparateFunc separate, + void* data ) ; +FUNCTION: void cpSpaceAddCollisionHandler ( + cpSpace* space, + cpCollisionType a, + cpCollisionType b, + cpCollisionBeginFunc begin, + cpCollisionPreSolveFunc preSolve, + cpCollisionPostSolveFunc postSolve, + cpCollisionSeparateFunc separate, + void* data ) ; +FUNCTION: void cpSpaceRemoveCollisionHandler ( cpSpace* space, cpCollisionType a, cpCollisionType b ) ; +FUNCTION: cpShape* cpSpaceAddShape ( cpSpace* space, cpShape* shape ) ; +FUNCTION: cpShape* cpSpaceAddStaticShape ( cpSpace* space, cpShape* shape ) ; +FUNCTION: cpBody* cpSpaceAddBody ( cpSpace* space, cpBody* body ) ; +FUNCTION: cpConstraint* cpSpaceAddConstraint ( cpSpace* space, cpConstraint* constraint ) ; +FUNCTION: void cpSpaceRemoveShape ( cpSpace* space, cpShape* shape ) ; +FUNCTION: void cpSpaceRemoveStaticShape ( cpSpace* space, cpShape* shape ) ; +FUNCTION: void cpSpaceRemoveBody ( cpSpace* space, cpBody* body ) ; +FUNCTION: void cpSpaceRemoveConstraint ( cpSpace* space, cpConstraint* constraint ) ; +CALLBACK: void cpPostStepFunc ( cpSpace* space, void* obj, void* data ) ; +FUNCTION: void cpSpaceAddPostStepCallback ( cpSpace* space, cpPostStepFunc func, void* obj, void* data ) ; +CALLBACK: void cpSpacePointQueryFunc ( cpShape* shape, void* data ) ; +FUNCTION: void cpSpacePointQuery ( cpSpace* space, cpVect point, cpLayers layers, cpGroup group, cpSpacePointQueryFunc func, void* data ) ; +FUNCTION: cpShape* cpSpacePointQueryFirst ( cpSpace* space, cpVect point, cpLayers layers, cpGroup group ) ; +CALLBACK: void cpSpaceSegmentQueryFunc ( cpShape* shape, cpFloat t, cpVect n, void* data ) ; +FUNCTION: int cpSpaceSegmentQuery ( cpSpace* space, cpVect start, cpVect end, cpLayers layers, cpGroup group, cpSpaceSegmentQueryFunc func, void* data ) ; +FUNCTION: cpShape* cpSpaceSegmentQueryFirst ( cpSpace* space, cpVect start, cpVect end, cpLayers layers, cpGroup group, cpSegmentQueryInfo* out ) ; +CALLBACK: void cpSpaceBBQueryFunc ( cpShape* shape, void* data ) ; +FUNCTION: void cpSpaceBBQuery ( cpSpace* space, cpBB bb, cpLayers layers, cpGroup group, cpSpaceBBQueryFunc func, void* data ) ; +CALLBACK: void cpSpaceBodyIterator ( cpBody* body, void* data ) ; +FUNCTION: void cpSpaceEachBody ( cpSpace* space, cpSpaceBodyIterator func, void* data ) ; +FUNCTION: void cpSpaceResizeStaticHash ( cpSpace* space, cpFloat dim, int count ) ; +FUNCTION: void cpSpaceResizeActiveHash ( cpSpace* space, cpFloat dim, int count ) ; +FUNCTION: void cpSpaceRehashStatic ( cpSpace* space ) ; +FUNCTION: void cpSpaceStep ( cpSpace* space, cpFloat dt ) ; + +! chipmunk.h +FUNCTION: void cpInitChipmunk ( ) ; +FUNCTION: cpFloat cpMomentForCircle ( cpFloat m, cpFloat r1, cpFloat r2, cpVect offset ) ; +FUNCTION: cpFloat cpMomentForSegment ( cpFloat m, cpVect a, cpVect b ) ; +FUNCTION: cpFloat cpMomentForPoly ( cpFloat m, int numVerts, cpVect* verts, cpVect offset ) ; + diff --git a/extra/chipmunk/demo/authors.txt b/extra/chipmunk/demo/authors.txt new file mode 100644 index 0000000000..6f03a12101 --- /dev/null +++ b/extra/chipmunk/demo/authors.txt @@ -0,0 +1 @@ +Erik Charlebois diff --git a/extra/chipmunk/demo/demo.factor b/extra/chipmunk/demo/demo.factor new file mode 100644 index 0000000000..031ed576b6 --- /dev/null +++ b/extra/chipmunk/demo/demo.factor @@ -0,0 +1,151 @@ +! Copyright (C) 2010 Erik Charlebois +! See http:// factorcode.org/license.txt for BSD license. +USING: accessors chipmunk classes.struct game.loop game.worlds gpu +gpu.util.wasd kernel literals locals math method-chains opengl.gl +random sequences specialized-arrays +specialized-arrays.instances.alien.c-types.void* ui.gadgets.worlds +ui.pixel-formats ; +IN: chipmunk.demo + +CONSTANT: image-width 188 +CONSTANT: image-height 35 +CONSTANT: image-row-length 24 + +CONSTANT: image-bitmap B{ + 15 -16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 -64 15 63 -32 -2 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 31 -64 15 127 -125 -1 -128 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 127 -64 15 127 15 -1 -64 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 -64 15 -2 + 31 -1 -64 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 -64 0 -4 63 -1 -32 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 1 -1 -64 15 -8 127 -1 -32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 -1 -64 0 -8 -15 -1 -32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -31 -1 -64 15 -8 -32 + -1 -32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 -15 -1 -64 9 -15 -32 -1 -32 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 31 -15 -1 -64 0 -15 -32 -1 -32 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 63 -7 -1 -64 9 -29 -32 127 -61 -16 63 15 -61 -1 -8 31 -16 15 -8 126 7 -31 + -8 31 -65 -7 -1 -64 9 -29 -32 0 7 -8 127 -97 -25 -1 -2 63 -8 31 -4 -1 15 -13 + -4 63 -1 -3 -1 -64 9 -29 -32 0 7 -8 127 -97 -25 -1 -2 63 -8 31 -4 -1 15 -13 + -2 63 -1 -3 -1 -64 9 -29 -32 0 7 -8 127 -97 -25 -1 -1 63 -4 63 -4 -1 15 -13 + -2 63 -33 -1 -1 -32 9 -25 -32 0 7 -8 127 -97 -25 -1 -1 63 -4 63 -4 -1 15 -13 + -1 63 -33 -1 -1 -16 9 -25 -32 0 7 -8 127 -97 -25 -1 -1 63 -4 63 -4 -1 15 -13 + -1 63 -49 -1 -1 -8 9 -57 -32 0 7 -8 127 -97 -25 -8 -1 63 -2 127 -4 -1 15 -13 + -1 -65 -49 -1 -1 -4 9 -57 -32 0 7 -8 127 -97 -25 -8 -1 63 -2 127 -4 -1 15 -13 + -1 -65 -57 -1 -1 -2 9 -57 -32 0 7 -8 127 -97 -25 -8 -1 63 -2 127 -4 -1 15 -13 + -1 -1 -57 -1 -1 -1 9 -57 -32 0 7 -1 -1 -97 -25 -8 -1 63 -1 -1 -4 -1 15 -13 -1 + -1 -61 -1 -1 -1 -119 -57 -32 0 7 -1 -1 -97 -25 -8 -1 63 -1 -1 -4 -1 15 -13 -1 + -1 -61 -1 -1 -1 -55 -49 -32 0 7 -1 -1 -97 -25 -8 -1 63 -1 -1 -4 -1 15 -13 -1 + -1 -63 -1 -1 -1 -23 -49 -32 127 -57 -1 -1 -97 -25 -1 -1 63 -1 -1 -4 -1 15 -13 + -1 -1 -63 -1 -1 -1 -16 -49 -32 -1 -25 -1 -1 -97 -25 -1 -1 63 -33 -5 -4 -1 15 + -13 -1 -1 -64 -1 -9 -1 -7 -49 -32 -1 -25 -8 127 -97 -25 -1 -1 63 -33 -5 -4 -1 + 15 -13 -1 -1 -64 -1 -13 -1 -32 -49 -32 -1 -25 -8 127 -97 -25 -1 -2 63 -49 -13 + -4 -1 15 -13 -1 -1 -64 127 -7 -1 -119 -17 -15 -1 -25 -8 127 -97 -25 -1 -2 63 + -49 -13 -4 -1 15 -13 -3 -1 -64 127 -8 -2 15 -17 -1 -1 -25 -8 127 -97 -25 -1 + -8 63 -49 -13 -4 -1 15 -13 -3 -1 -64 63 -4 120 0 -17 -1 -1 -25 -8 127 -97 -25 + -8 0 63 -57 -29 -4 -1 15 -13 -4 -1 -64 63 -4 0 15 -17 -1 -1 -25 -8 127 -97 + -25 -8 0 63 -57 -29 -4 -1 -1 -13 -4 -1 -64 31 -2 0 0 103 -1 -1 -57 -8 127 -97 + -25 -8 0 63 -57 -29 -4 -1 -1 -13 -4 127 -64 31 -2 0 15 103 -1 -1 -57 -8 127 + -97 -25 -8 0 63 -61 -61 -4 127 -1 -29 -4 127 -64 15 -8 0 0 55 -1 -1 -121 -8 + 127 -97 -25 -8 0 63 -61 -61 -4 127 -1 -29 -4 63 -64 15 -32 0 0 23 -1 -2 3 -16 + 63 15 -61 -16 0 31 -127 -127 -8 31 -1 -127 -8 31 -128 7 -128 0 0 } + +:: get-pixel ( x y -- z ) + x -3 shift y image-row-length * + image-bitmap nth + x bitnot 7 bitand neg shift 1 bitand 1 = ; + +:: make-ball ( x y -- shape ) + cpBodyAlloc 1.0 NAN: 0 cpBodyInit cpBody memory>struct + x y cpv >>p :> body + cpCircleShapeAlloc body 0.95 0 0 cpv cpCircleShapeInit cpCircleShape memory>struct + [ shape>> 0 >>e ] [ shape>> 0 >>u ] bi drop ; + +TUPLE: chipmunk-world < wasd-world + space ; + +AFTER: chipmunk-world tick-game-world + space>> 1.0 60.0 / cpSpaceStep ; + +SPECIALIZED-ARRAY: cpContact +M:: chipmunk-world draw-world* ( world -- ) + 1 1 1 0 glClearColor + GL_COLOR_BUFFER_BIT glClear + GL_PROJECTION glMatrixMode + glLoadIdentity + -320 320 -240 240 -1 1 glOrtho + 0.5 0.5 0 glTranslatef + GL_VERTEX_ARRAY glEnableClientState + + world space>> :> space + + 3 glPointSize + 0 0 0 glColor3f + GL_POINTS glBegin + space bodies>> cpArray memory>struct + [ num>> ] [ arr>> swap ] bi [ + cpBody memory>struct p>> [ x>> ] [ y>> ] bi glVertex2f + ] each + glEnd + + 2 glPointSize + 1 0 0 glColor3f + GL_POINTS glBegin + space arbiters>> cpArray memory>struct + [ num>> ] [ arr>> swap ] bi [ + cpArbiter memory>struct + [ numContacts>> ] [ contacts>> swap ] bi [ + p>> [ x>> ] [ y>> ] bi glVertex2f + ] each + ] each + glEnd ; + +M:: chipmunk-world begin-game-world ( world -- ) + cpInitChipmunk + init-gpu + world { -0.2 0.13 0.1 } 1.1 0.2 set-wasd-view drop + + cpSpaceAlloc cpSpaceInit cpSpace memory>struct :> space + + world space >>space drop + space 2.0 10000 cpSpaceResizeActiveHash + space 1 >>iterations drop + + image-height iota [| y | + image-width iota [| x | + x y get-pixel [ + x image-width 2 / - 0.05 0.0 1.0 uniform-random-float * + 2 * + image-height 2 / y - 0.05 0.0 1.0 uniform-random-float * + 2 * + make-ball :> shape + space shape body>> cpSpaceAddBody drop + space shape cpSpaceAddShape drop + ] when + ] each + ] each + + space cpBodyAlloc NAN: 0 dup cpBodyInit cpSpaceAddBody cpBody memory>struct :> body + body -1000 -10 cpv >>p drop + body 400 0 cpv >>v drop + + space cpCircleShapeAlloc body 8 0 0 cpv cpCircleShapeInit cpSpaceAddShape cpCircleShape memory>struct :> shape + shape + [ shape>> 0 >>e drop ] + [ shape>> 0 >>u drop ] bi ; + +M: chipmunk-world end-game-world + space>> + [ cpSpaceFreeChildren ] + [ cpSpaceFree ] bi ; + +M: chipmunk-world wasd-movement-speed drop 1/160. ; +M: chipmunk-world wasd-near-plane drop 1/32. ; +M: chipmunk-world wasd-far-plane drop 256.0 ; + +GAME: chipmunk-demo { + { world-class chipmunk-world } + { title "Chipmunk Physics Demo" } + { pixel-format-attributes { + windowed + double-buffered + T{ depth-bits { value 24 } } + } } + { grab-input? t } + { use-game-input? t } + { pref-dim { 640 480 } } + { tick-interval-micros $[ 60 fps ] } + } ; diff --git a/extra/chipmunk/demo/summary.txt b/extra/chipmunk/demo/summary.txt new file mode 100644 index 0000000000..6aaf716bb0 --- /dev/null +++ b/extra/chipmunk/demo/summary.txt @@ -0,0 +1 @@ +Demonstration of Chipmunk library bindings. diff --git a/extra/chipmunk/summary.txt b/extra/chipmunk/summary.txt new file mode 100644 index 0000000000..ebc56a79ed --- /dev/null +++ b/extra/chipmunk/summary.txt @@ -0,0 +1 @@ +FFI bindings to the Chipmunk 2D physics library. From a19c5f566311ba86b8f01098eac92161eb29ee82 Mon Sep 17 00:00:00 2001 From: Erik Charlebois Date: Wed, 10 Feb 2010 22:03:39 -0800 Subject: [PATCH 04/12] Update FUEL font coloring for new syntactic keywords --- misc/fuel/fuel-font-lock.el | 2 ++ misc/fuel/fuel-syntax.el | 16 ++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/misc/fuel/fuel-font-lock.el b/misc/fuel/fuel-font-lock.el index aa7d25ebbd..983e1bcb98 100644 --- a/misc/fuel/fuel-font-lock.el +++ b/misc/fuel/fuel-font-lock.el @@ -101,6 +101,8 @@ (,fuel-syntax--brace-words-regex 1 'factor-font-lock-parsing-word) (,fuel-syntax--alien-function-regex (1 'factor-font-lock-type-name) (2 'factor-font-lock-word)) + (,fuel-syntax--alien-callback-regex (1 'factor-font-lock-type-name) + (2 'factor-font-lock-word)) (,fuel-syntax--vocab-ref-regexp 2 'factor-font-lock-vocabulary-name) (,fuel-syntax--constructor-decl-regex (1 'factor-font-lock-word) diff --git a/misc/fuel/fuel-syntax.el b/misc/fuel/fuel-syntax.el index c22d03bdc5..1b060e5dd1 100644 --- a/misc/fuel/fuel-syntax.el +++ b/misc/fuel/fuel-syntax.el @@ -46,7 +46,7 @@ '(":" "::" ";" "&:" "<<" ">" "ABOUT:" "ALIAS:" "ALIEN:" "ARTICLE:" "B" "BIN:" - "C:" "C-ENUM:" "C-STRUCT:" "C-UNION:" "CHAR:" "CONSTANT:" "call-next-method" + "C:" "CALLBACK:" "C-ENUM:" "C-STRUCT:" "C-TYPE:" "C-UNION:" "CHAR:" "CONSTANT:" "call-next-method" "DEFER:" "EBNF:" ";EBNF" "ERROR:" "EXCLUDE:" "f" "FORGET:" "FROM:" "FUNCTION:" @@ -61,7 +61,7 @@ "POSTPONE:" "PREDICATE:" "PRIMITIVE:" "PRIVATE>" "PROVIDE:" "QUALIFIED-WITH:" "QUALIFIED:" "read-only" "RENAME:" "REQUIRE:" "REQUIRES:" - "SINGLETON:" "SINGLETONS:" "SLOT:" "STRING:" "SYMBOL:" "SYMBOLS:" "SYNTAX:" + "SINGLETON:" "SINGLETONS:" "SLOT:" "SPECIALIZED-ARRAY:" "SPECIALIZED-ARRAYS:" "STRING:" "STRUCT:" "SYMBOL:" "SYMBOLS:" "SYNTAX:" "TUPLE:" "t" "t?" "TYPEDEF:" "TYPED:" "TYPED::" "UNIFORM-TUPLE:" "UNION:" "USE:" "USING:" "VARS:" "VERTEX-FORMAT:")) @@ -125,7 +125,7 @@ (defconst fuel-syntax--type-definition-regex (fuel-syntax--second-word-regex - '("C-STRUCT:" "C-UNION:" "MIXIN:" "TUPLE:" "SINGLETON:" "UNION:"))) + '("C-STRUCT:" "C-UNION:" "MIXIN:" "TUPLE:" "SINGLETON:" "SPECIALIZED-ARRAY:" "STRUCT:" "UNION:"))) (defconst fuel-syntax--tuple-decl-regex "^TUPLE: +\\([^ \n]+\\) +< +\\([^ \n]+\\)\\_>") @@ -152,6 +152,9 @@ (defconst fuel-syntax--alien-function-regex "\\_" "\\)" (1 "\\)" + ("\\_<\\(SYMBOLS\\|VARS\\|SPECIALIZED-ARRAYS\\|SINGLETONS\\): *?\\( \\|\n\\)\\([^;\n]\\|\\_>\\)" (2 "" (1 ">b")) ;; Let and lambda: From a118f208dca35c09530364507a20b6c5e9d6185d Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 12 Feb 2010 02:50:59 +1300 Subject: [PATCH 05/12] compiler.tree.propagation, compiler.tree.escape-analysis: make these passes handle constants in a more robust way in compilation units involving tuple reshaping --- .../tree/escape-analysis/simple/simple.factor | 7 +++++-- .../tree/propagation/slots/slots.factor | 21 ++++++++++++++----- core/classes/tuple/tuple-tests.factor | 18 ++++++++++++++++ core/classes/tuple/tuple.factor | 4 ++++ 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/basis/compiler/tree/escape-analysis/simple/simple.factor b/basis/compiler/tree/escape-analysis/simple/simple.factor index 50fa7ef0a8..5be206f2f8 100644 --- a/basis/compiler/tree/escape-analysis/simple/simple.factor +++ b/basis/compiler/tree/escape-analysis/simple/simple.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2008, 2009 Slava Pestov. +! Copyright (C) 2008, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: kernel accessors sequences classes.tuple classes.tuple.private arrays math math.private slots.private @@ -50,7 +50,10 @@ DEFER: record-literal-allocation if* ; M: #push escape-analysis* - [ out-d>> first ] [ literal>> ] bi record-literal-allocation ; + dup literal>> layout-up-to-date? + [ [ out-d>> first ] [ literal>> ] bi record-literal-allocation ] + [ out-d>> unknown-allocations ] + if ; : record-unknown-allocation ( #call -- ) [ in-d>> add-escaping-values ] diff --git a/basis/compiler/tree/propagation/slots/slots.factor b/basis/compiler/tree/propagation/slots/slots.factor index 11a4cdc4c6..18d31985d6 100644 --- a/basis/compiler/tree/propagation/slots/slots.factor +++ b/basis/compiler/tree/propagation/slots/slots.factor @@ -1,9 +1,10 @@ -! Copyright (C) 2008, 2009 Slava Pestov. +! Copyright (C) 2008, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: fry assocs arrays byte-arrays strings accessors sequences kernel slots classes.algebra classes.tuple classes.tuple.private -words math math.private combinators sequences.private namespaces -slots.private classes compiler.tree.propagation.info ; +combinators.short-circuit words math math.private combinators +sequences.private namespaces slots.private classes +compiler.tree.propagation.info ; IN: compiler.tree.propagation.slots ! Propagation of immutable slots and array lengths @@ -52,8 +53,18 @@ UNION: fixed-length-sequence array byte-array string ; dup [ read-only>> ] when ; : literal-info-slot ( slot object -- info/f ) - 2dup class read-only-slot? - [ swap slot ] [ 2drop f ] if ; + #! literal-info-slot makes an unsafe call to 'slot'. + #! Check that the layout is up to date to avoid accessing the + #! wrong slot during a compilation unit where reshaping took + #! place. This could happen otherwise because the "slots" word + #! property would reflect the new layout, but instances in the + #! heap would use the old layout since instances are updated + #! immediately after compilation. + { + [ class read-only-slot? ] + [ nip layout-up-to-date? ] + [ swap slot ] + } 2&& ; : length-accessor? ( slot info -- ? ) [ 1 = ] [ length>> ] bi* and ; diff --git a/core/classes/tuple/tuple-tests.factor b/core/classes/tuple/tuple-tests.factor index fe55365f46..f452d8fb28 100644 --- a/core/classes/tuple/tuple-tests.factor +++ b/core/classes/tuple/tuple-tests.factor @@ -746,3 +746,21 @@ TUPLE: g < a-g ; [ ] [ "IN: classes.tuple.tests MIXIN: a-g TUPLE: g ;" eval( -- ) ] unit-test [ t ] [ g new layout-of "g" get layout-of eq? ] unit-test + +! Joe Groff discovered this bug +DEFER: factor-crashes-anymore + +[ ] [ + "IN: classes.tuple.tests + TUPLE: unsafe-slot-access ; + CONSTANT: unsafe-slot-access' T{ unsafe-slot-access }" eval( -- ) +] unit-test + +[ ] [ + "IN: classes.tuple.tests + USE: accessors + TUPLE: unsafe-slot-access { x read-only initial: 31337 } ; + : factor-crashes-anymore ( -- x ) unsafe-slot-access' x>> ;" eval( -- ) +] unit-test + +[ 31337 ] [ factor-crashes-anymore ] unit-test diff --git a/core/classes/tuple/tuple.factor b/core/classes/tuple/tuple.factor index ee49980f4d..363c2879e9 100644 --- a/core/classes/tuple/tuple.factor +++ b/core/classes/tuple/tuple.factor @@ -32,6 +32,10 @@ M: tuple class layout-of 2 slot { word } declare ; inline : tuple-size ( tuple -- size ) layout-of 3 slot { fixnum } declare ; inline +: layout-up-to-date? ( object -- ? ) + dup tuple? + [ [ layout-of ] [ class tuple-layout ] bi eq? ] [ drop t ] if ; + : check-tuple ( object -- tuple ) dup tuple? [ not-a-tuple ] unless ; inline From 72013c88c968104bda7c1e8f3f3178a1636bcd45 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Thu, 11 Feb 2010 10:55:50 -0800 Subject: [PATCH 06/12] use inline and TYPED: in terrain so that vector math can optimize --- extra/terrain/terrain.factor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extra/terrain/terrain.factor b/extra/terrain/terrain.factor index 27bd7df403..e4838061f5 100644 --- a/extra/terrain/terrain.factor +++ b/extra/terrain/terrain.factor @@ -178,9 +178,9 @@ terrain-world H{ [ { 0 2 3 3 } vshuffle terrain-height-at PLAYER-HEIGHT + -1/0. swap -1/0. -1/0. float-4-boa - ] keep vmax ; + ] keep vmax ; inline -:: collide ( world player -- ) +TYPED:: collide ( world: terrain-world player: player -- ) world terrain-segment>> :> segment player location>> :> location segment location (collide) :> location' From 83d10d81351c051a46e30088c30cbbfb75a34c4e Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Thu, 11 Feb 2010 14:22:54 -0800 Subject: [PATCH 07/12] gpu.textures: add compressed texture support --- basis/opengl/gl/gl.factor | 7 ++ extra/gpu/textures/textures-docs.factor | 85 +++++++++++++-- extra/gpu/textures/textures.factor | 137 +++++++++++++++++------- 3 files changed, 187 insertions(+), 42 deletions(-) diff --git a/basis/opengl/gl/gl.factor b/basis/opengl/gl/gl.factor index 412405c852..d04875c66e 100644 --- a/basis/opengl/gl/gl.factor +++ b/basis/opengl/gl/gl.factor @@ -2251,3 +2251,10 @@ CONSTANT: GL_LUMINANCE_ALPHA_INTEGER_EXT HEX: 8D9D GL-FUNCTION: void glClearColorIiEXT { } ( GLint r, GLint g, GLint b, GLint a ) ; GL-FUNCTION: void glClearColorIuiEXT { } ( GLuint r, GLuint g, GLuint b, GLuint a ) ; +! GL_EXT_texture_compression_s3tc, GL_EXT_texture_compression_dxt1 + +CONSTANT: GL_COMPRESSED_RGB_S3TC_DXT1_EXT HEX: 83F0 +CONSTANT: GL_COMPRESSED_RGBA_S3TC_DXT1_EXT HEX: 83F1 +CONSTANT: GL_COMPRESSED_RGBA_S3TC_DXT3_EXT HEX: 83F2 +CONSTANT: GL_COMPRESSED_RGBA_S3TC_DXT5_EXT HEX: 83F3 + diff --git a/extra/gpu/textures/textures-docs.factor b/extra/gpu/textures/textures-docs.factor index 76fdcfd9e8..ffac0bc29b 100644 --- a/extra/gpu/textures/textures-docs.factor +++ b/extra/gpu/textures/textures-docs.factor @@ -88,6 +88,13 @@ HELP: { $description "Creates a new rectangle texture. The new texture starts out with no image data; " { $link allocate-texture } " or " { $link allocate-texture-image } " must be used to allocate memory for the texture." } { $notes "Rectangle textures require OpenGL 3.1 or the " { $snippet "GL_ARB_texture_rectangle" } " extension." } ; +HELP: allocate-compressed-texture +{ $values + { "tdt" texture-data-target } { "level" integer } { "dim" "an " { $link integer } " or sequence of " { $link integer } "s" } { "compressed-data" compressed-texture-data } +} +{ $description "Allocates a new block of GPU memory for the " { $snippet "level" } "th level of detail of a " { $link texture-data-target } ". The new data is initialized with compressed texture data from the given " { $link compressed-texture-data } " object." } +{ $notes "Using a " { $link buffer-ptr } " as the " { $snippet "ptr" } " of a " { $snippet "compressed-texture-data" } " object requires OpenGL 2.1 or later or the " { $snippet "GL_ARB_pixel_buffer_object" } " extension." } ; + HELP: allocate-texture { $values { "tdt" texture-data-target } { "level" integer } { "dim" "an " { $link integer } " or sequence of " { $link integer } "s" } { "data" { $maybe texture-data } } @@ -101,7 +108,7 @@ HELP: allocate-texture-image } { $description "Allocates a new block of GPU memory for the " { $snippet "level" } "th level of detail of a " { $link texture-data-target } " and initializes it with the contents of an " { $link image } "." } ; -{ allocate-texture allocate-texture-image } related-words +{ allocate-compressed-texture allocate-texture allocate-texture-image } related-words HELP: clamp-texcoord-to-border { $class-description "This " { $link texture-wrap } " value clamps texture coordinates to a texture's border." } ; @@ -140,6 +147,21 @@ HELP: image>texture-data } { $description "Constructs a " { $link texture-data } " tuple referencing the pixel data from an " { $link image } "." } ; +HELP: read-compressed-texture +{ $values + { "tdt" texture-data-target } { "level" integer } + { "byte-array" byte-array } +} +{ $description "Reads the entire compressed image for the " { $snippet "level" } "th level of detail of a texture into a new " { $link byte-array } ". The format of the data in the byte array is determined by the " { $link compressed-texture-format } " of the data originally allocated by " { $link allocate-compressed-texture } " for the texture." } ; + +HELP: read-compressed-texture-to +{ $values + { "tdt" texture-data-target } { "level" integer } + { "gpu-data-ptr" byte-array } +} +{ $description "Reads the entire compressed image for the " { $snippet "level" } "th level of detail of a texture into the CPU or GPU memory referenced by " { $link gpu-data-ptr } ". The format of the written data is determined by the " { $link compressed-texture-format } " of the data originally allocated by " { $link allocate-compressed-texture } " for the texture." } +{ $notes "Reading texture data into a GPU " { $snippet "buffer-ptr" } " requires OpenGL 2.1 or later or the " { $snippet "GL_ARB_pixel_buffer_object" } " extension." } ; + HELP: read-texture { $values { "tdt" texture-data-target } { "level" integer } @@ -158,10 +180,10 @@ HELP: read-texture-to { $values { "tdt" texture-data-target } { "level" integer } { "gpu-data-ptr" gpu-data-ptr } } -{ $description "Reads the entire image for the " { $snippet "level" } "th level of detail of a texture into the CPU or GPU memory referenced by " { $link gpu-data-ptr } ". The format of the data in the byte array is determined by the " { $link component-order } " and " { $link component-type } " of the texture." } +{ $description "Reads the entire image for the " { $snippet "level" } "th level of detail of a texture into the CPU or GPU memory referenced by " { $link gpu-data-ptr } ". The format of the written data is determined by the " { $link component-order } " and " { $link component-type } " of the texture." } { $notes "Reading texture data into a GPU " { $snippet "buffer-ptr" } " requires OpenGL 2.1 or later or the " { $snippet "GL_ARB_pixel_buffer_object" } " extension." } ; -{ read-texture read-texture-image read-texture-to } related-words +{ read-compressed-texture read-compressed-texture-to read-texture read-texture-image read-texture-to } related-words HELP: repeat-texcoord { $class-description "This " { $link texture-wrap } " value causes the texture image to be repeated through texture coordinate space." } ; @@ -256,6 +278,13 @@ HELP: texture-dim } { $description "Returns the dimensions of the memory allocated for the " { $snippet "level" } "th level of detail of the given " { $link texture-data-target } "." } ; +HELP: compressed-texture-data-size +{ $values + { "tdt" texture-data-target } { "level" integer } + { "size" integer } +} +{ $description "Returns the size in bytes of the memory allocated for the compressed texture data making up the " { $snippet "level" } "th level of detail of the given " { $link texture-data-target } "." } ; + HELP: texture-filter { $class-description { $snippet "texture-filter" } " values are used in a " { $link texture-parameters } " tuple to determine how a texture should be sampled between pixels or between levels of detail. " { $link filter-linear } " selects linear filtering, while " { $link filter-nearest } " selects nearest-neighbor sampling." } ; @@ -277,6 +306,13 @@ HELP: texture-rectangle { $class-description "A two-dimensional rectangle " { $link texture } " object. Textures of this type are dimensioned by pairs of integers in calls to " { $link allocate-texture } " and " { $link update-texture } ". Rectangle textures differ from normal 2D textures (" { $link texture-2d } ") in that texture coordinates map directly to pixel coordinates when they are sampled from shader code, rather than being normalized into the 0.0 to 1.0 range as with other texture types. Also, rectangle textures do not support mipmapping or texture wrapping." } { $notes "Rectangle textures require OpenGL 3.1 or the " { $snippet "GL_ARB_texture_rectangle" } " extension." } ; +HELP: update-compressed-texture +{ $values + { "tdt" texture-data-target } { "level" integer } { "loc" "an " { $link integer } " or sequence of integers" } { "dim" "an " { $link integer } " or sequence of integers" } { "compressed-data" texture-data } +} +{ $description "Updates the linear, rectangular, or cubic subregion of a compressed " { $link texture-data-target } " bounded by " { $snippet "loc" } " and " { $snippet "dim" } " with the data referenced by the given " { $link compressed-texture-data } " tuple. The given level of detail of the texture must have been previously allocated for compressed data with " { $link allocate-compressed-texture } "." } +{ $notes "Using a " { $link buffer-ptr } " as the " { $snippet "ptr" } " of a " { $snippet "compressed-texture-data" } " object requires OpenGL 2.1 or later or the " { $snippet "GL_ARB_pixel_buffer_object" } " extension." } ; + HELP: update-texture { $values { "tdt" texture-data-target } { "level" integer } { "loc" "an " { $link integer } " or sequence of integers" } { "dim" "an " { $link integer } " or sequence of integers" } { "data" texture-data } @@ -290,22 +326,59 @@ HELP: update-texture-image } { $description "Updates the linear, rectangular, or cubic subregion of a " { $link texture-data-target } " bounded by " { $snippet "loc" } " and " { $snippet "dim" } " with new image data from an " { $link image } " object." } ; -{ update-texture update-texture-image } related-words +{ update-compressed-texture update-texture update-texture-image } related-words + +HELP: compressed-texture-format +{ $class-description { $snippet "compressed-texture-format" } " values are used as part of a " { $link compressed-texture-data } " tuple to specify the binary format of texture data being given to " { $link allocate-compressed-texture } " or " { $link update-compressed-texture } ". The following compressed formats are available:" +{ $list +{ { $link DXT1-RGB } } +{ { $link DXT1-RGBA } } +{ { $link DXT3 } } +{ { $link DXT5 } } +{ { $link RGTC1 } } +{ { $link RGTC1-SIGNED } } +{ { $link RGTC2 } } +{ { $link RGTC2-SIGNED } } +} } +{ $notes "The " { $snippet "DXT1" } " formats require either the " { $snippet "GL_EXT_texture_compression_s3tc" } " or " { $snippet "GL_EXT_texture_compression_dxt1" } " extension. The other " { $snippet "DXT" } " formats require the " { $snippet "GL_EXT_texture_compression_s3tc" } " extension. The " { $snippet "RGTC" } " formats require OpenGL 3.0 or later or the " { $snippet "GL_EXT_texture_compression_rgtc" } " extension." } ; + +HELP: compressed-texture-data +{ $class-description { $snippet "compressed-texture-data" } " tuples are used to feed compressed texture data to " { $link allocate-compressed-texture } " and " { $link update-compressed-texture } "." +{ $list +{ "The " { $snippet "ptr" } " slot references either CPU memory (as a " { $link byte-array } " or " { $link alien } ") or a GPU " { $link buffer-ptr } " that contains the image data." } +{ "The " { $snippet "format" } " slot determines the " { $link compressed-texture-format } " of the referenced data." } +{ "The " { $snippet "length" } " slot determines the size in bytes of the referenced data." } +} } +{ $notes "Using a " { $link buffer-ptr } " as the " { $snippet "ptr" } " of a " { $snippet "texture-data" } " object requires OpenGL 2.1 or later or the " { $snippet "GL_ARB_pixel_buffer_object" } " extension." } ; + +{ compressed-texture-data } related-words ARTICLE: "gpu.textures" "Texture objects" "The " { $vocab-link "gpu.textures" } " vocabulary provides words for creating, allocating, updating, and reading GPU texture objects." { $subsections texture + texture-data allocate-texture update-texture + texture-dim read-texture + read-texture-to } -"Words are also provided to interface textures with the " { $vocab-link "images" } " library:" +"Words are also provided to use " { $link image } " objects from the " { $vocab-link "images" } " library as data sources and destinations for texture data:" { $subsections allocate-texture-image update-texture-image read-texture-image } -; +"Compressed texture data can also be supplied and read:" +{ $subsections + compressed-texture-format + compressed-texture-data + allocate-compressed-texture + update-compressed-texture + compressed-texture-data-size + read-compressed-texture + read-compressed-texture-to +} ; ABOUT: "gpu.textures" diff --git a/extra/gpu/textures/textures.factor b/extra/gpu/textures/textures.factor index ba2e2c32a0..e1afc20f88 100644 --- a/extra/gpu/textures/textures.factor +++ b/extra/gpu/textures/textures.factor @@ -49,6 +49,18 @@ C: texture-data UNION: ?texture-data texture-data POSTPONE: f ; UNION: ?float-array float-array POSTPONE: f ; +VARIANT: compressed-texture-format + DXT1-RGB DXT1-RGBA DXT3 DXT5 + RGTC1 RGTC1-SIGNED RGTC2 RGTC2-SIGNED ; + +TUPLE: compressed-texture-data + { ptr read-only } + { format compressed-texture-format read-only } + { length integer read-only } ; + +C: compressed-texture-data +UNION: ?compressed-texture-data compressed-texture-data POSTPONE: f ; + VARIANT: texture-wrap clamp-texcoord-to-edge clamp-texcoord-to-border repeat-texcoord repeat-texcoord-mirrored ; VARIANT: texture-filter @@ -76,6 +88,18 @@ M: cube-map-face texture-object M: texture texture-object ; inline +: gl-compressed-texture-format ( format -- gl-format ) + { + { DXT1-RGB [ GL_COMPRESSED_RGB_S3TC_DXT1_EXT ] } + { DXT1-RGBA [ GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ] } + { DXT3 [ GL_COMPRESSED_RGBA_S3TC_DXT3_EXT ] } + { DXT5 [ GL_COMPRESSED_RGBA_S3TC_DXT5_EXT ] } + { RGTC1 [ GL_COMPRESSED_RED_RGTC1 ] } + { RGTC1-SIGNED [ GL_COMPRESSED_SIGNED_RED_RGTC1 ] } + { RGTC2 [ GL_COMPRESSED_RG_RGTC2 ] } + { RGTC2-SIGNED [ GL_COMPRESSED_SIGNED_RG_RGTC2 ] } + } case ; inline + : gl-wrap ( wrap -- gl-wrap ) { { clamp-texcoord-to-edge [ GL_CLAMP_TO_EDGE ] } @@ -159,49 +183,77 @@ M: cube-map-face texture-data-gl-target : ?product ( x -- y ) dup number? [ product ] unless ; inline +:: (allocate-texture) ( tdt level dim data dim-quot teximage-quot -- ) + tdt bind-tdt :> texture + tdt texture-data-gl-target level texture texture-gl-internal-format + dim dim-quot call 0 texture data texture-data-gl-args + pixel-unpack-buffer teximage-quot with-gpu-data-ptr ; inline + +:: (allocate-compressed-texture) ( tdt level dim compressed-data dim-quot teximage-quot -- ) + tdt bind-tdt :> texture + tdt texture-data-gl-target level compressed-data format>> gl-compressed-texture-format + dim dim-quot call 0 compressed-data [ length>> ] [ ptr>> ] bi + pixel-unpack-buffer teximage-quot with-gpu-data-ptr ; inline + +:: (update-texture) ( tdt level loc dim data dim-quot texsubimage-quot -- ) + tdt bind-tdt :> texture + tdt texture-data-gl-target level + loc dim dim-quot bi@ + texture data texture-data-gl-args + pixel-unpack-buffer texsubimage-quot with-gpu-data-ptr ; inline + +:: (update-compressed-texture) ( tdt level loc dim compressed-data dim-quot texsubimage-quot -- ) + tdt bind-tdt :> texture + tdt texture-data-gl-target level + loc dim dim-quot bi@ + compressed-data [ format>> gl-compressed-texture-format ] [ length>> ] [ ptr>> ] tri + pixel-unpack-buffer texsubimage-quot with-gpu-data-ptr ; inline + PRIVATE> GENERIC# allocate-texture 3 ( tdt level dim data -- ) -M:: texture-1d-data-target allocate-texture ( tdt level dim data -- ) - tdt bind-tdt :> texture - tdt texture-data-gl-target level texture texture-gl-internal-format - dim 0 texture data texture-data-gl-args - pixel-unpack-buffer [ glTexImage1D ] with-gpu-data-ptr ; +M: texture-1d-data-target allocate-texture ( tdt level dim data -- ) + [ ] [ glTexImage1D ] (allocate-texture) ; -M:: texture-2d-data-target allocate-texture ( tdt level dim data -- ) - tdt bind-tdt :> texture - tdt texture-data-gl-target level texture texture-gl-internal-format - dim first2 0 texture data texture-data-gl-args - pixel-unpack-buffer [ glTexImage2D ] with-gpu-data-ptr ; +M: texture-2d-data-target allocate-texture ( tdt level dim data -- ) + [ first2 ] [ glTexImage2D ] (allocate-texture) ; -M:: texture-3d-data-target allocate-texture ( tdt level dim data -- ) - tdt bind-tdt :> texture - tdt texture-data-gl-target level texture texture-gl-internal-format - dim first3 0 texture data texture-data-gl-args - pixel-unpack-buffer [ glTexImage3D ] with-gpu-data-ptr ; +M: texture-3d-data-target allocate-texture ( tdt level dim data -- ) + [ first3 ] [ glTexImage3D ] (allocate-texture) ; + +GENERIC# allocate-compressed-texture 3 ( tdt level dim compressed-data -- ) + +M: texture-1d-data-target allocate-compressed-texture ( tdt level dim compressed-data -- ) + [ ] [ glCompressedTexImage1D ] (allocate-compressed-texture) ; + +M: texture-2d-data-target allocate-compressed-texture ( tdt level dim compressed-data -- ) + [ first2 ] [ glCompressedTexImage2D ] (allocate-compressed-texture) ; + +M: texture-3d-data-target allocate-compressed-texture ( tdt level dim compressed-data -- ) + [ first3 ] [ glCompressedTexImage3D ] (allocate-compressed-texture) ; GENERIC# update-texture 4 ( tdt level loc dim data -- ) -M:: texture-1d-data-target update-texture ( tdt level loc dim data -- ) - tdt bind-tdt :> texture - tdt texture-data-gl-target level - loc dim texture data texture-data-gl-args - pixel-unpack-buffer [ glTexSubImage1D ] with-gpu-data-ptr ; +M: texture-1d-data-target update-texture ( tdt level loc dim data -- ) + [ ] [ glTexSubImage1D ] (update-texture) ; -M:: texture-2d-data-target update-texture ( tdt level loc dim data -- ) - tdt bind-tdt :> texture - tdt texture-data-gl-target level - loc dim [ first2 ] bi@ - texture data texture-data-gl-args - pixel-unpack-buffer [ glTexSubImage2D ] with-gpu-data-ptr ; +M: texture-2d-data-target update-texture ( tdt level loc dim data -- ) + [ first2 ] [ glTexSubImage2D ] (update-texture) ; -M:: texture-3d-data-target update-texture ( tdt level loc dim data -- ) - tdt bind-tdt :> texture - tdt texture-data-gl-target level - loc dim [ first3 ] bi@ - texture data texture-data-gl-args - pixel-unpack-buffer [ glTexSubImage3D ] with-gpu-data-ptr ; +M: texture-3d-data-target update-texture ( tdt level loc dim data -- ) + [ first3 ] [ glTexSubImage3D ] (update-texture) ; + +GENERIC# update-compressed-texture 4 ( tdt level loc dim compressed-data -- ) + +M: texture-1d-data-target update-compressed-texture ( tdt level loc dim compressed-data -- ) + [ ] [ glCompressedTexSubImage1D ] (update-compressed-texture) ; + +M: texture-2d-data-target update-compressed-texture ( tdt level loc dim compressed-data -- ) + [ first2 ] [ glCompressedTexSubImage2D ] (update-compressed-texture) ; + +M: texture-3d-data-target update-compressed-texture ( tdt level loc dim compressed-data -- ) + [ first3 ] [ glCompressedTexSubImage3D ] (update-compressed-texture) ; : image>texture-data ( image -- dim texture-data ) { [ dim>> ] [ bitmap>> ] [ component-order>> ] [ component-type>> ] } cleave @@ -211,13 +263,13 @@ GENERIC# texture-dim 1 ( tdt level -- dim ) M:: texture-1d-data-target texture-dim ( tdt level -- dim ) tdt bind-tdt :> texture - tdt texture-data-gl-target level GL_TEXTURE_WIDTH get-texture-int ; + tdt texture-data-gl-target level GL_TEXTURE_WIDTH get-texture-int ; inline M:: texture-2d-data-target texture-dim ( tdt level -- dim ) tdt bind-tdt :> texture tdt texture-data-gl-target level [ GL_TEXTURE_WIDTH get-texture-int ] [ GL_TEXTURE_HEIGHT get-texture-int ] 2bi - 2array ; + 2array ; inline M:: texture-3d-data-target texture-dim ( tdt level -- dim ) tdt bind-tdt :> texture @@ -225,7 +277,11 @@ M:: texture-3d-data-target texture-dim ( tdt level -- dim ) [ GL_TEXTURE_WIDTH get-texture-int ] [ GL_TEXTURE_HEIGHT get-texture-int ] [ GL_TEXTURE_DEPTH get-texture-int ] 2tri - 3array ; + 3array ; inline + +: compressed-texture-data-size ( tdt level -- size ) + [ [ bind-tdt drop ] [ texture-data-gl-target ] bi ] dip + GL_TEXTURE_COMPRESSED_IMAGE_SIZE get-texture-int ; inline : texture-data-size ( tdt level -- size ) [ texture-dim ?product ] [ drop texture-object bytes-per-pixel ] 2bi * ; inline @@ -237,9 +293,18 @@ TYPED:: read-texture-to ( tdt: texture-data-target level: integer gpu-data-ptr - gpu-data-ptr pixel-pack-buffer [ glGetTexImage ] with-gpu-data-ptr ; TYPED: read-texture ( tdt: texture-data-target level: integer -- byte-array: byte-array ) - 2dup texture-data-size + 2dup texture-data-size (byte-array) [ read-texture-to ] keep ; +TYPED:: read-compressed-texture-to ( tdt: texture-data-target level: integer gpu-data-ptr -- ) + tdt bind-tdt :> texture + tdt texture-data-gl-target level + gpu-data-ptr pixel-pack-buffer [ glGetCompressedTexImage ] with-gpu-data-ptr ; + +TYPED: read-compressed-texture ( tdt: texture-data-target level: integer -- byte-array: byte-array ) + 2dup compressed-texture-data-size (byte-array) + [ read-compressed-texture-to ] keep ; + : allocate-texture-image ( tdt level image -- ) image>texture-data allocate-texture ; inline From ba493063fbb516c0495ff40fe67ac0b581218789 Mon Sep 17 00:00:00 2001 From: Erik Charlebois Date: Sat, 13 Feb 2010 02:34:26 -0800 Subject: [PATCH 08/12] Constants for GL_EXT_texture_compression_s3tc and GL_EXT_texture_compression_latc --- basis/opengl/gl/gl.factor | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/basis/opengl/gl/gl.factor b/basis/opengl/gl/gl.factor index 412405c852..b59ab116e8 100644 --- a/basis/opengl/gl/gl.factor +++ b/basis/opengl/gl/gl.factor @@ -2251,3 +2251,16 @@ CONSTANT: GL_LUMINANCE_ALPHA_INTEGER_EXT HEX: 8D9D GL-FUNCTION: void glClearColorIiEXT { } ( GLint r, GLint g, GLint b, GLint a ) ; GL-FUNCTION: void glClearColorIuiEXT { } ( GLuint r, GLuint g, GLuint b, GLuint a ) ; +! GL_EXT_texture_compression_s3tc + +CONSTANT: GL_COMPRESSED_RGB_S3TC_DXT1_EXT HEX: 83F0 +CONSTANT: GL_COMPRESSED_RGBA_S3TC_DXT1_EXT HEX: 83F1 +CONSTANT: GL_COMPRESSED_RGBA_S3TC_DXT3_EXT HEX: 83F2 +CONSTANT: GL_COMPRESSED_RGBA_S3TC_DXT5_EXT HEX: 83F3 + +! GL_EXT_texture_compression_latc + +CONSTANT: GL_COMPRESSED_LUMINANCE_LATC1_EXT HEX: 8C70 +CONSTANT: GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT HEX: 8C71 +CONSTANT: GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT HEX: 8C72 +CONSTANT: GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT HEX: 8C73 From 52230d6c4d08ecaebfe5aea0c9f3c7efb2add706 Mon Sep 17 00:00:00 2001 From: Erik Charlebois Date: Sat, 13 Feb 2010 02:35:09 -0800 Subject: [PATCH 09/12] Add p^ to polynomial vocab for exponentiation of polynomials --- basis/math/polynomials/polynomials-docs.factor | 6 ++++++ basis/math/polynomials/polynomials-tests.factor | 2 ++ basis/math/polynomials/polynomials.factor | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/basis/math/polynomials/polynomials-docs.factor b/basis/math/polynomials/polynomials-docs.factor index cb2d2a6058..9c16bf8a7e 100644 --- a/basis/math/polynomials/polynomials-docs.factor +++ b/basis/math/polynomials/polynomials-docs.factor @@ -11,6 +11,7 @@ ARTICLE: "polynomials" "Polynomials" p- p* p-sq + p^ powers n*p p/mod @@ -74,6 +75,11 @@ HELP: p-sq { $description "Squares a polynomial." } { $examples { $example "USING: math.polynomials prettyprint ;" "{ 1 2 0 } p-sq ." "{ 1 4 4 0 0 }" } } ; +HELP: p^ +{ $values { "p" "a polynomial" } { "n" number } { "p^n" "a polynomial" } } +{ $description "Computes " { $snippet "p" } " to the power of " { $snippet "n" } "." } +{ $examples { $example "USING: math.polynomials prettyprint ;" "{ 1 2 0 } 3 p^ ." "{ 1 6 12 8 0 0 0 }" } } ; + HELP: p/mod { $values { "p" "a polynomial" } { "q" "a polynomial" } { "z" "a polynomial" } { "w" "a polynomial" } } { $description "Computes to quotient " { $snippet "z" } " and remainder " { $snippet "w" } " of dividing " { $snippet "p" } " by " { $snippet "q" } "." } diff --git a/basis/math/polynomials/polynomials-tests.factor b/basis/math/polynomials/polynomials-tests.factor index cd88d19d13..e0cedb9adf 100644 --- a/basis/math/polynomials/polynomials-tests.factor +++ b/basis/math/polynomials/polynomials-tests.factor @@ -15,6 +15,8 @@ IN: math.polynomials.tests [ { 0 0 0 } ] [ { 0 0 0 } { 0 0 0 } p- ] unit-test [ { 0 0 0 } ] [ 4 { 0 0 0 } n*p ] unit-test [ { 4 8 0 12 } ] [ 4 { 1 2 0 3 } n*p ] unit-test +[ { 1 4 4 0 0 } ] [ { 1 2 0 } p-sq ] unit-test +[ { 1 6 12 8 0 0 0 } ] [ { 1 2 0 } 3 p^ ] unit-test [ { 1 4 7 6 0 0 0 0 0 } ] [ { 1 2 3 0 0 0 } { 1 2 0 0 } p* ] unit-test [ V{ 7 -2 1 } V{ -20 0 0 } ] [ { 1 1 1 1 } { 3 1 } p/mod ] unit-test [ V{ 0 0 } V{ 1 1 } ] [ { 1 1 } { 1 1 1 1 } p/mod ] unit-test diff --git a/basis/math/polynomials/polynomials.factor b/basis/math/polynomials/polynomials.factor index 99d77d0ce2..694b9ef542 100644 --- a/basis/math/polynomials/polynomials.factor +++ b/basis/math/polynomials/polynomials.factor @@ -38,6 +38,15 @@ PRIVATE> : p-sq ( p -- p^2 ) dup p* ; +ERROR: negative-power-polynomial p n ; + +: p^ ( p n -- p^n ) + { + { [ dup 0 > ] [ 1 - dupd [ p* ] with times ] } + { [ dup 0 = ] [ 2drop { 1 } ] } + { [ dup 0 < ] [ negative-power-polynomial ] } + } cond ; + Date: Sat, 13 Feb 2010 02:43:42 -0800 Subject: [PATCH 10/12] Merge up with Joe's earlier change that added s3tc --- basis/opengl/gl/gl.factor | 1 + extra/gpu/shaders/shaders-docs.factor | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/basis/opengl/gl/gl.factor b/basis/opengl/gl/gl.factor index de842a0ba7..d89cee57d4 100644 --- a/basis/opengl/gl/gl.factor +++ b/basis/opengl/gl/gl.factor @@ -2264,3 +2264,4 @@ CONSTANT: GL_COMPRESSED_LUMINANCE_LATC1_EXT HEX: 8C70 CONSTANT: GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT HEX: 8C71 CONSTANT: GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT HEX: 8C72 CONSTANT: GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT HEX: 8C73 + diff --git a/extra/gpu/shaders/shaders-docs.factor b/extra/gpu/shaders/shaders-docs.factor index fa3fbd6aa4..dd16224529 100644 --- a/extra/gpu/shaders/shaders-docs.factor +++ b/extra/gpu/shaders/shaders-docs.factor @@ -31,7 +31,7 @@ HELP: feedback-format: HELP: GLSL-PROGRAM: { $syntax "GLSL-PROGRAM: program-name shader shader ... [vertex-format vertex-format ...] [feedback-format: vertex-format] ;" } -{ $description "Defines a new " { $link program } " named " { $snippet "program-name" } ". When the program is instantiated with " { $link } ", it will link together instances of all of the specified " { $link shader } "s to create the program instance. If any " { $link vertex-format } "s are specified, their attributes will be pre-assigned attribute indexes at link time, to ensure that their indexes remain constant if the program is refreshed with " { $link refresh-program } ". A trasform feedback vertex format may optionally be specified with " { $link POSTPONE: feedback-format: } "; if the program is used to collect transform feedback, the given vertex format will be used for the output." } +{ $description "Defines a new " { $link program } " named " { $snippet "program-name" } ". When the program is instantiated with " { $link } ", it will link together instances of all of the specified " { $link shader } "s to create the program instance. If any " { $link vertex-format } "s are specified, their attributes will be pre-assigned attribute indexes at link time, to ensure that their indexes remain constant if the program is refreshed with " { $link refresh-program } ". A transform feedback vertex format may optionally be specified with " { $link POSTPONE: feedback-format: } "; if the program is used to collect transform feedback, the given vertex format will be used for the output." } { $notes "Transform feedback requires OpenGL 3.0 or one of the " { $snippet "GL_EXT_transform_feedback" } " or " { $snippet "GL_ARB_transform_feedback" } " extensions." } ; HELP: GLSL-SHADER-FILE: From 68c5335d5094d3c80f1c1f81247cadfebb524b5c Mon Sep 17 00:00:00 2001 From: Erik Charlebois Date: Sat, 13 Feb 2010 03:50:04 -0800 Subject: [PATCH 11/12] Fix stack effect decl in listener.factor and mismatched dynamic stack effect for error hook in remote.factor --- basis/listener/listener.factor | 2 +- extra/fuel/remote/remote.factor | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/basis/listener/listener.factor b/basis/listener/listener.factor index 168971aeee..96db935f07 100644 --- a/basis/listener/listener.factor +++ b/basis/listener/listener.factor @@ -48,7 +48,7 @@ SYMBOL: error-hook : call-error-hook ( error -- ) error-continuation get error-hook get - call( error continuation -- ) ; + call( continuation error -- ) ; [ drop print-error-and-restarts ] error-hook set-global diff --git a/extra/fuel/remote/remote.factor b/extra/fuel/remote/remote.factor index d3b48efac6..97ab5b59db 100644 --- a/extra/fuel/remote/remote.factor +++ b/extra/fuel/remote/remote.factor @@ -8,7 +8,7 @@ IN: fuel.remote From a99d35a7abe61659a926197333ae0a70377759ff Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 11 Feb 2010 16:26:12 +1300 Subject: [PATCH 12/12] webapps.mason: work in progress --- extra/mason/server/release/release.factor | 10 +- .../{download.xml => download-package.xml} | 0 extra/webapps/mason/download-release.xml | 29 +++ extra/webapps/mason/grids/authors.txt | 1 + extra/webapps/mason/grids/grids.factor | 93 +++++++++ extra/webapps/mason/mason.factor | 187 ++---------------- extra/webapps/mason/package/authors.txt | 1 + extra/webapps/mason/package/package.factor | 71 +++++++ extra/webapps/mason/release/authors.txt | 1 + extra/webapps/mason/release/release.factor | 25 +++ extra/webapps/mason/report/authors.txt | 1 + extra/webapps/mason/report/report.factor | 16 ++ extra/webapps/mason/utils/authors.txt | 1 + extra/webapps/mason/utils/utils.factor | 40 ++++ 14 files changed, 302 insertions(+), 174 deletions(-) rename extra/webapps/mason/{download.xml => download-package.xml} (100%) create mode 100644 extra/webapps/mason/download-release.xml create mode 100644 extra/webapps/mason/grids/authors.txt create mode 100644 extra/webapps/mason/grids/grids.factor create mode 100644 extra/webapps/mason/package/authors.txt create mode 100644 extra/webapps/mason/package/package.factor create mode 100644 extra/webapps/mason/release/authors.txt create mode 100644 extra/webapps/mason/release/release.factor create mode 100644 extra/webapps/mason/report/authors.txt create mode 100644 extra/webapps/mason/report/report.factor create mode 100644 extra/webapps/mason/utils/authors.txt create mode 100644 extra/webapps/mason/utils/utils.factor diff --git a/extra/mason/server/release/release.factor b/extra/mason/server/release/release.factor index 2683d642de..8aae749839 100644 --- a/extra/mason/server/release/release.factor +++ b/extra/mason/server/release/release.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors calendar db db.tuples grouping io +USING: accessors calendar db db.tuples db.types grouping io io.encodings.ascii io.launcher kernel locals make mason.release.archive mason.server namespaces sequences ; IN: mason.server.release @@ -39,6 +39,14 @@ TUPLE: release host-name os cpu last-release release-git-id ; +release "RELEASES" { + { "host-name" "HOST_NAME" TEXT +user-assigned-id+ } + { "os" "OS" TEXT +user-assigned-id+ } + { "cpu" "CPU" TEXT +user-assigned-id+ } + { "last-release" "LAST_RELEASE" TEXT } + { "release-git-id" "RELEASE_GIT_ID" TEXT } +} define-persistent + :: ( version builder -- release ) release new builder host-name>> >>host-name diff --git a/extra/webapps/mason/download.xml b/extra/webapps/mason/download-package.xml similarity index 100% rename from extra/webapps/mason/download.xml rename to extra/webapps/mason/download-package.xml diff --git a/extra/webapps/mason/download-release.xml b/extra/webapps/mason/download-release.xml new file mode 100644 index 0000000000..751bb14c77 --- /dev/null +++ b/extra/webapps/mason/download-release.xml @@ -0,0 +1,29 @@ + + + + + + + + + + Factor binary package for <t:label t:name="platform" /> + + +
Logo
+ +

Factor binary package for

+ +

Requirements:

+ + +

Download

+ +

This release was built from GIT ID .

+ +

Once you download Factor, you can get started with the language.

+ + + +
diff --git a/extra/webapps/mason/grids/authors.txt b/extra/webapps/mason/grids/authors.txt new file mode 100644 index 0000000000..d4f5d6b3ae --- /dev/null +++ b/extra/webapps/mason/grids/authors.txt @@ -0,0 +1 @@ +Slava Pestov \ No newline at end of file diff --git a/extra/webapps/mason/grids/grids.factor b/extra/webapps/mason/grids/grids.factor new file mode 100644 index 0000000000..57551b4aa5 --- /dev/null +++ b/extra/webapps/mason/grids/grids.factor @@ -0,0 +1,93 @@ +! Copyright (C) 2010 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors assocs db.tuples furnace.actions +furnace.utilities http.server.responses kernel locals +mason.server mason.server.release sequences splitting urls +webapps.mason.utils xml.syntax xml.writer ; +IN: webapps.mason.grids + +: render-grid-cell ( cpu os quot -- xml ) + call( cpu os -- url label ) + 2dup and + [ link [XML
<->
XML] ] + [ 2drop [XML XML] ] + if ; + +CONSTANT: oses +{ + { "winnt" "Windows" } + { "macosx" "Mac OS X" } + { "linux" "Linux" } + { "freebsd" "FreeBSD" } + { "netbsd" "NetBSD" } + { "openbsd" "OpenBSD" } +} + +CONSTANT: cpus +{ + { "x86.32" "x86" } + { "x86.64" "x86-64" } + { "ppc" "PowerPC" } +} + +: render-grid-header ( -- xml ) + oses values [ [XML <-> XML] ] map ; + +:: render-grid-row ( cpu quot -- xml ) + cpu second oses keys [| os | cpu os quot render-grid-cell ] map + [XML <-><-> XML] ; + +:: render-grid ( quot -- xml ) + render-grid-header + cpus [ quot render-grid-row ] map + [XML + + <-> + <-> +
OS/CPU
+ XML] ; + +: package-url ( builder -- url ) + [ URL" $mason-app/package" ] dip + [ os>> "os" set-query-param ] + [ cpu>> "cpu" set-query-param ] bi + adjust-url ; + +: package-date ( filename -- date ) + "." split1 drop 16 tail* 6 head* ; + +: package-grid-cell ( cpu os -- url label ) + builder new swap >>os swap >>cpu select-tuple [ + [ package-url ] + [ last-release>> [ package-date ] [ "N/A" ] if* ] bi + ] [ f f ] if* ; + +: package-grid ( -- xml ) + [ package-grid-cell ] render-grid ; + +: ( -- action ) + + [ package-grid xml>string "text/html" ] >>display ; + +: release-url ( builder -- url ) + [ URL" $mason-app/release" ] dip + [ os>> "os" set-query-param ] + [ cpu>> "cpu" set-query-param ] bi + adjust-url ; + +: release-version ( filename -- release ) + ".tar.gz" ?tail drop ".zip" ?tail drop ".dmg" ?tail drop + "-" split1-last nip ; + +: release-grid-cell ( cpu os -- url label ) + release new swap >>os swap >>cpu select-tuple [ + [ release-url ] + [ last-release>> [ release-version ] [ "N/A" ] if* ] bi + ] [ f f ] if* ; + +: release-grid ( -- xml ) + [ release-grid-cell ] render-grid ; + +: ( -- action ) + + [ release-grid xml>string "text/html" ] >>display ; diff --git a/extra/webapps/mason/mason.factor b/extra/webapps/mason/mason.factor index 1c2d9e0d8c..00e1b200f6 100644 --- a/extra/webapps/mason/mason.factor +++ b/extra/webapps/mason/mason.factor @@ -1,183 +1,24 @@ ! Copyright (C) 2009, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors arrays combinators db db.tuples furnace.actions -http.server.responses http.server.dispatchers kernel mason.platform -mason.server mason.report math.order sequences sorting -splitting xml.syntax xml.writer io.pathnames io.encodings.utf8 -io.files present validators html.forms furnace.db urls ; -FROM: assocs => at keys values ; +USING: accessors furnace.db http.server.dispatchers mason.server +webapps.mason.grids webapps.mason.package webapps.mason.release +webapps.mason.report ; IN: webapps.mason TUPLE: mason-app < dispatcher ; -: link ( url label -- xml ) - [XML ><-> XML] ; - -: download-link ( builder label -- xml ) - [ - [ URL" http://builds.factorcode.org/download" ] dip - [ os>> "os" set-query-param ] - [ cpu>> "cpu" set-query-param ] bi - ] dip link ; - -: download-grid-cell ( cpu os -- xml ) - builder new swap >>os swap >>cpu select-tuple [ - dup last-release>> dup - [ "." split1 drop 16 tail* 6 head* download-link ] [ 2drop f ] if - [XML
<->
XML] - ] [ - [XML XML] - ] if* ; - -CONSTANT: oses -{ - { "winnt" "Windows" } - { "macosx" "Mac OS X" } - { "linux" "Linux" } - { "freebsd" "FreeBSD" } - { "netbsd" "NetBSD" } - { "openbsd" "OpenBSD" } -} - -CONSTANT: cpus -{ - { "x86.32" "x86" } - { "x86.64" "x86-64" } - { "ppc" "PowerPC" } -} - -: download-grid ( -- xml ) - oses - [ values [ [XML <-> XML] ] map ] - [ - keys - cpus [ - [ nip second ] [ first ] 2bi [ - swap download-grid-cell - ] curry map - [XML <-><-> XML] - ] with map - ] bi - [XML - - <-> - <-> -
OS/CPU
- XML] ; - -: ( -- action ) - - [ download-grid xml>string "text/html" ] >>display ; - -: validate-os/cpu ( -- ) - { - { "os" [ v-one-line ] } - { "cpu" [ v-one-line ] } - } validate-params ; - -: current-builder ( -- builder ) - builder new "os" value >>os "cpu" value >>cpu select-tuple ; - -: ( -- action ) - - [ validate-os/cpu ] >>init - [ current-builder last-report>> "text/html" ] >>display ; - -: building ( builder string -- xml ) - swap current-git-id>> git-link - [XML <-> for <-> XML] ; - -: status-string ( builder -- string ) - dup status>> { - { +dirty+ [ drop "Dirty" ] } - { +clean+ [ drop "Clean" ] } - { +error+ [ drop "Error" ] } - { +starting+ [ "Starting build" building ] } - { +make-vm+ [ "Compiling VM" building ] } - { +boot+ [ "Bootstrapping" building ] } - { +test+ [ "Testing" building ] } - [ 2drop "Unknown" ] - } case ; - -: current-status ( builder -- xml ) - [ status-string ] - [ current-timestamp>> present " (as of " ")" surround ] bi - 2array ; - -: build-status ( git-id timestamp -- xml ) - over [ [ git-link ] [ present ] bi* " (built on " ")" surround 2array ] [ 2drop f ] if ; - -: binaries-url ( builder -- url ) - [ os>> ] [ cpu>> ] bi (platform) "http://downloads.factorcode.org/" prepend ; - -: latest-binary-link ( builder -- xml ) - [ binaries-url ] [ last-release>> ] bi [ "/" glue ] keep link ; - -: binaries-link ( builder -- link ) - binaries-url dup link ; - -: clean-image-url ( builder -- url ) - [ os>> ] [ cpu>> ] bi (platform) "http://factorcode.org/images/clean/" prepend ; - -: clean-image-link ( builder -- link ) - clean-image-url dup link ; - -: report-link ( builder -- xml ) - [ URL" report" ] dip - [ os>> "os" set-query-param ] - [ cpu>> "cpu" set-query-param ] bi - [XML >Latest build report XML] ; - -: requirements ( builder -- xml ) - [ - os>> { - { "winnt" "Windows XP, Windows Vista or Windows 7" } - { "macosx" "Mac OS X 10.5 Leopard" } - { "linux" "Ubuntu Linux 9.04 (other distributions may also work)" } - { "freebsd" "FreeBSD 7.1" } - { "netbsd" "NetBSD 5.0" } - { "openbsd" "OpenBSD 4.4" } - } at - ] [ - dup cpu>> "x86.32" = [ - os>> { - { [ dup { "winnt" "linux" "freebsd" "netbsd" } member? ] [ drop "Intel Pentium 4, Core Duo, or other x86 chip with SSE2 support. Note that 32-bit Athlon XP processors do not support SSE2." ] } - { [ dup { "openbsd" } member? ] [ drop "Intel Pentium Pro or better" ] } - { [ t ] [ drop f ] } - } cond - ] [ drop f ] if - ] bi - 2array sift [ [XML
  • <->
  • XML] ] map [XML
      <->
    XML] ; - -: last-build-status ( builder -- xml ) - [ last-git-id>> ] [ last-timestamp>> ] bi build-status ; - -: clean-build-status ( builder -- xml ) - [ clean-git-id>> ] [ clean-timestamp>> ] bi build-status ; - -: ( -- action ) - - [ - validate-os/cpu - "os" value "cpu" value (platform) "platform" set-value - current-builder { - [ latest-binary-link "package" set-value ] - [ release-git-id>> git-link "git-id" set-value ] - [ requirements "requirements" set-value ] - [ host-name>> "host-name" set-value ] - [ current-status "status" set-value ] - [ last-build-status "last-build" set-value ] - [ clean-build-status "last-clean-build" set-value ] - [ binaries-link "binaries" set-value ] - [ clean-image-link "clean-images" set-value ] - [ report-link "last-report" set-value ] - } cleave - ] >>init - { mason-app "download" } >>template ; - : ( -- dispatcher ) mason-app new-dispatcher "report" add-responder - "download" add-responder - "grid" add-responder + + { mason-app "download-package" } >>template + "package" add-responder + + "packages" add-responder + + + { mason-app "download-release" } >>template + "release" add-responder + + "releases" add-responder mason-db ; diff --git a/extra/webapps/mason/package/authors.txt b/extra/webapps/mason/package/authors.txt new file mode 100644 index 0000000000..d4f5d6b3ae --- /dev/null +++ b/extra/webapps/mason/package/authors.txt @@ -0,0 +1 @@ +Slava Pestov \ No newline at end of file diff --git a/extra/webapps/mason/package/package.factor b/extra/webapps/mason/package/package.factor new file mode 100644 index 0000000000..0917eaa33a --- /dev/null +++ b/extra/webapps/mason/package/package.factor @@ -0,0 +1,71 @@ +! Copyright (C) 2010 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors arrays combinators furnace.actions html.forms +kernel mason.platform mason.report mason.server present +sequences webapps.mason webapps.mason.report +webapps.mason.utils xml.syntax ; +IN: webapps.mason.package + +: building ( builder string -- xml ) + swap current-git-id>> git-link + [XML <-> for <-> XML] ; + +: status-string ( builder -- string ) + dup status>> { + { +dirty+ [ drop "Dirty" ] } + { +clean+ [ drop "Clean" ] } + { +error+ [ drop "Error" ] } + { +starting+ [ "Starting build" building ] } + { +make-vm+ [ "Compiling VM" building ] } + { +boot+ [ "Bootstrapping" building ] } + { +test+ [ "Testing" building ] } + [ 2drop "Unknown" ] + } case ; + +: current-status ( builder -- xml ) + [ status-string ] + [ current-timestamp>> present " (as of " ")" surround ] bi + 2array ; + +: build-status ( git-id timestamp -- xml ) + over [ [ git-link ] [ present ] bi* " (built on " ")" surround 2array ] [ 2drop f ] if ; + +: packages-url ( builder -- url ) + [ os>> ] [ cpu>> ] bi (platform) "http://downloads.factorcode.org/" prepend ; + +: package-link ( builder -- xml ) + [ packages-url ] [ last-release>> ] bi [ "/" glue ] keep link ; + +: packages-link ( builder -- link ) + packages-url dup link ; + +: clean-image-url ( builder -- url ) + [ os>> ] [ cpu>> ] bi (platform) "http://factorcode.org/images/clean/" prepend ; + +: clean-image-link ( builder -- link ) + clean-image-url dup link ; + +: last-build-status ( builder -- xml ) + [ last-git-id>> ] [ last-timestamp>> ] bi build-status ; + +: clean-build-status ( builder -- xml ) + [ clean-git-id>> ] [ clean-timestamp>> ] bi build-status ; + +: ( -- action ) + + [ + validate-os/cpu + "os" value "cpu" value (platform) "platform" set-value + current-builder { + [ package-link "package" set-value ] + [ release-git-id>> git-link "git-id" set-value ] + [ requirements "requirements" set-value ] + [ host-name>> "host-name" set-value ] + [ current-status "status" set-value ] + [ last-build-status "last-build" set-value ] + [ clean-build-status "last-clean-build" set-value ] + [ packages-link "binaries" set-value ] + [ clean-image-link "clean-images" set-value ] + [ report-link "last-report" set-value ] + } cleave + ] >>init ; diff --git a/extra/webapps/mason/release/authors.txt b/extra/webapps/mason/release/authors.txt new file mode 100644 index 0000000000..d4f5d6b3ae --- /dev/null +++ b/extra/webapps/mason/release/authors.txt @@ -0,0 +1 @@ +Slava Pestov \ No newline at end of file diff --git a/extra/webapps/mason/release/release.factor b/extra/webapps/mason/release/release.factor new file mode 100644 index 0000000000..e87b53fdfe --- /dev/null +++ b/extra/webapps/mason/release/release.factor @@ -0,0 +1,25 @@ +! Copyright (C) 2010 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors furnace.actions html.forms kernel +mason.platform mason.report sequences webapps.mason +webapps.mason.utils ; +IN: webapps.mason.release + +: releases-url ( builder -- url ) + [ os>> ] [ cpu>> ] bi (platform) + "http://downloads.factorcode.org/releases/" prepend ; + +: release-link ( builder -- xml ) + [ releases-url ] [ last-release>> ] bi [ "/" glue ] keep link ; + +: ( -- action ) + + [ + validate-os/cpu + "os" value "cpu" value (platform) "platform" set-value + current-release + [ release-link "release" set-value ] + [ release-git-id>> git-link "git-id" set-value ] + [ requirements "requirements" set-value ] + tri + ] >>init ; diff --git a/extra/webapps/mason/report/authors.txt b/extra/webapps/mason/report/authors.txt new file mode 100644 index 0000000000..d4f5d6b3ae --- /dev/null +++ b/extra/webapps/mason/report/authors.txt @@ -0,0 +1 @@ +Slava Pestov \ No newline at end of file diff --git a/extra/webapps/mason/report/report.factor b/extra/webapps/mason/report/report.factor new file mode 100644 index 0000000000..f2d7542b9e --- /dev/null +++ b/extra/webapps/mason/report/report.factor @@ -0,0 +1,16 @@ +! Copyright (C) 2010 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors furnace.actions http.server.responses kernel +urls webapps.mason.utils xml.syntax ; +IN: webapps.mason.report + +: ( -- action ) + + [ validate-os/cpu ] >>init + [ current-builder last-report>> "text/html" ] >>display ; + +: report-link ( builder -- xml ) + [ URL" report" ] dip + [ os>> "os" set-query-param ] + [ cpu>> "cpu" set-query-param ] bi + [XML >Latest build report XML] ; diff --git a/extra/webapps/mason/utils/authors.txt b/extra/webapps/mason/utils/authors.txt new file mode 100644 index 0000000000..d4f5d6b3ae --- /dev/null +++ b/extra/webapps/mason/utils/authors.txt @@ -0,0 +1 @@ +Slava Pestov \ No newline at end of file diff --git a/extra/webapps/mason/utils/utils.factor b/extra/webapps/mason/utils/utils.factor new file mode 100644 index 0000000000..8197cce820 --- /dev/null +++ b/extra/webapps/mason/utils/utils.factor @@ -0,0 +1,40 @@ +! Copyright (C) 2010 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors arrays assocs db.tuples furnace.actions +html.forms kernel mason.server mason.server.release sequences +validators xml.syntax ; +IN: webapps.mason.utils + +: link ( url label -- xml ) + [XML ><-> XML] ; + +: validate-os/cpu ( -- ) + { + { "os" [ v-one-line ] } + { "cpu" [ v-one-line ] } + } validate-params ; + +: current-builder ( -- builder ) + builder new "os" value >>os "cpu" value >>cpu select-tuple ; + +: current-release ( -- builder ) + release new "os" value >>os "cpu" value >>cpu select-tuple ; + +: requirements ( builder -- xml ) + [ + os>> { + { "winnt" "Windows XP, Windows Vista or Windows 7" } + { "macosx" "Mac OS X 10.5 Leopard" } + { "linux" "Ubuntu Linux 9.04 (other distributions may also work)" } + { "freebsd" "FreeBSD 7.1" } + { "netbsd" "NetBSD 5.0" } + { "openbsd" "OpenBSD 4.5" } + } at + ] [ + dup cpu>> "x86.32" = [ + os>> "macosx" = + f "Intel Pentium 4, Core Duo, or other x86 chip with SSE2 support. Note that 32-bit Athlon XP processors do not support SSE2." + ? + ] [ drop f ] if + ] bi + 2array sift [ [XML
  • <->
  • XML] ] map [XML
      <->
    XML] ;