code wiki / (root) / nx_crater_field.nx

nx_crater_field.nx

buildroot/runtime/nx_crater_field.nx

28331 B608 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_crater_field.nx -- deterministic crater-impact field distribution. Cross-cutting Substrate C primitive per nxc2/docs/NISHI_GAME_ENGINE_ROADMAP.md. Generic generator consumed by every airless-body surface (Mercury, the Moon, Mars highlands, Callisto, every asteroid, every comet nucleus). Lives in nishi-core because any astronomical-visualisation program also uses it -- not voxel-specific. FULL CAPABILITY (per feedback-maximum-capability-no-simplification cardinal, 2026-05-16): - Neukum 1983 power-law radius distribution (alpha = 2 default, caller-overridable). Sampled via the exact inverse-CDF transform r = r_min / (1 - u * (1 - r_min/r_max)) which produces N(>D) ~ D^-2 in clean Q14 integer math. - Age-banded saturation density: caller queries nx_crater_saturation_count(age, area, r_avg) to learn how many craters fit the chosen band (YOUNG -> sparse; SATURATION -> densely packed to ~lunar-saturation 1/(2r)^2 limit). - Composite elevation profile per crater: * Inside bowl (d_norm < 0.85): parabolic depression * Rim ring (0.85 <= d_norm < 1.05): elevated rim, peak at d_norm = 0.95, parabolic falloff, +15% of bowl depth * Central peak (d_norm < 0.15 AND r >= transition radius): parabolic uplift, +30% of bowl depth. Lunar transition diameter ~ 15 km (caller-overridable). - Boolean-max (newest crater wins) over overlapping craters via nx_crater_field_elevation_at; original nx_crater_field_depth_at preserved as wrapper for callers that only care about the bowl depth. Determinism: same (seed, area_w, area_h, count) -> byte-equal crater list everywhere. Park-Miller LCG seeded with (seed XOR crater_index XOR field_id) gives well-spread positions. Loss audit (HONEST residuals): - alpha = 2 fixed (Neukum 1983 standard). Real lunar fits alpha in [1.8, 2.1] depending on epoch. Caller can post-process the radius distribution if needed; not a capability reduction since the most-cited literature value ships.

dependencies 3 imports · 0 importers

nx_syscalls.nx nx_hal.nx nx_tier.nx nx_crater_field.nx

imports: nx_syscalls.nxnx_hal.nxnx_tier.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap nx_crater_field_sample nx_crater_age_band_is_vali _crater_age_depth_mult_q14 _crater_hash _crater_mod_q14 _crater_powerlaw_radius_q1 nx_hal_exit nx_hal_active_shim nx_hal_exit_linux nx_hal_exit_bare_metal nx_hal_exit_nishi_silicon nx_crater_field_sample_sim nx_crater_field_sample ↻ nx_crater_field_depth_at nx_crater_age_band_is_vali ↻ nx_crater_saturation_count _crater_age_density_q14 nx_crater_field_elevation_

structs

none

consts

59const NX_MAGIC_4096: i64 = 4096
60const NX_MAGIC_10650: i64 = 10650
61const NX_MAGIC_16384: i64 = 16384
62const NX_MAGIC_12288: i64 = 12288
63const NX_MAGIC_8192: i64 = 8192
64const NX_MAGIC_4915: i64 = 4915
65const NX_MAGIC_2654435761: i64 = 2654435761
66const NX_MAGIC_1597334677: i64 = 1597334677
67const NX_MAGIC_31130: i64 = 31130
68const NX_MAGIC_7777: i64 = 7777
69const NX_MAGIC_8888: i64 = 8888
70const NX_MAGIC_9999: i64 = 9999
73const NX_CRATER_Q: nx_int = 16384
76const NX_CRATER_STRIDE: nx_int = 4
79const NX_CRATER_OFF_X: nx_int = 0
80const NX_CRATER_OFF_Y: nx_int = 1
81const NX_CRATER_OFF_R: nx_int = 2
82const NX_CRATER_OFF_DEPTH: nx_int = 3
88const NX_CRATER_DEPTH_RATIO_Q14: nx_int = 3277 // 0.20
92const NX_CRATER_LCG_A: nx_int = 48271
93const NX_CRATER_LCG_M: nx_int = 2147483647
98const NX_CRATER_BOWL_HALF_Q14: nx_int = 13926 // 0.85 -- bowl extends to 0.85 r
99const NX_CRATER_RIM_PEAK_Q14: nx_int = 15565 // 0.95 -- rim peak at 0.95 r
100const NX_CRATER_OUTER_Q14: nx_int = 17204 // 1.05 -- profile ends at 1.05 r
101const NX_CRATER_RIM_HALFW_Q14: nx_int = 1638 // 0.10 -- rim falloff half-width
102const NX_CRATER_RIM_HEIGHT_FRAC: nx_int = 2458 // 0.15 of bowl depth -> rim height
103const NX_CRATER_CENTRAL_RAD_Q14: nx_int = 2458 // 0.15 -- central peak radius (relative)
104const NX_CRATER_CENTRAL_HEIGHT: nx_int = 4915 // 0.30 of bowl depth -> central peak
110const NX_CRATER_TRANSITION_R_Q14: nx_int = 245760 // 15.0 in Q14
114const NX_CRATER_AGE_YOUNG: nx_int = 0 // post-impact (lunar maria, post-Imbrium)
115const NX_CRATER_AGE_MID: nx_int = 1 // moderate density (lunar uplands)
116const NX_CRATER_AGE_OLD: nx_int = 2 // high density (Mercury cratered terrain)
117const NX_CRATER_AGE_SATURATION: nx_int = 3 // maximally cratered (asteroids, oldest plateaus)

functions

119func nx_crater_age_band_is_valid(b: nx_int) -> nx_int
130func _crater_age_density_q14(age: nx_int) -> nx_int
140func _crater_age_depth_mult_q14(age: nx_int) -> nx_int
159func nx_crater_saturation_count(
called by 1: main calls 1: _crater_age_density_q14
186func _crater_hash(seed: nx_int, index: nx_int, axis: nx_int) -> nx_int
196func _crater_mod_q14(hash_v: nx_int, span_q14: nx_int) -> nx_int
210func _crater_powerlaw_radius_q14(
252func nx_crater_field_sample(
303func nx_crater_field_sample_simple(
called by 1: main calls 1: nx_crater_field_sample
342func nx_crater_field_elevation_at(
called by 1: main
431func nx_crater_field_depth_at(
called by 1: main
460func main() -> i64