@korial29/tiny-fps 0.14.0 → 0.15.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/README.md CHANGED
@@ -198,13 +198,15 @@ For now the game is the movement and the room; the rules come with the next step
198
198
 
199
199
  - [x] Multiplayer over WebSocket, or between tabs of one browser with no server
200
200
  - [x] A brush world under an open sky: roofs at any height, gaps, floating platforms and overhangs, steps, falls back to a spawn; eight procedural materials (brick, tile, lava, stone, metal, wood, moss, grating) with bump mapping and per-material highlights; a sky with a blooming sun, a sun shadow that follows you, daylight from the sky
201
- - [x] The rooftop map: a deck, a parapet, a crate, a block and a platform with steps
201
+ - [x] ROOFTOPS, a parkour course: roofs across jumpable and unjumpable gaps, a stair to a floating platform, ledges to grab, a long wall to run along, a slot to slide under, a beam, a far roof for sprint plus dash
202
202
  - [x] Client-side prediction, exact to the bit, and the other players interpolated
203
203
  - [x] A per-tick history of the players on the host, for lag compensation
204
- - [x] Flashlights with shadow maps, a light colour per room, a fog colour per map, flickering lava light, dust in the flashlight beam
204
+ - [x] Daylight: a sky with a blooming sun, a sun shadow that follows you, a light colour per box, haze toward the horizon
205
205
  - [x] Post-processing: bloom, tone mapping, vignette, film grain, 4x antialiasing
206
+ - [x] Parkour moves, predicted exactly: momentum, sprint, dash, double jump, ledge grab and climb, wall-run, slide, coyote time and jump buffer
207
+ - [x] Your own body in first person, Mirror's Edge style: arms that pump with the stride, hands on the ledge, legs when you look down; a camera that kicks its field of view, dips on landings, leans into wall-runs; speed lines
206
208
  - [x] A model for the other players: jointed legs and arms that follow their stride
207
- - [x] Sound: a jsfxr-style synthesiser and a looped music; M mutes
209
+ - [x] Sound: a jsfxr-style synthesiser for steps, jumps, dashes, landings, grabs, climbs, slides and the wind of speed, placed in stereo; a looped music; M mutes
208
210
  - [x] A title screen with the controls, a muted mark, a player count and name tags
209
211
  - [x] Shadow DOM, zero runtime dependencies, size-gated in CI
