@korial29/tiny-fps 0.19.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,54 +1,54 @@
1
- var e=.4,t=1.8,n=1.55,r=.9,i=7.5,a=5.5,o=[`Red`,`Blue`],s=[`#ff3d4f`,`#2f80ff`],c=1.5,l={HOME:0,CARRIED:1,DROPPED:2},u={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,SPRINT:32,DASH:64,CROUCH:128},d={GROUND:0,AIR:1,WALLRUN:2,HANG:3,CLIMB:4,SLIDE:5,CROUCH:6},f={NONE:0,EAST:1,WEST:2,SOUTH:3,NORTH:4},p={JUMP:1,DOUBLE:2,DASH:4,LAND:8,GRAB:16,CLIMB:32,WALLRUN_START:64,WALLRUN_END:128,SLIDE_START:256,SLIDE_END:512,RESPAWN:1024},m={BRICK:0,TILE:1,LAVA:2,STONE:3,METAL:4,WOOD:5,MOSS:6,GRATE:7},h=-30,g=(e,t,n,r,i)=>({min:[e,h,t],max:[n,i,r],top:m.TILE,side:m.BRICK}),_=([e,t,n],[r,i,a],o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c}),v={name:`Rooftops`,brushes:[g(4,57.7,24,76,10),g(4,36,24,53.5,10),g(4,20,24,36,12.4),g(4,-5,24,7,12.4),g(27,20,47,50,8),g(27,60,47,76,8),_([9,12.2,39],[19,12.6,47],m.METAL,m.METAL),...((e,t)=>[1,2,3,4,5,6].map(n=>_([12,t,e-n],[14,t+.4*n,e-n+1],m.STONE,m.STONE)))(53,10),_([5,10,42],[5.5,14,42.5],m.METAL),_([5,10,50],[5.5,14,50.5],m.METAL),_([8,12.4,24],[20,12.85,24.45],m.METAL),_([36,8,22],[37,14.5,48],m.STONE,m.STONE,[1,.75,.62]),_([30,8,28],[34,10,32],m.STONE,m.BRICK),_([40,8,30],[44,10.2,34],m.STONE,m.BRICK),_([28,9.2,44],[35,12,46],m.METAL,m.GRATE,[.8,.9,1]),_([41.5,7.6,50],[42,8,60],m.METAL),_([30,8,64],[34,9.6,68],m.STONE,m.BRICK)],teams:[{base:[14,10,62.5],spawns:[[6,10,72,0],[10,10,72,0],[14,10,72,0],[18,10,72,0],[22,10,72,0],[8,10,66,0],[14,10,66,0],[20,10,66,0]]},{base:[14,12.4,2.2],spawns:[[6,12.4,-3,Math.PI],[10,12.4,-3,Math.PI],[14,12.4,-3,Math.PI],[18,12.4,-3,Math.PI],[22,12.4,-3,Math.PI],[8,12.4,.5,Math.PI],[14,12.4,.5,Math.PI],[20,12.4,.5,Math.PI]]}],floor:-25,sun:{dir:[.6,.64,.48],color:[3,2.7,2.2]},sky:[[.12,.3,.75],[.7,.82,.95]],fog:[.7,.82,.95,.008]},y=4,b=1024,x=(e,t)=>(e+b)*(2*b)+t+b,S=(e,t)=>Math.min(Math.max(Math.floor(e/t),-1024),1023),C=(e,t=y)=>{let n=/* @__PURE__ */ new Map;return e.brushes.forEach(({min:e,max:r},i)=>{for(let a=S(e[0],t);a<=S(r[0],t);a++)for(let o=S(e[2],t);o<=S(r[2],t);o++){let e=x(a,o),t=n.get(e);t?t.push(i):n.set(e,[i])}}),{def:e,cell:t,grid:n}},w=(e,t,n,r)=>{let i=[];for(let a=S(t-r,e.cell);a<=S(t+r,e.cell);a++)for(let t=S(n-r,e.cell);t<=S(n+r,e.cell);t++)for(let n of e.grid.get(x(a,t))??[])i.includes(n)||i.push(n);return i},T=(e,t,n,r)=>{let{cell:i,def:a}=e,o=r,s=S(t[0],i),c=S(t[2],i),l=Math.sign(n[0]),u=Math.sign(n[2]),d=l?((s+ +(l>0))*i-t[0])/n[0]:1/0,f=u?((c+ +(u>0))*i-t[2])/n[2]:1/0,p=d,m=f,h=l?i/Math.abs(n[0]):1/0,g=u?i/Math.abs(n[2]):1/0;for(;;){for(let r of e.grid.get(x(s,c))??[]){let e=a.brushes[r],[i,s]=[0,o];for(let r=0;r<3&&i<=s;r++){if(!n[r]){(t[r]<e.min[r]||t[r]>e.max[r])&&(s=-1);continue}let a=(e.min[r]-t[r])/n[r],o=(e.max[r]-t[r])/n[r];i=Math.max(i,Math.min(a,o)),s=Math.min(s,Math.max(a,o))}i<=s&&s>0&&i<o&&(o=i)}if(Math.min(p,m)>=o||Math.abs(s)>b||Math.abs(c)>b)return o;p<m?(s+=l,p+=h):(c+=u,m+=g)}},ee=(e,t,n)=>{let[r,i,a]=[n[0]-t[0],n[1]-t[1],n[2]-t[2]],o=Math.hypot(r,i,a);return o>0&&T(e,t,[r/o,i/o,a/o],o)<o-1e-4},E=1/60,D=Math.PI*2,O=1e-6,k=.01,A=.001,j=e=>(e%D+D)%D,te=e=>[-Math.sin(e),-Math.cos(e)],M=Math.fround,N=Math.sqrt,P=(e,t,n)=>Math.min(Math.max(e,t),n),F=(e,t)=>N(e*e+t*t),I=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],ne={vx:0,vz:0,mode:d.GROUND,t:0,wall:f.NONE,edge:0,jumps:1,dashes:1,dash:0,coyote:6,buffer:0,held:0,ev:0,fall:0},re=(e,t,n,r=0)=>{let{spawns:i}=t.def.teams[r],[a,o,s,c]=i[(n%i.length+i.length)%i.length];return{id:e,x:M(a),y:M(o),z:M(s),vy:0,yaw:j(c),pitch:0,ground:!0,...ne}},L=e=>e===d.GROUND||e===d.SLIDE||e===d.CROUCH,ie=e=>e.mode===d.SLIDE||e.mode===d.CROUCH?r:t,ae=e=>e.mode===d.SLIDE||e.mode===d.CROUCH?.7:1.6,oe=e=>F(e.vx,e.vz),se=e=>e.mode===d.GROUND&&F(e.vx,e.vz)>6.5,ce=(e,t,n)=>e.max[1]>t+.5+k&&e.min[1]<t+n-k,le=(e,t,n)=>[t-P(t,e.min[0],e.max[0]),n-P(n,e.min[2],e.max[2])],ue=(t,n,r)=>{let{brushes:i}=n.def,a=w(n,t.x,t.z,2*e),o=(e-O)**2,[s,c]=[0,0];for(let n=0;n<4;n++){let n=0,l=0,u=0;for(let s of a){let a=i[s];if(!ce(a,t.y,r))continue;let[c,d]=le(a,t.x,t.z),f=c*c+d*d;if(f>=o)continue;if(f){let t=N(f);.4-t>n&&(n=e-t,l=c/t*n,u=d/t*n);continue}let[p,m,h]=[[t.x-a.min[0],-1,0],[a.max[0]-t.x,1,0],[t.z-a.min[2],0,-1],[a.max[2]-t.z,0,1]].reduce((e,t)=>t[0]<e[0]?t:e);p+.4>n&&(n=p+e,[l,u]=[m*n,h*n])}if(!n)break;t.x+=l,t.z+=u,s+=l,c+=u}return[s,c]},de=(t,n,r)=>{let{brushes:i}=n.def,a=(e-O)**2,o=-1/0,s=1/0;for(let c of w(n,t.x,t.z,e)){let e=i[c],[n,l]=le(e,t.x,t.z);n*n+l*l>=a||(e.max[1]<=t.y+.5+k?o=Math.max(o,e.max[1]):e.min[1]>=t.y+r-k&&(s=Math.min(s,e.min[1])))}return[o,s]},fe=(t,n)=>{let r=(e-O)**2;return w(n,t.x,t.z,e).every(e=>{let i=n.def.brushes[e],[a,o]=le(i,t.x,t.z);return a*a+o*o>=r||!ce(i,t.y,1.8)})},pe=(t,n,r,i,a)=>{let o=(e-O)**2;return w(t,n,r,e).every(e=>{let s=t.def.brushes[e],[c,l]=le(s,n,r);return c*c+l*l>=o||s.max[1]<=i||s.min[1]>=a})},me=(e,t)=>{let[n,r]=I[t],i=n?0:2;return{a:i,o:2-i,sign:n||r,c:n?e.x:e.z,co:n?e.z:e.x}},he=(e,t,n,r)=>{let{a:i,o:a,sign:o,c:s,co:c}=me(t,n),l=((o>0?e.min[i]:e.max[i])-s)*o;return l>=.4-A&&l<=.4+r&&c>=e.min[a]&&c<=e.max[a]?l:void 0},ge=(t,n,r)=>{let i;for(let a of w(n,t.x,t.z,.9)){let o=n.def.brushes[a],s=he(o,t,r,.5);s!==void 0&&o.min[1]<t.y+.5&&o.max[1]>t.y+1.8&&(i=Math.min(i??1/0,Math.max(0,s-e)))}return i},_e=(e,t)=>{let[n,r]=te(e.yaw),i;for(let a=1;a<=4;a++){let[o,s]=I[a];if(a===e.wall||n*o+r*s<.5)continue;let{a:c,sign:l}=me(e,a);for(let n of w(t,e.x,e.z,.6000000000000001)){let r=t.def.brushes[n],o=r.max[1],s=o-e.y;if(he(r,e,a,.2)===void 0||s<1.2||s>2.4||r.min[1]>o-.25||i&&i.top>=o)continue;let u=l>0?r.min[c]:r.max[c],d=u-l*.43000000000000005,f=u+l*.2,[p,m]=c===0?[d,e.z]:[e.x,d],[h,g]=c===0?[f,e.z]:[e.x,f];pe(t,p,m,Math.min(e.y,o-2)+k,o+1.8)&&pe(t,h,g,o+k,o+1.8)&&(i={side:a,top:o,hang:d})}}return i},ve=(e,t)=>{let{a:n,o:r,sign:i,c:a,co:o}=me(e,e.wall);return w(t,e.x,e.z,0).some(s=>{let c=t.def.brushes[s],l=i>0?a-c.min[n]:c.max[n]-a;return M(c.max[1])===e.edge&&o>=c.min[r]&&o<=c.max[r]&&l>=.2})},ye=(e,n)=>{if(e.vy>=0)return!1;let[r]=de(e,n,t),i=6*E;return e.y-r<=-e.vy*i+10*i*i},R=(e,t)=>{e.mode=t,e.t=0},be=(e,t)=>{let n=F(e.vx,e.vz);n>t&&(e.vx*=t/n,e.vz*=t/n)},xe=(t,n,r,i)=>{let[a,o]=[r.wx,r.wz];for(let r of w(n,t.x,t.z,e+A)){let e=n.def.brushes[r],[s,c]=le(e,t.x,t.z),l=F(s,c);if(l>0&&l<=.4+A&&ce(e,t.y,i)){let e=(-a*s-o*c)/l;e>0&&(a+=e*s/l,o+=e*c/l)}}return[a,o]},Se=(e,t,n)=>{let r=F(t[0],t[1]);if(r<O){let t=F(e.vx,e.vz),n=t?Math.max(0,t-45*E)/t:0;e.vx*=n,e.vz*=n;return}let[i,a]=[t[0]/r,t[1]/r],o=e.vx*i+e.vz*a,[s,c]=[e.vx-o*i,e.vz-o*a],l=F(s,c);if(l){let e=Math.max(0,l-45*E)/l;[s,c]=[s*e,c*e]}n*=r,o=o<n?Math.min(n,o+(o>=6?3:50)*E):Math.max(n,o-12*E),e.vx=s+o*i,e.vz=c+o*a},Ce=(e,t,n,r,i)=>{let a=e.y;e.x+=e.vx*E,e.z+=e.vz*E;let[o,s]=ue(e,t,n),c=F(o,s);if(c){let t=(e.vx*o+e.vz*s)/c;t<0&&(e.vx-=t*o/c,e.vz-=t*s/c)}let[l,u]=de(e,t,n),d=e.vy-r*20*E;if(e.y+=(e.vy+d)/2*E,e.vy=d,e.y+n>u&&(e.y=u-n,e.vy=Math.min(e.vy,0)),e.vy<=0?e.y<=l+k:e.y<l){if(e.y=l,e.vy<=0){let t=-e.vy;return e.vy=0,t}}else if(i&&e.vy<=0&&l>=a-.5)return e.y=l,e.vy=0,0;return-1},we=(e,t)=>{e.vy=t,e.coyote=0,e.buffer=0,e.ev|=p.JUMP},Te=(e,n,r)=>{let[i,a]=I[e.wall],o=t=>{R(e,t),e.edge=0};if(r.keys&(u.BACK|u.CROUCH))o(d.AIR),e.coyote=0;else if(r.jump&&r.fx*i+r.fz*a<0)o(d.AIR),e.vx=-i*4,e.vz=-a*4,we(e,6);else if(r.jump||r.fwd&&e.t>=6)R(e,d.CLIMB);else if(e.t>=30)o(d.AIR),e.coyote=0;else{let r=Math.max(e.edge-2,de(e,n,t)[0]);e.y+=P(r-e.y,-8*E,8*E)}},Ee=(e,t)=>{let[n,r]=I[e.wall];e.y<e.edge?e.y=Math.min(e.edge,e.y+8*E):(e.x+=n*a*E,e.z+=r*a*E),e.y>=e.edge&&ve(e,t)?(R(e,d.GROUND),e.vx=n*3,e.vz=r*3,e.vy=0,e.edge=0,e.wall=f.NONE,e.coyote=6,e.ev|=p.CLIMB):e.t>=40&&(R(e,e.y>=e.edge?d.GROUND:d.AIR),e.edge=0,e.wall=f.NONE)},De=(e,t,n)=>{let[r,i]=I[e.wall],a=e.vx*r+e.vz*i,[o,s]=[e.vx-a*r,e.vz-a*i],c=F(o,s);if(n.jump)R(e,d.AIR),e.vx=o-r*5,e.vz=s-i*5,we(e,6.5),e.jumps=1,e.dashes=1,e.ev|=p.WALLRUN_END;else{let a=ge(e,t,e.wall);if(a===void 0||!n.fwd||c<3.5||e.t>=60){R(e,d.AIR),e.ev|=p.WALLRUN_END;return}let l=Math.max(0,c-1.5*E)/c;e.vx=o*l,e.vz=s*l;let u=Math.min(a,4*E);e.x+=r*u,e.z+=i*u}},Oe=(e,t,n)=>{if(!n.fwd)return;let r=F(e.vx,e.vz);if(!(r<4.5))for(let n=1;n<=4;n++){let[i,a]=I[n],o=e.vx*i+e.vz*a,[s,c]=[e.vx-o*i,e.vz-o*a];if(n!==e.wall&&o<=.75*r&&o>=-.2*r&&ge(e,t,n)!==void 0){let t=F(s,c),i=Math.max(t,.9*r)/t;R(e,d.WALLRUN),e.wall=n,[e.vx,e.vz]=[s*i,c*i],e.vy=P(e.vy,2,3),e.jumps=1,e.dashes=1,e.coyote=0,e.ev|=p.WALLRUN_START;return}}},ke=(e,t)=>{R(e,d.HANG),e.wall=t.side,e.edge=M(t.top),t.side<=f.WEST?e.x=t.hang:e.z=t.hang,e.vx=e.vy=e.vz=0,e.jumps=1,e.dashes=1,e.coyote=0,e.buffer=0,e.ev|=p.GRAB},Ae=(e,t,n)=>{let r=e.mode===d.GROUND;if(n.dash&&e.dash===0&&(r||(e.mode===d.AIR||e.mode===d.WALLRUN)&&e.dashes>0)){let[t,i]=n.wx||n.wz?[n.wx,n.wz]:[n.fx,n.fz];r||(e.dashes--,e.vy=0,e.mode===d.WALLRUN&&(R(e,d.AIR),e.ev|=p.WALLRUN_END)),e.vx=t*16,e.vz=i*16,e.dash=60,e.ev|=p.DASH}let a=e.dash>50;e.mode===d.WALLRUN&&De(e,t,n),L(e.mode)&&je(e,t,n,a),e.mode===d.AIR&&Me(e,t,n,a);let o=a&&e.vy<=0?0:e.mode===d.WALLRUN?.15:1,s=e.mode,c=Ce(e,t,ie(e),o,L(s));if(c>=0){if(!L(e.mode)){if(e.ev|=p.LAND|(e.mode===d.WALLRUN?p.WALLRUN_END:0),e.fall=c,e.jumps=1,e.dashes=1,e.wall=f.NONE,n.keys&u.CROUCH){let t=F(e.vx,e.vz)>=i;R(e,t?d.SLIDE:d.CROUCH),e.ev|=t?p.SLIDE_START:0}else R(e,d.GROUND)}e.coyote=6}else L(e.mode)&&(e.ev|=e.mode===d.SLIDE?p.SLIDE_END:0,R(e,d.AIR));if(e.mode===d.AIR){let r=_e(e,t);r?ke(e,r):Oe(e,t,n)}},je=(e,n,a,o)=>{let s=(a.keys&u.CROUCH)!==0;if(e.buffer>0&&(e.mode===d.GROUND||fe(e,n))){e.ev|=e.mode===d.SLIDE?p.SLIDE_END:0,R(e,d.AIR),we(e,7);return}let c=F(e.vx,e.vz);if(e.mode===d.GROUND&&s){let t=c>=i;R(e,t?d.SLIDE:d.CROUCH),e.ev|=t?p.SLIDE_START:0}else e.mode===d.SLIDE&&(e.t>=60||c<4.5)?(e.ev|=p.SLIDE_END,R(e,!s&&fe(e,n)?d.GROUND:d.CROUCH)):e.mode===d.SLIDE&&!s&&fe(e,n)?(e.ev|=p.SLIDE_END,R(e,d.GROUND)):e.mode===d.CROUCH&&!s&&fe(e,n)&&R(e,d.GROUND);if(!o){if(e.mode===d.SLIDE){let t=Math.max(0,c-4*E)/c;e.vx*=t,e.vz*=t}else if(e.mode===d.CROUCH)Se(e,xe(e,n,a,r),3);else{let r=(a.keys&u.SPRINT)!==0&&a.fwd;Se(e,xe(e,n,a,t),r?9:6)}}},Me=(e,t,n,r)=>{if(e.buffer>0&&(e.coyote>0?we(e,7):e.jumps>0&&!ye(e,t)&&(e.jumps--,we(e,6),e.ev=e.ev&~p.JUMP|p.DOUBLE)),r||!n.wx&&!n.wz)return;let i=F(e.vx,e.vz);e.vx+=n.wx*14*E,e.vz+=n.wz*14*E,be(e,Math.max(i,6))},Ne=(e,t,r,i=0)=>{e.yaw=j(t.yaw),e.pitch=Math.max(-1.55,Math.min(n,t.pitch));let a=(t.keys&u.FORWARD?1:0)-(t.keys&u.BACK?1:0),o=(t.keys&u.RIGHT?1:0)-(t.keys&u.LEFT?1:0),s=F(a,o)||1,[c,l]=te(e.yaw),f=n=>(t.keys&n)!==0&&(e.held&n)===0,m={keys:t.keys,jump:f(u.JUMP),dash:f(u.DASH),fwd:a>0,wx:(c*a-l*o)/s,wz:(l*a+c*o)/s,fx:c,fz:l},h=e.mode;if(e.ev=0,e.fall=0,m.jump&&(e.buffer=7),e.dash>0&&(e.dash--,e.dash===50&&be(e,10)),e.mode===d.HANG&&Te(e,r,m),e.mode===d.CLIMB?Ee(e,r):e.mode!==d.HANG&&Ae(e,r,m),e.y<r.def.floor){let{yaw:t,pitch:n,id:a}=e;Object.assign(e,re(a,r,a,i),{yaw:t,pitch:n,ev:e.ev|p.RESPAWN})}e.t=e.mode===h?Math.min(255,e.t+1):e.t,e.buffer=Math.max(0,e.buffer-1),e.mode===d.AIR&&h===d.AIR&&(e.coyote=Math.max(0,e.coyote-1)),e.held=t.keys&(u.JUMP|u.DASH),e.ground=L(e.mode),e.x=M(e.x),e.y=M(e.y),e.z=M(e.z),e.vx=M(e.vx),e.vy=M(e.vy),e.vz=M(e.vz),e.edge=M(e.edge)},Pe=16,Fe=65536/(2*Math.PI),Ie=e=>Math.round(e*Fe)&65535,Le=e=>Math.max(-32768,Math.min(32767,Math.round(e))),Re=e=>Le(e*1e4),ze=e=>e/1e4,Be=e=>e/Fe,Ve=(e=0)=>Math.round(e*256)&16777215,He=e=>({...e,yaw:Be(Ie(e.yaw)),pitch:ze(Re(e.pitch)),...e.view!==void 0&&{view:Ve(e.view)/256}}),Ue=e=>{let t=/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(11));t.setUint8(0,1),t.setUint16(1,e.seq&65535),t.setUint8(3,e.keys&255),t.setUint16(4,Ie(e.yaw)),t.setInt16(6,Re(e.pitch));let n=Ve(e.view);return t.setUint16(8,n>>8),t.setUint8(10,n&255),t.buffer},We=e=>e===l.CARRIED?2:e===l.DROPPED?8:1,Ge=e=>{if(e.byteLength<4)return null;let t=new DataView(e),n=t.getUint8(3),r=4+39*n;if(t.getUint8(0)!==2||e.byteLength<r+4+2)return null;let i=[];for(let e=0;e<n;e++){let n=4+e*39,r=t.getUint8(n+35),a=t.getUint8(n+38),o=r&7;i.push({id:t.getUint8(n),x:t.getFloat32(n+1),y:t.getFloat32(n+5),z:t.getFloat32(n+9),vx:t.getFloat32(n+13),vy:t.getFloat32(n+17),vz:t.getFloat32(n+21),edge:t.getFloat32(n+25),yaw:Be(t.getUint16(n+29)),pitch:ze(t.getInt16(n+31)),ack:t.getUint16(n+33),ground:o===d.GROUND||o===d.SLIDE||o===d.CROUCH,mode:o,wall:r>>3&7,jumps:r>>6&1,dashes:r>>7,t:t.getUint8(n+36),dash:t.getUint8(n+37),coyote:a&7,buffer:a>>3&7,held:(a&64?u.JUMP:0)|(a&128?u.DASH:0),ev:0,fall:0})}let a=t.getUint16(r+2),o=r+4,s=[];for(let n=0;n<2;n++){let n=o<e.byteLength?t.getUint8(o):-1;if(n<0||n>l.DROPPED||o+We(n)>e.byteLength)return null;let r={state:n,by:0,x:0,y:0,z:0,left:0};n===l.CARRIED?r.by=t.getUint8(o+1):n===l.DROPPED&&([r.x,r.y,r.z]=[1,3,5].map(e=>t.getInt16(o+e)/Pe),r.left=t.getUint8(o+7)),s.push(r),o+=We(n)}return o===e.byteLength?{tick:t.getUint16(1),players:i,score:[t.getUint8(r),t.getUint8(r+1)],clock:a&32767,over:!!(a&32768),flags:s}:null},Ke=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},qe=44100,Je=([e,t,n,r,i,a,o,s,c,l,u],d)=>{let f=new Float32Array(Math.ceil((r+i+a)*qe)),p=0,m=0,h=0,g=()=>{d=d+1831565813|0;let e=Math.imul(d^d>>>15,1|d);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/2**31-1};for(let d=0;d<f.length;d++){let _=d/qe;p+=t*2**(n*_)*(_>c?l:1)*(1+o*Math.sin(_*44))/qe,p>=1&&(p%=1,h=g());let v=e==3?h:e==2?Math.sin(p*2*Math.PI):e?1-2*p:p<.5?1:-1;m+=(v-m)*s;let y=_<r?_/r:_<r+i?1:((r+i+a-_)/a)**2;f[d]=m*y*u}return f},z={STEP:0,WALLSTEP:1,JUMP:2,DOUBLE:3,DASH:4,LAND:5,GRAB:6,SCUFF:7,WIND:8,SCRAPE:9,TAKE:10,DROP:11,RETURN:12,CAPTURE:13},Ye=[[[2,130,-3,.001,.005,.06,0,1,0,1,.7],[3,8e3,-1,.001,0,.035,0,.4,0,1,.45]],[[3,12e3,0,.001,0,.03,0,.5,0,1,.4],[2,190,-3,.001,0,.04,0,1,0,1,.3]],[[3,14e3,0,.015,.02,.09,.3,.18,0,1,.5],[2,70,-2,.003,0,.07,0,1,0,1,.3]],[[3,4e3,3.5,.03,.03,.2,0,.25,0,1,.5],[2,350,1.2,.03,.02,.18,.02,1,0,1,.12]],[[3,14e3,-2.5,.008,.07,.2,.25,.3,0,1,.8],[3,3500,.5,.01,.06,.2,0,.12,0,1,.5]],[[2,70,-2.5,.001,.01,.2,0,1,0,1,.9],[3,7e3,-1,.001,0,.09,0,.25,0,1,.5]],[[3,6e3,-1,.001,0,.05,0,.5,0,1,.7],[2,160,-4,.001,0,.07,0,1,0,1,.5]],[[3,5e3,0,.01,.04,.14,.5,.3,0,1,.5],[3,2500,0,.03,0,.1,.4,.2,0,1,.3,.08]],[[3,2e4,0,.001,2.1,.001,.25,.06,0,1,1.2],[3,2e4,0,.001,2.1,.001,.35,.3,0,1,.3]],[[3,9e3,0,.001,2.1,.001,.5,.4,0,1,.5],[3,3e3,0,.001,2.1,.001,.4,.2,0,1,.5]],[[0,392,0,.003,.05,.08,0,.35,.07,1.5,.5],[2,784,0,.003,.03,.1,.01,1,0,1,.3,.05]],[[1,330,-2.2,.003,.04,.22,.04,.25,0,1,.45],[3,2500,-1,.001,0,.12,0,.3,0,1,.4]],[[2,659,0,.003,.06,.25,.015,1,.09,1.5,.5],[2,1318,0,.003,.03,.2,0,1,0,1,.2,.09]],[[0,523,0,.004,.07,.1,0,.3,0,1,.4],[0,659,0,.004,.07,.1,0,.3,0,1,.4,.11],[0,784,0,.004,.07,.1,0,.3,0,1,.4,.22],[0,1047,0,.004,.2,.35,.008,.3,0,1,.5,.33],[2,262,0,.004,.25,.3,0,1,0,1,.35,.33]]],Xe=[z.WIND,z.SCRAPE],Ze=(e,t=Ye)=>{let n=t[e].map((t,n)=>[Je(t,e*9+n),Math.round((t[11]??0)*qe)]);return Float32Array.from({length:Math.max(...n.map(([e,t])=>t+e.length))},(e,t)=>Math.tanh(n.reduce((e,[n,r])=>e+(n[t-r]??0),0)))},Qe=(e,t=qe/10)=>{let n=e.length-t;return Float32Array.from({length:n},(r,i)=>i<t?e[i]*Math.sqrt(i/t)+e[n+i]*Math.sqrt(1-i/t):e[i])},$e=qe*60/108,et=$e/4,tt=4,nt=[2,150,-6,.002,0,.25,0,1,0,1,1],rt=[3,9e3,0,.002,0,.15,0,.5,0,1,.5],it=[3,3e4,0,.001,0,.04,0,.7,0,1,.15],at=()=>{let e=new Float32Array($e*4*tt),t={},n=(n,r)=>(t[String(r)]??=Je(r,1)).forEach((t,r)=>e[(n*et+r)%e.length]+=t),r=e=>55*2**(e/12),i=[0,0,-4,-5],a=[0,0,12,0,0,7,12,7];for(let e=0;e<64;e++){let t=e%16;if(`x.......x.x.....`[t]==`x`&&n(e,nt),`....x.......x...`[t]==`x`&&n(e,rt),t%2==0){n(e,it);let o=i[e>>4]+a[t>>1];n(e,[1,r(o),0,.005,.08,.18,0,.15,0,1,.6])}}[15,12,10,19,17,15].forEach((e,t)=>n([18,24,28,50,54,60][t],[2,r(e+24),0,.02,.1,.6,.01,1,0,1,.5]));let o=e.reduce((e,t)=>Math.max(e,Math.abs(t)),0);return e.map(e=>e/o*.35)},ot=40,st=24,ct=.5,lt=`tiny-fps:muted`,ut=()=>{let e=!1;return{unlock:()=>{},listen:()=>{},play:()=>{},loop:()=>({set:()=>{}}),mute:t=>{e=t},get muted(){return e},destroy:()=>{}}},dt=(e=Ye)=>{let t;try{t=new AudioContext}catch{return ut()}let n=(e,n=1)=>{let r=t.createGain();return r.gain.value=n,r.connect(e),r},r=n(t.destination),i=n(r,ct),a=[],o=!1,s=/* @__PURE__ */ new Set,c=[0,0,0],l=0,u=!1,d=e=>{let n=t.createBuffer(1,e.length,qe);return n.getChannelData(0).set(e),n},f=e=>{let n=t.createBufferSource();return n.buffer=e,n};return{unlock(){if(t.resume().catch(()=>{}),!o){o=!0,e.forEach((t,n)=>{let r=Ze(n,e);a[n]=d(Xe.includes(n)?Qe(r):r)});let t=f(d(at()));t.loop=!0,t.connect(i),t.start()}},listen(e,t){[c,l]=[e,t]},play(e,i,o=1,u=1){let d=0,p=o;if(i){let[e,t,n]=i.map((e,t)=>e-c[t]),r=Math.hypot(e,t,n);p=Math.max(0,1-r/ot)**2*o,d=(e*Math.cos(l)-n*Math.sin(l))/Math.max(r,1)}let m=a[e];if(!m||!p)return;if(s.size>=st){let e=[...s].reduce((e,t)=>t.vol<e.vol?t:e);if(e.vol>=p)return;e.src.stop(),s.delete(e)}let h=f(m);h.playbackRate.value=u;let g=t.createStereoPanner();g.pan.value=d,h.connect(g).connect(n(r,p));let _={vol:p,src:h};s.add(_),h.onended=()=>s.delete(_),h.start()},loop(e){let i,o;return{set(s,c){!i&&a[e]&&(i=f(a[e]),i.loop=!0,i.connect(o=n(r,0)),i.start()),i&&(o.gain.setTargetAtTime(s,t.currentTime,.08),i.playbackRate.setTargetAtTime(c,t.currentTime,.08))}}},mute(e){u=e,r.gain.setTargetAtTime(+!e,t.currentTime,.05)},get muted(){return u},destroy:()=>void t.close().catch(()=>{})}},ft=()=>{try{return localStorage.getItem(lt)==`1`}catch{return!1}},pt=e=>{e.mute(!e.muted);try{localStorage.setItem(lt,e.muted?`1`:`0`)}catch{}return e.muted},mt=(e,t)=>{if(!e)return[];if(e.over||t.over)return e.over&&!t.over?[{kind:`start`}]:[];let n=[];for(let r of[0,1])t.score[r]>e.score[r]&&n.push({kind:`capture`,team:r});return t.flags.forEach((t,r)=>{let i=e.flags[r];t.state===l.CARRIED&&(i.state!==l.CARRIED||i.by!==t.by)?n.push({kind:`take`,flag:r,by:t.by}):t.state===l.DROPPED&&i.state===l.CARRIED?n.push({kind:`drop`,flag:r}):t.state===l.HOME&&i.state===l.DROPPED&&n.push({kind:`return`,flag:r})}),n},ht=(e,t,n)=>{let r=e=>o[e].toLowerCase();switch(e.kind){case`take`:{let i=1-e.flag;return{team:i,text:e.flag===t.team?`${o[i]} took your flag`:e.by===t.id?`You took the ${r(e.flag)} flag`:`${n(e.by)} took the ${r(e.flag)} flag`}}case`drop`:return{team:e.flag,text:e.flag===t.team?`Your flag was dropped`:`${o[e.flag]} flag dropped`};case`return`:return{team:e.flag,text:e.flag===t.team?`Your flag returned`:`${o[e.flag]} flag returned`};case`capture`:return{team:e.team,text:`${o[e.team]} scored`};default:return{text:`New match`}}},gt=(e,t)=>{switch(e.kind){case`take`:return[z.TAKE,e.flag===t?.8:1];case`drop`:return[z.DROP,e.flag===t?1:.85];case`return`:return[z.RETURN,e.flag===t?1:.85];case`capture`:return[z.CAPTURE,e.team===t?1:.8];default:return}},B=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],_t=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],vt=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],V=(e,t,n)=>[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n],H=e=>{let t=Math.hypot(...e)||1;return[e[0]/t,e[1]/t,e[2]/t]},yt=(e,t,n=0)=>{let[r,i,a,o,s,c]=[e,t,n].flatMap(e=>[Math.sin(e),Math.cos(e)]),l=[i,0,-r],u=[r*a,o,i*a];return[l.map((e,t)=>e*c-u[t]*s),u.map((e,t)=>e*c+l[t]*s),[-r*o,a,-i*o]]},bt=(e,t,n=[0,0,0])=>{let r=[],i=e.filter((t,n)=>!n||Math.hypot(t[0]-e[n-1][0],t[1]-e[n-1][1])>1e-9),a=i.slice(1).map(([e,t],n)=>{let[r,a]=i[n],o=Math.hypot(e-r,t-a);return[(t-a)/o,-(e-r)/o]}),o=i.map(([e],t)=>{let[n,r]=[0,1].map(e=>(a[t-1]?.[e]??0)+(a[t]?.[e]??0)),i=Math.hypot(n,r);return e?[n/i,r/i]:[0,Math.sign(r)]}),s=(e,a)=>{let[s,c]=i[a],[l,u]=[Math.cos(e*D/t),Math.sin(e*D/t)];r.push(n[0]+s*l,n[1]+s*u,n[2]-c,o[a][0]*l,o[a][0]*u,-o[a][1])};for(let e=1;e<i.length;e++)for(let n=0;n<t;n++)[...i[e-1][0]?[[n,e-1],[n+1,e-1],[n+1,e]]:[],...i[e][0]?[[n,e-1],[n+1,e],[n,e]]:[]].forEach(([e,t])=>s(e,t));return r},xt=(e,t,n,[r,i],a)=>{let o=(e,t,n,r)=>Array.from({length:t},(i,a)=>{let o=a*D/t/4;return[e*Math.sin(o),n-r*e*Math.cos(o)]});return bt([...r?o(t[0],r,0,1):[[0,0]],...t.map((n,r)=>[n,e*r/(t.length-1)]),...i?o(t[t.length-1],i,e,-1).reverse():[[0,e]]],n,a)},St=(e,[t,n,r])=>Array.from({length:e.length*(10/6)},(i,a)=>{let[o,s]=[Math.floor(a/10),a%10];return s<6?e[o*6+s]:[t,n,-1,r][s-6]}),Ct=[[5,1],[7,2],[10,3]],wt=/* @__PURE__ */ new Map,U=(e,t,n,r=[1,1])=>{let[i,a]=Ct[e];!e&&n.length>3&&(n=[n[0],n[n.length>>1],n[n.length-1]]);let o=`${e} ${t} ${n} ${r}`,s=wt.get(o);return s||(s=St(xt(t,n,i,r.map(e=>Math.ceil(a*e))),[1,1,1]),wt.set(o,s)),s},W=(e,t,n,[r,i,a],o,s,c=[1,1,1])=>{let[l,u,d]=typeof s==`number`?[s,s,s]:s,f=l==u&&u==d,[p,m,h,g,_,v,y,b,x]=[...r,...i,...a],S=n[0]+p*o[0]+g*o[1]+y*o[2],C=n[1]+m*o[0]+_*o[1]+b*o[2],w=n[2]+h*o[0]+v*o[1]+x*o[2];for(let n=0;n<t.length;n+=10){let[r,i,a]=[t[n]*l,t[n+1]*u,t[n+2]*d],[o,s,T]=[t[n+3],t[n+4],t[n+5]];if(!f){[o,s,T]=[o/l,s/u,T/d];let e=Math.sqrt(o*o+s*s+T*T)||1;[o,s,T]=[o/e,s/e,T/e]}e.push(S+p*r+g*i-y*a,C+m*r+_*i-b*a,w+h*r+v*i-x*a,p*o+g*s-y*T,m*o+_*s-b*T,h*o+v*s-x*T,t[n+6]*c[0],t[n+7]*c[1],t[n+8],t[n+9]*c[2])}},Tt=(e,t)=>{let n=e[0]*t[0]+e[1]*t[1]+e[2]*t[2],r=t.map((t,r)=>t-e[r]*n),i=Math.hypot(...r)||1,[a,o,s]=r.map(e=>e/i);return[[a,o,s],[o*e[2]-s*e[1],s*e[0]-a*e[2],a*e[1]-o*e[0]],e]},G=(e,t,n,r,i,a,o=1,s)=>{let c=[r[0]-n[0],r[1]-n[1],r[2]-n[2]],l=Math.hypot(...c)||1,[u,d]=typeof o==`number`?[o,o]:o;W(e,t,n,Tt([c[0]/l,c[1]/l,c[2]/l],i),[0,0,0],[u,d,l/a],s)},Et=[.66,.45,.35],Dt=[.82,.82,.84],K={upper:[.055,.052,.042],fore:[.04,.043,.03],thigh:[.09,.08,.058],shin:[.056,.06,.05,.037]},Ot=[.17,.153,.16,.18,.196,.19,.105],kt=.62,At=(e,t,n,r,i,a,o,s,c=1)=>{let l=n.map((e,t)=>e+r[t]*kt*c);G(e,U(t,kt,Ot,[0,0]),n,l,a,kt,[1,.62],o),W(e,U(t,0,[1,1]),n,Tt(i,a),[0,-.02,0],[.165,.11,.13],s)},jt=(e,t,n,r,i)=>G(e,U(t,.17,[.066,.06],[0,.5]),n.map((e,t)=>e+r[t]*.55),n.map((e,t)=>e+r[t]*.72),i,.17,1,Et),Mt=(e,t,n,r,i,a,o)=>{let s=vt(i,r)*.4,c=Tt(H([i[0]-r[0]*s,i[1]-r[1]*s,i[2]-r[2]*s]),a),l=U(0,0,[1,1]);W(e,U(t&&t-1,0,[1,1]),n,c,[0,-.048,.045],[.05,.022,.135],Dt),W(e,U(t,0,[1,1]),n,c,[0,-.015,.03],[.046,.042,.115],o),t>1&&W(e,l,n,c,[0,-.04,.125],[.042,.028,.05],Dt)},Nt=()=>U(0,.04,[.0105,.0095],[1,2]),Pt=[1,1.1,1,.82],Ft=[[[.55,-.2,.8],[.2,-.75,.6]],[[.4,-.1,.9],[-.55,-.5,.65]]],It=(e,t,n,r,i,a,o=Et)=>{let[s,c,l]=Tt(n,r),u=([e,n,r])=>[t[0]+s[0]*e*i+c[0]*n+l[0]*r,t[1]+s[1]*e*i+c[1]*n+l[1]*r,t[2]+s[2]*e*i+c[2]*n+l[2]*r],d=(t,n,r,i)=>n.reduce((t,n,a)=>{let c=[t[0]+n[0]*r,t[1]+n[1]*r,t[2]+n[2]*r];return G(e,Nt(),u(t),u(c),s,.04,i*.88**a,o),c},t);W(e,U(1,0,[1,1]),t,[s,c,l],[0,0,.045],[.0425,.02,.058],o);for(let e=0;e<4;e++){let[t,n]=[.1+1.3*a,.2+3*a],r=-(e-1.5)*.08*(1-a);d([.0315-.021*e,-.004,.092],[t,n].map(e=>H([r,-Math.sin(e),Math.cos(e)])),.04*Pt[e],1)}d([.034,-.012,.025],Ft.map(([e,t])=>H(V(e,t,a))),.037,1.25)},Lt=(e,t,n,r,i)=>{let a=B(t,e),o=H(a),s=Math.max(Math.min(Math.hypot(...a),(r+i)*.99),.15),c=(r*r-i*i+s*s)/(2*s),l=Math.sqrt(Math.max(r*r-c*c,0)),u=vt(n,o),d=H([n[0]-o[0]*u,n[1]-o[1]*u,n[2]-o[2]*u]);return[[e[0]+o[0]*c+d[0]*l,e[1]+o[1]*c+d[1]*l,e[2]+o[2]*c+d[2]*l],[e[0]+o[0]*s,e[1]+o[1]*s,e[2]+o[2]*s]]},Rt=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],zt=2.2,Bt=.5,Vt=-.15,[Ht,Ut]=[.35,.38],[Wt,Gt]=[.43,.45],Kt=[.95,.22,.1],[qt,Jt,Yt]=[[.3,.32,.37],[.14,.15,.2],[.6,.61,.65]],Xt=()=>({upper:U(2,Ht,K.upper,[1,1]),fore:U(2,Ut,K.fore,[1,0]),cuff:U(2,.03,[.033,.033],[0,0]),thigh:U(1,Wt,K.thigh,[.5,1]),shin:U(1,Gt,K.shin,[.5,.5])}),q=(e,t,n,r,i,a,o)=>[[e*t,n,r],[e*i,a,o]],J=([e,t],[n,r],i)=>[V(e,n,i),V(t,r,i)],Zt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Qt={sprint:6,air:12,dash:14,hang:16,climb:12,wall:10,slide:10,low:12,amp:8},$t={jump:5,tuck:4,land:7},en=()=>{let e,t={sprint:0,air:0,dash:0,hang:0,climb:0,wall:0,slide:0,low:0,amp:0},n={jump:0,tuck:0,land:0},r={jump:0,tuck:0,land:0},i=0,a=0,o,s=e=>e==d.GROUND||e==d.WALLRUN||e==d.CROUCH,c=(c,{ev:l,fall:u},f)=>{if(!c){e=void 0;return}let m=e&&s(e.mode)&&s(c.mode)?Math.hypot(c.x-e.x,c.z-e.z):0,h=s(c.mode)&&m<1;i+=h?m*(zt-.6*t.sprint):0,e={...c};let g={sprint:+se(c),air:+(c.mode==d.AIR&&c.dash<=50),dash:+(c.dash>50),hang:+(c.mode==d.HANG),climb:+(c.mode==d.CLIMB),wall:+(c.mode==d.WALLRUN),slide:+(c.mode==d.SLIDE),low:+(c.mode==d.SLIDE||c.mode==d.CROUCH),amp:s(c.mode)?Zt(oe(c)/9):0};for(let e of Object.keys(Qt))t[e]+=(g[e]-t[e])*(1-Math.exp(-f*Qt[e]));l&p.JUMP&&(n.jump=1),l&p.DOUBLE&&(n.tuck=1),l&p.LAND&&(n.land=Zt(u/12,.3));for(let e of Object.keys($t))r[e]+=(n[e]-r[e])*(1-Math.exp(-f*24)),n[e]*=Math.exp(-f*$t[e]);let[_,v]=Rt[c.wall];a+=(Zt(_*Math.cos(c.yaw)-v*Math.sin(c.yaw),-1,1)-a)*(1-Math.exp(-f*10)),(c.mode==d.HANG||c.mode==d.CLIMB)&&c.edge&&(o={x:c.x,z:c.z,y:c.edge,dx:_,dz:v})},l=(n,s,c,l=0)=>{if(!e||Math.hypot(...B(n,[e.x,e.y+ae(e),e.z]))>Bt)return;let[u,d,f]=yt(s,c,l),p=e=>[vt(e,u),vt(e,d),vt(e,f)],m=([e,t,n])=>[u[0]*e+d[0]*t+f[0]*n,u[1]*e+d[1]*t+f[1]*n,u[2]*e+d[2]*t+f[2]*n],h=e=>_t(n,m(e)),[g,_]=[Math.sin(s),Math.cos(s)],v=([t,n,r])=>[e.x+t*_-r*g,e.y+n,e.z-t*g-r*_],y=t.amp*(1+.5*t.sprint),b=Math.max(t.hang,t.climb),x=[-1,1].map(e=>{let s=Math.sin(i+(e>0?Math.PI:0)),c=Math.sign(s)*Math.abs(s)**(1-.4*t.sprint),l=V([.27,-.27,.46],[.2,-.16,.44],t.sprint),u=q(e,l[0],l[1]+.08*y*c,l[2]+.1*y*c,.7,-1,-.5);u=J(u,q(e,.4,-.2,.36,.8,-.8,-.3),t.air),u=J(u,q(e,.3,.04,.5,.6,-1,-.2),r.jump),u=J(u,q(e,.15,-.24,.28,.9,-.4,-.6),r.tuck),u=J(u,q(e,.42,-.4,.3,1,-1,-.2),r.land),u=J(u,q(e,.13,-.1,.64,.7,-1,-.3),t.dash);let d=q(e,.4,-.2+.02*Math.sin(i*2),.52,.4,-1,-.5),f=t.wall*Zt(a*e);u=J(u,d,f),u=J(u,e>0?q(1,.46,-.32,.4,1,-.4,-.5):q(1,-.3,-.12,.5,-.8,-.6,-.3),t.slide);let v;if(o){let t=-o.dz,r=o.dx;t*_-r*g<0&&([t,r]=[-t,-r]);let i=.43000000000000005,a=[o.x+o.dx*i+t*.12*e,o.y+.06,o.z+o.dz*i+r*.12*e],[s,c,l]=p(B(a,n));u=J(u,[[s,Math.max(c,-.36),Math.max(l,.3)],[e*.5,-1,-.4]],b),v=p([o.dx,-.15,o.dz])}let x=.55+.35*t.sprint;for(let[e,n]of[[.3,t.air],[.1,r.jump],[.9,r.tuck],[1,t.dash],[.1,f],[.35,t.slide],[.1,b]])x+=(e-x)*n;let S=[e*(.15-.05*b),-.22+.08*b,-.2+.12*b],[C,w]=Lt(S,u[0],u[1],Ht,Ut),T=H(B(w,C));return{root:h(S),mid:h(C),end:h(w),dir:m(v?V(T,H(v),b):T),curl:x,roll:(1-b)*(1-2*f)}}),S=V(V([0,.88,-.12],[0,.46,-.2],t.low),[0,.26,-.4],t.slide);S[1]-=.22*r.land;let C=V(V([0,1.4,-.2],[0,.55,-.12],t.low),[0,.5,-.3],t.slide);return{arms:x,legs:[-1,1].map(e=>{let n=Math.sin(i+(e>0?0:Math.PI)),a=Math.cos(i+(e>0?0:Math.PI)),o=t.amp*(1+.5*t.sprint),s=[e*.12,.07+.2*o*Math.max(0,a),-.02-.1*t.low+.3*o*n];s=V(s,[e*.12,.3,e*.2],t.air),s=V(s,[e*.12,.62,.1],r.tuck),s=V(s,[e*.1,.28,-.4],t.dash),s=V(s,[e*.1,.12,-.12],t.hang),s=V(s,e>0?[.1,.5,.2]:[-.1,.1,-.1],t.climb),s=V(s,[e*.11,.2,.84+.08*e],t.slide);let c=[S[0]+e*.11,S[1],S[2]],[l,u]=Lt(c,s,[e*.15,.2,1],Wt,Gt);return{root:v(c),mid:v(l),end:v(u),dir:[-g,0,-_],curl:0,roll:1}}),torso:[v(S),v(C)],grip:b,low:t.low}};return{update:c,rig:l,draw(e,t,n,r,i=0){let a=l(t,n,r,i);if(!a)return;let[o]=yt(n,r,i),[s,c]=[[Math.cos(n),0,-Math.sin(n)],[-Math.sin(n),0,-Math.cos(n)]],[u,d]=a.torso,f=Xt();if(r<Vt||a.low>.2){At(e,2,u,H(B(d,u)),c,s,qt,Jt,.75);for(let{root:t,mid:n,end:r}of a.legs)G(e,f.thigh,t,n,s,Wt,1,Jt),G(e,f.shin,n,r,s,Gt,1,Jt),Mt(e,1,r,H(B(r,n)),c,s,Yt)}a.arms.forEach(({root:t,mid:n,end:r,dir:i,curl:s,roll:c},l)=>{let u=l?1:-1,d=H(B(r,n));G(e,f.upper,t,n,o,Ht,1-.4*a.grip,qt),G(e,f.fore,n,r,o,Ut,1-.3*a.grip,qt),G(e,f.cuff,B(r,d.map(e=>e*.025)),_t(r,d.map(e=>e*.005)),o,.03,1,Kt),It(e,r,i,_t(o.map(e=>e*(1-Math.abs(c))),[0,-u*c,0]),-u,s)})}}},tn=e=>.6+.2*e,nn=e=>e?.mode===d.GROUND||e?.mode===d.CROUCH,rn=e=>nn(e)||e?.mode===d.WALLRUN,an=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],on=e=>.02+.0025*e,sn=.006,cn=.03,ln=.14,un=.05,dn=5,fn=9,pn=6.5,mn=.25,hn=.22,gn=.9,_n=4,vn=1,yn=.12,bn=24,xn=15.7,Sn=.45,Cn=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),wn=(e,t)=>{let n=Math.ceil(t*120);for(let r=0;r<n;r++)e[1]+=(-15.7*xn*e[0]-2*Sn*xn*e[1])*(t/n),e[0]+=e[1]*(t/n)},Tn=()=>{let e=0,t=0,n=0,r=0,i=0,a,o,s=[0,0],c=[0,0],l={dy:0,pitch:0,roll:0,fov:0,lines:0,stride:0,update(f,m,h,g={ev:0,fall:0}){let _=e=>Math.min(1,h*e),v=f?oe(f):0,y=f&&o&&rn(f)&&rn(o)?Math.hypot(f.x-o.x,f.z-o.z):0;y<1&&(l.stride+=y/tn(v)),e+=((nn(f)&&y>.5*h&&y<1?1:0)-e)*_(10),o=f,g.ev&p.LAND&&(s[1]-=hn*Math.min(g.fall,20)),g.ev&p.CLIMB&&(s[1]-=hn*_n),g.ev&(p.JUMP|p.DOUBLE)&&(s[1]+=gn),g.ev&p.GRAB&&(c[1]-=vn),wn(s,h),wn(c,h);let b=f?ae(f):0;a=f?a===void 0?b:a+(b-a)*_(14):void 0,l.dy=(a??0)-b+s[0]-Math.cos(l.stride*2*Math.PI)*on(v)*e,i+=((f?.mode===d.CLIMB?yn*Math.sin(Math.PI*Cn(f.t/bn)):0)-i)*_(10),l.pitch=c[0]+i;let x=f?.mode===d.WALLRUN?an[f.wall]:[0,0],S=f?x[0]*Math.cos(f.yaw)-x[1]*Math.sin(f.yaw):0,C=+!!(m&u.RIGHT)-!!(m&u.LEFT);t+=(C*cn+S*ln+(f?.mode===d.SLIDE?un:0)-t)*_(8),l.roll=t+Math.sin(l.stride*Math.PI)*sn*e;let w=!!f&&f.dash>50;n+=(+w-n)*_(w?40:6),r+=(Cn((v-6)/3)-r)*_(4),l.fov=r*dn+n*fn,l.lines+=(Cn((v-pn)/(9-pn))*mn+n*.75-l.lines)*_(8)}};return l},En=2.4,Dn=[1,.62],On=8,kn=28,An=2.2,jn=.04,Mn=.045,Nn=e=>{let t=parseInt(s[e].slice(1),16);return[t>>16,t>>8&255,t&255].map(e=>e/255)},Pn=(e,t,n)=>e.flatMap((e,r)=>{if(e.state===l.DROPPED)return[{team:r,at:[e.x,e.y,e.z],dropped:!0}];if(e.state===l.CARRIED){let t=n(e.by);return t?[{team:r,at:[t.x,t.y,t.z],by:{yaw:t.yaw,vx:t.vx,vz:t.vz}}]:[]}return[{team:r,at:t[r]}]}),Fn=[[1,0,0],[0,1,0],[0,0,1]],In=(e,t,n)=>{for(let r=t;r<e.length;r+=10)e[r+6]*=n,e[r+7]*=n,e[r+9]*=n,e[r+8]=-2},Ln=(e,t,n,r,[i,a,o])=>{let[s,c,l]=[n[0]-t[0],n[1]-t[1],n[2]-t[2]],[u,d,f]=[r[0]-t[0],r[1]-t[1],r[2]-t[2]],p=[c*f-l*d,l*u-s*f,s*d-c*u],m=Math.hypot(...p)||1;for(let s of[t,n,r])e.push(...s,p[0]/m,p[1]/m,p[2]/m,i,a,-1,o)},Rn=(e,t,n,r,i)=>{for(let a=0;a<kn;a++){let[o,s]=[a,a+1].map(e=>e*2*Math.PI/kn),c=(e,n)=>[t[0]+e*Math.cos(n),t[1],t[2]+e*Math.sin(n)];Ln(e,c(n,o),c(r,s),c(r,o),i),Ln(e,c(n,o),c(n,s),c(r,s),i)}},zn=(e,t,n,r)=>{for(let i=0;i<kn;i++){let[a,o]=[i,i+1].map(e=>e*2*Math.PI/kn);Ln(e,t,[t[0]+n*Math.cos(o),t[1],t[2]+n*Math.sin(o)],[t[0]+n*Math.cos(a),t[1],t[2]+n*Math.sin(a)],r)}},Bn=(e,t,n,r)=>{zn(e,[t[0],t[1]+jn,t[2]],c,n.map(e=>e*.4));let i=e.length;Rn(e,[t[0],t[1]+Mn,t[2]],c-.16,c,n),In(e,i,An*(.75+.25*Math.sin(r*3)))},Vn=(e,t,n,[r,i],a,o,s)=>{let c=[-n[2],0,n[0]],l=(e,s)=>{let l=a*e*Math.sin(o*7-e*5),u=i*s*(1-e);return[t[0]+n[0]*r*e+c[0]*l,t[1]-u+.12*r*e*Math.sin(o*5-e*4)*a,t[2]+n[2]*r*e+c[2]*l]};for(let t=0;t<On;t++){let[n,r]=[t/On,(t+1)/On],[i,a,o,c]=[l(n,0),l(r,0),l(r,1),l(n,1)],u=[(a[1]-i[1])*(c[2]-i[2])-(a[2]-i[2])*(c[1]-i[1]),(a[2]-i[2])*(c[0]-i[0])-(a[0]-i[0])*(c[2]-i[2]),(a[0]-i[0])*(c[1]-i[1])-(a[1]-i[1])*(c[0]-i[0])],d=Math.hypot(...u)||1,f=(e,t)=>[e[0]+u[0]/d*.004*t,e[1]+u[1]/d*.004*t,e[2]+u[2]/d*.004*t];for(let t of[1,-1]){let n=[i,a,o,c].map(e=>f(e,t)),[r,l,u,d]=t>0?n:[n[0],n[3],n[2],n[1]];Ln(e,r,l,u,s),Ln(e,r,u,d,s)}}},Hn=(e,t,n,r)=>{G(e,U(1,1,[1,1],[0,0]),t,n,[.6,0,.8],1,.045,[.82,.84,.9]);let i=e.length;W(e,U(1,0,[1,1]),n,Fn,[0,0,0],.09,r),In(e,i,An)},Un=(e,t,n,r)=>{let[i,a,o]=t.at,s=r+t.team*1.7;if(t.by){let{yaw:r,vx:c,vz:l}=t.by,u=-Math.sin(r),d=-Math.cos(r),f=Math.hypot(c,l),p=[i-u*.28,a+.55,o-d*.28],m=[i-u*.38,a+.55+En-.2,o-d*.38],[h,g]=f>1?[-c/f,-l/f]:[-u,-d];Hn(e,p,m,n);let _=Math.min(1,f/8);Vn(e,m,[h,0,g],[Dn[0]*(.7+.5*_),Dn[1]],.1+.16*_,s,n);return}if(t.dropped){let t=i*12.9898+o*78.233,[l,u]=[Math.cos(t),Math.sin(t)],d=[i+l*2.3,a+.6,o+u*2.3];Hn(e,[i,a+.06,o],d,n),Vn(e,d,[l,0,u],[Dn[0]*.8,Dn[1]*.8],.04,s,n);let f=e.length;Rn(e,[i,a+Mn,o],c-.1,c,n),In(e,f,An*(.5+.5*Math.abs(Math.sin(r*5))));return}let l=[i,a+En,o];Hn(e,[i,a,o],l,n);let u=.6+t.team*Math.PI;Vn(e,l,[Math.cos(u),0,Math.sin(u)],Dn,.18,s,n)},Wn=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Gn=e=>{let t=e.loop(z.WIND),n=e.loop(z.SCRAPE),r=0,i=/* @__PURE__ */ new Map,a=(t,n,r)=>{let i=se(t);e.play(t.mode===d.WALLRUN?z.WALLSTEP:z.STEP,r,i||t.mode===d.WALLRUN?1:t.mode===d.CROUCH?.35:.6,(i?.92:1)*(n&1?1.06:.94))},o=(t,n)=>e.play(z.LAND,n,Wn(t/14,.2),1.25-.5*Wn(t/20));return{me(i,s,c){let l=Math.floor(c),u=l>r;if(r=l,!i||e.muted)return;u&&a(i,l);for(let[t,n]of[[p.JUMP,z.JUMP],[p.DOUBLE,z.DOUBLE],[p.DASH,z.DASH],[p.GRAB,z.GRAB],[p.CLIMB,z.SCUFF]])s.ev&t&&e.play(n);s.ev&p.LAND&&o(s.fall);let f=Wn((Math.hypot(i.vx,i.vy,i.vz)-4)/12);t.set(.55*f**1.5,.6+.9*f);let m=Wn(oe(i)/9);n.set(i.mode===d.SLIDE?.2+.5*m:0,.8+.4*m)},others(t){for(let n of t){let t=i.get(n.id);if(t&&!e.muted){let e=[n.x,n.y+.1,n.z],r=Math.hypot(n.x-t.p.x,n.z-t.p.z);if(rn(n)&&rn(t.p)&&r<1){let i=Math.floor(t.stride);t.stride+=r/tn(oe(n)),Math.floor(t.stride)>i&&a(n,i,e)}n.ground&&!t.p.ground&&t.p.vy<-3&&o(-t.p.vy,e)}i.set(n.id,{p:n,stride:t?.stride??0})}for(let e of i.keys())t.some(t=>t.id===e)||i.delete(e)}}},Kn=`h5,aside,nav,output,section,em{position:absolute;margin:0;padding:0;pointer-events:none;user-select:none;white-space:pre-line}h5{top:8px;right:12px;font-size:12px}nav{top:8px;left:50%;transform:translateX(-50%);display:grid;grid-template-columns:1fr auto 1fr;gap:2px 16px;align-items:center;text-align:center;font-size:13px}nav span,nav time{font:900 clamp(16px,4.6vw,24px)/1 system-ui,sans-serif;letter-spacing:.03em;white-space:nowrap}nav time{min-width:4.2ch;font-variant-numeric:tabular-nums;font-size:clamp(14px,3.8vw,20px)}nav small{font-size:clamp(10px,2.6vw,12px);white-space:nowrap;opacity:.95}nav small:first-of-type{text-align:right}nav small:last-of-type{text-align:left}output{top:20%;left:50%;transform:translateX(-50%);padding:6px 18px;font:900 clamp(18px,3.4vw,30px)/1.1 system-ui,sans-serif;letter-spacing:.06em;text-transform:uppercase;white-space:nowrap;background:#000a;border-bottom:3px solid currentColor}em{font-style:normal;font-size:13px;font-weight:800;line-height:1.1;text-align:center;transform:translate(-50%,-50%)}em span{display:block;font-size:20px;line-height:1}section{inset:0;z-index:2;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;padding:0 12px;text-align:center;background:#000c}section h6{font:900 clamp(30px,9vw,72px)/1 system-ui,sans-serif;letter-spacing:.04em}section strong{font-size:34px}section td:first-child{text-align:left;opacity:1}section td+td{text-align:center}section th{padding:2px 10px;font-size:12px;opacity:.7;font-weight:600}aside{inset:0;z-index:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:14px;padding:0 12px;text-align:center;background:#000b}h6{margin:0;font-size:inherit;text-shadow:none}aside h6{font:900 clamp(36px,13vw,84px)/1 system-ui,sans-serif;letter-spacing:.04em;transform:skewX(-8deg);background:linear-gradient(#fe6,#f92 45%,#d21);-webkit-background-clip:text;background-clip:text;color:transparent;filter:drop-shadow(0 3px 0 #500) drop-shadow(0 0 14px #f604)}strong{font-size:22px}table{border-collapse:collapse;font-size:16px}td{padding:2px 10px}td+td{text-align:left}td:first-child{text-align:right;opacity:.7}`,qn=2800,Jn=e=>`${Math.floor(e/60)}:${`${e%60}`.padStart(2,`0`)}`,Yn=e=>{e.insertAdjacentHTML(`beforeend`,`<aside hidden><h6>TINY FPS</h6><span></span><table><tr><td>Mouse<td>look<tr><td>WASD / ZQSD<td>move<tr><td>Shift<td>sprint<tr><td>Space<td>jump, again in the air<tr><td>Move key twice<td>dash that way<tr><td>C<td>crouch, slide when fast<tr><td>M<td>mute</table><span>Take the enemy flag to your own base while yours is home.</span><strong></strong></aside><h5 hidden>Muted (M)</h5><nav hidden><span></span><time></time><span></span><small></small><small></small></nav><output hidden></output><section hidden><h6></h6><strong></strong><table></table><span></span></section>`);let t=t=>e.querySelector(t),[n,r]=[`h5`,`aside`].map(e=>t(e)),[i,a]=[`aside span`,`aside strong`].map(e=>t(e)),c=(e,t)=>e.textContent!=t&&(e.textContent=t),u=t(`nav`),[d,f,p]=[...u.querySelectorAll(`span, time`)],[m,h]=[...u.querySelectorAll(`small`)],g=t(`output`),_=t(`section`),[v,y,b]=[`h6`,`strong`,`span`].map(e=>_.querySelector(e)),x=_.querySelector(`table`),S=[],C,w,T=(e,t)=>e.style.color=s[t];return[d,m].forEach(e=>T(e,0)),[p,h].forEach(e=>T(e,1)),{title(e,t){r.hidden=!e,c(i,t),c(a,e)},mute:e=>n.hidden=!e,match(e,t){u.hidden=!1,c(d,`${o[0].toUpperCase()} ${e.score[0]}`),c(p,`${e.score[1]} ${o[1].toUpperCase()}`),c(f,e.over?`END`:Jn(e.clock)),e.flags.forEach((e,n)=>{let r=e.state===l.CARRIED?`taken by ${t(e.by)}`:e.state===l.DROPPED?`dropped ${e.left}s`:`home`;c(n?h:m,`${o[n]} flag: ${r}`)})},marks(t){for(;S.length<t.length;){let t=document.createElement(`em`);t.innerHTML=`<span></span><small></small>`,S.push(t),e.append(t)}S.splice(t.length).forEach(e=>e.remove()),t.forEach((e,t)=>{let n=S[t];n.style.left=`${e.x*100}%`,n.style.top=`${e.y*100}%`,T(n,e.team);let[r,i]=[n.children[0],n.children[1]];r.style.transform=e.arrow===void 0?``:`rotate(${e.arrow}rad)`,c(r,e.arrow===void 0?`▼`:`▲`),c(i,`${e.kind===`base`?`Base `:``}${e.text}`)})},banner(e,t){g.hidden=!1,c(g,e),g.style.color=t===void 0?`#fff`:s[t],clearTimeout(C),C=setTimeout(()=>g.hidden=!0,qn)},end(e,t){if(_.hidden=!e,!e)w=void 0;else{if(w!==e){w=e;let[t,n]=e.score,r=t>n?0:n>t?1:-1;c(v,r<0?`DRAW`:`${o[r].toUpperCase()} WINS`),v.style.color=r<0?`#fff`:s[r],c(y,`${t} – ${n}`);let i=[...e.players].sort((e,t)=>t.caps-e.caps||t.returns-e.returns||e.id-t.id);x.replaceChildren(),x.insertAdjacentHTML(`beforeend`,`<tr><th>Player<th>Captures<th>Returns</tr>`);for(let e of i){let t=x.insertRow();[e.name,e.caps,e.returns].forEach(e=>t.insertCell().textContent=`${e}`),t.style.color=s[e.team]}}c(b,`Next match in ${t}`)}}}},Xn=.0025,Zn=Math.PI*2,Qn={KeyW:u.FORWARD,ArrowUp:u.FORWARD,KeyS:u.BACK,ArrowDown:u.BACK,KeyA:u.LEFT,ArrowLeft:u.LEFT,KeyD:u.RIGHT,ArrowRight:u.RIGHT,Space:u.JUMP,ShiftLeft:u.SPRINT,ShiftRight:u.SPRINT,KeyC:u.CROUCH},$n=u.FORWARD|u.BACK|u.LEFT|u.RIGHT,er=(e,t)=>e&~$n|t|u.DASH,tr=e=>Qn[e]??0,nr=(e,t=()=>{})=>{let r=new AbortController,i=(e,t,n)=>e.addEventListener(t,n,{signal:r.signal}),a=/* @__PURE__ */ new Set,o=/* @__PURE__ */ new Map,s=0,c={yaw:0,pitch:0,keys:0,take(){let e=s?er(c.keys,s):c.keys;return s=0,e},locked:()=>e.getRootNode().pointerLockElement==e,destroy:()=>r.abort()};i(e,`click`,()=>{Promise.resolve(e.requestPointerLock()).catch(()=>{})}),i(document,`mousemove`,e=>{c.locked()&&(c.yaw=((c.yaw-e.movementX*Xn)%Zn+Zn)%Zn,c.pitch=Math.max(-1.55,Math.min(n,c.pitch-e.movementY*Xn)))}),i(document,`keydown`,e=>{let n=tr(e.code);if(e.code==`KeyM`&&!e.repeat&&c.locked()&&t(),n&&c.locked()){if(n&$n&&!e.repeat&&!a.has(e.code)){let t=performance.now(),r=o.get(e.code);r!==void 0&&t-r<=250?(s=n,o.delete(e.code)):o.set(e.code,t)}a.add(e.code),c.keys|=n,e.preventDefault()}}),i(document,`keyup`,e=>{a.delete(e.code),c.keys&=~tr(e.code)});let l=()=>{c.keys=s=0,a.clear(),o.clear()};return i(window,`blur`,l),i(document,`pointerlockchange`,()=>c.locked()||l()),c},rr=120,ir=16,ar=e=>{let t={...e};return delete t.ack,t},or=(e,t,n)=>({x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n,z:e.z+(t.z-e.z)*n}),sr=(e,t,n)=>j(e+(((t-e+Math.PI)%D+D)%D-Math.PI)*n),cr=(e,t)=>(t-e&65535)<32768,lr=(e,t,n)=>({...t,...or(e,t,n),yaw:sr(e.yaw,t.yaw,n),pitch:e.pitch+(t.pitch-e.pitch)*n}),ur=e=>{let t,n=0,r=0,i=[],a,o,s=[],c=0,l=0,u=e=>{let t=e-100,n=0;for(;n+1<s.length&&s[n+1].t<=t;)n++;let r=s[n],i=s[n+1]??r;return{a:r,b:i,u:i.t>r.t?Math.max(0,Math.min(1,(t-r.t)/(i.t-r.t))):0}},d=e=>{if(!s.length)return;let{a:t,b:n,u:r}=u(e);return(t.s.tick+(n.s.tick-t.s.tick&65535)*r)%65536};return{you:(e,r=0)=>{[t,n]=[e,r]},step:(t,s)=>{let u=He({...t,seq:r,view:s===void 0?void 0:d(s)});return r=r+1&65535,i.push(u),i.length>rr&&i.shift(),a&&(o=ar(a),Ne(a,u,e,n),c|=a.ev,l=Math.max(l,a.fall)),u},snapshot:(r,c)=>{s.push({t:c,s:r}),s.length>ir&&s.shift();let l=r.players.find(e=>e.id===t);l&&(i=i.filter(e=>!cr(e.seq,l.ack)),a=ar(l),o=ar(a),i.forEach((t,r)=>{r===i.length-1&&(o=ar(a)),Ne(a,t,e,n)}))},events:()=>{let e={ev:c,fall:l};return c=l=0,e},me:e=>a&&o?lr(o,a,Math.max(0,Math.min(1,e))):void 0,others:e=>{let n=s.at(-1);if(!n)return[];let{a:r,b:i,u:a}=u(e);return n.s.players.filter(e=>e.id!==t).map(e=>{let t=r.s.players.find(t=>t.id===e.id),n=i.s.players.find(t=>t.id===e.id);return t&&n?lr(ar(t),ar(n),a):ar(n??t??e)})}}},dr={SPOT:0,POINT:1},fr=9,pr=6,mr=e=>{let{ctf:t,t:n}=e;if(!t)return[];let r=([e,t,n],r,i,a)=>({kind:dr.POINT,p:[e,t,n],d:[0,-1,0],cone:0,range:i,color:Nn(r).map(e=>e*a),shadow:!1});return[...t.bases.map(([e,t,i],a)=>r([e,t+1.2,i],a,fr,1.1+.3*Math.sin(n*3))),...t.flags.filter(e=>e.dropped).map(e=>r([e.at[0],e.at[1]+.8,e.at[2]],e.team,pr,.9))]},Y={x0:.05,x1:.95,y0:.15,y1:.92},hr=(e,t,n,r,i)=>{let[a,o]=[r-e,i-t];return Math.atan2(a*Math.cos(n)-o*Math.sin(n),-a*Math.sin(n)-o*Math.cos(n))},gr=e=>{let[t,n]=[Math.sin(e),-Math.cos(e)],[r,i]=[(Y.x0+Y.x1)/2,(Y.y0+Y.y1)/2],[a,o]=[(Y.x1-Y.x0)/2,(Y.y1-Y.y0)/2],s=Math.min(a/(Math.abs(t)||1e-9),o/(Math.abs(n)||1e-9));return[r+t*s,i+n*s]},_r=2.6,vr=e=>{let t=[],n=(n,r,[i,a,o])=>{let s=Math.round(Math.hypot(i-e.eye[0],a+_r-e.eye[1],o-e.eye[2])),c=e.project(i,a+_r,o),l=c&&c[0]>=Y.x0&&c[0]<=Y.x1&&c[1]>=Y.y0&&c[1]<=Y.y1,u=`${s} m`;if(l)t.push({team:n,kind:r,x:c[0],y:c[1],text:u});else{let a=hr(e.eye[0],e.eye[2],e.yaw,i,o),[s,c]=gr(a);t.push({team:n,kind:r,x:s,y:c,arrow:a,text:u})}},r=e.flags.some(t=>t.state===l.CARRIED&&t.by===e.id);return e.flags.forEach((t,i)=>{if(t.state===l.CARRIED&&t.by===e.id){n(e.team,`base`,e.bases[e.team]);return}if(r&&i===e.team&&t.state===l.HOME)return;let a=t.state===l.HOME?e.bases[i]:t.state===l.DROPPED?[t.x,t.y,t.z]:e.where(t.by);a&&n(i,`flag`,a)}),t},yr=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),br=(e,t)=>Math.atan2(Math.sin(t-e),Math.cos(t-e)),xr=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],Sr={speed:8,sprint:6,air:12,rise:14,dash:14,hang:16,climb:12,wr:10,wl:10,slide:10,low:12},Cr=e=>e==d.GROUND||e==d.CROUCH,wr=e=>Cr(e)||e==d.SLIDE,Tr=e=>e==d.HANG||e==d.CLIMB,Er=e=>oe(e)>1?Math.atan2(-e.vx,-e.vz):e.yaw,Dr=e=>{let[t,n]=Rt[e.wall],r=Er(e);return t*Math.cos(r)-n*Math.sin(r)},Or=e=>{let t=e.mode==d.WALLRUN,n=Dr(e);return{speed:Cr(e.mode)?oe(e):0,sprint:+se(e),air:+(e.mode==d.AIR),rise:+(e.mode==d.AIR&&e.vy>.5),dash:+(e.dash>50),hang:+(e.mode==d.HANG),climb:+(e.mode==d.CLIMB),wr:+(t&&n>=0),wl:+(t&&n<0),slide:+(e.mode==d.SLIDE),low:+(e.mode==d.SLIDE||e.mode==d.CROUCH)}},kr=e=>({p:{...e},yaw:e.yaw,phase:0,time:0,w:Or(e),kick:0,dip:0,flip:0,fall:0,h:2,f:.43000000000000005,wy:e.yaw}),Ar=5,jr=(t,n,r)=>{let i=t.p,a=Math.hypot(n.x-i.x,n.z-i.z);if(Math.hypot(a,n.y-i.y)>Ar){Object.assign(t,kr(n));return}t.kick*=Math.exp(-r*7);let o=n.mode==d.AIR;o&&i.mode==d.AIR&&n.jumps<i.jumps&&n.vy>i.vy&&(t.flip=.001),o?t.fall=Math.min(t.fall,n.vy):(i.mode==d.AIR&&wr(n.mode)&&t.fall<-3&&(t.kick=yr(-t.fall/12,.3)),t.fall=0),t.flip&&=(t.flip+=r*(o?2.2:8),t.flip>=1?0:t.flip),t.phase+=Cr(n.mode)&&Cr(i.mode)?a*(2.3-.7*t.w.sprint):0;let s=Or(n);for(let e of Object.keys(Sr))t.w[e]+=(s[e]-t.w[e])*(1-Math.exp(-r*Sr[e]));if(t.dip+=(t.kick-t.dip)*(1-Math.exp(-r*24)),t.time+=r,Tr(n.mode)&&n.wall){let[r,i]=Rt[n.wall];t.grip&&n.mode!=d.HANG||(t.grip={x:n.x,z:n.z}),t.h=n.edge?n.edge-n.y:t.h,t.f=(t.grip.x-n.x)*r+(t.grip.z-n.z)*i+e+.03,t.wy=Math.atan2(-r,-i)}else!Tr(n.mode)&&t.w.hang+t.w.climb<.01&&(t.grip=void 0);let c=yr(t.w.wr+t.w.wl+t.w.slide+t.w.dash),l=n.yaw+br(n.yaw,Er(n))*c;t.yaw=l+br(l,t.wy)*yr(t.w.hang+t.w.climb),t.p={...n}},Mr=(e,t,n)=>{for(let n of e.keys())t.some(e=>e.id==n)||e.delete(n);for(let r of t){let t=e.get(r.id);t?jr(t,r,n):e.set(r.id,kr(r))}},Nr=e=>e.map((e,t)=>t%3?e:-e),Pr=e=>[Nr(e),e],Fr=(e,t,n)=>e>0?[n,t]:[Nr(t),Nr(n)],Ir=(e,t,n,r,i,a)=>({c:[t[0],t[1],t[2],t[3]*e],a:Fr(e,n,r),l:Fr(e,i,a)}),Lr=[.15,.2,1],Rr={crouch:{c:[.5,.05,.45,0],a:Pr([.3,.75,.35,.5,-1,-.4])},air:{c:[.9,0,.12,0],a:Pr([.72,1.3,.05,.3,-1,-.6]),l:[[-.14,.2,-.18,-.15,.2,1,0],[.14,.32,.3,...Lr,0]]},rise:{c:[.95,.02,.2,0],a:Pr([.32,1.95,.28,.7,-.3,-1]),l:[[-.12,.32,-.18,-.15,.2,1,0],[.13,.5,.2,...Lr,0]]},tuck:{c:[.95,0,.55,0],a:Pr([.2,.78,.32,.8,-.2,-.2]),l:Pr([.13,.5,-.12,...Lr,0])},land:{c:[.52,.06,.45,0],a:Pr([.3,.85,.35,.5,-1,-.5]),l:Pr([.15,.07,.05,...Lr,0])},dash:{c:[.64,.15,1,0],a:Pr([.3,.95,.1,.3,1,-.3]),l:[[-.11,.5,-.62,0,-1,.3,0],[.12,.38,.6,...Lr,0]]},slide:Ir(1,[.2,-.12,-1.15,0],[.42,.62,.35,.5,-.3,-1],[-.4,.06,-.5,-.5,.3,-1],[.14,.3,.95,.1,1,.3,0],[-.2,.08,.15,-.3,1,.5,0])},zr=[1,-1].map(e=>Ir(e,[.9,0,.22,-.35],[.4,1,.35,.4,-1,-.2],[-.82,1.3,.1,-.2,-1,-.4],[.38,.55,.3,.3,.3,1,-1.3],[-.1,.3,-.5,0,-1,.3,0])),Br=e=>{let{h:t,f:n}=e,r=yr((1.5-t)/.9),i=.05*Math.sin(e.time*3),a=e=>[e*.14,Math.max(t+.03,.6),n+.04-.1*r,e*.6,-1,-.4],o=(e,t)=>e.map((e,n)=>e+(t[n]-e)*r);return{c:[Math.max(.88,t-.95)+.17*r,n-.22+.2*r,.6*r,0],a:[a(-1),a(1)],l:[o([-.11,.12,.05-i,-.15,.2,1,0],[-.11,.25,.1,-.15,.2,1,0]),o([.11,.1,-.12+i,...Lr,0],[.12,t+.07,n+.25,...Lr,0])]}},Vr=(e,t,n)=>t?e.map((e,r)=>e+((t[r]??e)-e)*n):e,Hr=e=>H([Math.sin(e[3]),Math.cos(e[2])*Math.cos(e[3]),Math.sin(e[2])]),Ur=e=>H([1-e[0]*e[0],-e[0]*e[1],-e[0]*e[2]]),[Wr,Gr,Kr,qr]=[.31,.27,.43,.38],Jr=(e,t,n)=>{let[r,i]=[Hr(e),Ur(Hr(e))];return[i[0]*n+r[0]*t,e[0]+i[1]*n+r[1]*t,e[1]+i[2]*n+r[2]*t]},Yr=e=>{let{w:t}=e,[n,r]=[yr(t.speed/2.5),yr(t.speed/9)],i=1+.2*t.sprint,a=Math.sin(e.phase),o=[.88-.03*r-.05*t.sprint-.05*n*r*a*a,0,.04+.28*r+.1*t.sprint,.04*r*a],s=yr(t.hang+t.climb),c=[-1,1].map(t=>{let a=Math.sin(e.phase+(t>0?Math.PI:0)),[s,c,l]=Jr(o,.5,t*.205);return[s+t*.04,c-.52+n*r*(.12+.3*Math.max(0,a)),l+n*(.05+.45*r*i)*a,t*.5,-1,-.6]}),l=[-1,1].map(t=>{let a=e.phase+(t>0?0:Math.PI),o=n*(.05+.3*r*i);return[t*.11,.07+o*Math.max(0,Math.cos(a)),n*(.1+.42*r*i)*Math.sin(a),t*.15,.2,1,0]}),u=e.flip?Math.sqrt(Math.sin(Math.PI*e.flip)):0,d=[[t.low,Rr.crouch],[t.air,Rr.air],[t.rise,Rr.rise],[e.dip,Rr.land],[t.dash,Rr.dash],[t.wr,zr[0]],[t.wl,zr[1]],[t.slide,Rr.slide],[s,s>.001?Br(e):{}],[u,Rr.tuck]];for(let[e,t]of d)e>.001&&(o=Vr(o,t.c,e),c=c.map((n,r)=>Vr(n,t.a?.[r],e)),l=l.map((n,r)=>Vr(n,t.l?.[r],e)));let[f,p]=[Hr(o),[0,0,1]],m=Jr(o,0,0),h=H(B(p,[f[0]*f[2],f[1]*f[2],f[2]*f[2]])),g=(e,t,n,r)=>e.map((e,i)=>{let a=t(i?1:-1),[o,s]=Lt(a,e.slice(0,3),e.slice(3,6),n,r);return{root:a,mid:o,end:s,dir:H(B(s,o)),tilt:e[6]??0}}),_={pelvis:m,spine:f,chest:h,head:Jr(o,.787,0),look:H(V(h,p,.5)),arms:g(c,e=>Jr(o,.5,e*.205),Wr,Gr),legs:g(l,e=>Jr(o,0,e*.11),Kr,qr)};for(let e of _.arms)e.dir=H(V(e.dir,[0,-.15,1],s));if(e.flip){let t=2*Math.PI*(3-2*e.flip)*e.flip*e.flip,[n,r]=[Math.cos(t),Math.sin(t)],i=([e,t,i],a=[0,0,0])=>[e,a[1]+(t-a[1])*n-(i-a[2])*r,a[2]+(i-a[2])*n+(t-a[1])*r],a=[0,m[1]+.15,m[2]];_.pelvis=i(m,a),_.head=i(_.head,a);for(let e of[`spine`,`chest`,`look`])_[e]=i(_[e]);for(let e of[..._.arms,..._.legs])[e.root,e.mid,e.end]=[e.root,e.mid,e.end].map(e=>i(e,a)),e.dir=i(e.dir)}return _},[Xr,Zr,Qr,$r]=[[.12,.13,.17],[.09,.07,.06],[.16,.16,.19],[.03,.03,.04]],ei=(e,t,n,r)=>{let i=H([-t.p.vx,0,-t.p.vz]),[a,o,s]=n.map(e=>.6+.6*e);[[.5,.12,1.3],[.9,-.16,1.7],[1.25,.14,1.2]].forEach(([n,c,l],u)=>{let d=r([c,n,-.2-.1*u]),f=d.map((e,n)=>e+i[n]*l*t.w.dash);for(let t of[[-i[2]*.03,0,i[0]*.03],[0,.03,0]])for(let n of[d.map((e,n)=>e+t[n]),d.map((e,n)=>e-t[n]),f])e.push(...n,0,1,0,a,o,-2,s)})},ti=(e,t,n,r=1)=>{let i=Yr(t),[a,o]=[Math.sin(t.yaw),Math.cos(t.yaw)],{x:s,y:c,z:l}=t.p,u=([e,t,n])=>[s+e*o-n*a,c+t,l-e*a-n*o],d=([e,t,n])=>[e*o-n*a,t,-e*a-n*o],[f,p,m]=[d([1,0,0]),d(i.chest),d(i.spine)],h=u(i.pelvis);At(e,r,h,m,p,f,n,Xr);let[g,_]=[r,0].map(e=>U(e,0,[1,1])),[v,y]=[u(i.head),Tt(d(i.look),f)];r&&jt(e,r,h,m,f),W(e,g,v,y,[0,0,.012],[.082,.12,.1],Et),W(e,g,v,y,[0,.02,-.004],[.088,.113,.11],Zr),r&&(W(e,_,h.map((e,t)=>e+m[t]*.58),y,[0,0,-.075],[.115,.055,.06],n),W(e,_,v,y,[0,-.02,.108],[.016,.028,.022],Et),W(e,_,v,y,[0,.025,.083],[.068,.016,.03],$r));let b=d([0,0,1]);for(let{root:t,mid:n,end:a,tilt:o}of i.legs){let[i,s,c]=[t,n,a].map(u);G(e,U(r,Kr,K.thigh,[.5,1]),i,s,f,Kr,1,Xr),G(e,U(r,qr,K.shin,[.5,.5]),s,c,f,qr,1,Xr);let l=[Math.sin(o)*f[0],Math.cos(o),Math.sin(o)*f[2]];Mt(e,r,c,H(B(c,s)),b,xr(b,l),Qr)}for(let{root:t,mid:a,end:o,dir:s}of i.arms){let[i,c,l]=[t,a,o].map(u);G(e,U(r,Wr,K.upper,[1,.5]),i,c,f,Wr,1,n),G(e,U(r,Gr,K.fore,[.5,0]),c,l,f,Gr,1,n),W(e,_,l,Tt(d(s),f),[0,0,.04],[.04,.036,.058],Et)}t.w.dash>.15&&ei(e,t,n,u)},ni=Object.keys(m).length,ri=(e,t,n)=>{let r=Math.imul(e,374761393)+Math.imul(t,668265263)+Math.imul(n,144665)|0;return r=Math.imul(r^r>>>13,1274126177),((r^r>>>16)>>>0)/4294967296},X=(e,t,n,r)=>{let[i,a]=[Math.floor(e),Math.floor(t)],[o,s]=[e-i,t-a].map(e=>e*e*(3-2*e)),c=(e,t)=>ri((i+e)%n,(a+t)%n,r);return(c(0,0)*(1-o)+c(1,0)*o)*(1-s)+(c(0,1)*(1-o)+c(1,1)*o)*s},ii=(e,t,n,r,i)=>{let[a,o]=[0,.5];for(let s=0;s<r;s++,o/=2)a+=o*X(e*(1<<s),t*(1<<s),n<<s,i+s);return a/(1-o*2)},ai=(e,t,n)=>e.map((e,r)=>e+(t[r]-e)*n),Z=(e,t)=>e.map(e=>e*t),Q=e=>Math.min(Math.max(e,0),1),oi=Math.PI*2,$=[];$[m.BRICK]=(e,t)=>{let n=Math.floor(t*8),r=e*4+(n&1)*.5,[i,a,o]=[Math.floor(r)%4,r%1,t*8%1],s=X(e*16,t*16,16,5),c=.8+.4*s;return a<.05||o<.1?[Z([165,160,150],.7+.3*c),.1+.1*s]:[Z([170,78,56],(.8+.4*ri(i,n,1))*c*(.85+.15*o)),.7+.2*s+.1*Q(Math.min(a-.05,o-.1)*12)]},$[m.TILE]=(e,t)=>{let[n,r]=[Math.floor(e*4),Math.floor(t*4)],[i,a]=[e*4%1,t*4%1],o=X(e*16,t*16,16,7),s=.9+.2*o;return i<.05||a<.05?[Z([85,85,80],s),.1]:[Z([196,190,172],s*(.88+.08*(n+r&1)+.1*ri(n,r,2))),.8+.1*o+.1*Q((Math.min(i,a)-.05)*14)]},$[m.LAVA]=(e,t)=>{let n=ii(e*4,t*4,4,4,11),r=Math.max(0,1-Math.abs(n-.5)*7)**2;return[ai(ai([55,8,4],[230,70,8],n),[255,215,90],r),.5]},$[m.STONE]=(e,t)=>{let n=ii(e*8,t*8,8,4,3);return[Z([128,124,120],.45+.7*(n*1.3+.1*ri(Math.floor(e*128),Math.floor(t*128),4))),Q(n*1.4-.2)]},$[m.METAL]=(e,t)=>{let[n,r,i,a]=[Math.floor(e*2),Math.floor(t*2),e*2%1,t*2%1],o=Q((X(e*8,t*8,8,13)-.68)*6),s=e=>Math.min(Math.max(Math.round((e-.1)/.4),0),2)*.4+.1,[c,l]=[s(i),s(a)],u=c==l&&c==.5?1:Math.hypot(i-c,a-l),d=Q(1-u/.07),f=Z([98,108,124],(.9+.2*X(e*32,t*32,32,9)+.12*ri(n,r,6))*(1+.3*d)*(.65+.35*Q((u-.06)/.04)));return Math.min(i,a,1-i,1-a)<.03?[Z([40,44,50],1+o),.05]:[ai(f,[105,68,45],o*.7),.5+.1*(1-o)+.4*d]},$[m.WOOD]=(e,t)=>{let n=Math.floor(t*8),r=e*2+ri(n,0,8)*2,[i,a,o]=[Math.floor(r)%2,r%1,t*8%1],s=ri(n,i,3),c=.5+.5*Math.sin(oi*(t*40+2.5*X(e*4,t*4,4,21)+s*7));return o<.08||a<.015?[[28,18,10],.05]:[ai([92,58,32],[158,106,62],c*.6+s*.35),.7+.15*c+.15*Q((o-.08)*15)]},$[m.MOSS]=(e,t)=>{let n=Math.floor(t*4),r=e*2+(n&1)*.5,[i,a,o]=[Math.floor(r)%2,r%1,t*4%1],s=Math.min(a,1-a,(o<.5?o:1-o)*.5),c=a<.04||o<.06,l=Q((.3*ii(e*12,t*12,12,3,17)-.03-s)*12),u=X(e*64,t*64,64,19),d=Z([128,126,118],(.7+.4*ri(i,n,5))*(.7+.5*X(e*16,t*16,16,15)));return[ai(c?Z(d,.45):d,ai([52,100,34],[96,148,56],u),l),c?.1+.6*l*u:.6+.2*Q(s*30)+.2*l*u]},$[m.GRATE]=(e,t)=>{let[n,r]=[e*8%1,t*8%1],i=Math.max(Math.abs(n-.5),Math.abs(r-.5)),a=Math.min(Math.abs(n-.5),Math.abs(r-.5))>.43,o=X(e*16,t*16,16,23);return i<.36?[[9,9,12],0]:[Z(ai([104,108,116],[96,80,68],Q((o-.55)*4)),(a?1.25:1)-(.5-i)*2.2+.2*o),a?1:.6+.4*Q((i-.36)*12)]};var si=()=>{let e=new Uint8ClampedArray(ni*128*128*4);return $.forEach((t,n)=>{for(let r=0;r<16384;r++){let[i,a]=t(r%128/128,Math.floor(r/128)/128);e.set([...i,a*255],(n*128*128+r)*4)}}),e},ci=1<<18,li=2,ui=1024,di=.6,fi=Math.tan(70*Math.PI/360),pi=10,mi=4,hi=`#version 300 es
1
+ var e=.4,t=1.8,n=1.55,r=.5,i=.9,a=7.5,o=2.4,s=5.5,c=2.5,l=[`Red`,`Blue`],u=[`#ff3d4f`,`#2f80ff`],d=1.5,f={HOME:0,CARRIED:1,DROPPED:2},p={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,SPRINT:32,DASH:64,CROUCH:128},m={GROUND:0,AIR:1,WALLRUN:2,HANG:3,CLIMB:4,SLIDE:5,CROUCH:6},h={NONE:0,EAST:1,WEST:2,SOUTH:3,NORTH:4},g={JUMP:1,DOUBLE:2,DASH:4,LAND:8,GRAB:16,CLIMB:32,WALLRUN_START:64,WALLRUN_END:128,SLIDE_START:256,SLIDE_END:512,RESPAWN:1024},_={BRICK:0,TILE:1,LAVA:2,STONE:3,METAL:4,WOOD:5,MOSS:6,GRATE:7,CONCRETE:8,GLASS:9,STEEL:10,PAINT:11},v=-30,y=(e,t,n,r,i,a=_.CONCRETE)=>({min:[e,v,t],max:[n,i,r],top:_.CONCRETE,side:a}),b=([e,t,n],[r,i,a],o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c}),x={name:`Rooftops`,brushes:[y(4,57.7,24,76,10),y(4,36,24,53.5,10,_.GLASS),y(4,20,24,36,12.4),y(4,-5,24,7,12.4,_.GLASS),y(27,20,47,50,8),y(27,60,47,76,8,_.BRICK),b([9,12.2,39],[19,12.6,47],_.STEEL),...((e,t)=>[1,2,3,4,5,6].map(n=>b([12,t,e-n],[14,t+.4*n,e-n+1],_.CONCRETE)))(53,10),b([5,10,42],[5.5,14,42.5],_.STEEL),b([5,10,50],[5.5,14,50.5],_.STEEL),b([8,12.4,24],[20,12.85,24.45],_.STEEL),b([36,8,22],[37,14.5,48],_.PAINT,_.PAINT,[.15,.72,.62]),b([30,8,28],[34,10,32],_.CONCRETE),b([40,8,30],[44,10.2,34],_.PAINT,_.PAINT,[1,.3,.06]),b([28,9.2,44],[35,12,46],_.STEEL,_.PAINT,[.2,.42,1]),b([41.5,7.6,50],[42,8,60],_.STEEL),b([30,8,64],[34,9.6,68],_.PAINT,_.PAINT,[.2,.8,.3])],teams:[{base:[14,10,62.5],spawns:[[6,10,72,0],[10,10,72,0],[14,10,72,0],[18,10,72,0],[22,10,72,0],[8,10,66,0],[14,10,66,0],[20,10,66,0]]},{base:[14,12.4,2.2],spawns:[[6,12.4,-3,Math.PI],[10,12.4,-3,Math.PI],[14,12.4,-3,Math.PI],[18,12.4,-3,Math.PI],[22,12.4,-3,Math.PI],[8,12.4,.5,Math.PI],[14,12.4,.5,Math.PI],[20,12.4,.5,Math.PI]]}],floor:-25,sun:{dir:[.6,.64,.48],color:[2.6,2.3,1.8]},sky:[[.04,.2,.72],[.72,.86,.98]],fog:[.72,.86,.98,.0055]},S=4,C=1024,w=(e,t)=>(e+C)*(2*C)+t+C,T=(e,t)=>Math.min(Math.max(Math.floor(e/t),-1024),1023),E=(e,t=S)=>{let n=/* @__PURE__ */ new Map;return e.brushes.forEach(({min:e,max:r},i)=>{for(let a=T(e[0],t);a<=T(r[0],t);a++)for(let o=T(e[2],t);o<=T(r[2],t);o++){let e=w(a,o),t=n.get(e);t?t.push(i):n.set(e,[i])}}),{def:e,cell:t,grid:n}},D=(e,t,n,r)=>{let i=[];for(let a=T(t-r,e.cell);a<=T(t+r,e.cell);a++)for(let t=T(n-r,e.cell);t<=T(n+r,e.cell);t++)for(let n of e.grid.get(w(a,t))??[])i.includes(n)||i.push(n);return i},O=(e,t,n,r)=>{let{cell:i,def:a}=e,o=r,s=T(t[0],i),c=T(t[2],i),l=Math.sign(n[0]),u=Math.sign(n[2]),d=l?((s+ +(l>0))*i-t[0])/n[0]:1/0,f=u?((c+ +(u>0))*i-t[2])/n[2]:1/0,p=d,m=f,h=l?i/Math.abs(n[0]):1/0,g=u?i/Math.abs(n[2]):1/0;for(;;){for(let r of e.grid.get(w(s,c))??[]){let e=a.brushes[r],[i,s]=[0,o];for(let r=0;r<3&&i<=s;r++){if(!n[r]){(t[r]<e.min[r]||t[r]>e.max[r])&&(s=-1);continue}let a=(e.min[r]-t[r])/n[r],o=(e.max[r]-t[r])/n[r];i=Math.max(i,Math.min(a,o)),s=Math.min(s,Math.max(a,o))}i<=s&&s>0&&i<o&&(o=i)}if(Math.min(p,m)>=o||Math.abs(s)>C||Math.abs(c)>C)return o;p<m?(s+=l,p+=h):(c+=u,m+=g)}},ee=(e,t,n)=>{let[r,i,a]=[n[0]-t[0],n[1]-t[1],n[2]-t[2]],o=Math.hypot(r,i,a);return o>0&&O(e,t,[r/o,i/o,a/o],o)<o-1e-4},k=1/60,A=Math.PI*2,j=1e-6,M=.01,N=.001,P=e=>(e%A+A)%A,te=e=>[-Math.sin(e),-Math.cos(e)],F=Math.fround,I=Math.sqrt,ne=(e,t,n)=>Math.min(Math.max(e,t),n),L=(e,t)=>I(e*e+t*t),R=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],re={vx:0,vz:0,mode:m.GROUND,t:0,wall:h.NONE,edge:0,jumps:1,dashes:1,dash:0,stun:0,coyote:6,buffer:0,held:0,ev:0,fall:0},ie=(e,t,n,r=0)=>{let{spawns:i}=t.def.teams[r],[a,o,s,c]=i[(n%i.length+i.length)%i.length];return{id:e,x:F(a),y:F(o),z:F(s),vy:0,yaw:P(c),pitch:0,ground:!0,...re}},ae=e=>e===m.GROUND||e===m.SLIDE||e===m.CROUCH,oe=e=>e.mode===m.SLIDE||e.mode===m.CROUCH?i:t,se=e=>e.mode===m.SLIDE||e.mode===m.CROUCH?.7:1.6,ce=e=>L(e.vx,e.vz),le=e=>e.mode===m.GROUND&&L(e.vx,e.vz)>6.5,ue=(e,t,n)=>e.max[1]>t+.5+M&&e.min[1]<t+n-M,de=(e,t,n)=>[t-ne(t,e.min[0],e.max[0]),n-ne(n,e.min[2],e.max[2])],fe=(t,n,r)=>{let{brushes:i}=n.def,a=D(n,t.x,t.z,2*e),o=(e-j)**2,[s,c]=[0,0];for(let n=0;n<4;n++){let n=0,l=0,u=0;for(let s of a){let a=i[s];if(!ue(a,t.y,r))continue;let[c,d]=de(a,t.x,t.z),f=c*c+d*d;if(f>=o)continue;if(f){let t=I(f);.4-t>n&&(n=e-t,l=c/t*n,u=d/t*n);continue}let[p,m,h]=[[t.x-a.min[0],-1,0],[a.max[0]-t.x,1,0],[t.z-a.min[2],0,-1],[a.max[2]-t.z,0,1]].reduce((e,t)=>t[0]<e[0]?t:e);p+.4>n&&(n=p+e,[l,u]=[m*n,h*n])}if(!n)break;t.x+=l,t.z+=u,s+=l,c+=u}return[s,c]},pe=(t,n,r)=>{let{brushes:i}=n.def,a=(e-j)**2,o=-1/0,s=1/0;for(let c of D(n,t.x,t.z,e)){let e=i[c],[n,l]=de(e,t.x,t.z);n*n+l*l>=a||(e.max[1]<=t.y+.5+M?o=Math.max(o,e.max[1]):e.min[1]>=t.y+r-M&&(s=Math.min(s,e.min[1])))}return[o,s]},me=(t,n)=>{let r=(e-j)**2;return D(n,t.x,t.z,e).every(e=>{let i=n.def.brushes[e],[a,o]=de(i,t.x,t.z);return a*a+o*o>=r||!ue(i,t.y,1.8)})},he=(t,n,r,i,a)=>{let o=(e-j)**2;return D(t,n,r,e).every(e=>{let s=t.def.brushes[e],[c,l]=de(s,n,r);return c*c+l*l>=o||s.max[1]<=i||s.min[1]>=a})},ge=(e,t)=>{let[n,r]=R[t],i=n?0:2;return{a:i,o:2-i,sign:n||r,c:n?e.x:e.z,co:n?e.z:e.x}},_e=(e,t,n,r)=>{let{a:i,o:a,sign:o,c:s,co:c}=ge(t,n),l=((o>0?e.min[i]:e.max[i])-s)*o;return l>=.4-N&&l<=.4+r&&c>=e.min[a]&&c<=e.max[a]?l:void 0},ve=(t,n,r)=>{let i;for(let a of D(n,t.x,t.z,.9)){let o=n.def.brushes[a],s=_e(o,t,r,.5);s!==void 0&&o.min[1]<t.y+.5&&o.max[1]>t.y+1.8&&(i=Math.min(i??1/0,Math.max(0,s-e)))}return i},ye=(e,t)=>{let[n,r]=te(e.yaw),i;for(let a=1;a<=4;a++){let[o,s]=R[a];if(a===e.wall||n*o+r*s<.5)continue;let{a:c,sign:l}=ge(e,a);for(let n of D(t,e.x,e.z,.6000000000000001)){let r=t.def.brushes[n],o=r.max[1],s=o-e.y;if(_e(r,e,a,.2)===void 0||s<1.2||s>2.4||r.min[1]>o-.25||i&&i.top>=o)continue;let u=l>0?r.min[c]:r.max[c],d=u-l*.43000000000000005,f=u+l*.2,[p,m]=c===0?[d,e.z]:[e.x,d],[h,g]=c===0?[f,e.z]:[e.x,f];he(t,p,m,Math.min(e.y,o-2)+M,o+1.8)&&he(t,h,g,o+M,o+1.8)&&(i={side:a,top:o,hang:d})}}return i},be=(e,t)=>{let{a:n,o:r,sign:i,c:a,co:o}=ge(e,e.wall);return D(t,e.x,e.z,0).some(s=>{let c=t.def.brushes[s],l=i>0?a-c.min[n]:c.max[n]-a;return F(c.max[1])===e.edge&&o>=c.min[r]&&o<=c.max[r]&&l>=.2})},xe=(e,n)=>{if(e.vy>=0)return!1;let[r]=pe(e,n,t),i=6*k;return e.y-r<=-e.vy*i+10*i*i},z=(e,t)=>{e.mode=t,e.t=0},Se=(e,t)=>{let n=L(e.vx,e.vz);n>t&&(e.vx*=t/n,e.vz*=t/n)},Ce=(t,n,r,i)=>{let[a,o]=[r.wx,r.wz];for(let r of D(n,t.x,t.z,e+N)){let e=n.def.brushes[r],[s,c]=de(e,t.x,t.z),l=L(s,c);if(l>0&&l<=.4+N&&ue(e,t.y,i)){let e=(-a*s-o*c)/l;e>0&&(a+=e*s/l,o+=e*c/l)}}return[a,o]},we=(e,t,n)=>{let r=L(t[0],t[1]);if(r<j){let t=L(e.vx,e.vz),n=t?Math.max(0,t-45*k)/t:0;e.vx*=n,e.vz*=n;return}let[i,a]=[t[0]/r,t[1]/r],o=e.vx*i+e.vz*a,[s,c]=[e.vx-o*i,e.vz-o*a],l=L(s,c);if(l){let e=Math.max(0,l-45*k)/l;[s,c]=[s*e,c*e]}n*=r,o=o<n?Math.min(n,o+(o>=6?3:50)*k):Math.max(n,o-12*k),e.vx=s+o*i,e.vz=c+o*a},Te=(e,t,n,r,i)=>{let a=e.y;e.x+=e.vx*k,e.z+=e.vz*k;let[o,s]=fe(e,t,n),c=L(o,s);if(c){let t=(e.vx*o+e.vz*s)/c;t<0&&(e.vx-=t*o/c,e.vz-=t*s/c)}let[l,u]=pe(e,t,n),d=e.vy-r*20*k;if(e.y+=(e.vy+d)/2*k,e.vy=d,e.y+n>u&&(e.y=u-n,e.vy=Math.min(e.vy,0)),e.vy<=0?e.y<=l+M:e.y<l){if(e.y=l,e.vy<=0){let t=-e.vy;return e.vy=0,t}}else if(i&&e.vy<=0&&l>=a-.5)return e.y=l,e.vy=0,0;return-1},Ee=(e,t)=>{e.vy=t,e.coyote=0,e.buffer=0,e.ev|=g.JUMP},De=(e,n,r)=>{let[i,a]=R[e.wall],o=t=>{z(e,t),e.edge=0};if(r.keys&(p.BACK|p.CROUCH))o(m.AIR),e.coyote=0;else if(r.jump&&r.fx*i+r.fz*a<0)o(m.AIR),e.vx=-i*4,e.vz=-a*4,Ee(e,6);else if(r.jump||r.fwd&&e.t>=6)z(e,m.CLIMB);else if(e.t>=30)o(m.AIR),e.coyote=0;else{let r=Math.max(e.edge-2,pe(e,n,t)[0]);e.y+=ne(r-e.y,-8*k,8*k)}},Oe=(e,t)=>{let[n,r]=R[e.wall];e.y<e.edge?e.y=Math.min(e.edge,e.y+8*k):(e.x+=n*s*k,e.z+=r*s*k),e.y>=e.edge&&be(e,t)?(z(e,m.GROUND),e.vx=n*3,e.vz=r*3,e.vy=0,e.edge=0,e.wall=h.NONE,e.coyote=6,e.ev|=g.CLIMB):e.t>=40&&(z(e,e.y>=e.edge?m.GROUND:m.AIR),e.edge=0,e.wall=h.NONE)},ke=(e,t,n)=>{let[r,i]=R[e.wall],a=e.vx*r+e.vz*i,[o,s]=[e.vx-a*r,e.vz-a*i],c=L(o,s);if(n.jump)z(e,m.AIR),e.vx=o-r*5,e.vz=s-i*5,Ee(e,6.5),e.jumps=1,e.dashes=1,e.ev|=g.WALLRUN_END;else{let a=ve(e,t,e.wall);if(a===void 0||!n.fwd||c<3.5||e.t>=60){z(e,m.AIR),e.ev|=g.WALLRUN_END;return}let l=Math.max(0,c-1.5*k)/c;e.vx=o*l,e.vz=s*l;let u=Math.min(a,4*k);e.x+=r*u,e.z+=i*u}},Ae=(e,t,n)=>{if(!n.fwd)return;let r=L(e.vx,e.vz);if(!(r<4.5))for(let n=1;n<=4;n++){let[i,a]=R[n],o=e.vx*i+e.vz*a,[s,c]=[e.vx-o*i,e.vz-o*a];if(n!==e.wall&&o<=.75*r&&o>=-.2*r&&ve(e,t,n)!==void 0){let t=L(s,c),i=Math.max(t,.9*r)/t;z(e,m.WALLRUN),e.wall=n,[e.vx,e.vz]=[s*i,c*i],e.vy=ne(e.vy,2,3),e.jumps=1,e.dashes=1,e.coyote=0,e.ev|=g.WALLRUN_START;return}}},je=(e,t)=>{z(e,m.HANG),e.wall=t.side,e.edge=F(t.top),t.side<=h.WEST?e.x=t.hang:e.z=t.hang,e.vx=e.vy=e.vz=0,e.jumps=1,e.dashes=1,e.coyote=0,e.buffer=0,e.ev|=g.GRAB},Me=(e,t,n)=>{let r=e.mode===m.GROUND;if(n.dash&&e.dash===0&&(r||(e.mode===m.AIR||e.mode===m.WALLRUN)&&e.dashes>0)){let[t,i]=n.wx||n.wz?[n.wx,n.wz]:[n.fx,n.fz];r||(e.dashes--,e.vy=0,e.mode===m.WALLRUN&&(z(e,m.AIR),e.ev|=g.WALLRUN_END)),e.vx=t*16,e.vz=i*16,e.dash=60,e.ev|=g.DASH}let i=e.dash>50;e.mode===m.WALLRUN&&ke(e,t,n),ae(e.mode)&&Ne(e,t,n,i),e.mode===m.AIR&&Pe(e,t,n,i);let o=i&&e.vy<=0?0:e.mode===m.WALLRUN?.15:1,s=e.mode,c=Te(e,t,oe(e),o,ae(s));if(c>=0){if(!ae(e.mode)){if(e.ev|=g.LAND|(e.mode===m.WALLRUN?g.WALLRUN_END:0),e.fall=c,e.jumps=1,e.dashes=1,e.wall=h.NONE,n.keys&p.CROUCH){let t=L(e.vx,e.vz)>=a;z(e,t?m.SLIDE:m.CROUCH),e.ev|=t?g.SLIDE_START:0}else z(e,m.GROUND)}e.coyote=6}else ae(e.mode)&&(e.ev|=e.mode===m.SLIDE?g.SLIDE_END:0,z(e,m.AIR));if(e.mode===m.AIR){let r=ye(e,t);r?je(e,r):Ae(e,t,n)}},Ne=(e,n,r,o)=>{let s=(r.keys&p.CROUCH)!==0;if(e.buffer>0&&(e.mode===m.GROUND||me(e,n))){e.ev|=e.mode===m.SLIDE?g.SLIDE_END:0,z(e,m.AIR),Ee(e,7);return}let l=L(e.vx,e.vz);if(e.mode===m.GROUND&&s){let t=l>=a;z(e,t?m.SLIDE:m.CROUCH),e.ev|=t?g.SLIDE_START:0}else e.mode===m.SLIDE&&(e.t>=60||l<4.5||r.stumble)?(e.ev|=g.SLIDE_END,z(e,!s&&me(e,n)?m.GROUND:m.CROUCH)):e.mode===m.SLIDE&&!s&&me(e,n)?(e.ev|=g.SLIDE_END,z(e,m.GROUND)):e.mode===m.CROUCH&&!s&&me(e,n)&&z(e,m.GROUND);if(!o){if(r.stumble){if(l>2.5){let t=Math.max(c,l-12*k)/l;e.vx*=t,e.vz*=t}else we(e,Ce(e,n,r,oe(e)),c)}else if(e.mode===m.SLIDE){let t=Math.max(0,l-4*k)/l;e.vx*=t,e.vz*=t}else if(e.mode===m.CROUCH)we(e,Ce(e,n,r,i),3);else{let i=(r.keys&p.SPRINT)!==0&&r.fwd;we(e,Ce(e,n,r,t),i?9:6)}}},Pe=(e,t,n,r)=>{if(e.buffer>0&&(e.coyote>0?Ee(e,7):e.jumps>0&&!xe(e,t)&&(e.jumps--,Ee(e,6),e.ev=e.ev&~g.JUMP|g.DOUBLE)),r||!n.wx&&!n.wz)return;let i=L(e.vx,e.vz);e.vx+=n.wx*14*k,e.vz+=n.wz*14*k,Se(e,Math.max(i,6))},Fe=(e,t,r,i=0)=>{e.yaw=P(t.yaw),e.pitch=Math.max(-1.55,Math.min(n,t.pitch));let a=(t.keys&p.FORWARD?1:0)-(t.keys&p.BACK?1:0),o=(t.keys&p.RIGHT?1:0)-(t.keys&p.LEFT?1:0),s=L(a,o)||1,[c,l]=te(e.yaw),u=n=>(t.keys&n)!==0&&(e.held&n)===0,d=e.stun>0,f={keys:t.keys,stumble:d,jump:!d&&u(p.JUMP),dash:!d&&u(p.DASH),fwd:a>0,wx:(c*a-l*o)/s,wz:(l*a+c*o)/s,fx:c,fz:l},h=e.mode;if(e.ev=0,e.fall=0,f.jump&&(e.buffer=7),d&&e.stun--,e.dash>0&&(e.dash--,e.dash===50&&Se(e,10)),e.mode===m.HANG&&De(e,r,f),e.mode===m.CLIMB?Oe(e,r):e.mode!==m.HANG&&Me(e,r,f),e.y<r.def.floor){let{yaw:t,pitch:n,id:a}=e;Object.assign(e,ie(a,r,a,i),{yaw:t,pitch:n,ev:e.ev|g.RESPAWN})}e.t=e.mode===h?Math.min(255,e.t+1):e.t,e.buffer=Math.max(0,e.buffer-1),e.mode===m.AIR&&h===m.AIR&&(e.coyote=Math.max(0,e.coyote-1)),e.held=t.keys&(p.JUMP|p.DASH),e.ground=ae(e.mode),e.x=F(e.x),e.y=F(e.y),e.z=F(e.z),e.vx=F(e.vx),e.vy=F(e.vy),e.vz=F(e.vz),e.edge=F(e.edge)},Ie=16,Le=65536/(2*Math.PI),Re=e=>Math.round(e*Le)&65535,ze=e=>Math.max(-32768,Math.min(32767,Math.round(e))),Be=e=>ze(e*1e4),Ve=e=>e/1e4,He=e=>e/Le,Ue=(e=0)=>Math.round(e*256)&16777215,We=e=>({...e,yaw:He(Re(e.yaw)),pitch:Ve(Be(e.pitch)),...e.view!==void 0&&{view:Ue(e.view)/256}}),Ge=e=>{let t=/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(11));t.setUint8(0,1),t.setUint16(1,e.seq&65535),t.setUint8(3,e.keys&255),t.setUint16(4,Re(e.yaw)),t.setInt16(6,Be(e.pitch));let n=Ue(e.view);return t.setUint16(8,n>>8),t.setUint8(10,n&255),t.buffer},Ke=e=>e===f.CARRIED?2:e===f.DROPPED?8:1,qe=e=>{if(e.byteLength<4)return null;let t=new DataView(e),n=t.getUint8(3),r=4+40*n;if(t.getUint8(0)!==2||e.byteLength<r+4+2)return null;let i=[];for(let e=0;e<n;e++){let n=4+e*40,r=t.getUint8(n+35),a=t.getUint8(n+38),[o,s]=[t.getUint8(n+37),t.getUint8(n+39)],c=r&7;i.push({id:t.getUint8(n),x:t.getFloat32(n+1),y:t.getFloat32(n+5),z:t.getFloat32(n+9),vx:t.getFloat32(n+13),vy:t.getFloat32(n+17),vz:t.getFloat32(n+21),edge:t.getFloat32(n+25),yaw:He(t.getUint16(n+29)),pitch:Ve(t.getInt16(n+31)),ack:t.getUint16(n+33),ground:c===m.GROUND||c===m.SLIDE||c===m.CROUCH,mode:c,wall:r>>3&7,jumps:r>>6&1,dashes:r>>7,t:t.getUint8(n+36),dash:o&63,stun:s&63,by:o>>6<<2|s>>6,coyote:a&7,buffer:a>>3&7,held:(a&64?p.JUMP:0)|(a&128?p.DASH:0),ev:0,fall:0})}let a=t.getUint16(r+2),o=r+4,s=[];for(let n=0;n<2;n++){let n=o<e.byteLength?t.getUint8(o):-1;if(n<0||n>f.DROPPED||o+Ke(n)>e.byteLength)return null;let r={state:n,by:0,x:0,y:0,z:0,left:0};n===f.CARRIED?r.by=t.getUint8(o+1):n===f.DROPPED&&([r.x,r.y,r.z]=[1,3,5].map(e=>t.getInt16(o+e)/Ie),r.left=t.getUint8(o+7)),s.push(r),o+=Ke(n)}return o===e.byteLength?{tick:t.getUint16(1),players:i,score:[t.getUint8(r),t.getUint8(r+1)],clock:a&32767,over:!!(a&32768),flags:s}:null},Je=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},Ye=44100,Xe=([e,t,n,r,i,a,o,s,c,l,u],d)=>{let f=new Float32Array(Math.ceil((r+i+a)*Ye)),p=0,m=0,h=0,g=()=>{d=d+1831565813|0;let e=Math.imul(d^d>>>15,1|d);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/2**31-1};for(let d=0;d<f.length;d++){let _=d/Ye;p+=t*2**(n*_)*(_>c?l:1)*(1+o*Math.sin(_*44))/Ye,p>=1&&(p%=1,h=g());let v=e==3?h:e==2?Math.sin(p*2*Math.PI):e?1-2*p:p<.5?1:-1;m+=(v-m)*s;let y=_<r?_/r:_<r+i?1:((r+i+a-_)/a)**2;f[d]=m*y*u}return f},B={STEP:0,WALLSTEP:1,JUMP:2,DOUBLE:3,DASH:4,LAND:5,GRAB:6,SCUFF:7,WIND:8,SCRAPE:9,TAKE:10,DROP:11,RETURN:12,CAPTURE:13,TACKLE:14,GRUNT:15},Ze=[[[2,130,-3,.001,.005,.06,0,1,0,1,.7],[3,8e3,-1,.001,0,.035,0,.4,0,1,.45]],[[3,12e3,0,.001,0,.03,0,.5,0,1,.4],[2,190,-3,.001,0,.04,0,1,0,1,.3]],[[3,14e3,0,.015,.02,.09,.3,.18,0,1,.5],[2,70,-2,.003,0,.07,0,1,0,1,.3]],[[3,4e3,3.5,.03,.03,.2,0,.25,0,1,.5],[2,350,1.2,.03,.02,.18,.02,1,0,1,.12]],[[3,14e3,-2.5,.008,.07,.2,.25,.3,0,1,.8],[3,3500,.5,.01,.06,.2,0,.12,0,1,.5]],[[2,70,-2.5,.001,.01,.2,0,1,0,1,.9],[3,7e3,-1,.001,0,.09,0,.25,0,1,.5]],[[3,6e3,-1,.001,0,.05,0,.5,0,1,.7],[2,160,-4,.001,0,.07,0,1,0,1,.5]],[[3,5e3,0,.01,.04,.14,.5,.3,0,1,.5],[3,2500,0,.03,0,.1,.4,.2,0,1,.3,.08]],[[3,2e4,0,.001,2.1,.001,.25,.06,0,1,1.2],[3,2e4,0,.001,2.1,.001,.35,.3,0,1,.3]],[[3,9e3,0,.001,2.1,.001,.5,.4,0,1,.5],[3,3e3,0,.001,2.1,.001,.4,.2,0,1,.5]],[[0,392,0,.003,.05,.08,0,.35,.07,1.5,.5],[2,784,0,.003,.03,.1,.01,1,0,1,.3,.05]],[[1,330,-2.2,.003,.04,.22,.04,.25,0,1,.45],[3,2500,-1,.001,0,.12,0,.3,0,1,.4]],[[2,659,0,.003,.06,.25,.015,1,.09,1.5,.5],[2,1318,0,.003,.03,.2,0,1,0,1,.2,.09]],[[0,523,0,.004,.07,.1,0,.3,0,1,.4],[0,659,0,.004,.07,.1,0,.3,0,1,.4,.11],[0,784,0,.004,.07,.1,0,.3,0,1,.4,.22],[0,1047,0,.004,.2,.35,.008,.3,0,1,.5,.33],[2,262,0,.004,.25,.3,0,1,0,1,.35,.33]],[[2,120,-3,.001,.01,.24,0,1,0,1,1],[3,5e3,-1.5,.001,0,.09,0,.35,0,1,.7],[3,2200,0,.01,.03,.16,.3,.15,0,1,.4,.03]],[[1,170,-.9,.012,.05,.17,.06,.2,0,1,.5],[3,3e3,0,.01,.04,.14,.4,.12,0,1,.5]]],Qe=[B.WIND,B.SCRAPE],$e=(e,t=Ze)=>{let n=t[e].map((t,n)=>[Xe(t,e*9+n),Math.round((t[11]??0)*Ye)]);return Float32Array.from({length:Math.max(...n.map(([e,t])=>t+e.length))},(e,t)=>Math.tanh(n.reduce((e,[n,r])=>e+(n[t-r]??0),0)))},et=(e,t=Ye/10)=>{let n=e.length-t;return Float32Array.from({length:n},(r,i)=>i<t?e[i]*Math.sqrt(i/t)+e[n+i]*Math.sqrt(1-i/t):e[i])},tt=Ye*60/108,nt=tt/4,rt=4,it=[2,150,-6,.002,0,.25,0,1,0,1,1],at=[3,9e3,0,.002,0,.15,0,.5,0,1,.5],ot=[3,3e4,0,.001,0,.04,0,.7,0,1,.15],st=()=>{let e=new Float32Array(tt*4*rt),t={},n=(n,r)=>(t[String(r)]??=Xe(r,1)).forEach((t,r)=>e[(n*nt+r)%e.length]+=t),r=e=>55*2**(e/12),i=[0,0,-4,-5],a=[0,0,12,0,0,7,12,7];for(let e=0;e<64;e++){let t=e%16;if(`x.......x.x.....`[t]==`x`&&n(e,it),`....x.......x...`[t]==`x`&&n(e,at),t%2==0){n(e,ot);let o=i[e>>4]+a[t>>1];n(e,[1,r(o),0,.005,.08,.18,0,.15,0,1,.6])}}[15,12,10,19,17,15].forEach((e,t)=>n([18,24,28,50,54,60][t],[2,r(e+24),0,.02,.1,.6,.01,1,0,1,.5]));let o=e.reduce((e,t)=>Math.max(e,Math.abs(t)),0);return e.map(e=>e/o*.35)},ct=40,lt=24,ut=.5,dt=`tiny-fps:muted`,ft=()=>{let e=!1;return{unlock:()=>{},listen:()=>{},play:()=>{},loop:()=>({set:()=>{}}),mute:t=>{e=t},get muted(){return e},destroy:()=>{}}},pt=(e=Ze)=>{let t;try{t=new AudioContext}catch{return ft()}let n=(e,n=1)=>{let r=t.createGain();return r.gain.value=n,r.connect(e),r},r=n(t.destination),i=n(r,ut),a=[],o=!1,s=/* @__PURE__ */ new Set,c=[0,0,0],l=0,u=!1,d=e=>{let n=t.createBuffer(1,e.length,Ye);return n.getChannelData(0).set(e),n},f=e=>{let n=t.createBufferSource();return n.buffer=e,n};return{unlock(){if(t.resume().catch(()=>{}),!o){o=!0,e.forEach((t,n)=>{let r=$e(n,e);a[n]=d(Qe.includes(n)?et(r):r)});let t=f(d(st()));t.loop=!0,t.connect(i),t.start()}},listen(e,t){[c,l]=[e,t]},play(e,i,o=1,u=1){let d=0,p=o;if(i){let[e,t,n]=i.map((e,t)=>e-c[t]),r=Math.hypot(e,t,n);p=Math.max(0,1-r/ct)**2*o,d=(e*Math.cos(l)-n*Math.sin(l))/Math.max(r,1)}let m=a[e];if(!m||!p)return;if(s.size>=lt){let e=[...s].reduce((e,t)=>t.vol<e.vol?t:e);if(e.vol>=p)return;e.src.stop(),s.delete(e)}let h=f(m);h.playbackRate.value=u;let g=t.createStereoPanner();g.pan.value=d,h.connect(g).connect(n(r,p));let _={vol:p,src:h};s.add(_),h.onended=()=>s.delete(_),h.start()},loop(e){let i,o;return{set(s,c){!i&&a[e]&&(i=f(a[e]),i.loop=!0,i.connect(o=n(r,0)),i.start()),i&&(o.gain.setTargetAtTime(s,t.currentTime,.08),i.playbackRate.setTargetAtTime(c,t.currentTime,.08))}}},mute(e){u=e,r.gain.setTargetAtTime(+!e,t.currentTime,.05)},get muted(){return u},destroy:()=>void t.close().catch(()=>{})}},mt=()=>{try{return localStorage.getItem(dt)==`1`}catch{return!1}},ht=e=>{e.mute(!e.muted);try{localStorage.setItem(dt,e.muted?`1`:`0`)}catch{}return e.muted},gt=(e,t)=>{if(!e)return[];if(e.over||t.over)return e.over&&!t.over?[{kind:`start`}]:[];let n=[];for(let r of[0,1])t.score[r]>e.score[r]&&n.push({kind:`capture`,team:r});let r=n.length>0;t.flags.forEach((t,i)=>{let a=e.flags[i];t.state===f.CARRIED&&(a.state!==f.CARRIED||a.by!==t.by)?n.push({kind:`take`,flag:i,by:t.by}):t.state===f.DROPPED&&a.state===f.CARRIED?n.push({kind:`drop`,flag:i}):t.state===f.HOME&&(a.state===f.DROPPED||a.state===f.CARRIED&&!r)&&n.push({kind:`return`,flag:i})});for(let r of t.players)r.stun>(e.players.find(e=>e.id===r.id)?.stun??1/0)&&n.push({kind:`tackle`,who:r.id,by:r.by,at:[r.x,r.y+1,r.z]});return n},_t=(e,t,n)=>{let r=e=>l[e].toLowerCase();switch(e.kind){case`take`:{let i=1-e.flag;return{team:i,text:e.flag===t.team?`${l[i]} took your flag`:e.by===t.id?`You took the ${r(e.flag)} flag`:`${n(e.by)} took the ${r(e.flag)} flag`}}case`drop`:return{team:e.flag,text:e.flag===t.team?`Your flag was dropped`:`${l[e.flag]} flag dropped`};case`return`:return{team:e.flag,text:e.flag===t.team?`Your flag returned`:`${l[e.flag]} flag returned`};case`capture`:return{team:e.team,text:`${l[e.team]} scored`};case`tackle`:return e.by===t.id?{team:t.team,text:`Tackled ${n(e.who)}!`}:void 0;default:return{text:`New match`}}},vt=(e,t)=>{let{team:n}=t;switch(e.kind){case`take`:return[{id:B.TAKE,rate:e.flag===n?.8:1}];case`drop`:return[{id:B.DROP,rate:e.flag===n?1:.85}];case`return`:return[{id:B.RETURN,rate:e.flag===n?1:.85}];case`capture`:return[{id:B.CAPTURE,rate:e.team===n?1:.8}];case`tackle`:return e.who===t.id?[{id:B.TACKLE},{id:B.GRUNT}]:e.by===t.id?[{id:B.TACKLE,gain:.8,rate:1.1}]:[{id:B.TACKLE,at:e.at}];default:return[]}},V=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],yt=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],bt=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],H=(e,t,n)=>[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n],U=e=>{let t=Math.hypot(...e)||1;return[e[0]/t,e[1]/t,e[2]/t]},xt=(e,t,n=0)=>{let[r,i,a,o,s,c]=[e,t,n].flatMap(e=>[Math.sin(e),Math.cos(e)]),l=[i,0,-r],u=[r*a,o,i*a];return[l.map((e,t)=>e*c-u[t]*s),u.map((e,t)=>e*c+l[t]*s),[-r*o,a,-i*o]]},St=(e,t,n=[0,0,0])=>{let r=[],i=e.filter((t,n)=>!n||Math.hypot(t[0]-e[n-1][0],t[1]-e[n-1][1])>1e-9),a=i.slice(1).map(([e,t],n)=>{let[r,a]=i[n],o=Math.hypot(e-r,t-a);return[(t-a)/o,-(e-r)/o]}),o=i.map(([e],t)=>{let[n,r]=[0,1].map(e=>(a[t-1]?.[e]??0)+(a[t]?.[e]??0)),i=Math.hypot(n,r);return e?[n/i,r/i]:[0,Math.sign(r)]}),s=(e,a)=>{let[s,c]=i[a],[l,u]=[Math.cos(e*A/t),Math.sin(e*A/t)];r.push(n[0]+s*l,n[1]+s*u,n[2]-c,o[a][0]*l,o[a][0]*u,-o[a][1])};for(let e=1;e<i.length;e++)for(let n=0;n<t;n++)[...i[e-1][0]?[[n,e-1],[n+1,e-1],[n+1,e]]:[],...i[e][0]?[[n,e-1],[n+1,e],[n,e]]:[]].forEach(([e,t])=>s(e,t));return r},Ct=(e,t,n,[r,i],a)=>{let o=(e,t,n,r)=>Array.from({length:t},(i,a)=>{let o=a*A/t/4;return[e*Math.sin(o),n-r*e*Math.cos(o)]});return St([...r?o(t[0],r,0,1):[[0,0]],...t.map((n,r)=>[n,e*r/(t.length-1)]),...i?o(t[t.length-1],i,e,-1).reverse():[[0,e]]],n,a)},wt=(e,[t,n,r])=>Array.from({length:e.length*(10/6)},(i,a)=>{let[o,s]=[Math.floor(a/10),a%10];return s<6?e[o*6+s]:[t,n,-1,r][s-6]}),Tt=[[5,1],[7,2],[10,3]],Et=/* @__PURE__ */ new Map,W=(e,t,n,r=[1,1])=>{let[i,a]=Tt[e];!e&&n.length>3&&(n=[n[0],n[n.length>>1],n[n.length-1]]);let o=`${e} ${t} ${n} ${r}`,s=Et.get(o);return s||(s=wt(Ct(t,n,i,r.map(e=>Math.ceil(a*e))),[1,1,1]),Et.set(o,s)),s},G=(e,t,n,[r,i,a],o,s,c=[1,1,1])=>{let[l,u,d]=typeof s==`number`?[s,s,s]:s,f=l==u&&u==d,[p,m,h,g,_,v,y,b,x]=[...r,...i,...a],S=n[0]+p*o[0]+g*o[1]+y*o[2],C=n[1]+m*o[0]+_*o[1]+b*o[2],w=n[2]+h*o[0]+v*o[1]+x*o[2];for(let n=0;n<t.length;n+=10){let[r,i,a]=[t[n]*l,t[n+1]*u,t[n+2]*d],[o,s,T]=[t[n+3],t[n+4],t[n+5]];if(!f){[o,s,T]=[o/l,s/u,T/d];let e=Math.sqrt(o*o+s*s+T*T)||1;[o,s,T]=[o/e,s/e,T/e]}e.push(S+p*r+g*i-y*a,C+m*r+_*i-b*a,w+h*r+v*i-x*a,p*o+g*s-y*T,m*o+_*s-b*T,h*o+v*s-x*T,t[n+6]*c[0],t[n+7]*c[1],t[n+8],t[n+9]*c[2])}},Dt=(e,t)=>{let n=e[0]*t[0]+e[1]*t[1]+e[2]*t[2],r=t.map((t,r)=>t-e[r]*n),i=Math.hypot(...r)||1,[a,o,s]=r.map(e=>e/i);return[[a,o,s],[o*e[2]-s*e[1],s*e[0]-a*e[2],a*e[1]-o*e[0]],e]},K=(e,t,n,r,i,a,o=1,s)=>{let c=[r[0]-n[0],r[1]-n[1],r[2]-n[2]],l=Math.hypot(...c)||1,[u,d]=typeof o==`number`?[o,o]:o;G(e,t,n,Dt([c[0]/l,c[1]/l,c[2]/l],i),[0,0,0],[u,d,l/a],s)},Ot=[.66,.45,.35],kt=[.82,.82,.84],At={upper:[.055,.052,.042],fore:[.04,.043,.03],thigh:[.09,.08,.058],shin:[.056,.06,.05,.037]},jt=[.17,.153,.16,.18,.196,.19,.105],Mt=.62,Nt=(e,t,n,r,i,a,o,s,c=1)=>{let l=n.map((e,t)=>e+r[t]*Mt*c);K(e,W(t,Mt,jt,[0,0]),n,l,a,Mt,[1,.62],o),G(e,W(t,0,[1,1]),n,Dt(i,a),[0,-.02,0],[.165,.11,.13],s)},Pt=(e,t,n,r,i)=>K(e,W(t,.17,[.066,.06],[0,.5]),n.map((e,t)=>e+r[t]*.55),n.map((e,t)=>e+r[t]*.72),i,.17,1,Ot),Ft=(e,t,n,r,i,a,o)=>{let s=bt(i,r)*.4,c=Dt(U([i[0]-r[0]*s,i[1]-r[1]*s,i[2]-r[2]*s]),a),l=W(0,0,[1,1]);G(e,W(t&&t-1,0,[1,1]),n,c,[0,-.048,.045],[.05,.022,.135],kt),G(e,W(t,0,[1,1]),n,c,[0,-.015,.03],[.046,.042,.115],o),t>1&&G(e,l,n,c,[0,-.04,.125],[.042,.028,.05],kt)},It=()=>W(0,.04,[.0105,.0095],[1,2]),Lt=[1,1.1,1,.82],Rt=[[[.55,-.2,.8],[.2,-.75,.6]],[[.4,-.1,.9],[-.55,-.5,.65]]],zt=(e,t,n,r,i,a,o=Ot)=>{let[s,c,l]=Dt(n,r),u=([e,n,r])=>[t[0]+s[0]*e*i+c[0]*n+l[0]*r,t[1]+s[1]*e*i+c[1]*n+l[1]*r,t[2]+s[2]*e*i+c[2]*n+l[2]*r],d=(t,n,r,i)=>n.reduce((t,n,a)=>{let c=[t[0]+n[0]*r,t[1]+n[1]*r,t[2]+n[2]*r];return K(e,It(),u(t),u(c),s,.04,i*.88**a,o),c},t);G(e,W(1,0,[1,1]),t,[s,c,l],[0,0,.045],[.0425,.02,.058],o);for(let e=0;e<4;e++){let[t,n]=[.1+1.3*a,.2+3*a],r=-(e-1.5)*.08*(1-a);d([.0315-.021*e,-.004,.092],[t,n].map(e=>U([r,-Math.sin(e),Math.cos(e)])),.04*Lt[e],1)}d([.034,-.012,.025],Rt.map(([e,t])=>U(H(e,t,a))),.037,1.25)},Bt=(e,t,n,r,i)=>{let a=V(t,e),o=U(a),s=Math.max(Math.min(Math.hypot(...a),(r+i)*.99),.15),c=(r*r-i*i+s*s)/(2*s),l=Math.sqrt(Math.max(r*r-c*c,0)),u=bt(n,o),d=U([n[0]-o[0]*u,n[1]-o[1]*u,n[2]-o[2]*u]);return[[e[0]+o[0]*c+d[0]*l,e[1]+o[1]*c+d[1]*l,e[2]+o[2]*c+d[2]*l],[e[0]+o[0]*s,e[1]+o[1]*s,e[2]+o[2]*s]]},Vt=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],Ht=2.2,Ut=.5,Wt=-.15,[Gt,Kt]=[.35,.38],[qt,Jt]=[.43,.45],Yt=[.95,.22,.1],[Xt,Zt,Qt]=[[.3,.32,.37],[.14,.15,.2],[.6,.61,.65]],$t=()=>({upper:W(2,Gt,At.upper,[1,1]),fore:W(2,Kt,At.fore,[1,0]),cuff:W(2,.03,[.033,.033],[0,0]),thigh:W(1,qt,At.thigh,[.5,1]),shin:W(1,Jt,At.shin,[.5,.5])}),q=(e,t,n,r,i,a,o)=>[[e*t,n,r],[e*i,a,o]],en=([e,t],[n,r],i)=>[H(e,n,i),H(t,r,i)],tn=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),nn={sprint:6,air:12,dash:14,hang:16,climb:12,wall:10,slide:10,low:12,amp:8,stun:14},rn={jump:5,tuck:4,land:7},an=()=>{let e,t={sprint:0,air:0,dash:0,hang:0,climb:0,wall:0,slide:0,low:0,amp:0,stun:0},n=0,r={jump:0,tuck:0,land:0},i={jump:0,tuck:0,land:0},a=0,o=0,s,c=e=>e==m.GROUND||e==m.WALLRUN||e==m.CROUCH,l=(l,{ev:u,fall:d},f)=>{if(!l){e=void 0;return}let p=e&&c(e.mode)&&c(l.mode)?Math.hypot(l.x-e.x,l.z-e.z):0,h=c(l.mode)&&p<1;a+=h?p*(Ht-.6*t.sprint):0,e={...l},n+=f;let _={sprint:+le(l),air:+(l.mode==m.AIR&&l.dash<=50),dash:+(l.dash>50),hang:+(l.mode==m.HANG),climb:+(l.mode==m.CLIMB),wall:+(l.mode==m.WALLRUN),slide:+(l.mode==m.SLIDE),low:+(l.mode==m.SLIDE||l.mode==m.CROUCH),amp:c(l.mode)?tn(ce(l)/9):0,stun:+(l.stun>0)};for(let e of Object.keys(nn))t[e]+=(_[e]-t[e])*(1-Math.exp(-f*nn[e]));u&g.JUMP&&(r.jump=1),u&g.DOUBLE&&(r.tuck=1),u&g.LAND&&(r.land=tn(d/12,.3));for(let e of Object.keys(rn))i[e]+=(r[e]-i[e])*(1-Math.exp(-f*24)),r[e]*=Math.exp(-f*rn[e]);let[v,y]=Vt[l.wall];o+=(tn(v*Math.cos(l.yaw)-y*Math.sin(l.yaw),-1,1)-o)*(1-Math.exp(-f*10)),(l.mode==m.HANG||l.mode==m.CLIMB)&&l.edge&&(s={x:l.x,z:l.z,y:l.edge,dx:v,dz:y})},u=(r,c,l,u=0)=>{if(!e||Math.hypot(...V(r,[e.x,e.y+se(e),e.z]))>Ut)return;let[d,f,p]=xt(c,l,u),m=e=>[bt(e,d),bt(e,f),bt(e,p)],h=([e,t,n])=>[d[0]*e+f[0]*t+p[0]*n,d[1]*e+f[1]*t+p[1]*n,d[2]*e+f[2]*t+p[2]*n],g=e=>yt(r,h(e)),[_,v]=[Math.sin(c),Math.cos(c)],y=([t,n,r])=>[e.x+t*v-r*_,e.y+n,e.z-t*_-r*v],b=t.amp*(1+.5*t.sprint),x=Math.max(t.hang,t.climb),S=[-1,1].map(e=>{let c=Math.sin(a+(e>0?Math.PI:0)),l=Math.sign(c)*Math.abs(c)**(1-.4*t.sprint),u=H([.27,-.27,.46],[.2,-.16,.44],t.sprint),d=q(e,u[0],u[1]+.08*b*l,u[2]+.1*b*l,.7,-1,-.5);d=en(d,q(e,.4,-.2,.36,.8,-.8,-.3),t.air),d=en(d,q(e,.3,.04,.5,.6,-1,-.2),i.jump),d=en(d,q(e,.15,-.24,.28,.9,-.4,-.6),i.tuck),d=en(d,q(e,.42,-.4,.3,1,-1,-.2),i.land),d=en(d,q(e,.13,-.1,.64,.7,-1,-.3),t.dash);let f=q(e,.4,-.2+.02*Math.sin(a*2),.52,.4,-1,-.5),p=t.wall*tn(o*e);d=en(d,f,p),d=en(d,e>0?q(1,.46,-.32,.4,1,-.4,-.5):q(1,-.3,-.12,.5,-.8,-.6,-.3),t.slide);let y=Math.sin(n*12+(e>0?Math.PI:0));d=en(d,q(e,.5,.05+.2*y,.5+.1*y,1,-.2,-.6),t.stun);let S;if(s){let t=-s.dz,n=s.dx;t*v-n*_<0&&([t,n]=[-t,-n]);let i=.43000000000000005,a=[s.x+s.dx*i+t*.12*e,s.y+.06,s.z+s.dz*i+n*.12*e],[o,c,l]=m(V(a,r));d=en(d,[[o,Math.max(c,-.36),Math.max(l,.3)],[e*.5,-1,-.4]],x),S=m([s.dx,-.15,s.dz])}let C=.55+.35*t.sprint;for(let[e,n]of[[.3,t.air],[.1,i.jump],[.9,i.tuck],[1,t.dash],[.1,p],[.35,t.slide],[.1,x],[.2,t.stun]])C+=(e-C)*n;let w=[e*(.15-.05*x),-.22+.08*x,-.2+.12*x],[T,E]=Bt(w,d[0],d[1],Gt,Kt),D=U(V(E,T));return{root:g(w),mid:g(T),end:g(E),dir:h(S?H(D,U(S),x):D),curl:C,roll:(1-x)*(1-2*p)}}),C=H([0,.88,-.12],[0,.46,-.2],t.low);C[2]+=.12*t.stun;let w=H(C,[0,.26,-.4],t.slide);w[1]-=.22*i.land;let T=H(H([0,1.4,-.2],[0,.55,-.12],t.low),[0,.5,-.3],t.slide);return T[2]-=.2*t.stun,{arms:S,legs:[-1,1].map(e=>{let n=Math.sin(a+(e>0?0:Math.PI)),r=Math.cos(a+(e>0?0:Math.PI)),o=t.amp*(1+.5*t.sprint),s=[e*.12,.07+.2*o*Math.max(0,r),-.02-.1*t.low+.3*o*n];s=H(s,[e*.12,.3,e*.2],t.air),s=H(s,[e*.12,.62,.1],i.tuck),s=H(s,[e*.1,.28,-.4],t.dash),s=H(s,[e*.1,.12,-.12],t.hang),s=H(s,e>0?[.1,.5,.2]:[-.1,.1,-.1],t.climb),s=H(s,[e*.11,.2,.84+.08*e],t.slide);let c=[w[0]+e*.11,w[1],w[2]],[l,u]=Bt(c,s,[e*.15,.2,1],qt,Jt);return{root:y(c),mid:y(l),end:y(u),dir:[-_,0,-v],curl:0,roll:1}}),torso:[y(w),y(T)],grip:x,low:t.low}};return{update:l,rig:u,draw(e,t,n,r,i=0){let a=u(t,n,r,i);if(!a)return;let[o]=xt(n,r,i),[s,c]=[[Math.cos(n),0,-Math.sin(n)],[-Math.sin(n),0,-Math.cos(n)]],[l,d]=a.torso,f=$t();if(r<Wt||a.low>.2){Nt(e,2,l,U(V(d,l)),c,s,Xt,Zt,.75);for(let{root:t,mid:n,end:r}of a.legs)K(e,f.thigh,t,n,s,qt,1,Zt),K(e,f.shin,n,r,s,Jt,1,Zt),Ft(e,1,r,U(V(r,n)),c,s,Qt)}a.arms.forEach(({root:t,mid:n,end:r,dir:i,curl:s,roll:c},l)=>{let u=l?1:-1,d=U(V(r,n));K(e,f.upper,t,n,o,Gt,1-.4*a.grip,Xt),K(e,f.fore,n,r,o,Kt,1-.3*a.grip,Xt),K(e,f.cuff,V(r,d.map(e=>e*.025)),yt(r,d.map(e=>e*.005)),o,.03,1,Yt),zt(e,r,i,yt(o.map(e=>e*(1-Math.abs(c))),[0,-u*c,0]),-u,s)})}}},on=e=>.6+.2*e,sn=e=>e?.mode===m.GROUND||e?.mode===m.CROUCH,cn=e=>sn(e)||e?.mode===m.WALLRUN,ln=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],un=e=>.02+.0025*e,dn=.006,fn=.03,pn=.14,mn=.05,hn=5,gn=9,_n=6.5,vn=.25,yn=.22,bn=.9,xn=4,Sn=1,Cn=.12,wn=24,Tn=15.7,En=.45,Dn=[-8,4,5],On=3,kn=[-1,1.2],An=4,jn=[.1,.05,11],Mn=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Nn=(e,t)=>{let n=Math.ceil(t*120);for(let r=0;r<n;r++)e[1]+=(-15.7*Tn*e[0]-2*En*Tn*e[1])*(t/n),e[0]+=e[1]*(t/n)},Pn=()=>{let e=0,t=0,n=0,r=0,i=0,a=0,o=0,s,c,l=[0,0],u=[0,0],d=[0,0],f={dy:0,pitch:0,roll:0,fov:0,lines:0,stride:0,hurt:0,jolt(){l[1]+=Dn[0],u[1]+=Dn[1],d[1]+=Dn[2],f.hurt=1},punch(){l[1]+=kn[0],u[1]+=kn[1],a=1},update(h,_,v,y={ev:0,fall:0}){let b=e=>Math.min(1,v*e),x=h?ce(h):0,S=h&&c&&cn(h)&&cn(c)?Math.hypot(h.x-c.x,h.z-c.z):0;S<1&&(f.stride+=S/on(x)),e+=((sn(h)&&S>.5*v&&S<1?1:0)-e)*b(10),c=h,y.ev&g.LAND&&(l[1]-=yn*Math.min(y.fall,20)),y.ev&g.CLIMB&&(l[1]-=yn*xn),y.ev&(g.JUMP|g.DOUBLE)&&(l[1]+=bn),y.ev&g.GRAB&&(u[1]-=Sn),Nn(l,v),Nn(u,v),Nn(d,v),f.hurt*=Math.exp(-v*On),a*=Math.exp(-v*10),o+=v*jn[2];let C=h?Math.min(1,h.stun/48):0,w=h?se(h):0;s=h?s===void 0?w:s+(w-s)*b(14):void 0,f.dy=(s??0)-w+l[0]-Math.cos(f.stride*2*Math.PI)*un(x)*e,i+=((h?.mode===m.CLIMB?Cn*Math.sin(Math.PI*Mn(h.t/wn)):0)-i)*b(10),f.pitch=u[0]+i+Math.sin(o*.8)*jn[1]*C;let T=h?.mode===m.WALLRUN?ln[h.wall]:[0,0],E=h?T[0]*Math.cos(h.yaw)-T[1]*Math.sin(h.yaw):0,D=+!!(_&p.RIGHT)-!!(_&p.LEFT);t+=(D*fn+E*pn+(h?.mode===m.SLIDE?mn:0)-t)*b(8),f.roll=t+Math.sin(f.stride*Math.PI)*dn*e+d[0]+Math.sin(o)*jn[0]*C;let O=!!h&&h.dash>50;n+=(+O-n)*b(O?40:6),r+=(Mn((x-6)/3)-r)*b(4),f.fov=r*hn+n*gn+a*An,f.lines+=(Mn((x-_n)/(9-_n))*vn+n*.75-f.lines)*b(8)}};return f},Fn=2.4,In=[1,.62],Ln=8,Rn=28,zn=2.2,Bn=.04,Vn=.045,Hn=e=>{let t=parseInt(u[e].slice(1),16);return[t>>16,t>>8&255,t&255].map(e=>e/255)},Un=(e,t,n)=>e.flatMap((e,r)=>{if(e.state===f.DROPPED)return[{team:r,at:[e.x,e.y,e.z],dropped:!0}];if(e.state===f.CARRIED){let t=n(e.by);return t?[{team:r,at:[t.x,t.y,t.z],by:{yaw:t.yaw,vx:t.vx,vz:t.vz}}]:[]}return[{team:r,at:t[r]}]}),Wn=[[1,0,0],[0,1,0],[0,0,1]],Gn=(e,t,n)=>{for(let r=t;r<e.length;r+=10)e[r+6]*=n,e[r+7]*=n,e[r+9]*=n,e[r+8]=-2},Kn=(e,t,n,r,[i,a,o])=>{let[s,c,l]=[n[0]-t[0],n[1]-t[1],n[2]-t[2]],[u,d,f]=[r[0]-t[0],r[1]-t[1],r[2]-t[2]],p=[c*f-l*d,l*u-s*f,s*d-c*u],m=Math.hypot(...p)||1;for(let s of[t,n,r])e.push(...s,p[0]/m,p[1]/m,p[2]/m,i,a,-1,o)},qn=(e,t,n,r,i)=>{for(let a=0;a<Rn;a++){let[o,s]=[a,a+1].map(e=>e*2*Math.PI/Rn),c=(e,n)=>[t[0]+e*Math.cos(n),t[1],t[2]+e*Math.sin(n)];Kn(e,c(n,o),c(r,s),c(r,o),i),Kn(e,c(n,o),c(n,s),c(r,s),i)}},Jn=(e,t,n,r)=>{for(let i=0;i<Rn;i++){let[a,o]=[i,i+1].map(e=>e*2*Math.PI/Rn);Kn(e,t,[t[0]+n*Math.cos(o),t[1],t[2]+n*Math.sin(o)],[t[0]+n*Math.cos(a),t[1],t[2]+n*Math.sin(a)],r)}},Yn=(e,t,n,r)=>{Jn(e,[t[0],t[1]+Bn,t[2]],d,n.map(e=>e*.4));let i=e.length;qn(e,[t[0],t[1]+Vn,t[2]],d-.16,d,n),Gn(e,i,zn*(.75+.25*Math.sin(r*3)))},Xn=(e,t,n,[r,i],a,o,s)=>{let c=[-n[2],0,n[0]],l=(e,s)=>{let l=a*e*Math.sin(o*7-e*5),u=i*s*(1-e);return[t[0]+n[0]*r*e+c[0]*l,t[1]-u+.12*r*e*Math.sin(o*5-e*4)*a,t[2]+n[2]*r*e+c[2]*l]};for(let t=0;t<Ln;t++){let[n,r]=[t/Ln,(t+1)/Ln],[i,a,o,c]=[l(n,0),l(r,0),l(r,1),l(n,1)],u=[(a[1]-i[1])*(c[2]-i[2])-(a[2]-i[2])*(c[1]-i[1]),(a[2]-i[2])*(c[0]-i[0])-(a[0]-i[0])*(c[2]-i[2]),(a[0]-i[0])*(c[1]-i[1])-(a[1]-i[1])*(c[0]-i[0])],d=Math.hypot(...u)||1,f=(e,t)=>[e[0]+u[0]/d*.004*t,e[1]+u[1]/d*.004*t,e[2]+u[2]/d*.004*t];for(let t of[1,-1]){let n=[i,a,o,c].map(e=>f(e,t)),[r,l,u,d]=t>0?n:[n[0],n[3],n[2],n[1]];Kn(e,r,l,u,s),Kn(e,r,u,d,s)}}},Zn=(e,t,n,r)=>{K(e,W(1,1,[1,1],[0,0]),t,n,[.6,0,.8],1,.045,[.82,.84,.9]);let i=e.length;G(e,W(1,0,[1,1]),n,Wn,[0,0,0],.09,r),Gn(e,i,zn)},Qn=(e,t,n,r)=>{let[i,a,o]=t.at,s=r+t.team*1.7;if(t.by){let{yaw:r,vx:c,vz:l}=t.by,u=-Math.sin(r),d=-Math.cos(r),f=Math.hypot(c,l),p=[i-u*.28,a+.55,o-d*.28],m=[i-u*.38,a+.55+Fn-.2,o-d*.38],[h,g]=f>1?[-c/f,-l/f]:[-u,-d];Zn(e,p,m,n);let _=Math.min(1,f/8);Xn(e,m,[h,0,g],[In[0]*(.7+.5*_),In[1]],.1+.16*_,s,n);return}if(t.dropped){let t=i*12.9898+o*78.233,[c,l]=[Math.cos(t),Math.sin(t)],u=[i+c*2.3,a+.6,o+l*2.3];Zn(e,[i,a+.06,o],u,n),Xn(e,u,[c,0,l],[In[0]*.8,In[1]*.8],.04,s,n);let f=e.length;qn(e,[i,a+Vn,o],d-.1,d,n),Gn(e,f,zn*(.5+.5*Math.abs(Math.sin(r*5))));return}let c=[i,a+Fn,o];Zn(e,[i,a,o],c,n);let l=.6+t.team*Math.PI;Xn(e,c,[Math.cos(l),0,Math.sin(l)],In,.18,s,n)},$n=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),er=e=>{let t=e.loop(B.WIND),n=e.loop(B.SCRAPE),r=0,i=/* @__PURE__ */ new Map,a=(t,n,r)=>{let i=le(t);e.play(t.mode===m.WALLRUN?B.WALLSTEP:B.STEP,r,i||t.mode===m.WALLRUN?1:t.mode===m.CROUCH?.35:.6,(i?.92:1)*(n&1?1.06:.94))},o=(t,n)=>e.play(B.LAND,n,$n(t/14,.2),1.25-.5*$n(t/20));return{me(i,s,c){let l=Math.floor(c),u=l>r;if(r=l,!i||e.muted)return;u&&a(i,l);for(let[t,n]of[[g.JUMP,B.JUMP],[g.DOUBLE,B.DOUBLE],[g.DASH,B.DASH],[g.GRAB,B.GRAB],[g.CLIMB,B.SCUFF]])s.ev&t&&e.play(n);s.ev&g.LAND&&o(s.fall);let d=$n((Math.hypot(i.vx,i.vy,i.vz)-4)/12);t.set(.55*d**1.5,.6+.9*d);let f=$n(ce(i)/9);n.set(i.mode===m.SLIDE?.2+.5*f:0,.8+.4*f)},others(t){for(let n of t){let t=i.get(n.id);if(t&&!e.muted){let e=[n.x,n.y+.1,n.z],r=Math.hypot(n.x-t.p.x,n.z-t.p.z);if(cn(n)&&cn(t.p)&&r<1){let i=Math.floor(t.stride);t.stride+=r/on(ce(n)),Math.floor(t.stride)>i&&a(n,i,e)}n.ground&&!t.p.ground&&t.p.vy<-3&&o(-t.p.vy,e)}i.set(n.id,{p:n,stride:t?.stride??0})}for(let e of i.keys())t.some(t=>t.id===e)||i.delete(e)}}},tr=`h5,aside,nav,output,section,em,u{position:absolute;margin:0;padding:0;pointer-events:none;user-select:none;white-space:pre-line}h5{top:8px;right:12px;font-size:12px}u{inset:0;opacity:0;background:radial-gradient(ellipse at center,#0000 35%,#d10000dd 120%)}nav{top:8px;left:50%;transform:translateX(-50%);display:grid;grid-template-columns:1fr auto 1fr;gap:2px 16px;align-items:center;text-align:center;font-size:13px}nav span,nav time{font:900 clamp(16px,4.6vw,24px)/1 system-ui,sans-serif;letter-spacing:.03em;white-space:nowrap}nav time{min-width:4.2ch;font-variant-numeric:tabular-nums;font-size:clamp(14px,3.8vw,20px)}nav small{font-size:clamp(10px,2.6vw,12px);white-space:nowrap;opacity:.95}nav small:first-of-type{text-align:right}nav small:last-of-type{text-align:left}output{top:20%;left:50%;transform:translateX(-50%);padding:6px 18px;font:900 clamp(18px,3.4vw,30px)/1.1 system-ui,sans-serif;letter-spacing:.06em;text-transform:uppercase;white-space:nowrap;background:#000a;border-bottom:3px solid currentColor}em{font-style:normal;font-size:13px;font-weight:800;line-height:1.1;text-align:center;transform:translate(-50%,-50%)}em span{display:block;font-size:20px;line-height:1}section{inset:0;z-index:2;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;padding:0 12px;text-align:center;background:#000c}section h6{font:900 clamp(30px,9vw,72px)/1 system-ui,sans-serif;letter-spacing:.04em}section strong{font-size:34px}section td:first-child{text-align:left;opacity:1}section td+td{text-align:center}section th{padding:2px 10px;font-size:12px;opacity:.7;font-weight:600}aside{inset:0;z-index:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:14px;padding:0 12px;text-align:center;background:#000b}h6{margin:0;font-size:inherit;text-shadow:none}aside h6{font:900 clamp(36px,13vw,84px)/1 system-ui,sans-serif;letter-spacing:.04em;transform:skewX(-8deg);background:linear-gradient(#fe6,#f92 45%,#d21);-webkit-background-clip:text;background-clip:text;color:transparent;filter:drop-shadow(0 3px 0 #500) drop-shadow(0 0 14px #f604)}strong{font-size:22px}table{border-collapse:collapse;font-size:16px}td{padding:2px 10px}td+td{text-align:left}td:first-child{text-align:right;opacity:.7}`,nr=2800,rr=e=>`${Math.floor(e/60)}:${`${e%60}`.padStart(2,`0`)}`,ir=e=>{e.insertAdjacentHTML(`beforeend`,`<aside hidden><h6>TINY FPS</h6><span></span><table><tr><td>Mouse<td>look<tr><td>WASD / ZQSD<td>move<tr><td>Shift<td>sprint<tr><td>Space<td>jump, again in the air<tr><td>Move key twice<td>dash that way<tr><td>C<td>crouch, slide when fast<tr><td>M<td>mute</table><span>Take the enemy flag to your own base while yours is home.</span><strong></strong></aside><u></u><h5 hidden>Muted (M)</h5><nav hidden><span></span><time></time><span></span><small></small><small></small></nav><output hidden></output><section hidden><h6></h6><strong></strong><table></table><span></span></section>`);let t=t=>e.querySelector(t),[n,r]=[`h5`,`aside`].map(e=>t(e)),[i,a]=[`aside span`,`aside strong`].map(e=>t(e)),o=(e,t)=>e.textContent!=t&&(e.textContent=t),s=t(`nav`),[c,d,p]=[...s.querySelectorAll(`span, time`)],[m,h]=[...s.querySelectorAll(`small`)],g=t(`output`),_=t(`u`),v=t(`section`),[y,b,x]=[`h6`,`strong`,`span`].map(e=>v.querySelector(e)),S=v.querySelector(`table`),C=[],w,T,E=(e,t)=>e.style.color=u[t];return[c,m].forEach(e=>E(e,0)),[p,h].forEach(e=>E(e,1)),{title(e,t){r.hidden=!e,o(i,t),o(a,e)},mute:e=>n.hidden=!e,match(e,t){s.hidden=!1,o(c,`${l[0].toUpperCase()} ${e.score[0]}`),o(p,`${e.score[1]} ${l[1].toUpperCase()}`),o(d,e.over?`END`:rr(e.clock)),e.flags.forEach((e,n)=>{let r=e.state===f.CARRIED?`taken by ${t(e.by)}`:e.state===f.DROPPED?`dropped ${e.left}s`:`home`;o(n?h:m,`${l[n]} flag: ${r}`)})},marks(t){for(;C.length<t.length;){let t=document.createElement(`em`);t.innerHTML=`<span></span><small></small>`,C.push(t),e.append(t)}C.splice(t.length).forEach(e=>e.remove()),t.forEach((e,t)=>{let n=C[t];n.style.left=`${e.x*100}%`,n.style.top=`${e.y*100}%`,E(n,e.team);let[r,i]=[n.children[0],n.children[1]];r.style.transform=e.arrow===void 0?``:`rotate(${e.arrow}rad)`,o(r,e.arrow===void 0?`▼`:`▲`),o(i,`${e.kind===`base`?`Base `:``}${e.text}`)})},hurt(e){let t=e<.01?``:`${Math.min(1,e)}`;_.style.opacity!=t&&(_.style.opacity=t)},banner(e,t){g.hidden=!1,o(g,e),g.style.color=t===void 0?`#fff`:u[t],clearTimeout(w),w=setTimeout(()=>g.hidden=!0,nr)},end(e,t){if(v.hidden=!e,!e)T=void 0;else{if(T!==e){T=e;let[t,n]=e.score,r=t>n?0:n>t?1:-1;o(y,r<0?`DRAW`:`${l[r].toUpperCase()} WINS`),y.style.color=r<0?`#fff`:u[r],o(b,`${t} – ${n}`);let i=[...e.players].sort((e,t)=>t.caps-e.caps||t.returns-e.returns||e.id-t.id);S.replaceChildren(),S.insertAdjacentHTML(`beforeend`,`<tr><th>Player<th>Captures<th>Returns</tr>`);for(let e of i){let t=S.insertRow();[e.name,e.caps,e.returns].forEach(e=>t.insertCell().textContent=`${e}`),t.style.color=u[e.team]}}o(x,`Next match in ${t}`)}}}},ar=.0025,or=Math.PI*2,sr={KeyW:p.FORWARD,ArrowUp:p.FORWARD,KeyS:p.BACK,ArrowDown:p.BACK,KeyA:p.LEFT,ArrowLeft:p.LEFT,KeyD:p.RIGHT,ArrowRight:p.RIGHT,Space:p.JUMP,ShiftLeft:p.SPRINT,ShiftRight:p.SPRINT,KeyC:p.CROUCH},cr=p.FORWARD|p.BACK|p.LEFT|p.RIGHT,lr=(e,t)=>e&~cr|t|p.DASH,ur=e=>sr[e]??0,dr=(e,t=()=>{})=>{let r=new AbortController,i=(e,t,n)=>e.addEventListener(t,n,{signal:r.signal}),a=/* @__PURE__ */ new Set,o=/* @__PURE__ */ new Map,s=0,c={yaw:0,pitch:0,keys:0,take(){let e=s?lr(c.keys,s):c.keys;return s=0,e},locked:()=>e.getRootNode().pointerLockElement==e,destroy:()=>r.abort()};i(e,`click`,()=>{Promise.resolve(e.requestPointerLock()).catch(()=>{})}),i(document,`mousemove`,e=>{c.locked()&&(c.yaw=((c.yaw-e.movementX*ar)%or+or)%or,c.pitch=Math.max(-1.55,Math.min(n,c.pitch-e.movementY*ar)))}),i(document,`keydown`,e=>{let n=ur(e.code);if(e.code==`KeyM`&&!e.repeat&&c.locked()&&t(),n&&c.locked()){if(n&cr&&!e.repeat&&!a.has(e.code)){let t=performance.now(),r=o.get(e.code);r!==void 0&&t-r<=250?(s=n,o.delete(e.code)):o.set(e.code,t)}a.add(e.code),c.keys|=n,e.preventDefault()}}),i(document,`keyup`,e=>{a.delete(e.code),c.keys&=~ur(e.code)});let l=()=>{c.keys=s=0,a.clear(),o.clear()};return i(window,`blur`,l),i(document,`pointerlockchange`,()=>c.locked()||l()),c},fr=120,pr=16,mr=e=>{let t={...e};return delete t.ack,delete t.by,t},hr=(e,t,n)=>({x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n,z:e.z+(t.z-e.z)*n}),gr=(e,t,n)=>P(e+(((t-e+Math.PI)%A+A)%A-Math.PI)*n),_r=(e,t)=>(t-e&65535)<32768,vr=(e,t,n)=>({...t,...hr(e,t,n),yaw:gr(e.yaw,t.yaw,n),pitch:e.pitch+(t.pitch-e.pitch)*n}),yr=e=>{let t,n=0,r=0,i=[],a,o,s=[],c=0,l=0,u=e=>{let t=e-100,n=0;for(;n+1<s.length&&s[n+1].t<=t;)n++;let r=s[n],i=s[n+1]??r;return{a:r,b:i,u:i.t>r.t?Math.max(0,Math.min(1,(t-r.t)/(i.t-r.t))):0}},d=e=>{if(!s.length)return;let{a:t,b:n,u:r}=u(e);return(t.s.tick+(n.s.tick-t.s.tick&65535)*r)%65536};return{you:(e,r=0)=>{[t,n]=[e,r]},step:(t,s)=>{let u=We({...t,seq:r,view:s===void 0?void 0:d(s)});return r=r+1&65535,i.push(u),i.length>fr&&i.shift(),a&&(o=mr(a),Fe(a,u,e,n),c|=a.ev,l=Math.max(l,a.fall)),u},snapshot:(r,c)=>{s.push({t:c,s:r}),s.length>pr&&s.shift();let l=r.players.find(e=>e.id===t);l&&(i=i.filter(e=>!_r(e.seq,l.ack)),a=mr(l),o=mr(a),i.forEach((t,r)=>{r===i.length-1&&(o=mr(a)),Fe(a,t,e,n)}))},events:()=>{let e={ev:c,fall:l};return c=l=0,e},me:e=>a&&o?vr(o,a,Math.max(0,Math.min(1,e))):void 0,others:e=>{let n=s.at(-1);if(!n)return[];let{a:r,b:i,u:a}=u(e);return n.s.players.filter(e=>e.id!==t).map(e=>{let t=r.s.players.find(t=>t.id===e.id),n=i.s.players.find(t=>t.id===e.id);return t&&n?vr(mr(t),mr(n),a):mr(n??t??e)})}}},br={SPOT:0,POINT:1},xr=9,Sr=6,Cr=e=>{let{ctf:t,t:n}=e;if(!t)return[];let r=([e,t,n],r,i,a)=>({kind:br.POINT,p:[e,t,n],d:[0,-1,0],cone:0,range:i,color:Hn(r).map(e=>e*a),shadow:!1});return[...t.bases.map(([e,t,i],a)=>r([e,t+1.2,i],a,xr,1.1+.3*Math.sin(n*3))),...t.flags.filter(e=>e.dropped).map(e=>r([e.at[0],e.at[1]+.8,e.at[2]],e.team,Sr,.9))]},J={x0:.05,x1:.95,y0:.15,y1:.92},wr=(e,t,n,r,i)=>{let[a,o]=[r-e,i-t];return Math.atan2(a*Math.cos(n)-o*Math.sin(n),-a*Math.sin(n)-o*Math.cos(n))},Tr=e=>{let[t,n]=[Math.sin(e),-Math.cos(e)],[r,i]=[(J.x0+J.x1)/2,(J.y0+J.y1)/2],[a,o]=[(J.x1-J.x0)/2,(J.y1-J.y0)/2],s=Math.min(a/(Math.abs(t)||1e-9),o/(Math.abs(n)||1e-9));return[r+t*s,i+n*s]},Er=2.6,Dr=e=>{let t=[],n=(n,r,[i,a,o])=>{let s=Math.round(Math.hypot(i-e.eye[0],a+Er-e.eye[1],o-e.eye[2])),c=e.project(i,a+Er,o),l=c&&c[0]>=J.x0&&c[0]<=J.x1&&c[1]>=J.y0&&c[1]<=J.y1,u=`${s} m`;if(l)t.push({team:n,kind:r,x:c[0],y:c[1],text:u});else{let a=wr(e.eye[0],e.eye[2],e.yaw,i,o),[s,c]=Tr(a);t.push({team:n,kind:r,x:s,y:c,arrow:a,text:u})}},r=e.flags.some(t=>t.state===f.CARRIED&&t.by===e.id);return e.flags.forEach((t,i)=>{if(t.state===f.CARRIED&&t.by===e.id){n(e.team,`base`,e.bases[e.team]);return}if(r&&i===e.team&&t.state===f.HOME)return;let a=t.state===f.HOME?e.bases[i]:t.state===f.DROPPED?[t.x,t.y,t.z]:e.where(t.by);a&&n(i,`flag`,a)}),t},Or=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),kr=(e,t)=>Math.atan2(Math.sin(t-e),Math.cos(t-e)),Ar=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],jr={speed:8,sprint:6,air:12,rise:14,dash:14,hang:16,climb:12,wr:10,wl:10,slide:10,low:12,stun:14},Mr=e=>e==m.GROUND||e==m.CROUCH,Nr=e=>Mr(e)||e==m.SLIDE,Pr=e=>e==m.HANG||e==m.CLIMB,Fr=e=>ce(e)>1?Math.atan2(-e.vx,-e.vz):e.yaw,Ir=e=>{let[t,n]=Vt[e.wall],r=Fr(e);return t*Math.cos(r)-n*Math.sin(r)},Lr=e=>{let t=e.mode==m.WALLRUN,n=Ir(e);return{speed:Mr(e.mode)?ce(e):0,sprint:+le(e),air:+(e.mode==m.AIR),rise:+(e.mode==m.AIR&&e.vy>.5),dash:+(e.dash>50),hang:+(e.mode==m.HANG),climb:+(e.mode==m.CLIMB),wr:+(t&&n>=0),wl:+(t&&n<0),slide:+(e.mode==m.SLIDE),low:+(e.mode==m.SLIDE||e.mode==m.CROUCH),stun:+(e.stun>0)}},Rr=e=>({p:{...e},yaw:e.yaw,phase:0,time:0,w:Lr(e),kick:0,dip:0,flip:0,fall:0,h:2,f:.43000000000000005,wy:e.yaw}),zr=5,Br=(t,n,r)=>{let i=t.p,a=Math.hypot(n.x-i.x,n.z-i.z);if(Math.hypot(a,n.y-i.y)>zr){Object.assign(t,Rr(n));return}t.kick*=Math.exp(-r*7);let o=n.mode==m.AIR;o&&i.mode==m.AIR&&n.jumps<i.jumps&&n.vy>i.vy&&(t.flip=.001),o?t.fall=Math.min(t.fall,n.vy):(i.mode==m.AIR&&Nr(n.mode)&&t.fall<-3&&(t.kick=Or(-t.fall/12,.3)),t.fall=0),t.flip&&=(t.flip+=r*(o?2.2:8),t.flip>=1?0:t.flip),t.phase+=Mr(n.mode)&&Mr(i.mode)?a*(2.3-.7*t.w.sprint):0;let s=Lr(n);for(let e of Object.keys(jr))t.w[e]+=(s[e]-t.w[e])*(1-Math.exp(-r*jr[e]));if(t.dip+=(t.kick-t.dip)*(1-Math.exp(-r*24)),t.time+=r,Pr(n.mode)&&n.wall){let[r,i]=Vt[n.wall];t.grip&&n.mode!=m.HANG||(t.grip={x:n.x,z:n.z}),t.h=n.edge?n.edge-n.y:t.h,t.f=(t.grip.x-n.x)*r+(t.grip.z-n.z)*i+e+.03,t.wy=Math.atan2(-r,-i)}else!Pr(n.mode)&&t.w.hang+t.w.climb<.01&&(t.grip=void 0);let c=Or(t.w.wr+t.w.wl+t.w.slide+t.w.dash),l=n.yaw+kr(n.yaw,Fr(n))*c;t.yaw=l+kr(l,t.wy)*Or(t.w.hang+t.w.climb),t.p={...n}},Vr=(e,t,n)=>{for(let n of e.keys())t.some(e=>e.id==n)||e.delete(n);for(let r of t){let t=e.get(r.id);t?Br(t,r,n):e.set(r.id,Rr(r))}},Hr=e=>e.map((e,t)=>t%3?e:-e),Ur=e=>[Hr(e),e],Wr=(e,t,n)=>e>0?[n,t]:[Hr(t),Hr(n)],Gr=(e,t,n,r,i,a)=>({c:[t[0],t[1],t[2],t[3]*e],a:Wr(e,n,r),l:Wr(e,i,a)}),Kr=[.15,.2,1],qr={crouch:{c:[.5,.05,.45,0],a:Ur([.3,.75,.35,.5,-1,-.4])},air:{c:[.9,0,.12,0],a:Ur([.72,1.3,.05,.3,-1,-.6]),l:[[-.14,.2,-.18,-.15,.2,1,0],[.14,.32,.3,...Kr,0]]},rise:{c:[.95,.02,.2,0],a:Ur([.32,1.95,.28,.7,-.3,-1]),l:[[-.12,.32,-.18,-.15,.2,1,0],[.13,.5,.2,...Kr,0]]},tuck:{c:[.95,0,.55,0],a:Ur([.2,.78,.32,.8,-.2,-.2]),l:Ur([.13,.5,-.12,...Kr,0])},land:{c:[.52,.06,.45,0],a:Ur([.3,.85,.35,.5,-1,-.5]),l:Ur([.15,.07,.05,...Kr,0])},dash:{c:[.64,.15,1,0],a:Ur([.3,.95,.1,.3,1,-.3]),l:[[-.11,.5,-.62,0,-1,.3,0],[.12,.38,.6,...Kr,0]]},slide:Gr(1,[.2,-.12,-1.15,0],[.42,.62,.35,.5,-.3,-1],[-.4,.06,-.5,-.5,.3,-1],[.14,.3,.95,.1,1,.3,0],[-.2,.08,.15,-.3,1,.5,0])},Jr=[1,-1].map(e=>Gr(e,[.9,0,.22,-.35],[.4,1,.35,.4,-1,-.2],[-.82,1.3,.1,-.2,-1,-.4],[.38,.55,.3,.3,.3,1,-1.3],[-.1,.3,-.5,0,-1,.3,0])),Yr=e=>{let{h:t,f:n}=e,r=Or((1.5-t)/.9),i=.05*Math.sin(e.time*3),a=e=>[e*.14,Math.max(t+.03,.6),n+.04-.1*r,e*.6,-1,-.4],o=(e,t)=>e.map((e,n)=>e+(t[n]-e)*r);return{c:[Math.max(.88,t-.95)+.17*r,n-.22+.2*r,.6*r,0],a:[a(-1),a(1)],l:[o([-.11,.12,.05-i,-.15,.2,1,0],[-.11,.25,.1,-.15,.2,1,0]),o([.11,.1,-.12+i,...Kr,0],[.12,t+.07,n+.25,...Kr,0])]}},Xr=e=>{let t=Math.sin(e.time*12),n=(e,t)=>[e*.85,1.2+.28*t,-.1+.2*t,e*.4,-.3,-1];return{c:[.8,-.12,-.5,.18*t],a:[n(-1,-t),n(1,t)],l:[[-.12,.2,.3,-.15,.2,1,0],[.14,.12,-.35,...Kr,0]]}},Zr=(e,t,n)=>t?e.map((e,r)=>e+((t[r]??e)-e)*n):e,Qr=e=>U([Math.sin(e[3]),Math.cos(e[2])*Math.cos(e[3]),Math.sin(e[2])]),$r=e=>U([1-e[0]*e[0],-e[0]*e[1],-e[0]*e[2]]),[ei,ti,ni,ri]=[.31,.27,.43,.38],ii=(e,t,n)=>{let[r,i]=[Qr(e),$r(Qr(e))];return[i[0]*n+r[0]*t,e[0]+i[1]*n+r[1]*t,e[1]+i[2]*n+r[2]*t]},ai=e=>{let{w:t}=e,[n,r]=[Or(t.speed/2.5),Or(t.speed/9)],i=1+.2*t.sprint,a=Math.sin(e.phase),o=[.88-.03*r-.05*t.sprint-.05*n*r*a*a,0,.04+.28*r+.1*t.sprint,.04*r*a],s=Or(t.hang+t.climb),c=[-1,1].map(t=>{let a=Math.sin(e.phase+(t>0?Math.PI:0)),[s,c,l]=ii(o,.5,t*.205);return[s+t*.04,c-.52+n*r*(.12+.3*Math.max(0,a)),l+n*(.05+.45*r*i)*a,t*.5,-1,-.6]}),l=[-1,1].map(t=>{let a=e.phase+(t>0?0:Math.PI),o=n*(.05+.3*r*i);return[t*.11,.07+o*Math.max(0,Math.cos(a)),n*(.1+.42*r*i)*Math.sin(a),t*.15,.2,1,0]}),u=e.flip?Math.sqrt(Math.sin(Math.PI*e.flip)):0,d=[[t.low,qr.crouch],[t.air,qr.air],[t.rise,qr.rise],[e.dip,qr.land],[t.dash,qr.dash],[t.wr,Jr[0]],[t.wl,Jr[1]],[t.slide,qr.slide],[s,s>.001?Yr(e):{}],[u,qr.tuck],[t.stun,t.stun>.001?Xr(e):{}]];for(let[e,t]of d)e>.001&&(o=Zr(o,t.c,e),c=c.map((n,r)=>Zr(n,t.a?.[r],e)),l=l.map((n,r)=>Zr(n,t.l?.[r],e)));let[f,p]=[Qr(o),[0,0,1]],m=ii(o,0,0),h=U(V(p,[f[0]*f[2],f[1]*f[2],f[2]*f[2]])),g=(e,t,n,r)=>e.map((e,i)=>{let a=t(i?1:-1),[o,s]=Bt(a,e.slice(0,3),e.slice(3,6),n,r);return{root:a,mid:o,end:s,dir:U(V(s,o)),tilt:e[6]??0}}),_={pelvis:m,spine:f,chest:h,head:ii(o,.787,0),look:U(H(h,p,.5)),arms:g(c,e=>ii(o,.5,e*.205),ei,ti),legs:g(l,e=>ii(o,0,e*.11),ni,ri)};for(let e of _.arms)e.dir=U(H(e.dir,[0,-.15,1],s));if(e.flip){let t=2*Math.PI*(3-2*e.flip)*e.flip*e.flip,[n,r]=[Math.cos(t),Math.sin(t)],i=([e,t,i],a=[0,0,0])=>[e,a[1]+(t-a[1])*n-(i-a[2])*r,a[2]+(i-a[2])*n+(t-a[1])*r],a=[0,m[1]+.15,m[2]];_.pelvis=i(m,a),_.head=i(_.head,a);for(let e of[`spine`,`chest`,`look`])_[e]=i(_[e]);for(let e of[..._.arms,..._.legs])[e.root,e.mid,e.end]=[e.root,e.mid,e.end].map(e=>i(e,a)),e.dir=i(e.dir)}return _},[oi,si,ci,li]=[[.12,.13,.17],[.09,.07,.06],[.16,.16,.19],[.03,.03,.04]],ui=(e,t,n,r)=>{let i=U([-t.p.vx,0,-t.p.vz]),[a,o,s]=n.map(e=>.6+.6*e);[[.5,.12,1.3],[.9,-.16,1.7],[1.25,.14,1.2]].forEach(([n,c,l],u)=>{let d=r([c,n,-.2-.1*u]),f=d.map((e,n)=>e+i[n]*l*t.w.dash);for(let t of[[-i[2]*.03,0,i[0]*.03],[0,.03,0]])for(let n of[d.map((e,n)=>e+t[n]),d.map((e,n)=>e-t[n]),f])e.push(...n,0,1,0,a,o,-2,s)})},di=(e,t,n,r=1)=>{let i=ai(t),[a,o]=[Math.sin(t.yaw),Math.cos(t.yaw)],{x:s,y:c,z:l}=t.p,u=([e,t,n])=>[s+e*o-n*a,c+t,l-e*a-n*o],d=([e,t,n])=>[e*o-n*a,t,-e*a-n*o],[f,p,m]=[d([1,0,0]),d(i.chest),d(i.spine)],h=u(i.pelvis);Nt(e,r,h,m,p,f,n,oi);let[g,_]=[r,0].map(e=>W(e,0,[1,1])),[v,y]=[u(i.head),Dt(d(i.look),f)];r&&Pt(e,r,h,m,f),G(e,g,v,y,[0,0,.012],[.082,.12,.1],Ot),G(e,g,v,y,[0,.02,-.004],[.088,.113,.11],si),r&&(G(e,_,h.map((e,t)=>e+m[t]*.58),y,[0,0,-.075],[.115,.055,.06],n),G(e,_,v,y,[0,-.02,.108],[.016,.028,.022],Ot),G(e,_,v,y,[0,.025,.083],[.068,.016,.03],li));let b=d([0,0,1]);for(let{root:t,mid:n,end:a,tilt:o}of i.legs){let[i,s,c]=[t,n,a].map(u);K(e,W(r,ni,At.thigh,[.5,1]),i,s,f,ni,1,oi),K(e,W(r,ri,At.shin,[.5,.5]),s,c,f,ri,1,oi);let l=[Math.sin(o)*f[0],Math.cos(o),Math.sin(o)*f[2]];Ft(e,r,c,U(V(c,s)),b,Ar(b,l),ci)}for(let{root:t,mid:a,end:o,dir:s}of i.arms){let[i,c,l]=[t,a,o].map(u);K(e,W(r,ei,At.upper,[1,.5]),i,c,f,ei,1,n),K(e,W(r,ti,At.fore,[.5,0]),c,l,f,ti,1,n),G(e,_,l,Dt(d(s),f),[0,0,.04],[.04,.036,.058],Ot)}t.w.dash>.15&&ui(e,t,n,u)},fi=Object.keys(_).length,Y=(e,t,n)=>{let r=Math.imul(e,374761393)+Math.imul(t,668265263)+Math.imul(n,144665)|0;return r=Math.imul(r^r>>>13,1274126177),((r^r>>>16)>>>0)/4294967296},X=(e,t,n,r)=>{let[i,a]=[Math.floor(e),Math.floor(t)],[o,s]=[e-i,t-a].map(e=>e*e*(3-2*e)),c=(e,t)=>Y((i+e)%n,(a+t)%n,r);return(c(0,0)*(1-o)+c(1,0)*o)*(1-s)+(c(0,1)*(1-o)+c(1,1)*o)*s},pi=(e,t,n,r,i)=>{let[a,o]=[0,.5];for(let s=0;s<r;s++,o/=2)a+=o*X(e*(1<<s),t*(1<<s),n<<s,i+s);return a/(1-o*2)},mi=(e,t,n)=>e.map((e,r)=>e+(t[r]-e)*n),Z=(e,t)=>e.map(e=>e*t),Q=e=>Math.min(Math.max(e,0),1),hi=Math.PI*2,$=[];$[_.BRICK]=(e,t)=>{let n=Math.floor(t*8),r=e*4+(n&1)*.5,[i,a,o]=[Math.floor(r)%4,r%1,t*8%1],s=X(e*16,t*16,16,5),c=.8+.4*s;return a<.05||o<.1?[Z([165,160,150],.7+.3*c),.1+.1*s]:[Z([170,78,56],(.8+.4*Y(i,n,1))*c*(.85+.15*o)),.7+.2*s+.1*Q(Math.min(a-.05,o-.1)*12)]},$[_.TILE]=(e,t)=>{let[n,r]=[Math.floor(e*4),Math.floor(t*4)],[i,a]=[e*4%1,t*4%1],o=X(e*16,t*16,16,7),s=.9+.2*o;return i<.05||a<.05?[Z([85,85,80],s),.1]:[Z([196,190,172],s*(.88+.08*(n+r&1)+.1*Y(n,r,2))),.8+.1*o+.1*Q((Math.min(i,a)-.05)*14)]},$[_.LAVA]=(e,t)=>{let n=pi(e*4,t*4,4,4,11),r=Math.max(0,1-Math.abs(n-.5)*7)**2;return[mi(mi([55,8,4],[230,70,8],n),[255,215,90],r),.5]},$[_.STONE]=(e,t)=>{let n=pi(e*8,t*8,8,4,3);return[Z([128,124,120],.45+.7*(n*1.3+.1*Y(Math.floor(e*128),Math.floor(t*128),4))),Q(n*1.4-.2)]},$[_.METAL]=(e,t)=>{let[n,r,i,a]=[Math.floor(e*2),Math.floor(t*2),e*2%1,t*2%1],o=Q((X(e*8,t*8,8,13)-.68)*6),s=e=>Math.min(Math.max(Math.round((e-.1)/.4),0),2)*.4+.1,[c,l]=[s(i),s(a)],u=c==l&&c==.5?1:Math.hypot(i-c,a-l),d=Q(1-u/.07),f=Z([98,108,124],(.9+.2*X(e*32,t*32,32,9)+.12*Y(n,r,6))*(1+.3*d)*(.65+.35*Q((u-.06)/.04)));return Math.min(i,a,1-i,1-a)<.03?[Z([40,44,50],1+o),.05]:[mi(f,[105,68,45],o*.7),.5+.1*(1-o)+.4*d]},$[_.WOOD]=(e,t)=>{let n=Math.floor(t*8),r=e*2+Y(n,0,8)*2,[i,a,o]=[Math.floor(r)%2,r%1,t*8%1],s=Y(n,i,3),c=.5+.5*Math.sin(hi*(t*40+2.5*X(e*4,t*4,4,21)+s*7));return o<.08||a<.015?[[28,18,10],.05]:[mi([92,58,32],[158,106,62],c*.6+s*.35),.7+.15*c+.15*Q((o-.08)*15)]},$[_.MOSS]=(e,t)=>{let n=Math.floor(t*4),r=e*2+(n&1)*.5,[i,a,o]=[Math.floor(r)%2,r%1,t*4%1],s=Math.min(a,1-a,(o<.5?o:1-o)*.5),c=a<.04||o<.06,l=Q((.3*pi(e*12,t*12,12,3,17)-.03-s)*12),u=X(e*64,t*64,64,19),d=Z([128,126,118],(.7+.4*Y(i,n,5))*(.7+.5*X(e*16,t*16,16,15)));return[mi(c?Z(d,.45):d,mi([52,100,34],[96,148,56],u),l),c?.1+.6*l*u:.6+.2*Q(s*30)+.2*l*u]},$[_.GRATE]=(e,t)=>{let[n,r]=[e*8%1,t*8%1],i=Math.max(Math.abs(n-.5),Math.abs(r-.5)),a=Math.min(Math.abs(n-.5),Math.abs(r-.5))>.43,o=X(e*16,t*16,16,23);return i<.36?[[9,9,12],0]:[Z(mi([104,108,116],[96,80,68],Q((o-.55)*4)),(a?1.25:1)-(.5-i)*2.2+.2*o),a?1:.6+.4*Q((i-.36)*12)]},$[_.CONCRETE]=(e,t)=>{let[n,r]=[e*2%1,t*2%1],i=pi(e*4,t*4,4,3,41),a=Y(Math.floor(e*128),Math.floor(t*128),43)>.992,o=Math.hypot(n%.5-.25,r%.5-.25)<.02,s=(.94+.1*i+.03*Y(Math.floor(e*2),Math.floor(t*2),44))*(a||o?.9:1);return n<.015||r<.015?[Z([160,164,172],s),.3]:[Z([206,209,214],s),o?.5:.8+.2*i-(a?.15:0)]},$[_.GLASS]=(e,t)=>{let n=e*2%1,r=((n+t*.7)%1-.5)/.12,i=Math.exp(-r*r);return n<.03||t<.03?[Z([150,158,170],1-.3*n),.9]:[mi(mi([7,20,44],[48,88,136],t**2),[120,160,200],i*.18),.4]},$[_.STEEL]=(e,t)=>{let n=Math.floor(t*128),r=.5*Y(n,3,31)+.5*X(e*8,0,8,n+7),i=e*4%1;return i<.03?[[60,66,76],.1]:[Z([176,184,196],.8+.35*r+(i>.97?.15:0)),.6+.2*r]},$[_.PAINT]=(e,t)=>{let[n,r]=[e*2%1,t*2%1],i=Y(Math.floor(e*128),Math.floor(t*128),47);return n<.02||r<.02?[[200,200,206],.3]:[Z([246,246,248],.96+.06*i),.85+.04*i]};var gi=()=>{let e=new Uint8ClampedArray(fi*128*128*4);return $.forEach((t,n)=>{for(let r=0;r<16384;r++){let[i,a]=t(r%128/128,Math.floor(r/128)/128);e.set([...i,a*255],(n*128*128+r)*4)}}),e},_i=[18,26],vi=8,yi=40,bi=55,xi=-60,Si=[[1,.45,.12],[.2,.6,1],[.9,.15,.2],[.25,.85,.55]],Ci=({brushes:e})=>{let[t,n,r,i]=[0,2].flatMap(t=>[Math.min(...e.map(e=>e.min[t])),Math.max(...e.map(e=>e.max[t]))]),[a,o,s]=[(t+n)/2,(r+i)/2,Math.hypot(n-t,i-r)/2];return _i.flatMap((e,t)=>Array.from({length:e},(n,r)=>{let i=e=>Y(r,t,vi+e),c=(r+i(1)*.8)/e*2*Math.PI,l=s+yi+t*bi+i(2)*30,[u,d]=[a+l*Math.cos(c),o+l*Math.sin(c)],[f,p]=[5+i(3)*8,5+i(4)*8],m=t?-5+i(5)**2*90:-20+i(5)*30,h=[_.GLASS,_.STEEL,_.CONCRETE][+(i(6)>.7)+ +(i(6)>.85)],g={min:[u-f,xi,d-p],max:[u+f,m,d+p],top:_.CONCRETE,side:h};return i(7)<.35?[g,{min:[u-f/2,m,d-p/2],max:[u+f/2,m+3+i(8)*3,d+p/2],top:_.PAINT,side:_.PAINT,tint:Si[Math.floor(i(9)*Si.length)]}]:[g]}).flat())},wi=r,Ti=o+.05,Ei=1.5,Di=.6,Oi=8,ki=2.5,Ai=3,ji=.4,Mi=.012,Ni=.2,Pi=[1.2,1.45],Fi=[1.6,.12,.08],Ii=[.9,.07,.05],Li=[.85,.07,.05],Ri=(e,t,n,r)=>{let i=-1/0;for(let a of e)if(a!=t&&a.min[0]<=n&&n<=a.max[0]&&a.min[2]<=r&&r<=a.max[2]){if(a.max[1]>t.max[1]+.001){if(a.min[1]<t.max[1])return 1/0}else i=Math.max(i,a.max[1])}return t.max[1]-i},zi=({brushes:e,floor:t},n)=>{let r=n.max.map((e,t)=>e-n.min[t]),i=[...r].sort((e,t)=>e-t),a={beam:i[1]<=Di&&i[2]>=2*Di,lips:[],stripes:[]};if(a.beam)return a;for(let i of[0,2]){let o=2-i;for(let t of[0,1]){let s=[n.min[0],0,n.min[2]];s[i]=(t?n.max:n.min)[i]+(t?ji:-.4),s[o]=(n.min[o]+n.max[o])/2;let c=Ri(e,n,s[0],s[2]);c>wi&&c<=Ti&&r[o]>=Ei&&a.lips.push([i,t])}n.min[1]>t&&r[1]>=ki&&r[o]>=Oi&&r[i]<=Ai&&a.stripes.push([i,0],[i,1])}return a},Bi=(e,t,n,r,i,a,o)=>{let[s,c]=[(r+1)%3,(r+2)%3],l=[0,0,0];l[r]=i?1:-1;for(let[u,d]of[[0,0],[1,0],[1,1],[0,0],[1,1],[0,1]]){let f=[0,0,0];[f[r],f[s],f[c]]=[(i?n:t)[r],(u?n:t)[s],(d?n:t)[c]],e.push(...f,...l,o[0],o[1],a,o[2])}},Vi=e=>{let t=[];for(let n of e.brushes){let{beam:r,lips:i,stripes:a}=zi(e,n),[o,s]=[n.min.map(e=>e-Mi),n.max.map(e=>e+Mi)];if(r)for(let e=0;e<3;e++)for(let n of[0,1])(e!=1||n)&&Bi(t,o,s,e,n,-1,Li);for(let[e,r]of i){let i=r?1:-1,a=(r?n.max:n.min)[e],o=[n.min[0],n.max[1]+Mi,n.min[2]],s=[n.max[0],n.max[1]+Mi,n.max[2]];[o[e],s[e]]=r?[a-Ni,a]:[a,a+Ni],Bi(t,o,s,1,1,-2,Fi);let[c,l]=[o.slice(),s.slice()];[c[1],l[1]]=[n.max[1]-Ni,n.max[1]],[c[e],l[e]]=[a+i*Mi,a+i*Mi],Bi(t,c,l,e,r,-2,Fi)}for(let[e,r]of a){let i=2-e,[a,o]=[[...n.min],[...n.max]];[a[1],o[1]]=[n.min[1]+Pi[0],n.min[1]+Pi[1]],[a[i],o[i]]=[n.min[i]+.3,n.max[i]-.3],a[e]=o[e]=(r?n.max:n.min)[e]+(r?Mi:-.012),Bi(t,a,o,e,r,-2,Ii)}}return t},Hi=4.2,Ui=({teams:e})=>{let t=[];return e.forEach(({base:[e,n,r]},i)=>{let a=Hn(i),o=a.map(e=>.25+.45*e),s=(i,a,o,s,c,l)=>Bi(t,[e+i,n+l,r+a],[e+o,n+l,r+s],1,1,-1,c);s(-4.2,-4.2,Hi,Hi,o,.02);for(let[e,t,n,r]of[[-4.2,-4.2,Hi,-3.85],[-4.2,3.85,Hi,Hi],[-4.2,-4.2,-3.85,Hi],[3.85,-4.2,Hi,Hi]])s(e,t,n,r,a.map(e=>e*.8),.03)}),t},Wi=1<<18,Gi=2,Ki=1024,qi=.6,Ji=Math.tan(70*Math.PI/360),Yi=10,Xi=4,Zi=`#version 300 es
2
2
  layout(location=0)in vec3 p;layout(location=1)in vec3 n;layout(location=2)in vec4 c;
3
3
  uniform mat4 m;uniform float Y;uniform vec3 J[3];out vec3 P,N;out vec4 C;
4
4
  void main(){
5
5
  if(Y>.5){vec2 q=vec2(gl_VertexID&1,gl_VertexID>>1)*4.-1.;gl_Position=vec4(q,1,1);P=J[0]*q.x+J[1]*q.y+J[2];N=vec3(0);C=vec4(0);return;}
6
- P=p;N=n;C=c;gl_Position=m*vec4(p,1);}`,gi=`#version 300 es
7
- out vec2 U;void main(){U=vec2(gl_VertexID&1,gl_VertexID>>1)*2.;gl_Position=vec4(U*2.-1.,0,1);}`,_i=`#version 300 es
6
+ P=p;N=n;C=c;gl_Position=m*vec4(p,1);}`,Qi=`#version 300 es
7
+ out vec2 U;void main(){U=vec2(gl_VertexID&1,gl_VertexID>>1)*2.;gl_Position=vec4(U*2.-1.,0,1);}`,$i=`#version 300 es
8
8
  precision highp float;uniform sampler2D S[4];uniform vec4 Y;uniform float L;in vec2 U;out vec4 o;
9
- vec3 b(vec2 x){vec3 c=texture(S[0],x).rgb;return c*smoothstep(.95,2.2,max(c.r,max(c.g,c.b)));}
9
+ vec3 b(vec2 x){vec3 c=texture(S[0],x).rgb;return c*smoothstep(.9,2.,max(c.r,max(c.g,c.b)));}
10
10
  #define T(k)texture(S[0],U+Y.xy*(k)).rgb
11
11
  void main(){
12
12
  vec3 c;
13
13
  if(Y.z<1.)c=(b(U+Y.xy)+b(U-Y.xy)+b(U+Y.xy*vec2(1,-1))+b(U-Y.xy*vec2(1,-1)))/4.;
14
14
  else if(Y.z<2.)c=T(0.)*.227+(T(1.3846)+T(-1.3846))*.3162+(T(3.2308)+T(-3.2308))*.0703;
15
15
  else{
16
- c=texture(S[0],U).rgb+texture(S[1],U).rgb*1.+texture(S[2],U).rgb*.8+texture(S[3],U).rgb*.6;
16
+ c=texture(S[0],U).rgb+texture(S[1],U).rgb*1.3+texture(S[2],U).rgb*1.+texture(S[3],U).rgb*.7;
17
17
  vec2 q=U-.5;
18
18
  c=min(c,.6)+.4*(1.-exp(-max(c-.6,0.)/.4));
19
19
  float a=atan(q.y,q.x)*24.,h=fract(sin(floor(a)*12.9898)*43758.5453);
20
20
  c+=L*step(.85-.5*L,h)*sin(fract(a)*3.1416)*smoothstep(.2,.6,length(q))*fract(length(q)*3.-Y.w*.002+h*9.)*.22;
21
21
  c*=1.-(.7+.3*L)*dot(q,q);
22
- c=pow(c,vec3(.92))+(fract(sin(dot(gl_FragCoord.xy+Y.w,vec2(12.9898,78.233)))*43758.5453)-.5)*.03;}
23
- o=vec4(c,1);}`,vi=[[.04,8],[.25,30],[0,1],[.08,10],[.8,48],[.06,12],[.3,20],[.7,40],[.1,24]],yi=`#version 300 es
22
+ c=pow(c*vec3(.97,1.,1.03),vec3(.92))+(fract(sin(dot(gl_FragCoord.xy+Y.w,vec2(12.9898,78.233)))*43758.5453)-.5)*.03;}
23
+ o=vec4(c,1);}`,ea=[[.04,8],[.25,30],[0,1],[.08,10],[.8,48],[.06,12],[.3,20],[.7,40],[.06,14],[1.5,110],[.9,60],[.25,30],[.1,24]],ta=`#version 300 es
24
24
  precision highp float;precision highp sampler2DArray;precision highp sampler2DArrayShadow;
25
25
  in vec3 P,N;in vec4 C;uniform vec3 E;uniform float T,Z,Y;uniform int Q;
26
26
  uniform vec4 A[16],B[16],K[16],F;uniform vec3 G[16],H[5],O,X;uniform mat4 M[4],W;
27
27
  uniform sampler2DArray S;uniform sampler2DArrayShadow D;out vec4 o;
28
- const vec2 SP[${vi.length}]=vec2[](${vi.map(([e,t])=>`vec2(${e},${t})`)});
28
+ const vec2 SP[${ea.length}]=vec2[](${ea.map(([e,t])=>`vec2(${e},${t})`)});
29
29
  vec3 e(vec3 x){return 2.*(1.-exp(-.5*x));}
30
- void main(){
31
- if(Z<0.)return;
32
- if(Y>.5){
33
- vec3 d=normalize(P);float h=d.y,k=max(dot(d,O),0.);
30
+ vec3 K0(vec3 d){
31
+ float h=d.y,k=max(dot(d,O),0.);
34
32
  vec3 c=mix(H[4],H[3],pow(clamp(h,0.,1.),.5));
35
33
  c=mix(c,H[4]*1.08,exp(-abs(h)*7.));
36
- c+=X*(.2*pow(k,24.)+.05*pow(k,4.)+2.*smoothstep(.9993,.9997,k));
37
- o=vec4(c,1);return;}
38
- float L=C.z,s=step(0.,L),I=floor(C.w*.5),g=step(abs(L-${m.LAVA}.),.5)+step(L,-1.5);
39
- vec4 t=texture(S,vec3(C.xy/${li}.+vec2(g*T*.01,0),max(L,0.)));
34
+ return c+X*(.2*pow(k,24.)+.05*pow(k,4.)+2.*smoothstep(.9993,.9997,k));}
35
+ void main(){
36
+ if(Z<0.)return;
37
+ if(Y>.5){o=vec4(K0(normalize(P)),1);return;}
38
+ float L=C.z,s=step(0.,L),I=floor(C.w*.5),g=step(abs(L-${_.LAVA}.),.5)+step(L,-1.5);
39
+ vec4 t=texture(S,vec3(C.xy/${Gi}.+vec2(g*T*.01,0),max(L,0.)));
40
40
  vec3 c=mix(vec3(C.xy,C.w),t.rgb,s);
41
41
  vec3 n=normalize(N),dx=dFdx(P),dy=dFdy(P),a=cross(dy,n),b=cross(n,dx);
42
42
  float h=t.a*s*0.06,det=dot(dx,a);
43
- float f=1.-smoothstep(.6,2.5,${128/li}.*max(length(dFdx(C.xy)),length(dFdy(C.xy))));
43
+ float f=1.-smoothstep(.6,2.5,${128/Gi}.*max(length(dFdx(C.xy)),length(dFdy(C.xy))));
44
44
  vec3 m=normalize(abs(det)*n-sign(det)*f*(dFdx(h)*a+dFdy(h)*b)+n*1e-9);
45
- vec2 R=SP[int(s>0.?L+.5:${ni}.)];
45
+ vec2 R=SP[int(s>0.?L+.5:${fi}.)];
46
46
  vec3 y=mix(vec3(1),G[int(min(I,15.))]*(C.w-2.*I),s),V=normalize(E-P),w=normalize(n+m);
47
47
  float sd=max(dot(m,O),0.)*smoothstep(0.,.1,dot(n,O)),sv=1.;
48
48
  if(sd>0.&&g<1.){
49
49
  vec4 q=W*vec4(P+n*.08,1);q.xyz=q.xyz*.5+.5;
50
50
  float v=0.;
51
- for(int j=0;j<4;j++)v+=texture(D,vec4(q.xy+(vec2(j&1,j>>1)*2.-1.)*${.75/ui},0,q.z-.0004));
51
+ for(int j=0;j<4;j++)v+=texture(D,vec4(q.xy+(vec2(j&1,j>>1)*2.-1.)*${.75/Ki},0,q.z-.0004));
52
52
  sv=mix(v/4.,1.,smoothstep(.8,1.,max(abs(q.x-.5),abs(q.y-.5))*2.));}
53
53
  vec3 l=y*(mix(mix(H[1],H[0],max(w.y,0.)),H[2],max(-w.y,0.))+X*sd*sv),sp=X*sv*sd*pow(max(dot(m,normalize(O+V)),0.),R.y);
54
54
  for(int i=0;i<16;i++){
@@ -60,9 +60,10 @@ w*=w*smoothstep(u,u+(1.-u)*.4,-dot(d,B[i].xyz))*max(dot(m,d),0.);
60
60
  if(w>0.&&k>=0.){
61
61
  vec4 q=M[int(k)]*vec4(P+n*.03,1);q.xyz=q.xyz/q.w*.5+.5;
62
62
  float v=0.;
63
- for(int j=0;j<4;j++)v+=texture(D,vec4(q.xy+(vec2(j&1,j>>1)*2.-1.)*${.75/ui},k+1.,q.z-.0005));
63
+ for(int j=0;j<4;j++)v+=texture(D,vec4(q.xy+(vec2(j&1,j>>1)*2.-1.)*${.75/Ki},k+1.,q.z-.0005));
64
64
  w*=v/4.;}
65
65
  l+=K[i].rgb*w;
66
66
  sp+=K[i].rgb*w*pow(max(dot(m,normalize(d+V)),0.),R.y);}
67
67
  c=c*mix(e(l),vec3(1.4),g)+e(sp*R.x*(.4+.6*mix(1.,t.a,s)));
68
- o=vec4(mix(c,F.rgb,1.-exp(-F.a*length(P-E))),1.);}`,bi=(e,t,n,r,i=0,a=fi,[o,s]=[.1,200])=>{let[c,l,u]=yt(t,n,i),d=(s+o)/(s-o),f=[c.map(e=>e/(a*r)),l.map(e=>e/a),u.map(e=>e*d),u].map(t=>[...t,-t[0]*e[0]-t[1]*e[1]-t[2]*e[2]]);return f[2][3]-=2*s*o/(s-o),Float32Array.from({length:16},(e,t)=>f[t&3][t>>2])},xi=(e,t,n,r)=>{let i=e[3]*t+e[7]*n+e[11]*r+e[15];if(i<=0)return;let a=e[0]*t+e[4]*n+e[8]*r+e[12],o=e[1]*t+e[5]*n+e[9]*r+e[13];return[.5+a/(2*i),.5-o/(2*i)]},Si=({p:e,d:t,cone:n,range:r})=>bi(e,Math.atan2(-t[0],-t[2]),Math.atan2(t[1],Math.hypot(t[0],t[2])),1,0,Math.min(Math.tan(Math.acos(n)),5.7),[.3,r]),Ci=e=>{let[t,n,r]=[0,0,0].map(()=>/* @__PURE__ */ new Float32Array(64)),i=/* @__PURE__ */ new Float32Array(64),a=0,o=e.slice(0,16);return o.forEach((e,o)=>{let s=e.shadow&&e.kind==dr.SPOT&&a<4?a++:-1;t.set([...e.p,e.range],o*4),n.set([...e.d,e.kind==dr.POINT?-9:e.cone],o*4),r.set([...e.color,s],o*4),s>=0&&i.set(Si(e),s*16)}),{n:o.length,maps:a,a:t,b:n,k:r,m:i}},wi=(e,t,n=64,r=100)=>{let i=e.map(e=>-e),a=Math.hypot(i[0],i[2]),o=a>.001?[-i[2]/a,0,i[0]/a]:[1,0,0],s=[o[1]*i[2]-o[2]*i[1],o[2]*i[0]-o[0]*i[2],o[0]*i[1]-o[1]*i[0]],c=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],[l,u]=[n/2,n/ui],d=[o,s].map(e=>[...e.map(e=>e/l),-(Math.round(c(e,t)/u)*u)/l]);return d.push([...i.map(e=>e/r),-c(i,t)/r],[0,0,0,1]),Float32Array.from({length:16},(e,t)=>d[t&3][t>>2])},Ti=({def:e})=>[...new Map([[`1,1,1`,[1,1,1]],...e.brushes.flatMap(({tint:e})=>e?[[`${e}`,e]]:[])]).values()].slice(0,16),Ei=[[0,0],[1,0],[1,1],[0,0],[1,1],[0,1]],Di=e=>{let{brushes:t,floor:n}=e.def,r=[],i=Ti(e).map(String);return t.forEach((e,a)=>{let o=1+2*Math.max(0,i.indexOf(`${e.tint}`));for(let i=0;i<3;i++){let[s,c]=[(i+1)%3,(i+2)%3],[l,u]=i==0?[2,1]:i==1?[0,2]:[0,1];for(let d of[0,1]){let f=d?e.max[i]:e.min[i];if(t.some((t,n)=>n!=a&&(d?t.min[i]:t.max[i])==f&&t.min[s]<=e.min[s]&&t.max[s]>=e.max[s]&&t.min[c]<=e.min[c]&&t.max[c]>=e.max[c])||i==1&&!d&&e.min[1]<=n)continue;let p=[0,0,0];p[i]=d?1:-1;for(let[t,n]of Ei){let a=[0,0,0];[a[i],a[s],a[c]]=[f,(t?e.max:e.min)[s],(n?e.max:e.min)[c]],r.push(...a,...p,a[l],a[u],i==1&&d?e.top:e.side,o)}}}}),r},Oi=({sky:[e,t]})=>[e.map(e=>(e*.55+.45)*.62),t.map(e=>(e*.7+.3)*.58),t.map((e,t)=>e*[1,.92,.8][t]*.34),e,t],ki=({fog:e,sky:t})=>e?[...[0,1,2].map(n=>e[n]+(t[1][n]-e[n])*di),e[3]]:[...t[1],0],Ai=2073600,ji=(e,t,n)=>{let r=Math.min(n,2,Math.sqrt(Ai/(e*t||1)));return[Math.round(e*r),Math.round(t*r)]},Mi=(e,t)=>{let n=/* @__PURE__ */ new Map,r=performance.now()/1e3,i=e.getContext(`webgl2`,{antialias:!1,depth:!1});if(!i)throw Error(`WebGL2 is not available`);let a=document.createElement(`canvas`).getContext(`2d`),o=/* @__PURE__ */ new Map,s=e=>{let t=o.get(e);if(!t){a.fillStyle=`#888`,a.fillStyle=e;let n=parseInt(a.fillStyle.slice(1),16),r=n>=0?n:8947848;o.set(e,t=[r>>16,r>>8&255,r&255].map(e=>e/255))}return t},c=()=>ji(e.clientWidth,e.clientHeight,devicePixelRatio),l=Di(t),{sun:u,sky:d}=t.def,f=u.dir.map(e=>e/Math.hypot(...u.dir)),p=si(),m=l.length*4,h=m+ci,g={},_,v,y,b,x={},S,C,w,T,ee=[0,0],E=[],D=!1,O=/* @__PURE__ */ new Float32Array(16),k=()=>{i.bufferData(i.ARRAY_BUFFER,h,i.DYNAMIC_DRAW),i.bufferSubData(i.ARRAY_BUFFER,0,new Float32Array(l))},A=(e,t,n)=>{let r=i.createProgram();for(let[n,a]of[[i.VERTEX_SHADER,e],[i.FRAGMENT_SHADER,t]]){let e=i.createShader(n);i.shaderSource(e,a),i.compileShader(e),i.attachShader(r,e)}return i.linkProgram(r),i.useProgram(r),[r,Object.fromEntries(n.map(e=>[e,i.getUniformLocation(r,e)]))]},j=(e,t)=>{let n=i.createTexture();i.bindTexture(i.TEXTURE_2D,n),i.texStorage2D(i.TEXTURE_2D,1,S,e,t),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE);let r=i.createFramebuffer();return i.bindFramebuffer(i.FRAMEBUFFER,r),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,n,0),E.push(()=>i.deleteTexture(n),()=>i.deleteFramebuffer(r)),{t:n,f:r,w:e,h:t}},te=(e,t)=>{E.splice(0).forEach(e=>e()),ee=[e,t],w=j(e,t),T=[1,2,3].map(n=>[0,1].map(()=>j(e>>n||1,t>>n||1)));let n=n=>{let r=i.createRenderbuffer();return i.bindRenderbuffer(i.RENDERBUFFER,r),i.renderbufferStorageMultisample(i.RENDERBUFFER,mi,n,e,t),E.push(()=>i.deleteRenderbuffer(r)),r};i.bindFramebuffer(i.FRAMEBUFFER,C=i.createFramebuffer()),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.RENDERBUFFER,n(S)),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.RENDERBUFFER,n(i.DEPTH_COMPONENT24)),E.push(()=>i.deleteFramebuffer(C))},M=(e,t,n,r,...a)=>{i.bindFramebuffer(i.FRAMEBUFFER,e?.f??null),i.viewport(0,0,e?.w??ee[0],e?.h??ee[1]),a.forEach((e,t)=>{i.activeTexture(i.TEXTURE0+t),i.bindTexture(i.TEXTURE_2D,e.t)}),i.uniform4f(x.Y,n,r,t,performance.now()%1e4),i.drawArrays(i.TRIANGLES,0,3)},N=()=>{S=i.getExtension(`EXT_color_buffer_float`)?i.RGBA16F:i.RGBA8,E.length=0,ee=[0,0],[b,x]=A(gi,_i,[`S`,`Y`,`L`]),i.uniform1iv(x.S,[0,1,2,3]),[y,g]=A(hi,yi,[`m`,`E`,`T`,`Z`,`Q`,`A`,`B`,`K`,`M`,`D`,`F`,`G`,`W`,`H`,`O`,`X`,`Y`,`J`]),i.uniform1i(g.D,1),i.bindBuffer(i.ARRAY_BUFFER,i.createBuffer()),k(),[3,3,4].reduce((e,t,n)=>(i.enableVertexAttribArray(n),i.vertexAttribPointer(n,t,i.FLOAT,!1,40,e*4),e+t),0),i.activeTexture(i.TEXTURE1),i.bindTexture(i.TEXTURE_2D_ARRAY,_=i.createTexture()),i.texStorage3D(i.TEXTURE_2D_ARRAY,1,i.DEPTH_COMPONENT24,ui,ui,5);for(let[e,t]of[[i.TEXTURE_MIN_FILTER,i.LINEAR],[i.TEXTURE_MAG_FILTER,i.LINEAR],[i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE],[i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE],[i.TEXTURE_COMPARE_MODE,i.COMPARE_REF_TO_TEXTURE]])i.texParameteri(i.TEXTURE_2D_ARRAY,e,t);i.bindFramebuffer(i.FRAMEBUFFER,v=i.createFramebuffer()),i.drawBuffers([i.NONE]),i.bindFramebuffer(i.FRAMEBUFFER,null),i.polygonOffset(2,4),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D_ARRAY,i.createTexture()),i.texImage3D(i.TEXTURE_2D_ARRAY,0,i.RGBA8,128,128,ni,0,i.RGBA,i.UNSIGNED_BYTE,p),i.generateMipmap(i.TEXTURE_2D_ARRAY),i.texParameteri(i.TEXTURE_2D_ARRAY,i.TEXTURE_MIN_FILTER,i.LINEAR_MIPMAP_LINEAR);let e=i.getExtension(`EXT_texture_filter_anisotropic`);e&&i.texParameterf(i.TEXTURE_2D_ARRAY,e.TEXTURE_MAX_ANISOTROPY_EXT,8),i.enable(i.DEPTH_TEST),i.depthFunc(i.LEQUAL),P();let[t,n]=c();t&&n&&te(t,n)},P=()=>{let e=Ti(t);i.uniform4fv(g.F,ki(t.def)),i.uniform3fv(g.H,Oi(t.def).flat()),i.uniform3fv(g.O,f),i.uniform3fv(g.X,u.color),i.uniform3fv(g.G,Float32Array.from({length:48},(t,n)=>e[n/3|0]?.[n%3]??1)),i.clearColor(...d[1],1)};N();let F=e=>{e.preventDefault(),D=!0},I=()=>{N(),D=!1};return e.addEventListener(`webglcontextlost`,F),e.addEventListener(`webglcontextrestored`,I),{frame(t,a,o,u,d,p,S,E,A){let[j,N]=c();if(D||!j||!N)return;(e.width!=j||e.height!=N)&&(e.width=j,e.height=N),(ee[0]!=j||ee[1]!=N)&&te(j,N);let P=Math.tan((70+p.fov)*Math.PI/360);O=bi(t,a,o,j/N,p.roll,P);let F=[],I=performance.now()/1e3,ne=Math.min(.1,I-r);r=I,Mr(n,u,ne),A?.bases.forEach((e,t)=>Bn(F,e,Nn(t),I)),A?.flags.forEach(e=>Un(F,e,Nn(e.team),I));for(let e of u)ti(F,n.get(e.id),s(d.get(e.id)??`#888`),+(Math.hypot(e.x-t[0],e.z-t[2])<pi));let re=F.length;E?.draw(F,t,a,o,p.roll),m+F.length*4>h&&(h=m+F.length*8,k()),i.bufferSubData(i.ARRAY_BUFFER,m,new Float32Array(F));let L=Ci(S),ie=l.length/10,ae=wi(f,t);i.uniform1f(g.Z,-1),i.activeTexture(i.TEXTURE1),i.bindTexture(i.TEXTURE_2D_ARRAY,null),i.bindFramebuffer(i.FRAMEBUFFER,v),i.viewport(0,0,ui,ui),i.enable(i.POLYGON_OFFSET_FILL);for(let e=0;e<=L.maps;e++)i.framebufferTextureLayer(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,_,0,e),i.uniformMatrix4fv(g.m,!1,e?L.m.subarray(e*16-16,e*16):ae),i.clear(i.DEPTH_BUFFER_BIT),i.drawArrays(i.TRIANGLES,0,ie+re/10);i.disable(i.POLYGON_OFFSET_FILL),i.bindTexture(i.TEXTURE_2D_ARRAY,_),i.activeTexture(i.TEXTURE0),i.bindFramebuffer(i.FRAMEBUFFER,C),i.viewport(0,0,j,N),i.uniformMatrix4fv(g.m,!1,O),i.uniformMatrix4fv(g.W,!1,ae),i.uniform3fv(g.E,t),i.uniform1f(g.T,performance.now()/1e3),i.uniform1f(g.Z,1),i.uniform1i(g.Q,L.n),i.uniform4fv(g.A,L.a),i.uniform4fv(g.B,L.b),i.uniform4fv(g.K,L.k),i.uniformMatrix4fv(g.M,!1,L.m),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT);let[oe,se,ce]=yt(a,o,p.roll);i.uniform3fv(g.J,[oe.map(e=>e*P*(j/N)),se.map(e=>e*P),ce].flat()),i.uniform1f(g.Y,1),i.drawArrays(i.TRIANGLES,0,3),i.uniform1f(g.Y,0),i.drawArrays(i.TRIANGLES,0,ie+re/10),F.length>re&&(i.clear(i.DEPTH_BUFFER_BIT),i.drawArrays(i.TRIANGLES,ie+re/10,(F.length-re)/10)),i.bindFramebuffer(i.READ_FRAMEBUFFER,C),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,w.f),i.blitFramebuffer(0,0,j,N,0,0,j,N,i.COLOR_BUFFER_BIT,i.NEAREST),i.useProgram(b),M(T[0][0],0,1/j,1/N,w),T.forEach(([e,t],n)=>{M(t,1,1/t.w,0,T[n&&n-1][0]),M(e,1,0,1/e.h,t)}),i.uniform1f(x.L,p.lines),M(void 0,2,0,0,w,...T.map(e=>e[0]));for(let e=3;e>0;e--)i.activeTexture(i.TEXTURE0+e),i.bindTexture(i.TEXTURE_2D,null);i.activeTexture(i.TEXTURE0),i.useProgram(y)},project:(e,t,n)=>xi(O,e,t,n),destroy(){e.removeEventListener(`webglcontextlost`,F),e.removeEventListener(`webglcontextrestored`,I),i.getExtension(`WEBGL_lose_context`)?.loseContext()}}},Ni=1/60,Pi=5,Fi=(e,n)=>{let r=document.createElement(`div`),i=r.attachShadow({mode:`open`});i.innerHTML=`<style>:host{display:block;width:100%;height:100%}div{position:relative;width:100%;height:100%;overflow:hidden;background:#000;font:600 14px system-ui,sans-serif;color:#fff;text-shadow:0 1px 2px #000}canvas{display:block;width:100%;height:100%;cursor:pointer}i,p,b{position:absolute;pointer-events:none;user-select:none;margin:0}`+Kn+`i{left:50%;top:50%;width:6px;height:6px;margin:-3px;border-radius:50%;background:#fff;box-shadow:0 0 0 1px #0008}p{bottom:8px;left:12px}b{transform:translate(-50%,-100%);font-size:12px;white-space:nowrap}[hidden]{display:none}</style><div><canvas></canvas><i></i><p></p></div>`,e.append(r);let a=i.querySelector(`canvas`),o=i.querySelector(`p`),s=i.querySelector(`div`),c=Yn(s),l={roster:[],open:[],close:[]},u=e=>l[e].forEach(e=>e()),d=C(v),f=ur(d),p=dt();p.mute(ft()),c.mute(p.muted);let m=nr(a,()=>c.mute(pt(p)));a.addEventListener(`click`,()=>p.unlock());let h=Tn(),g=Gn(p),_=en(),y;try{y=Mi(a,d)}catch{}let b=d.def.teams.map(e=>e.base),x=[],S={id:-1,team:0},w,T,E=/* @__PURE__ */ new Map,D=/* @__PURE__ */ new Map,O=/* @__PURE__ */ new Map,k=!1,A=y?``:`WebGL2 is not available`,j=!1,te=performance.now(),M=0,N=0,P=!1,F=n.socket??new WebSocket(n.url);F.binaryType=`arraybuffer`,F.onopen=()=>{k=!0,F.send(JSON.stringify({t:`join`,name:n.name})),u(`open`)},F.onclose=()=>{k=!1,A||=`Connection closed`,u(`close`)},F.onmessage=({data:e})=>{if(typeof e!=`string`){let t=Ge(e);if(t){f.snapshot(t,performance.now());for(let e of mt(w,t)){let t=ht(e,S,e=>D.get(e)??`Someone`);c.banner(t.text,t.team),e.kind==`start`&&([m.yaw,m.pitch]=[d.def.teams[S.team].spawns[0][3],0]);let n=gt(e,S.team);n&&p.play(n[0],void 0,1,n[1])}w=t}return}let t=Ke(e);t?.t==`roster`?(x=t.players,E=new Map(x.map(e=>[e.id,e.color])),D=new Map(x.map(e=>[e.id,e.name])),S={id:t.you,team:x.find(e=>e.id==t.you)?.team??0},f.you(S.id,S.team),o.textContent=`Players: ${x.length}`,u(`roster`)):t?.t==`end`?T={score:t.score,players:t.players}:t?.t==`full`&&(A=`Room is full`)};let I=e=>{let t=O.get(e);return t||(O.set(e,t=document.createElement(`b`)),s.append(t)),t},ne=()=>{N=requestAnimationFrame(ne);let e=performance.now(),n=te;if(M=Math.min(M+(e-te)/1e3,Pi*Ni),te=e,!j){let e=f.me(0);e&&([m.yaw,m.pitch,j]=[e.yaw,e.pitch,!0]),M=0}for(;j&&M>=Ni;M-=Ni){let t=f.step({keys:m.take(),yaw:m.yaw,pitch:m.pitch},e);k&&F.send(Ue(t))}let r=f.me(M/Ni),i=f.others(e),a=r?[r.x,r.y+ae(r),r.z]:[0,0,0];p.listen(a,m.yaw);let o=Math.min((e-n)/1e3,.1),s=e=>e==S.id?r:i.find(t=>t.id==e),l=w&&{bases:b,flags:Pn(w.flags,b,s)},u=f.events();if(h.update(r,m.keys,o,u),g.me(r,u,h.stride),g.others(i),_.update(r,u,o),r&&y){let t=[a[0],a[1]+h.dy,a[2]],n=m.pitch+h.pitch;y.frame(t,m.yaw,n,i,E,h,mr({eye:t,yaw:m.yaw,pitch:n,others:i,t:e/1e3,ctf:l}),_,l)}w&&(c.match(w,e=>D.get(e)??`?`),c.marks(r&&y?vr({eye:a,id:S.id,team:S.team,yaw:m.yaw,flags:w.flags,bases:b,where:e=>{let t=s(e);return t&&[t.x,t.y,t.z]},project:y.project}):[]),c.end(w.over?T:void 0,w.clock));let v=/* @__PURE__ */ new Set;for(let e of i){let n=[e.x,e.y+t+.3,e.z],i=r&&!ee(d,a,n)?y?.project(...n):void 0,o=I(e.id);v.add(e.id),o.hidden=!i,i&&(o.style.left=i[0]*100+`%`,o.style.top=i[1]*100+`%`);let s=D.get(e.id)??``;o.textContent!=s&&(o.textContent=s),o.style.color=E.get(e.id)??``}for(let[e,t]of O)v.has(e)||(t.remove(),O.delete(e));c.title(A||(k?j?m.locked()?``:`Click to play`:`Joining…`:`Connecting…`),d.def.name??``)};return N=requestAnimationFrame(ne),{on:(e,t)=>void l[e].push(t),players:()=>x,destroy(){P||(P=!0,cancelAnimationFrame(N),m.destroy(),p.destroy(),y?.destroy(),F.onopen=F.onclose=F.onmessage=null,F.close(),document.exitPointerLock(),r.remove())}}};export{Fi as tinyFps};
68
+ c+=step(abs(L-${_.GLASS}.),.5)*K0(reflect(-V,m))*(.1+.9*pow(1.-max(dot(m,V),0.),4.));
69
+ o=vec4(mix(c,F.rgb,1.-exp(-F.a*length(P-E))),1.);}`,na=(e,t,n,r,i=0,a=Ji,[o,s]=[.1,400])=>{let[c,l,u]=xt(t,n,i),d=(s+o)/(s-o),f=[c.map(e=>e/(a*r)),l.map(e=>e/a),u.map(e=>e*d),u].map(t=>[...t,-t[0]*e[0]-t[1]*e[1]-t[2]*e[2]]);return f[2][3]-=2*s*o/(s-o),Float32Array.from({length:16},(e,t)=>f[t&3][t>>2])},ra=(e,t,n,r)=>{let i=e[3]*t+e[7]*n+e[11]*r+e[15];if(i<=0)return;let a=e[0]*t+e[4]*n+e[8]*r+e[12],o=e[1]*t+e[5]*n+e[9]*r+e[13];return[.5+a/(2*i),.5-o/(2*i)]},ia=({p:e,d:t,cone:n,range:r})=>na(e,Math.atan2(-t[0],-t[2]),Math.atan2(t[1],Math.hypot(t[0],t[2])),1,0,Math.min(Math.tan(Math.acos(n)),5.7),[.3,r]),aa=e=>{let[t,n,r]=[0,0,0].map(()=>/* @__PURE__ */ new Float32Array(64)),i=/* @__PURE__ */ new Float32Array(64),a=0,o=e.slice(0,16);return o.forEach((e,o)=>{let s=e.shadow&&e.kind==br.SPOT&&a<4?a++:-1;t.set([...e.p,e.range],o*4),n.set([...e.d,e.kind==br.POINT?-9:e.cone],o*4),r.set([...e.color,s],o*4),s>=0&&i.set(ia(e),s*16)}),{n:o.length,maps:a,a:t,b:n,k:r,m:i}},oa=(e,t,n=64,r=100)=>{let i=e.map(e=>-e),a=Math.hypot(i[0],i[2]),o=a>.001?[-i[2]/a,0,i[0]/a]:[1,0,0],s=[o[1]*i[2]-o[2]*i[1],o[2]*i[0]-o[0]*i[2],o[0]*i[1]-o[1]*i[0]],c=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],[l,u]=[n/2,n/Ki],d=[o,s].map(e=>[...e.map(e=>e/l),-(Math.round(c(e,t)/u)*u)/l]);return d.push([...i.map(e=>e/r),-c(i,t)/r],[0,0,0,1]),Float32Array.from({length:16},(e,t)=>d[t&3][t>>2])},sa=({def:e})=>[...new Map([[`1,1,1`,[1,1,1]],...e.brushes.flatMap(({tint:e})=>e?[[`${e}`,e]]:[])]).values()].slice(0,16),ca=[[0,0],[1,0],[1,1],[0,0],[1,1],[0,1]],la=e=>{let{brushes:t,floor:n}=e.def,r=[],i=sa(e).map(String);return t.forEach((e,a)=>{let o=1+2*Math.max(0,i.indexOf(`${e.tint}`));for(let i=0;i<3;i++){let[s,c]=[(i+1)%3,(i+2)%3],[l,u]=i==0?[2,1]:i==1?[0,2]:[0,1];for(let d of[0,1]){let f=d?e.max[i]:e.min[i];if(t.some((t,n)=>n!=a&&(d?t.min[i]:t.max[i])==f&&t.min[s]<=e.min[s]&&t.max[s]>=e.max[s]&&t.min[c]<=e.min[c]&&t.max[c]>=e.max[c])||i==1&&!d&&e.min[1]<=n)continue;let p=[0,0,0];p[i]=d?1:-1;for(let[t,n]of ca){let a=[0,0,0];[a[i],a[s],a[c]]=[f,(t?e.max:e.min)[s],(n?e.max:e.min)[c]],r.push(...a,...p,a[l],a[u],i==1&&d?e.top:e.side,o)}}}}),r},ua=({sky:[e,t]})=>[e.map(e=>(e*.45+.55)*.74),t.map(e=>(e*.7+.3)*.58),t.map((e,t)=>e*[1,.92,.8][t]*.34),e,t],da=e=>({...e,def:{...e.def,brushes:[...e.def.brushes,...Ci(e.def)]}}),fa=({fog:e,sky:t})=>e?[...[0,1,2].map(n=>e[n]+(t[1][n]-e[n])*qi),e[3]]:[...t[1],0],pa=2073600,ma=(e,t,n)=>{let r=Math.min(n,2,Math.sqrt(pa/(e*t||1)));return[Math.round(e*r),Math.round(t*r)]},ha=(e,t)=>{let n=/* @__PURE__ */ new Map,r=performance.now()/1e3,i=e.getContext(`webgl2`,{antialias:!1,depth:!1});if(!i)throw Error(`WebGL2 is not available`);let a=document.createElement(`canvas`).getContext(`2d`),o=/* @__PURE__ */ new Map,s=e=>{let t=o.get(e);if(!t){a.fillStyle=`#888`,a.fillStyle=e;let n=parseInt(a.fillStyle.slice(1),16),r=n>=0?n:8947848;o.set(e,t=[r>>16,r>>8&255,r&255].map(e=>e/255))}return t},c=()=>ma(e.clientWidth,e.clientHeight,devicePixelRatio),l=[...la({...t,def:{...t.def,brushes:[...t.def.brushes,...Ci(t.def)]}}),...Vi(t.def),...Ui(t.def)],{sun:u,sky:d}=t.def,f=u.dir.map(e=>e/Math.hypot(...u.dir)),p=gi(),m=l.length*4,h=m+Wi,g={},_,v,y,b,x={},S,C,w,T,E=[0,0],D=[],O=!1,ee=/* @__PURE__ */ new Float32Array(16),k=()=>{i.bufferData(i.ARRAY_BUFFER,h,i.DYNAMIC_DRAW),i.bufferSubData(i.ARRAY_BUFFER,0,new Float32Array(l))},A=(e,t,n)=>{let r=i.createProgram();for(let[n,a]of[[i.VERTEX_SHADER,e],[i.FRAGMENT_SHADER,t]]){let e=i.createShader(n);i.shaderSource(e,a),i.compileShader(e),i.attachShader(r,e)}return i.linkProgram(r),i.useProgram(r),[r,Object.fromEntries(n.map(e=>[e,i.getUniformLocation(r,e)]))]},j=(e,t)=>{let n=i.createTexture();i.bindTexture(i.TEXTURE_2D,n),i.texStorage2D(i.TEXTURE_2D,1,S,e,t),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE);let r=i.createFramebuffer();return i.bindFramebuffer(i.FRAMEBUFFER,r),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,n,0),D.push(()=>i.deleteTexture(n),()=>i.deleteFramebuffer(r)),{t:n,f:r,w:e,h:t}},M=(e,t)=>{D.splice(0).forEach(e=>e()),E=[e,t],w=j(e,t),T=[1,2,3].map(n=>[0,1].map(()=>j(e>>n||1,t>>n||1)));let n=n=>{let r=i.createRenderbuffer();return i.bindRenderbuffer(i.RENDERBUFFER,r),i.renderbufferStorageMultisample(i.RENDERBUFFER,Xi,n,e,t),D.push(()=>i.deleteRenderbuffer(r)),r};i.bindFramebuffer(i.FRAMEBUFFER,C=i.createFramebuffer()),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.RENDERBUFFER,n(S)),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.RENDERBUFFER,n(i.DEPTH_COMPONENT24)),D.push(()=>i.deleteFramebuffer(C))},N=(e,t,n,r,...a)=>{i.bindFramebuffer(i.FRAMEBUFFER,e?.f??null),i.viewport(0,0,e?.w??E[0],e?.h??E[1]),a.forEach((e,t)=>{i.activeTexture(i.TEXTURE0+t),i.bindTexture(i.TEXTURE_2D,e.t)}),i.uniform4f(x.Y,n,r,t,performance.now()%1e4),i.drawArrays(i.TRIANGLES,0,3)},P=()=>{S=i.getExtension(`EXT_color_buffer_float`)?i.RGBA16F:i.RGBA8,D.length=0,E=[0,0],[b,x]=A(Qi,$i,[`S`,`Y`,`L`]),i.uniform1iv(x.S,[0,1,2,3]),[y,g]=A(Zi,ta,[`m`,`E`,`T`,`Z`,`Q`,`A`,`B`,`K`,`M`,`D`,`F`,`G`,`W`,`H`,`O`,`X`,`Y`,`J`]),i.uniform1i(g.D,1),i.bindBuffer(i.ARRAY_BUFFER,i.createBuffer()),k(),[3,3,4].reduce((e,t,n)=>(i.enableVertexAttribArray(n),i.vertexAttribPointer(n,t,i.FLOAT,!1,40,e*4),e+t),0),i.activeTexture(i.TEXTURE1),i.bindTexture(i.TEXTURE_2D_ARRAY,_=i.createTexture()),i.texStorage3D(i.TEXTURE_2D_ARRAY,1,i.DEPTH_COMPONENT24,Ki,Ki,5);for(let[e,t]of[[i.TEXTURE_MIN_FILTER,i.LINEAR],[i.TEXTURE_MAG_FILTER,i.LINEAR],[i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE],[i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE],[i.TEXTURE_COMPARE_MODE,i.COMPARE_REF_TO_TEXTURE]])i.texParameteri(i.TEXTURE_2D_ARRAY,e,t);i.bindFramebuffer(i.FRAMEBUFFER,v=i.createFramebuffer()),i.drawBuffers([i.NONE]),i.bindFramebuffer(i.FRAMEBUFFER,null),i.polygonOffset(2,4),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D_ARRAY,i.createTexture()),i.texImage3D(i.TEXTURE_2D_ARRAY,0,i.RGBA8,128,128,fi,0,i.RGBA,i.UNSIGNED_BYTE,p),i.generateMipmap(i.TEXTURE_2D_ARRAY),i.texParameteri(i.TEXTURE_2D_ARRAY,i.TEXTURE_MIN_FILTER,i.LINEAR_MIPMAP_LINEAR);let e=i.getExtension(`EXT_texture_filter_anisotropic`);e&&i.texParameterf(i.TEXTURE_2D_ARRAY,e.TEXTURE_MAX_ANISOTROPY_EXT,8),i.enable(i.DEPTH_TEST),i.depthFunc(i.LEQUAL),te();let[t,n]=c();t&&n&&M(t,n)},te=()=>{let e=sa(da(t));i.uniform4fv(g.F,fa(t.def)),i.uniform3fv(g.H,ua(t.def).flat()),i.uniform3fv(g.O,f),i.uniform3fv(g.X,u.color),i.uniform3fv(g.G,Float32Array.from({length:48},(t,n)=>e[n/3|0]?.[n%3]??1)),i.clearColor(...d[1],1)};P();let F=e=>{e.preventDefault(),O=!0},I=()=>{P(),O=!1};return e.addEventListener(`webglcontextlost`,F),e.addEventListener(`webglcontextrestored`,I),{frame(t,a,o,u,d,p,S,D,A){let[j,P]=c();if(O||!j||!P)return;(e.width!=j||e.height!=P)&&(e.width=j,e.height=P),(E[0]!=j||E[1]!=P)&&M(j,P);let te=Math.tan((70+p.fov)*Math.PI/360);ee=na(t,a,o,j/P,p.roll,te);let F=[],I=performance.now()/1e3,ne=Math.min(.1,I-r);r=I,Vr(n,u,ne),A?.bases.forEach((e,t)=>Yn(F,e,Hn(t),I)),A?.flags.forEach(e=>Qn(F,e,Hn(e.team),I));for(let e of u)di(F,n.get(e.id),s(d.get(e.id)??`#888`),+(Math.hypot(e.x-t[0],e.z-t[2])<Yi));let L=F.length;D?.draw(F,t,a,o,p.roll),m+F.length*4>h&&(h=m+F.length*8,k()),i.bufferSubData(i.ARRAY_BUFFER,m,new Float32Array(F));let R=aa(S),re=l.length/10,ie=oa(f,t);i.uniform1f(g.Z,-1),i.activeTexture(i.TEXTURE1),i.bindTexture(i.TEXTURE_2D_ARRAY,null),i.bindFramebuffer(i.FRAMEBUFFER,v),i.viewport(0,0,Ki,Ki),i.enable(i.POLYGON_OFFSET_FILL);for(let e=0;e<=R.maps;e++)i.framebufferTextureLayer(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,_,0,e),i.uniformMatrix4fv(g.m,!1,e?R.m.subarray(e*16-16,e*16):ie),i.clear(i.DEPTH_BUFFER_BIT),i.drawArrays(i.TRIANGLES,0,re+L/10);i.disable(i.POLYGON_OFFSET_FILL),i.bindTexture(i.TEXTURE_2D_ARRAY,_),i.activeTexture(i.TEXTURE0),i.bindFramebuffer(i.FRAMEBUFFER,C),i.viewport(0,0,j,P),i.uniformMatrix4fv(g.m,!1,ee),i.uniformMatrix4fv(g.W,!1,ie),i.uniform3fv(g.E,t),i.uniform1f(g.T,performance.now()/1e3),i.uniform1f(g.Z,1),i.uniform1i(g.Q,R.n),i.uniform4fv(g.A,R.a),i.uniform4fv(g.B,R.b),i.uniform4fv(g.K,R.k),i.uniformMatrix4fv(g.M,!1,R.m),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT);let[ae,oe,se]=xt(a,o,p.roll);i.uniform3fv(g.J,[ae.map(e=>e*te*(j/P)),oe.map(e=>e*te),se].flat()),i.uniform1f(g.Y,1),i.drawArrays(i.TRIANGLES,0,3),i.uniform1f(g.Y,0),i.drawArrays(i.TRIANGLES,0,re+L/10),F.length>L&&(i.clear(i.DEPTH_BUFFER_BIT),i.drawArrays(i.TRIANGLES,re+L/10,(F.length-L)/10)),i.bindFramebuffer(i.READ_FRAMEBUFFER,C),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,w.f),i.blitFramebuffer(0,0,j,P,0,0,j,P,i.COLOR_BUFFER_BIT,i.NEAREST),i.useProgram(b),N(T[0][0],0,1/j,1/P,w),T.forEach(([e,t],n)=>{N(t,1,1/t.w,0,T[n&&n-1][0]),N(e,1,0,1/e.h,t)}),i.uniform1f(x.L,p.lines),N(void 0,2,0,0,w,...T.map(e=>e[0]));for(let e=3;e>0;e--)i.activeTexture(i.TEXTURE0+e),i.bindTexture(i.TEXTURE_2D,null);i.activeTexture(i.TEXTURE0),i.useProgram(y)},project:(e,t,n)=>ra(ee,e,t,n),destroy(){e.removeEventListener(`webglcontextlost`,F),e.removeEventListener(`webglcontextrestored`,I),i.getExtension(`WEBGL_lose_context`)?.loseContext()}}},ga=1/60,_a=5,va=(e,n)=>{let r=document.createElement(`div`),i=r.attachShadow({mode:`open`});i.innerHTML=`<style>:host{display:block;width:100%;height:100%}div{position:relative;width:100%;height:100%;overflow:hidden;background:#000;font:600 14px system-ui,sans-serif;color:#fff;text-shadow:0 1px 2px #000}canvas{display:block;width:100%;height:100%;cursor:pointer}i,p,b{position:absolute;pointer-events:none;user-select:none;margin:0}`+tr+`i{left:50%;top:50%;width:6px;height:6px;margin:-3px;border-radius:50%;background:#fff;box-shadow:0 0 0 1px #0008}p{bottom:8px;left:12px}b{transform:translate(-50%,-100%);font-size:12px;white-space:nowrap}[hidden]{display:none}</style><div><canvas></canvas><i></i><p></p></div>`,e.append(r);let a=i.querySelector(`canvas`),o=i.querySelector(`p`),s=i.querySelector(`div`),c=ir(s),l={roster:[],open:[],close:[]},u=e=>l[e].forEach(e=>e()),d=E(x),f=yr(d),p=pt();p.mute(mt()),c.mute(p.muted);let m=dr(a,()=>c.mute(ht(p)));a.addEventListener(`click`,()=>p.unlock());let h=Pn(),g=er(p),_=an(),v;try{v=ha(a,d)}catch{}let y=d.def.teams.map(e=>e.base),b=[],S={id:-1,team:0},C,w,T=/* @__PURE__ */ new Map,D=/* @__PURE__ */ new Map,O=/* @__PURE__ */ new Map,k=!1,A=v?``:`WebGL2 is not available`,j=!1,M=performance.now(),N=0,P=0,te=!1,F=n.socket??new WebSocket(n.url);F.binaryType=`arraybuffer`,F.onopen=()=>{k=!0,F.send(JSON.stringify({t:`join`,name:n.name})),u(`open`)},F.onclose=()=>{k=!1,A||=`Connection closed`,u(`close`)},F.onmessage=({data:e})=>{if(typeof e!=`string`){let t=qe(e);if(t){f.snapshot(t,performance.now());for(let e of gt(C,t)){let t=_t(e,S,e=>D.get(e)??`Someone`);t&&c.banner(t.text,t.team),e.kind==`start`&&([m.yaw,m.pitch]=[d.def.teams[S.team].spawns[0][3],0]);for(let t of vt(e,S))p.play(t.id,t.at,t.gain,t.rate);e.kind==`tackle`&&(e.who==S.id?h.jolt():e.by==S.id&&h.punch())}C=t}return}let t=Je(e);t?.t==`roster`?(b=t.players,T=new Map(b.map(e=>[e.id,e.color])),D=new Map(b.map(e=>[e.id,e.name])),S={id:t.you,team:b.find(e=>e.id==t.you)?.team??0},f.you(S.id,S.team),o.textContent=`Players: ${b.length}`,u(`roster`)):t?.t==`end`?w={score:t.score,players:t.players}:t?.t==`full`&&(A=`Room is full`)};let I=e=>{let t=O.get(e);return t||(O.set(e,t=document.createElement(`b`)),s.append(t)),t},ne=()=>{P=requestAnimationFrame(ne);let e=performance.now(),n=M;if(N=Math.min(N+(e-M)/1e3,_a*ga),M=e,!j){let e=f.me(0);e&&([m.yaw,m.pitch,j]=[e.yaw,e.pitch,!0]),N=0}for(;j&&N>=ga;N-=ga){let t=f.step({keys:m.take(),yaw:m.yaw,pitch:m.pitch},e);k&&F.send(Ge(t))}let r=f.me(N/ga),i=f.others(e),a=r?[r.x,r.y+se(r),r.z]:[0,0,0];p.listen(a,m.yaw);let o=Math.min((e-n)/1e3,.1),s=e=>e==S.id?r:i.find(t=>t.id==e),l=C&&{bases:y,flags:Un(C.flags,y,s)},u=f.events();if(h.update(r,m.keys,o,u),c.hurt(h.hurt),g.me(r,u,h.stride),g.others(i),_.update(r,u,o),r&&v){let t=[a[0],a[1]+h.dy,a[2]],n=m.pitch+h.pitch;v.frame(t,m.yaw,n,i,T,h,Cr({eye:t,yaw:m.yaw,pitch:n,others:i,t:e/1e3,ctf:l}),_,l)}C&&(c.match(C,e=>D.get(e)??`?`),c.marks(r&&v?Dr({eye:a,id:S.id,team:S.team,yaw:m.yaw,flags:C.flags,bases:y,where:e=>{let t=s(e);return t&&[t.x,t.y,t.z]},project:v.project}):[]),c.end(C.over?w:void 0,C.clock));let b=/* @__PURE__ */ new Set;for(let e of i){let n=[e.x,e.y+t+.3,e.z],i=r&&!ee(d,a,n)?v?.project(...n):void 0,o=I(e.id);b.add(e.id),o.hidden=!i,i&&(o.style.left=i[0]*100+`%`,o.style.top=i[1]*100+`%`);let s=D.get(e.id)??``;o.textContent!=s&&(o.textContent=s),o.style.color=T.get(e.id)??``}for(let[e,t]of O)b.has(e)||(t.remove(),O.delete(e));c.title(A||(k?j?m.locked()?``:`Click to play`:`Joining…`:`Connecting…`),d.def.name??``)};return P=requestAnimationFrame(ne),{on:(e,t)=>void l[e].push(t),players:()=>b,destroy(){te||(te=!0,cancelAnimationFrame(P),m.destroy(),p.destroy(),v?.destroy(),F.onopen=F.onclose=F.onmessage=null,F.close(),document.exitPointerLock(),r.remove())}}};export{va as tinyFps};
package/dist/local.js CHANGED
@@ -1 +1 @@
1
- var e={HOME:0,CARRIED:1,DROPPED:2},t={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,SPRINT:32,DASH:64,CROUCH:128},n={GROUND:0,AIR:1,WALLRUN:2,HANG:3,CLIMB:4,SLIDE:5,CROUCH:6},r={NONE:0,EAST:1,WEST:2,SOUTH:3,NORTH:4},i={JUMP:1,DOUBLE:2,DASH:4,LAND:8,GRAB:16,CLIMB:32,WALLRUN_START:64,WALLRUN_END:128,SLIDE_START:256,SLIDE_END:512,RESPAWN:1024},a={BRICK:0,TILE:1,LAVA:2,STONE:3,METAL:4,WOOD:5,MOSS:6,GRATE:7},o=16,s=65536/(2*Math.PI),c=e=>Math.round(e*s)&65535,l=e=>Math.max(-32768,Math.min(32767,Math.round(e))),u=e=>l(e*1e4),d=e=>e/1e4,f=e=>e/s,p=e=>{if(e.byteLength!==11)return null;let t=new DataView(e);return t.getUint8(0)===1?{seq:t.getUint16(1),keys:t.getUint8(3),yaw:f(t.getUint16(4)),pitch:d(t.getInt16(6)),view:(t.getUint16(8)*256+t.getUint8(10))/256}:null},m=t=>t===e.CARRIED?2:t===e.DROPPED?8:1,h=n=>{let r=4+39*n.players.length,i=new DataView(new ArrayBuffer(r+4+n.flags.reduce((e,t)=>e+m(t.state),0)));i.setUint8(0,2),i.setUint16(1,n.tick&65535),i.setUint8(3,n.players.length),n.players.forEach((e,n)=>{let r=4+n*39;i.setUint8(r,e.id),i.setFloat32(r+1,e.x),i.setFloat32(r+5,e.y),i.setFloat32(r+9,e.z),i.setFloat32(r+13,e.vx),i.setFloat32(r+17,e.vy),i.setFloat32(r+21,e.vz),i.setFloat32(r+25,e.edge),i.setUint16(r+29,c(e.yaw)),i.setInt16(r+31,u(e.pitch)),i.setUint16(r+33,e.ack&65535),i.setUint8(r+35,e.mode&7|(e.wall&7)<<3|(e.jumps&1)<<6|e.dashes<<7),i.setUint8(r+36,e.t),i.setUint8(r+37,e.dash),i.setUint8(r+38,e.coyote&7|(e.buffer&7)<<3|(e.held&t.JUMP?64:0)|(e.held&t.DASH?128:0))}),i.setUint8(r,n.score[0]),i.setUint8(r+1,n.score[1]),i.setUint16(r+2,n.clock&32767|(n.over?32768:0));let a=r+4;for(let t of n.flags)i.setUint8(a,t.state),t.state===e.CARRIED?i.setUint8(a+1,t.by):t.state===e.DROPPED&&(i.setInt16(a+1,l(t.x*o)),i.setInt16(a+3,l(t.y*o)),i.setInt16(a+5,l(t.z*o)),i.setUint8(a+7,Math.min(255,t.left))),a+=m(t.state);return i.buffer},g=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},_=.4,v=1.8,y=1.55,b=.9,x=7.5,S=1.5,ee=.15,C=.5,te=.9,ne=6.5,re=.2,ie=.03,ae=.2,oe=5.5,se=[`#ff3d4f`,`#2f80ff`],ce={maxPlayers:16,scoreLimit:3,timeLimit:480},le=4,w=1024,T=(e,t)=>(e+w)*(2*w)+t+w,E=(e,t)=>Math.min(Math.max(Math.floor(e/t),-1024),1023),ue=(e,t=le)=>{let n=/* @__PURE__ */ new Map;return e.brushes.forEach(({min:e,max:r},i)=>{for(let a=E(e[0],t);a<=E(r[0],t);a++)for(let o=E(e[2],t);o<=E(r[2],t);o++){let e=T(a,o),t=n.get(e);t?t.push(i):n.set(e,[i])}}),{def:e,cell:t,grid:n}},D=(e,t,n,r)=>{let i=[];for(let a=E(t-r,e.cell);a<=E(t+r,e.cell);a++)for(let t=E(n-r,e.cell);t<=E(n+r,e.cell);t++)for(let n of e.grid.get(T(a,t))??[])i.includes(n)||i.push(n);return i},de=(e,t,n,r)=>{let{cell:i,def:a}=e,o=r,s=E(t[0],i),c=E(t[2],i),l=Math.sign(n[0]),u=Math.sign(n[2]),d=l?((s+ +(l>0))*i-t[0])/n[0]:1/0,f=u?((c+ +(u>0))*i-t[2])/n[2]:1/0,p=d,m=f,h=l?i/Math.abs(n[0]):1/0,g=u?i/Math.abs(n[2]):1/0;for(;;){for(let r of e.grid.get(T(s,c))??[]){let e=a.brushes[r],[i,s]=[0,o];for(let r=0;r<3&&i<=s;r++){if(!n[r]){(t[r]<e.min[r]||t[r]>e.max[r])&&(s=-1);continue}let a=(e.min[r]-t[r])/n[r],o=(e.max[r]-t[r])/n[r];i=Math.max(i,Math.min(a,o)),s=Math.min(s,Math.max(a,o))}i<=s&&s>0&&i<o&&(o=i)}if(Math.min(p,m)>=o||Math.abs(s)>w||Math.abs(c)>w)return o;p<m?(s+=l,p+=h):(c+=u,m+=g)}},O=()=>({state:e.HOME,by:0,x:0,y:0,z:0,left:0}),k=60,fe=class{score=[0,0];over=!1;flags=[O(),O()];world;rules;mates=/* @__PURE__ */ new Map;clock;back=[0,0];lock=[{id:-1,left:0},{id:-1,left:0}];constructor(e,t){this.world=e,this.rules=t,this.clock=t.timeLimit*60}join(e,t,n){this.mates.set(e,{team:t,caps:0,returns:0,ground:[n.x,n.y,n.z]})}leave(e){let t=this.carrying(e),n=this.mates.get(e);t>=0&&n&&this.dropAt(t,n.ground),this.mates.delete(e)}place(e,t){let n=this.mates.get(e);n&&(n.ground=[t.x,t.y,t.z])}moved(e){let t=this.mates.get(e.id);if(!t)return;let n=this.carrying(e.id);e.ev&i.RESPAWN&&n>=0&&this.dropAt(n,t.ground),e.ground&&(t.ground=[e.x,e.y,e.z])}drop(e){let t=this.carrying(e.id),n=this.mates.get(e.id);if(t<0||!n||this.over)return!1;let r=n.ground;if(e.ground)r=[e.x,e.y,e.z];else{let t=de(this.world,[e.x,e.y+.05,e.z],[0,-1,0],k);t<k&&(r=[e.x,e.y+.05-t,e.z])}return this.dropAt(t,r),this.lock[t]={id:e.id,left:120},!0}carrying(t){return this.flags.findIndex(n=>n.state===e.CARRIED&&n.by===t)}winner(){let[e,t]=this.score;return e>t?0:t>e?1:-1}tally(){return[...this.mates].map(([e,t])=>({id:e,caps:t.caps,returns:t.returns}))}reset(){this.over=!1,this.score=[0,0],this.flags=[O(),O()],this.back=[0,0],this.lock.forEach(e=>e.left=0),this.clock=this.rules.timeLimit*60;for(let e of this.mates.values())e.caps=e.returns=0}wire(){return{score:[...this.score],clock:Math.ceil(this.clock/60),over:this.over,flags:this.flags.map(e=>({...e}))}}tick(t){if(this.over)return--this.clock<=0?(this.reset(),`start`):void 0;for(let t of[0,1]){let n=this.flags[t];this.lock[t].left--,n.state===e.DROPPED&&(n.left=Math.ceil(--this.back[t]/60),this.back[t]<=0&&(this.flags[t]=O()))}for(let n of[0,1]){let r=this.flags[n];if(r.state===e.CARRIED)continue;let i=r.state===e.HOME?this.world.def.teams[n].base:[r.x,r.y,r.z],a=t.filter(e=>pe(e.state,i)),o=r.state===e.DROPPED?a.find(e=>e.team===n):void 0,s=a.find(e=>e.team!==n&&(e.id!==this.lock[n].id||this.lock[n].left<=0));if(o){let e=this.mates.get(o.id);e&&e.returns++,this.flags[n]=O()}else s&&(this.flags[n]={...O(),state:e.CARRIED,by:s.id})}for(let n of t){let t=this.carrying(n.id);if(t>=0&&this.flags[n.team].state===e.HOME&&pe(n.state,this.world.def.teams[n.team].base)){this.score[n.team]++;let e=this.mates.get(n.id);e&&e.caps++,this.flags[t]=O()}}if(this.score.some(e=>e>=this.rules.scoreLimit)||--this.clock<=0)return this.over=!0,this.clock=600,`end`}dropAt(t,[n,r,i]){this.flags[t]={state:e.DROPPED,by:0,x:n,y:r,z:i,left:10},this.back[t]=600}},pe=(e,t)=>Math.hypot(e.x-t[0],e.z-t[2])<1.5&&e.y<t[1]+2.2&&e.y+1.8>t[1],me=-30,A=(e,t,n,r,i)=>({min:[e,me,t],max:[n,i,r],top:a.TILE,side:a.BRICK}),j=([e,t,n],[r,i,a],o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c}),he={name:`Rooftops`,brushes:[A(4,57.7,24,76,10),A(4,36,24,53.5,10),A(4,20,24,36,12.4),A(4,-5,24,7,12.4),A(27,20,47,50,8),A(27,60,47,76,8),j([9,12.2,39],[19,12.6,47],a.METAL,a.METAL),...((e,t)=>[1,2,3,4,5,6].map(n=>j([12,t,e-n],[14,t+.4*n,e-n+1],a.STONE,a.STONE)))(53,10),j([5,10,42],[5.5,14,42.5],a.METAL),j([5,10,50],[5.5,14,50.5],a.METAL),j([8,12.4,24],[20,12.85,24.45],a.METAL),j([36,8,22],[37,14.5,48],a.STONE,a.STONE,[1,.75,.62]),j([30,8,28],[34,10,32],a.STONE,a.BRICK),j([40,8,30],[44,10.2,34],a.STONE,a.BRICK),j([28,9.2,44],[35,12,46],a.METAL,a.GRATE,[.8,.9,1]),j([41.5,7.6,50],[42,8,60],a.METAL),j([30,8,64],[34,9.6,68],a.STONE,a.BRICK)],teams:[{base:[14,10,62.5],spawns:[[6,10,72,0],[10,10,72,0],[14,10,72,0],[18,10,72,0],[22,10,72,0],[8,10,66,0],[14,10,66,0],[20,10,66,0]]},{base:[14,12.4,2.2],spawns:[[6,12.4,-3,Math.PI],[10,12.4,-3,Math.PI],[14,12.4,-3,Math.PI],[18,12.4,-3,Math.PI],[22,12.4,-3,Math.PI],[8,12.4,.5,Math.PI],[14,12.4,.5,Math.PI],[20,12.4,.5,Math.PI]]}],floor:-25,sun:{dir:[.6,.64,.48],color:[3,2.7,2.2]},sky:[[.12,.3,.75],[.7,.82,.95]],fog:[.7,.82,.95,.008]},M=1/60,N=Math.PI*2,P=1e-6,F=.01,I=.001,L=e=>(e%N+N)%N,R=e=>[-Math.sin(e),-Math.cos(e)],z=Math.fround,B=Math.sqrt,V=(e,t,n)=>Math.min(Math.max(e,t),n),H=(e,t)=>B(e*e+t*t),U=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],ge={vx:0,vz:0,mode:n.GROUND,t:0,wall:r.NONE,edge:0,jumps:1,dashes:1,dash:0,coyote:6,buffer:0,held:0,ev:0,fall:0},W=(e,t,n,r=0)=>{let{spawns:i}=t.def.teams[r],[a,o,s,c]=i[(n%i.length+i.length)%i.length];return{id:e,x:z(a),y:z(o),z:z(s),vy:0,yaw:L(c),pitch:0,ground:!0,...ge}},G=e=>e===n.GROUND||e===n.SLIDE||e===n.CROUCH,_e=e=>e.mode===n.SLIDE||e.mode===n.CROUCH?b:v,K=(e,t,n)=>e.max[1]>t+.5+F&&e.min[1]<t+n-F,q=(e,t,n)=>[t-V(t,e.min[0],e.max[0]),n-V(n,e.min[2],e.max[2])],ve=(e,t,n)=>{let{brushes:r}=t.def,i=D(t,e.x,e.z,2*_),a=(_-P)**2,[o,s]=[0,0];for(let t=0;t<4;t++){let t=0,c=0,l=0;for(let o of i){let i=r[o];if(!K(i,e.y,n))continue;let[s,u]=q(i,e.x,e.z),d=s*s+u*u;if(d>=a)continue;if(d){let e=B(d);.4-e>t&&(t=_-e,c=s/e*t,l=u/e*t);continue}let[f,p,m]=[[e.x-i.min[0],-1,0],[i.max[0]-e.x,1,0],[e.z-i.min[2],0,-1],[i.max[2]-e.z,0,1]].reduce((e,t)=>t[0]<e[0]?t:e);f+.4>t&&(t=f+_,[c,l]=[p*t,m*t])}if(!t)break;e.x+=c,e.z+=l,o+=c,s+=l}return[o,s]},J=(e,t,n)=>{let{brushes:r}=t.def,i=(_-P)**2,a=-1/0,o=1/0;for(let s of D(t,e.x,e.z,_)){let t=r[s],[c,l]=q(t,e.x,e.z);c*c+l*l>=i||(t.max[1]<=e.y+.5+F?a=Math.max(a,t.max[1]):t.min[1]>=e.y+n-F&&(o=Math.min(o,t.min[1])))}return[a,o]},Y=(e,t)=>{let n=(_-P)**2;return D(t,e.x,e.z,_).every(r=>{let i=t.def.brushes[r],[a,o]=q(i,e.x,e.z);return a*a+o*o>=n||!K(i,e.y,1.8)})},ye=(e,t,n,r,i)=>{let a=(_-P)**2;return D(e,t,n,_).every(o=>{let s=e.def.brushes[o],[c,l]=q(s,t,n);return c*c+l*l>=a||s.max[1]<=r||s.min[1]>=i})},X=(e,t)=>{let[n,r]=U[t],i=n?0:2;return{a:i,o:2-i,sign:n||r,c:n?e.x:e.z,co:n?e.z:e.x}},be=(e,t,n,r)=>{let{a:i,o:a,sign:o,c:s,co:c}=X(t,n),l=((o>0?e.min[i]:e.max[i])-s)*o;return l>=.4-I&&l<=.4+r&&c>=e.min[a]&&c<=e.max[a]?l:void 0},xe=(e,t,n)=>{let r;for(let i of D(t,e.x,e.z,_+C)){let a=t.def.brushes[i],o=be(a,e,n,C);o!==void 0&&a.min[1]<e.y+.5&&a.max[1]>e.y+1.8&&(r=Math.min(r??1/0,Math.max(0,o-_)))}return r},Se=(e,t)=>{let[n,r]=R(e.yaw),i;for(let a=1;a<=4;a++){let[o,s]=U[a];if(a===e.wall||n*o+r*s<.5)continue;let{a:c,sign:l}=X(e,a);for(let n of D(t,e.x,e.z,_+re)){let r=t.def.brushes[n],o=r.max[1],s=o-e.y;if(be(r,e,a,.2)===void 0||s<1.2||s>2.4||r.min[1]>o-.25||i&&i.top>=o)continue;let u=l>0?r.min[c]:r.max[c],d=u-l*(_+ie),f=u+l*ae,[p,m]=c===0?[d,e.z]:[e.x,d],[h,g]=c===0?[f,e.z]:[e.x,f];ye(t,p,m,Math.min(e.y,o-2)+F,o+1.8)&&ye(t,h,g,o+F,o+1.8)&&(i={side:a,top:o,hang:d})}}return i},Ce=(e,t)=>{let{a:n,o:r,sign:i,c:a,co:o}=X(e,e.wall);return D(t,e.x,e.z,0).some(s=>{let c=t.def.brushes[s],l=i>0?a-c.min[n]:c.max[n]-a;return z(c.max[1])===e.edge&&o>=c.min[r]&&o<=c.max[r]&&l>=.2})},we=(e,t)=>{if(e.vy>=0)return!1;let[n]=J(e,t,v),r=6*M;return e.y-n<=-e.vy*r+10*r*r},Z=(e,t)=>{e.mode=t,e.t=0},Te=(e,t)=>{let n=H(e.vx,e.vz);n>t&&(e.vx*=t/n,e.vz*=t/n)},Ee=(e,t,n,r)=>{let[i,a]=[n.wx,n.wz];for(let n of D(t,e.x,e.z,_+I)){let o=t.def.brushes[n],[s,c]=q(o,e.x,e.z),l=H(s,c);if(l>0&&l<=.4+I&&K(o,e.y,r)){let e=(-i*s-a*c)/l;e>0&&(i+=e*s/l,a+=e*c/l)}}return[i,a]},De=(e,t,n)=>{let r=H(t[0],t[1]);if(r<P){let t=H(e.vx,e.vz),n=t?Math.max(0,t-45*M)/t:0;e.vx*=n,e.vz*=n;return}let[i,a]=[t[0]/r,t[1]/r],o=e.vx*i+e.vz*a,[s,c]=[e.vx-o*i,e.vz-o*a],l=H(s,c);if(l){let e=Math.max(0,l-45*M)/l;[s,c]=[s*e,c*e]}n*=r,o=o<n?Math.min(n,o+(o>=6?3:50)*M):Math.max(n,o-12*M),e.vx=s+o*i,e.vz=c+o*a},Oe=(e,t,n,r,i)=>{let a=e.y;e.x+=e.vx*M,e.z+=e.vz*M;let[o,s]=ve(e,t,n),c=H(o,s);if(c){let t=(e.vx*o+e.vz*s)/c;t<0&&(e.vx-=t*o/c,e.vz-=t*s/c)}let[l,u]=J(e,t,n),d=e.vy-r*20*M;if(e.y+=(e.vy+d)/2*M,e.vy=d,e.y+n>u&&(e.y=u-n,e.vy=Math.min(e.vy,0)),e.vy<=0?e.y<=l+F:e.y<l){if(e.y=l,e.vy<=0){let t=-e.vy;return e.vy=0,t}}else if(i&&e.vy<=0&&l>=a-.5)return e.y=l,e.vy=0,0;return-1},Q=(e,t)=>{e.vy=t,e.coyote=0,e.buffer=0,e.ev|=i.JUMP},ke=(e,r,i)=>{let[a,o]=U[e.wall],s=t=>{Z(e,t),e.edge=0};if(i.keys&(t.BACK|t.CROUCH))s(n.AIR),e.coyote=0;else if(i.jump&&i.fx*a+i.fz*o<0)s(n.AIR),e.vx=-a*4,e.vz=-o*4,Q(e,6);else if(i.jump||i.fwd&&e.t>=6)Z(e,n.CLIMB);else if(e.t>=30)s(n.AIR),e.coyote=0;else{let t=Math.max(e.edge-2,J(e,r,v)[0]);e.y+=V(t-e.y,-8*M,8*M)}},Ae=(e,t)=>{let[a,o]=U[e.wall];e.y<e.edge?e.y=Math.min(e.edge,e.y+8*M):(e.x+=a*oe*M,e.z+=o*oe*M),e.y>=e.edge&&Ce(e,t)?(Z(e,n.GROUND),e.vx=a*3,e.vz=o*3,e.vy=0,e.edge=0,e.wall=r.NONE,e.coyote=6,e.ev|=i.CLIMB):e.t>=40&&(Z(e,e.y>=e.edge?n.GROUND:n.AIR),e.edge=0,e.wall=r.NONE)},je=(e,t,r)=>{let[a,o]=U[e.wall],s=e.vx*a+e.vz*o,[c,l]=[e.vx-s*a,e.vz-s*o],u=H(c,l);if(r.jump)Z(e,n.AIR),e.vx=c-a*5,e.vz=l-o*5,Q(e,ne),e.jumps=1,e.dashes=1,e.ev|=i.WALLRUN_END;else{let s=xe(e,t,e.wall);if(s===void 0||!r.fwd||u<3.5||e.t>=60){Z(e,n.AIR),e.ev|=i.WALLRUN_END;return}let d=Math.max(0,u-S*M)/u;e.vx=c*d,e.vz=l*d;let f=Math.min(s,4*M);e.x+=a*f,e.z+=o*f}},Me=(e,t,r)=>{if(!r.fwd)return;let a=H(e.vx,e.vz);if(!(a<4.5))for(let r=1;r<=4;r++){let[o,s]=U[r],c=e.vx*o+e.vz*s,[l,u]=[e.vx-c*o,e.vz-c*s];if(r!==e.wall&&c<=.75*a&&c>=-.2*a&&xe(e,t,r)!==void 0){let t=H(l,u),o=Math.max(t,te*a)/t;Z(e,n.WALLRUN),e.wall=r,[e.vx,e.vz]=[l*o,u*o],e.vy=V(e.vy,2,3),e.jumps=1,e.dashes=1,e.coyote=0,e.ev|=i.WALLRUN_START;return}}},Ne=(e,t)=>{Z(e,n.HANG),e.wall=t.side,e.edge=z(t.top),t.side<=r.WEST?e.x=t.hang:e.z=t.hang,e.vx=e.vy=e.vz=0,e.jumps=1,e.dashes=1,e.coyote=0,e.buffer=0,e.ev|=i.GRAB},Pe=(e,a,o)=>{let s=e.mode===n.GROUND;if(o.dash&&e.dash===0&&(s||(e.mode===n.AIR||e.mode===n.WALLRUN)&&e.dashes>0)){let[t,r]=o.wx||o.wz?[o.wx,o.wz]:[o.fx,o.fz];s||(e.dashes--,e.vy=0,e.mode===n.WALLRUN&&(Z(e,n.AIR),e.ev|=i.WALLRUN_END)),e.vx=t*16,e.vz=r*16,e.dash=60,e.ev|=i.DASH}let c=e.dash>50;e.mode===n.WALLRUN&&je(e,a,o),G(e.mode)&&Fe(e,a,o,c),e.mode===n.AIR&&Ie(e,a,o,c);let l=c&&e.vy<=0?0:e.mode===n.WALLRUN?ee:1,u=e.mode,d=Oe(e,a,_e(e),l,G(u));if(d>=0){if(!G(e.mode)){if(e.ev|=i.LAND|(e.mode===n.WALLRUN?i.WALLRUN_END:0),e.fall=d,e.jumps=1,e.dashes=1,e.wall=r.NONE,o.keys&t.CROUCH){let t=H(e.vx,e.vz)>=x;Z(e,t?n.SLIDE:n.CROUCH),e.ev|=t?i.SLIDE_START:0}else Z(e,n.GROUND)}e.coyote=6}else G(e.mode)&&(e.ev|=e.mode===n.SLIDE?i.SLIDE_END:0,Z(e,n.AIR));if(e.mode===n.AIR){let t=Se(e,a);t?Ne(e,t):Me(e,a,o)}},Fe=(e,r,a,o)=>{let s=(a.keys&t.CROUCH)!==0;if(e.buffer>0&&(e.mode===n.GROUND||Y(e,r))){e.ev|=e.mode===n.SLIDE?i.SLIDE_END:0,Z(e,n.AIR),Q(e,7);return}let c=H(e.vx,e.vz);if(e.mode===n.GROUND&&s){let t=c>=x;Z(e,t?n.SLIDE:n.CROUCH),e.ev|=t?i.SLIDE_START:0}else e.mode===n.SLIDE&&(e.t>=60||c<4.5)?(e.ev|=i.SLIDE_END,Z(e,!s&&Y(e,r)?n.GROUND:n.CROUCH)):e.mode===n.SLIDE&&!s&&Y(e,r)?(e.ev|=i.SLIDE_END,Z(e,n.GROUND)):e.mode===n.CROUCH&&!s&&Y(e,r)&&Z(e,n.GROUND);if(!o){if(e.mode===n.SLIDE){let t=Math.max(0,c-4*M)/c;e.vx*=t,e.vz*=t}else if(e.mode===n.CROUCH)De(e,Ee(e,r,a,b),3);else{let n=(a.keys&t.SPRINT)!==0&&a.fwd;De(e,Ee(e,r,a,v),n?9:6)}}},Ie=(e,t,n,r)=>{if(e.buffer>0&&(e.coyote>0?Q(e,7):e.jumps>0&&!we(e,t)&&(e.jumps--,Q(e,6),e.ev=e.ev&~i.JUMP|i.DOUBLE)),r||!n.wx&&!n.wz)return;let a=H(e.vx,e.vz);e.vx+=n.wx*14*M,e.vz+=n.wz*14*M,Te(e,Math.max(a,6))},Le=(e,r,a,o=0)=>{e.yaw=L(r.yaw),e.pitch=Math.max(-y,Math.min(y,r.pitch));let s=(r.keys&t.FORWARD?1:0)-(r.keys&t.BACK?1:0),c=(r.keys&t.RIGHT?1:0)-(r.keys&t.LEFT?1:0),l=H(s,c)||1,[u,d]=R(e.yaw),f=t=>(r.keys&t)!==0&&(e.held&t)===0,p={keys:r.keys,jump:f(t.JUMP),dash:f(t.DASH),fwd:s>0,wx:(u*s-d*c)/l,wz:(d*s+u*c)/l,fx:u,fz:d},m=e.mode;if(e.ev=0,e.fall=0,p.jump&&(e.buffer=7),e.dash>0&&(e.dash--,e.dash===50&&Te(e,10)),e.mode===n.HANG&&ke(e,a,p),e.mode===n.CLIMB?Ae(e,a):e.mode!==n.HANG&&Pe(e,a,p),e.y<a.def.floor){let{yaw:t,pitch:n,id:r}=e;Object.assign(e,W(r,a,r,o),{yaw:t,pitch:n,ev:e.ev|i.RESPAWN})}e.t=e.mode===m?Math.min(255,e.t+1):e.t,e.buffer=Math.max(0,e.buffer-1),e.mode===n.AIR&&m===n.AIR&&(e.coyote=Math.max(0,e.coyote-1)),e.held=r.keys&(t.JUMP|t.DASH),e.ground=G(e.mode),e.x=z(e.x),e.y=z(e.y),e.z=z(e.z),e.vx=z(e.vx),e.vy=z(e.vy),e.vz=z(e.vz),e.edge=z(e.edge)},Re=20,ze=2,$=(e,t)=>Array.from(e).slice(0,t).join(``).trim(),Be=e=>$((typeof e==`string`?e:``).replace(/\s+/g,` `).replace(/\p{Cc}/gu,``).trim(),16),Ve=(e,t)=>{let n=e;for(let r=2;t.includes(n);r++)n=`${$(e,15-`${r}`.length)} ${r}`;return n},He=(e,t)=>{let n=setInterval(e,t);return()=>clearInterval(n)},Ue=class{peers=/* @__PURE__ */ new Map;ticks=0;history=[];world;ctf;halt;rules;rr=[0,0];constructor(e={},t=he){this.rules={...ce,...e},this.world=ue(t),this.ctf=new fe(this.world,this.rules)}get size(){return this.players().length}connect(e){this.peers.set(e,null)}receive(e,t){let n=this.peers.get(e);if(typeof t==`string`){let r=g(t);n===null&&r?.t===`join`&&this.join(e,r.name);return}let r=n&&p(t);r&&n.bank>0&&(n.bank--,Le(n.state,r,this.world,n.info.team),this.ctf.moved(n.state),n.ack=r.seq)}disconnect(e){let t=this.peers.get(e);this.peers.delete(e),t&&(this.ctf.leave(t.info.id),this.size||this.ctf.reset(),this.roster())}drop(e){let t=this.players().find(t=>t.info.id===e);return!!t&&this.ctf.drop(t.state)}tick(){let e=this.players();if(!e.length)return;let t=++this.ticks;for(let t of e)t.bank=Math.min(10,t.bank+1);let n=this.ctf.tick(e.map(e=>({id:e.info.id,team:e.info.team,state:e.state})));if(n===`end`?this.end(e):n===`start`&&this.restart(e),t%2==0){for(this.history.push({tick:t,players:e.map(e=>({...e.state}))});this.history[0].tick<t-30;)this.history.shift();let n=h({tick:t,players:e.map(e=>({...e.state,ack:e.ack})),...this.ctf.wire()});e.forEach(e=>e.conn.send(n))}}start(e=He){if(this.halt)return;let t=1e3/60,n=performance.now(),r=0;this.halt=e(()=>{let e=performance.now();r+=e-n,n=e;for(let e=0;r>=t&&e<Re;e++)this.tick(),r-=t;r%=t},t)}stop(){this.halt?.(),this.halt=void 0}rewind(e,t=0){let n=this.players().filter(t=>t.info.id!==e).map(e=>e.state),[r,i]=[this.history[0],this.history.at(-1)];if(!r||!i)return n;let a=((this.ticks-t+32768)%65536+65536)%65536-32768,o=Math.min(Math.max(this.ticks-a,r.tick),i.tick),s=0;for(;s+1<this.history.length&&this.history[s+1].tick<=o;)s++;let[c,l]=[this.history[s],this.history[s+1]??this.history[s]],u=l.tick>c.tick?(o-c.tick)/(l.tick-c.tick):0,d=(e,t)=>e+(t-e)*u;return n.map(e=>{let t=c.players.find(t=>t.id===e.id),n=l.players.find(t=>t.id===e.id);return t&&n?{...n,x:d(t.x,n.x),y:d(t.y,n.y),z:d(t.z,n.z)}:n??t??e})}place(e,t,n){let r=this.world.def.teams[t].spawns.findIndex((r,i)=>{let{x:a,z:o}=W(e,this.world,i,t);return!n.some(e=>Math.hypot(e.x-a,e.z-o)<ze)});return W(e,this.world,r<0?this.rr[t]++:r,t)}end(e){let t=this.ctf.tally().flatMap(t=>{let n=e.find(e=>e.info.id===t.id)?.info;return n?[{...t,name:n.name,team:n.team}]:[]}),n=JSON.stringify({t:`end`,score:this.ctf.score,players:t});e.forEach(e=>e.conn.send(n))}restart(e){let t=[];this.rr=[0,0];for(let n of e)n.state=this.place(n.info.id,n.info.team,t),t.push(n.state),this.ctf.place(n.info.id,n.state)}players(){return[...this.peers.values()].filter(e=>e!==null)}join(e,t){let n=this.players();if(n.length>=this.rules.maxPlayers){e.send(JSON.stringify({t:`full`}));return}let r=0;for(;n.some(e=>e.info.id===r);)r++;let i=n.filter(e=>e.info.team===0).length,a=+(i>n.length-i),o={conn:e,info:{id:r,name:Ve(Be(t)||`Player ${r}`,n.map(e=>e.info.name)),team:a,color:se[a]},state:this.place(r,a,n.map(e=>e.state)),bank:10,ack:65535};this.peers.set(e,o),this.ctf.join(r,a,o.state),this.roster()}roster(){let e=this.players(),t=e.map(e=>e.info).sort((e,t)=>e.id-t.id);e.forEach(e=>e.conn.send(JSON.stringify({t:`roster`,you:e.info.id,players:t})))}},We=(e,t)=>{let n=()=>{},r=()=>{n();let r=setInterval(e,t);n=()=>clearInterval(r)};try{let i=URL.createObjectURL(new Blob([`setInterval(()=>postMessage(0),${t})`])),a=new Worker(i);a.onmessage=e,a.onerror=r,n=()=>{a.terminate(),URL.revokeObjectURL(i)}}catch{r()}return()=>n()},Ge=(e,t)=>{let n=`tiny-fps:`+e,r=Math.random().toString(36).slice(2),i=new BroadcastChannel(n),a=new AbortController,o=globalThis.navigator?.locks,s,c,l,u,d=[],f,p=!1,m=e=>i.postMessage({from:r,...e}),h=e=>!p&&S.onmessage?.({data:e}),_={send:e=>queueMicrotask(()=>h(e))},v=()=>{let e=d.length?d:f?[f]:[];return d=[],e},y=e=>{if(p)return e();l=e,u=r,c=/* @__PURE__ */ new Map,s=new Ue(t),s.start(We),s.connect(_),v().forEach(e=>s.receive(_,e)),m({kind:`h`})};i.onmessage=({data:e})=>{if(!p){if(s&&c){let{from:t,kind:n}=e,r=c.get(t);n===`q`?m({to:t,kind:`h`}):n===`m`&&!e.to?(r||(r={send:e=>!p&&m({to:t,kind:`m`,data:e})},c.set(t,r),s.connect(r)),s.receive(r,e.data)):n===`b`&&r&&(c.delete(t),s.disconnect(r))}else e.to!==r&&e.to||(e.kind===`m`&&e.to?h(e.data):e.kind===`h`&&e.from!==u&&(u=e.from,v().forEach(e=>m({kind:`m`,data:e}))))}};let b=e=>{p||(typeof e==`string`&&g(e)?.t===`join`&&(f=e),s?s.receive(_,e):u?m({kind:`m`,data:e}):d.push(e))},x=()=>{p||(p=!0,globalThis.removeEventListener?.(`pagehide`,x),s?(s.stop(),l()):(m({kind:`b`}),a.abort()),i.close(),setTimeout(()=>S.onclose?.()))},S={binaryType:`arraybuffer`,onopen:null,onclose:null,onmessage:null,send:b,close:x};return o?o.request(n,{signal:a.signal},()=>new Promise(y)).catch(()=>{}):y(()=>{}),m({kind:`q`}),globalThis.addEventListener?.(`pagehide`,x),setTimeout(()=>!p&&S.onopen?.()),S};export{Ge as localSocket};
1
+ var e={HOME:0,CARRIED:1,DROPPED:2},t={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,SPRINT:32,DASH:64,CROUCH:128},n={GROUND:0,AIR:1,WALLRUN:2,HANG:3,CLIMB:4,SLIDE:5,CROUCH:6},r={NONE:0,EAST:1,WEST:2,SOUTH:3,NORTH:4},i={JUMP:1,DOUBLE:2,DASH:4,LAND:8,GRAB:16,CLIMB:32,WALLRUN_START:64,WALLRUN_END:128,SLIDE_START:256,SLIDE_END:512,RESPAWN:1024},a={BRICK:0,TILE:1,LAVA:2,STONE:3,METAL:4,WOOD:5,MOSS:6,GRATE:7,CONCRETE:8,GLASS:9,STEEL:10,PAINT:11},o=16,s=65536/(2*Math.PI),c=e=>Math.round(e*s)&65535,l=e=>Math.max(-32768,Math.min(32767,Math.round(e))),u=e=>l(e*1e4),d=e=>e/1e4,f=e=>e/s,p=e=>{if(e.byteLength!==11)return null;let t=new DataView(e);return t.getUint8(0)===1?{seq:t.getUint16(1),keys:t.getUint8(3),yaw:f(t.getUint16(4)),pitch:d(t.getInt16(6)),view:(t.getUint16(8)*256+t.getUint8(10))/256}:null},m=t=>t===e.CARRIED?2:t===e.DROPPED?8:1,h=n=>{let r=4+40*n.players.length,i=new DataView(new ArrayBuffer(r+4+n.flags.reduce((e,t)=>e+m(t.state),0)));i.setUint8(0,2),i.setUint16(1,n.tick&65535),i.setUint8(3,n.players.length),n.players.forEach((e,n)=>{let r=4+n*40;i.setUint8(r,e.id),i.setFloat32(r+1,e.x),i.setFloat32(r+5,e.y),i.setFloat32(r+9,e.z),i.setFloat32(r+13,e.vx),i.setFloat32(r+17,e.vy),i.setFloat32(r+21,e.vz),i.setFloat32(r+25,e.edge),i.setUint16(r+29,c(e.yaw)),i.setInt16(r+31,u(e.pitch)),i.setUint16(r+33,e.ack&65535),i.setUint8(r+35,e.mode&7|(e.wall&7)<<3|(e.jumps&1)<<6|e.dashes<<7),i.setUint8(r+36,e.t),i.setUint8(r+37,e.dash|(e.by>>2&3)<<6),i.setUint8(r+38,e.coyote&7|(e.buffer&7)<<3|(e.held&t.JUMP?64:0)|(e.held&t.DASH?128:0)),i.setUint8(r+39,e.stun|(e.by&3)<<6)}),i.setUint8(r,n.score[0]),i.setUint8(r+1,n.score[1]),i.setUint16(r+2,n.clock&32767|(n.over?32768:0));let a=r+4;for(let t of n.flags)i.setUint8(a,t.state),t.state===e.CARRIED?i.setUint8(a+1,t.by):t.state===e.DROPPED&&(i.setInt16(a+1,l(t.x*o)),i.setInt16(a+3,l(t.y*o)),i.setInt16(a+5,l(t.z*o)),i.setUint8(a+7,Math.min(255,t.left))),a+=m(t.state);return i.buffer},g=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},_=.4,v=1.8,y=1.55,b=.9,x=7.5,S=1.5,ee=.15,te=.5,ne=.9,re=6.5,ie=.2,ae=.03,oe=.2,se=5.5,ce=2.5,le=[`#ff3d4f`,`#2f80ff`],ue={maxPlayers:16,scoreLimit:3,timeLimit:480},de=4,C=1024,w=(e,t)=>(e+C)*(2*C)+t+C,T=(e,t)=>Math.min(Math.max(Math.floor(e/t),-1024),1023),fe=(e,t=de)=>{let n=/* @__PURE__ */ new Map;return e.brushes.forEach(({min:e,max:r},i)=>{for(let a=T(e[0],t);a<=T(r[0],t);a++)for(let o=T(e[2],t);o<=T(r[2],t);o++){let e=w(a,o),t=n.get(e);t?t.push(i):n.set(e,[i])}}),{def:e,cell:t,grid:n}},E=(e,t,n,r)=>{let i=[];for(let a=T(t-r,e.cell);a<=T(t+r,e.cell);a++)for(let t=T(n-r,e.cell);t<=T(n+r,e.cell);t++)for(let n of e.grid.get(w(a,t))??[])i.includes(n)||i.push(n);return i},pe=(e,t,n,r)=>{let{cell:i,def:a}=e,o=r,s=T(t[0],i),c=T(t[2],i),l=Math.sign(n[0]),u=Math.sign(n[2]),d=l?((s+ +(l>0))*i-t[0])/n[0]:1/0,f=u?((c+ +(u>0))*i-t[2])/n[2]:1/0,p=d,m=f,h=l?i/Math.abs(n[0]):1/0,g=u?i/Math.abs(n[2]):1/0;for(;;){for(let r of e.grid.get(w(s,c))??[]){let e=a.brushes[r],[i,s]=[0,o];for(let r=0;r<3&&i<=s;r++){if(!n[r]){(t[r]<e.min[r]||t[r]>e.max[r])&&(s=-1);continue}let a=(e.min[r]-t[r])/n[r],o=(e.max[r]-t[r])/n[r];i=Math.max(i,Math.min(a,o)),s=Math.min(s,Math.max(a,o))}i<=s&&s>0&&i<o&&(o=i)}if(Math.min(p,m)>=o||Math.abs(s)>C||Math.abs(c)>C)return o;p<m?(s+=l,p+=h):(c+=u,m+=g)}},D=()=>({state:e.HOME,by:0,x:0,y:0,z:0,left:0}),O=60,me=class{score=[0,0];over=!1;flags=[D(),D()];world;rules;mates=/* @__PURE__ */ new Map;clock;back=[0,0];lock=[{id:-1,left:0},{id:-1,left:0}];constructor(e,t){this.world=e,this.rules=t,this.clock=t.timeLimit*60}join(e,t,n){this.mates.set(e,{team:t,caps:0,returns:0,ground:[n.x,n.y,n.z]})}leave(e){let t=this.carrying(e),n=this.mates.get(e);t>=0&&n&&this.dropAt(t,n.ground),this.mates.delete(e)}place(e,t){let n=this.mates.get(e);n&&(n.ground=[t.x,t.y,t.z])}moved(e){let t=this.mates.get(e.id);if(!t)return;let n=this.carrying(e.id);e.ev&i.RESPAWN&&n>=0&&this.dropAt(n,t.ground),e.ground&&(t.ground=[e.x,e.y,e.z])}drop(e){let t=this.carrying(e.id),n=this.mates.get(e.id);if(t<0||!n||this.over)return!1;let r=n.ground;if(e.ground)r=[e.x,e.y,e.z];else{let t=pe(this.world,[e.x,e.y+.05,e.z],[0,-1,0],O);t<O&&(r=[e.x,e.y+.05-t,e.z])}return this.dropAt(t,r),this.lock[t]={id:e.id,left:120},!0}carrying(t){return this.flags.findIndex(n=>n.state===e.CARRIED&&n.by===t)}winner(){let[e,t]=this.score;return e>t?0:t>e?1:-1}tally(){return[...this.mates].map(([e,t])=>({id:e,caps:t.caps,returns:t.returns}))}reset(){this.over=!1,this.score=[0,0],this.flags=[D(),D()],this.back=[0,0],this.lock.forEach(e=>e.left=0),this.clock=this.rules.timeLimit*60;for(let e of this.mates.values())e.caps=e.returns=0}wire(){return{score:[...this.score],clock:Math.ceil(this.clock/60),over:this.over,flags:this.flags.map(e=>({...e}))}}tick(t){if(this.over)return--this.clock<=0?(this.reset(),`start`):void 0;for(let t of[0,1]){let n=this.flags[t];this.lock[t].left--,n.state===e.DROPPED&&(n.left=Math.ceil(--this.back[t]/60),this.back[t]<=0&&(this.flags[t]=D()))}for(let n of[0,1]){let r=this.flags[n];if(r.state===e.CARRIED)continue;let i=r.state===e.HOME?this.world.def.teams[n].base:[r.x,r.y,r.z],a=t.filter(e=>he(e.state,i)),o=r.state===e.DROPPED?a.find(e=>e.team===n):void 0,s=a.find(e=>e.team!==n&&(e.id!==this.lock[n].id||this.lock[n].left<=0));if(o){let e=this.mates.get(o.id);e&&e.returns++,this.flags[n]=D()}else s&&(this.flags[n]={...D(),state:e.CARRIED,by:s.id})}for(let n of t){let t=this.carrying(n.id);if(t>=0&&this.flags[n.team].state===e.HOME&&he(n.state,this.world.def.teams[n.team].base)){this.score[n.team]++;let e=this.mates.get(n.id);e&&e.caps++,this.flags[t]=D()}}if(this.score.some(e=>e>=this.rules.scoreLimit)||--this.clock<=0)return this.over=!0,this.clock=600,`end`}dropAt(t,[n,r,i]){this.flags[t]={state:e.DROPPED,by:0,x:n,y:r,z:i,left:10},this.back[t]=600}},he=(e,t)=>Math.hypot(e.x-t[0],e.z-t[2])<1.5&&e.y<t[1]+2.2&&e.y+1.8>t[1],ge=-30,k=(e,t,n,r,i,o=a.CONCRETE)=>({min:[e,ge,t],max:[n,i,r],top:a.CONCRETE,side:o}),A=([e,t,n],[r,i,a],o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c}),_e={name:`Rooftops`,brushes:[k(4,57.7,24,76,10),k(4,36,24,53.5,10,a.GLASS),k(4,20,24,36,12.4),k(4,-5,24,7,12.4,a.GLASS),k(27,20,47,50,8),k(27,60,47,76,8,a.BRICK),A([9,12.2,39],[19,12.6,47],a.STEEL),...((e,t)=>[1,2,3,4,5,6].map(n=>A([12,t,e-n],[14,t+.4*n,e-n+1],a.CONCRETE)))(53,10),A([5,10,42],[5.5,14,42.5],a.STEEL),A([5,10,50],[5.5,14,50.5],a.STEEL),A([8,12.4,24],[20,12.85,24.45],a.STEEL),A([36,8,22],[37,14.5,48],a.PAINT,a.PAINT,[.15,.72,.62]),A([30,8,28],[34,10,32],a.CONCRETE),A([40,8,30],[44,10.2,34],a.PAINT,a.PAINT,[1,.3,.06]),A([28,9.2,44],[35,12,46],a.STEEL,a.PAINT,[.2,.42,1]),A([41.5,7.6,50],[42,8,60],a.STEEL),A([30,8,64],[34,9.6,68],a.PAINT,a.PAINT,[.2,.8,.3])],teams:[{base:[14,10,62.5],spawns:[[6,10,72,0],[10,10,72,0],[14,10,72,0],[18,10,72,0],[22,10,72,0],[8,10,66,0],[14,10,66,0],[20,10,66,0]]},{base:[14,12.4,2.2],spawns:[[6,12.4,-3,Math.PI],[10,12.4,-3,Math.PI],[14,12.4,-3,Math.PI],[18,12.4,-3,Math.PI],[22,12.4,-3,Math.PI],[8,12.4,.5,Math.PI],[14,12.4,.5,Math.PI],[20,12.4,.5,Math.PI]]}],floor:-25,sun:{dir:[.6,.64,.48],color:[2.6,2.3,1.8]},sky:[[.04,.2,.72],[.72,.86,.98]],fog:[.72,.86,.98,.0055]},j=1/60,M=Math.PI*2,N=1e-6,P=.01,F=.001,I=e=>(e%M+M)%M,L=e=>[-Math.sin(e),-Math.cos(e)],R=Math.fround,ve=Math.sqrt,z=(e,t,n)=>Math.min(Math.max(e,t),n),B=(e,t)=>ve(e*e+t*t),V=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],ye={vx:0,vz:0,mode:n.GROUND,t:0,wall:r.NONE,edge:0,jumps:1,dashes:1,dash:0,stun:0,coyote:6,buffer:0,held:0,ev:0,fall:0},H=(e,t,n,r=0)=>{let{spawns:i}=t.def.teams[r],[a,o,s,c]=i[(n%i.length+i.length)%i.length];return{id:e,x:R(a),y:R(o),z:R(s),vy:0,yaw:I(c),pitch:0,ground:!0,...ye}},U=e=>e===n.GROUND||e===n.SLIDE||e===n.CROUCH,W=e=>e.mode===n.SLIDE||e.mode===n.CROUCH?b:v,be=e=>B(e.vx,e.vz),G=(e,t,n)=>e.max[1]>t+.5+P&&e.min[1]<t+n-P,K=(e,t,n)=>[t-z(t,e.min[0],e.max[0]),n-z(n,e.min[2],e.max[2])],xe=(e,t,n)=>{let{brushes:r}=t.def,i=E(t,e.x,e.z,2*_),a=(_-N)**2,[o,s]=[0,0];for(let t=0;t<4;t++){let t=0,c=0,l=0;for(let o of i){let i=r[o];if(!G(i,e.y,n))continue;let[s,u]=K(i,e.x,e.z),d=s*s+u*u;if(d>=a)continue;if(d){let e=ve(d);.4-e>t&&(t=_-e,c=s/e*t,l=u/e*t);continue}let[f,p,m]=[[e.x-i.min[0],-1,0],[i.max[0]-e.x,1,0],[e.z-i.min[2],0,-1],[i.max[2]-e.z,0,1]].reduce((e,t)=>t[0]<e[0]?t:e);f+.4>t&&(t=f+_,[c,l]=[p*t,m*t])}if(!t)break;e.x+=c,e.z+=l,o+=c,s+=l}return[o,s]},q=(e,t,n)=>{let{brushes:r}=t.def,i=(_-N)**2,a=-1/0,o=1/0;for(let s of E(t,e.x,e.z,_)){let t=r[s],[c,l]=K(t,e.x,e.z);c*c+l*l>=i||(t.max[1]<=e.y+.5+P?a=Math.max(a,t.max[1]):t.min[1]>=e.y+n-P&&(o=Math.min(o,t.min[1])))}return[a,o]},J=(e,t)=>{let n=(_-N)**2;return E(t,e.x,e.z,_).every(r=>{let i=t.def.brushes[r],[a,o]=K(i,e.x,e.z);return a*a+o*o>=n||!G(i,e.y,1.8)})},Se=(e,t,n,r,i)=>{let a=(_-N)**2;return E(e,t,n,_).every(o=>{let s=e.def.brushes[o],[c,l]=K(s,t,n);return c*c+l*l>=a||s.max[1]<=r||s.min[1]>=i})},Y=(e,t)=>{let[n,r]=V[t],i=n?0:2;return{a:i,o:2-i,sign:n||r,c:n?e.x:e.z,co:n?e.z:e.x}},Ce=(e,t,n,r)=>{let{a:i,o:a,sign:o,c:s,co:c}=Y(t,n),l=((o>0?e.min[i]:e.max[i])-s)*o;return l>=.4-F&&l<=.4+r&&c>=e.min[a]&&c<=e.max[a]?l:void 0},we=(e,t,n)=>{let r;for(let i of E(t,e.x,e.z,_+te)){let a=t.def.brushes[i],o=Ce(a,e,n,te);o!==void 0&&a.min[1]<e.y+.5&&a.max[1]>e.y+1.8&&(r=Math.min(r??1/0,Math.max(0,o-_)))}return r},Te=(e,t)=>{let[n,r]=L(e.yaw),i;for(let a=1;a<=4;a++){let[o,s]=V[a];if(a===e.wall||n*o+r*s<.5)continue;let{a:c,sign:l}=Y(e,a);for(let n of E(t,e.x,e.z,_+ie)){let r=t.def.brushes[n],o=r.max[1],s=o-e.y;if(Ce(r,e,a,.2)===void 0||s<1.2||s>2.4||r.min[1]>o-.25||i&&i.top>=o)continue;let u=l>0?r.min[c]:r.max[c],d=u-l*(_+ae),f=u+l*oe,[p,m]=c===0?[d,e.z]:[e.x,d],[h,g]=c===0?[f,e.z]:[e.x,f];Se(t,p,m,Math.min(e.y,o-2)+P,o+1.8)&&Se(t,h,g,o+P,o+1.8)&&(i={side:a,top:o,hang:d})}}return i},Ee=(e,t)=>{let{a:n,o:r,sign:i,c:a,co:o}=Y(e,e.wall);return E(t,e.x,e.z,0).some(s=>{let c=t.def.brushes[s],l=i>0?a-c.min[n]:c.max[n]-a;return R(c.max[1])===e.edge&&o>=c.min[r]&&o<=c.max[r]&&l>=.2})},De=(e,t)=>{if(e.vy>=0)return!1;let[n]=q(e,t,v),r=6*j;return e.y-n<=-e.vy*r+10*r*r},X=(e,t)=>{e.mode=t,e.t=0},Oe=(e,t,r)=>{e.stun=48,e.vx=R(t*6),e.vz=R(r*6),e.dash=Math.min(e.dash,50),e.coyote=0,e.buffer=0,(e.mode===n.HANG||e.mode===n.CLIMB)&&(e.vy=0),(e.mode===n.HANG||e.mode===n.CLIMB||e.mode===n.WALLRUN)&&(X(e,n.AIR),e.edge=0)},ke=(e,t)=>{let n=B(e.vx,e.vz);n>t&&(e.vx*=t/n,e.vz*=t/n)},Z=(e,t,n,r)=>{let[i,a]=[n.wx,n.wz];for(let n of E(t,e.x,e.z,_+F)){let o=t.def.brushes[n],[s,c]=K(o,e.x,e.z),l=B(s,c);if(l>0&&l<=.4+F&&G(o,e.y,r)){let e=(-i*s-a*c)/l;e>0&&(i+=e*s/l,a+=e*c/l)}}return[i,a]},Q=(e,t,n)=>{let r=B(t[0],t[1]);if(r<N){let t=B(e.vx,e.vz),n=t?Math.max(0,t-45*j)/t:0;e.vx*=n,e.vz*=n;return}let[i,a]=[t[0]/r,t[1]/r],o=e.vx*i+e.vz*a,[s,c]=[e.vx-o*i,e.vz-o*a],l=B(s,c);if(l){let e=Math.max(0,l-45*j)/l;[s,c]=[s*e,c*e]}n*=r,o=o<n?Math.min(n,o+(o>=6?3:50)*j):Math.max(n,o-12*j),e.vx=s+o*i,e.vz=c+o*a},Ae=(e,t,n,r,i)=>{let a=e.y;e.x+=e.vx*j,e.z+=e.vz*j;let[o,s]=xe(e,t,n),c=B(o,s);if(c){let t=(e.vx*o+e.vz*s)/c;t<0&&(e.vx-=t*o/c,e.vz-=t*s/c)}let[l,u]=q(e,t,n),d=e.vy-r*20*j;if(e.y+=(e.vy+d)/2*j,e.vy=d,e.y+n>u&&(e.y=u-n,e.vy=Math.min(e.vy,0)),e.vy<=0?e.y<=l+P:e.y<l){if(e.y=l,e.vy<=0){let t=-e.vy;return e.vy=0,t}}else if(i&&e.vy<=0&&l>=a-.5)return e.y=l,e.vy=0,0;return-1},$=(e,t)=>{e.vy=t,e.coyote=0,e.buffer=0,e.ev|=i.JUMP},je=(e,r,i)=>{let[a,o]=V[e.wall],s=t=>{X(e,t),e.edge=0};if(i.keys&(t.BACK|t.CROUCH))s(n.AIR),e.coyote=0;else if(i.jump&&i.fx*a+i.fz*o<0)s(n.AIR),e.vx=-a*4,e.vz=-o*4,$(e,6);else if(i.jump||i.fwd&&e.t>=6)X(e,n.CLIMB);else if(e.t>=30)s(n.AIR),e.coyote=0;else{let t=Math.max(e.edge-2,q(e,r,v)[0]);e.y+=z(t-e.y,-8*j,8*j)}},Me=(e,t)=>{let[a,o]=V[e.wall];e.y<e.edge?e.y=Math.min(e.edge,e.y+8*j):(e.x+=a*se*j,e.z+=o*se*j),e.y>=e.edge&&Ee(e,t)?(X(e,n.GROUND),e.vx=a*3,e.vz=o*3,e.vy=0,e.edge=0,e.wall=r.NONE,e.coyote=6,e.ev|=i.CLIMB):e.t>=40&&(X(e,e.y>=e.edge?n.GROUND:n.AIR),e.edge=0,e.wall=r.NONE)},Ne=(e,t,r)=>{let[a,o]=V[e.wall],s=e.vx*a+e.vz*o,[c,l]=[e.vx-s*a,e.vz-s*o],u=B(c,l);if(r.jump)X(e,n.AIR),e.vx=c-a*5,e.vz=l-o*5,$(e,re),e.jumps=1,e.dashes=1,e.ev|=i.WALLRUN_END;else{let s=we(e,t,e.wall);if(s===void 0||!r.fwd||u<3.5||e.t>=60){X(e,n.AIR),e.ev|=i.WALLRUN_END;return}let d=Math.max(0,u-S*j)/u;e.vx=c*d,e.vz=l*d;let f=Math.min(s,4*j);e.x+=a*f,e.z+=o*f}},Pe=(e,t,r)=>{if(!r.fwd)return;let a=B(e.vx,e.vz);if(!(a<4.5))for(let r=1;r<=4;r++){let[o,s]=V[r],c=e.vx*o+e.vz*s,[l,u]=[e.vx-c*o,e.vz-c*s];if(r!==e.wall&&c<=.75*a&&c>=-.2*a&&we(e,t,r)!==void 0){let t=B(l,u),o=Math.max(t,ne*a)/t;X(e,n.WALLRUN),e.wall=r,[e.vx,e.vz]=[l*o,u*o],e.vy=z(e.vy,2,3),e.jumps=1,e.dashes=1,e.coyote=0,e.ev|=i.WALLRUN_START;return}}},Fe=(e,t)=>{X(e,n.HANG),e.wall=t.side,e.edge=R(t.top),t.side<=r.WEST?e.x=t.hang:e.z=t.hang,e.vx=e.vy=e.vz=0,e.jumps=1,e.dashes=1,e.coyote=0,e.buffer=0,e.ev|=i.GRAB},Ie=(e,a,o)=>{let s=e.mode===n.GROUND;if(o.dash&&e.dash===0&&(s||(e.mode===n.AIR||e.mode===n.WALLRUN)&&e.dashes>0)){let[t,r]=o.wx||o.wz?[o.wx,o.wz]:[o.fx,o.fz];s||(e.dashes--,e.vy=0,e.mode===n.WALLRUN&&(X(e,n.AIR),e.ev|=i.WALLRUN_END)),e.vx=t*16,e.vz=r*16,e.dash=60,e.ev|=i.DASH}let c=e.dash>50;e.mode===n.WALLRUN&&Ne(e,a,o),U(e.mode)&&Le(e,a,o,c),e.mode===n.AIR&&Re(e,a,o,c);let l=c&&e.vy<=0?0:e.mode===n.WALLRUN?ee:1,u=e.mode,d=Ae(e,a,W(e),l,U(u));if(d>=0){if(!U(e.mode)){if(e.ev|=i.LAND|(e.mode===n.WALLRUN?i.WALLRUN_END:0),e.fall=d,e.jumps=1,e.dashes=1,e.wall=r.NONE,o.keys&t.CROUCH){let t=B(e.vx,e.vz)>=x;X(e,t?n.SLIDE:n.CROUCH),e.ev|=t?i.SLIDE_START:0}else X(e,n.GROUND)}e.coyote=6}else U(e.mode)&&(e.ev|=e.mode===n.SLIDE?i.SLIDE_END:0,X(e,n.AIR));if(e.mode===n.AIR){let t=Te(e,a);t?Fe(e,t):Pe(e,a,o)}},Le=(e,r,a,o)=>{let s=(a.keys&t.CROUCH)!==0;if(e.buffer>0&&(e.mode===n.GROUND||J(e,r))){e.ev|=e.mode===n.SLIDE?i.SLIDE_END:0,X(e,n.AIR),$(e,7);return}let c=B(e.vx,e.vz);if(e.mode===n.GROUND&&s){let t=c>=x;X(e,t?n.SLIDE:n.CROUCH),e.ev|=t?i.SLIDE_START:0}else e.mode===n.SLIDE&&(e.t>=60||c<4.5||a.stumble)?(e.ev|=i.SLIDE_END,X(e,!s&&J(e,r)?n.GROUND:n.CROUCH)):e.mode===n.SLIDE&&!s&&J(e,r)?(e.ev|=i.SLIDE_END,X(e,n.GROUND)):e.mode===n.CROUCH&&!s&&J(e,r)&&X(e,n.GROUND);if(!o){if(a.stumble){if(c>2.5){let t=Math.max(ce,c-12*j)/c;e.vx*=t,e.vz*=t}else Q(e,Z(e,r,a,W(e)),ce)}else if(e.mode===n.SLIDE){let t=Math.max(0,c-4*j)/c;e.vx*=t,e.vz*=t}else if(e.mode===n.CROUCH)Q(e,Z(e,r,a,b),3);else{let n=(a.keys&t.SPRINT)!==0&&a.fwd;Q(e,Z(e,r,a,v),n?9:6)}}},Re=(e,t,n,r)=>{if(e.buffer>0&&(e.coyote>0?$(e,7):e.jumps>0&&!De(e,t)&&(e.jumps--,$(e,6),e.ev=e.ev&~i.JUMP|i.DOUBLE)),r||!n.wx&&!n.wz)return;let a=B(e.vx,e.vz);e.vx+=n.wx*14*j,e.vz+=n.wz*14*j,ke(e,Math.max(a,6))},ze=(e,r,a,o=0)=>{e.yaw=I(r.yaw),e.pitch=Math.max(-y,Math.min(y,r.pitch));let s=(r.keys&t.FORWARD?1:0)-(r.keys&t.BACK?1:0),c=(r.keys&t.RIGHT?1:0)-(r.keys&t.LEFT?1:0),l=B(s,c)||1,[u,d]=L(e.yaw),f=t=>(r.keys&t)!==0&&(e.held&t)===0,p=e.stun>0,m={keys:r.keys,stumble:p,jump:!p&&f(t.JUMP),dash:!p&&f(t.DASH),fwd:s>0,wx:(u*s-d*c)/l,wz:(d*s+u*c)/l,fx:u,fz:d},h=e.mode;if(e.ev=0,e.fall=0,m.jump&&(e.buffer=7),p&&e.stun--,e.dash>0&&(e.dash--,e.dash===50&&ke(e,10)),e.mode===n.HANG&&je(e,a,m),e.mode===n.CLIMB?Me(e,a):e.mode!==n.HANG&&Ie(e,a,m),e.y<a.def.floor){let{yaw:t,pitch:n,id:r}=e;Object.assign(e,H(r,a,r,o),{yaw:t,pitch:n,ev:e.ev|i.RESPAWN})}e.t=e.mode===h?Math.min(255,e.t+1):e.t,e.buffer=Math.max(0,e.buffer-1),e.mode===n.AIR&&h===n.AIR&&(e.coyote=Math.max(0,e.coyote-1)),e.held=r.keys&(t.JUMP|t.DASH),e.ground=U(e.mode),e.x=R(e.x),e.y=R(e.y),e.z=R(e.z),e.vx=R(e.vx),e.vy=R(e.vy),e.vz=R(e.vz),e.edge=R(e.edge)},Be=e=>e.mode===n.SLIDE||e.dash>50,Ve=(e,t)=>Math.hypot(e.x-t.x,e.z-t.z)<1.1&&e.y<t.y+W(t)&&t.y<e.y+W(e),He=20,Ue=2,We=(e,t)=>Array.from(e).slice(0,t).join(``).trim(),Ge=e=>We((typeof e==`string`?e:``).replace(/\s+/g,` `).replace(/\p{Cc}/gu,``).trim(),16),Ke=(e,t)=>{let n=e;for(let r=2;t.includes(n);r++)n=`${We(e,15-`${r}`.length)} ${r}`;return n},qe=(e,t)=>{let n=setInterval(e,t);return()=>clearInterval(n)},Je=class{peers=/* @__PURE__ */ new Map;ticks=0;history=[];world;ctf;halt;rules;rr=[0,0];constructor(e={},t=_e){this.rules={...ue,...e},this.world=fe(t),this.ctf=new me(this.world,this.rules)}get size(){return this.players().length}connect(e){this.peers.set(e,null)}receive(e,t){let n=this.peers.get(e);if(typeof t==`string`){let r=g(t);n===null&&r?.t===`join`&&this.join(e,r.name);return}let r=n&&p(t);r&&n.bank>0&&(n.bank--,ze(n.state,r,this.world,n.info.team),this.ctf.moved(n.state),this.tackle(n,r.view),n.ack=r.seq)}disconnect(e){let t=this.peers.get(e);this.peers.delete(e),t&&(this.ctf.leave(t.info.id),this.size||this.ctf.reset(),this.roster())}drop(e){let t=this.players().find(t=>t.info.id===e);return!!t&&this.ctf.drop(t.state)}tick(){let e=this.players();if(!e.length)return;let t=++this.ticks;for(let t of e)t.bank=Math.min(10,t.bank+1);let n=this.ctf.tick(e.map(e=>({id:e.info.id,team:e.info.team,state:e.state})));if(n===`end`?this.end(e):n===`start`&&this.restart(e),t%2==0){for(this.history.push({tick:t,players:e.map(e=>({...e.state}))});this.history[0].tick<t-30;)this.history.shift();let n=h({tick:t,players:e.map(e=>({...e.state,ack:e.ack,by:e.state.stun?e.by:0})),...this.ctf.wire()});e.forEach(e=>e.conn.send(n))}}start(e=qe){if(this.halt)return;let t=1e3/60,n=performance.now(),r=0;this.halt=e(()=>{let e=performance.now();r+=e-n,n=e;for(let e=0;r>=t&&e<He;e++)this.tick(),r-=t;r%=t},t)}stop(){this.halt?.(),this.halt=void 0}rewind(e,t=0){let n=this.players().filter(t=>t.info.id!==e).map(e=>e.state),[r,i]=[this.history[0],this.history.at(-1)];if(!r||!i)return n;let a=((this.ticks-t+32768)%65536+65536)%65536-32768,o=Math.min(Math.max(this.ticks-a,r.tick),i.tick),s=0;for(;s+1<this.history.length&&this.history[s+1].tick<=o;)s++;let[c,l]=[this.history[s],this.history[s+1]??this.history[s]],u=l.tick>c.tick?(o-c.tick)/(l.tick-c.tick):0,d=(e,t)=>e+(t-e)*u;return n.map(e=>{let t=c.players.find(t=>t.id===e.id),n=l.players.find(t=>t.id===e.id);return t&&n?{...n,x:d(t.x,n.x),y:d(t.y,n.y),z:d(t.z,n.z)}:n??t??e})}tackle(e,t){let n=e.state;if(!Be(n)||this.ticks-e.tackled<30)return;let r=this.players().filter(t=>t.info.team!==e.info.team),i=this.rewind(e.info.id,t).find(e=>Ve(n,e)&&r.some(t=>t.info.id===e.id&&this.ctf.carrying(t.info.id)>=0)),a=r.find(e=>e.info.id===i?.id);if(!a||!this.drop(a.info.id))return;let o=be(n),[s,c]=o>.001?[n.vx/o,n.vz/o]:L(n.yaw);Oe(a.state,s,c),a.by=e.info.id,e.tackled=this.ticks}place(e,t,n){let r=this.world.def.teams[t].spawns.findIndex((r,i)=>{let{x:a,z:o}=H(e,this.world,i,t);return!n.some(e=>Math.hypot(e.x-a,e.z-o)<Ue)});return H(e,this.world,r<0?this.rr[t]++:r,t)}end(e){let t=this.ctf.tally().flatMap(t=>{let n=e.find(e=>e.info.id===t.id)?.info;return n?[{...t,name:n.name,team:n.team}]:[]}),n=JSON.stringify({t:`end`,score:this.ctf.score,players:t});e.forEach(e=>e.conn.send(n))}restart(e){let t=[];this.rr=[0,0];for(let n of e)n.state=this.place(n.info.id,n.info.team,t),t.push(n.state),this.ctf.place(n.info.id,n.state)}players(){return[...this.peers.values()].filter(e=>e!==null)}join(e,t){let n=this.players();if(n.length>=this.rules.maxPlayers){e.send(JSON.stringify({t:`full`}));return}let r=0;for(;n.some(e=>e.info.id===r);)r++;let i=n.filter(e=>e.info.team===0).length,a=+(i>n.length-i),o={conn:e,info:{id:r,name:Ke(Ge(t)||`Player ${r}`,n.map(e=>e.info.name)),team:a,color:le[a]},state:this.place(r,a,n.map(e=>e.state)),bank:10,ack:65535,by:0,tackled:-30};this.peers.set(e,o),this.ctf.join(r,a,o.state),this.roster()}roster(){let e=this.players(),t=e.map(e=>e.info).sort((e,t)=>e.id-t.id);e.forEach(e=>e.conn.send(JSON.stringify({t:`roster`,you:e.info.id,players:t})))}},Ye=(e,t)=>{let n=()=>{},r=()=>{n();let r=setInterval(e,t);n=()=>clearInterval(r)};try{let i=URL.createObjectURL(new Blob([`setInterval(()=>postMessage(0),${t})`])),a=new Worker(i);a.onmessage=e,a.onerror=r,n=()=>{a.terminate(),URL.revokeObjectURL(i)}}catch{r()}return()=>n()},Xe=(e,t)=>{let n=`tiny-fps:`+e,r=Math.random().toString(36).slice(2),i=new BroadcastChannel(n),a=new AbortController,o=globalThis.navigator?.locks,s,c,l,u,d=[],f,p=!1,m=e=>i.postMessage({from:r,...e}),h=e=>!p&&S.onmessage?.({data:e}),_={send:e=>queueMicrotask(()=>h(e))},v=()=>{let e=d.length?d:f?[f]:[];return d=[],e},y=e=>{if(p)return e();l=e,u=r,c=/* @__PURE__ */ new Map,s=new Je(t),s.start(Ye),s.connect(_),v().forEach(e=>s.receive(_,e)),m({kind:`h`})};i.onmessage=({data:e})=>{if(!p){if(s&&c){let{from:t,kind:n}=e,r=c.get(t);n===`q`?m({to:t,kind:`h`}):n===`m`&&!e.to?(r||(r={send:e=>!p&&m({to:t,kind:`m`,data:e})},c.set(t,r),s.connect(r)),s.receive(r,e.data)):n===`b`&&r&&(c.delete(t),s.disconnect(r))}else e.to!==r&&e.to||(e.kind===`m`&&e.to?h(e.data):e.kind===`h`&&e.from!==u&&(u=e.from,v().forEach(e=>m({kind:`m`,data:e}))))}};let b=e=>{p||(typeof e==`string`&&g(e)?.t===`join`&&(f=e),s?s.receive(_,e):u?m({kind:`m`,data:e}):d.push(e))},x=()=>{p||(p=!0,globalThis.removeEventListener?.(`pagehide`,x),s?(s.stop(),l()):(m({kind:`b`}),a.abort()),i.close(),setTimeout(()=>S.onclose?.()))},S={binaryType:`arraybuffer`,onopen:null,onclose:null,onmessage:null,send:b,close:x};return o?o.request(n,{signal:a.signal},()=>new Promise(y)).catch(()=>{}):y(()=>{}),m({kind:`q`}),globalThis.addEventListener?.(`pagehide`,x),setTimeout(()=>!p&&S.onopen?.()),S};export{Xe as localSocket};
package/dist/server.js CHANGED
@@ -25,6 +25,7 @@ var GRAB_REACH = .2;
25
25
  var GRAB_GAP = .03;
26
26
  var CLIMB_INSET = .2;
27
27
  var CLIMB_FWD_SPEED = 5.5;
28
+ var STUMBLE_SPEED = 2.5;
28
29
  var TEAM_COLOR = ["#ff3d4f", "#2f80ff"];
29
30
  var RULES = {
30
31
  maxPlayers: 16,
@@ -111,7 +112,15 @@ var TEX = {
111
112
  /** Stone blocks with moss in the joints. */
112
113
  MOSS: 6,
113
114
  /** Metal floor grating over darkness. */
114
- GRATE: 7
115
+ GRATE: 7,
116
+ /** White precast concrete in 1 m panels: the roofs and walls. */
117
+ CONCRETE: 8,
118
+ /** Dark blue glass in steel frames; the shader adds the sky's reflection. */
119
+ GLASS: 9,
120
+ /** Brushed steel. */
121
+ STEEL: 10,
122
+ /** A near white painted panel: the brush tint is its colour. */
123
+ PAINT: 11
115
124
  };
116
125
  // src/shared/world.ts
117
126
  /** Metres per grid cell: about the size of the player's reach, so a query touches 1 to 4 cells. */
@@ -425,8 +434,8 @@ var touches = (p, at) => Math.hypot(p.x - at[0], p.z - at[2]) < 1.5 && p.y < at[
425
434
  // src/shared/map.ts
426
435
  /** The bottom of every building: far below the kill floor, so nothing shows beneath a roof. */
427
436
  var BASE = -30;
428
- /** A building: the footprint x0..x1 by z0..z1 from the street up to a flat roof at `top`. */
429
- var roof = (x0, z0, x1, z1, top) => ({
437
+ /** A building: the footprint x0..x1 by z0..z1 from the street up to a flat roof at `top`, white concrete over a facade. */
438
+ var roof = (x0, z0, x1, z1, top, side = TEX.CONCRETE) => ({
430
439
  min: [
431
440
  x0,
432
441
  BASE,
@@ -437,8 +446,8 @@ var roof = (x0, z0, x1, z1, top) => ({
437
446
  top,
438
447
  z1
439
448
  ],
440
- top: TEX.TILE,
441
- side: TEX.BRICK
449
+ top: TEX.CONCRETE,
450
+ side
442
451
  });
443
452
  /** Any box, corners (x0, y0, z0) and (x1, y1, z1). */
444
453
  var box = ([x0, y0, z0], [x1, y1, z1], top, side = top, tint) => ({
@@ -472,7 +481,7 @@ var stair = (z, y) => [
472
481
  14,
473
482
  y + .4 * k,
474
483
  z - k + 1
475
- ], TEX.STONE, TEX.STONE));
484
+ ], TEX.CONCRETE));
476
485
  /**
477
486
  * A parkour test course, laid out for the moves of step 3 and flown with them by test/lines.ts.
478
487
  * Metres, y up, the course runs north (toward -z). A walking jump flies about 4.2 m on the flat, a
@@ -496,11 +505,11 @@ var ROOFTOPS = {
496
505
  name: "Rooftops",
497
506
  brushes: [
498
507
  roof(4, 57.7, 24, 76, 10),
499
- roof(4, 36, 24, 53.5, 10),
508
+ roof(4, 36, 24, 53.5, 10, TEX.GLASS),
500
509
  roof(4, 20, 24, 36, 12.4),
501
- roof(4, -5, 24, 7, 12.4),
510
+ roof(4, -5, 24, 7, 12.4, TEX.GLASS),
502
511
  roof(27, 20, 47, 50, 8),
503
- roof(27, 60, 47, 76, 8),
512
+ roof(27, 60, 47, 76, 8, TEX.BRICK),
504
513
  box([
505
514
  9,
506
515
  12.2,
@@ -509,7 +518,7 @@ var ROOFTOPS = {
509
518
  19,
510
519
  12.6,
511
520
  47
512
- ], TEX.METAL, TEX.METAL),
521
+ ], TEX.STEEL),
513
522
  ...stair(53, 10),
514
523
  box([
515
524
  5,
@@ -519,7 +528,7 @@ var ROOFTOPS = {
519
528
  5.5,
520
529
  14,
521
530
  42.5
522
- ], TEX.METAL),
531
+ ], TEX.STEEL),
523
532
  box([
524
533
  5,
525
534
  10,
@@ -528,7 +537,7 @@ var ROOFTOPS = {
528
537
  5.5,
529
538
  14,
530
539
  50.5
531
- ], TEX.METAL),
540
+ ], TEX.STEEL),
532
541
  box([
533
542
  8,
534
543
  12.4,
@@ -537,7 +546,7 @@ var ROOFTOPS = {
537
546
  20,
538
547
  12.85,
539
548
  24.45
540
- ], TEX.METAL),
549
+ ], TEX.STEEL),
541
550
  box([
542
551
  36,
543
552
  8,
@@ -546,9 +555,9 @@ var ROOFTOPS = {
546
555
  37,
547
556
  14.5,
548
557
  48
549
- ], TEX.STONE, TEX.STONE, [
550
- 1,
551
- .75,
558
+ ], TEX.PAINT, TEX.PAINT, [
559
+ .15,
560
+ .72,
552
561
  .62
553
562
  ]),
554
563
  box([
@@ -559,7 +568,7 @@ var ROOFTOPS = {
559
568
  34,
560
569
  10,
561
570
  32
562
- ], TEX.STONE, TEX.BRICK),
571
+ ], TEX.CONCRETE),
563
572
  box([
564
573
  40,
565
574
  8,
@@ -568,7 +577,11 @@ var ROOFTOPS = {
568
577
  44,
569
578
  10.2,
570
579
  34
571
- ], TEX.STONE, TEX.BRICK),
580
+ ], TEX.PAINT, TEX.PAINT, [
581
+ 1,
582
+ .3,
583
+ .06
584
+ ]),
572
585
  box([
573
586
  28,
574
587
  9.2,
@@ -577,9 +590,9 @@ var ROOFTOPS = {
577
590
  35,
578
591
  12,
579
592
  46
580
- ], TEX.METAL, TEX.GRATE, [
581
- .8,
582
- .9,
593
+ ], TEX.STEEL, TEX.PAINT, [
594
+ .2,
595
+ .42,
583
596
  1
584
597
  ]),
585
598
  box([
@@ -590,7 +603,7 @@ var ROOFTOPS = {
590
603
  42,
591
604
  8,
592
605
  60
593
- ], TEX.METAL),
606
+ ], TEX.STEEL),
594
607
  box([
595
608
  30,
596
609
  8,
@@ -599,7 +612,11 @@ var ROOFTOPS = {
599
612
  34,
600
613
  9.6,
601
614
  68
602
- ], TEX.STONE, TEX.BRICK)
615
+ ], TEX.PAINT, TEX.PAINT, [
616
+ .2,
617
+ .8,
618
+ .3
619
+ ])
603
620
  ],
604
621
  teams: [{
605
622
  base: [
@@ -722,25 +739,25 @@ var ROOFTOPS = {
722
739
  .48
723
740
  ],
724
741
  color: [
725
- 3,
726
- 2.7,
727
- 2.2
742
+ 2.6,
743
+ 2.3,
744
+ 1.8
728
745
  ]
729
746
  },
730
747
  sky: [[
731
- .12,
732
- .3,
733
- .75
748
+ .04,
749
+ .2,
750
+ .72
734
751
  ], [
735
- .7,
736
- .82,
737
- .95
752
+ .72,
753
+ .86,
754
+ .98
738
755
  ]],
739
756
  fog: [
740
- .7,
741
- .82,
742
- .95,
743
- .008
757
+ .72,
758
+ .86,
759
+ .98,
760
+ .0055
744
761
  ]
745
762
  };
746
763
  // src/shared/physics.ts
@@ -787,6 +804,7 @@ var STILL = {
787
804
  jumps: 1,
788
805
  dashes: 1,
789
806
  dash: 0,
807
+ stun: 0,
790
808
  coyote: 6,
791
809
  buffer: 0,
792
810
  held: 0,
@@ -813,6 +831,8 @@ var spawn = (id, w, n, team = 0) => {
813
831
  var onFloor = (m) => m === MODE.GROUND || m === MODE.SLIDE || m === MODE.CROUCH;
814
832
  /** The height of the cylinder in this mode. */
815
833
  var heightOf = (p) => p.mode === MODE.SLIDE || p.mode === MODE.CROUCH ? LOW_H : PLAYER_H;
834
+ /** Horizontal speed, m/s. */
835
+ var speedOf = (p) => len(p.vx, p.vz);
816
836
  /** Whether the brush stops a body of height h whose feet are at y when it walks sideways into it. */
817
837
  var blocks = (b, y, h) => b.max[1] > y + .5 + SKIN && b.min[1] < y + h - SKIN;
818
838
  /** The closest point of the brush footprint to (x, z), as the offset from it to (x, z). */
@@ -1022,6 +1042,24 @@ var enter = (p, mode) => {
1022
1042
  p.mode = mode;
1023
1043
  p.t = 0;
1024
1044
  };
1045
+ /**
1046
+ * A tackle lands on the player: he stumbles for STUMBLE_TICKS and is thrown STUMBLE_KNOCK m/s along
1047
+ * (dx, dz), a unit vector (the tackler's way). It ends a dash, a wall-run, a hang and a climb, and
1048
+ * clears a jump press and the coyote window. For the host to call between two steps.
1049
+ */
1050
+ var stumble = (p, dx, dz) => {
1051
+ p.stun = 48;
1052
+ p.vx = f32(dx * 6);
1053
+ p.vz = f32(dz * 6);
1054
+ p.dash = Math.min(p.dash, 50);
1055
+ p.coyote = 0;
1056
+ p.buffer = 0;
1057
+ if (p.mode === MODE.HANG || p.mode === MODE.CLIMB) p.vy = 0;
1058
+ if (p.mode === MODE.HANG || p.mode === MODE.CLIMB || p.mode === MODE.WALLRUN) {
1059
+ enter(p, MODE.AIR);
1060
+ p.edge = 0;
1061
+ }
1062
+ };
1025
1063
  /** Scales the horizontal speed to at most max. */
1026
1064
  var cap = (p, max) => {
1027
1065
  const s = len(p.vx, p.vz);
@@ -1308,7 +1346,7 @@ var onGround = (p, w, c, burst) => {
1308
1346
  const slide = speed >= SLIDE_MIN_SPEED;
1309
1347
  enter(p, slide ? MODE.SLIDE : MODE.CROUCH);
1310
1348
  p.ev |= slide ? EV.SLIDE_START : 0;
1311
- } else if (p.mode === MODE.SLIDE && (p.t >= 60 || speed < 4.5)) {
1349
+ } else if (p.mode === MODE.SLIDE && (p.t >= 60 || speed < 4.5 || c.stumble)) {
1312
1350
  p.ev |= EV.SLIDE_END;
1313
1351
  enter(p, !low && canStand(p, w) ? MODE.GROUND : MODE.CROUCH);
1314
1352
  } else if (p.mode === MODE.SLIDE && !low && canStand(p, w)) {
@@ -1316,7 +1354,13 @@ var onGround = (p, w, c, burst) => {
1316
1354
  enter(p, MODE.GROUND);
1317
1355
  } else if (p.mode === MODE.CROUCH && !low && canStand(p, w)) enter(p, MODE.GROUND);
1318
1356
  if (burst) return;
1319
- if (p.mode === MODE.SLIDE) {
1357
+ if (c.stumble) {
1358
+ if (speed > 2.5) {
1359
+ const k = Math.max(STUMBLE_SPEED, speed - 12 * DT) / speed;
1360
+ p.vx *= k;
1361
+ p.vz *= k;
1362
+ } else steer(p, unwalled(p, w, c, heightOf(p)), STUMBLE_SPEED);
1363
+ } else if (p.mode === MODE.SLIDE) {
1320
1364
  const k = Math.max(0, speed - 4 * DT) / speed;
1321
1365
  p.vx *= k;
1322
1366
  p.vz *= k;
@@ -1355,10 +1399,12 @@ var move = (p, i, w, team = 0) => {
1355
1399
  const n = len(f, s) || 1;
1356
1400
  const [fx, fz] = forward(p.yaw);
1357
1401
  const pressed = (bit) => (i.keys & bit) !== 0 && (p.held & bit) === 0;
1402
+ const stumbling = p.stun > 0;
1358
1403
  const c = {
1359
1404
  keys: i.keys,
1360
- jump: pressed(KEY.JUMP),
1361
- dash: pressed(KEY.DASH),
1405
+ stumble: stumbling,
1406
+ jump: !stumbling && pressed(KEY.JUMP),
1407
+ dash: !stumbling && pressed(KEY.DASH),
1362
1408
  fwd: f > 0,
1363
1409
  wx: (fx * f - fz * s) / n,
1364
1410
  wz: (fz * f + fx * s) / n,
@@ -1369,6 +1415,7 @@ var move = (p, i, w, team = 0) => {
1369
1415
  p.ev = 0;
1370
1416
  p.fall = 0;
1371
1417
  if (c.jump) p.buffer = 7;
1418
+ if (stumbling) p.stun--;
1372
1419
  if (p.dash > 0) {
1373
1420
  p.dash--;
1374
1421
  if (p.dash === 50) cap(p, 10);
@@ -1423,13 +1470,13 @@ var decodeInput = (buf) => {
1423
1470
  /** Bytes of a flag on the wire, by its state. */
1424
1471
  var flagBytes = (state) => state === FLAG.CARRIED ? 2 : state === FLAG.DROPPED ? 8 : 1;
1425
1472
  var encodeSnapshot = (s) => {
1426
- const end = 4 + 39 * s.players.length;
1473
+ const end = 4 + 40 * s.players.length;
1427
1474
  const v = new DataView(new ArrayBuffer(end + 4 + s.flags.reduce((n, f) => n + flagBytes(f.state), 0)));
1428
1475
  v.setUint8(0, 2);
1429
1476
  v.setUint16(1, s.tick & 65535);
1430
1477
  v.setUint8(3, s.players.length);
1431
1478
  s.players.forEach((p, i) => {
1432
- const o = 4 + i * 39;
1479
+ const o = 4 + i * 40;
1433
1480
  v.setUint8(o, p.id);
1434
1481
  v.setFloat32(o + 1, p.x);
1435
1482
  v.setFloat32(o + 5, p.y);
@@ -1443,8 +1490,9 @@ var encodeSnapshot = (s) => {
1443
1490
  v.setUint16(o + 33, p.ack & 65535);
1444
1491
  v.setUint8(o + 35, p.mode & 7 | (p.wall & 7) << 3 | (p.jumps & 1) << 6 | p.dashes << 7);
1445
1492
  v.setUint8(o + 36, p.t);
1446
- v.setUint8(o + 37, p.dash);
1493
+ v.setUint8(o + 37, p.dash | (p.by >> 2 & 3) << 6);
1447
1494
  v.setUint8(o + 38, p.coyote & 7 | (p.buffer & 7) << 3 | (p.held & KEY.JUMP ? 64 : 0) | (p.held & KEY.DASH ? 128 : 0));
1495
+ v.setUint8(o + 39, p.stun | (p.by & 3) << 6);
1448
1496
  });
1449
1497
  v.setUint8(end, s.score[0]);
1450
1498
  v.setUint8(end + 1, s.score[1]);
@@ -1472,6 +1520,14 @@ var parseText = (raw) => {
1472
1520
  return null;
1473
1521
  }
1474
1522
  };
1523
+ // src/shared/tackle.ts
1524
+ /** Whether the player's body is a weapon: in a slide, or in the burst of a dash. */
1525
+ var tackling = (p) => p.mode === MODE.SLIDE || p.dash > 50;
1526
+ /**
1527
+ * Whether the cylinders of `a` and `b` overlap, with TACKLE_REACH of reach on top: closer than
1528
+ * two radii and the reach on the floor plane, and their heights (low in a slide) overlap.
1529
+ */
1530
+ var reaches = (a, b) => Math.hypot(a.x - b.x, a.z - b.z) < 1.1 && a.y < b.y + heightOf(b) && b.y < a.y + heightOf(a);
1475
1531
  // src/shared/room.ts
1476
1532
  /** Ticks run at most this many times per timer callback, so a stalled host does not spiral. */
1477
1533
  var MAX_CATCH_UP = 20;
@@ -1549,6 +1605,7 @@ var Room = class {
1549
1605
  p.bank--;
1550
1606
  move(p.state, input, this.world, p.info.team);
1551
1607
  this.ctf.moved(p.state);
1608
+ this.tackle(p, input.view);
1552
1609
  p.ack = input.seq;
1553
1610
  }
1554
1611
  }
@@ -1593,7 +1650,8 @@ var Room = class {
1593
1650
  tick: now,
1594
1651
  players: players.map((p) => ({
1595
1652
  ...p.state,
1596
- ack: p.ack
1653
+ ack: p.ack,
1654
+ by: p.state.stun ? p.by : 0
1597
1655
  })),
1598
1656
  ...this.ctf.wire()
1599
1657
  });
@@ -1655,6 +1713,25 @@ var Room = class {
1655
1713
  } : pb ?? pa ?? p;
1656
1714
  });
1657
1715
  }
1716
+ /**
1717
+ * After a move of `p` at the view tick `view`: a dash or a slide that overlaps an enemy carrier
1718
+ * tackles him. The carrier is where `p` drew him (lag compensation), so a tackle that hit on
1719
+ * the tackler's screen counts; the carrier drops the flag and stumbles, thrown the way the
1720
+ * tackler goes. Once per TACKLE_COOLDOWN ticks, for the first carrier hit.
1721
+ */
1722
+ tackle(p, view) {
1723
+ const me = p.state;
1724
+ if (!tackling(me) || this.ticks - p.tackled < 30) return;
1725
+ const foes = this.players().filter((q) => q.info.team !== p.info.team);
1726
+ const hit = this.rewind(p.info.id, view).find((seen) => reaches(me, seen) && foes.some((q) => q.info.id === seen.id && this.ctf.carrying(q.info.id) >= 0));
1727
+ const foe = foes.find((q) => q.info.id === hit?.id);
1728
+ if (!foe || !this.drop(foe.info.id)) return;
1729
+ const v = speedOf(me);
1730
+ const [dx, dz] = v > .001 ? [me.vx / v, me.vz / v] : forward(me.yaw);
1731
+ stumble(foe.state, dx, dz);
1732
+ foe.by = p.info.id;
1733
+ p.tackled = this.ticks;
1734
+ }
1658
1735
  /** The first spawn point of the team with none of `others` within SPAWN_CLEAR, else the next one round-robin. */
1659
1736
  place(id, team, others) {
1660
1737
  const n = this.world.def.teams[team].spawns.findIndex((_, k) => {
@@ -1713,7 +1790,9 @@ var Room = class {
1713
1790
  },
1714
1791
  state: this.place(id, team, players.map((p) => p.state)),
1715
1792
  bank: 10,
1716
- ack: 65535
1793
+ ack: 65535,
1794
+ by: 0,
1795
+ tackled: -30
1717
1796
  };
1718
1797
  this.peers.set(conn, player);
1719
1798
  this.ctf.join(id, team, player.state);
@@ -1,4 +1,5 @@
1
1
  import type { Snapshot } from '../shared/types';
2
+ import type { Vec3 } from './mesh';
2
3
  /** One thing that happened. `flag` is the team the flag belongs to. */
3
4
  export type Beat = {
4
5
  kind: 'take';
@@ -15,25 +16,48 @@ export type Beat = {
15
16
  team: number;
16
17
  } | {
17
18
  kind: 'start';
19
+ }
20
+ /** Player `who` was tackled by player `by`, at `at` (the middle of his body in the snapshot). */
21
+ | {
22
+ kind: 'tackle';
23
+ who: number;
24
+ by: number;
25
+ at: Vec3;
18
26
  };
19
27
  /**
20
28
  * The beats from snapshot `a` to `b`. Nothing at the first snapshot, nothing while a match is
21
29
  * over (the flags and the score are frozen), and a new match is one beat of its own, whatever
22
30
  * its flags and score reset from. A capture is one beat: the carried flag going home with it is
23
- * not a return.
31
+ * not a return. A carried flag that is home in the next snapshot without a capture was dropped and
32
+ * sent home by its tackler within the same two ticks: one return. A tackle is a player whose
33
+ * stumble timer is higher than it was (a new stumble), one beat each, after the flag beats.
24
34
  */
25
35
  export declare const beats: (a: Snapshot | undefined, b: Snapshot) => Beat[];
26
- /** A line for the banner, and the team whose colour it is in. `me` is the own player. */
36
+ /**
37
+ * A line for the banner, and the team whose colour it is in, or none: a tackle is told to the
38
+ * tackler only. `me` is the own player.
39
+ */
27
40
  export declare const say: (beat: Beat, me: {
28
41
  id: number;
29
42
  team: number;
30
43
  }, name: (id: number) => string) => {
31
44
  text: string;
32
45
  team?: number;
33
- };
46
+ } | undefined;
47
+ /** A sound to play: its id, where (none: centred, the own player's), how loud and at what speed. */
48
+ export interface Cue {
49
+ id: number;
50
+ at?: Vec3;
51
+ gain?: number;
52
+ rate?: number;
53
+ }
34
54
  /**
35
- * The sound of a beat and its speed: a lower pitch for bad news for the own team (its flag taken,
36
- * the enemy flag dropped or returned, a point for the other side), the plain one for good news.
37
- * Undefined for a beat with no sound.
55
+ * The sounds of a beat: a lower pitch for bad news for the own team (its flag taken, the enemy
56
+ * flag dropped or returned, a point for the other side), the plain one for good news. A tackle
57
+ * is an impact at the spot for the others, a close one for the tackler, and for the one tackled
58
+ * an impact and a grunt, centred. None for a new match.
38
59
  */
39
- export declare const cue: (beat: Beat, team: number) => [id: number, rate: number] | undefined;
60
+ export declare const cues: (beat: Beat, me: {
61
+ id: number;
62
+ team: number;
63
+ }) => Cue[];
@@ -17,6 +17,12 @@ export interface Effects {
17
17
  lines: number;
18
18
  /** Steps walked on a floor or a wall: each whole number is a footfall. */
19
19
  stride: number;
20
+ /** 0 to 1: the red vignette of a tackle, full at the hit and gone in under a second. */
21
+ hurt: number;
22
+ /** The own player was tackled: a hard jolt of the eye, the look and the roll, and the vignette. */
23
+ jolt(): void;
24
+ /** The own player tackled someone: a small punch of the look and the field of view. */
25
+ punch(): void;
20
26
  /** Advances dt seconds: the own player (eased, undefined before the first snapshot), the held keys, the events. */
21
27
  update(me: PlayerState | undefined, keys: number, dt: number, hit?: Hit): void;
22
28
  }
@@ -19,6 +19,8 @@ export interface Hud {
19
19
  match(m: Pick<Snapshot, 'score' | 'clock' | 'over' | 'flags'>, who: (id: number) => string): void;
20
20
  /** The markers of this frame (see marks.ts), in the order given; the ones before are removed. */
21
21
  marks(list: Mark[]): void;
22
+ /** The red vignette of a tackle, 0 (none) to 1 (full). */
23
+ hurt(level: number): void;
22
24
  /** A line in the middle of the top of the screen in `team`'s colour, for a few seconds; a newer one replaces it. */
23
25
  banner(text: string, team?: number): void;
24
26
  /** The end screen with the result and each player's captures and returns, `next` seconds before the next match; undefined hides it. */
@@ -20,7 +20,8 @@ export declare const FOV_DEG = 70;
20
20
  export declare const FOV: number;
21
21
  /**
22
22
  * Blinn-Phong strength and exponent: a row per TEX id in order (brick, tile, lava, stone, metal, wood,
23
- * moss, grate), then the flat bodies. Lava and glows never get here: they light themselves.
23
+ * moss, grate, concrete, glass, steel, paint), then the flat bodies. Lava and glows never get here:
24
+ * they light themselves.
24
25
  */
25
26
  export declare const SPEC: number[][];
26
27
  /**
@@ -74,6 +75,10 @@ export declare const level: (world: World) => number[];
74
75
  * blue-grey and not blue, and dimmer on the sides and below.
75
76
  */
76
77
  export declare const daylight: ({ sky: [zenith, horizon] }: WorldDef) => Vec3[];
78
+ /** The world as it is drawn: its brushes and a distant city around them. The physics knows only the brushes. */
79
+ export declare const city: (world: World) => World;
80
+ /** All the map's vertices, drawn once: the city, the brushes, the runner's red and the team zones. */
81
+ export declare const scenery: (world: World) => number[];
77
82
  /** The shader's fog uniform: the world's fog colour pulled toward its horizon by HAZE, and its density; none when the world has no fog. */
78
83
  export declare const fogOf: ({ fog, sky }: WorldDef) => [number, number, number, number];
79
84
  export interface Renderer {
@@ -37,6 +37,9 @@ export declare const SOUND: {
37
37
  readonly DROP: 11;
38
38
  readonly RETURN: 12;
39
39
  readonly CAPTURE: 13;
40
+ /** A tackle: the impact, and the grunt of the one tackled. */
41
+ readonly TACKLE: 14;
42
+ readonly GRUNT: 15;
40
43
  };
41
44
  /**
42
45
  * The sounds of the game: one entry per sound, its voices layered, in SOUND order. A low-passed
@@ -0,0 +1,3 @@
1
+ import type { Brush, WorldDef } from '../shared/world';
2
+ /** The towers of a world's skyline, centred on its play area; the same ones every time. */
3
+ export declare const skyline: ({ brushes }: WorldDef) => Brush[];
@@ -13,6 +13,7 @@ declare const RATES: {
13
13
  wl: number;
14
14
  slide: number;
15
15
  low: number;
16
+ stun: number;
16
17
  };
17
18
  type Blends = Record<keyof typeof RATES, number>;
18
19
  /** What a runner keeps between frames. */
@@ -1,4 +1,6 @@
1
1
  export declare const SIZE = 128;
2
2
  export declare const LAYERS: number;
3
+ /** Integer hash of a lattice point to [0, 1). */
4
+ export declare const hash: (x: number, y: number, s: number) => number;
3
5
  /** All layers, RGBA, layer after layer, rows top to bottom: the upload of a texture array. */
4
6
  export declare const textures: () => Uint8ClampedArray;
@@ -0,0 +1,17 @@
1
+ import type { Brush, WorldDef } from '../shared/world';
2
+ /** A side of a brush: its axis (0 x, 2 z) and 1 for its max, 0 for its min. */
3
+ export type Side = [axis: number, up: number];
4
+ export interface Use {
5
+ /** The whole brush is red. */
6
+ beam: boolean;
7
+ /** Top edges to band. */
8
+ lips: Side[];
9
+ /** Faces to stripe at hand height. */
10
+ stripes: Side[];
11
+ }
12
+ /** What a runner can use on brush `b` of the world `def`. */
13
+ export declare const uses: ({ brushes, floor }: WorldDef, b: Brush) => Use;
14
+ /** The red of every use in the world, in the map's vertex format (layer -2 glows, -1 is lit). */
15
+ export declare const vision: (def: WorldDef) => number[];
16
+ /** A square on each team's roof around its base, lit paint of the team's colour: pale inside, a strong frame. */
17
+ export declare const zones: ({ teams }: WorldDef) => number[];
@@ -128,6 +128,22 @@ export declare const CLIMB_EXIT_SPEED = 3;
128
128
  /** Jumping off a ledge facing away from it: speed away and upward (m/s). */
129
129
  export declare const VAULT_SPEED = 4;
130
130
  export declare const VAULT_UP = 6;
131
+ /**
132
+ * The tackle (tackle.ts, room.ts): a dash or a slide into an enemy carrier. The tackler's body
133
+ * reaches TACKLE_REACH metres past touching the carrier's, as the tackler drew him.
134
+ */
135
+ export declare const TACKLE_REACH = 0.3;
136
+ /** Ticks before a tackler may tackle again (0.5 s): one dash that carries through two carriers tackles one. */
137
+ export declare const TACKLE_COOLDOWN = 30;
138
+ /**
139
+ * The stumble a tackle leaves (physics.ts, `stumble()`): the carrier cannot sprint, dash or jump
140
+ * for STUMBLE_TICKS (0.8 s), walks at STUMBLE_SPEED at most, and is thrown STUMBLE_KNOCK m/s along
141
+ * the tackler's way, a speed that slides out at STUMBLE_DRAG m/s² (about a metre).
142
+ */
143
+ export declare const STUMBLE_TICKS = 48;
144
+ export declare const STUMBLE_SPEED = 2.5;
145
+ export declare const STUMBLE_KNOCK = 6;
146
+ export declare const STUMBLE_DRAG = 12;
131
147
  /**
132
148
  * Host ticks the history of the players goes back (0.5 s): the host rewinds the others to the
133
149
  * view tick of an input, clamped to this.
@@ -138,6 +154,7 @@ export declare const MAX_REWIND = 30;
138
154
  * INPUT_BURST of them; inputs beyond the bank are dropped (and not acked).
139
155
  */
140
156
  export declare const INPUT_BURST = 10;
157
+ /** At most 16: the id of a tackler goes on the wire in 4 bits (protocol.ts). */
141
158
  export declare const MAX_PLAYERS = 16;
142
159
  /** Team names and colours (CSS), red then blue: the runners, the flags, the bases and the HUD wear them. */
143
160
  export declare const TEAM_NAME: string[];
@@ -16,6 +16,7 @@ export declare const STILL: {
16
16
  jumps: number;
17
17
  dashes: number;
18
18
  dash: number;
19
+ stun: number;
19
20
  coyote: number;
20
21
  buffer: number;
21
22
  held: number;
@@ -32,6 +33,12 @@ export declare const eyeHeight: (p: Pick<PlayerState, "mode">) => number;
32
33
  export declare const speedOf: (p: Pick<PlayerState, "vx" | "vz">) => number;
33
34
  /** Running faster than a walk on the ground: the sprint, for the animation to pump the arms. */
34
35
  export declare const sprinting: (p: Pick<PlayerState, "mode" | "vx" | "vz">) => boolean;
36
+ /**
37
+ * A tackle lands on the player: he stumbles for STUMBLE_TICKS and is thrown STUMBLE_KNOCK m/s along
38
+ * (dx, dz), a unit vector (the tackler's way). It ends a dash, a wall-run, a hang and a climb, and
39
+ * clears a jump press and the coyote window. For the host to call between two steps.
40
+ */
41
+ export declare const stumble: (p: PlayerState, dx: number, dz: number) => void;
35
42
  /**
36
43
  * Applies one input for 1 / TICK_HZ s, in place: yaw and pitch from the input (pitch clamped to
37
44
  * MAX_PITCH), then the step of the current mode (see the top of the file). Feet under the world's
@@ -28,7 +28,7 @@ export declare const MSG_INPUT = 1;
28
28
  export declare const MSG_SNAPSHOT = 2;
29
29
  export declare const INPUT_BYTES = 11;
30
30
  export declare const SNAP_HEAD = 4;
31
- export declare const SNAP_PLAYER = 39;
31
+ export declare const SNAP_PLAYER = 40;
32
32
  /** The match block after the players: the captures, the clock; the flags follow (2 to 16 bytes). */
33
33
  export declare const SNAP_MATCH = 4;
34
34
  /**
@@ -62,6 +62,13 @@ export declare class Room {
62
62
  * One the history does not hold stands where it is.
63
63
  */
64
64
  rewind(id: number, view?: number): PlayerState[];
65
+ /**
66
+ * After a move of `p` at the view tick `view`: a dash or a slide that overlaps an enemy carrier
67
+ * tackles him. The carrier is where `p` drew him (lag compensation), so a tackle that hit on
68
+ * the tackler's screen counts; the carrier drops the flag and stumbles, thrown the way the
69
+ * tackler goes. Once per TACKLE_COOLDOWN ticks, for the first carrier hit.
70
+ */
71
+ private tackle;
65
72
  /** The first spawn point of the team with none of `others` within SPAWN_CLEAR, else the next one round-robin. */
66
73
  private place;
67
74
  /** The match is over: everyone gets the result and what each player did. */
@@ -0,0 +1,8 @@
1
+ import type { PlayerState } from './types';
2
+ /** Whether the player's body is a weapon: in a slide, or in the burst of a dash. */
3
+ export declare const tackling: (p: PlayerState) => boolean;
4
+ /**
5
+ * Whether the cylinders of `a` and `b` overlap, with TACKLE_REACH of reach on top: closer than
6
+ * two radii and the reach on the floor plane, and their heights (low in a slide) overlap.
7
+ */
8
+ export declare const reaches: (a: PlayerState, b: PlayerState) => boolean;
@@ -125,6 +125,8 @@ export interface PlayerState {
125
125
  dashes: number;
126
126
  /** Ticks to the next dash; the first DASH_TICKS of DASH_COOLDOWN are the burst. */
127
127
  dash: number;
128
+ /** Ticks of stumble left after a tackle (STUMBLE_TICKS at the start): no sprint, dash or jump, and slow. */
129
+ stun: number;
128
130
  /** Ticks left in which a jump still works after walking off an edge, and in which a press is kept. */
129
131
  coyote: number;
130
132
  buffer: number;
@@ -148,11 +150,21 @@ export declare const TEX: {
148
150
  readonly MOSS: 6;
149
151
  /** Metal floor grating over darkness. */
150
152
  readonly GRATE: 7;
153
+ /** White precast concrete in 1 m panels: the roofs and walls. */
154
+ readonly CONCRETE: 8;
155
+ /** Dark blue glass in steel frames; the shader adds the sky's reflection. */
156
+ readonly GLASS: 9;
157
+ /** Brushed steel. */
158
+ readonly STEEL: 10;
159
+ /** A near white painted panel: the brush tint is its colour. */
160
+ readonly PAINT: 11;
151
161
  };
152
162
  /** One player in a snapshot: the state (its ev and fall read 0) and the ack. */
153
163
  export interface SnapPlayer extends PlayerState {
154
164
  /** Seq of the last input of this player the host applied: the client replays the ones after. */
155
165
  ack: number;
166
+ /** While `stun` runs: the id of the player who tackled this one (4 bits), else 0. Not part of the movement. */
167
+ by: number;
156
168
  }
157
169
  /** The flag of a team as a snapshot carries it: only the fields of its state are meaningful, the rest read 0. */
158
170
  export interface FlagState {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@korial29/tiny-fps",
3
3
  "description": "Tiny multiplayer first-person rooftop game for the browser: raw WebGL, zero runtime dependencies, WebSocket or same-browser multi-tab play.",
4
4
  "license": "Apache-2.0",
5
- "version": "0.19.0",
5
+ "version": "0.21.0",
6
6
  "type": "module",
7
7
  "files": [
8
8
  "dist"