]> gitweb.factorcode.org Git - factor.git/commitdiff
add begin-game-world and end-game-world generics so method-chains aren't needed just...
authorJoe Groff <arcata@gmail.com>
Sun, 17 Jan 2010 07:06:54 +0000 (23:06 -0800)
committerJoe Groff <arcata@gmail.com>
Sun, 17 Jan 2010 07:06:54 +0000 (23:06 -0800)
extra/game/worlds/worlds-docs.factor
extra/game/worlds/worlds.factor
extra/gpu/demos/bunny/bunny.factor
extra/gpu/demos/raytrace/raytrace.factor
extra/terrain/terrain.factor

index e021ed571851fbc99159c8c657c252b70af39a14..faa21a18dc061b6d05f163de093ddcc9f0a4515f 100644 (file)
@@ -1,5 +1,6 @@
 ! (c)2009 Joe Groff bsd license
-USING: game.loop help.markup help.syntax kernel math ui ui.gadgets.worlds words ;
+USING: game.loop help.markup help.syntax kernel math method-chains
+ui ui.gadgets.worlds words ;
 IN: game.worlds
 
 HELP: GAME:
@@ -14,7 +15,17 @@ HELP: game-attributes
 } ;
 
 HELP: game-world
-{ $class-description "" } ;
+{ $class-description "A subclass of " { $link world } " that automatically sets up and manages connections to the " { $vocab-link "game.loop" } " and " { $vocab-link "game.input" } " libraries. It does this by providing methods on " { $link begin-world } ", " { $link end-world } ", and " { $link draw* } ". Subclasses can provide their own world setup and teardown code by adding methods to the " { $link begin-game-world } " and " { $link end-game-world } " generic words." } ;
+
+HELP: begin-game-world
+{ $values { "world" game-world } }
+{ $description "This generic word is called by the " { $link begin-world } " method for " { $link game-world } " subclasses immediately before the game world starts the game loop." } ;
+
+HELP: end-game-world
+{ $values { "world" game-world } }
+{ $description "This generic word is called by the " { $link end-world } " method for " { $link game-world } " subclasses immediately after the game world stops the game loop." } ;
+
+{ game-world begin-game-world end-game-world } related-words
 
 HELP: tick-interval-micros
 { $values
@@ -30,6 +41,10 @@ ARTICLE: "game.worlds" "Game worlds"
     game-attributes
     POSTPONE: GAME:
 }
-;
+"Subclasses of " { $link game-world } " can provide their own setup and teardown code by providing methods for these generic words:"
+{ $subsections
+    begin-game-world
+    end-game-world
+} ;
 
 ABOUT: "game.worlds"
index 1fd7f53905306282d9ee125afe5dd616bd04ae86..d624a1b41e80f44837885ee0aae137507dbc1a75 100644 (file)
@@ -10,18 +10,25 @@ TUPLE: game-world < world
 
 GENERIC: tick-interval-micros ( world -- micros )
 
+GENERIC: begin-game-world ( world -- )
+M: object begin-game-world drop ;
+
+GENERIC: end-game-world ( world -- )
+M: object end-game-world drop ;
+
 M: game-world draw*
     swap >>tick-slice relayout-1 yield ;
 
 M: game-world begin-world
     open-game-input 
+    dup begin-game-world
     dup [ tick-interval-micros ] [ ] bi <game-loop> [ >>game-loop ] keep start-loop
     drop ;
 
 M: game-world end-world
     [ [ stop-loop ] when* f ] change-game-loop
-    close-game-input
-    drop ;
+    end-game-world
+    close-game-input ;
 
 TUPLE: game-attributes < world-attributes
     { tick-interval-micros fixnum read-only } ;
index e18d76ed8d9c12fa227e335f4d62cb222f3bbd40..3199cdcffd2a8b32e041c8633c792f5909cbf9a8 100644 (file)
@@ -214,7 +214,7 @@ CONSTANT: bunny-model-url "http://factorcode.org/bun_zipper.ply"
         dup 0 "vocab:gpu/demos/bunny/loading.tiff" load-image allocate-texture-image
         >>texture ;
 
-BEFORE: bunny-world begin-world
+M: bunny-world begin-game-world
     init-gpu
     
     { -0.2 0.13 0.1 } 1.1 0.2 set-wasd-view
index b474ca1f09dbbab95df6b2d2b9eaea0e0080f603..a58388fc00bb6b0d4337dd62ab945f3fc085b394 100644 (file)
@@ -69,7 +69,7 @@ CONSTANT: initial-spheres {
     T{ sphere f { 1.0 0.0  0.0 } {  0.0 5.0 0.0 } 0.025 1.0 { 1.0 1.0 0.0 1.0 } }
 }
 
-BEFORE: raytrace-world begin-world
+M: raytrace-world begin-game-world
     init-gpu
     { -2.0 6.25 10.0 } 0.19 0.55 set-wasd-view
     initial-spheres [ clone ] map >>spheres    
index 39bc7f3ec8b75d49bf6eb03ab7433c00b341bc9d..370c7634a710d9c12c9e426879cfeecd38d71195 100644 (file)
@@ -6,7 +6,7 @@ math.vectors opengl opengl.capabilities opengl.gl
 opengl.shaders opengl.textures opengl.textures.private
 sequences sequences.product specialized-arrays
 terrain.generation terrain.shaders typed ui ui.gadgets
-ui.gadgets.worlds ui.pixel-formats game.worlds method-chains
+ui.gadgets.worlds ui.pixel-formats game.worlds
 math.matrices.simd noise ui.gestures combinators.short-circuit
 destructors grid-meshes math.vectors.simd ;
 QUALIFIED-WITH: alien.c-types c
@@ -233,7 +233,7 @@ M: terrain-world tick*
 : sky-theta ( world -- theta )
     game-loop>> tick-number>> SKY-SPEED * ;
 
-BEFORE: terrain-world begin-world
+M: terrain-world begin-game-world
     "2.0" { "GL_ARB_vertex_buffer_object" "GL_ARB_shader_objects" }
     require-gl-version-or-extensions
     GL_DEPTH_TEST glEnable
@@ -254,7 +254,7 @@ BEFORE: terrain-world begin-world
     terrain-vertex-size <grid-mesh> >>terrain-mesh
     drop ;
 
-AFTER: terrain-world end-world
+M: terrain-world end-game-world
     {
         [ terrain-mesh>> dispose ]
         [ terrain-program>> delete-gl-program ]