210
212
 
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
- var e=.4,t=1.8,n=1.55,r=.9,i=7.5,a=5.5,o={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,SPRINT:32,DASH:64,CROUCH:128},s={GROUND:0,AIR:1,WALLRUN:2,HANG:3,CLIMB:4,SLIDE:5,CROUCH:6},c={NONE:0,EAST:1,WEST:2,SOUTH:3,NORTH:4},l={JUMP:1,DOUBLE:2,DASH:4,LAND:8,GRAB:16,CLIMB:32,WALLRUN_START:64,WALLRUN_END:128,SLIDE_START:256,SLIDE_END:512},u={BRICK:0,TILE:1,LAVA:2,STONE:3,METAL:4,WOOD:5,MOSS:6,GRATE:7},d=-30,f=(e,t,n,r,i)=>({min:[e,d,t],max:[n,i,r],top:u.TILE,side:u.BRICK}),p=([e,t,n],[r,i,a],o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c}),m={name:`Rooftops`,brushes:[f(4,57.7,24,76,10),f(4,36,24,53.5,10),f(4,20,24,36,12.4),f(4,-5,24,7,12.4),f(27,20,47,50,8),f(27,60,47,76,8),p([9,12.2,39],[19,12.6,47],u.METAL,u.METAL),...((e,t)=>[1,2,3,4,5,6].map(n=>p([12,t,e-n],[14,t+.4*n,e-n+1],u.STONE,u.STONE)))(53,10),p([5,10,42],[5.5,14,42.5],u.METAL),p([5,10,50],[5.5,14,50.5],u.METAL),p([8,12.4,24],[20,12.85,24.45],u.METAL),p([36,8,22],[37,14.5,48],u.STONE,u.STONE,[1,.75,.62]),p([30,8,28],[34,10,32],u.STONE,u.BRICK),p([40,8,30],[44,10.2,34],u.STONE,u.BRICK),p([28,9.2,44],[35,12,46],u.METAL,u.GRATE,[.8,.9,1]),p([41.5,7.6,50],[42,8,60],u.METAL),p([30,8,64],[34,9.6,68],u.STONE,u.BRICK)],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]],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]},h=4,g=1024,_=(e,t)=>(e+g)*(2*g)+t+g,v=(e,t)=>Math.min(Math.max(Math.floor(e/t),-1024),1023),y=(e,t=h)=>{let n=/* @__PURE__ */ new Map;return e.brushes.forEach(({min:e,max:r},i)=>{for(let a=v(e[0],t);a<=v(r[0],t);a++)for(let o=v(e[2],t);o<=v(r[2],t);o++){let e=_(a,o),t=n.get(e);t?t.push(i):n.set(e,[i])}}),{def:e,cell:t,grid:n}},b=(e,t,n,r)=>{let i=[];for(let a=v(t-r,e.cell);a<=v(t+r,e.cell);a++)for(let t=v(n-r,e.cell);t<=v(n+r,e.cell);t++)for(let n of e.grid.get(_(a,t))??[])i.includes(n)||i.push(n);return i},x=(e,t,n,r)=>{let{cell:i,def:a}=e,o=r,s=v(t[0],i),c=v(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,y=u?i/Math.abs(n[2]):1/0;for(;;){for(let r of e.grid.get(_(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)>g||Math.abs(c)>g)return o;p<m?(s+=l,p+=h):(c+=u,m+=y)}},S=(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&&x(e,t,[r/o,i/o,a/o],o)<o-1e-4},C=1/60,w=Math.PI*2,T=1e-6,E=.01,D=.001,O=e=>(e%w+w)%w,k=e=>[-Math.sin(e),-Math.cos(e)],A=Math.fround,j=Math.sqrt,M=(e,t,n)=>Math.min(Math.max(e,t),n),N=(e,t)=>j(e*e+t*t),P=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],F={vx:0,vz:0,mode:s.GROUND,t:0,wall:c.NONE,edge:0,jumps:1,dashes:1,dash:0,coyote:6,buffer:0,held:0,ev:0,fall:0},I=(e,t,n)=>{let{spawns:r}=t.def,[i,a,o,s]=r[(n%r.length+r.length)%r.length];return{id:e,x:A(i),y:A(a),z:A(o),vy:0,yaw:O(s),pitch:0,ground:!0,...F}},L=e=>e===s.GROUND||e===s.SLIDE||e===s.CROUCH,R=e=>e.mode===s.SLIDE||e.mode===s.CROUCH?r:t,ee=e=>e.mode===s.SLIDE||e.mode===s.CROUCH?.7:1.6,z=(e,t,n)=>e.max[1]>t+.5+E&&e.min[1]<t+n-E,B=(e,t,n)=>[t-M(t,e.min[0],e.max[0]),n-M(n,e.min[2],e.max[2])],te=(t,n,r)=>{let{brushes:i}=n.def,a=b(n,t.x,t.z,2*e),o=(e-T)**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(!z(a,t.y,r))continue;let[c,d]=B(a,t.x,t.z),f=c*c+d*d;if(f>=o)continue;if(f){let t=j(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]},ne=(t,n,r)=>{let{brushes:i}=n.def,a=(e-T)**2,o=-1/0,s=1/0;for(let c of b(n,t.x,t.z,e)){let e=i[c],[n,l]=B(e,t.x,t.z);n*n+l*l>=a||(e.max[1]<=t.y+.5+E?o=Math.max(o,e.max[1]):e.min[1]>=t.y+r-E&&(s=Math.min(s,e.min[1])))}return[o,s]},re=(t,n)=>{let r=(e-T)**2;return b(n,t.x,t.z,e).every(e=>{let i=n.def.brushes[e],[a,o]=B(i,t.x,t.z);return a*a+o*o>=r||!z(i,t.y,1.8)})},ie=(t,n,r,i,a)=>{let o=(e-T)**2;return b(t,n,r,e).every(e=>{let s=t.def.brushes[e],[c,l]=B(s,n,r);return c*c+l*l>=o||s.max[1]<=i||s.min[1]>=a})},ae=(e,t)=>{let[n,r]=P[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}},oe=(e,t,n,r)=>{let{a:i,o:a,sign:o,c:s,co:c}=ae(t,n),l=((o>0?e.min[i]:e.max[i])-s)*o;return l>=.4-D&&l<=.4+r&&c>=e.min[a]&&c<=e.max[a]?l:void 0},se=(e,t,n)=>b(t,e.x,e.z,.55).some(r=>{let i=t.def.brushes[r];return oe(i,e,n,.15)!==void 0&&i.min[1]<e.y+.5&&i.max[1]>e.y+1.8}),ce=(e,t)=>{let[n,r]=k(e.yaw),i;for(let a=1;a<=4;a++){let[o,s]=P[a];if(a===e.wall||n*o+r*s<.5)continue;let{a:c,sign:l}=ae(e,a);for(let n of b(t,e.x,e.z,.6000000000000001)){let r=t.def.brushes[n],o=r.max[1],s=o-e.y;if(oe(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];ie(t,p,m,Math.min(e.y,o-2)+E,o+1.8)&&ie(t,h,g,o+E,o+1.8)&&(i={side:a,top:o,hang:d})}}return i},le=(e,t)=>{let{a:n,o:r,sign:i,c:a,co:o}=ae(e,e.wall);return b(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 A(c.max[1])===e.edge&&o>=c.min[r]&&o<=c.max[r]&&l>=.2})},ue=(e,n)=>{if(e.vy>=0)return!1;let[r]=ne(e,n,t),i=6*C;return e.y-r<=-e.vy*i+10*i*i},V=(e,t)=>{e.mode=t,e.t=0},de=(e,t)=>{let n=N(e.vx,e.vz);n>t&&(e.vx*=t/n,e.vz*=t/n)},fe=(t,n,r,i)=>{let[a,o]=[r.wx,r.wz];for(let r of b(n,t.x,t.z,e+D)){let e=n.def.brushes[r],[s,c]=B(e,t.x,t.z),l=N(s,c);if(l>0&&l<=.4+D&&z(e,t.y,i)){let e=(-a*s-o*c)/l;e>0&&(a+=e*s/l,o+=e*c/l)}}return[a,o]},pe=(e,t,n)=>{let r=N(t[0],t[1]);if(r<T){let t=N(e.vx,e.vz),n=t?Math.max(0,t-45*C)/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=N(s,c);if(l){let e=Math.max(0,l-45*C)/l;[s,c]=[s*e,c*e]}n*=r,o=o<n?Math.min(n,o+(o>=6?3:50)*C):Math.max(n,o-12*C),e.vx=s+o*i,e.vz=c+o*a},me=(e,t,n,r,i)=>{let a=e.y;e.x+=e.vx*C,e.z+=e.vz*C;let[o,s]=te(e,t,n),c=N(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]=ne(e,t,n),d=e.vy-r*20*C;if(e.y+=(e.vy+d)/2*C,e.vy=d,e.y+n>u&&(e.y=u-n,e.vy=Math.min(e.vy,0)),e.vy<=0?e.y<=l+E: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},H=(e,t)=>{e.vy=t,e.coyote=0,e.buffer=0,e.ev|=l.JUMP},he=(e,n,r)=>{let[i,a]=P[e.wall],c=t=>{V(e,t),e.edge=0};if(r.keys&(o.BACK|o.CROUCH))c(s.AIR),e.coyote=0;else if(r.jump&&r.fx*i+r.fz*a<0)c(s.AIR),e.vx=-i*4,e.vz=-a*4,H(e,6);else if(r.jump||r.fwd&&e.t>=6)V(e,s.CLIMB);else if(e.t>=30)c(s.AIR),e.coyote=0;else{let r=Math.max(e.edge-2,ne(e,n,t)[0]);e.y+=M(r-e.y,-8*C,8*C)}},ge=(e,t)=>{let[n,r]=P[e.wall];e.y<e.edge?e.y=Math.min(e.edge,e.y+8*C):(e.x+=n*a*C,e.z+=r*a*C),e.y>=e.edge&&le(e,t)?(V(e,s.GROUND),e.vx=n*3,e.vz=r*3,e.vy=0,e.edge=0,e.wall=c.NONE,e.coyote=6,e.ev|=l.CLIMB):e.t>=40&&(V(e,e.y>=e.edge?s.GROUND:s.AIR),e.edge=0,e.wall=c.NONE)},_e=(e,t,n)=>{let[r,i]=P[e.wall],a=e.vx*r+e.vz*i,[o,c]=[e.vx-a*r,e.vz-a*i],u=N(o,c);if(n.jump)V(e,s.AIR),e.vx=o-r*5,e.vz=c-i*5,H(e,6.5),e.jumps=1,e.dashes=1,e.ev|=l.WALLRUN_END;else if(!n.fwd||u<5.5||e.t>=60||!se(e,t,e.wall))V(e,s.AIR),e.ev|=l.WALLRUN_END;else{let t=Math.max(0,u-2.5*C)/u;e.vx=o*t,e.vz=c*t}},ve=(e,t,n)=>{if(!n.fwd)return;let r=N(e.vx,e.vz);for(let n=1;n<=4;n++){let[i,a]=P[n],o=e.vx*i+e.vz*a,[c,u]=[e.vx-o*i,e.vz-o*a];if(n!==e.wall&&N(c,u)>=7&&Math.abs(o)<=.4*r&&se(e,t,n)){V(e,s.WALLRUN),e.wall=n,[e.vx,e.vz]=[c,u],e.vy=Math.min(e.vy,3),e.jumps=1,e.dashes=1,e.coyote=0,e.ev|=l.WALLRUN_START;return}}},ye=(e,t)=>{V(e,s.HANG),e.wall=t.side,e.edge=A(t.top),t.side<=c.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|=l.GRAB},be=(e,t,n)=>{let r=e.mode===s.GROUND;if(n.dash&&e.dash===0&&(r||(e.mode===s.AIR||e.mode===s.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===s.WALLRUN&&(V(e,s.AIR),e.ev|=l.WALLRUN_END)),e.vx=t*16,e.vz=i*16,e.dash=60,e.ev|=l.DASH}let a=e.dash>50;e.mode===s.WALLRUN&&_e(e,t,n),L(e.mode)&&xe(e,t,n,a),e.mode===s.AIR&&Se(e,t,n,a);let u=a&&e.vy<=0?0:e.mode===s.WALLRUN?.15:1,d=e.mode,f=me(e,t,R(e),u,L(d));if(f>=0){if(!L(e.mode)){if(e.ev|=l.LAND|(e.mode===s.WALLRUN?l.WALLRUN_END:0),e.fall=f,e.jumps=1,e.dashes=1,e.wall=c.NONE,n.keys&o.CROUCH){let t=N(e.vx,e.vz)>=i;V(e,t?s.SLIDE:s.CROUCH),e.ev|=t?l.SLIDE_START:0}else V(e,s.GROUND)}e.coyote=6}else L(e.mode)&&(e.ev|=e.mode===s.SLIDE?l.SLIDE_END:0,V(e,s.AIR));if(e.mode===s.AIR){let r=ce(e,t);r?ye(e,r):ve(e,t,n)}},xe=(e,n,a,c)=>{let u=(a.keys&o.CROUCH)!==0;if(e.buffer>0&&(e.mode===s.GROUND||re(e,n))){e.ev|=e.mode===s.SLIDE?l.SLIDE_END:0,V(e,s.AIR),H(e,7);return}let d=N(e.vx,e.vz);if(e.mode===s.GROUND&&u){let t=d>=i;V(e,t?s.SLIDE:s.CROUCH),e.ev|=t?l.SLIDE_START:0}else e.mode===s.SLIDE&&(e.t>=60||d<4.5)?(e.ev|=l.SLIDE_END,V(e,!u&&re(e,n)?s.GROUND:s.CROUCH)):e.mode===s.SLIDE&&!u&&re(e,n)?(e.ev|=l.SLIDE_END,V(e,s.GROUND)):e.mode===s.CROUCH&&!u&&re(e,n)&&V(e,s.GROUND);if(!c){if(e.mode===s.SLIDE){let t=Math.max(0,d-4*C)/d;e.vx*=t,e.vz*=t}else if(e.mode===s.CROUCH)pe(e,fe(e,n,a,r),3);else{let r=(a.keys&o.SPRINT)!==0&&a.fwd;pe(e,fe(e,n,a,t),r?9:6)}}},Se=(e,t,n,r)=>{if(e.buffer>0&&(e.coyote>0?H(e,7):e.jumps>0&&!ue(e,t)&&(e.jumps--,H(e,6),e.ev=e.ev&~l.JUMP|l.DOUBLE)),r||!n.wx&&!n.wz)return;let i=N(e.vx,e.vz);e.vx+=n.wx*14*C,e.vz+=n.wz*14*C,de(e,Math.max(i,6))},Ce=(e,t,r)=>{e.yaw=O(t.yaw),e.pitch=Math.max(-1.55,Math.min(n,t.pitch));let i=(t.keys&o.FORWARD?1:0)-(t.keys&o.BACK?1:0),a=(t.keys&o.RIGHT?1:0)-(t.keys&o.LEFT?1:0),c=N(i,a)||1,[l,u]=k(e.yaw),d=n=>(t.keys&n)!==0&&(e.held&n)===0,f={keys:t.keys,jump:d(o.JUMP),dash:d(o.DASH),fwd:i>0,wx:(l*i-u*a)/c,wz:(u*i+l*a)/c,fx:l,fz:u},p=e.mode;if(e.ev=0,e.fall=0,f.jump&&(e.buffer=7),e.dash>0&&(e.dash--,e.dash===50&&de(e,10)),e.mode===s.HANG&&he(e,r,f),e.mode===s.CLIMB?ge(e,r):e.mode!==s.HANG&&be(e,r,f),e.y<r.def.floor){let{yaw:t,pitch:n,id:i}=e;Object.assign(e,I(i,r,i),{yaw:t,pitch:n})}e.t=e.mode===p?Math.min(255,e.t+1):e.t,e.buffer=Math.max(0,e.buffer-1),e.mode===s.AIR&&p===s.AIR&&(e.coyote=Math.max(0,e.coyote-1)),e.held=t.keys&(o.JUMP|o.DASH),e.ground=L(e.mode),e.x=A(e.x),e.y=A(e.y),e.z=A(e.z),e.vx=A(e.vx),e.vy=A(e.vy),e.vz=A(e.vz),e.edge=A(e.edge)},we=65536/(2*Math.PI),Te=e=>Math.round(e*we)&65535,Ee=e=>Math.max(-32768,Math.min(32767,Math.round(e))),De=e=>Ee(e*1e4),Oe=e=>e/1e4,ke=e=>e/we,Ae=(e=0)=>Math.round(e*256)&16777215,je=e=>({...e,yaw:ke(Te(e.yaw)),pitch:Oe(De(e.pitch)),...e.view!==void 0&&{view:Ae(e.view)/256}}),Me=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,Te(e.yaw)),t.setInt16(6,De(e.pitch));let n=Ae(e.view);return t.setUint16(8,n>>8),t.setUint8(10,n&255),t.buffer},Ne=e=>{if(e.byteLength<4)return null;let t=new DataView(e),n=t.getUint8(3);if(t.getUint8(0)!==2||e.byteLength!==4+39*n)return null;let r=[];for(let e=0;e<n;e++){let n=4+e*39,i=t.getUint8(n+35),a=t.getUint8(n+38),c=i&7;r.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:ke(t.getUint16(n+29)),pitch:Oe(t.getInt16(n+31)),ack:t.getUint16(n+33),ground:c===s.GROUND||c===s.SLIDE||c===s.CROUCH,mode:c,wall:i>>3&7,jumps:i>>6&1,dashes:i>>7,t:t.getUint8(n+36),dash:t.getUint8(n+37),coyote:a&7,buffer:a>>3&7,held:(a&64?o.JUMP:0)|(a&128?o.DASH:0),ev:0,fall:0})}return{tick:t.getUint16(1),players:r}},Pe=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},U=44100,Fe=([e,t,n,r,i,a,o,s,c,l,u],d)=>{let f=new Float32Array(Math.ceil((r+i+a)*U)),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/U;p+=t*2**(n*_)*(_>c?l:1)*(1+o*Math.sin(_*44))/U,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},Ie=[],Le=(e,t=Ie)=>{let n=t[e].map((t,n)=>[Fe(t,e*9+n),Math.round((t[11]??0)*U)]);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)))},Re=U*60/108,ze=Re/4,Be=4,Ve=[2,150,-6,.002,0,.25,0,1,0,1,1],He=[3,9e3,0,.002,0,.15,0,.5,0,1,.5],Ue=[3,3e4,0,.001,0,.04,0,.7,0,1,.15],We=()=>{let e=new Float32Array(Re*4*Be),t={},n=(n,r)=>(t[String(r)]??=Fe(r,1)).forEach((t,r)=>e[(n*ze+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,Ve),`....x.......x...`[t]==`x`&&n(e,He),t%2==0){n(e,Ue);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)},Ge=40,Ke=24,qe=.5,Je=`tiny-fps:muted`,Ye=()=>{let e=!1;return{unlock:()=>{},listen:()=>{},play:()=>{},mute:t=>{e=t},get muted(){return e},destroy:()=>{}}},Xe=(e=Ie)=>{let t;try{t=new AudioContext}catch{return Ye()}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,qe),a=[],o=!1,s=/* @__PURE__ */ new Set,c=[0,0,0],l=0,u=!1,d=e=>{let n=t.createBuffer(1,e.length,U);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)=>a[n]=d(Le(n,e)));let t=f(d(We()));t.loop=!0,t.connect(i),t.start()}},listen(e,t){[c,l]=[e,t]},play(e,i,o=1){let u=0,d=o;if(i){let[e,t,n]=i.map((e,t)=>e-c[t]),r=Math.hypot(e,t,n);d=Math.max(0,1-r/Ge)**2*o,u=(e*Math.cos(l)-n*Math.sin(l))/Math.max(r,1)}let p=a[e];if(!p||!d)return;if(s.size>=Ke){let e=[...s].reduce((e,t)=>t.vol<e.vol?t:e);if(e.vol>=d)return;e.src.stop(),s.delete(e)}let m=f(p),h=t.createStereoPanner();h.pan.value=u,m.connect(h).connect(n(r,d));let g={vol:d,src:m};s.add(g),m.onended=()=>s.delete(g),m.start()},mute(e){u=e,r.gain.setTargetAtTime(+!e,t.currentTime,.05)},get muted(){return u},destroy:()=>void t.close().catch(()=>{})}},Ze=()=>{try{return localStorage.getItem(Je)==`1`}catch{return!1}},Qe=e=>{e.mute(!e.muted);try{localStorage.setItem(Je,e.muted?`1`:`0`)}catch{}return e.muted},$e=4.4,et=.035,tt=.03,nt=()=>{let e=0,t=0,n=0,r,i={bob:0,roll:0,update(a,s,c){let l=Math.min(1,c*10),u=a&&r?.ground&&a.ground?Math.hypot(a.x-r.x,a.z-r.z):0;u<1&&(e+=u*$e),t+=(+(u>.5*c&&u<1)-t)*l,r=a,i.bob=Math.sin(e)*et*t;let d=+!!(s&o.RIGHT)-!!(s&o.LEFT);n+=(d*tt-n)*Math.min(1,c*8),i.roll=n}};return i},rt=`h5,aside{position:absolute;margin:0;padding:0;pointer-events:none;user-select:none;white-space:pre-line}h5{top:8px;right:12px;font-size:12px}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}`,it=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>E / right click<td>dash<tr><td>C<td>crouch, slide when fast<tr><td>M<td>mute</table><strong></strong></aside><h5 hidden>Muted (M)</h5>`);let t=t=>e.querySelector(t),[n,r]=[`h5`,`aside`].map(e=>t(e)),[i,a]=[`aside span`,`strong`].map(e=>t(e)),o=(e,t)=>e.textContent!=t&&(e.textContent=t);return{title(e,t){r.hidden=!e,o(i,t),o(a,e)},mute:e=>n.hidden=!e}},at=.0025,ot=Math.PI*2,st={KeyW:o.FORWARD,ArrowUp:o.FORWARD,KeyS:o.BACK,ArrowDown:o.BACK,KeyA:o.LEFT,ArrowLeft:o.LEFT,KeyD:o.RIGHT,ArrowRight:o.RIGHT,Space:o.JUMP,ShiftLeft:o.SPRINT,ShiftRight:o.SPRINT,KeyE:o.DASH,KeyC:o.CROUCH},ct=2,lt=e=>st[e]??0,ut=(e,t=()=>{})=>{let r=new AbortController,i=(e,t,n)=>e.addEventListener(t,n,{signal:r.signal}),a={yaw:0,pitch:0,keys:0,locked:()=>e.getRootNode().pointerLockElement==e,destroy:()=>r.abort()};i(e,`click`,()=>{Promise.resolve(e.requestPointerLock()).catch(()=>{})}),i(document,`mousemove`,e=>{a.locked()&&(a.yaw=((a.yaw-e.movementX*at)%ot+ot)%ot,a.pitch=Math.max(-1.55,Math.min(n,a.pitch-e.movementY*at)))}),i(document,`keydown`,e=>{let n=lt(e.code);e.code==`KeyM`&&!e.repeat&&a.locked()&&t(),n&&a.locked()&&(a.keys|=n,e.preventDefault())}),i(document,`keyup`,e=>{a.keys&=~lt(e.code)}),i(document,`mousedown`,e=>{e.button===ct&&a.locked()&&(a.keys|=o.DASH,e.preventDefault())}),i(document,`mouseup`,e=>{e.button===ct&&(a.keys&=~o.DASH)}),i(document,`contextmenu`,e=>a.locked()&&e.preventDefault());let s=()=>{a.keys=0};return i(window,`blur`,s),i(document,`pointerlockchange`,()=>a.locked()||s()),a},dt=120,ft=16,W=e=>{let t={...e};return delete t.ack,t},pt=(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}),mt=(e,t,n)=>O(e+(((t-e+Math.PI)%w+w)%w-Math.PI)*n),ht=(e,t)=>(t-e&65535)<32768,gt=(e,t,n)=>({...t,...pt(e,t,n),yaw:mt(e.yaw,t.yaw,n),pitch:e.pitch+(t.pitch-e.pitch)*n}),_t=e=>{let t,n=0,r=[],i,a,o=[],s=0,c=0,l=e=>{let t=e-100,n=0;for(;n+1<o.length&&o[n+1].t<=t;)n++;let r=o[n],i=o[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}},u=e=>{if(!o.length)return;let{a:t,b:n,u:r}=l(e);return(t.s.tick+(n.s.tick-t.s.tick&65535)*r)%65536};return{you:e=>{t=e},step:(t,o)=>{let l=je({...t,seq:n,view:o===void 0?void 0:u(o)});return n=n+1&65535,r.push(l),r.length>dt&&r.shift(),i&&(a=W(i),Ce(i,l,e),s|=i.ev,c=Math.max(c,i.fall)),l},snapshot:(n,s)=>{o.push({t:s,s:n}),o.length>ft&&o.shift();let c=n.players.find(e=>e.id===t);c&&(r=r.filter(e=>!ht(e.seq,c.ack)),i=W(c),a=W(i),r.forEach((t,n)=>{n===r.length-1&&(a=W(i)),Ce(i,t,e)}))},events:()=>{let e={ev:s,fall:c};return s=c=0,e},me:e=>i&&a?gt(a,i,Math.max(0,Math.min(1,e))):void 0,others:e=>{let n=o.at(-1);if(!n)return[];let{a:r,b:i,u:a}=l(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?gt(W(t),W(n),a):W(n??t??e)})}}},vt={SPOT:0,POINT:1},yt=e=>[],bt=(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]]},xt=[[-1,-1],[1,-1],[1,1],[-1,-1],[1,1],[-1,1]],St=(e,[t,n,r],[i,a,o],s,c,l=-1)=>{let[u,d]=[Math.sin(s),Math.cos(s)],f=(e,t)=>[e*d+t*u,-e*u+t*d];for(let s=0;s<3;s++)for(let u of[-1,1]){let[d,p]=[(s+1)%3,(s+2)%3],m=[0,0,0];m[s]=u;let[h,g]=f(m[0],m[2]);for(let[_,v]of xt){let y=[0,0,0];[y[s],y[d],y[p]]=[u,_,v];let[b,x]=f(y[0]*i,y[2]*o);e.push(t+b,n+y[1]*a,r+x,h,m[1],g,c[0],c[1],l,c[2])}}},Ct=(e,t,n=[0,0,0])=>{let r=[];for(let i=1;i<e.length;i++){let[[a,o],[s,c]]=[e[i-1],e[i]],l=Math.hypot(s-a,c-o);if(!l)continue;let[u,d]=[(c-o)/l,-(s-a)/l],f=(e,i,a)=>{let[o,s]=[Math.cos(e*w/t),Math.sin(e*w/t)];r.push(n[0]+i*o,n[1]+i*s,n[2]-a,u*o,u*s,-d)};for(let e=0;e<t;e++)for(let[t,n,r]of[[e,a,o],[e+1,a,o],[e+1,s,c],[e,a,o],[e+1,s,c],[e,s,c]])f(t,n,r)}return r},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=(e,t,n,[r,i,a],o,s,c=[1,1,1])=>{let[l,u,d]=typeof s==`number`?[s,s,s]:s,[f,p,m,h,g,_,v,y,b]=[...r,...i,...a],x=n[0]+f*o[0]+h*o[1]+v*o[2],S=n[1]+p*o[0]+g*o[1]+y*o[2],C=n[2]+m*o[0]+_*o[1]+b*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,w]=[t[n+3],t[n+4],t[n+5]];e.push(x+f*r+h*i-v*a,S+p*r+g*i-y*a,C+m*r+_*i-b*a,f*o+h*s-v*w,p*o+g*s-y*w,m*o+_*s-b*w,t[n+6]*c[0],t[n+7]*c[1],t[n+8],t[n+9]*c[2])}},Et=(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]},Dt=3.6,G=({x:e,y:t,z:n,yaw:r},i,a,o)=>{let[s,c]=[Math.sin(r),Math.cos(r)];return[e+i*c-o*s,t+a,n-i*s-o*c]},Ot=(e,t,n,r,i)=>{let a=e.get(t)??{x:n,z:r,walked:0,vx:0,vz:0},o=Math.hypot(n-a.x,r-a.z),s=i>0&&o<1?1-Math.exp(-i*8):0;return a.vx+=((n-a.x)/(i||1)-a.vx)*s,a.vz+=((r-a.z)/(i||1)-a.vz)*s,a.walked+=o<1?o:0,[a.x,a.z]=[n,r],e.set(t,a),a},kt=e=>Math.min(1,Math.hypot(e.vx,e.vz)/2),At=(e,t)=>wt(Ct(e,t),[1,1,1]),jt=At([[0,0],[1,.05],[.65,1],[0,1]],5),Mt=At([[0,0],[.8,.05],[.55,.7],[1,.8],[.5,1],[0,1]],5),Nt=At([[0,0],[.15,0],[.13,.25],[.22,.7],[.2,.95],[0,1]],6),Pt=At([[0,0],[.1,.06],[.155,.4],[.13,.8],[0,1]],8),Ft=(e,t,n,r,i,a,o,s=1)=>{let c=i.map((e,t)=>e-r[t]),l=Math.hypot(...c);Tt(e,t,r,Et(c.map(e=>e/l),[Math.cos(n),0,-Math.sin(n)]),[0,0,0],[a*s,a,l],o)},K=(e,t,n,r,i,a,o,s=1)=>Ft(e,t,n.yaw,G(n,...r),G(n,...i),a,o,s),It=([e,t,n],r,i,a,o)=>{let[s,c]=[t-a*Math.cos(r),n+a*Math.sin(r)];return[[e,s,c],[e,s-o*Math.cos(i),c+o*Math.sin(i)]]},Lt=(e,t,n)=>{let r=.55*Math.sin(t)*n;return It(e,r,r-.9*Math.max(0,-Math.sin(t+.5))*n,.43,.45)},Rt=.88,zt=(e,n,r,i,a)=>{let o=i*Dt,s=Rt-.08*Math.sin(o)**2*a,[c,l]=[r.map(e=>e*.45),[.1,.1,.12]],[u,d]=[[0,s,0],[0,s+.55,.02]];K(e,Nt,n,u,d,1,r,1.25),K(e,Pt,n,d,[0,t,.02],1.1,c);let f=r.map(e=>.35+.65*e);St(e,G(n,0,d[1]+.17,.17),[.11,.035,.03],n.yaw,f,-2),St(e,G(n,0,s+.4,-.2),[.15,.2,.07],n.yaw,c);for(let t of[-1,1]){let i=[t*.12,s,0],[u,d]=Lt(i,o+(t>0?Math.PI:0),a);K(e,jt,n,i,u,.1,c),K(e,jt,n,u,d,.08,c),St(e,G(n,d[0],d[1]+.03,d[2]+.05),[.06,.03,.1],n.yaw,l);let f=[t*.27,s+.5,.02],p=.45*Math.sin(o+(t<0?Math.PI:0))*a,[m,h]=It(f,p,p+.3,.34,.36);K(e,jt,n,f,m,.07,r),K(e,Mt,n,m,h,.06,c)}},Bt=Object.keys(u).length,q=(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},J=(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)=>q((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},Vt=(e,t,n,r,i)=>{let[a,o]=[0,.5];for(let s=0;s<r;s++,o/=2)a+=o*J(e*(1<<s),t*(1<<s),n<<s,i+s);return a/(1-o*2)},Y=(e,t,n)=>e.map((e,r)=>e+(t[r]-e)*n),X=(e,t)=>e.map(e=>e*t),Z=e=>Math.min(Math.max(e,0),1),Ht=Math.PI*2,Q=[];Q[u.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=J(e*16,t*16,16,5),c=.8+.4*s;return a<.05||o<.1?[X([165,160,150],.7+.3*c),.1+.1*s]:[X([170,78,56],(.8+.4*q(i,n,1))*c*(.85+.15*o)),.7+.2*s+.1*Z(Math.min(a-.05,o-.1)*12)]},Q[u.TILE]=(e,t)=>{let[n,r]=[Math.floor(e*4),Math.floor(t*4)],[i,a]=[e*4%1,t*4%1],o=J(e*16,t*16,16,7),s=.9+.2*o;return i<.05||a<.05?[X([85,85,80],s),.1]:[X([196,190,172],s*(.88+.08*(n+r&1)+.1*q(n,r,2))),.8+.1*o+.1*Z((Math.min(i,a)-.05)*14)]},Q[u.LAVA]=(e,t)=>{let n=Vt(e*4,t*4,4,4,11),r=Math.max(0,1-Math.abs(n-.5)*7)**2;return[Y(Y([55,8,4],[230,70,8],n),[255,215,90],r),.5]},Q[u.STONE]=(e,t)=>{let n=Vt(e*8,t*8,8,4,3);return[X([128,124,120],.45+.7*(n*1.3+.1*q(Math.floor(e*128),Math.floor(t*128),4))),Z(n*1.4-.2)]},Q[u.METAL]=(e,t)=>{let[n,r,i,a]=[Math.floor(e*2),Math.floor(t*2),e*2%1,t*2%1],o=Z((J(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=Z(1-u/.07),f=X([98,108,124],(.9+.2*J(e*32,t*32,32,9)+.12*q(n,r,6))*(1+.3*d)*(.65+.35*Z((u-.06)/.04)));return Math.min(i,a,1-i,1-a)<.03?[X([40,44,50],1+o),.05]:[Y(f,[105,68,45],o*.7),.5+.1*(1-o)+.4*d]},Q[u.WOOD]=(e,t)=>{let n=Math.floor(t*8),r=e*2+q(n,0,8)*2,[i,a,o]=[Math.floor(r)%2,r%1,t*8%1],s=q(n,i,3),c=.5+.5*Math.sin(Ht*(t*40+2.5*J(e*4,t*4,4,21)+s*7));return o<.08||a<.015?[[28,18,10],.05]:[Y([92,58,32],[158,106,62],c*.6+s*.35),.7+.15*c+.15*Z((o-.08)*15)]},Q[u.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=Z((.3*Vt(e*12,t*12,12,3,17)-.03-s)*12),u=J(e*64,t*64,64,19),d=X([128,126,118],(.7+.4*q(i,n,5))*(.7+.5*J(e*16,t*16,16,15)));return[Y(c?X(d,.45):d,Y([52,100,34],[96,148,56],u),l),c?.1+.6*l*u:.6+.2*Z(s*30)+.2*l*u]},Q[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=J(e*16,t*16,16,23);return i<.36?[[9,9,12],0]:[X(Y([104,108,116],[96,80,68],Z((o-.55)*4)),(a?1.25:1)-(.5-i)*2.2+.2*o),a?1:.6+.4*Z((i-.36)*12)]};var Ut=()=>{let e=new Uint8ClampedArray(Bt*128*128*4);return Q.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},Wt=1<<18,Gt=2,$=1024,Kt=.6,qt=Math.tan(70*Math.PI/360),Jt=4,Yt=`#version 300 es
1
+ var e=.4,t=1.8,n=1.55,r=.9,i=7.5,a=5.5,o={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,SPRINT:32,DASH:64,CROUCH:128},s={GROUND:0,AIR:1,WALLRUN:2,HANG:3,CLIMB:4,SLIDE:5,CROUCH:6},c={NONE:0,EAST:1,WEST:2,SOUTH:3,NORTH:4},l={JUMP:1,DOUBLE:2,DASH:4,LAND:8,GRAB:16,CLIMB:32,WALLRUN_START:64,WALLRUN_END:128,SLIDE_START:256,SLIDE_END:512},u={BRICK:0,TILE:1,LAVA:2,STONE:3,METAL:4,WOOD:5,MOSS:6,GRATE:7},d=-30,f=(e,t,n,r,i)=>({min:[e,d,t],max:[n,i,r],top:u.TILE,side:u.BRICK}),p=([e,t,n],[r,i,a],o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c}),m={name:`Rooftops`,brushes:[f(4,57.7,24,76,10),f(4,36,24,53.5,10),f(4,20,24,36,12.4),f(4,-5,24,7,12.4),f(27,20,47,50,8),f(27,60,47,76,8),p([9,12.2,39],[19,12.6,47],u.METAL,u.METAL),...((e,t)=>[1,2,3,4,5,6].map(n=>p([12,t,e-n],[14,t+.4*n,e-n+1],u.STONE,u.STONE)))(53,10),p([5,10,42],[5.5,14,42.5],u.METAL),p([5,10,50],[5.5,14,50.5],u.METAL),p([8,12.4,24],[20,12.85,24.45],u.METAL),p([36,8,22],[37,14.5,48],u.STONE,u.STONE,[1,.75,.62]),p([30,8,28],[34,10,32],u.STONE,u.BRICK),p([40,8,30],[44,10.2,34],u.STONE,u.BRICK),p([28,9.2,44],[35,12,46],u.METAL,u.GRATE,[.8,.9,1]),p([41.5,7.6,50],[42,8,60],u.METAL),p([30,8,64],[34,9.6,68],u.STONE,u.BRICK)],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]],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]},h=4,g=1024,_=(e,t)=>(e+g)*(2*g)+t+g,v=(e,t)=>Math.min(Math.max(Math.floor(e/t),-1024),1023),y=(e,t=h)=>{let n=/* @__PURE__ */ new Map;return e.brushes.forEach(({min:e,max:r},i)=>{for(let a=v(e[0],t);a<=v(r[0],t);a++)for(let o=v(e[2],t);o<=v(r[2],t);o++){let e=_(a,o),t=n.get(e);t?t.push(i):n.set(e,[i])}}),{def:e,cell:t,grid:n}},b=(e,t,n,r)=>{let i=[];for(let a=v(t-r,e.cell);a<=v(t+r,e.cell);a++)for(let t=v(n-r,e.cell);t<=v(n+r,e.cell);t++)for(let n of e.grid.get(_(a,t))??[])i.includes(n)||i.push(n);return i},x=(e,t,n,r)=>{let{cell:i,def:a}=e,o=r,s=v(t[0],i),c=v(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,y=u?i/Math.abs(n[2]):1/0;for(;;){for(let r of e.grid.get(_(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)>g||Math.abs(c)>g)return o;p<m?(s+=l,p+=h):(c+=u,m+=y)}},S=(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&&x(e,t,[r/o,i/o,a/o],o)<o-1e-4},C=1/60,w=Math.PI*2,T=1e-6,E=.01,D=.001,O=e=>(e%w+w)%w,k=e=>[-Math.sin(e),-Math.cos(e)],A=Math.fround,j=Math.sqrt,M=(e,t,n)=>Math.min(Math.max(e,t),n),N=(e,t)=>j(e*e+t*t),P=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],F={vx:0,vz:0,mode:s.GROUND,t:0,wall:c.NONE,edge:0,jumps:1,dashes:1,dash:0,coyote:6,buffer:0,held:0,ev:0,fall:0},I=(e,t,n)=>{let{spawns:r}=t.def,[i,a,o,s]=r[(n%r.length+r.length)%r.length];return{id:e,x:A(i),y:A(a),z:A(o),vy:0,yaw:O(s),pitch:0,ground:!0,...F}},L=e=>e===s.GROUND||e===s.SLIDE||e===s.CROUCH,ee=e=>e.mode===s.SLIDE||e.mode===s.CROUCH?r:t,R=e=>e.mode===s.SLIDE||e.mode===s.CROUCH?.7:1.6,z=e=>N(e.vx,e.vz),te=e=>e.mode===s.GROUND&&N(e.vx,e.vz)>6.5,ne=(e,t,n)=>e.max[1]>t+.5+E&&e.min[1]<t+n-E,re=(e,t,n)=>[t-M(t,e.min[0],e.max[0]),n-M(n,e.min[2],e.max[2])],ie=(t,n,r)=>{let{brushes:i}=n.def,a=b(n,t.x,t.z,2*e),o=(e-T)**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(!ne(a,t.y,r))continue;let[c,d]=re(a,t.x,t.z),f=c*c+d*d;if(f>=o)continue;if(f){let t=j(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]},ae=(t,n,r)=>{let{brushes:i}=n.def,a=(e-T)**2,o=-1/0,s=1/0;for(let c of b(n,t.x,t.z,e)){let e=i[c],[n,l]=re(e,t.x,t.z);n*n+l*l>=a||(e.max[1]<=t.y+.5+E?o=Math.max(o,e.max[1]):e.min[1]>=t.y+r-E&&(s=Math.min(s,e.min[1])))}return[o,s]},oe=(t,n)=>{let r=(e-T)**2;return b(n,t.x,t.z,e).every(e=>{let i=n.def.brushes[e],[a,o]=re(i,t.x,t.z);return a*a+o*o>=r||!ne(i,t.y,1.8)})},se=(t,n,r,i,a)=>{let o=(e-T)**2;return b(t,n,r,e).every(e=>{let s=t.def.brushes[e],[c,l]=re(s,n,r);return c*c+l*l>=o||s.max[1]<=i||s.min[1]>=a})},ce=(e,t)=>{let[n,r]=P[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}},le=(e,t,n,r)=>{let{a:i,o:a,sign:o,c:s,co:c}=ce(t,n),l=((o>0?e.min[i]:e.max[i])-s)*o;return l>=.4-D&&l<=.4+r&&c>=e.min[a]&&c<=e.max[a]?l:void 0},ue=(e,t,n)=>b(t,e.x,e.z,.55).some(r=>{let i=t.def.brushes[r];return le(i,e,n,.15)!==void 0&&i.min[1]<e.y+.5&&i.max[1]>e.y+1.8}),de=(e,t)=>{let[n,r]=k(e.yaw),i;for(let a=1;a<=4;a++){let[o,s]=P[a];if(a===e.wall||n*o+r*s<.5)continue;let{a:c,sign:l}=ce(e,a);for(let n of b(t,e.x,e.z,.6000000000000001)){let r=t.def.brushes[n],o=r.max[1],s=o-e.y;if(le(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];se(t,p,m,Math.min(e.y,o-2)+E,o+1.8)&&se(t,h,g,o+E,o+1.8)&&(i={side:a,top:o,hang:d})}}return i},fe=(e,t)=>{let{a:n,o:r,sign:i,c:a,co:o}=ce(e,e.wall);return b(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 A(c.max[1])===e.edge&&o>=c.min[r]&&o<=c.max[r]&&l>=.2})},pe=(e,n)=>{if(e.vy>=0)return!1;let[r]=ae(e,n,t),i=6*C;return e.y-r<=-e.vy*i+10*i*i},B=(e,t)=>{e.mode=t,e.t=0},me=(e,t)=>{let n=N(e.vx,e.vz);n>t&&(e.vx*=t/n,e.vz*=t/n)},he=(t,n,r,i)=>{let[a,o]=[r.wx,r.wz];for(let r of b(n,t.x,t.z,e+D)){let e=n.def.brushes[r],[s,c]=re(e,t.x,t.z),l=N(s,c);if(l>0&&l<=.4+D&&ne(e,t.y,i)){let e=(-a*s-o*c)/l;e>0&&(a+=e*s/l,o+=e*c/l)}}return[a,o]},ge=(e,t,n)=>{let r=N(t[0],t[1]);if(r<T){let t=N(e.vx,e.vz),n=t?Math.max(0,t-45*C)/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=N(s,c);if(l){let e=Math.max(0,l-45*C)/l;[s,c]=[s*e,c*e]}n*=r,o=o<n?Math.min(n,o+(o>=6?3:50)*C):Math.max(n,o-12*C),e.vx=s+o*i,e.vz=c+o*a},_e=(e,t,n,r,i)=>{let a=e.y;e.x+=e.vx*C,e.z+=e.vz*C;let[o,s]=ie(e,t,n),c=N(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]=ae(e,t,n),d=e.vy-r*20*C;if(e.y+=(e.vy+d)/2*C,e.vy=d,e.y+n>u&&(e.y=u-n,e.vy=Math.min(e.vy,0)),e.vy<=0?e.y<=l+E: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},ve=(e,t)=>{e.vy=t,e.coyote=0,e.buffer=0,e.ev|=l.JUMP},ye=(e,n,r)=>{let[i,a]=P[e.wall],c=t=>{B(e,t),e.edge=0};if(r.keys&(o.BACK|o.CROUCH))c(s.AIR),e.coyote=0;else if(r.jump&&r.fx*i+r.fz*a<0)c(s.AIR),e.vx=-i*4,e.vz=-a*4,ve(e,6);else if(r.jump||r.fwd&&e.t>=6)B(e,s.CLIMB);else if(e.t>=30)c(s.AIR),e.coyote=0;else{let r=Math.max(e.edge-2,ae(e,n,t)[0]);e.y+=M(r-e.y,-8*C,8*C)}},be=(e,t)=>{let[n,r]=P[e.wall];e.y<e.edge?e.y=Math.min(e.edge,e.y+8*C):(e.x+=n*a*C,e.z+=r*a*C),e.y>=e.edge&&fe(e,t)?(B(e,s.GROUND),e.vx=n*3,e.vz=r*3,e.vy=0,e.edge=0,e.wall=c.NONE,e.coyote=6,e.ev|=l.CLIMB):e.t>=40&&(B(e,e.y>=e.edge?s.GROUND:s.AIR),e.edge=0,e.wall=c.NONE)},xe=(e,t,n)=>{let[r,i]=P[e.wall],a=e.vx*r+e.vz*i,[o,c]=[e.vx-a*r,e.vz-a*i],u=N(o,c);if(n.jump)B(e,s.AIR),e.vx=o-r*5,e.vz=c-i*5,ve(e,6.5),e.jumps=1,e.dashes=1,e.ev|=l.WALLRUN_END;else if(!n.fwd||u<5.5||e.t>=60||!ue(e,t,e.wall))B(e,s.AIR),e.ev|=l.WALLRUN_END;else{let t=Math.max(0,u-2.5*C)/u;e.vx=o*t,e.vz=c*t}},Se=(e,t,n)=>{if(!n.fwd)return;let r=N(e.vx,e.vz);for(let n=1;n<=4;n++){let[i,a]=P[n],o=e.vx*i+e.vz*a,[c,u]=[e.vx-o*i,e.vz-o*a];if(n!==e.wall&&N(c,u)>=7&&Math.abs(o)<=.4*r&&ue(e,t,n)){B(e,s.WALLRUN),e.wall=n,[e.vx,e.vz]=[c,u],e.vy=Math.min(e.vy,3),e.jumps=1,e.dashes=1,e.coyote=0,e.ev|=l.WALLRUN_START;return}}},Ce=(e,t)=>{B(e,s.HANG),e.wall=t.side,e.edge=A(t.top),t.side<=c.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|=l.GRAB},we=(e,t,n)=>{let r=e.mode===s.GROUND;if(n.dash&&e.dash===0&&(r||(e.mode===s.AIR||e.mode===s.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===s.WALLRUN&&(B(e,s.AIR),e.ev|=l.WALLRUN_END)),e.vx=t*16,e.vz=i*16,e.dash=60,e.ev|=l.DASH}let a=e.dash>50;e.mode===s.WALLRUN&&xe(e,t,n),L(e.mode)&&Te(e,t,n,a),e.mode===s.AIR&&Ee(e,t,n,a);let u=a&&e.vy<=0?0:e.mode===s.WALLRUN?.15:1,d=e.mode,f=_e(e,t,ee(e),u,L(d));if(f>=0){if(!L(e.mode)){if(e.ev|=l.LAND|(e.mode===s.WALLRUN?l.WALLRUN_END:0),e.fall=f,e.jumps=1,e.dashes=1,e.wall=c.NONE,n.keys&o.CROUCH){let t=N(e.vx,e.vz)>=i;B(e,t?s.SLIDE:s.CROUCH),e.ev|=t?l.SLIDE_START:0}else B(e,s.GROUND)}e.coyote=6}else L(e.mode)&&(e.ev|=e.mode===s.SLIDE?l.SLIDE_END:0,B(e,s.AIR));if(e.mode===s.AIR){let r=de(e,t);r?Ce(e,r):Se(e,t,n)}},Te=(e,n,a,c)=>{let u=(a.keys&o.CROUCH)!==0;if(e.buffer>0&&(e.mode===s.GROUND||oe(e,n))){e.ev|=e.mode===s.SLIDE?l.SLIDE_END:0,B(e,s.AIR),ve(e,7);return}let d=N(e.vx,e.vz);if(e.mode===s.GROUND&&u){let t=d>=i;B(e,t?s.SLIDE:s.CROUCH),e.ev|=t?l.SLIDE_START:0}else e.mode===s.SLIDE&&(e.t>=60||d<4.5)?(e.ev|=l.SLIDE_END,B(e,!u&&oe(e,n)?s.GROUND:s.CROUCH)):e.mode===s.SLIDE&&!u&&oe(e,n)?(e.ev|=l.SLIDE_END,B(e,s.GROUND)):e.mode===s.CROUCH&&!u&&oe(e,n)&&B(e,s.GROUND);if(!c){if(e.mode===s.SLIDE){let t=Math.max(0,d-4*C)/d;e.vx*=t,e.vz*=t}else if(e.mode===s.CROUCH)ge(e,he(e,n,a,r),3);else{let r=(a.keys&o.SPRINT)!==0&&a.fwd;ge(e,he(e,n,a,t),r?9:6)}}},Ee=(e,t,n,r)=>{if(e.buffer>0&&(e.coyote>0?ve(e,7):e.jumps>0&&!pe(e,t)&&(e.jumps--,ve(e,6),e.ev=e.ev&~l.JUMP|l.DOUBLE)),r||!n.wx&&!n.wz)return;let i=N(e.vx,e.vz);e.vx+=n.wx*14*C,e.vz+=n.wz*14*C,me(e,Math.max(i,6))},De=(e,t,r)=>{e.yaw=O(t.yaw),e.pitch=Math.max(-1.55,Math.min(n,t.pitch));let i=(t.keys&o.FORWARD?1:0)-(t.keys&o.BACK?1:0),a=(t.keys&o.RIGHT?1:0)-(t.keys&o.LEFT?1:0),c=N(i,a)||1,[l,u]=k(e.yaw),d=n=>(t.keys&n)!==0&&(e.held&n)===0,f={keys:t.keys,jump:d(o.JUMP),dash:d(o.DASH),fwd:i>0,wx:(l*i-u*a)/c,wz:(u*i+l*a)/c,fx:l,fz:u},p=e.mode;if(e.ev=0,e.fall=0,f.jump&&(e.buffer=7),e.dash>0&&(e.dash--,e.dash===50&&me(e,10)),e.mode===s.HANG&&ye(e,r,f),e.mode===s.CLIMB?be(e,r):e.mode!==s.HANG&&we(e,r,f),e.y<r.def.floor){let{yaw:t,pitch:n,id:i}=e;Object.assign(e,I(i,r,i),{yaw:t,pitch:n})}e.t=e.mode===p?Math.min(255,e.t+1):e.t,e.buffer=Math.max(0,e.buffer-1),e.mode===s.AIR&&p===s.AIR&&(e.coyote=Math.max(0,e.coyote-1)),e.held=t.keys&(o.JUMP|o.DASH),e.ground=L(e.mode),e.x=A(e.x),e.y=A(e.y),e.z=A(e.z),e.vx=A(e.vx),e.vy=A(e.vy),e.vz=A(e.vz),e.edge=A(e.edge)},Oe=65536/(2*Math.PI),ke=e=>Math.round(e*Oe)&65535,Ae=e=>Math.max(-32768,Math.min(32767,Math.round(e))),je=e=>Ae(e*1e4),Me=e=>e/1e4,Ne=e=>e/Oe,Pe=(e=0)=>Math.round(e*256)&16777215,Fe=e=>({...e,yaw:Ne(ke(e.yaw)),pitch:Me(je(e.pitch)),...e.view!==void 0&&{view:Pe(e.view)/256}}),Ie=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,ke(e.yaw)),t.setInt16(6,je(e.pitch));let n=Pe(e.view);return t.setUint16(8,n>>8),t.setUint8(10,n&255),t.buffer},Le=e=>{if(e.byteLength<4)return null;let t=new DataView(e),n=t.getUint8(3);if(t.getUint8(0)!==2||e.byteLength!==4+39*n)return null;let r=[];for(let e=0;e<n;e++){let n=4+e*39,i=t.getUint8(n+35),a=t.getUint8(n+38),c=i&7;r.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:Ne(t.getUint16(n+29)),pitch:Me(t.getInt16(n+31)),ack:t.getUint16(n+33),ground:c===s.GROUND||c===s.SLIDE||c===s.CROUCH,mode:c,wall:i>>3&7,jumps:i>>6&1,dashes:i>>7,t:t.getUint8(n+36),dash:t.getUint8(n+37),coyote:a&7,buffer:a>>3&7,held:(a&64?o.JUMP:0)|(a&128?o.DASH:0),ev:0,fall:0})}return{tick:t.getUint16(1),players:r}},Re=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},V=44100,ze=([e,t,n,r,i,a,o,s,c,l,u],d)=>{let f=new Float32Array(Math.ceil((r+i+a)*V)),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/V;p+=t*2**(n*_)*(_>c?l:1)*(1+o*Math.sin(_*44))/V,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},H={STEP:0,WALLSTEP:1,JUMP:2,DOUBLE:3,DASH:4,LAND:5,GRAB:6,SCUFF:7,WIND:8,SCRAPE:9},Be=[[[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]]],Ve=[H.WIND,H.SCRAPE],He=(e,t=Be)=>{let n=t[e].map((t,n)=>[ze(t,e*9+n),Math.round((t[11]??0)*V)]);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)))},Ue=(e,t=V/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])},We=V*60/108,Ge=We/4,Ke=4,qe=[2,150,-6,.002,0,.25,0,1,0,1,1],Je=[3,9e3,0,.002,0,.15,0,.5,0,1,.5],Ye=[3,3e4,0,.001,0,.04,0,.7,0,1,.15],Xe=()=>{let e=new Float32Array(We*4*Ke),t={},n=(n,r)=>(t[String(r)]??=ze(r,1)).forEach((t,r)=>e[(n*Ge+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,qe),`....x.......x...`[t]==`x`&&n(e,Je),t%2==0){n(e,Ye);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)},Ze=40,Qe=24,$e=.5,et=`tiny-fps:muted`,tt=()=>{let e=!1;return{unlock:()=>{},listen:()=>{},play:()=>{},loop:()=>({set:()=>{}}),mute:t=>{e=t},get muted(){return e},destroy:()=>{}}},nt=(e=Be)=>{let t;try{t=new AudioContext}catch{return tt()}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,$e),a=[],o=!1,s=/* @__PURE__ */ new Set,c=[0,0,0],l=0,u=!1,d=e=>{let n=t.createBuffer(1,e.length,V);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=He(n,e);a[n]=d(Ve.includes(n)?Ue(r):r)});let t=f(d(Xe()));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/Ze)**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>=Qe){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(()=>{})}},rt=()=>{try{return localStorage.getItem(et)==`1`}catch{return!1}},it=e=>{e.mute(!e.muted);try{localStorage.setItem(et,e.muted?`1`:`0`)}catch{}return e.muted},at=(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]]},ot=[[-1,-1],[1,-1],[1,1],[-1,-1],[1,1],[-1,1]],st=(e,[t,n,r],[i,a,o],s,c,l=-1)=>{let[u,d]=[Math.sin(s),Math.cos(s)],f=(e,t)=>[e*d+t*u,-e*u+t*d];for(let s=0;s<3;s++)for(let u of[-1,1]){let[d,p]=[(s+1)%3,(s+2)%3],m=[0,0,0];m[s]=u;let[h,g]=f(m[0],m[2]);for(let[_,v]of ot){let y=[0,0,0];[y[s],y[d],y[p]]=[u,_,v];let[b,x]=f(y[0]*i,y[2]*o);e.push(t+b,n+y[1]*a,r+x,h,m[1],g,c[0],c[1],l,c[2])}}},ct=(e,t,n=[0,0,0])=>{let r=[];for(let i=1;i<e.length;i++){let[[a,o],[s,c]]=[e[i-1],e[i]],l=Math.hypot(s-a,c-o);if(!l)continue;let[u,d]=[(c-o)/l,-(s-a)/l],f=(e,i,a)=>{let[o,s]=[Math.cos(e*w/t),Math.sin(e*w/t)];r.push(n[0]+i*o,n[1]+i*s,n[2]-a,u*o,u*s,-d)};for(let e=0;e<t;e++)for(let[t,n,r]of[[e,a,o],[e+1,a,o],[e+1,s,c],[e,a,o],[e+1,s,c],[e,s,c]])f(t,n,r)}return r},lt=(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]}),ut=(e,t,n,[r,i,a],o,s,c=[1,1,1])=>{let[l,u,d]=typeof s==`number`?[s,s,s]:s,[f,p,m,h,g,_,v,y,b]=[...r,...i,...a],x=n[0]+f*o[0]+h*o[1]+v*o[2],S=n[1]+p*o[0]+g*o[1]+y*o[2],C=n[2]+m*o[0]+_*o[1]+b*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,w]=[t[n+3],t[n+4],t[n+5]];e.push(x+f*r+h*i-v*a,S+p*r+g*i-y*a,C+m*r+_*i-b*a,f*o+h*s-v*w,p*o+g*s-y*w,m*o+_*s-b*w,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]},ft=2.2,pt=.5,mt=-.15,[ht,gt,_t]=[.35,.38,.15],[vt,yt]=[.43,.45],bt=[.95,.22,.1],xt=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],St=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],Ct=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],U=(e,t,n)=>[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n],wt=e=>{let t=Math.hypot(...e)||1;return[e[0]/t,e[1]/t,e[2]/t]},Tt=(e,t,n,r,i)=>{let a=xt(t,e),o=wt(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=Ct(n,o),d=wt([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]]},Et=(e,t,n,r)=>lt(ct(e,t,r),n),Dt=[[0,0],[.9,.04],[1,.15],[.78,.95],[0,1]],Ot=[.07,.075,.09],kt=[.2,.19,.2],At=Et(Dt,5,Ot),jt=[...At,...Et([[.97,.5],[.9,.66]],5,bt)],Mt=Et(Dt,4,[.14,.15,.19]),Nt=[-1,1].map(e=>[...Et([[0,0],[.8,.05],[1,.3],[.9,.82],[0,1]],5,kt),...Et([[.4,0],[.35,.5],[0,.55]],4,kt,[-e*1.05,.1,-.05])]),[Pt,Ft]=[Ot,[.6,.62,.68]],It=(e,t,n,r,i,a,o=1)=>{let s=xt(r,n),c=Math.hypot(...s);ut(e,t,n,dt(wt(s),i),[0,0,0],[a*o,a,c])},Lt=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],W=(e,t,n,r,i,a,o)=>[[e*t,n,r],[e*i,a,o]],G=([e,t],[n,r],i)=>[U(e,n,i),U(t,r,i)],Rt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),zt={sprint:6,air:12,dash:14,hang:16,climb:12,wall:10,slide:10,low:12,amp:8},Bt={jump:5,tuck:4,land:7},Vt=()=>{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,c=e=>e==s.GROUND||e==s.WALLRUN||e==s.CROUCH,u=(u,{ev:d,fall:f},p)=>{if(!u){e=void 0;return}let m=e&&c(e.mode)&&c(u.mode)?Math.hypot(u.x-e.x,u.z-e.z):0,h=c(u.mode)&&m<1;i+=h?m*(ft-.6*t.sprint):0,e={...u};let g={sprint:+te(u),air:+(u.mode==s.AIR&&u.dash<=50),dash:+(u.dash>50),hang:+(u.mode==s.HANG),climb:+(u.mode==s.CLIMB),wall:+(u.mode==s.WALLRUN),slide:+(u.mode==s.SLIDE),low:+(u.mode==s.SLIDE||u.mode==s.CROUCH),amp:c(u.mode)?Rt(z(u)/9):0};for(let e of Object.keys(zt))t[e]+=(g[e]-t[e])*(1-Math.exp(-p*zt[e]));d&l.JUMP&&(n.jump=1),d&l.DOUBLE&&(n.tuck=1),d&l.LAND&&(n.land=Rt(f/12,.3));for(let e of Object.keys(Bt))r[e]+=(n[e]-r[e])*(1-Math.exp(-p*24)),n[e]*=Math.exp(-p*Bt[e]);let[_,v]=Lt[u.wall];a+=(Rt(_*Math.cos(u.yaw)-v*Math.sin(u.yaw),-1,1)-a)*(1-Math.exp(-p*10)),(u.mode==s.HANG||u.mode==s.CLIMB)&&u.edge&&(o={x:u.x,z:u.z,y:u.edge,dx:_,dz:v})},d=(n,s,c,l=0)=>{if(!e||Math.hypot(...xt(n,[e.x,e.y+R(e),e.z]))>pt)return;let[u,d,f]=at(s,c,l),p=e=>[Ct(e,u),Ct(e,d),Ct(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=>St(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=U([.27,-.27,.46],[.2,-.16,.44],t.sprint),u=W(e,l[0],l[1]+.08*y*c,l[2]+.1*y*c,.7,-1,-.5);u=G(u,W(e,.4,-.2,.36,.8,-.8,-.3),t.air),u=G(u,W(e,.3,.04,.5,.6,-1,-.2),r.jump),u=G(u,W(e,.15,-.24,.28,.9,-.4,-.6),r.tuck),u=G(u,W(e,.42,-.4,.3,1,-1,-.2),r.land),u=G(u,W(e,.13,-.1,.64,.7,-1,-.3),t.dash);let d=W(e,.4,-.2+.02*Math.sin(i*2),.52,.4,-1,-.5);u=G(u,d,t.wall*Rt(a*e)),u=G(u,e>0?W(1,.46,-.32,.4,1,-.4,-.5):W(1,-.3,-.12,.5,-.8,-.6,-.3),t.slide);let f;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(xt(a,n));u=G(u,[[s,Math.max(c,-.36),Math.max(l,.3)],[e*.5,-1,-.4]],b),f=p([o.dx,-.15,o.dz])}let v=[e*(.15-.05*b),-.22+.08*b,-.2+.12*b],[x,S]=Tt(v,u[0],u[1],ht,gt),C=wt(xt(S,x));return{root:h(v),mid:h(x),end:h(S),dir:m(f?U(C,wt(f),b):C)}}),S=U(U([0,.88,-.12],[0,.46,-.2],t.low),[0,.26,-.4],t.slide);S[1]-=.22*r.land;let C=U(U([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=U(s,[e*.12,.3,e*.2],t.air),s=U(s,[e*.12,.62,.1],r.tuck),s=U(s,[e*.1,.28,-.4],t.dash),s=U(s,[e*.1,.12,-.12],t.hang),s=U(s,e>0?[.1,.5,.2]:[-.1,.1,-.1],t.climb),s=U(s,[e*.11,.2,.84+.08*e],t.slide);let c=[S[0]+e*.11,S[1],S[2]],[l,u]=Tt(c,s,[e*.15,.2,1],vt,yt);return{root:v(c),mid:v(l),end:v(u),dir:[-g,0,-_]}}),torso:[v(S),v(C)],grip:b,low:t.low}};return{update:u,rig:d,draw(e,t,n,r,i=0){let a=d(t,n,r,i);if(!a)return;let[o]=at(n,r,i),s=[Math.cos(n),0,-Math.sin(n)],[c,l]=a.torso;st(e,U(c,l,.5),[.2,Math.abs(l[1]-c[1])/2,.1],n,Pt);for(let{root:t,mid:i,end:o,dir:c}of r<mt||a.low>.2?a.legs:[])It(e,Mt,t,i,s,.075),It(e,Mt,i,o,s,.06),st(e,[o[0]+c[0]*.07,o[1]-.03,o[2]+c[2]*.07],[.055,.035,.12],n,Ft);a.arms.forEach(({root:t,mid:n,end:r,dir:i},s)=>{It(e,At,t,n,o,.046*(1-.4*a.grip)),It(e,jt,n,r,o,.038*(1-.3*a.grip)),ut(e,Nt[s],r,dt(i,o),[0,0,0],[.04,.036,_t])})}}},Ht=e=>.6+.2*e,Ut=e=>e?.mode===s.GROUND||e?.mode===s.CROUCH,Wt=e=>Ut(e)||e?.mode===s.WALLRUN,Gt=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],Kt=e=>.02+.0025*e,qt=.006,Jt=.03,Yt=.14,Xt=.05,Zt=5,Qt=9,$t=6.5,en=.25,tn=.22,nn=.9,rn=4,an=1,on=.12,sn=24,cn=15.7,ln=.45,un=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),dn=(e,t)=>{let n=Math.ceil(t*120);for(let r=0;r<n;r++)e[1]+=(-15.7*cn*e[0]-2*ln*cn*e[1])*(t/n),e[0]+=e[1]*(t/n)},fn=()=>{let e=0,t=0,n=0,r=0,i=0,a,c,u=[0,0],d=[0,0],f={dy:0,pitch:0,roll:0,fov:0,lines:0,stride:0,update(p,m,h,g={ev:0,fall:0}){let _=e=>Math.min(1,h*e),v=p?z(p):0,y=p&&c&&Wt(p)&&Wt(c)?Math.hypot(p.x-c.x,p.z-c.z):0;y<1&&(f.stride+=y/Ht(v)),e+=((Ut(p)&&y>.5*h&&y<1?1:0)-e)*_(10),c=p,g.ev&l.LAND&&(u[1]-=tn*Math.min(g.fall,20)),g.ev&l.CLIMB&&(u[1]-=tn*rn),g.ev&(l.JUMP|l.DOUBLE)&&(u[1]+=nn),g.ev&l.GRAB&&(d[1]-=an),dn(u,h),dn(d,h);let b=p?R(p):0;a=p?a===void 0?b:a+(b-a)*_(14):void 0,f.dy=(a??0)-b+u[0]-Math.cos(f.stride*2*Math.PI)*Kt(v)*e,i+=((p?.mode===s.CLIMB?on*Math.sin(Math.PI*un(p.t/sn)):0)-i)*_(10),f.pitch=d[0]+i;let x=p?.mode===s.WALLRUN?Gt[p.wall]:[0,0],S=p?x[0]*Math.cos(p.yaw)-x[1]*Math.sin(p.yaw):0,C=+!!(m&o.RIGHT)-!!(m&o.LEFT);t+=(C*Jt+S*Yt+(p?.mode===s.SLIDE?Xt:0)-t)*_(8),f.roll=t+Math.sin(f.stride*Math.PI)*qt*e;let w=!!p&&p.dash>50;n+=(+w-n)*_(w?40:6),r+=(un((v-6)/3)-r)*_(4),f.fov=r*Zt+n*Qt,f.lines+=(un((v-$t)/(9-$t))*en+n*.75-f.lines)*_(8)}};return f},pn=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),mn=e=>{let t=e.loop(H.WIND),n=e.loop(H.SCRAPE),r=0,i=/* @__PURE__ */ new Map,a=(t,n,r)=>{let i=te(t);e.play(t.mode===s.WALLRUN?H.WALLSTEP:H.STEP,r,i||t.mode===s.WALLRUN?1:t.mode===s.CROUCH?.35:.6,(i?.92:1)*(n&1?1.06:.94))},o=(t,n)=>e.play(H.LAND,n,pn(t/14,.2),1.25-.5*pn(t/20));return{me(i,c,u){let d=Math.floor(u),f=d>r;if(r=d,!i||e.muted)return;f&&a(i,d);for(let[t,n]of[[l.JUMP,H.JUMP],[l.DOUBLE,H.DOUBLE],[l.DASH,H.DASH],[l.GRAB,H.GRAB],[l.CLIMB,H.SCUFF]])c.ev&t&&e.play(n);c.ev&l.LAND&&o(c.fall);let p=pn((Math.hypot(i.vx,i.vy,i.vz)-4)/12);t.set(.55*p**1.5,.6+.9*p);let m=pn(z(i)/9);n.set(i.mode===s.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(Wt(n)&&Wt(t.p)&&r<1){let i=Math.floor(t.stride);t.stride+=r/Ht(z(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)}}},hn=`h5,aside{position:absolute;margin:0;padding:0;pointer-events:none;user-select:none;white-space:pre-line}h5{top:8px;right:12px;font-size:12px}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}`,gn=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>E / right click<td>dash<tr><td>C<td>crouch, slide when fast<tr><td>M<td>mute</table><strong></strong></aside><h5 hidden>Muted (M)</h5>`);let t=t=>e.querySelector(t),[n,r]=[`h5`,`aside`].map(e=>t(e)),[i,a]=[`aside span`,`strong`].map(e=>t(e)),o=(e,t)=>e.textContent!=t&&(e.textContent=t);return{title(e,t){r.hidden=!e,o(i,t),o(a,e)},mute:e=>n.hidden=!e}},_n=.0025,vn=Math.PI*2,yn={KeyW:o.FORWARD,ArrowUp:o.FORWARD,KeyS:o.BACK,ArrowDown:o.BACK,KeyA:o.LEFT,ArrowLeft:o.LEFT,KeyD:o.RIGHT,ArrowRight:o.RIGHT,Space:o.JUMP,ShiftLeft:o.SPRINT,ShiftRight:o.SPRINT,KeyE:o.DASH,KeyC:o.CROUCH},bn=2,xn=e=>yn[e]??0,Sn=(e,t=()=>{})=>{let r=new AbortController,i=(e,t,n)=>e.addEventListener(t,n,{signal:r.signal}),a={yaw:0,pitch:0,keys:0,locked:()=>e.getRootNode().pointerLockElement==e,destroy:()=>r.abort()};i(e,`click`,()=>{Promise.resolve(e.requestPointerLock()).catch(()=>{})}),i(document,`mousemove`,e=>{a.locked()&&(a.yaw=((a.yaw-e.movementX*_n)%vn+vn)%vn,a.pitch=Math.max(-1.55,Math.min(n,a.pitch-e.movementY*_n)))}),i(document,`keydown`,e=>{let n=xn(e.code);e.code==`KeyM`&&!e.repeat&&a.locked()&&t(),n&&a.locked()&&(a.keys|=n,e.preventDefault())}),i(document,`keyup`,e=>{a.keys&=~xn(e.code)}),i(document,`mousedown`,e=>{e.button===bn&&a.locked()&&(a.keys|=o.DASH,e.preventDefault())}),i(document,`mouseup`,e=>{e.button===bn&&(a.keys&=~o.DASH)}),i(document,`contextmenu`,e=>a.locked()&&e.preventDefault());let s=()=>{a.keys=0};return i(window,`blur`,s),i(document,`pointerlockchange`,()=>a.locked()||s()),a},Cn=120,wn=16,K=e=>{let t={...e};return delete t.ack,t},Tn=(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}),En=(e,t,n)=>O(e+(((t-e+Math.PI)%w+w)%w-Math.PI)*n),Dn=(e,t)=>(t-e&65535)<32768,On=(e,t,n)=>({...t,...Tn(e,t,n),yaw:En(e.yaw,t.yaw,n),pitch:e.pitch+(t.pitch-e.pitch)*n}),kn=e=>{let t,n=0,r=[],i,a,o=[],s=0,c=0,l=e=>{let t=e-100,n=0;for(;n+1<o.length&&o[n+1].t<=t;)n++;let r=o[n],i=o[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}},u=e=>{if(!o.length)return;let{a:t,b:n,u:r}=l(e);return(t.s.tick+(n.s.tick-t.s.tick&65535)*r)%65536};return{you:e=>{t=e},step:(t,o)=>{let l=Fe({...t,seq:n,view:o===void 0?void 0:u(o)});return n=n+1&65535,r.push(l),r.length>Cn&&r.shift(),i&&(a=K(i),De(i,l,e),s|=i.ev,c=Math.max(c,i.fall)),l},snapshot:(n,s)=>{o.push({t:s,s:n}),o.length>wn&&o.shift();let c=n.players.find(e=>e.id===t);c&&(r=r.filter(e=>!Dn(e.seq,c.ack)),i=K(c),a=K(i),r.forEach((t,n)=>{n===r.length-1&&(a=K(i)),De(i,t,e)}))},events:()=>{let e={ev:s,fall:c};return s=c=0,e},me:e=>i&&a?On(a,i,Math.max(0,Math.min(1,e))):void 0,others:e=>{let n=o.at(-1);if(!n)return[];let{a:r,b:i,u:a}=l(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?On(K(t),K(n),a):K(n??t??e)})}}},An={SPOT:0,POINT:1},jn=e=>[],Mn=3.6,Nn=({x:e,y:t,z:n,yaw:r},i,a,o)=>{let[s,c]=[Math.sin(r),Math.cos(r)];return[e+i*c-o*s,t+a,n-i*s-o*c]},Pn=(e,t,n,r,i)=>{let a=e.get(t)??{x:n,z:r,walked:0,vx:0,vz:0},o=Math.hypot(n-a.x,r-a.z),s=i>0&&o<1?1-Math.exp(-i*8):0;return a.vx+=((n-a.x)/(i||1)-a.vx)*s,a.vz+=((r-a.z)/(i||1)-a.vz)*s,a.walked+=o<1?o:0,[a.x,a.z]=[n,r],e.set(t,a),a},Fn=e=>Math.min(1,Math.hypot(e.vx,e.vz)/2),In=(e,t)=>lt(ct(e,t),[1,1,1]),Ln=In([[0,0],[1,.05],[.65,1],[0,1]],5),Rn=In([[0,0],[.8,.05],[.55,.7],[1,.8],[.5,1],[0,1]],5),zn=In([[0,0],[.15,0],[.13,.25],[.22,.7],[.2,.95],[0,1]],6),Bn=In([[0,0],[.1,.06],[.155,.4],[.13,.8],[0,1]],8),Vn=(e,t,n,r,i,a,o,s=1)=>{let c=i.map((e,t)=>e-r[t]),l=Math.hypot(...c);ut(e,t,r,dt(c.map(e=>e/l),[Math.cos(n),0,-Math.sin(n)]),[0,0,0],[a*s,a,l],o)},Hn=(e,t,n,r,i,a,o,s=1)=>Vn(e,t,n.yaw,Nn(n,...r),Nn(n,...i),a,o,s),Un=([e,t,n],r,i,a,o)=>{let[s,c]=[t-a*Math.cos(r),n+a*Math.sin(r)];return[[e,s,c],[e,s-o*Math.cos(i),c+o*Math.sin(i)]]},Wn=(e,t,n)=>{let r=.55*Math.sin(t)*n;return Un(e,r,r-.9*Math.max(0,-Math.sin(t+.5))*n,.43,.45)},Gn=.88,Kn=(e,n,r,i,a)=>{let o=i*Mn,s=Gn-.08*Math.sin(o)**2*a,[c,l]=[r.map(e=>e*.45),[.1,.1,.12]],[u,d]=[[0,s,0],[0,s+.55,.02]];Hn(e,zn,n,u,d,1,r,1.25),Hn(e,Bn,n,d,[0,t,.02],1.1,c);let f=r.map(e=>.35+.65*e);st(e,Nn(n,0,d[1]+.17,.17),[.11,.035,.03],n.yaw,f,-2),st(e,Nn(n,0,s+.4,-.2),[.15,.2,.07],n.yaw,c);for(let t of[-1,1]){let i=[t*.12,s,0],[u,d]=Wn(i,o+(t>0?Math.PI:0),a);Hn(e,Ln,n,i,u,.1,c),Hn(e,Ln,n,u,d,.08,c),st(e,Nn(n,d[0],d[1]+.03,d[2]+.05),[.06,.03,.1],n.yaw,l);let f=[t*.27,s+.5,.02],p=.45*Math.sin(o+(t<0?Math.PI:0))*a,[m,h]=Un(f,p,p+.3,.34,.36);Hn(e,Ln,n,f,m,.07,r),Hn(e,Rn,n,m,h,.06,c)}},qn=Object.keys(u).length,q=(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},J=(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)=>q((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},Jn=(e,t,n,r,i)=>{let[a,o]=[0,.5];for(let s=0;s<r;s++,o/=2)a+=o*J(e*(1<<s),t*(1<<s),n<<s,i+s);return a/(1-o*2)},Y=(e,t,n)=>e.map((e,r)=>e+(t[r]-e)*n),X=(e,t)=>e.map(e=>e*t),Z=e=>Math.min(Math.max(e,0),1),Yn=Math.PI*2,Q=[];Q[u.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=J(e*16,t*16,16,5),c=.8+.4*s;return a<.05||o<.1?[X([165,160,150],.7+.3*c),.1+.1*s]:[X([170,78,56],(.8+.4*q(i,n,1))*c*(.85+.15*o)),.7+.2*s+.1*Z(Math.min(a-.05,o-.1)*12)]},Q[u.TILE]=(e,t)=>{let[n,r]=[Math.floor(e*4),Math.floor(t*4)],[i,a]=[e*4%1,t*4%1],o=J(e*16,t*16,16,7),s=.9+.2*o;return i<.05||a<.05?[X([85,85,80],s),.1]:[X([196,190,172],s*(.88+.08*(n+r&1)+.1*q(n,r,2))),.8+.1*o+.1*Z((Math.min(i,a)-.05)*14)]},Q[u.LAVA]=(e,t)=>{let n=Jn(e*4,t*4,4,4,11),r=Math.max(0,1-Math.abs(n-.5)*7)**2;return[Y(Y([55,8,4],[230,70,8],n),[255,215,90],r),.5]},Q[u.STONE]=(e,t)=>{let n=Jn(e*8,t*8,8,4,3);return[X([128,124,120],.45+.7*(n*1.3+.1*q(Math.floor(e*128),Math.floor(t*128),4))),Z(n*1.4-.2)]},Q[u.METAL]=(e,t)=>{let[n,r,i,a]=[Math.floor(e*2),Math.floor(t*2),e*2%1,t*2%1],o=Z((J(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=Z(1-u/.07),f=X([98,108,124],(.9+.2*J(e*32,t*32,32,9)+.12*q(n,r,6))*(1+.3*d)*(.65+.35*Z((u-.06)/.04)));return Math.min(i,a,1-i,1-a)<.03?[X([40,44,50],1+o),.05]:[Y(f,[105,68,45],o*.7),.5+.1*(1-o)+.4*d]},Q[u.WOOD]=(e,t)=>{let n=Math.floor(t*8),r=e*2+q(n,0,8)*2,[i,a,o]=[Math.floor(r)%2,r%1,t*8%1],s=q(n,i,3),c=.5+.5*Math.sin(Yn*(t*40+2.5*J(e*4,t*4,4,21)+s*7));return o<.08||a<.015?[[28,18,10],.05]:[Y([92,58,32],[158,106,62],c*.6+s*.35),.7+.15*c+.15*Z((o-.08)*15)]},Q[u.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=Z((.3*Jn(e*12,t*12,12,3,17)-.03-s)*12),u=J(e*64,t*64,64,19),d=X([128,126,118],(.7+.4*q(i,n,5))*(.7+.5*J(e*16,t*16,16,15)));return[Y(c?X(d,.45):d,Y([52,100,34],[96,148,56],u),l),c?.1+.6*l*u:.6+.2*Z(s*30)+.2*l*u]},Q[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=J(e*16,t*16,16,23);return i<.36?[[9,9,12],0]:[X(Y([104,108,116],[96,80,68],Z((o-.55)*4)),(a?1.25:1)-(.5-i)*2.2+.2*o),a?1:.6+.4*Z((i-.36)*12)]};var Xn=()=>{let e=new Uint8ClampedArray(qn*128*128*4);return Q.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},Zn=1<<18,Qn=2,$=1024,$n=.6,er=Math.tan(70*Math.PI/360),tr=4,nr=`#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);}`,Xt=`#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);}`,Zt=`#version 300 es
8
- precision highp float;uniform sampler2D S[4];uniform vec4 Y;in vec2 U;out vec4 o;
6
+ P=p;N=n;C=c;gl_Position=m*vec4(p,1);}`,rr=`#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);}`,ir=`#version 300 es
8
+ precision highp float;uniform sampler2D S[4];uniform vec4 Y;uniform float L;in vec2 U;out vec4 o;
9
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)));}
10
10
  #define T(k)texture(S[0],U+Y.xy*(k)).rgb
