2009-05-18 11:31:05 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								! (c)2009 Joe Groff, Doug Coleman. bsd license
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-08 02:42:54 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								USING: accessors arrays combinators game.input game.loop
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								game.input.scancodes grouping kernel literals locals
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								math math.constants math.functions math.order
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								math.vectors opengl opengl.capabilities opengl.gl
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								opengl.shaders opengl.textures opengl.textures.private
							 | 
						
					
						
							
								
									
										
										
										
											2009-09-09 23:33:34 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								sequences sequences.product specialized-arrays
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								terrain.generation terrain.shaders typed ui ui.gadgets
							 | 
						
					
						
							
								
									
										
										
										
											2010-01-19 13:28:06 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								ui.gadgets.worlds ui.pixel-formats game.worlds
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								math.matrices.simd noise ui.gestures combinators.short-circuit
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								destructors grid-meshes math.vectors.simd ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								QUALIFIED-WITH: alien.c-types c
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								SPECIALIZED-ARRAY: c:float
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								IN: terrain
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-08-13 20:21:44 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								CONSTANT: FOV $[ 2.0 sqrt 1 + ]
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								CONSTANT: NEAR-PLANE 1/1024.
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-10 14:45:58 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								CONSTANT: FAR-PLANE 2.0
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								CONSTANT: PLAYER-START-LOCATION float-4{ 0.5 0.51 0.5 1.0 }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								CONSTANT: VELOCITY-MODIFIER-NORMAL float-4{ 1.0 1.0 1.0 0.0 }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								CONSTANT: VELOCITY-MODIFIER-FAST float-4{ 2.0 1.0 2.0 0.0 }
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-16 18:05:44 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								CONSTANT: BOUNCE float-4{ 1.0 -0.2 1.0 1.0 }
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								CONSTANT: PLAYER-HEIGHT 1/256.
							 | 
						
					
						
							
								
									
										
										
										
											2010-01-15 17:36:45 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								CONSTANT: GRAVITY float-4{ 0.0 -1/8192. 0.0 0.0 }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								CONSTANT: JUMP 1/2048.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								CONSTANT: MOUSE-SCALE 1/20.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								CONSTANT: MOVEMENT-SPEED 1/32768.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								CONSTANT: FRICTION float-4{ 0.97 0.995 0.97 1.0 }
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								CONSTANT: COMPONENT-SCALE float-4{ 0.5 0.01 0.0005 0.0 }
							 | 
						
					
						
							
								
									
										
										
										
											2010-01-15 17:36:45 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								CONSTANT: SKY-PERIOD 2400
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								CONSTANT: SKY-SPEED 0.00025
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								CONSTANT: terrain-vertex-size { 512 512 }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								TUPLE: player
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    { location float-4 }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    { yaw float }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    { pitch float }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    { velocity float-4 }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    { velocity-modifier float-4 }
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-15 20:36:36 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    reverse-time ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 13:53:01 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								TUPLE: terrain-world < game-world
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    { player player }
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-10 14:45:58 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    sky-image sky-texture sky-program
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    terrain terrain-segment terrain-texture terrain-program
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-18 11:31:05 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    terrain-mesh
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-15 20:36:36 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    history ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: <player> ( -- player )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    player new
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        PLAYER-START-LOCATION >>location
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        0.0 >>yaw
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        0.0 >>pitch
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        float-4{ 0.0 0.0 0.0 1.0 } >>velocity
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-15 20:36:36 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        VELOCITY-MODIFIER-NORMAL >>velocity-modifier ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 13:53:01 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: frustum ( dim -- -x x -y y near far )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    dup first2 min v/n
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    NEAR-PLANE FOV / v*n first2 [ [ neg ] keep ] bi@
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    NEAR-PLANE FAR-PLANE ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: set-modelview-matrix ( gadget -- )
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-10 14:45:58 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    GL_DEPTH_BUFFER_BIT glClear
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    GL_MODELVIEW glMatrixMode
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    glLoadIdentity
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    player>>
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ pitch>> 1.0 0.0 0.0 glRotatef ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ yaw>> 0.0 1.0 0.0 glRotatef ]
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ location>> vneg first3 glTranslatef ] tri ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: degrees ( deg -- rad )
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    pi 180.0 / * ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								TYPED: eye-rotate ( yaw: float pitch: float v: float-4 -- v': float-4 )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ float-4{  0.0 -1.0 0.0 0.0 } swap degrees rotation-matrix4 ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ float-4{ -1.0  0.0 0.0 0.0 } swap degrees rotation-matrix4 m4. ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ m4.v ] tri* float-4{ t t t f } vand ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: forward-vector ( player -- v )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    yaw>> 0.0
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    float-4{ 0.0 0.0 $ MOVEMENT-SPEED 1.0 } vneg eye-rotate ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: rightward-vector ( player -- v )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    yaw>> 0.0
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    float-4{ $ MOVEMENT-SPEED 0.0 0.0 1.0 } eye-rotate ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-13 20:21:27 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: clamp-pitch ( pitch -- pitch' )
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    -90.0 90.0 clamp ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-13 20:21:27 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: walk-forward ( player -- )
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    dup forward-vector [ v+ ] curry change-velocity drop ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: walk-backward ( player -- )
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    dup forward-vector [ v- ] curry change-velocity drop ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: walk-leftward ( player -- )
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    dup rightward-vector [ v- ] curry change-velocity drop ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: walk-rightward ( player -- )
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    dup rightward-vector [ v+ ] curry change-velocity drop ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: jump ( player -- )
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ float-4{ 0.0 $ JUMP 0.0 0.0 } v+ ] change-velocity drop ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-13 20:21:27 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: rotate-leftward ( player x -- )
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ - ] curry change-yaw drop ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-13 20:21:27 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: rotate-rightward ( player x -- )
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ + ] curry change-yaw drop ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-13 20:21:27 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: look-horizontally ( player x -- )
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ + ] curry change-yaw drop ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-13 20:21:27 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: look-vertically ( player x -- )
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ + clamp-pitch ] curry change-pitch drop ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: rotate-with-mouse ( player mouse -- )
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-13 20:21:27 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ dx>> MOUSE-SCALE * look-horizontally ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ dy>> MOUSE-SCALE * look-vertically ] 2bi ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-13 21:06:13 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								terrain-world H{
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-15 12:04:11 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    { T{ key-down { mods { A+ } } { sym "RET" } } [ toggle-fullscreen ] }
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-13 21:06:13 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								} set-gestures
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								:: handle-input ( world -- )
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    world player>> :> player
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    read-keyboard keys>> :> keys
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-15 20:36:36 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    key-left-shift keys nth
							 | 
						
					
						
							
								
									
										
										
										
											2010-05-05 16:52:54 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    VELOCITY-MODIFIER-FAST VELOCITY-MODIFIER-NORMAL ? player velocity-modifier<<
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-15 20:36:36 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ key-1 keys nth 1  f ? ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ key-2 keys nth 2  f ? ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ key-3 keys nth 3  f ? ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ key-4 keys nth 4  f ? ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ key-5 keys nth 10000 f ? ]
							 | 
						
					
						
							
								
									
										
										
										
											2010-05-05 16:52:54 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } 0|| player reverse-time<<
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-13 21:06:13 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2014-10-13 17:31:04 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    key-w keys nth [ player walk-forward ] when
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    key-s keys nth [ player walk-backward ] when
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    key-a keys nth [ player walk-leftward ] when
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    key-d keys nth [ player walk-rightward ] when
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    key-q keys nth [ player -1 look-horizontally ] when
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    key-e keys nth [ player 1 look-horizontally ] when
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    key-left-arrow keys nth [ player -1 look-horizontally ] when
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    key-right-arrow keys nth [ player 1 look-horizontally ] when
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    key-down-arrow keys nth [ player 1 look-vertically ] when
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    key-up-arrow keys nth [ player -1 look-vertically ] when
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    key-space keys nth [ player jump ] when
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-08 17:18:56 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    key-escape keys nth [ world close-window ] when
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    player read-mouse rotate-with-mouse
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    reset-mouse ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: apply-friction ( velocity -- velocity' )
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-13 21:06:13 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    FRICTION v* ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: apply-gravity ( velocity -- velocity' )
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    GRAVITY v+ ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 21:15:55 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: clamp-coords ( coords dim -- coords' )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ { 0 0 } vmax ] dip { 2 2 } v- vmin ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:36:24 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								:: pixel-indices ( coords dim -- indices )
							 | 
						
					
						
							
								
									
										
										
										
											2014-10-13 17:31:04 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    coords vfloor v>integer dim clamp-coords :> floor-coords
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:36:24 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    floor-coords first2 dim first * + :> base-index
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    base-index dim first + :> next-row-index
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    base-index
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    base-index 1 +
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    next-row-index
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    next-row-index 1 + 4array ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								:: terrain-height-at ( segment point -- height )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    segment dim>> :> dim
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    dim point v* :> pixel
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    pixel dup vfloor v- :> pixel-mantissa
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    segment bitmap>> 4 <groups> :> pixels
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    pixel dim pixel-indices :> indices
							 | 
						
					
						
							
								
									
										
										
										
											2014-10-13 17:31:04 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:36:24 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    indices [ pixels nth COMPONENT-SCALE v. 255.0 / ] map
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:43:04 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    first4 pixel-mantissa bilerp ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-16 18:05:44 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: (collide) ( segment location -- location' )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        { 0 2 3 3 } vshuffle terrain-height-at PLAYER-HEIGHT +
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        -1/0. swap -1/0. -1/0. float-4-boa
							 | 
						
					
						
							
								
									
										
										
										
											2010-02-11 13:55:50 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ] keep vmax ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-16 18:05:44 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2010-02-11 13:55:50 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								TYPED:: collide ( world: terrain-world player: player -- )
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-16 18:05:44 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    world terrain-segment>> :> segment
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    player location>> :> location
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    segment location (collide) :> location'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    location location' = not [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        player
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            location' >>location
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            [ BOUNCE v* ] change-velocity
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            drop
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ] when ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-13 21:06:13 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: scaled-velocity ( player -- velocity )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ velocity>> ] [ velocity-modifier>> ] bi v* ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-15 20:36:36 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: save-history ( world player -- )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    clone swap history>> push ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								:: tick-player-reverse ( world player -- )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    player reverse-time>> :> reverse-time
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    world history>> :> history
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    history length 0 > [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        history length reverse-time 1 - - 1 max history set-length
							 | 
						
					
						
							
								
									
										
										
										
											2010-05-05 16:52:54 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        history pop world player<<
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-15 20:36:36 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ] when ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: tick-player-forward ( world player -- )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    2dup save-history
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ apply-friction apply-gravity ] change-velocity
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-16 18:05:44 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    dup scaled-velocity [ v+ ] curry change-location
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    collide ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-15 20:36:36 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: tick-player ( world player -- )
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    dup reverse-time>>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ tick-player-reverse ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ tick-player-forward ] if ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-15 20:36:36 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2010-01-19 18:02:47 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								M: terrain-world tick-game-world
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-09 12:15:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ dup focused?>> [ handle-input ] [ drop ] if ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ dup player>> tick-player ] bi ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-10 14:45:58 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: set-texture-parameters ( texture -- )
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    GL_TEXTURE_2D GL_TEXTURE0 bind-texture-unit
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    GL_TEXTURE_2D GL_TEXTURE_MIN_FILTER GL_LINEAR glTexParameteri
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    GL_TEXTURE_2D GL_TEXTURE_MAG_FILTER GL_LINEAR glTexParameteri
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-08 14:00:34 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    GL_TEXTURE_2D GL_TEXTURE_WRAP_S GL_CLAMP_TO_EDGE glTexParameteri
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    GL_TEXTURE_2D GL_TEXTURE_WRAP_T GL_CLAMP_TO_EDGE glTexParameteri ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-10 14:45:58 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: sky-gradient ( world -- t )
							 | 
						
					
						
							
								
									
										
										
										
											2010-06-08 19:08:43 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    game-loop>> tick#>> SKY-PERIOD mod SKY-PERIOD /f ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-10 14:45:58 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: sky-theta ( world -- theta )
							 | 
						
					
						
							
								
									
										
										
										
											2010-06-08 19:08:43 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    game-loop>> tick#>> SKY-SPEED * ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-10 14:45:58 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2010-01-17 02:06:54 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								M: terrain-world begin-game-world
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    "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
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-15 20:36:36 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    <player> >>player
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    V{ } clone >>history
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    <perlin-noise-table> 0.01 float-4-with scale-matrix4 { 512 512 } perlin-noise-image
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-10 14:45:58 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ >>sky-image ] keep
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    make-texture [ set-texture-parameters ] keep >>sky-texture
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    <terrain> [ >>terrain ] keep
							 | 
						
					
						
							
								
									
										
										
										
											2009-10-15 23:37:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    float-4{ 0.0 0.0 0.0 1.0 } terrain-segment [ >>terrain-segment ] keep
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-10 14:45:58 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    make-texture [ set-texture-parameters ] keep >>terrain-texture
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    sky-vertex-shader sky-pixel-shader <simple-gl-program>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    >>sky-program
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    terrain-vertex-shader terrain-pixel-shader <simple-gl-program>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    >>terrain-program
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-18 11:31:05 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    terrain-vertex-size <grid-mesh> >>terrain-mesh
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    drop ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2010-01-17 02:06:54 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								M: terrain-world end-game-world
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    {
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-18 11:31:05 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        [ terrain-mesh>> dispose ]
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ terrain-program>> delete-gl-program ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ terrain-texture>> delete-texture ]
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-10 14:45:58 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        [ sky-program>> delete-gl-program ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ sky-texture>> delete-texture ]
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } cleave ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								M: terrain-world resize-world
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    GL_PROJECTION glMatrixMode
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    glLoadIdentity
							 | 
						
					
						
							
								
									
										
										
										
											2012-11-01 20:12:13 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    dim>> [ [ { 0 0 } ] dip gl-viewport ]
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ frustum glFrustum ] bi ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								M: terrain-world draw-world*
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-10 14:45:58 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ set-modelview-matrix ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ terrain-texture>> GL_TEXTURE_2D GL_TEXTURE0 bind-texture-unit ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ sky-texture>> GL_TEXTURE_2D GL_TEXTURE1 bind-texture-unit ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ GL_DEPTH_TEST glDisable dup sky-program>> [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            [ nip "sky" glGetUniformLocation 1 glUniform1i ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            [ "sky_gradient" glGetUniformLocation swap sky-gradient glUniform1f ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            [ "sky_theta" glGetUniformLocation swap sky-theta glUniform1f ] 2tri
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            { -1.0 -1.0 } { 2.0 2.0 } gl-fill-rect
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ] with-gl-program ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ GL_DEPTH_TEST glEnable dup terrain-program>> [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            [ "heightmap" glGetUniformLocation 0 glUniform1i ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            [ "component_scale" glGetUniformLocation COMPONENT-SCALE first4 glUniform4f ] bi
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-18 11:31:05 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            terrain-mesh>> draw-grid-mesh
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-10 14:45:58 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        ] with-gl-program ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } cleave gl-error ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:53:56 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2010-01-16 15:18:50 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								GAME: terrain-game {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        { world-class terrain-world }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        { title "Terrain" }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        { pixel-format-attributes {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            windowed
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            double-buffered
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            T{ depth-bits { value 24 } }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } }
							 | 
						
					
						
							
								
									
										
										
										
											2010-01-19 18:02:47 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        { use-game-input? t }
							 | 
						
					
						
							
								
									
										
										
										
											2010-01-16 15:18:50 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        { grab-input? t }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        { pref-dim { 1024 768 } }
							 | 
						
					
						
							
								
									
										
										
										
											2010-05-22 00:50:42 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        { tick-interval-nanos $[ 60 fps ] }
							 | 
						
					
						
							
								
									
										
										
										
											2010-01-16 16:13:13 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } ;
							 |