begin-game-world ( world -- )
Game worlds
Prev:game-attributes
Next:end-game-world ( world -- )


Vocabulary
game.worlds

Inputs and outputs
worlda game-world


Word description
This generic word is called by the begin-world method for game-world subclasses immediately before the game world starts the game loop. If the game world has an audio-engine, it will be initialized and started before begin-game-world is called.

See also
game-world, end-game-world, tick-game-world

Definition
IN: game.worlds

GENERIC: begin-game-world ( world -- )


Methods
USING: accessors game.worlds gpu gpu.demos.bunny gpu.util
gpu.util.wasd kernel ;

M: bunny-world begin-game-world
init-gpu { -0.2 0.13 0.1 } 1.1 0.2 set-wasd-view
<bunny-state> >>bunny <window-vertex-buffer>
[ <sobel-state> >>sobel ] [ <loading-state> >>loading ] bi
drop ;


USING: accessors chipmunk.demo chipmunk.ffi game.worlds kernel
locals locals.prettyprint math random sequences ;

M:: chipmunk-world begin-game-world ( world -- )
cpInitChipmunk cpSpaceAlloc cpSpaceInit :> 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 random-unit * + 2 *
image-height 2 / y - 0.05 random-unit * + 2 *
make-ball
:> shape space shape shape>> body>>
cpSpaceAddBody drop space shape cpSpaceAddShape
drop
] when
] each
] each space cpBodyAlloc 1/0. dup cpBodyInit cpSpaceAddBody
:> body body -1000 -10 cpv >>p drop body 400 0 cpv >>v drop
space cpCircleShapeAlloc
[ body 8 0 0 cpv cpCircleShapeInit cpSpaceAddShape drop ]
keep :> shape shape shape>> 0 >>e 0 >>u drop ;


USING: accessors fluids game.worlds gpu kernel namespaces ;

M: fluids-world begin-game-world
dup fluid set init-gpu initial-particles clone >>particles
"vocab:fluids/particle2.pgm" make-texture >>texture
"vocab:fluids/colors.ppm" make-texture >>ramp drop ;


USING: accessors game.worlds gpu gpu.util.wasd kernel
model-viewer ;

M: model-world begin-game-world
init-gpu { 0.0 0.0 2.0 } 0 0 set-wasd-view
[ <model-state> [ fill-model-state ] keep ]
[ model-state<< ] bi ;


USING: game.worlds kernel ;

M: object begin-game-world drop ;


USING: accessors game.worlds gpu gpu.demos.raytrace gpu.shaders
gpu.util gpu.util.wasd kernel sequences ;

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
raytrace-program <program-instance> <window-vertex-array>
>>vertex-array set-up-audio ;


USING: accessors game.worlds grid-meshes kernel
math.matrices.simd math.vectors.simd noise opengl.capabilities
opengl.gl opengl.shaders opengl.textures terrain
terrain.generation terrain.shaders ;

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
GL_TEXTURE_2D glEnable GL_VERTEX_ARRAY glEnableClientState
<player> >>player V{ } clone >>history
<perlin-noise-table> 0.01 float-4-with scale-matrix4
{ 512 512 } perlin-noise-image [ >>sky-image ] keep
make-texture [ set-texture-parameters ] keep >>sky-texture
<terrain> [ >>terrain ] keep
float-4{ 0.0 0.0 0.0 1.0 } terrain-segment
[ >>terrain-segment ] keep make-texture
[ set-texture-parameters ] keep >>terrain-texture
sky-vertex-shader sky-pixel-shader <simple-gl-program>
>>sky-program
terrain-vertex-shader terrain-pixel-shader
<simple-gl-program> >>terrain-program
terrain-vertex-size <grid-mesh> >>terrain-mesh drop ;


USING: accessors game.debug.tests game.worlds gpu gpu.util.wasd
kernel ;

M: tests-world begin-game-world
init-gpu 0 >>frame# { 0.0 0.0 2.0 } 0 0 set-wasd-view drop
;