11
11
  void main(){
@@ -16,14 +16,16 @@ else{
16
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;
17
17
  vec2 q=U-.5;
18
18
  c=min(c,.6)+.4*(1.-exp(-max(c-.6,0.)/.4));
19
- c*=1.-.7*dot(q,q);
19
+ float a=atan(q.y,q.x)*24.,h=fract(sin(floor(a)*12.9898)*43758.5453);
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
+ c*=1.-(.7+.3*L)*dot(q,q);
20
22
  c=pow(c,vec3(.92))+(fract(sin(dot(gl_FragCoord.xy+Y.w,vec2(12.9898,78.233)))*43758.5453)-.5)*.03;}
21
- o=vec4(c,1);}`,Qt=[[.04,8],[.25,30],[0,1],[.08,10],[.8,48],[.06,12],[.3,20],[.7,40],[.1,24]],$t=`#version 300 es
23
+ o=vec4(c,1);}`,ar=[[.04,8],[.25,30],[0,1],[.08,10],[.8,48],[.06,12],[.3,20],[.7,40],[.1,24]],or=`#version 300 es
22
24
  precision highp float;precision highp sampler2DArray;precision highp sampler2DArrayShadow;
23
25
  in vec3 P,N;in vec4 C;uniform vec3 E;uniform float T,Z,Y;uniform int Q;
