code wiki / (root) / nx_game_engine_lib.nx

nx_game_engine_lib.nx

buildroot/runtime/nx_game_engine_lib.nx

14842 B432 linesdepth 2pulls 2 transitivereach 15 importersview sourcekind librarytopic game
docsdependenciesstructsconstsfunctions

about

nx_game_engine_lib.nx -- the GENERIC Nishi dungeon-crawler ENGINE (reusable library). This is the "engine" half of autonomous game-gen: it is written ONCE and reused by every generated game. All per-game variation (title, difficulty, enemy/loot counts, damage model, and the COMBAT FSM transition table) arrives at runtime in a config array -- nothing is hardcoded. A generated per-game module just fills the config + FSM table and calls eng_run(cfg); the emitter (nx_game_emit) writes that tiny module from a data game-spec. Built native by Nishi's own toolchain (nx_cc->nxasm_x86). Combat is fully DATA-DRIVEN: g_fsm_step reads the supplied transition table (the STATE_MACHINE shape generalized to runtime data). The combat EVENT CONVENTION the spec's table must follow (same as the emitter-authored _pe_dungenc): states 0=START 1=PLAYER_TURN 2=ENEMY_TURN 3=WIN 4=FLEE 5=END events 0=enter 1=attack 2=enemy_act 3=defeat 4=flee 5=resolve HONEST AUTHORSHIP: this engine library + the emitter are TUTOR-authored tooling (Claude). The GAMES the emitter produces from specs are emitter-authored output = the autonomy lever (feed specs -> games hands-off). The combat FSM tables come from the team's STATE_MACHINE specs. license_tier: ORIGINAL state st[]: 0=px 1=py 2=hp 3=score 4=level 5=mode 6=fsm 7=enemy_hp 8=rng 9=foes 10=msg 11=enemy_x 12=enemy_y | config: 13=walls 14=enemy_base 15=enemy_per_lvl 16=ehp_base 17=ehp_per_lvl 18=loot 19=dmg_base 20=dmg_rand 21=title_ptr 22=fsm_table_ptr 23=fsm_nstates 24=fsm_nevents | world grid 16x12 bytes at st+256

dependencies 1 imports · 10 importers

nx_syscalls.nx nx_game_engine_lib.nx _game_abyss.nx _game_caves.nx _game_crypt.nx _game_forest.nx _game_temple.nx _game_vault.nx nx_m2d_engine.nx nx_tactics_engine_lib.nx nx_tactics_native.nx nx_voxel_native.nx

imports: nx_syscalls.nx

imported by: _game_abyss.nx_game_caves.nx_game_crypt.nx_game_forest.nx_game_temple.nx_game_vault.nxnx_m2d_engine.nxnx_tactics_engine_lib.nxnx_tactics_native.nxnx_voxel_native.nx

structs

none

consts

26const K_MAGIC_1103515245: i64 = 1103515245
27const K_MAGIC_12345: i64 = 12345
28const K_MAGIC_32767: i64 = 32767
29const K_MAGIC_8192: i64 = 8192
30const K_MAGIC_16384: i64 = 16384

functions

32func g_rng(st: *i64) -> i64
38func g_cell_get(st: *i64, x: i64, y: i64) -> i64
46func g_cell_set(st: *i64, x: i64, y: i64, v: i64) -> i64
52func g_fsm_step(st: *i64, s: i64, e: i64) -> i64
62func g_place(st: *i64, kind: i64, n: i64) -> i64
77func g_build_level(st: *i64) -> i64
114func gi_init(st: *i64, seed: i64) -> i64
called by 2: gi_inputeng_run calls 1: g_build_level
126func gi_next(st: *i64) -> i64
called by 1: gi_input calls 1: g_build_level
134func g_try_move(st: *i64, dx: i64, dy: i64) -> i64
154func g_attack(st: *i64) -> i64
called by 1: gi_input calls 3: g_rngg_fsm_stepg_cell_set
176func g_flee(st: *i64) -> i64
called by 1: gi_input calls 1: g_fsm_step
185func gi_input(st: *i64, key: i64) -> i64
210func bputc(buf: *u8, off: *i64, c: i64) -> i64 { buf[off[0]] = c as u8; off[0] = off[0] + 1; return 0 }
211func bput(buf: *u8, off: *i64, s: *u8) -> i64
217func bputn(buf: *u8, off: *i64, v: i64) -> i64
228func bput_bg(buf: *u8, off: *i64, r: i64, g: i64, b: i64) -> i64
235func bput_fg(buf: *u8, off: *i64, r: i64, g: i64, b: i64) -> i64
242func bput_reset(buf: *u8, off: *i64) -> i64 { bputc(buf, off, 27); bput(buf, off, "[0m" as *u8); return 0 }
243func bput_clear(buf: *u8, off: *i64) -> i64
246func draw_cell(buf: *u8, off: *i64, d: i64) -> i64
257func render_hud(buf: *u8, off: *i64, st: *i64) -> i64
called by 1: eng_render calls 3: bputbputnbputc
267func render_grid(buf: *u8, off: *i64, st: *i64) -> i64
289func render_bar(buf: *u8, off: *i64, val: i64, max: i64, r: i64, g: i64) -> i64
300func render_combat(buf: *u8, off: *i64, st: *i64) -> i64
called by 1: eng_render calls 3: bputcbputrender_bar
312func render_foot(buf: *u8, off: *i64, st: *i64) -> i64
called by 1: eng_render calls 2: bputcbput
322func eng_render(buf: *u8, st: *i64) -> i64
332func map_key(c: i64) -> i64
called by 1: eng_run
344func term_raw_on(orig: *u8, raw: *u8) -> i64
called by 4: eng_runteng_runmainmain calls 1: sys_ioctl
358func term_raw_off(orig: *u8) -> i64 { sys_ioctl(0, 0x5402, orig as i64); return 0 }
called by 4: eng_runteng_runmainmain calls 1: sys_ioctl
364func eng_load_best(st: *i64) -> i64
called by 1: eng_run calls 2: sys_mmapsys_read_file
385func eng_save_best(st: *i64) -> i64
400func eng_run(cfg: *i64) -> i64