code wiki / (root) / nx_fluid.nx

nx_fluid.nx

buildroot/runtime/nx_fluid.nx

8680 B189 linesdepth 2pulls 3 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 2 imports · 1 importers

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

imports: nx_syscalls.nxnx_itrig.nx

imported by: nx_fluid_gate.nx

structs

none

consts

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

functions

22func fl_isqrt(x: i64) -> i64 { if x<=0 {return 0} var a: i64=x; var b: i64=(a+1)/2; while b<a {a=b; b=(a+x/a)/2} return a }
called by 2: fl_frontfl_render
23func fl_iabs(v: i64) -> i64 { if v<0 {return 0-v} return v }
24func 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
26func fl_init() -> i64
called by 1: main calls 1: sys_mmap
38func fl_drop(cx: i64, cy: i64, r: i64, amp: i64) -> i64
called by 1: main
60func fl_step() -> i64
called by 1: main
117func fl_h(x: i64, y: i64) -> i64 { let h: *i64 = FL_H as *i64; return h[y*FL_N+x] }
called by 1: main
118func fl_n() -> i64 { return FL_N }
called by 1: main
120func 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
121func 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
124func 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
126func fl_front(cx: i64, cy: i64, thr: i64) -> i64
called by 1: main calls 2: fl_iabsfl_isqrt
146func fl_render(fb: *i64, W: i64, H: i64, sunx: i64, suny: i64, sunz: i64) -> i64
called by 1: main calls 2: fl_isqrtfl_clampi