]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/bunny/bunny.factor
Delete empty unit tests files, remove 1- and 1+, reorder IN: lines in a lot of places...
[factor.git] / extra / bunny / bunny.factor
index d546f9ea41c229a136732ca8fc8e7b70c6d86662..b7400c4acb53e054c7497d95dd2d451b8cc41848 100755 (executable)
@@ -1,63 +1,67 @@
-USING: alien alien.c-types arrays sequences math math.vectors
-math.matrices math.parser io io.files kernel opengl opengl.gl
-opengl.glu shuffle http.client vectors namespaces ui.gadgets
-ui.gadgets.canvas ui.render ui splitting combinators tools.time
-system combinators.lib float-arrays continuations
-opengl.demo-support multiline ui.gestures bunny.fixed-pipeline
-bunny.cel-shaded bunny.outlined bunny.model accessors ;
+USING: accessors arrays bunny.cel-shaded bunny.fixed-pipeline
+bunny.model bunny.outlined destructors kernel math opengl.demo-support
+opengl.gl sequences ui ui.gadgets ui.gadgets.worlds ui.gestures
+ui.render words ui.pixel-formats ;
 IN: bunny
 
-TUPLE: bunny-gadget model geom draw-seq draw-n ;
+TUPLE: bunny-world < demo-world model-triangles geom draw-seq draw-n ;
 
-: <bunny-gadget> ( -- bunny-gadget )
-    0.0 0.0 0.375 <demo-gadget>
-    maybe-download read-model {
-        set-delegate
-        (>>model)
-    } bunny-gadget construct ;
+: get-draw ( gadget -- draw )
+    [ draw-n>> ] [ draw-seq>> ] bi nth ;
 
-: bunny-gadget-draw ( gadget -- draw )
-    { draw-n>> draw-seq>> }
-    get-slots nth ;
-
-: bunny-gadget-next-draw ( gadget -- )
-    dup { draw-seq>> draw-n>> }
-    get-slots
-    1+ swap length mod
+: next-draw ( gadget -- )
+    dup [ draw-seq>> ] [ draw-n>> ] bi
+    1 + swap length mod
     >>draw-n relayout-1 ;
 
-M: bunny-gadget graft* ( gadget -- )
-    GL_DEPTH_TEST glEnable
-    dup model>> <bunny-geom> >>geom
-    dup
+: make-draws ( gadget -- draw-seq )
     [ <bunny-fixed-pipeline> ]
     [ <bunny-cel-shaded> ]
     [ <bunny-outlined> ] tri 3array
-    [ ] filter >>draw-seq
+    sift ;
+
+M: bunny-world begin-world
+    GL_DEPTH_TEST glEnable
+    0.0 0.0 0.375 set-demo-orientation
+    maybe-download read-model
+    [ >>model-triangles ] [ <bunny-geom> >>geom ] bi
+    dup make-draws >>draw-seq
     0 >>draw-n
     drop ;
 
-M: bunny-gadget ungraft* ( gadget -- )
+M: bunny-world end-world
+    dup find-gl-context
     [ geom>> [ dispose ] when* ]
     [ draw-seq>> [ [ dispose ] when* ] each ] bi ;
 
-M: bunny-gadget draw-gadget* ( gadget -- )
-    0.15 0.15 0.15 1.0 glClearColor
-    GL_DEPTH_BUFFER_BIT GL_COLOR_BUFFER_BIT bitor glClear
-    dup demo-gadget-set-matrices
-    GL_MODELVIEW glMatrixMode
-    0.02 -0.105 0.0 glTranslatef
-    { geom>> bunny-gadget-draw } get-slots
-    draw-bunny ;
+M: bunny-world draw-world*
+    dup draw-seq>> empty? [ drop ] [
+        0.15 0.15 0.15 1.0 glClearColor
+        GL_DEPTH_BUFFER_BIT GL_COLOR_BUFFER_BIT bitor glClear
+        dup demo-world-set-matrix
+        GL_MODELVIEW glMatrixMode
+        0.02 -0.105 0.0 glTranslatef
+        [ geom>> ] [ get-draw ] bi draw-bunny
+    ] if ;
 
-M: bunny-gadget pref-dim* ( gadget -- dim )
+M: bunny-world pref-dim* ( gadget -- dim )
     drop { 640 480 } ;
     
-bunny-gadget H{
-    { T{ key-down f f "TAB" } [ bunny-gadget-next-draw ] }
+bunny-world H{
+    { T{ key-down f f "TAB" } [ next-draw ] }
 } set-gestures
 
 : bunny-window ( -- )
-    [ <bunny-gadget> "Bunny" open-window ] with-ui ;
+    [
+        f T{ world-attributes
+            { world-class bunny-world }
+            { title "Bunny" }
+            { pixel-format-attributes {
+                windowed
+                double-buffered
+                T{ depth-bits { value 16 } }
+            } }
+        } open-window
+    ] with-ui ;
 
 MAIN: bunny-window