24
26
  uniform vec4 A[16],B[16],K[16],F;uniform vec3 G[16],H[5],O,X;uniform mat4 M[4],W;
25
27
  uniform sampler2DArray S;uniform sampler2DArrayShadow D;out vec4 o;
26
- const vec2 SP[${Qt.length}]=vec2[](${Qt.map(([e,t])=>`vec2(${e},${t})`)});
28
+ const vec2 SP[${ar.length}]=vec2[](${ar.map(([e,t])=>`vec2(${e},${t})`)});
27
29
  vec3 e(vec3 x){return 2.*(1.-exp(-.5*x));}
28
30
  void main(){
29
31
  if(Z<0.)return;
@@ -34,13 +36,13 @@ c=mix(c,H[4]*1.08,exp(-abs(h)*7.));
34
36
  c+=X*(.2*pow(k,24.)+.05*pow(k,4.)+2.*smoothstep(.9993,.9997,k));
35
37
  o=vec4(c,1);return;}
36
38
  float L=C.z,s=step(0.,L),I=floor(C.w*.5),g=step(abs(L-${u.LAVA}.),.5)+step(L,-1.5);
37
- vec4 t=texture(S,vec3(C.xy/${Gt}.+vec2(g*T*.01,0),max(L,0.)));
39
+ vec4 t=texture(S,vec3(C.xy/${Qn}.+vec2(g*T*.01,0),max(L,0.)));
38
40
  vec3 c=mix(vec3(C.xy,C.w),t.rgb,s);
