! (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:
} ;
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
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"
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 } ;
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
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
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
: 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
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 ]