code wiki / (root) / nx_imported_body_craft_gate_t262.nx

nx_imported_body_craft_gate_t262.nx source

↩ module page · 68 lines · 6588 B

1// nx_imported_body_craft_gate_t137.nx -- Validates imported body memory layout and interaction behavior in the Nishi ecosystem. 2import "_hdl_build/nx_wasm_craft_imported_t262.nx" 3import "nx_nxa_bind.nx" 4static bc_checks:i64=0 5static bc_failures:i64=0 6func bc_check(ok:i64,label:*u8)->i64{bc_checks=bc_checks+1;if ok==1{nb_text("PASS " as *u8)}else{bc_failures=bc_failures+1;nb_text("FAIL " as *u8)};nb_text(label);nb_text("\n" as *u8);return 0} 7func main()->i64{ 8 let mem:*u8=sys_mmap(CRAFT_EXT_TOTAL+128);let base:i64=mem as i64 9 bc_check(O_WCM==CRAFT_EXT_TOTAL&&O_IMPORTED_BODY==CRAFT_BYTES&&O_IMPORTED_BODY>=O_SAVE+SAVE_LEN&&O_BODY_AFFINE_SCRATCH+LA_STATIC_SCRATCH_WORDS*8==O_WCM,"morph arena starts after fixed body and affine storage" as *u8) 10 let fence:*i64=(base+CRAFT_EXT_TOTAL) as *i64;fence[0]=773311;var guard:i64=1;while guard<16{fence[guard]=773311+guard;guard=guard+1} 11 bc_check(wc_body_init(base,2,CRAFT_EXT_TOTAL-1)==IBR_CAPACITY,"arena boundary refuses undersized memory" as *u8) 12 bc_check(wc_body_init(base,IMPORTED_BODY_CAP+1,CRAFT_EXT_TOTAL)==IBR_CAPACITY,"runtime capacity refuses reserved overflow" as *u8) 13 bc_check(wc_body_init(base,2,CRAFT_EXT_TOTAL)==0,"explicit imported registry init" as *u8) 14 bc_check(wc_player_sweep(base,0,EYE,1024,0,2000)==2000,"empty imported registry preserves actual player sweep" as *u8) 15 bc_check(wc_body_init(base,3,CRAFT_EXT_TOTAL)==IBR_CONFLICT,"existing registry capacity cannot be silently changed" as *u8) 16 let record:*i64=(base+O_IMPORTED_STAGE) as *i64 17 record[IBR_ID_HI]=7;record[IBR_ID_LO]=111;record[IBR_REV]=1;record[IBR_SHAPE_REV]=1;record[IBR_POSE_REV]=1 18 record[IBR_WORLD_X]=1000;record[IBR_WORLD_Y]=0;record[IBR_WORLD_Z]=1024 19 record[IBR_MIN_X]=0-100;record[IBR_MIN_Y]=0;record[IBR_MIN_Z]=0-100 20 record[IBR_MAX_X]=100;record[IBR_MAX_Y]=500;record[IBR_MAX_Z]=100 21 record[IBR_LAYER]=4;record[IBR_MASK]=BODY_LAYER_PLAYER|BODY_LAYER_NPC;record[IBR_ENABLED]=1;record[IBR_KIND]=1 22 let handle:i64=wc_body_bind(base) 23 bc_check(handle>0&&wc_body_bind(base)==handle,"native staging bind is idempotent" as *u8) 24 let state:*i64=wst(base);state[S_CX]=0;state[S_CY]=EYE;state[S_CZ]=1024 25 bc_check(wc_player_axis_apply(base,0,2000,0)==900&&state[S_CX]==900,"actual player movement stops at imported body" as *u8) 26 bc_check(wc_contact_result(base).delta_q8==900&&wc_contact_result(base).hit_material==0,"imported contact delta and non-voxel material attribution agree" as *u8) 27 bc_check(wc_contact_state(base)[1]==1,"existing player collision audit sees imported contact" as *u8) 28 bc_check(wc_body_mob_axis(base,0,0,1024,0,2000)==900-MOB_R_Q8,"resident NPC movement clips against imported body" as *u8) 29 bc_check(wc_body_mob_axis(base,0,600,1024,0,2000)==2000,"NPC on another altitude remains free" as *u8) 30 state[S_CX]=0-4096;state[S_WOX]=16 31 bc_check(wc_player_axis_apply(base,0,2000,0)==900&&state[S_CX]==900-4096,"player owner uses same absolute body after origin shift" as *u8) 32 bc_check(ibr_find(wc_body_arena(base),7,111)==handle,"body identity survives origin and render-independent movement" as *u8) 33 state[S_CX]=1000-4096 34 bc_check(wc_player_axis_apply(base,0,100,0)==0&&state[S_CX]==1000-4096&&wc_contact_result(base).initial_overlap==1,"embedded player reports overlap without arbitrary teleport" as *u8) 35 let hit:*ImportedBodyHit=(base+O_IMPORTED_HIT) as *ImportedBodyHit 36 bc_check(wc_player_sweep(base,0-4096,EYE,0,0,0)==0&&hit.initial_overlap==0&&hit.hit_handle==0&&wc_contact_result(base).initial_overlap==0,"zero displacement outside bodies clears prior overlap evidence" as *u8) 37 record[IBR_REV]=2;record[IBR_ENABLED]=0 38 bc_check(wc_body_bind(base)==handle,"explicit policy disables same physical handle" as *u8) 39 state[S_CX]=0-4096 40 bc_check(wc_player_axis_apply(base,0,2000,0)==2000,"disabled body restores passage without deleting identity" as *u8) 41 bc_check(hit.initial_overlap==0&&hit.hit_handle==0&&hit.tested==0,"disabled cohort does not retain prior hit identity" as *u8) 42 record[IBR_REV]=3;record[IBR_ENABLED]=1;record[IBR_MIN_X]=0-101 43 bc_check(wc_body_bind(base)==IBR_CONFLICT,"changed geometry refuses unchanged shape revision" as *u8) 44 record[IBR_SHAPE_REV]=2 45 bc_check(wc_body_bind(base)==handle,"new shape revision updates existing identity" as *u8) 46 var intact:i64=1;guard=0;while guard<16{if fence[guard]!=773311+guard{intact=0};guard=guard+1} 47 bc_check(intact==1,"body operations preserve first sixteen dynamic morph words" as *u8) 48 bc_check(fence[0]==773311,"fixed imported body region preserves end canary" as *u8) 49 let entities:*i64=ibr_entities(wc_body_arena(base)) 50 let revision_before:i64=en_get(entities,handle,IBR_REV) 51 bc_check(init_impl_v(base,0,CRAFT_DEFAULT_SEED)==0,"actual world initialization succeeds with existing registry" as *u8) 52 bc_check(ibr_find(wc_body_arena(base),7,111)==handle&&en_get(entities,handle,IBR_ENABLED)==0&&en_get(entities,handle,IBR_REV)==revision_before+1,"world initialization suspends contact while retaining identity" as *u8) 53 record[IBR_REV]=revision_before+2 54 bc_check(wc_body_bind(base)==handle,"explicit current-world bind restores suspended body" as *u8) 55 let saved:i64=wc_save_build(base);let savehead:*i64=(base+O_SAVE) as *i64;let checksum:i64=savehead[11] 56 bc_check(saved==SAVE_LEN&&savehead[1]==SAVE_VER,"existing current version save contract is unchanged" as *u8) 57 bc_check(wc_save_apply_bytes(base,SAVE_LEN-1)==SAVE_RC_LENGTH&&en_get(entities,handle,IBR_ENABLED)==1,"refused truncated save does not suspend current contact" as *u8) 58 bc_check(wc_save_apply_bytes(base,SAVE_LEN)==0&&en_get(entities,handle,IBR_ENABLED)==0,"successful current version load requires explicit body rebind" as *u8) 59 bc_check(ibr_find(wc_body_arena(base),7,111)==handle&&wc_save_ck(base)==checksum,"runtime body state is not falsely serialized by legacy save" as *u8) 60 record[IBR_REV]=en_get(entities,handle,IBR_REV)+1 61 bc_check(wc_body_bind(base)==handle,"body rebind after save retains placed-instance handle" as *u8) 62 savehead[1]=SAVE_VER5;savehead[11]=wc_save_ck_v5(base) 63 bc_check(wc_save_apply_bytes(base,SAVE_HDR+SAVE_BODY_V5)==0&&en_get(entities,handle,IBR_ENABLED)==0,"accepted version five load also suspends unpersisted bodies" as *u8) 64 intact=1;guard=0;while guard<16{if fence[guard]!=773311+guard{intact=0};guard=guard+1} 65 bc_check(intact==1,"init and both legacy loads preserve dynamic morph storage boundary" as *u8) 66 nb_text("BODY_CRAFT_GATE checks=" as *u8);nb_num(bc_checks);nb_text(" failures=" as *u8);nb_num(bc_failures);nb_text(" actual_wasm=UNQUALIFIED page_bind=UNWIRED save_version=UNWIRED\n" as *u8) 67 if bc_failures!=0{return 3};return 0 68}