39
41
  vec3 n=normalize(N),dx=dFdx(P),dy=dFdy(P),a=cross(dy,n),b=cross(n,dx);
40
42
  float h=t.a*s*0.06,det=dot(dx,a);
41
- float f=1.-smoothstep(.6,2.5,${128/Gt}.*max(length(dFdx(C.xy)),length(dFdy(C.xy))));
43
+ float f=1.-smoothstep(.6,2.5,${128/Qn}.*max(length(dFdx(C.xy)),length(dFdy(C.xy))));
42
44
  vec3 m=normalize(abs(det)*n-sign(det)*f*(dFdx(h)*a+dFdy(h)*b)+n*1e-9);
43
- vec2 R=SP[int(s>0.?L+.5:${Bt}.)];
45
+ vec2 R=SP[int(s>0.?L+.5:${qn}.)];
44
46
  vec3 y=mix(vec3(1),G[int(min(I,15.))]*(C.w-2.*I),s),V=normalize(E-P),w=normalize(n+m);
45
47
  float sd=max(dot(m,O),0.)*smoothstep(0.,.1,dot(n,O)),sv=1.;
46
48
  if(sd>0.&&g<1.){
@@ -63,4 +65,4 @@ w*=v/4.;}
63
65
  l+=K[i].rgb*w;
