add begin-game-world and end-game-world generics so method-chains aren't needed just to do game setup and teardown at the right time
parent
a2e3d64de6
commit
89f104d8ab
|
@ -1,5 +1,6 @@
|
||||||
! (c)2009 Joe Groff bsd license
|
! (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
|
IN: game.worlds
|
||||||
|
|
||||||
HELP: GAME:
|
HELP: GAME:
|
||||||
|
@ -14,7 +15,17 @@ HELP: game-attributes
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: game-world
|
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
|
HELP: tick-interval-micros
|
||||||
{ $values
|
{ $values
|
||||||
|
@ -30,6 +41,10 @@ ARTICLE: "game.worlds" "Game worlds"
|
||||||
game-attributes
|
game-attributes
|
||||||
POSTPONE: GAME:
|
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"
|
ABOUT: "game.worlds"
|
||||||
|
|
|
@ -10,18 +10,25 @@ TUPLE: game-world < world
|
||||||
|
|
||||||
GENERIC: tick-interval-micros ( world -- micros )
|
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*
|
M: game-world draw*
|
||||||
swap >>tick-slice relayout-1 yield ;
|
swap >>tick-slice relayout-1 yield ;
|
||||||
|
|
||||||
M: game-world begin-world
|
M: game-world begin-world
|
||||||
open-game-input
|
open-game-input
|
||||||
|
dup begin-game-world
|
||||||
dup [ tick-interval-micros ] [ ] bi <game-loop> [ >>game-loop ] keep start-loop
|
dup [ tick-interval-micros ] [ ] bi <game-loop> [ >>game-loop ] keep start-loop
|
||||||
drop ;
|
drop ;
|
||||||
|
|
||||||
M: game-world end-world
|
M: game-world end-world
|
||||||
[ [ stop-loop ] when* f ] change-game-loop
|
[ [ stop-loop ] when* f ] change-game-loop
|
||||||
close-game-input
|
end-game-world
|
||||||
drop ;
|
close-game-input ;
|
||||||
|
|
||||||
TUPLE: game-attributes < world-attributes
|
TUPLE: game-attributes < world-attributes
|
||||||
{ tick-interval-micros fixnum read-only } ;
|
{ tick-interval-micros fixnum read-only } ;
|
||||||
|
|
|
@ -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
|
dup 0 "vocab:gpu/demos/bunny/loading.tiff" load-image allocate-texture-image
|
||||||
>>texture ;
|
>>texture ;
|
||||||
|
|
||||||
BEFORE: bunny-world begin-world
|
M: bunny-world begin-game-world
|
||||||
init-gpu
|
init-gpu
|
||||||
|
|
||||||
{ -0.2 0.13 0.1 } 1.1 0.2 set-wasd-view
|
{ -0.2 0.13 0.1 } 1.1 0.2 set-wasd-view
|
||||||
|
|
|
@ -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 } }
|
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
|
init-gpu
|
||||||
{ -2.0 6.25 10.0 } 0.19 0.55 set-wasd-view
|
{ -2.0 6.25 10.0 } 0.19 0.55 set-wasd-view
|
||||||
initial-spheres [ clone ] map >>spheres
|
initial-spheres [ clone ] map >>spheres
|
||||||
|
|
|
@ -6,7 +6,7 @@ math.vectors opengl opengl.capabilities opengl.gl
|
||||||
opengl.shaders opengl.textures opengl.textures.private
|
opengl.shaders opengl.textures opengl.textures.private
|
||||||
sequences sequences.product specialized-arrays
|
sequences sequences.product specialized-arrays
|
||||||
terrain.generation terrain.shaders typed ui ui.gadgets
|
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
|
math.matrices.simd noise ui.gestures combinators.short-circuit
|
||||||
destructors grid-meshes math.vectors.simd ;
|
destructors grid-meshes math.vectors.simd ;
|
||||||
QUALIFIED-WITH: alien.c-types c
|
QUALIFIED-WITH: alien.c-types c
|
||||||
|
@ -233,7 +233,7 @@ M: terrain-world tick*
|
||||||
: sky-theta ( world -- theta )
|
: sky-theta ( world -- theta )
|
||||||
game-loop>> tick-number>> SKY-SPEED * ;
|
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" }
|
"2.0" { "GL_ARB_vertex_buffer_object" "GL_ARB_shader_objects" }
|
||||||
require-gl-version-or-extensions
|
require-gl-version-or-extensions
|
||||||
GL_DEPTH_TEST glEnable
|
GL_DEPTH_TEST glEnable
|
||||||
|
@ -254,7 +254,7 @@ BEFORE: terrain-world begin-world
|
||||||
terrain-vertex-size <grid-mesh> >>terrain-mesh
|
terrain-vertex-size <grid-mesh> >>terrain-mesh
|
||||||
drop ;
|
drop ;
|
||||||
|
|
||||||
AFTER: terrain-world end-world
|
M: terrain-world end-game-world
|
||||||
{
|
{
|
||||||
[ terrain-mesh>> dispose ]
|
[ terrain-mesh>> dispose ]
|
||||||
[ terrain-program>> delete-gl-program ]
|
[ terrain-program>> delete-gl-program ]
|
||||||
|
|
Loading…
Reference in New Issue