code wiki / (root) / nx_voxel_world.nx

nx_voxel_world.nx

buildroot/runtime/nx_voxel_world.nx

14921 B365 linesdepth 2pulls 3 transitivereach 7 importersview sourcekind librarytopic voxel
docsdependenciesstructsconstsfunctions

about

nx_voxel_world.nx -- PARAMETERIZED sovereign 3D-world renderer: a game-SPEC (DATA) -> a rendered world. Style is a spec field, NOT a hardcode -- the engine is not locked to one look: SP_STYLE 0=realism (textured, smooth light), 1=toon (banded light + silhouette outline = anime/cel), 2=flat (untextured facets = artsy low-poly). Geometry here is voxel terrain, but the rasterizer (fill_ztex) draws arbitrary textured triangles, so other geometry (meshes/characters) plugs into the same path. Composes nx_f32_hw. license_tier: ORIGINAL

dependencies 2 imports · 7 importers

nx_syscalls.nx nx_f32_hw.nx nx_voxel_world.nx nx_anim_gate.nx nx_entity_gate.nx nx_fpsworld_gate.nx nx_game_loop_gate.nx nx_voxel_spec_gate.nx nx_world_png_gate.nx nx_world_style_gate.nx

imports: nx_syscalls.nxnx_f32_hw.nx

imported by: nx_anim_gate.nxnx_entity_gate.nxnx_fpsworld_gate.nxnx_game_loop_gate.nxnx_voxel_spec_gate.nxnx_world_png_gate.nxnx_world_style_gate.nx

structs

none

consts

8const SP_MAGIC_65536: i64 = 65536
10const W: i64 = 320
11const H: i64 = 240
12const HW: i64 = 160
13const HH: i64 = 120
14const TN: i64 = 4
15const ZFAR: i64 = 1073741824
16const SP_SEED: i64 = 0
17const SP_N: i64 = 1
18const SP_WATER: i64 = 2
19const SP_MAXH: i64 = 3
20const SP_LAT: i64 = 4
21const SP_PSIN: i64 = 5
22const SP_PCOS: i64 = 6
23const SP_YSIN: i64 = 7
24const SP_YCOS: i64 = 8
25const SP_PUSH: i64 = 9
26const SP_FOCAL: i64 = 10
27const SP_STYLE: i64 = 11
28const SP_CAMX: i64 = 12 // first-person camera position (f32 bit-patterns)
29const SP_CAMY: i64 = 13
30const SP_CAMZ: i64 = 14
31const SP_FPS: i64 = 15 // 1 = first-person (subtract cam pos, no push); 0 = orbit (default)
32const STYLE_REAL: i64 = 0
33const STYLE_TOON: i64 = 1
34const STYLE_FLAT: i64 = 2

functions

36func world_pixels() -> i64 { return W * H }
37func world_fb_bytes() -> i64 { return W * H * 8 }
38func world_sky() -> i64 { return 142 + 186 * 256 + 228 * SP_MAGIC_65536 }
40func imin(a: i64, b: i64) -> i64 { if a < b { return a } return b }
called by 2: min3fill_ztex
41func imax(a: i64, b: i64) -> i64 { if a > b { return a } return b }
called by 2: max3fill_ztex
42func iabs(a: i64) -> i64 { if a < 0 { return 0 - a } return a }
called by 1: outline_pass
43func min3(a: i64, b: i64, c: i64) -> i64 { return imin(a, imin(b, c)) }
called by 1: fill_ztex calls 1: imin
44func max3(a: i64, b: i64, c: i64) -> i64 { return imax(a, imax(b, c)) }
called by 1: fill_ztex calls 1: imax
45func clamp255(v: i64) -> i64 { if v < 0 { return 0 } if v > 255 { return 255 } return v }
46func same_sign3(a: i64, b: i64, c: i64) -> i64
called by 1: fill_ztex
51func fratio(num: i64, den: i64) -> i64 { return f32_div(f32_of(num), f32_of(den)) }
called by 2: projectbuild_cam calls 2: f32_divf32_of
53func lat(ix: i64, iz: i64, seed: i64) -> i64
called by 1: terrain_h
58func terrain_h(sp: *i64, gx: i64, gz: i64) -> i64
78func hN(sp: *i64, gx: i64, gz: i64) -> i64
called by 1: draw_col calls 1: terrain_h
85func top_color(sp: *i64, h: i64) -> i64
called by 1: draw_col
91func side_color(sp: *i64, h: i64) -> i64
called by 1: draw_col
97func texel_col(style: i64, baseR: i64, baseG: i64, baseB: i64, u: i64, v: i64, bright: i64) -> i64
called by 1: fill_ztex calls 1: clamp255
106func toon_band(b: i64) -> i64
called by 1: draw_face
110func fill_ztex(fb: *i64, zb: *i64, t: *i64, br: i64, bg: i64, bb: i64, bright: i64, style: i64) -> i64
143func project(sp: *i64, R: *i64, iwx: i64, iwy: i64, iwz: i64, out: *i64) -> i64
168func shade_local(lnx: i64, lny: i64, lnz: i64) -> i64
called by 1: draw_face calls 1: clamp255
173func draw_face(fb: *i64, zb: *i64, sx: *i64, sy: *i64, sd: *i64, sok: *i64,
195func draw_col(sp: *i64, fb: *i64, zb: *i64, R: *i64, gx: i64, gz: i64) -> i64
222func draw_obox(sp: *i64, fb: *i64, zb: *i64, R: *i64, x0: i64, y0: i64, z0: i64, hx: i64, hy: i64, hz: i64, col: i64, style: i64) -> i64
245func has_tree(sp: *i64, gx: i64, gz: i64) -> i64
called by 1: render_world calls 1: terrain_h
254func draw_tree(sp: *i64, fb: *i64, zb: *i64, R: *i64, gx: i64, gz: i64, style: i64) -> i64
called by 1: render_world calls 2: terrain_hdraw_obox
261func outline_pass(fb: *i64, zb: *i64) -> i64
called by 1: render_world calls 1: iabs
286func put_u32le(b: *u8, o: i64, v: i64) -> i64
called by 1: write_bmp
293func write_bmp(fb: *i64, path: *u8) -> i64
329func build_cam(sp: *i64, R: *i64) -> i64
338func world_project(sp: *i64, R: *i64, iwx: i64, iwy: i64, iwz: i64, out: *i64) -> i64 { return project(sp, R, iwx, iwy, iwz, out) }
calls 1: project
339func world_height(sp: *i64, gx: i64, gz: i64) -> i64 { return terrain_h(sp, gx, gz) }
called by 3: mainmainmain calls 1: terrain_h
340func world_obox(sp: *i64, fb: *i64, zb: *i64, R: *i64, x0: i64, y0: i64, z0: i64, hx: i64, hy: i64, hz: i64, col: i64, style: i64) -> i64
called by 2: mainmain calls 1: draw_obox
343func render_world(sp: *i64, fb: *i64, zb: *i64) -> i64