nx_day_night_cycle.nx
buildroot/runtime/nx_day_night_cycle.nx
about
nx_day_night_cycle.nx -- diurnal lighting + sun position model.
Per honest gap roadmap 2026-05-16: world needs a day/night loop so
gameplay has dawn/dusk dramatic moments, hostile mobs spawn at
night, and atmosphere primitives have meaningful sun position to
drive sky color.
MODEL:
- 1 game day = N ticks (caller-configurable; default 24000 ticks
for Minecraft-compatible 20 minutes at 20 tps).
- Sub-phases:
* DAWN ticks [0, day/8) sun rising; sky reddening
* MORNING ticks [day/8, day*3/8) sun climbing
* NOON ticks [day*3/8, day*5/8) sun overhead
* AFTERNOON ticks [day*5/8, day*7/8) sun descending
* DUSK ticks [day*7/8, day*9/16) sun setting; sky reddening
* NIGHT ticks [day*9/16, day) moon up; hostile spawn enabled
(Actually for simplicity: day_frac in [0, Q]; mid-day = Q/2;
midnight = 0 / Q. Sub-phases inferred from day_frac.)
PUBLIC APIs:
nx_day_frac_q14(tick, ticks_per_day) -> Q14 [0, Q]
nx_sun_zenith_q14(day_frac) -> Q14 (0 = overhead, Q = horizon)
nx_ambient_light_q14(day_frac) -> Q14 [0, Q]
nx_phase(day_frac) -> NX_PHASE_*
nx_is_night(day_frac) -> 0/1
genealogy_id: solar_day_canon + minecraft_day_night
lineage_id: nx_day_night_cycle_q14_v1
dependencies 2 imports · 0 importers
imports: nx_syscalls.nxnx_tier.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 39 | const NX_MAGIC_24000: i64 = 24000 |
| 40 | const NX_MAGIC_12000: i64 = 12000 |
| 41 | const NX_MAGIC_48000: i64 = 48000 |
| 43 | const NX_DN_Q: nx_int = 16384 |
| 46 | const NX_PHASE_DAWN: nx_int = 0 |
| 47 | const NX_PHASE_MORNING: nx_int = 1 |
| 48 | const NX_PHASE_NOON: nx_int = 2 |
| 49 | const NX_PHASE_AFTERNOON: nx_int = 3 |
| 50 | const NX_PHASE_DUSK: nx_int = 4 |
| 51 | const NX_PHASE_NIGHT: nx_int = 5 |
| 52 | const NX_PHASE_COUNT: nx_int = 6 |
| 61 | const NX_DN_DEFAULT_TICKS_PER_DAY: nx_int = 24000 |
functions
| 54 | func nx_phase_is_valid(p: nx_int) -> nx_int called by 1: main |
| 66 | func nx_day_frac_q14(tick: nx_int, ticks_per_day: nx_int) -> nx_int called by 1: main |
| 83 | func nx_phase(day_frac_q14: nx_int) -> nx_int |
| 95 | func nx_is_night(day_frac_q14: nx_int) -> nx_int |
| 112 | func nx_sun_zenith_q14(day_frac_q14: nx_int) -> nx_int |
| 135 | func nx_ambient_light_q14(day_frac_q14: nx_int) -> nx_int |
| 147 | func main() -> i64 |