sourceextensions/scene/demos/voxels-endless.xtl
1⍝│ Voxels, 6: an endless world. Walk in any direction and it never ends:
2⍝│ the land comes from value noise hashed from the coordinates
3⍝│ (vx:h_eightsAt), so any column of 16 by 16 blocks can be made by
4⍝│ itself and fits its neighbors; columns are made around the player as
5⍝│ it walks -- the nearest missing one each frame -- and dropped behind
6⍝│ it; fog hides the edge of what is made, and a curved horizon (scene
7⍝│ lowers the world by d^2 / 2R) makes it look like a small planet.
8⍝│ Collision asks the columns themselves. The world and the player are
9⍝│ the library Endless.xtl, shared with voxels-fly: each column is made
10⍝│ over three frames, so no frame waits long.
11⍝│ Run: just demo scene voxels-endless
12⍝│ W A S D walk, Shift run, Space jump (in water: swim up; at the
13⍝│ surface: climb out onto a bank one block high), drag the mouse or
14⍝│ the arrows to look, H: back to the start, q or close: quit
15
16"en:" u̲se< "Endless"
17"sc:" u̲se< "Scene"
18
19w ← "Voxels 6: endless -- X_eTaL" ˢᶜo̲pen! 640 400
20g ← w ˢᶜf̲og! 22.0 44.0
21_ ← w ˢᶜs̲ky! 0.55 0.72 0.92
22_ ← w ˢᶜc̲urve! 160.0
23
24"keys: W A S D walk, Shift run, Space jump (in water: swim up, climb out), drag or arrows look, H home, q quit"
25
26⍝│ the world around the start made before the first frame: each column
27⍝│ takes three steps
28s ← ᵉⁿn̲ew w
29streamed ← (3 × (1 + 2 × ᵉⁿreach) × 1 + 2 × ᵉⁿreach) 'ᵉⁿs̲tream p̲ower s
30"columns made at the start:"
31t̲ally ᵉⁿk̲eys streamed
32
33⍝│ one frame: an event, then a third of a column's work, then the
34⍝│ player
35ᵘf̲rame ← { s →
36 ᵉⁿs̲topped s ? s
37 v ← ˢᶜn̲ext! w
38 ((v m̲atch "close") + (v m̲atch "key q") + v m̲atch "key Escape") > 0 ? ᵉⁿs̲top s
39 stepped ← ᵉⁿs̲tream (v m̲atch "key h") ᵘi̲f s
40 stepped ᵉⁿm̲ove ˢᶜc̲ontrols w
41}
42ᵘi̲f ← { yes s →
43 yes ? ᵉⁿh̲omeAgain s
44 s
45}
46last ← 100000 'ᵘf̲rame p̲ower streamed
47z ← ˢᶜc̲lose! w
48"where the walk ended (x y z, blocks), the columns kept:"
49(f̲loat f̲loor 0.5 + ᵉⁿp̲osition last) c̲at f̲loat t̲ally ᵉⁿk̲eys last
50"bye"