code wiki / (root) / nx_fluid.nx

nx_fluid.nx

buildroot/runtime/nx_fluid.nx

8631 B190 linesdepth 2pulls 4 transitivereach 1 importersview sourcekind librarytopic fluid
docsdependenciesstructsconstsfunctions

about

nx_fluid.nx -- ★R6 of the Infinigen ladder: FLUID SIMULATION (their FLIP-fluids axis). A height-field WAVE simulation (the shallow-water / wave-equation grid -- the standard real-time water technique; FLIP is the particle variant). Real physics, all integer: a height grid h + velocity grid v integrated by the discrete wave equation v += c^2*dt * laplacian(h) ; v *= damp ; h += v , with REFLECTING boundaries so VOLUME is exactly conserved (sum(laplacian)=0 => sum(v) stays 0 => sum(h) constant). Disturbances propagate outward at finite speed, reflect off shores, and damp -- not a flat plane. license_tier: ORIGINAL

dependencies 3 imports · 1 importers

nx_syscalls.nx nx_itrig.nx nx_vecmath.nx nx_fluid.nx nx_fluid_gate.nx

imports: nx_syscalls.nxnx_itrig.nxnx_vecmath.nx

imported by: nx_fluid_gate.nx

structs

none

consts

10const FL_MAGIC_1024: i64 = 1024
11const FL_MAGIC_1048576: i64 = 1048576
12const FL_MAGIC_9973: i64 = 9973
13const FL_MAGIC_4096: i64 = 4096
14const FL_MAGIC_65536: i64 = 65536
16const FL_N: i64 = 168 // grid cells per axis
17const FL_K: i64 = 100 // c^2*dt (fx1024) -- CFL-stable (4*K/1024 = 0.39, well under the 2D limit)
18const FL_DAMP: i64 = 1013 // velocity damping per step (~0.989) -- removes energy, keeps sum(v)=0

functions

23func fl_isqrt(x: i64) -> i64 { return vm_isqrt(x) }
called by 2: fl_frontfl_render calls 1: vm_isqrt
24func fl_iabs(v: i64) -> i64 { if v<0 {return 0-v} return v }
25func fl_clampi(v: i64, lo: i64, hi: i64) -> i64 { if v<lo {return lo} if v>hi {return hi} return v }
called by 1: fl_render
27func fl_init() -> i64
called by 1: main calls 1: sys_mmap
39func fl_drop(cx: i64, cy: i64, r: i64, amp: i64) -> i64
called by 1: main
61func fl_step() -> i64
called by 1: main
118func fl_h(x: i64, y: i64) -> i64 { let h: *i64 = FL_H as *i64; return h[y*FL_N+x] }
called by 1: main
119func fl_n() -> i64 { return FL_N }
called by 1: main
121func fl_volume() -> i64 { let h: *i64 = FL_H as *i64; var s: i64=0; var i: i64=0; while i<FL_N*FL_N { s=s+h[i]; i=i+1 } return s }
called by 1: main
122func fl_energy() -> i64 { let h: *i64 = FL_H as *i64; var s: i64=0; var i: i64=0; while i<FL_N*FL_N { s=s+fl_iabs(h[i]); i=i+1 } return s }
calls 1: fl_iabs
125func fl_maxabs() -> i64 { let h: *i64 = FL_H as *i64; var m: i64=0; var i: i64=0; while i<FL_N*FL_N { let a: i64=fl_iabs(h[i]); if a>m {m=a} i=i+1 } return m }
called by 1: main calls 1: fl_iabs
127func fl_front(cx: i64, cy: i64, thr: i64) -> i64
called by 1: main calls 2: fl_iabsfl_isqrt
147func fl_render(fb: *i64, W: i64, H: i64, sunx: i64, suny: i64, sunz: i64) -> i64
called by 1: main calls 2: fl_isqrtfl_clampi