import{r as e}from"./chunk-DECur_0Z.js";import{n as t,r as n,t as r}from"./jsx-runtime-BpGWiA-R.js";import{i,o as a}from"./react-three-fiber.esm-1xQMUSXT.js";import"./Html-BD9DC-n9.js";import{a as o,i as s}from"./SettingsProvider-DlQTXm3x.js";import{t as c}from"./logger-DePRU8Hm.js";import"./traditional-DPdbI9gv.js";import{Bt as l,Ct as u,D as d,Ft as f,Ht as p,It as m,Nt as h,S as g,g as _,h as v,kt as y,m as b,nt as x,p as S,rt as C,xt as w,yt as T,zt as E}from"./three.module-Bu2Gkdne.js";import"./mission-CWASMBNZ.js";import{a as D,n as O,r as k,t as A}from"./engineStore-Clbs91WD.js";import{B as j,F as M,I as N,M as ee,O as P,Q as F,R as I,_ as L,c as R,l as te,v as ne,z}from"./index-ClGJzuqQ.js";import{getCachedAudioBuffer as re,getSoundGeneration as ie,playOneShotSound as ae,resolveAudioProfile as oe,stopAllTrackedSounds as se,trackSound as ce,untrackSound as le}from"./AudioEmitter-CpW3GMEa.js";import{PlayerEyeOffset as ue}from"./PlayerModel-CLZ-My-h.js";var de=t(),B=e(n(),1),fe=Math.PI/180,pe=-9.81,me=Math.PI/(180*1e3),he=1/100,ge=-1e3,_e=50,V=5,ve=5,ye=10;function H(e,t,n){let r=e[t];return typeof r==`number`&&Number.isFinite(r)?r:n}function U(e,t,n){let r=e[t];return typeof r==`boolean`?r:typeof r==`number`?r!==0:n}function be(e){let t=e.keys,n=[];if(Array.isArray(t)&&t.length>0)for(let e=0;e0&&t[0]&&(r=t[0])}return{dragCoefficient:H(e,`dragCoefficient`,0)*ve,windCoefficient:H(e,`windCoefficient`,1),gravityCoefficient:H(e,`gravityCoefficient`,0)*ye,inheritedVelFactor:H(e,`inheritedVelFactor`,0),constantAcceleration:H(e,`constantAcceleration`,0),lifetimeMS:H(e,`lifetimeMS`,31)<=t){let r=e[n-1],i=e[n],a=i.time-r.time,o=a>0?(t-r.time)/a:0;return{r:r.r+(i.r-r.r)*o,g:r.g+(i.g-r.g)*o,b:r.b+(i.b-r.b)*o,a:r.a+(i.a-r.a)*o,size:r.size+(i.size-r.size)*o}}let n=e[e.length-1];return{r:n.r,g:n.g,b:n.b,a:n.a,size:n.size}}var Ee=class{data;particles=[];maxParticles;internalClock=0;nextParticleTime=0;emitterAge=0;emitterLifetime;emitterDead=!1;constructor(e,t=256,n){this.data=e,this.maxParticles=t;let r=n??e.lifetimeMS;!n&&e.lifetimeVarianceMS>0&&(r+=Math.round(W(0,e.lifetimeVarianceMS))),this.emitterLifetime=r}emitBurst(e,t,n=[0,0,1]){for(let r=0;r0;){if(this.nextParticleTime>0){let e=Math.min(r,this.nextParticleTime);this.nextParticleTime-=e,r-=e,this.internalClock+=e;continue}if(this.particles.length0)){let e=this.particles[this.particles.length-1];e.currentAge+=r,e.currentAge>=e.totalLifetime&&this.particles.pop()}let t=this.data.ejectionPeriodMS;this.data.periodVarianceMS>0&&(t+=Math.round(W(0,this.data.periodVarianceMS))),this.nextParticleTime=Math.max(1,t)}}update(e){this.emitterAge+=e,this.emitterLifetime>0&&this.emitterAge>this.emitterLifetime&&(this.emitterDead=!0);let t=e/1e3,n=this.data.particles;for(let r=this.particles.length-1;r>=0;r--){let i=this.particles[r];if(i.currentAge+=e,i.currentAge>=i.totalLifetime){this.particles[r]=this.particles[this.particles.length-1],this.particles.pop();continue}let a=n.dragCoefficient,o=n.gravityCoefficient,s=i.acc[0]-i.vel[0]*a,c=i.acc[1]-i.vel[1]*a,l=i.acc[2]-i.vel[2]*a+pe*o;i.vel[0]+=s*t,i.vel[1]+=c*t,i.vel[2]+=l*t,i.pos[0]+=i.vel[0]*t,i.pos[1]+=i.vel[1]*t,i.pos[2]+=i.vel[2]*t;let u=i.currentAge/i.totalLifetime,d=Te(n.keys,u);i.r=d.r,i.g=d.g,i.b=d.b,i.a=d.a,i.size=d.size,i.currentSpin=i.spinSpeed*i.currentAge*me}}isDead(){return this.emitterDead&&this.particles.length===0}kill(){this.emitterDead=!0}addParticle(e,t){let n=this.data,r=n.particles,i=t[0],a=t[1],o=t[2],s=Ce(i,a,o),c=(n.thetaMin+Math.random()*(n.thetaMax-n.thetaMin))*fe,l=(this.internalClock/1e3*n.phiReferenceVel+Math.random()*n.phiVariance)*fe;[i,a,o]=we(i,a,o,s[0],s[1],s[2],c),[i,a,o]=we(i,a,o,t[0],t[1],t[2],l);let u=Math.sqrt(i*i+a*a+o*o);u>1e-8&&(i/=u,a/=u,o/=u);let d=W(n.ejectionVelocity,n.velocityVariance),f=[e[0]+i*n.ejectionOffset,e[1]+a*n.ejectionOffset,e[2]+o*n.ejectionOffset],p=[i*d,a*d,o*d],m=r.constantAcceleration,h=[p[0]*m,p[1]*m,p[2]*m],g=r.lifetimeMS;r.lifetimeVarianceMS>0&&(g+=Math.round(W(0,r.lifetimeVarianceMS))),g=Math.max(1,g);let _=r.spinSpeed+Se(r.spinRandomMin,r.spinRandomMax),v=r.keys[0];this.particles.push({pos:f,vel:p,acc:h,orientDir:[i,a,o],currentAge:0,totalLifetime:g,dataIndex:0,spinSpeed:_,currentSpin:0,r:v.r,g:v.g,b:v.b,a:v.a,size:v.size})}},De=` // 'position' is auto-declared by Three.js for ShaderMaterial. attribute vec4 particleColor; attribute float particleSize; attribute float particleSpin; attribute vec2 quadCorner; // (-0.5,-0.5) to (0.5,0.5) attribute vec3 orientDir; uniform bool uOrientParticles; // cameraPosition is a built-in Three.js uniform. varying vec2 vUv; varying vec4 vColor; void main() { vUv = quadCorner + 0.5; // [0,1] range vColor = particleColor; if (uOrientParticles) { if (length(orientDir) < 0.0001) { // V12: don't render oriented particles with zero velocity. gl_Position = vec4(0.0, 0.0, 0.0, 0.0); return; } // V12 oriented particle: quad aligned along direction, facing camera. vec3 worldPos = (modelMatrix * vec4(position, 1.0)).xyz; vec3 dir = normalize(orientDir); vec3 dirFromCam = worldPos - cameraPosition; vec3 crossDir = normalize(cross(dirFromCam, dir)); // V12 maps U along dir (velocity) — match by using quadCorner.x for dir. vec3 offset = dir * quadCorner.x + crossDir * quadCorner.y; worldPos += offset * particleSize; gl_Position = projectionMatrix * viewMatrix * vec4(worldPos, 1.0); } else { // Standard camera-facing billboard. vec3 viewPos = (modelViewMatrix * vec4(position, 1.0)).xyz; // Apply spin rotation to quad corner. float c = cos(particleSpin); float s = sin(particleSpin); vec2 rotated = vec2( c * quadCorner.x - s * quadCorner.y, s * quadCorner.x + c * quadCorner.y ); // Offset in view space (camera-facing billboard). viewPos.xy += rotated * particleSize; gl_Position = projectionMatrix * vec4(viewPos, 1.0); } } `,Oe=` uniform sampler2D particleTexture; uniform bool hasTexture; uniform float debugOpacity; varying vec2 vUv; varying vec4 vColor; void main() { if (hasTexture) { vec4 texColor = texture2D(particleTexture, vUv); gl_FragColor = texColor * vColor; } else { gl_FragColor = vColor; } gl_FragColor.a *= debugOpacity; } `,G=r(),ke=c(`ParticleEffects`),K=256,Ae=new Float32Array([-.5,-.5,.5,-.5,.5,.5,-.5,.5]),je=new Map,Me=new Set,q=new g(new Uint8Array([255,255,255,255]),1,1,u,l);q.needsUpdate=!0;function J(e){if(!e)return q;let t=je.get(e);if(t)return t;try{let t=P(M(e),e=>{L(e),Me.add(e)});return L(t),je.set(e,t),t}catch{return q}}var Ne=new h(1,6,6),Pe=new C({color:16711680,wireframe:!0}),Fe=new S(.3,.3,.3),Ie=new C({color:65280,wireframe:!0}),Le=new h(1,12,8);function Re(e,t){let n=document.createElement(`canvas`),r=n.getContext(`2d`);r.font=`bold 32px monospace`;let i=r.measureText(e);n.width=Math.ceil(i.width)+16,n.height=48,r.font=`bold 32px monospace`,r.fillStyle=`#${t.toString(16).padStart(6,`0`)}`,r.textBaseline=`middle`,r.fillText(e,8,n.height/2);let a=new m({map:new _(n),transparent:!0,depthTest:!1,depthWrite:!1}),o=new f(a),s=n.width/n.height;return o.scale.set(s*2,2,1),{sprite:o,material:a}}function ze(e,t){let n=t(e);if(!n)return null;let r=n.colors??[],i=n.times??[0,.5,1,1];return{width:n.width??1,numSegments:Math.max(n.numSegments??16,4),velocity:n.velocity??0,height:n.height??0,verticalCurve:n.verticalCurve??0,acceleration:n.acceleration??0,texWrap:n.texWrap??1,lifetimeMS:n.lifetimeMS??500,is2D:!!n.is2D,renderSquare:!!n.renderSquare,renderBottom:!!n.renderBottom,mapToTerrain:!!n.mapToTerrain,colors:r,times:i,textureName:n.textureName??``,mapToTexture:n.mapToTexture??``}}function Be(e,t){let{colors:n,times:r}=e;if(n.length===0)return[1,1,1,1];let i=0;for(let e=0;e=r[e]&&(i=e);let a=Math.min(i+1,n.length-1),o=r[i]??0,s=(r[a]??1)-o,c=s>0?Math.min((t-o)/s,1):0,l=n[i]??n[0],u=n[a]??n[0];return[l.r+(u.r-l.r)*c,l.g+(u.g-l.g)*c,l.b+(u.b-l.b)*c,l.a+(u.a-l.a)*c]}var Ve=` attribute vec4 vertexColor; attribute vec2 texCoord; varying vec4 vColor; varying vec2 vUV; void main() { vColor = vertexColor; vUV = texCoord; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); } `,He=` uniform sampler2D uTexture; varying vec4 vColor; varying vec2 vUV; void main() { vec4 tex = texture2D(uTexture, vUV); gl_FragColor = vec4(vColor.rgb * tex.rgb, vColor.a * tex.a); } `;function Ue(e){let t=(e+1)*2,n=new Float32Array(t*3),r=new Float32Array(t*2),i=new Float32Array(t*4),a=e*6,o=new Uint16Array(a);for(let t=0;t0){let e=0;for(let n of t)e=Math.max(e,n.x,n.y,n.z);if(e>0)return e/1e3}let n=e.particleRadius;return typeof n==`number`&&n>0?n:5}function Je(e){let t=new v,n=e*4,r=e*6,i=new Float32Array(n*2);for(let t=0;t{let i=m.current,a=r.current;if(!i||!a)return;let o=k.getState().playback,s=o.status===`playing`,h=s?t*o.rate:0,_=h*1e3,y=n.getDataBlockData.bind(n);for(let e of a.entities){if(e.type!==`Explosion`||!e.explosionDataBlockId||!e.position||v.current.has(e.id))continue;v.current.add(e.id);let t=Ze(e.explosionDataBlockId,y);if(!t)continue;let n=[...e.position];for(let e of t.burstEmitters){let t=new Ee(e.data,K);t.emitBurst(n,e.density);let r=J(e.data.particles.textureName),a=Je(K),o=Ye(r,e.data.particles.useInvAlpha,e.data.orientParticles),s=new x(a,o);s.frustumCulled=!1,i.add(s),g.current.push({emitter:t,mesh:s,geometry:a,material:o,targetTexture:r,origin:n,isBurst:!0,hasBurst:!0})}for(let e of t.streamingEmitters){let r=new Ee(e,K,t.lifetimeMS),a=J(e.particles.textureName),o=Je(K),s=Ye(a,e.particles.useInvAlpha,e.orientParticles),c=new x(o,s);c.frustumCulled=!1,i.add(c),g.current.push({emitter:r,mesh:c,geometry:o,material:s,targetTexture:a,origin:n,isBurst:!1,hasBurst:!1})}let r=y(e.explosionDataBlockId);if(c){let a=r?qe(r):5,o=Ke(e.dataBlock),s=new C({color:o,wireframe:!0,transparent:!0,opacity:1,depthWrite:!1}),c=new x(Le,s);c.frustumCulled=!1,c.scale.setScalar(a),c.position.set(n[1],n[2],n[0]),i.add(c);let{sprite:l,material:u}=Re(`${e.id}: ${e.dataBlock??`expId:${e.explosionDataBlockId}`}`,o);l.position.set(n[1],n[2]+a+2,n[0]),l.frustumCulled=!1,i.add(l),M.current.push({entityId:e.id,mesh:c,material:s,label:l,labelMaterial:u,creationTime:O(),lifetimeMS:Math.max(t.lifetimeMS,3e3),targetRadius:a})}let a=r?.shockwave;if(typeof a==`number`){let t=ze(a,y);if(t){let r=J(t.textureName),a=Ue(t.numSegments),o=Ge(r),s=new x(a,o);s.frustumCulled=!1,s.position.set(n[1],n[2],n[0]),i.add(s);let c=null,l=null;t.renderBottom&&(l=Ue(t.numSegments),c=new x(l,o),c.frustumCulled=!1,c.position.set(n[1],n[2],n[0]),c.scale.y=-1,i.add(c));let u=Math.abs(t.velocity)>1e-10?t.velocity:0;P.current.push({entityId:e.id,mesh:s,bottomMesh:c,geometry:a,bottomGeometry:l,material:o,creationTime:O(),lifetimeMS:t.lifetimeMS,data:t,radius:0,velocity:u})}}}let S=new Set;for(let e of a.entities){if(S.add(e.id),!e.maintainEmitterId||b.current.has(e.id))continue;b.current.add(e.id);let t=y(e.maintainEmitterId);if(!t)continue;let n=xe(t,y);if(!n)continue;let r=e.position?[...e.position]:[0,0,0],a=new Ee(n,K),o=J(n.particles.textureName),s=Je(K),c=Ye(o,n.particles.useInvAlpha,n.orientParticles),l=new x(s,c);l.frustumCulled=!1,i.add(l),g.current.push({emitter:a,mesh:l,geometry:s,material:c,targetTexture:o,origin:r,isBurst:!1,hasBurst:!1,followEntityId:e.id})}for(let e of g.current)e.followEntityId&&!S.has(e.followEntityId)&&e.emitter.kill();for(let e of b.current)S.has(e)||b.current.delete(e);let E=g.current;for(let e=E.length-1;e>=0;e--){let t=E[e];if(t.shaderChecked||=(Xe(f,t.material,t.isBurst?`burst`:`stream`),!0),t.followEntityId){let e=a.entities.find(e=>e.id===t.followEntityId);e?.position&&(t.origin[0]=e.position[0],t.origin[1]=e.position[1],t.origin[2]=e.position[2]),e?.direction&&(t.emitAxis=e.direction)}if(t.isBurst||t.emitter.emitPeriodic(t.origin,_,t.emitAxis),t.emitter.update(_),Me.has(t.targetTexture)&&t.material.uniforms.particleTexture.value!==t.targetTexture&&(t.material.uniforms.particleTexture.value=t.targetTexture),t.material.uniforms.debugOpacity.value=c?.2:1,Qe(t),c){t.debugOriginMesh||(t.debugOriginMesh=new x(Ne,Pe),t.debugOriginMesh.frustumCulled=!1,i.add(t.debugOriginMesh)),t.debugOriginMesh.position.set(t.origin[1],t.origin[2],t.origin[0]),t.debugParticleMeshes||=[];let e=Math.min(t.emitter.particles.length,8);for(;t.debugParticleMeshes.length=0;e--){let t=A[e],n=j-t.creationTime,r=Math.min(n/t.lifetimeMS,1),a=Math.min(r/.1,1);t.mesh.scale.setScalar(t.targetRadius*a),t.material.opacity=1-r,t.labelMaterial.opacity=1-r,r>=1&&(i.remove(t.mesh),i.remove(t.label),t.material.dispose(),t.labelMaterial.dispose(),A.splice(e,1))}let N=P.current;for(let t=N.length-1;t>=0;t--){let n=N[t],r=j-n.creationTime,a=Math.min(r/n.lifetimeMS,1),o=h;n.velocity+=n.data.acceleration*o,n.radius+=n.velocity*o;let s=Be(n.data,a);We(n.geometry,n.data,n.radius,s,n.data.is2D),n.bottomGeometry&&We(n.bottomGeometry,n.data,n.radius,s,n.data.is2D),n.data.is2D&&n.mesh.lookAt(e.camera.position),a>=1&&(i.remove(n.mesh),n.bottomMesh&&i.remove(n.bottomMesh),n.geometry.dispose(),n.bottomGeometry?.dispose(),n.material.dispose(),N.splice(t,1))}if(s&&l&&u&&d&&m.current){for(let e of a.entities){if(e.type!==`Explosion`||!e.explosionDataBlockId||!e.position)continue;let t=`snd:${e.id}`;if(D.current.has(t))continue;D.current.add(t);let n=y(e.explosionDataBlockId);if(!n)continue;let r=n.soundProfile;if(typeof r!=`number`)continue;let i=oe(r,y);i&&ae(i,d,u,new p(e.position[1],e.position[2],e.position[0]),m.current)}let e=w.current;for(let t of a.entities){if(t.type!==`Projectile`||!t.dataBlockId||!t.position)continue;if(e.has(t.id)){e.get(t.id).position.set(t.position[1],t.position[2],t.position[0]);continue}if(e.size>=$e)continue;let n=y(t.dataBlockId);if(!n)continue;let r=n.sound;if(typeof r!=`number`)continue;let i=oe(r,y);if(!(!i||!i.isLooping||!i.is3D))try{let n=ee(i.filename),r=ie();re(n,u,n=>{if(r!==ie()||!S.has(t.id)||e.has(t.id))return;let a=m.current;if(!a)return;let s=new T(d);s.setBuffer(n),s.setDistanceModel(`inverse`),s.setRefDistance(i.refDist),s.setMaxDistance(i.maxDist),s.setRolloffFactor(1),s.setVolume(i.volume),s.setPlaybackRate(o.rate),s.setLoop(!0),s.position.set(t.position[1],t.position[2],t.position[0]),a.add(s),ce(s),s.play(),e.set(t.id,s)})}catch{}}for(let[t,n]of e)if(!S.has(t)){le(n);try{n.stop()}catch{}try{n.disconnect()}catch{}m.current?.remove(n),e.delete(t)}for(let e of a.audioEvents){let t=`${e.timeSec}:${e.profileId}:${e.position?.x??``}`;if(D.current.has(t))continue;D.current.add(t);let n=oe(e.profileId,y);n&&ae(n,d,u,e.position?new p(e.position.y,e.position.z,e.position.x):void 0,m.current)}}if(v.current.size>500){let e=new Set(a.entities.map(nt));for(let t of v.current)e.has(t)||v.current.delete(t)}if(D.current.size>500){let e=new Set(a.entities.map(tt));for(let t of D.current)t.startsWith(`snd:`)&&e.has(t.slice(4))||D.current.delete(t)}},t[7]=l,t[8]=d,t[9]=u,t[10]=c,t[11]=f,t[12]=n,t[13]=r,t[14]=F):F=t[14],i(F);let I,L;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(L=()=>()=>{let e=m.current;for(let t of g.current){if(e&&(e.remove(t.mesh),t.debugOriginMesh&&e.remove(t.debugOriginMesh),t.debugParticleMeshes))for(let n of t.debugParticleMeshes)e.remove(n);t.geometry.dispose(),t.material.dispose()}g.current=[];for(let t of M.current)e&&(e.remove(t.mesh),e.remove(t.label)),t.material.dispose(),t.labelMaterial.dispose();M.current=[];for(let t of P.current)e&&(e.remove(t.mesh),t.bottomMesh&&e.remove(t.bottomMesh)),t.geometry.dispose(),t.bottomGeometry?.dispose(),t.material.dispose();P.current=[],v.current.clear(),b.current.clear();for(let[,t]of w.current){le(t);try{t.stop()}catch{}try{t.disconnect()}catch{}e&&e.remove(t)}w.current.clear(),D.current.clear()},I=[],t[15]=I,t[16]=L):(I=t[15],L=t[16]),(0,B.useEffect)(L,I);let R;return t[17]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,G.jsx)(`group`,{ref:m}),t[17]=R):R=t[17],R}function tt(e){return e.id}function nt(e){return e.id}function rt(e){return e.gl}function Y(e,t){return{id:e.id,className:e.className??e.type,ghostIndex:e.ghostIndex,dataBlockId:e.dataBlockId,shapeHint:e.shapeHint,spawnTime:t,position:e.position,rotation:e.rotation,velocity:e.velocity,keyframes:[{time:t??0,position:e.position??[0,0,0],rotation:e.rotation??[0,0,0,1]}]}}function it(e,t){if(e.sceneData){let n={id:e.id,className:e.className??e.type,ghostIndex:e.ghostIndex,dataBlockId:e.dataBlockId,shapeHint:e.shapeHint,spawnTime:t};switch(e.sceneData.className){case`TerrainBlock`:return{...n,renderType:`TerrainBlock`,terrainData:e.sceneData};case`InteriorInstance`:return{...n,renderType:`InteriorInstance`,interiorData:e.sceneData};case`Sky`:return{...n,renderType:`Sky`,skyData:e.sceneData};case`Sun`:return{...n,renderType:`Sun`,sunData:e.sceneData};case`WaterBlock`:return{...n,renderType:`WaterBlock`,waterData:e.sceneData};case`MissionArea`:return{...n,renderType:`MissionArea`,missionAreaData:e.sceneData};case`TSStatic`:return{...Y(e,t),renderType:`Shape`,shapeName:e.sceneData.shapeName,shapeType:`TSStatic`,dataBlock:e.dataBlock}}}return e.visual?.kind===`tracer`?{...Y(e,t),renderType:`Tracer`,visual:e.visual,dataBlock:e.dataBlock,direction:e.direction}:e.visual?.kind===`sprite`?{...Y(e,t),renderType:`Sprite`,visual:e.visual}:e.type===`Player`?{...Y(e,t),renderType:`Player`,shapeName:e.dataBlock,dataBlock:e.dataBlock,weaponShape:e.weaponShape,packShape:e.packShape,flagShape:e.flagShape,falling:e.falling,jetting:e.jetting,playerName:e.playerName,iffColor:e.iffColor,threads:e.threads,weaponImageState:e.weaponImageState,weaponImageStates:e.weaponImageStates,headPitch:e.headPitch,headYaw:e.headYaw,targetRenderFlags:e.targetRenderFlags}:e.type===`Explosion`?{...Y(e,t),renderType:`Explosion`,shapeName:e.dataBlock,dataBlock:e.dataBlock,explosionDataBlockId:e.explosionDataBlockId,faceViewer:e.faceViewer}:e.className===`ForceFieldBare`?{...Y(e,t),renderType:`ForceFieldBare`}:e.className===`AudioEmitter`?{...Y(e,t),renderType:`AudioEmitter`,audioFileName:e.audioFileName,audioVolume:e.audioVolume,audioIs3D:e.audioIs3D,audioIsLooping:e.audioIsLooping??!0,audioMinDistance:e.audioMinDistance,audioMaxDistance:e.audioMaxDistance,audioMinLoopGap:e.audioMinLoopGap,audioMaxLoopGap:e.audioMaxLoopGap}:e.className===`WayPoint`?{...Y(e,t),renderType:`WayPoint`,label:e.label}:e.className===`Camera`?{...Y(e,t),renderType:`Camera`}:{...Y(e,t),renderType:`Shape`,shapeName:e.dataBlock,shapeType:e.className===`Turret`?`Turret`:e.className===`Item`?`Item`:`StaticShape`,dataBlock:e.dataBlock,weaponShape:e.weaponShape,threads:e.threads,targetRenderFlags:e.targetRenderFlags,iffColor:e.iffColor}}function at(e,t){return e[t]}function ot(e,t){switch(e.renderType){case`Player`:{let n=e;n.threads=t.threads,n.weaponShape=t.weaponShape,n.packShape=t.packShape,n.flagShape=t.flagShape,n.falling=t.falling,n.jetting=t.jetting,n.weaponImageState=t.weaponImageState,n.weaponImageStates=t.weaponImageStates,n.playerName=t.playerName,n.iffColor=t.iffColor,n.headPitch=t.headPitch,n.headYaw=t.headYaw,n.targetRenderFlags=t.targetRenderFlags;break}case`Shape`:{let n=e;n.threads=t.threads,n.targetRenderFlags=t.targetRenderFlags,n.iffColor=t.iffColor;break}}}var st=new WeakMap;function ct(e){let t=st.get(e);return t||(t=new Map(e.entities.map(e=>[e.id,e])),st.set(e,t)),t}function lt(e){F.getState().setAllStreamEntities(Array.from(e.values()))}var ut=new p,X=new w,Z=new w,dt=new w(0,1,0,0),Q=new p,$=new p,ft=new p;function pt(e){let t=(0,de.c)(25),{recording:n}=e,r=D(),a=(0,B.useRef)(0),o=(0,B.useRef)(null),s=(0,B.useRef)(null),c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=new p(0,R,0),t[0]=c):c=t[0];let l=(0,B.useRef)(c),u=(0,B.useRef)(n.streamingPlayback??null),d=(0,B.useRef)(null),f;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(f=new Map,t[1]=f):f=t[1];let m=(0,B.useRef)(f),h=(0,B.useRef)(null),[g,_]=(0,B.useState)(null),v;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(v=e=>{if(e===h.current)return;h.current=e;let t=m.current,n=new Map;for(let r of e.entities){let i=t.get(r.id),a=i&&(i.renderType===`Shape`||i.renderType===`Player`||i.renderType===`Explosion`);if(!i||i.className!==(r.className??r.type)||i.ghostIndex!==r.ghostIndex||i.dataBlockId!==r.dataBlockId||i.shapeHint!==r.shapeHint||a&&r.dataBlock!=null&&at(i,`shapeName`)!==r.dataBlock||i.renderType!==`Player`&&a&&at(i,`weaponShape`)!==r.weaponShape?i=it(r,e.timeSec):ot(i,r),n.set(r.id,i),N(i)||i.renderType===`None`)continue;let o=i.keyframes;o.length===0&&o.push({time:e.timeSec,position:r.position??[0,0,0],rotation:r.rotation??[0,0,0,1]});let s=o[0];s.time=e.timeSec,r.position&&(s.position=r.position),r.rotation&&(s.rotation=r.rotation),s.velocity=r.velocity,s.health=r.health,s.energy=r.energy,s.actionAnim=r.actionAnim,s.actionAtEnd=r.actionAtEnd,s.damageState=r.damageState}for(let[r,i]of t)if(!n.has(r)&&i.renderType===`Explosion`&&i.shapeName&&i.spawnTime!=null&&e.timeSec-i.spawnTime<5){n.set(r,i);continue}let r=n.size!==t.size||[...n.keys()].some(e=>!t.has(e));m.current=n,r&<(n);let i=null;if(e.camera?.mode===`first-person`&&e.camera.controlEntityId){let t=n.get(e.camera.controlEntityId),r=t?at(t,`shapeName`):void 0;r&&(i=r)}_(e=>e===i?e:i)},t[2]=v):v=t[2];let y=v,b;t[3]!==r||t[4]!==n.gameType||t[5]!==n.missionName||t[6]!==n.recorderName||t[7]!==n.recordingDate||t[8]!==n.serverDisplayName||t[9]!==n.source||t[10]!==n.streamingPlayback?(b=()=>{se(),u.current=n.streamingPlayback??null,m.current=new Map,h.current=null,d.current=null,I(),a.current=0,o.current=null,s.current=null;let e=u.current;if(z.setState({playback:e}),F.getState().beginStreaming(n.source),!e){r.getState().setPlaybackStreamSnapshot(null);return}e.onMissionInfoChange=()=>{F.getState().setMissionInfo({missionDisplayName:e.missionDisplayName??void 0,missionTypeDisplayName:e.missionTypeDisplayName??void 0,gameClassName:e.gameClassName??void 0,recorderName:e.connectedPlayerName??void 0})};let t=e.missionDisplayName,i=e.missionTypeDisplayName,c=e.gameClassName,l=e.serverDisplayName,f=e.connectedPlayerName;n.source!==`live`&&e.reset(),e.missionDisplayName=t,e.missionTypeDisplayName=i,e.gameClassName=c,e.serverDisplayName=l,e.connectedPlayerName=f,F.getState().setMissionInfo({missionName:n.missionName??void 0,missionTypeDisplayName:n.gameType??void 0,missionDisplayName:t??void 0,gameClassName:c??void 0,serverDisplayName:l??n.serverDisplayName??void 0,recorderName:f??n.recorderName??void 0,recordingDate:n.recordingDate??void 0});let p=e.getSnapshot();return z.setState({time:p.timeSec}),a.current=p.timeSec,o.current=p,s.current=p,y(p),r.getState().setPlaybackStreamSnapshot(p),d.current=p,()=>{se(),u.current=null,I()}},t[3]=r,t[4]=n.gameType,t[5]=n.missionName,t[6]=n.recorderName,t[7]=n.recordingDate,t[8]=n.serverDisplayName,t[9]=n.source,t[10]=n.streamingPlayback,t[11]=b):b=t[11];let x;t[12]!==r||t[13]!==n?(x=[n,r,y],t[12]=r,t[13]=n,t[14]=x):x=t[14],(0,B.useEffect)(b,x);let S;t[15]!==r||t[16]!==n.source?(S=(e,t)=>{let i=u.current;if(!i)return;let c=r.getState(),f=c.playback,p=f.status===`playing`,h=f.timeMs/1e3,g=!p&&Math.abs(h-a.current)>5e-4,_=p&&Math.abs(h-z.getState().time)>.05,v=g||_;v&&(a.current=h),p&&(A(t,f.rate),a.current+=t*f.rate);let b=Math.max(1,Math.ceil(t*1e3*Math.max(f.rate,.01)/32)+2),x=a.current+te,S=i.stepToTime(x,p&&!v?b:1/0),C=s.current;!C||S.timeSec.032*1.5?(o.current=S,s.current=S):S.timeSec!==C.timeSec&&(o.current=C,s.current=S);let w=s.current??S,T=o.current??w,E=w.timeSec-te,D=Math.max(0,Math.min(1,(a.current-E)/te));z.setState({time:a.current}),S.exhausted&&p&&(a.current=Math.min(a.current,S.timeSec)),y(w),z.getState().entities=m.current,w!==d.current&&(d.current=w,c.setPlaybackStreamSnapshot(w));let O=w.camera,k=O&&T.camera&&T.camera.mode===O.mode&&T.camera.controlEntityId===O.controlEntityId&&T.camera.orbitTargetId===O.orbitTargetId?T.camera:null,j=z.getState().freeFlyCamera,M=n.source===`live`;if(O&&!j){if(!M)if(k){let t=k.position[0],n=k.position[1],r=k.position[2],i=O.position[0],a=O.position[1],o=O.position[2],s=t+(i-t)*D,c=n+(a-n)*D,l=r+(o-r)*D;e.camera.position.set(c,l,s),X.set(...k.rotation),Z.set(...O.rotation),X.slerp(Z,D),e.camera.quaternion.copy(X)}else e.camera.position.set(O.position[1],O.position[2],O.position[0]),e.camera.quaternion.set(...O.rotation);if(Number.isFinite(O.fov)&&`isPerspectiveCamera`in e.camera&&e.camera.isPerspectiveCamera){let t=e.camera,n=ne(k&&Number.isFinite(k.fov)?k.fov+(O.fov-k.fov)*D:O.fov,t.aspect);Math.abs(t.fov-n)>.01&&(t.fov=n,t.updateProjectionMatrix())}}let ee=ct(w),P=ct(T),F=m.current,I=z.getState().root;if(I)for(let t of I.children){let n=F.get(t.name);if(n&&N(n))continue;let r=ee.get(t.name);if(!r){let e=n&&`keyframes`in n?n.keyframes:void 0;if(e?.[0]?.position){let n=e[0];t.visible=!0,t.position.set(n.position[1],n.position[2],n.position[0]);continue}}if(!r?.position){t.visible=!1;continue}t.visible=!0;let i=P.get(t.name);if(i?.position){let e=i.position[0],n=i.position[1],a=i.position[2],o=r.position[0],s=r.position[1],c=r.position[2],l=e+(o-e)*D,u=n+(s-n)*D,d=a+(c-a)*D;t.position.set(u,d,l)}else t.position.set(r.position[1],r.position[2],r.position[0]);r.faceViewer?t.quaternion.copy(e.camera.quaternion).multiply(dt):r.visual?.kind===`tracer`?t.quaternion.identity():r.rotation&&(i?.rotation?(X.set(...i.rotation),Z.set(...r.rotation),X.slerp(Z,D),t.quaternion.copy(X)):t.quaternion.set(...r.rotation))}let L=O?.mode;if(!j&&!M&&L===`third-person`&&I&&O?.orbitTargetId){let t=I.children.find(e=>e.name===O.orbitTargetId);if(t){let n=ee.get(O.orbitTargetId);$.copy(t.position),n?.type===`Player`&&($.y+=1);let r=!1;if(O.orbitDirection)Q.set(O.orbitDirection[0],O.orbitDirection[1],O.orbitDirection[2]),r=Q.lengthSq()>1e-8;else if(typeof O.yaw==`number`&&typeof O.pitch==`number`){let e=Math.sin(O.pitch),t=Math.cos(O.pitch),n=Math.sin(O.yaw),i=Math.cos(O.yaw);Q.set(-i*t,-e,-n*t),r=Q.lengthSq()>1e-8}if(r||=(Q.copy(e.camera.position).sub($),Q.lengthSq()>1e-8),r){Q.normalize();let t=Math.max(.1,O.orbitDistance??4);ft.copy($).addScaledVector(Q,t),e.camera.position.copy(ft),e.camera.lookAt($)}}}if(!j&&L===`first-person`&&I&&O?.controlEntityId){let t=I.children.find(e=>e.name===O.controlEntityId);t?(ut.copy(l.current).applyQuaternion(t.quaternion),e.camera.position.add(ut)):e.camera.position.y=e.camera.position.y+l.current.y}p&&S.exhausted&&c.setPlaybackStatus(`paused`);let R=a.current*1e3;Math.abs(R-f.timeMs)>.5&&c.setPlaybackTime(R)},t[15]=r,t[16]=n.source,t[17]=S):S=t[17],i(S);let C;t[18]===n.streamingPlayback?C=t[19]:(C=(0,G.jsx)(et,{playback:n.streamingPlayback,snapshotRef:s}),t[18]=n.streamingPlayback,t[19]=C);let w;t[20]===g?w=t[21]:(w=g&&(0,G.jsx)(B.Suspense,{children:(0,G.jsx)(ue,{shapeName:g,eyeOffsetRef:l})}),t[20]=g,t[21]=w);let T;return t[22]!==C||t[23]!==w?(T=(0,G.jsxs)(G.Fragment,{children:[C,w]}),t[22]=C,t[23]=w,t[24]=T):T=t[24],T}export{pt as StreamingController};