nx_imported_body_page_t262.nx
buildroot/runtime/nx_imported_body_page_t262.nx
dependencies 1 imports · 12 importers
diagram shows first 10 each side; +0 more imports, +2 more importers in the complete lists below.
imports: nx_imported_body_registry_t40.nx
imported by: nx_game_page_catwalk_lighting_candidate_t316.nxnx_game_page_hair_attachment_candidate_t263.nxnx_game_page_hair_attachment_t283.nxnx_game_page_host_candidate_t341.nxnx_game_page_integrated_t73.nxnx_game_page_motion_inventory_candidate_t330.nxnx_game_page_procedural_review_candidate_t333.nxnx_game_page_rig_comparison_t332.nxnx_game_page_rig_observation_candidate_t331.nxnx_game_page_shared_candidate_t340.nxnx_game_page_static_candidate_t338.nxnx_game_page_workbench_candidate_t342.nx
structs
| none |
consts
| 2 | const GPE_PREPARED_BODY_T262:*u8="\n\nconst nxImportedBodyOwner={engine:null,buffer:null};\nfunction nxBodyI64(row){if(row.some(v=>typeof v!=='bigint'||v<-(1n<<63n)||v>=(1n<<63n)))throw Error('body record integer range');}\nfunction nxImportedBodyContract(){\n const names=['body_capacity_current','body_capacity_max','body_init','body_record_words','body_stage_off','body_read_off','body_bind','body_handle','body_read','body_affine_input_off','body_affine_input_words','body_affine_bounds_off','body_static_bounds'];\n if(names.some(k=>typeof ex[k]!=='function'))throw Error('native imported body capability unavailable');\n if(Number(ex.body_record_words())!==NX_BODY.words||Number(ex.body_affine_input_words())!==13)throw Error('native imported body ABI mismatch');\n if(nxImportedBodyOwner.engine!==ex){\n let capacity=ex.body_capacity_current();if(capacity===0n){if(ex.body_init(ex.body_capacity_max(),BigInt(ex.memory.buffer.byteLength))!==0n)throw Error('native body arena admission refused');capacity=ex.body_capacity_current();}\n if(capacity<=0n)throw Error('native body arena unavailable');nxImportedBodyOwner.engine=ex;\n }\n if(nxImportedBodyOwner.buffer!==ex.memory.buffer){\n const spans=[[ex.body_stage_off(),NX_BODY.words],[ex.body_read_off(),NX_BODY.words],[ex.body_affine_input_off(),13],[ex.body_affine_bounds_off(),6]],bytes=BigInt(ex.memory.buffer.byteLength);\n for(const [offset,words] of spans){if(offset<0n||offset%8n!==0n||offset+BigInt(words)*8n>bytes)throw Error('native body ABI extent');}\n for(let i=0;i<spans.length;i++)for(let j=i+1;j<spans.length;j++){const [a,aw]=spans[i],[b,bw]=spans[j];if(a<b+BigInt(bw)*8n&&b<a+BigInt(aw)*8n)throw Error('native body ABI overlap');}\n nxImportedBodyOwner.buffer=ex.memory.buffer;\n }\n}\nasync function nxPreparedBodyIdentity(D){\n const instance=D.sourceId;if(typeof instance!=='string'||!instance||instance.includes('\\0'))throw Error('prepared instance identity');\n const digest=await crypto.subtle.digest('SHA-256',new TextEncoder().encode('nishi.scene-instance.v1\\0'+location.origin+location.pathname+'\\0'+instance)),view=new DataView(digest);\n return {instance,key:[view.getBigInt64(0,true),view.getBigInt64(8,true)],state:'waiting',requestedEnabled:true,checks:0,binds:0,unchanged:0,scope:'Current native pose conservative whole-mesh collision proxy; not anatomical contact or autonomous NPC'};\n}\nfunction nxPreparedBodyRead(handle){\n nxImportedBodyContract(); if(ex.body_read(handle)!==0n)throw Error('native body read refused');const view=new DataView(ex.memory.buffer),at=Number(ex.body_read_off());\n return Array.from({length:NX_BODY.words},(_,i)=>view.getBigInt64(at+i*8,true));\n}\nfunction nxPreparedCurrentSample(D){\n const motion=D.prepared.motionActive===false?null:D.prepared.motion;if(!motion)return D.prepared.packet.samples[D.prepared.selected];\n if(motion.error||!motion.sample||!Number.isSafeInteger(motion.revision)||motion.revision<=0)throw Error('prepared motion pose unavailable');\n if(motion.sample.time!==motion.time)throw Error('prepared motion pose time mismatch');if(motion.mode==='disposed'||motion.sample.boundsState!=='ready'||!['native-conservative-influence-aabb','native-exact-all-vertices'].includes(motion.sample.boundsKind))throw Error('prepared motion bounds unavailable');return motion.sample;\n}\nfunction nxPreparedBodyBind(D){\n const body=D.body;if(!body)return;\n body.checks++;if(!Number.isFinite(D.motionOffsetX??0)||!Number.isFinite(D.motionOffsetZ??0))throw Error('prepared motion placement offset invalid');nxImportedBodyContract();if(body.requestedEnabled===false){nxPreparedBodyDisable(D);return;}\n const sample=nxPreparedCurrentSample(D),motionActive=D.prepared.motionActive!==false&&!!D.prepared.motion;const cacheKey=[motionActive?'motion':'discrete',motionActive?D.prepared.motion.revision:D.prepared.selected,sample.time,D.wx,D.wz,D.motionOffsetX??0,D.motionOffsetZ??0,D.py,D.A,D.sc,new Float32Array(GPU.cvb)[NXCV.uSc/4]].join(':');\n const priorHandle=ex.body_handle(...body.key);if(body.cacheKey===cacheKey&&priorHandle>0n){const current=nxPreparedBodyRead(priorHandle);if(current[NX_BODY.fields.enabled]===1n&&String(current[NX_BODY.fields.revision])===body.revision){body.unchanged++;body.state='bound';body.reason=null;body.nativeActive=true;return;}}\n const q=D.prepared.packet.q,b=sample.bounds.map(x=>x/q);\n if(b.length!==6||!b.every(Number.isFinite)||b.slice(0,3).some((v,i)=>v>=b[i+3]))throw Error('prepared body bounds unavailable');\n const base=new Float32Array(GPU.cvb)[NXCV.uSc/4],sc=Math.fround(D.sc),sn=Math.fround(Math.sin(D.A)),cs=Math.fround(Math.cos(D.A));\n // Convert the source-scene Y-up bounds to the existing native Z-up affine ABI.\n const input=[b[0],-b[5],b[1],b[3],-b[2],b[4],sn,cs,base,sc,0,0,0],view=new DataView(ex.memory.buffer),bits=new DataView(new ArrayBuffer(4)),at=Number(ex.body_affine_input_off());\n input.forEach((v,i)=>{bits.setFloat32(0,v,true);view.setBigInt64(at+i*8,BigInt(bits.getUint32(0,true)),true);});\n const affineResult=ex.body_static_bounds(1n);if(affineResult!==0n){body.transformFailures=(body.transformFailures||0)+1;const inputBits=input.map((_,i)=>String(view.getBigInt64(at+i*8,true)));if(!body.transformFailure||body.transformFailure.returnCode!==String(affineResult)||inputBits.some((v,i)=>v!==body.transformFailure.inputBits[i]))body.transformFailure={schema:'nishi-body-affine-failure/1',operation:'body_static_bounds',returnCode:String(affineResult),encoding:'binary32-bits-in-i64',inputBits,sourceSha256:D.prepared.descriptor.sourceSha256,observedAt:new Date().toISOString(),postcondition:'proxy-not-bound'};throw Error('native pose proxy transform refused; code='+affineResult);}body.transformFailure=null;\n const out=Number(ex.body_affine_bounds_off()),shape=Array.from({length:6},(_,i)=>view.getBigInt64(out+i*8,true)),B=NX_BODY.fields,record=new Array(NX_BODY.words).fill(0n);\n const anchorQ=(x)=>{const v=Math.round(x*256);if(!Number.isSafeInteger(v))throw Error('body anchor range');return BigInt(v);};\n record[B.idHi]=body.key[0];record[B.idLo]=body.key[1];record[B.worldX]=D.wx*256n+128n+anchorQ(D.motionOffsetX??0);record[B.worldY]=anchorQ(D.py);record[B.worldZ]=D.wz*256n+128n+anchorQ(D.motionOffsetZ??0);\n const xResidual=(D.motionOffsetX??0)-Number(anchorQ(D.motionOffsetX??0))/256,zResidual=(D.motionOffsetZ??0)-Number(anchorQ(D.motionOffsetZ??0))/256;shape[0]+=BigInt(Math.floor(xResidual*256));shape[3]+=BigInt(Math.ceil(xResidual*256));shape[2]+=BigInt(Math.floor(zResidual*256));shape[5]+=BigInt(Math.ceil(zResidual*256));const yResidual=D.py-Number(record[B.worldY])/256;\n shape[1]+=BigInt(Math.floor(yResidual*256));shape[4]+=BigInt(Math.ceil(yResidual*256));shape.forEach((v,i)=>record[B.minX+i]=v);\n record[B.layer]=BigInt(NX_BODY_DEFAULT_POLICY.layer);record[B.mask]=BigInt(NX_BODY_DEFAULT_POLICY.mask);record[B.enabled]=1n;record[B.kind]=BigInt(NX_BODY_DEFAULT_POLICY.kind);\n const handle=ex.body_handle(...body.key),previous=handle>0n?nxPreparedBodyRead(handle):null;\n let changed=!previous,shapeChanged=!previous,poseChanged=!previous;\n if(previous){for(let i=0;i<record.length;i++){if(i>=B.revision&&i<=B.poseRevision)continue;if(record[i]!==previous[i])changed=true;}\n for(let i=B.minX;i<=B.maxZ;i++)if(record[i]!==previous[i])shapeChanged=true;\n for(let i=B.worldX;i<=B.worldZ;i++)if(record[i]!==previous[i])poseChanged=true;}\n if(!changed){body.unchanged++;body.state='bound';body.reason=null;body.nativeActive=true;body.cacheKey=cacheKey;body.revision=String(previous[B.revision]);body.handle=String(handle);body.shapeQ8=shape.map(String);body.anchorQ8=record.slice(B.worldX,B.worldZ+1).map(String);body.poseSample=D.prepared.motionActive!==false&&D.prepared.motion?null:D.prepared.selected;body.poseTime=sample.time;body.boundsKind=sample.boundsKind||'native-exact-discrete';body.observed_at=new Date().toISOString();return;}\n record[B.revision]=previous?previous[B.revision]+1n:1n;record[B.shapeRevision]=previous?previous[B.shapeRevision]+(shapeChanged?1n:0n):1n;record[B.poseRevision]=previous?previous[B.poseRevision]+(poseChanged?1n:0n):1n;\n nxBodyI64(record);const stage=Number(ex.body_stage_off());record.forEach((v,i)=>view.setBigInt64(stage+i*8,v,true));const bound=ex.body_bind();if(bound<=0n)throw Error('native body bind refused '+bound);\n const actual=nxPreparedBodyRead(bound);if(actual.some((v,i)=>v!==record[i]))throw Error('native body readback mismatch');\n body.cacheKey=cacheKey;body.revision=String(actual[B.revision]);body.binds++;body.state='bound';body.reason=null;body.nativeActive=true;body.handle=String(bound);body.shapeQ8=shape.map(String);body.anchorQ8=record.slice(B.worldX,B.worldZ+1).map(String);body.poseSample=D.prepared.motionActive!==false&&D.prepared.motion?null:D.prepared.selected;body.poseTime=sample.time;body.boundsKind=sample.boundsKind||'native-exact-discrete';body.observed_at=new Date().toISOString();\n}\n\n\nfunction nxPreparedBodyDisable(D){\n const body=D.body,handle=ex.body_handle(...body.key),B=NX_BODY.fields;\n if(handle>0n){\n const row=nxPreparedBodyRead(handle);\n if(row[B.enabled]!==0n){\n row[B.enabled]=0n;row[B.revision]+=1n;nxBodyI64(row);\n const view=new DataView(ex.memory.buffer),at=Number(ex.body_stage_off());\n row.forEach((v,i)=>view.setBigInt64(at+i*8,v,true));\n if(ex.body_bind()!==handle)throw Error('native body disable refused');\n const actual=nxPreparedBodyRead(handle);if(actual.some((v,i)=>v!==row[i]))throw Error('native body disable readback mismatch');\n body.binds++;\n }else body.unchanged++;\n body.handle=String(handle);body.revision=String(row[B.revision]);\n }else body.unchanged++;\n body.state='disabled';body.reason=null;body.cleanupError=null;body.nativeActive=false;body.cacheKey=null;body.observed_at=new Date().toISOString();\n}\nfunction nxPreparedCollision(asset,enabled){\n if(typeof asset!=='string'||typeof enabled!=='boolean')return {ok:false,state:'refused',code:'collision-argument-type'};\n const D=DN.find(d=>d.sourceId===asset&&d.prepared&&d.body);\n if(!D)return {ok:false,state:'refused',code:'prepared-instance-unavailable',asset};\n D.body.requestedEnabled=enabled;nxPreparedBodyUpdate(D);\n return {ok:D.body.nativeActive===enabled&&D.body.state===(enabled?'bound':'disabled'),state:D.body.state,asset,requestedEnabled:enabled,nativeActive:D.body.nativeActive,handle:D.body.handle,revision:D.body.revision,reason:D.body.reason||null,scope:D.body.scope};\n}\nfunction nxPreparedBodyMount(D,box){\n const label=document.createElement('label'),toggle=document.createElement('input'),status=document.createElement('p');\n toggle.type='checkbox';toggle.checked=D.body.requestedEnabled;toggle.setAttribute('aria-label','Selected pose collision proxy');\n label.append(toggle,document.createTextNode(' Selected pose collision proxy'));\n status.textContent='Collision proxy waiting for native binding.';status.setAttribute('aria-live','polite');D.body.status=status;D.body.toggle=toggle;\n toggle.addEventListener('change',()=>nxPreparedCollision(D.sourceId,toggle.checked));\n box.append(label,status);\n}\nwindow.nishiPreparedCollision=nxPreparedCollision;\n\nfunction nxPreparedBodyUpdate(D){\n try{nxPreparedBodyBind(D);}\n catch(error){\n if(D.body){const body=D.body;body.state='needs-intervention';body.reason=String(error);body.cacheKey=null;body.nativeActive=null;\n try{const handle=ex.body_handle(...body.key);if(handle>0n){const row=nxPreparedBodyRead(handle),B=NX_BODY.fields;\n if(row[B.enabled]===1n){row[B.enabled]=0n;row[B.revision]+=1n;if(row[B.revision]>=(1n<<63n))throw Error('body revision exhausted');\n nxBodyI64(row);const view=new DataView(ex.memory.buffer),at=Number(ex.body_stage_off());row.forEach((v,i)=>view.setBigInt64(at+i*8,v,true));\n if(ex.body_bind()!==handle)throw Error('stale proxy suspension refused');\n }\n body.nativeActive=nxPreparedBodyRead(handle)[B.enabled]===1n;\n }else body.nativeActive=false;}catch(cleanupError){body.cleanupError=String(cleanupError);}\n }\n }\n if(D.body?.toggle)D.body.toggle.checked=D.body.requestedEnabled;\n if(D.body?.status){const text=D.body.state==='bound'?'Selected pose collision proxy bound.':D.body.state==='disabled'?'Selected pose collision proxy disabled.':'Collision proxy: '+(D.body.reason||D.body.state);if(D.body.status.textContent!==text)D.body.status.textContent=text;}\n}\nObject.defineProperty(window,'__nx_imported_bodies',{configurable:true,get:()=>({scope:'Selected pose AABB proxies only; root locomotion, animated anatomical contact and attached eyes untested',entries:DN.map(d=>({asset:d.sourceId,state:d.body?.state||'unbound',nativeActive:d.body?.nativeActive,requestedEnabled:d.body?.requestedEnabled,revision:d.body?.revision,cleanupError:d.body?.cleanupError,handle:d.body?.handle,proxy:d.body?.scope,poseSample:d.body?.poseSample,poseTime:d.body?.poseTime,boundsKind:d.body?.boundsKind,shapeQ8:d.body?.shapeQ8,anchorQ8:d.body?.anchorQ8,checks:d.body?.checks,binds:d.body?.binds,unchanged:d.body?.unchanged,transformFailures:d.body?.transformFailures,transformFailure:d.body?.transformFailure,reason:d.body?.reason}))})});\n\nObject.defineProperty(window,'__nx_imported_contact',{configurable:true,get:()=>{const observed_at=new Date().toISOString(),names=['camx','camy','camz','wox','woz','contact_initial_overlap_impl','contact_clipped_axes_impl','contact_material_impl'];if(typeof ex==='undefined'||!ex)return {state:'waiting',observed_at,reason:'Native engine not initialized'};const missing=names.filter(k=>typeof ex[k]!=='function');if(missing.length)return {state:'unavailable',observed_at,missing};return {state:'measured',observed_at,coordinateFrame:'Camera is local streaming-window Q8 including eye height; world origin is separate cells',cameraQ8:[String(ex.camx()),String(ex.camy()),String(ex.camz())],worldOriginCells:[String(ex.wox()),String(ex.woz())],initialOverlap:String(ex.contact_initial_overlap_impl(0n)),clippedAxes:String(ex.contact_clipped_axes_impl(0n)),material:String(ex.contact_material_impl(0n)),qualification:'Whole-mesh proxy only; tissue, soles and autonomous movement untested'};}});\n" |
functions
| 4 | func gpe_prepared_body_emit(out:*u8,pos:i64)->i64 |