programextensions/scene/demos/voxels-endless.xtl

Voxels, 6: an endless world. Walk in any direction and it never ends: the land comes from value noise hashed from the coordinates (vx:h_eightsAt), so any column of 16 by 16 blocks can be made by itself and fits its neighbors; columns are made around the player as it walks -- the nearest missing one each frame -- and dropped behind it; fog hides the edge of what is made, and a curved horizon (scene lowers the world by d^2 / 2R) makes it look like a small planet. Collision asks the columns themselves. The world and the player are the library Endless.xtl, shared with voxels-fly: each column is made over three frames, so no frame waits long. Run: just demo scene voxels-endless W A S D walk, Shift run, Space jump (in water: swim up; at the surface: climb out onto a bank one block high), drag the mouse or the arrows to look, H: back to the start, q or close: quit

source · imports en: extensions/scene/demos/Endless.xtl; sc: extensions/scene/lib/Scene.xtl

w : Int

value · line 19
w ← "Voxels 6: endless -- X_eTaL" ˢᶜo̲pen! 640 400
Used in: g, k, s, ᵘf̲rame, z

g : Int

value · line 20
g ← w ˢᶜf̲og! 22.0 44.0

k : Int

value · line 21
k ← w ˢᶜs̲ky! 0.55 0.72 0.92

k : Int

value · line 22
k ← w ˢᶜc̲urve! 160.0

s : Box Float

value · line 28

the world around the start made before the first frame: each column takes three steps

s ← ᵉⁿn̲ew w

s : Box Float

value · line 29
s ← (3 × (1 + 2 × ᵉⁿreach) × 1 + 2 × ᵉⁿreach) 'ᵉⁿs̲tream p̲ower s

ᵘf̲rame : Box Float -> Box Float

function · line 35

one frame: an event, then a third of a column's work, then the player

ᵘf̲rame ← { s →
  ᵉⁿs̲topped s ? s
  v ← ˢᶜn̲ext! w
  ((v m̲atch "close") + (v m̲atch "key q") + v m̲atch "key Escape") > 0 ? ᵉⁿs̲top s
  s ← (v m̲atch "key h") ᵘi̲f s
  s ← ᵉⁿs̲tream s
  s ᵉⁿm̲ove ˢᶜc̲ontrols w
}
Used in: last

ᵘi̲f : Truthy a => a -> Box Float -> Box Float

function · line 43
ᵘi̲f ← { yes s →
  yes ? ᵉⁿh̲omeAgain s
  s
}
Used in: ᵘf̲rame

last : Box Float

value · line 47
last ← 100000 'ᵘf̲rame p̲ower s

z : Int

value · line 48
z ← ˢᶜc̲lose! w