64
66
  sp+=K[i].rgb*w*pow(max(dot(m,normalize(d+V)),0.),R.y);}
65
67
  c=c*mix(e(l),vec3(1.4),g)+e(sp*R.x*(.4+.6*mix(1.,t.a,s)));
66
- o=vec4(mix(c,F.rgb,1.-exp(-F.a*length(P-E))),1.);}`,en=(e,t,n,r,i=0,a=qt,[o,s]=[.1,200])=>{let[c,l,u]=bt(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])},tn=(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)]},nn=({p:e,d:t,cone:n,range:r})=>en(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]),rn=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==vt.SPOT&&a<4?a++:-1;t.set([...e.p,e.range],o*4),n.set([...e.d,e.kind==vt.POINT?-9:e.cone],o*4),r.set([...e.color,s],o*4),s>=0&&i.set(nn(e),s*16)}),{n:o.length,maps:a,a:t,b:n,k:r,m:i}},an=(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/$],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])},on=({def:e})=>[...new Map([[`1,1,1`,[1,1,1]],...e.brushes.flatMap(({tint:e})=>e?[[`${e}`,e]]:[])]).values()].slice(0,16),sn=[[0,0],[1,0],[1,1],[0,0],[1,1],[0,1]],cn=e=>{let{brushes:t,floor:n}=e.def,r=[],i=on(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 sn){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},ln=({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],un=({fog:e,sky:t})=>e?[...[0,1,2].map(n=>e[n]+(t[1][n]-e[n])*Kt),e[3]]:[...t[1],0],dn=2073600,fn=(e,t,n)=>{let r=Math.min(n,2,Math.sqrt(dn/(e*t||1)));return[Math.round(e*r),Math.round(t*r)]},pn=(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=()=>fn(e.clientWidth,e.clientHeight,devicePixelRatio),l=cn(t),{sun:u,sky:d}=t.def,f=u.dir.map(e=>e/Math.hypot(...u.dir)),p=Ut(),m=l.length*4,h=m+Wt,g={},_,v,y,b,x={},S,C,w,T,E=[0,0],D=[],O=!1,k=/* @__PURE__ */ new Float32Array(16),A=()=>{i.bufferData(i.ARRAY_BUFFER,h,i.DYNAMIC_DRAW),i.bufferSubData(i.ARRAY_BUFFER,0,new Float32Array(l))},j=(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)]))]},M=(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}},N=(e,t)=>{D.splice(0).forEach(e=>e()),E=[e,t],w=M(e,t),T=[1,2,3].map(n=>[0,1].map(()=>M(e>>n||1,t>>n||1)));let n=n=>{let r=i.createRenderbuffer();return i.bindRenderbuffer(i.RENDERBUFFER,r),i.renderbufferStorageMultisample(i.RENDERBUFFER,Jt,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))},P=(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)},F=()=>{S=i.getExtension(`EXT_color_buffer_float`)?i.RGBA16F:i.RGBA8,D.length=0,E=[0,0],[b,x]=j(Xt,Zt,[`S`,`Y`]),i.uniform1iv(x.S,[0,1,2,3]),[y,g]=j(Yt,$t,[`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()),A(),[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,$,$,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,Bt,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),I();let[t,n]=c();t&&n&&N(t,n)},I=()=>{let e=on(t);i.uniform4fv(g.F,un(t.def)),i.uniform3fv(g.H,ln(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)};F();let L=e=>{e.preventDefault(),O=!0},R=()=>{F(),O=!1};return e.addEventListener(`webglcontextlost`,L),e.addEventListener(`webglcontextrestored`,R),{frame(t,a,o,u,d,p,x){let[S,D]=c();if(O||!S||!D)return;(e.width!=S||e.height!=D)&&(e.width=S,e.height=D),(E[0]!=S||E[1]!=D)&&N(S,D),k=en(t,a,o,S/D,p.roll);let j=[],M=performance.now()/1e3,F=Math.min(.1,M-r);r=M;for(let e of u){let t=Ot(n,e.id,e.x,e.z,F);zt(j,e,s(d.get(e.id)??`#888`),t.walked,kt(t))}m+j.length*4>h&&(h=m+j.length*8,A()),i.bufferSubData(i.ARRAY_BUFFER,m,new Float32Array(j));let I=rn(x),L=l.length/10,R=an(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,$,$),i.enable(i.POLYGON_OFFSET_FILL);for(let e=0;e<=I.maps;e++)i.framebufferTextureLayer(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,_,0,e),i.uniformMatrix4fv(g.m,!1,e?I.m.subarray(e*16-16,e*16):R),i.clear(i.DEPTH_BUFFER_BIT),i.drawArrays(i.TRIANGLES,0,L+j.length/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,S,D),i.uniformMatrix4fv(g.m,!1,k),i.uniformMatrix4fv(g.W,!1,R),i.uniform3fv(g.E,t),i.uniform1f(g.T,performance.now()/1e3),i.uniform1f(g.Z,1),i.uniform1i(g.Q,I.n),i.uniform4fv(g.A,I.a),i.uniform4fv(g.B,I.b),i.uniform4fv(g.K,I.k),i.uniformMatrix4fv(g.M,!1,I.m),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT);let[ee,z,B]=bt(a,o,p.roll);i.uniform3fv(g.J,[ee.map(e=>e*qt*(S/D)),z.map(e=>e*qt),B].flat()),i.uniform1f(g.Y,1),i.drawArrays(i.TRIANGLES,0,3),i.uniform1f(g.Y,0),i.drawArrays(i.TRIANGLES,0,L+j.length/10),i.bindFramebuffer(i.READ_FRAMEBUFFER,C),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,w.f),i.blitFramebuffer(0,0,S,D,0,0,S,D,i.COLOR_BUFFER_BIT,i.NEAREST),i.useProgram(b),P(T[0][0],0,1/S,1/D,w),T.forEach(([e,t],n)=>{P(t,1,1/t.w,0,T[n&&n-1][0]),P(e,1,0,1/e.h,t)}),P(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)=>tn(k,e,t,n),destroy(){e.removeEventListener(`webglcontextlost`,L),e.removeEventListener(`webglcontextrestored`,R),i.getExtension(`WEBGL_lose_context`)?.loseContext()}}},mn=1/60,hn=5,gn=(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}`+rt+`i{left:50%;top:50%;width:6px;height:6px;margin:-3px;border-radius:50%;background:#fff;box-shadow:0 0 0 1px #0008}p{top: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=it(s),l={roster:[],open:[],close:[]},u=e=>l[e].forEach(e=>e()),d=y(m),f=_t(d),p=Xe();p.mute(Ze()),c.mute(p.muted);let h=ut(a,()=>c.mute(Qe(p)));a.addEventListener(`click`,()=>p.unlock());let g=nt(),_;try{_=pn(a,d)}catch{}let v=[],b=/* @__PURE__ */ new Map,x=/* @__PURE__ */ new Map,C=/* @__PURE__ */ new Map,w=!1,T=_?``:`WebGL2 is not available`,E=!1,D=performance.now(),O=0,k=0,A=!1,j=n.socket??new WebSocket(n.url);j.binaryType=`arraybuffer`,j.onopen=()=>{w=!0,j.send(JSON.stringify({t:`join`,name:n.name})),u(`open`)},j.onclose=()=>{w=!1,T||=`Connection closed`,u(`close`)},j.onmessage=({data:e})=>{if(typeof e!=`string`){let t=Ne(e);t&&f.snapshot(t,performance.now());return}let t=Pe(e);t?.t==`roster`?(v=t.players,b=new Map(v.map(e=>[e.id,e.color])),x=new Map(v.map(e=>[e.id,e.name])),f.you(t.you),o.textContent=`Players: ${v.length}`,u(`roster`)):t?.t==`full`&&(T=`Room is full`)};let M=e=>{let t=C.get(e);return t||(C.set(e,t=document.createElement(`b`)),s.append(t)),t},N=()=>{k=requestAnimationFrame(N);let e=performance.now(),n=D;if(O=Math.min(O+(e-D)/1e3,hn*mn),D=e,!E){let e=f.me(0);e&&([h.yaw,h.pitch,E]=[e.yaw,e.pitch,!0]),O=0}for(;E&&O>=mn;O-=mn){let t=f.step({keys:h.keys,yaw:h.yaw,pitch:h.pitch},e);w&&j.send(Me(t))}let r=f.me(O/mn),i=f.others(e),a=r?[r.x,r.y+ee(r),r.z]:[0,0,0];p.listen(a,h.yaw);let o=Math.min((e-n)/1e3,.1);g.update(r,h.keys,o),r&&_&&_.frame([a[0],a[1]+g.bob,a[2]],h.yaw,h.pitch,i,b,g,yt({eye:[a[0],a[1]+g.bob,a[2]],yaw:h.yaw,pitch:h.pitch,others:i,t:e/1e3}));let s=/* @__PURE__ */ new Set;for(let e of i){let n=[e.x,e.y+t+.3,e.z],i=r&&!S(d,a,n)?_?.project(...n):void 0,o=M(e.id);s.add(e.id),o.hidden=!i,i&&(o.style.left=i[0]*100+`%`,o.style.top=i[1]*100+`%`);let c=x.get(e.id)??``;o.textContent!=c&&(o.textContent=c)}for(let[e,t]of C)s.has(e)||(t.remove(),C.delete(e));c.title(T||(w?E?h.locked()?``:`Click to play`:`Joining…`:`Connecting…`),d.def.name??``)};return k=requestAnimationFrame(N),{on:(e,t)=>void l[e].push(t),players:()=>v,destroy(){A||(A=!0,cancelAnimationFrame(k),h.destroy(),p.destroy(),_?.destroy(),j.onopen=j.onclose=j.onmessage=null,j.close(),document.exitPointerLock(),r.remove())}}};export{gn as tinyFps};
68
+ o=vec4(mix(c,F.rgb,1.-exp(-F.a*length(P-E))),1.);}`,sr=(e,t,n,r,i=0,a=er,[o,s]=[.1,200])=>{let[c,l,u]=at(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])},cr=(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)]},lr=({p:e,d:t,cone:n,range:r})=>sr(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]),ur=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==An.SPOT&&a<4?a++:-1;t.set([...e.p,e.range],o*4),n.set([...e.d,e.kind==An.POINT?-9:e.cone],o*4),r.set([...e.color,s],o*4),s>=0&&i.set(lr(e),s*16)}),{n:o.length,maps:a,a:t,b:n,k:r,m:i}},dr=(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/$],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])},fr=({def:e})=>[...new Map([[`1,1,1`,[1,1,1]],...e.brushes.flatMap(({tint:e})=>e?[[`${e}`,e]]:[])]).values()].slice(0,16),pr=[[0,0],[1,0],[1,1],[0,0],[1,1],[0,1]],mr=e=>{let{brushes:t,floor:n}=e.def,r=[],i=fr(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 pr){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},hr=({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],gr=({fog:e,sky:t})=>e?[...[0,1,2].map(n=>e[n]+(t[1][n]-e[n])*$n),e[3]]:[...t[1],0],_r=2073600,vr=(e,t,n)=>{let r=Math.min(n,2,Math.sqrt(_r/(e*t||1)));return[Math.round(e*r),Math.round(t*r)]},yr=(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=()=>vr(e.clientWidth,e.clientHeight,devicePixelRatio),l=mr(t),{sun:u,sky:d}=t.def,f=u.dir.map(e=>e/Math.hypot(...u.dir)),p=Xn(),m=l.length*4,h=m+Zn,g={},_,v,y,b,x={},S,C,w,T,E=[0,0],D=[],O=!1,k=/* @__PURE__ */ new Float32Array(16),A=()=>{i.bufferData(i.ARRAY_BUFFER,h,i.DYNAMIC_DRAW),i.bufferSubData(i.ARRAY_BUFFER,0,new Float32Array(l))},j=(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)]))]},M=(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}},N=(e,t)=>{D.splice(0).forEach(e=>e()),E=[e,t],w=M(e,t),T=[1,2,3].map(n=>[0,1].map(()=>M(e>>n||1,t>>n||1)));let n=n=>{let r=i.createRenderbuffer();return i.bindRenderbuffer(i.RENDERBUFFER,r),i.renderbufferStorageMultisample(i.RENDERBUFFER,tr,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))},P=(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)},F=()=>{S=i.getExtension(`EXT_color_buffer_float`)?i.RGBA16F:i.RGBA8,D.length=0,E=[0,0],[b,x]=j(rr,ir,[`S`,`Y`,`L`]),i.uniform1iv(x.S,[0,1,2,3]),[y,g]=j(nr,or,[`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()),A(),[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,$,$,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,qn,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),I();let[t,n]=c();t&&n&&N(t,n)},I=()=>{let e=fr(t);i.uniform4fv(g.F,gr(t.def)),i.uniform3fv(g.H,hr(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)};F();let L=e=>{e.preventDefault(),O=!0},ee=()=>{F(),O=!1};return e.addEventListener(`webglcontextlost`,L),e.addEventListener(`webglcontextrestored`,ee),{frame(t,a,o,u,d,p,S,D){let[j,M]=c();if(O||!j||!M)return;(e.width!=j||e.height!=M)&&(e.width=j,e.height=M),(E[0]!=j||E[1]!=M)&&N(j,M);let F=Math.tan((70+p.fov)*Math.PI/360);k=sr(t,a,o,j/M,p.roll,F);let I=[],L=performance.now()/1e3,ee=Math.min(.1,L-r);r=L;for(let e of u){let t=Pn(n,e.id,e.x,e.z,ee);Kn(I,e,s(d.get(e.id)??`#888`),t.walked,Fn(t))}let R=I.length;D?.draw(I,t,a,o,p.roll),m+I.length*4>h&&(h=m+I.length*8,A()),i.bufferSubData(i.ARRAY_BUFFER,m,new Float32Array(I));let z=ur(S),te=l.length/10,ne=dr(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,$,$),i.enable(i.POLYGON_OFFSET_FILL);for(let e=0;e<=z.maps;e++)i.framebufferTextureLayer(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,_,0,e),i.uniformMatrix4fv(g.m,!1,e?z.m.subarray(e*16-16,e*16):ne),i.clear(i.DEPTH_BUFFER_BIT),i.drawArrays(i.TRIANGLES,0,te+R/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,M),i.uniformMatrix4fv(g.m,!1,k),i.uniformMatrix4fv(g.W,!1,ne),i.uniform3fv(g.E,t),i.uniform1f(g.T,performance.now()/1e3),i.uniform1f(g.Z,1),i.uniform1i(g.Q,z.n),i.uniform4fv(g.A,z.a),i.uniform4fv(g.B,z.b),i.uniform4fv(g.K,z.k),i.uniformMatrix4fv(g.M,!1,z.m),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT);let[re,ie,ae]=at(a,o,p.roll);i.uniform3fv(g.J,[re.map(e=>e*F*(j/M)),ie.map(e=>e*F),ae].flat()),i.uniform1f(g.Y,1),i.drawArrays(i.TRIANGLES,0,3),i.uniform1f(g.Y,0),i.drawArrays(i.TRIANGLES,0,te+R/10),I.length>R&&(i.clear(i.DEPTH_BUFFER_BIT),i.drawArrays(i.TRIANGLES,te+R/10,(I.length-R)/10)),i.bindFramebuffer(i.READ_FRAMEBUFFER,C),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,w.f),i.blitFramebuffer(0,0,j,M,0,0,j,M,i.COLOR_BUFFER_BIT,i.NEAREST),i.useProgram(b),P(T[0][0],0,1/j,1/M,w),T.forEach(([e,t],n)=>{P(t,1,1/t.w,0,T[n&&n-1][0]),P(e,1,0,1/e.h,t)}),i.uniform1f(x.L,p.lines),P(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)=>cr(k,e,t,n),destroy(){e.removeEventListener(`webglcontextlost`,L),e.removeEventListener(`webglcontextrestored`,ee),i.getExtension(`WEBGL_lose_context`)?.loseContext()}}},br=1/60,xr=5,Sr=(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}`+hn+`i{left:50%;top:50%;width:6px;height:6px;margin:-3px;border-radius:50%;background:#fff;box-shadow:0 0 0 1px #0008}p{top: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=gn(s),l={roster:[],open:[],close:[]},u=e=>l[e].forEach(e=>e()),d=y(m),f=kn(d),p=nt();p.mute(rt()),c.mute(p.muted);let h=Sn(a,()=>c.mute(it(p)));a.addEventListener(`click`,()=>p.unlock());let g=fn(),_=mn(p),v=Vt(),b;try{b=yr(a,d)}catch{}let x=[],C=/* @__PURE__ */ new Map,w=/* @__PURE__ */ new Map,T=/* @__PURE__ */ new Map,E=!1,D=b?``:`WebGL2 is not available`,O=!1,k=performance.now(),A=0,j=0,M=!1,N=n.socket??new WebSocket(n.url);N.binaryType=`arraybuffer`,N.onopen=()=>{E=!0,N.send(JSON.stringify({t:`join`,name:n.name})),u(`open`)},N.onclose=()=>{E=!1,D||=`Connection closed`,u(`close`)},N.onmessage=({data:e})=>{if(typeof e!=`string`){let t=Le(e);t&&f.snapshot(t,performance.now());return}let t=Re(e);t?.t==`roster`?(x=t.players,C=new Map(x.map(e=>[e.id,e.color])),w=new Map(x.map(e=>[e.id,e.name])),f.you(t.you),o.textContent=`Players: ${x.length}`,u(`roster`)):t?.t==`full`&&(D=`Room is full`)};let P=e=>{let t=T.get(e);return t||(T.set(e,t=document.createElement(`b`)),s.append(t)),t},F=()=>{j=requestAnimationFrame(F);let e=performance.now(),n=k;if(A=Math.min(A+(e-k)/1e3,xr*br),k=e,!O){let e=f.me(0);e&&([h.yaw,h.pitch,O]=[e.yaw,e.pitch,!0]),A=0}for(;O&&A>=br;A-=br){let t=f.step({keys:h.keys,yaw:h.yaw,pitch:h.pitch},e);E&&N.send(Ie(t))}let r=f.me(A/br),i=f.others(e),a=r?[r.x,r.y+R(r),r.z]:[0,0,0];p.listen(a,h.yaw);let o=Math.min((e-n)/1e3,.1),s=f.events();if(g.update(r,h.keys,o,s),_.me(r,s,g.stride),_.others(i),v.update(r,s,o),r&&b){let t=[a[0],a[1]+g.dy,a[2]],n=h.pitch+g.pitch;b.frame(t,h.yaw,n,i,C,g,jn({eye:t,yaw:h.yaw,pitch:n,others:i,t:e/1e3}),v)}let l=/* @__PURE__ */ new Set;for(let e of i){let n=[e.x,e.y+t+.3,e.z],i=r&&!S(d,a,n)?b?.project(...n):void 0,o=P(e.id);l.add(e.id),o.hidden=!i,i&&(o.style.left=i[0]*100+`%`,o.style.top=i[1]*100+`%`);let s=w.get(e.id)??``;o.textContent!=s&&(o.textContent=s)}for(let[e,t]of T)l.has(e)||(t.remove(),T.delete(e));c.title(D||(E?O?h.locked()?``:`Click to play`:`Joining…`:`Connecting…`),d.def.name??``)};return j=requestAnimationFrame(F),{on:(e,t)=>void l[e].push(t),players:()=>x,destroy(){M||(M=!0,cancelAnimationFrame(j),h.destroy(),p.destroy(),b?.destroy(),N.onopen=N.onclose=N.onmessage=null,N.close(),document.exitPointerLock(),r.remove())}}};export{Sr as tinyFps};
@@ -1,5 +1,10 @@
1
1
  import type { Vec3 } from './mesh';
2
2
  import type { Voice } from './sfx';
3
+ /** A sound that plays on and on, started on its first set. */
4
+ export interface Loop {
5
+ /** Volume and speed (pitch) to move to, eased over a fraction of a second: 0 is silence. */
6
+ set(volume: number, rate: number): void;
7
+ }
3
8
  export interface Audio {
4
9
  /**
5
10
  * Starts the AudioContext on a user gesture (browsers keep it suspended until one); the first
@@ -10,9 +15,12 @@ export interface Audio {
10
15
  listen(eye: Vec3, yaw: number): void;
11
16
  /**
12
17
  * Plays the sound `id` (an index into the layers). With `at`, panned left or right by its direction from the listener and
13
- * fainter with distance; without, centred (the own player's sounds). `gain` scales the volume.
18
+ * fainter with distance; without, centred (the own player's sounds). `gain` scales the volume,
19
+ * `rate` the speed and so the pitch.
14
20
  */
15
- play(id: number, at?: Vec3, gain?: number): void;
21
+ play(id: number, at?: Vec3, gain?: number, rate?: number): void;
22
+ /** The sound `id` (one of LOOPED) as a loop, silent until its first set; the own player's, centred. */
23
+ loop(id: number): Loop;
16
24
  /** Mutes or unmutes everything, music included. */
17
25
  mute(on: boolean): void;
18
26
  readonly muted: boolean;
@@ -0,0 +1,34 @@
1
+ import type { PlayerState } from '../shared/types';
2
+ import type { Vec3 } from './mesh';
3
+ /** What the predictor reports of the live steps since the last frame. */
4
+ export interface Events {
5
+ ev: number;
6
+ fall: number;
7
+ }
8
+ /** A limb in world space: its root, its joint, its end, and where the hand or foot points. */
9
+ export interface Limb {
10
+ root: Vec3;
11
+ mid: Vec3;
12
+ end: Vec3;
13
+ dir: Vec3;
14
+ }
15
+ /** The joints of the body: index 0 is the left side, 1 the right. */
16
+ export interface Rig {
17
+ arms: Limb[];
18
+ legs: Limb[];
19
+ /** Pelvis and the top of the chest. */
20
+ torso: [Vec3, Vec3];
21
+ /** 0 to 1: how much the hands hold a ledge; the sleeves slim down, being this close to the eye. */
22
+ grip: number;
23
+ /** 0 to 1: how low the body is (a crouch or a slide). */
24
+ low: number;
25
+ }
26
+ export interface Body {
27
+ /** Advances dt seconds: the own player (eased, undefined before the first snapshot) and the events of its steps. */
28
+ update(me: PlayerState | undefined, e: Events, dt: number): void;
29
+ /** The joints for a camera at `eye`; undefined without a player, or with the camera away from the body. */
30
+ rig(eye: Vec3, yaw: number, pitch: number, roll?: number): Rig | undefined;
31
+ /** Appends the body's vertices (see STRIDE) for that camera; nothing when rig() has none. */
32
+ draw(out: number[], eye: Vec3, yaw: number, pitch: number, roll?: number): void;
33
+ }
34
+ export declare const createBody: () => Body;
@@ -1,11 +1,27 @@
1
1
  import type { PlayerState } from '../shared/types';
2
- /** What the renderer and the camera read; update moves it. */
2
+ /** What happened in the live steps since the last frame: predictor.events(). */
3
+ export interface Hit {
4
+ ev: number;
5
+ fall: number;
6
+ }
3
7
  export interface Effects {
4
- /** Vertical eye offset, metres. */
5
- bob: number;
6
- /** Radians, positive leans right (strafing right). */
8
+ /** Vertical eye offset from the physics eye, metres: the eye height eased, the bob, the landing dip, the jump lift. */
9
+ dy: number;
10
+ /** Radians added to the look pitch (positive looks up): the grab settle and the climb arc. */
11
+ pitch: number;
12
+ /** Radians, positive leans right. */
7
13
  roll: number;
8
- /** Advances dt seconds: the own player (eased, undefined before the first snapshot) and the held keys. */
9
- update(me: PlayerState | undefined, keys: number, dt: number): void;
14
+ /** Degrees added to the vertical field of view. */
15
+ fov: number;
16
+ /** 0 to 1: the speed lines, and the touch of vignette that goes with them. */
17
+ lines: number;
18
+ /** Steps walked on a floor or a wall: each whole number is a footfall. */
19
+ stride: number;
20
+ /** Advances dt seconds: the own player (eased, undefined before the first snapshot), the held keys, the events. */
21
+ update(me: PlayerState | undefined, keys: number, dt: number, hit?: Hit): void;
10
22
  }
23
+ /** Metres from one footfall to the next at speed v: longer strides at a sprint. */
24
+ export declare const stepLength: (v: number) => number;
25
+ /** Taking steps: on a floor, or along a wall. */
26
+ export declare const stepping: (s?: PlayerState) => boolean;
11
27
  export declare const createEffects: () => Effects;
@@ -0,0 +1,10 @@
1
+ import type { PlayerState } from '../shared/types';
2
+ import type { Audio } from './audio';
3
+ import type { Hit } from './effects';
4
+ export interface Foley {
5
+ /** The own player as drawn (undefined before the first snapshot), what its live steps did, and the stride of the effects. */
6
+ me(p: PlayerState | undefined, hit: Hit, stride: number): void;
7
+ /** The other players as drawn: their steps and landings, at their position. */
8
+ others(ps: PlayerState[]): void;
9
+ }
10
+ export declare const createFoley: (a: Audio) => Foley;
@@ -1,5 +1,6 @@
1
1
  import type { PlayerState } from '../shared/types';
2
2
  import type { World, WorldDef } from '../shared/world';
3
+ import type { Body } from './body';
3
4
  import type { Effects } from './effects';
4
5
  import type { Light } from './lights';
5
6
  import type { Vec3 } from './mesh';
@@ -13,7 +14,8 @@ export declare const SUN_AREA = 64;
13
14
  export declare const SUN_DEPTH = 100;
14
15
  /** How far the fog colour is pulled toward the sky's horizon, 0 to 1: a fog unlike the horizon draws an edge against the sky. */
15
16
  export declare const HAZE = 0.6;
16
- /** Tangent of half the vertical field of view (70 degrees). */
17
+ /** The vertical field of view at rest, degrees, and the tangent of its half. */
18
+ export declare const FOV_DEG = 70;
17
19
  export declare const FOV: number;
18
20
  /**
19
21
  * Blinn-Phong strength and exponent: a row per TEX id in order (brick, tile, lava, stone, metal, wood,
@@ -75,12 +77,12 @@ export declare const daylight: ({ sky: [zenith, horizon] }: WorldDef) => Vec3[];
75
77
  export declare const fogOf: ({ fog, sky }: WorldDef) => [number, number, number, number];
76
78
  export interface Renderer {
77
79
  /**
78
- * Draws one frame: the sky, the brushes and the others as seen from eye. colors maps player id
79
- * to CSS.
80
+ * Draws one frame: the sky, the brushes and the others as seen from eye, then the own `body` over
81
+ * a cleared depth, lit but casting no shadow. colors maps player id to CSS.
80
82
  */
81
83
  frame(eye: Vec3, yaw: number, pitch: number, others: PlayerState[], colors: ReadonlyMap<number, string>, fx: Effects,
82
84
  /** gather() in lights.ts: at most MAX_LIGHTS, the first MAX_SHADOWS shadowed spots mapped, besides the sun. */
83
- lights: Light[]): void;
85
+ lights: Light[], body?: Body): void;
84
86
  /** A world point on screen as of the last frame, in [0, 1] from the top left. */
85
87
  project(x: number, y: number, z: number): [number, number] | undefined;
86
88
  destroy(): void;
@@ -19,16 +19,38 @@ export type Voice = [
19
19
  ];
20
20
  /** Sample rate of everything rendered here; audio.ts resamples through AudioBuffer if needed. */
21
21
  export declare const RATE = 44100;
22
+ /** The ids of the sounds: an index into LAYERS. The last two are loops (see LOOPED). */
23
+ export declare const SOUND: {
24
+ readonly STEP: 0;
25
+ /** The lighter tap of a step on a wall. */
26
+ readonly WALLSTEP: 1;
27
+ readonly JUMP: 2;
28
+ readonly DOUBLE: 3;
29
+ readonly DASH: 4;
30
+ readonly LAND: 5;
31
+ readonly GRAB: 6;
32
+ readonly SCUFF: 7;
33
+ readonly WIND: 8;
34
+ readonly SCRAPE: 9;
35
+ };
22
36
  /**
23
- * The sounds of the game: one entry per sound, its voices layered, an index per sound for
24
- * audio.play. None yet: the footsteps, the dash and the grab of the next steps go here.
37
+ * The sounds of the game: one entry per sound, its voices layered, in SOUND order. A low-passed
38
+ * noise is quiet (lp 0.06 keeps about a tenth of the swing): the loops have a high volume.
25
39
  */
26
40
  export declare const LAYERS: Voice[][];
41
+ /** The sounds played in a loop: their buffers go through seam. */
42
+ export declare const LOOPED: number[];
27
43
  /**
28
44
  * Renders the sound `id` of `layers` as mono samples in [-1, 1] at RATE, deterministic (seeded
29
45
  * noise), silent at both ends (no click).
30
46
  */
31
47
  export declare const render: (id: number, layers?: Voice[][]) => Float32Array;
48
+ /**
49
+ * A sound made loopable: the last `x` samples are cross-faded into the first, the length drops by
50
+ * `x`, and the end joins the start. For a stationary sound (a loop's voice is held at full
51
+ * volume, nothing but noise), whose own ends are no longer heard.
52
+ */
53
+ export declare const seam: (s: Float32Array, x?: number) => Float32Array;
32
54
  /**
33
55
  * The music: a loop of four bars in A minor at 108 bpm (whole beats, whole samples), mono samples
34
56
  * in [-1, 1] at RATE, deterministic, whose end joins its start without a click. Quiet enough to
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.14.0",
5
+ "version": "0.15.0",
6
6
  "type": "module",
7
7
  "files": [
8
8
  "dist"