code wiki / (root) / nx_imported_body_registry_gate_t43.nx

nx_imported_body_registry_gate_t43.nx source

↩ module page · 83 lines · 7597 B

1// nx_imported_body_registry_gate_t43.nx -- Tests the bounded registry's upsert behavior under various revision and shape modification scenarios. 2import "nx_imported_body_registry_t40.nx" 3import "nx_nxa_bind.nx" 4static checks:i64=0 5static failures:i64=0 6func bg_check(ok:i64,label:*u8)->i64{checks=checks+1;if ok==1{nb_text("PASS " as *u8)}else{nb_text("FAIL " as *u8);failures=failures+1};nb_text(label);nb_text("\n" as *u8);return 0} 7func bg_box(b:*BeachContactBox,x0:i64,y0:i64,z0:i64,x1:i64,y1:i64,z1:i64)->i64{b.min_x=x0;b.min_y=y0;b.min_z=z0;b.max_x=x1;b.max_y=y1;b.max_z=z1;return 0} 8func bg_same(a:*i64,b:*i64,n:i64)->i64{var i:i64=0;while i<n{if a[i]!=b[i]{return 0};i=i+1};return 1} 9func bg_copy(a:*i64,b:*i64,n:i64)->i64{var i:i64=0;while i<n{b[i]=a[i];i=i+1};return 0} 10func main()->i64{ 11 let words:i64=ibr_words(2);let arena:*i64=sys_mmap(words*8) as *i64 12 let snapshot:*i64=sys_mmap(words*8) as *i64 13 let record:*i64=sys_mmap(IBR_COMPONENTS*8) as *i64;let readback:*i64=sys_mmap(IBR_COMPONENTS*8) as *i64 14 let body:*BeachContactBox=sys_mmap(48) as *BeachContactBox;let scratch:*BeachContactBox=sys_mmap(48) as *BeachContactBox;let hit:*ImportedBodyHit=sys_mmap(48) as *ImportedBodyHit 15 bg_check(ibr_init(arena,words,2)==0,"bounded registry init" as *u8) 16 record[IBR_ID_LO]=101;record[IBR_REV]=1;record[IBR_SHAPE_REV]=1;record[IBR_POSE_REV]=0 17 record[IBR_WORLD_X]=1000;record[IBR_WORLD_Y]=0;record[IBR_WORLD_Z]=0 18 record[IBR_MIN_X]=0-100;record[IBR_MIN_Y]=0;record[IBR_MIN_Z]=0-100 19 record[IBR_MAX_X]=100;record[IBR_MAX_Y]=500;record[IBR_MAX_Z]=100 20 record[IBR_LAYER]=2;record[IBR_MASK]=3;record[IBR_ENABLED]=1;record[IBR_KIND]=IBR_SHAPE_AABB 21 let h:i64=ibr_upsert(arena,words,record,IBR_COMPONENTS) 22 bg_check(h>0,"instance receives stable generation handle" as *u8) 23 bg_copy(arena,snapshot,words) 24 bg_check(ibr_upsert(arena,words,record,IBR_COMPONENTS)==h&&bg_same(arena,snapshot,words)==1,"repeat upsert byte-identical" as *u8) 25 bg_check(ibr_init(arena,words,2)==0&&bg_same(arena,snapshot,words)==1,"repeat init preserves physical identity" as *u8) 26 bg_check(ibr_init(arena,words,3)==IBR_CAPACITY&&bg_same(arena,snapshot,words)==1,"requested init capacity mismatch preserves arena" as *u8) 27 record[IBR_REV]=2;record[IBR_MIN_X]=0-101 28 bg_check(ibr_upsert(arena,words,record,IBR_COMPONENTS)==IBR_CONFLICT&&bg_same(arena,snapshot,words)==1,"changed bounds require shape revision" as *u8) 29 record[IBR_MIN_X]=0-100;record[IBR_WORLD_X]=1001 30 bg_check(ibr_upsert(arena,words,record,IBR_COMPONENTS)==IBR_CONFLICT&&bg_same(arena,snapshot,words)==1,"changed anchor requires pose revision" as *u8) 31 record[IBR_REV]=1 32 bg_check(ibr_upsert(arena,words,record,IBR_COMPONENTS)==IBR_CONFLICT&&bg_same(arena,snapshot,words)==1,"same revision conflict preserves state" as *u8) 33 record[IBR_WORLD_X]=1000;record[IBR_KIND]=2 34 bg_check(ibr_upsert(arena,words,record,IBR_COMPONENTS)==IBR_BAD&&bg_same(arena,snapshot,words)==1,"unknown shape refused without mutation" as *u8) 35 record[IBR_KIND]=1;record[IBR_MAX_Y]=0 36 bg_check(ibr_upsert(arena,words,record,IBR_COMPONENTS)==IBR_BAD&&bg_same(arena,snapshot,words)==1,"empty body shape refused" as *u8) 37 record[IBR_MAX_Y]=500;record[IBR_WORLD_X]=IBR_DOMAIN 38 bg_check(ibr_upsert(arena,words,record,IBR_COMPONENTS)==IBR_BAD&&bg_same(arena,snapshot,words)==1,"coordinate overflow domain refused" as *u8) 39 record[IBR_WORLD_X]=1000;record[IBR_REV]=2;record[IBR_SHAPE_REV]=2;record[IBR_POSE_REV]=1 40 bg_check(ibr_upsert(arena,words,record,IBR_COMPONENTS)==h,"shape and pose update preserves handle" as *u8) 41 record[IBR_REV]=1 42 bg_check(ibr_upsert(arena,words,record,IBR_COMPONENTS)==IBR_CONFLICT,"stale state revision refused" as *u8) 43 record[IBR_REV]=2 44 bg_check(ibr_read(arena,words,h,readback,IBR_COMPONENTS)==0&&bg_same(record,readback,IBR_COMPONENTS)==1,"instance handle shape pose coverage readable" as *u8) 45 bg_box(body,0,0,0-50,100,450,50) 46 bg_check(ibr_sweep(arena,words,body,0,0,0,2000,1,2,0,scratch,hit)==0&&hit.delta_q8==800&&hit.hit_handle==h&&hit.hit_shape_revision==2&&hit.hit_pose_revision==1,"player swept contact blocks high displacement" as *u8) 47 bg_check(hit.initial_overlap==0&&hit.tested==1,"contact coverage and nonpenetration recorded" as *u8) 48 bg_box(body,0-4096,0,0-50,100-4096,450,50) 49 bg_check(ibr_sweep(arena,words,body,4096,0,0,2000,1,2,0,scratch,hit)==0&&hit.delta_q8==800&&hit.hit_handle==h,"origin shift preserves physical contact" as *u8) 50 bg_box(body,0,600,0-50,100,1000,50) 51 bg_check(ibr_sweep(arena,words,body,0,0,0,2000,1,2,0,scratch,hit)==0&&hit.delta_q8==2000&&hit.hit_handle==0,"different altitude is not an invisible wall" as *u8) 52 bg_box(body,0,0,100,100,450,200) 53 bg_check(ibr_sweep(arena,words,body,0,0,0,2000,1,2,0,scratch,hit)==0&&hit.delta_q8==2000,"tangential contact permits movement" as *u8) 54 bg_box(body,950,0,0-50,1050,450,50) 55 bg_check(ibr_sweep(arena,words,body,0,0,0,10,1,2,0,scratch,hit)==0&&hit.initial_overlap==1&&hit.delta_q8==0&&hit.hit_handle==h,"initial penetration explicitly reported" as *u8) 56 bg_box(body,0,0,0-50,100,450,50) 57 bg_check(ibr_sweep(arena,words,body,0,0,0,2000,2,2,h,scratch,hit)==0&&hit.delta_q8==2000&&hit.tested==0,"self handle excluded from NPC pair sweep" as *u8) 58 bg_check(ibr_sweep(arena,words,body,0,0,0,2000,2,2,0,scratch,hit)==0&&hit.delta_q8==800,"same registry supports NPC against imported body" as *u8) 59 bg_check(ibr_sweep(arena,words,body,0,0,0,2000,1,4,0,scratch,hit)==0&&hit.delta_q8==2000&&hit.tested==0,"collision masks respected" as *u8) 60 record[IBR_REV]=3;record[IBR_ENABLED]=0;ibr_upsert(arena,words,record,IBR_COMPONENTS) 61 bg_check(ibr_sweep(arena,words,body,0,0,0,2000,1,2,0,scratch,hit)==0&&hit.delta_q8==2000&&ibr_find(arena,0,101)==h,"explicit inactive state retains identity" as *u8) 62 record[IBR_REV]=4;record[IBR_ENABLED]=1;ibr_upsert(arena,words,record,IBR_COMPONENTS) 63 record[IBR_ID_LO]=102;record[IBR_WORLD_X]=2000 64 let h2:i64=ibr_upsert(arena,words,record,IBR_COMPONENTS) 65 bg_check(h2>0&&h2!=h,"independent physical identities" as *u8) 66 bg_copy(arena,snapshot,words);record[IBR_ID_LO]=103 67 bg_check(ibr_upsert(arena,words,record,IBR_COMPONENTS)==IBR_CAPACITY&&bg_same(arena,snapshot,words)==1,"capacity refusal preserves all identities" as *u8) 68 bg_check(ibr_sweep(arena,words,body,0,0,0,4000,1,2,0,scratch,hit)==0&&hit.delta_q8==800&&hit.hit_handle==h&&hit.tested==2,"nearest obstacle wins across registered instances" as *u8) 69 bg_check(bg_same(arena,snapshot,words)==1,"sweep never mutates registry" as *u8) 70 bg_check(ibr_sweep(arena,words,body,0,0,0,4000,1,2,h+1,scratch,hit)==IBR_BAD,"stale generation handle refused" as *u8) 71 bg_check(ibr_find(arena,0,101)==h&&ibr_find(arena,0,102)==h2,"renderer-free lifetime preserved" as *u8) 72 // The real converted asset supplies dimensions; this fixture explicitly selects whole-mesh AABB, not anatomy. 73 let boxlen:*i64=sys_mmap(8) as *i64;let bytes:*u8=sys_read_file("/tmp/dark-knight-affine-fullskin-t37.nxa" as *u8,boxlen) 74 if (bytes as i64)==0{bg_check(0,"actual converted asset present" as *u8)}else{ 75 let at:i64=nxa_counted_section(bytes,boxlen[0],nxa_tag4("VERT" as *u8),3) 76 if at<0{bg_check(0,"actual VERT validated" as *u8)}else{ 77 let data:*i64=bytes as *i64;let nv:i64=data[at];var lo:i64=data[at+2];var hi:i64=lo;var v:i64=0 78 while v<nv{let y:i64=data[at+2+v*3];if y<lo{lo=y};if y>hi{hi=y};v=v+1} 79 bg_check(nv==53296&&hi-lo==958896,"actual authored height provides scale input" as *u8) 80 }} 81 nb_text("IMPORTED_BODY_GATE checks=" as *u8);nb_num(checks);nb_text(" failures=" as *u8);nb_num(failures);nb_text(" serialization=UNWIRED page_body_bind=UNWIRED\n" as *u8) 82 if failures!=0{return 3};return 0 83}