nx_game_engine_lib.nx
buildroot/runtime/nx_game_engine_lib.nx
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
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
| 26 | const K_MAGIC_1103515245: i64 = 1103515245 |
| 27 | const K_MAGIC_12345: i64 = 12345 |
| 28 | const K_MAGIC_32767: i64 = 32767 |
| 29 | const K_MAGIC_8192: i64 = 8192 |
| 30 | const K_MAGIC_16384: i64 = 16384 |
functions
| 32 | func g_rng(st: *i64) -> i64 |
| 38 | func g_cell_get(st: *i64, x: i64, y: i64) -> i64 |
| 46 | func g_cell_set(st: *i64, x: i64, y: i64, v: i64) -> i64 |
| 52 | func g_fsm_step(st: *i64, s: i64, e: i64) -> i64 |
| 62 | func g_place(st: *i64, kind: i64, n: i64) -> i64 |
| 77 | func g_build_level(st: *i64) -> i64 |
| 114 | func gi_init(st: *i64, seed: i64) -> i64 |
| 126 | func gi_next(st: *i64) -> i64 |
| 134 | func g_try_move(st: *i64, dx: i64, dy: i64) -> i64 |
| 154 | func g_attack(st: *i64) -> i64 |
| 176 | func g_flee(st: *i64) -> i64 |
| 185 | func gi_input(st: *i64, key: i64) -> i64 |
| 210 | func bputc(buf: *u8, off: *i64, c: i64) -> i64 { buf[off[0]] = c as u8; off[0] = off[0] + 1; return 0 } |
| 211 | func bput(buf: *u8, off: *i64, s: *u8) -> i64 |
| 217 | func bputn(buf: *u8, off: *i64, v: i64) -> i64 |
| 228 | func bput_bg(buf: *u8, off: *i64, r: i64, g: i64, b: i64) -> i64 |
| 235 | func bput_fg(buf: *u8, off: *i64, r: i64, g: i64, b: i64) -> i64 called by 6: draw_cellrender_barmd_ansi_frameteng_draw_celltac_draw_cellvx_render calls 3: bputcbputbputn |
| 242 | func bput_reset(buf: *u8, off: *i64) -> i64 { bputc(buf, off, 27); bput(buf, off, "[0m" as *u8); return 0 } called by 9: draw_cellrender_gridrender_barmd_ansi_frameteng_draw_cellteng_render+3 calls 2: bputcbput |
| 243 | func bput_clear(buf: *u8, off: *i64) -> i64 |
| 246 | func draw_cell(buf: *u8, off: *i64, d: i64) -> i64 |
| 257 | func render_hud(buf: *u8, off: *i64, st: *i64) -> i64 |
| 267 | func render_grid(buf: *u8, off: *i64, st: *i64) -> i64 |
| 289 | func render_bar(buf: *u8, off: *i64, val: i64, max: i64, r: i64, g: i64) -> i64 |
| 300 | func render_combat(buf: *u8, off: *i64, st: *i64) -> i64 |
| 312 | func render_foot(buf: *u8, off: *i64, st: *i64) -> i64 |
| 322 | func eng_render(buf: *u8, st: *i64) -> i64 |
| 332 | func map_key(c: i64) -> i64 called by 1: eng_run |
| 344 | func term_raw_on(orig: *u8, raw: *u8) -> i64 |
| 358 | func term_raw_off(orig: *u8) -> i64 { sys_ioctl(0, 0x5402, orig as i64); return 0 } |
| 364 | func eng_load_best(st: *i64) -> i64 |
| 385 | func eng_save_best(st: *i64) -> i64 |
| 400 | func eng_run(cfg: *i64) -> i64 called by 6: mainmainmainmainmainmain calls 15: sys_mmapterm_raw_ongi_initsys_now_mseng_load_besteng_render+9 |