@korial29/tiny-fps 0.14.0 → 0.16.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
@@ -166,17 +166,17 @@ The subset of `WebSocket` the client uses: `binaryType`, `onopen`, `onclose`, `o
166
166
 
167
167
  ## Controls
168
168
 
169
- | Action | Keys |
170
- | ------ | -------------------------------------------------------------------------- |
171
- | Look | Mouse (click the game to lock the pointer, Esc to release it) |
172
- | Move | WASD, or the arrow keys |
173
- | Sprint | Shift, with forward: the top speed builds over about a second |
174
- | Jump | Space. Press it again in the air for a second jump |
175
- | Dash | E or the right mouse button: a short burst, once a second, once in the air |
176
- | Crouch | C. At sprint speed it is a slide, low enough to go under a 1.2 m slot |
177
- | Mute | M (remembered) |
178
-
179
- Facing a ledge between 1.2 and 2.4 m above your feet in the air, you take hold of it: forward or Space climbs, back or C lets go, and Space looking away jumps off it. Running fast along a wall in the air starts a wall-run (about a second, Space kicks off). Ctrl is not used, since Ctrl+W closes the tab.
169
+ | Action | Keys |
170
+ | ------ | ----------------------------------------------------------------------- |
171
+ | Look | Mouse (click the game to lock the pointer, Esc to release it) |
172
+ | Move | WASD, or the arrow keys |
173
+ | Sprint | Shift, with forward: the top speed builds over about a second |
174
+ | Jump | Space. Press it again in the air for a second jump |
175
+ | Dash | A move key pressed twice quickly: a short burst that way, once a second |
176
+ | Crouch | C. At sprint speed it is a slide, low enough to go under a 1.2 m slot |
177
+ | Mute | M (remembered) |
178
+
179
+ Facing a ledge between 1.2 and 2.4 m above your feet in the air, you take hold of it: forward or Space climbs, back or C lets go, and Space looking away jumps off it. Jumping while running next to a wall, up to half a metre away and not more than about 50 degrees off it, starts a wall-run along its side (about a second, hold forward, Space kicks off). Ctrl is not used, since Ctrl+W closes the tab.
180
180
 
181
181
  Keys are read by their position (`KeyboardEvent.code`), so on an AZERTY keyboard WASD is ZQSD with nothing to set.
182
182
 
@@ -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=(t,n,r)=>{let i;for(let a of b(n,t.x,t.z,.9)){let o=n.def.brushes[a],s=le(o,t,r,.5);s!==void 0&&o.min[1]<t.y+.5&&o.max[1]>t.y+1.8&&(i=Math.min(i??1/0,Math.max(0,s-e)))}return i},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{let a=ue(e,t,e.wall);if(a===void 0||!n.fwd||u<3.5||e.t>=60){B(e,s.AIR),e.ev|=l.WALLRUN_END;return}let d=Math.max(0,u-1.5*C)/u;e.vx=o*d,e.vz=c*d;let f=Math.min(a,4*C);e.x+=r*f,e.z+=i*f}},Se=(e,t,n)=>{if(!n.fwd)return;let r=N(e.vx,e.vz);if(!(r<4.5))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&&o<=.75*r&&o>=-.2*r&&ue(e,t,n)!==void 0){let t=N(c,u),i=Math.max(t,.9*r)/t;B(e,s.WALLRUN),e.wall=n,[e.vx,e.vz]=[c*i,u*i],e.vy=M(e.vy,2,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>Move key twice<td>dash that way<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,KeyC:o.CROUCH},bn=o.FORWARD|o.BACK|o.LEFT|o.RIGHT,xn=(e,t)=>e&~bn|t|o.DASH,Sn=e=>yn[e]??0,Cn=(e,t=()=>{})=>{let r=new AbortController,i=(e,t,n)=>e.addEventListener(t,n,{signal:r.signal}),a=/* @__PURE__ */ new Set,o=/* @__PURE__ */ new Map,s=0,c={yaw:0,pitch:0,keys:0,take(){let e=s?xn(c.keys,s):c.keys;return s=0,e},locked:()=>e.getRootNode().pointerLockElement==e,destroy:()=>r.abort()};i(e,`click`,()=>{Promise.resolve(e.requestPointerLock()).catch(()=>{})}),i(document,`mousemove`,e=>{c.locked()&&(c.yaw=((c.yaw-e.movementX*_n)%vn+vn)%vn,c.pitch=Math.max(-1.55,Math.min(n,c.pitch-e.movementY*_n)))}),i(document,`keydown`,e=>{let n=Sn(e.code);if(e.code==`KeyM`&&!e.repeat&&c.locked()&&t(),n&&c.locked()){if(n&bn&&!e.repeat&&!a.has(e.code)){let t=performance.now(),r=o.get(e.code);r!==void 0&&t-r<=250?(s=n,o.delete(e.code)):o.set(e.code,t)}a.add(e.code),c.keys|=n,e.preventDefault()}}),i(document,`keyup`,e=>{a.delete(e.code),c.keys&=~Sn(e.code)});let l=()=>{c.keys=s=0,a.clear(),o.clear()};return i(window,`blur`,l),i(document,`pointerlockchange`,()=>c.locked()||l()),c},wn=120,Tn=16,K=e=>{let t={...e};return delete t.ack,t},En=(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}),Dn=(e,t,n)=>O(e+(((t-e+Math.PI)%w+w)%w-Math.PI)*n),On=(e,t)=>(t-e&65535)<32768,kn=(e,t,n)=>({...t,...En(e,t,n),yaw:Dn(e.yaw,t.yaw,n),pitch:e.pitch+(t.pitch-e.pitch)*n}),An=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>wn&&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>Tn&&o.shift();let c=n.players.find(e=>e.id===t);c&&(r=r.filter(e=>!On(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?kn(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?kn(K(t),K(n),a):K(n??t??e)})}}},jn={SPOT:0,POINT:1},Mn=e=>[],Nn=3.6,Pn=({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]},Fn=(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},In=e=>Math.min(1,Math.hypot(e.vx,e.vz)/2),Ln=(e,t)=>lt(ct(e,t),[1,1,1]),Rn=Ln([[0,0],[1,.05],[.65,1],[0,1]],5),zn=Ln([[0,0],[.8,.05],[.55,.7],[1,.8],[.5,1],[0,1]],5),Bn=Ln([[0,0],[.15,0],[.13,.25],[.22,.7],[.2,.95],[0,1]],6),Vn=Ln([[0,0],[.1,.06],[.155,.4],[.13,.8],[0,1]],8),Hn=(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)},Un=(e,t,n,r,i,a,o,s=1)=>Hn(e,t,n.yaw,Pn(n,...r),Pn(n,...i),a,o,s),Wn=([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)]]},Gn=(e,t,n)=>{let r=.55*Math.sin(t)*n;return Wn(e,r,r-.9*Math.max(0,-Math.sin(t+.5))*n,.43,.45)},Kn=.88,qn=(e,n,r,i,a)=>{let o=i*Nn,s=Kn-.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]];Un(e,Bn,n,u,d,1,r,1.25),Un(e,Vn,n,d,[0,t,.02],1.1,c);let f=r.map(e=>.35+.65*e);st(e,Pn(n,0,d[1]+.17,.17),[.11,.035,.03],n.yaw,f,-2),st(e,Pn(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]=Gn(i,o+(t>0?Math.PI:0),a);Un(e,Rn,n,i,u,.1,c),Un(e,Rn,n,u,d,.08,c),st(e,Pn(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]=Wn(f,p,p+.3,.34,.36);Un(e,Rn,n,f,m,.07,r),Un(e,zn,n,m,h,.06,c)}},Jn=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},Yn=(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),Xn=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=Yn(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=Yn(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(Xn*(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*Yn(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 Zn=()=>{let e=new Uint8ClampedArray(Jn*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},Qn=1<<18,$n=2,$=1024,er=.6,tr=Math.tan(70*Math.PI/360),nr=4,rr=`#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);}`,ir=`#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);}`,ar=`#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);}`,or=[[.04,8],[.25,30],[0,1],[.08,10],[.8,48],[.06,12],[.3,20],[.7,40],[.1,24]],sr=`#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[${or.length}]=vec2[](${or.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/${$n}.+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/$n}.*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:${Jn}.)];
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.);}`,cr=(e,t,n,r,i=0,a=tr,[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])},lr=(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)]},ur=({p:e,d:t,cone:n,range:r})=>cr(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]),dr=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==jn.SPOT&&a<4?a++:-1;t.set([...e.p,e.range],o*4),n.set([...e.d,e.kind==jn.POINT?-9:e.cone],o*4),r.set([...e.color,s],o*4),s>=0&&i.set(ur(e),s*16)}),{n:o.length,maps:a,a:t,b:n,k:r,m:i}},fr=(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])},pr=({def:e})=>[...new Map([[`1,1,1`,[1,1,1]],...e.brushes.flatMap(({tint:e})=>e?[[`${e}`,e]]:[])]).values()].slice(0,16),mr=[[0,0],[1,0],[1,1],[0,0],[1,1],[0,1]],hr=e=>{let{brushes:t,floor:n}=e.def,r=[],i=pr(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 mr){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},gr=({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],_r=({fog:e,sky:t})=>e?[...[0,1,2].map(n=>e[n]+(t[1][n]-e[n])*er),e[3]]:[...t[1],0],vr=2073600,yr=(e,t,n)=>{let r=Math.min(n,2,Math.sqrt(vr/(e*t||1)));return[Math.round(e*r),Math.round(t*r)]},br=(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=()=>yr(e.clientWidth,e.clientHeight,devicePixelRatio),l=hr(t),{sun:u,sky:d}=t.def,f=u.dir.map(e=>e/Math.hypot(...u.dir)),p=Zn(),m=l.length*4,h=m+Qn,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,nr,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(ir,ar,[`S`,`Y`,`L`]),i.uniform1iv(x.S,[0,1,2,3]),[y,g]=j(rr,sr,[`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,Jn,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=pr(t);i.uniform4fv(g.F,_r(t.def)),i.uniform3fv(g.H,gr(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=cr(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=Fn(n,e.id,e.x,e.z,ee);qn(I,e,s(d.get(e.id)??`#888`),t.walked,In(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=dr(S),te=l.length/10,ne=fr(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)=>lr(k,e,t,n),destroy(){e.removeEventListener(`webglcontextlost`,L),e.removeEventListener(`webglcontextrestored`,ee),i.getExtension(`WEBGL_lose_context`)?.loseContext()}}},xr=1/60,Sr=5,Cr=(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=An(d),p=nt();p.mute(rt()),c.mute(p.muted);let h=Cn(a,()=>c.mute(it(p)));a.addEventListener(`click`,()=>p.unlock());let g=fn(),_=mn(p),v=Vt(),b;try{b=br(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,Sr*xr),k=e,!O){let e=f.me(0);e&&([h.yaw,h.pitch,O]=[e.yaw,e.pitch,!0]),A=0}for(;O&&A>=xr;A-=xr){let t=f.step({keys:h.take(),yaw:h.yaw,pitch:h.pitch},e);E&&N.send(Ie(t))}let r=f.me(A/xr),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,Mn({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{Cr as tinyFps};
package/dist/local.js CHANGED
@@ -1 +1 @@
1
- var e={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,SPRINT:32,DASH:64,CROUCH:128},t={GROUND:0,AIR:1,WALLRUN:2,HANG:3,CLIMB:4,SLIDE:5,CROUCH:6},n={NONE:0,EAST:1,WEST:2,SOUTH:3,NORTH:4},r={JUMP:1,DOUBLE:2,DASH:4,LAND:8,GRAB:16,CLIMB:32,WALLRUN_START:64,WALLRUN_END:128,SLIDE_START:256,SLIDE_END:512},i={BRICK:0,TILE:1,LAVA:2,STONE:3,METAL:4,WOOD:5,MOSS:6,GRATE:7},a=65536/(2*Math.PI),o=e=>Math.round(e*a)&65535,s=e=>Math.max(-32768,Math.min(32767,Math.round(e))),c=e=>s(e*1e4),l=e=>e/1e4,u=e=>e/a,d=e=>{if(e.byteLength!==11)return null;let t=new DataView(e);return t.getUint8(0)===1?{seq:t.getUint16(1),keys:t.getUint8(3),yaw:u(t.getUint16(4)),pitch:l(t.getInt16(6)),view:(t.getUint16(8)*256+t.getUint8(10))/256}:null},f=t=>{let n=/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(4+39*t.players.length));return n.setUint8(0,2),n.setUint16(1,t.tick&65535),n.setUint8(3,t.players.length),t.players.forEach((t,r)=>{let i=4+r*39;n.setUint8(i,t.id),n.setFloat32(i+1,t.x),n.setFloat32(i+5,t.y),n.setFloat32(i+9,t.z),n.setFloat32(i+13,t.vx),n.setFloat32(i+17,t.vy),n.setFloat32(i+21,t.vz),n.setFloat32(i+25,t.edge),n.setUint16(i+29,o(t.yaw)),n.setInt16(i+31,c(t.pitch)),n.setUint16(i+33,t.ack&65535),n.setUint8(i+35,t.mode&7|(t.wall&7)<<3|(t.jumps&1)<<6|t.dashes<<7),n.setUint8(i+36,t.t),n.setUint8(i+37,t.dash),n.setUint8(i+38,t.coyote&7|(t.buffer&7)<<3|(t.held&e.JUMP?64:0)|(t.held&e.DASH?128:0))}),n.buffer},p=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},m=.4,h=1.8,g=1.55,_=.9,v=7.5,y=2.5,b=.15,x=.15,S=6.5,ee=.2,te=.03,ne=.2,C=5.5,re={maxPlayers:16},ie=-30,w=(e,t,n,r,a)=>({min:[e,ie,t],max:[n,a,r],top:i.TILE,side:i.BRICK}),T=([e,t,n],[r,i,a],o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c}),ae={name:`Rooftops`,brushes:[w(4,57.7,24,76,10),w(4,36,24,53.5,10),w(4,20,24,36,12.4),w(4,-5,24,7,12.4),w(27,20,47,50,8),w(27,60,47,76,8),T([9,12.2,39],[19,12.6,47],i.METAL,i.METAL),...((e,t)=>[1,2,3,4,5,6].map(n=>T([12,t,e-n],[14,t+.4*n,e-n+1],i.STONE,i.STONE)))(53,10),T([5,10,42],[5.5,14,42.5],i.METAL),T([5,10,50],[5.5,14,50.5],i.METAL),T([8,12.4,24],[20,12.85,24.45],i.METAL),T([36,8,22],[37,14.5,48],i.STONE,i.STONE,[1,.75,.62]),T([30,8,28],[34,10,32],i.STONE,i.BRICK),T([40,8,30],[44,10.2,34],i.STONE,i.BRICK),T([28,9.2,44],[35,12,46],i.METAL,i.GRATE,[.8,.9,1]),T([41.5,7.6,50],[42,8,60],i.METAL),T([30,8,64],[34,9.6,68],i.STONE,i.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]},oe=4,E=1024,D=(e,t)=>(e+E)*(2*E)+t+E,O=(e,t)=>Math.min(Math.max(Math.floor(e/t),-1024),1023),se=(e,t=oe)=>{let n=/* @__PURE__ */ new Map;return e.brushes.forEach(({min:e,max:r},i)=>{for(let a=O(e[0],t);a<=O(r[0],t);a++)for(let o=O(e[2],t);o<=O(r[2],t);o++){let e=D(a,o),t=n.get(e);t?t.push(i):n.set(e,[i])}}),{def:e,cell:t,grid:n}},k=(e,t,n,r)=>{let i=[];for(let a=O(t-r,e.cell);a<=O(t+r,e.cell);a++)for(let t=O(n-r,e.cell);t<=O(n+r,e.cell);t++)for(let n of e.grid.get(D(a,t))??[])i.includes(n)||i.push(n);return i},A=1/60,j=Math.PI*2,M=1e-6,N=.01,P=.001,F=e=>(e%j+j)%j,I=e=>[-Math.sin(e),-Math.cos(e)],L=Math.fround,R=Math.sqrt,z=(e,t,n)=>Math.min(Math.max(e,t),n),B=(e,t)=>R(e*e+t*t),V=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],ce={vx:0,vz:0,mode:t.GROUND,t:0,wall:n.NONE,edge:0,jumps:1,dashes:1,dash:0,coyote:6,buffer:0,held:0,ev:0,fall:0},H=(e,t,n)=>{let{spawns:r}=t.def,[i,a,o,s]=r[(n%r.length+r.length)%r.length];return{id:e,x:L(i),y:L(a),z:L(o),vy:0,yaw:F(s),pitch:0,ground:!0,...ce}},U=e=>e===t.GROUND||e===t.SLIDE||e===t.CROUCH,le=e=>e.mode===t.SLIDE||e.mode===t.CROUCH?_:h,W=(e,t,n)=>e.max[1]>t+.5+N&&e.min[1]<t+n-N,G=(e,t,n)=>[t-z(t,e.min[0],e.max[0]),n-z(n,e.min[2],e.max[2])],ue=(e,t,n)=>{let{brushes:r}=t.def,i=k(t,e.x,e.z,2*m),a=(m-M)**2,[o,s]=[0,0];for(let t=0;t<4;t++){let t=0,c=0,l=0;for(let o of i){let i=r[o];if(!W(i,e.y,n))continue;let[s,u]=G(i,e.x,e.z),d=s*s+u*u;if(d>=a)continue;if(d){let e=R(d);.4-e>t&&(t=m-e,c=s/e*t,l=u/e*t);continue}let[f,p,h]=[[e.x-i.min[0],-1,0],[i.max[0]-e.x,1,0],[e.z-i.min[2],0,-1],[i.max[2]-e.z,0,1]].reduce((e,t)=>t[0]<e[0]?t:e);f+.4>t&&(t=f+m,[c,l]=[p*t,h*t])}if(!t)break;e.x+=c,e.z+=l,o+=c,s+=l}return[o,s]},K=(e,t,n)=>{let{brushes:r}=t.def,i=(m-M)**2,a=-1/0,o=1/0;for(let s of k(t,e.x,e.z,m)){let t=r[s],[c,l]=G(t,e.x,e.z);c*c+l*l>=i||(t.max[1]<=e.y+.5+N?a=Math.max(a,t.max[1]):t.min[1]>=e.y+n-N&&(o=Math.min(o,t.min[1])))}return[a,o]},q=(e,t)=>{let n=(m-M)**2;return k(t,e.x,e.z,m).every(r=>{let i=t.def.brushes[r],[a,o]=G(i,e.x,e.z);return a*a+o*o>=n||!W(i,e.y,1.8)})},J=(e,t,n,r,i)=>{let a=(m-M)**2;return k(e,t,n,m).every(o=>{let s=e.def.brushes[o],[c,l]=G(s,t,n);return c*c+l*l>=a||s.max[1]<=r||s.min[1]>=i})},Y=(e,t)=>{let[n,r]=V[t],i=n?0:2;return{a:i,o:2-i,sign:n||r,c:n?e.x:e.z,co:n?e.z:e.x}},de=(e,t,n,r)=>{let{a:i,o:a,sign:o,c:s,co:c}=Y(t,n),l=((o>0?e.min[i]:e.max[i])-s)*o;return l>=.4-P&&l<=.4+r&&c>=e.min[a]&&c<=e.max[a]?l:void 0},fe=(e,t,n)=>k(t,e.x,e.z,m+x).some(r=>{let i=t.def.brushes[r];return de(i,e,n,.15)!==void 0&&i.min[1]<e.y+.5&&i.max[1]>e.y+1.8}),pe=(e,t)=>{let[n,r]=I(e.yaw),i;for(let a=1;a<=4;a++){let[o,s]=V[a];if(a===e.wall||n*o+r*s<.5)continue;let{a:c,sign:l}=Y(e,a);for(let n of k(t,e.x,e.z,m+ee)){let r=t.def.brushes[n],o=r.max[1],s=o-e.y;if(de(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*(m+te),f=u+l*ne,[p,h]=c===0?[d,e.z]:[e.x,d],[g,_]=c===0?[f,e.z]:[e.x,f];J(t,p,h,Math.min(e.y,o-2)+N,o+1.8)&&J(t,g,_,o+N,o+1.8)&&(i={side:a,top:o,hang:d})}}return i},me=(e,t)=>{let{a:n,o:r,sign:i,c:a,co:o}=Y(e,e.wall);return k(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 L(c.max[1])===e.edge&&o>=c.min[r]&&o<=c.max[r]&&l>=.2})},he=(e,t)=>{if(e.vy>=0)return!1;let[n]=K(e,t,h),r=6*A;return e.y-n<=-e.vy*r+10*r*r},X=(e,t)=>{e.mode=t,e.t=0},ge=(e,t)=>{let n=B(e.vx,e.vz);n>t&&(e.vx*=t/n,e.vz*=t/n)},_e=(e,t,n,r)=>{let[i,a]=[n.wx,n.wz];for(let n of k(t,e.x,e.z,m+P)){let o=t.def.brushes[n],[s,c]=G(o,e.x,e.z),l=B(s,c);if(l>0&&l<=.4+P&&W(o,e.y,r)){let e=(-i*s-a*c)/l;e>0&&(i+=e*s/l,a+=e*c/l)}}return[i,a]},ve=(e,t,n)=>{let r=B(t[0],t[1]);if(r<M){let t=B(e.vx,e.vz),n=t?Math.max(0,t-45*A)/t:0;e.vx*=n,e.vz*=n;return}let[i,a]=[t[0]/r,t[1]/r],o=e.vx*i+e.vz*a,[s,c]=[e.vx-o*i,e.vz-o*a],l=B(s,c);if(l){let e=Math.max(0,l-45*A)/l;[s,c]=[s*e,c*e]}n*=r,o=o<n?Math.min(n,o+(o>=6?3:50)*A):Math.max(n,o-12*A),e.vx=s+o*i,e.vz=c+o*a},ye=(e,t,n,r,i)=>{let a=e.y;e.x+=e.vx*A,e.z+=e.vz*A;let[o,s]=ue(e,t,n),c=B(o,s);if(c){let t=(e.vx*o+e.vz*s)/c;t<0&&(e.vx-=t*o/c,e.vz-=t*s/c)}let[l,u]=K(e,t,n),d=e.vy-r*20*A;if(e.y+=(e.vy+d)/2*A,e.vy=d,e.y+n>u&&(e.y=u-n,e.vy=Math.min(e.vy,0)),e.vy<=0?e.y<=l+N: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},Z=(e,t)=>{e.vy=t,e.coyote=0,e.buffer=0,e.ev|=r.JUMP},be=(n,r,i)=>{let[a,o]=V[n.wall],s=e=>{X(n,e),n.edge=0};if(i.keys&(e.BACK|e.CROUCH))s(t.AIR),n.coyote=0;else if(i.jump&&i.fx*a+i.fz*o<0)s(t.AIR),n.vx=-a*4,n.vz=-o*4,Z(n,6);else if(i.jump||i.fwd&&n.t>=6)X(n,t.CLIMB);else if(n.t>=30)s(t.AIR),n.coyote=0;else{let e=Math.max(n.edge-2,K(n,r,h)[0]);n.y+=z(e-n.y,-8*A,8*A)}},xe=(e,i)=>{let[a,o]=V[e.wall];e.y<e.edge?e.y=Math.min(e.edge,e.y+8*A):(e.x+=a*C*A,e.z+=o*C*A),e.y>=e.edge&&me(e,i)?(X(e,t.GROUND),e.vx=a*3,e.vz=o*3,e.vy=0,e.edge=0,e.wall=n.NONE,e.coyote=6,e.ev|=r.CLIMB):e.t>=40&&(X(e,e.y>=e.edge?t.GROUND:t.AIR),e.edge=0,e.wall=n.NONE)},Se=(e,n,i)=>{let[a,o]=V[e.wall],s=e.vx*a+e.vz*o,[c,l]=[e.vx-s*a,e.vz-s*o],u=B(c,l);if(i.jump)X(e,t.AIR),e.vx=c-a*5,e.vz=l-o*5,Z(e,S),e.jumps=1,e.dashes=1,e.ev|=r.WALLRUN_END;else if(!i.fwd||u<5.5||e.t>=60||!fe(e,n,e.wall))X(e,t.AIR),e.ev|=r.WALLRUN_END;else{let t=Math.max(0,u-y*A)/u;e.vx=c*t,e.vz=l*t}},Ce=(e,n,i)=>{if(!i.fwd)return;let a=B(e.vx,e.vz);for(let i=1;i<=4;i++){let[o,s]=V[i],c=e.vx*o+e.vz*s,[l,u]=[e.vx-c*o,e.vz-c*s];if(i!==e.wall&&B(l,u)>=7&&Math.abs(c)<=.4*a&&fe(e,n,i)){X(e,t.WALLRUN),e.wall=i,[e.vx,e.vz]=[l,u],e.vy=Math.min(e.vy,3),e.jumps=1,e.dashes=1,e.coyote=0,e.ev|=r.WALLRUN_START;return}}},we=(e,i)=>{X(e,t.HANG),e.wall=i.side,e.edge=L(i.top),i.side<=n.WEST?e.x=i.hang:e.z=i.hang,e.vx=e.vy=e.vz=0,e.jumps=1,e.dashes=1,e.coyote=0,e.buffer=0,e.ev|=r.GRAB},Te=(i,a,o)=>{let s=i.mode===t.GROUND;if(o.dash&&i.dash===0&&(s||(i.mode===t.AIR||i.mode===t.WALLRUN)&&i.dashes>0)){let[e,n]=o.wx||o.wz?[o.wx,o.wz]:[o.fx,o.fz];s||(i.dashes--,i.vy=0,i.mode===t.WALLRUN&&(X(i,t.AIR),i.ev|=r.WALLRUN_END)),i.vx=e*16,i.vz=n*16,i.dash=60,i.ev|=r.DASH}let c=i.dash>50;i.mode===t.WALLRUN&&Se(i,a,o),U(i.mode)&&Ee(i,a,o,c),i.mode===t.AIR&&De(i,a,o,c);let l=c&&i.vy<=0?0:i.mode===t.WALLRUN?b:1,u=i.mode,d=ye(i,a,le(i),l,U(u));if(d>=0){if(!U(i.mode)){if(i.ev|=r.LAND|(i.mode===t.WALLRUN?r.WALLRUN_END:0),i.fall=d,i.jumps=1,i.dashes=1,i.wall=n.NONE,o.keys&e.CROUCH){let e=B(i.vx,i.vz)>=v;X(i,e?t.SLIDE:t.CROUCH),i.ev|=e?r.SLIDE_START:0}else X(i,t.GROUND)}i.coyote=6}else U(i.mode)&&(i.ev|=i.mode===t.SLIDE?r.SLIDE_END:0,X(i,t.AIR));if(i.mode===t.AIR){let e=pe(i,a);e?we(i,e):Ce(i,a,o)}},Ee=(n,i,a,o)=>{let s=(a.keys&e.CROUCH)!==0;if(n.buffer>0&&(n.mode===t.GROUND||q(n,i))){n.ev|=n.mode===t.SLIDE?r.SLIDE_END:0,X(n,t.AIR),Z(n,7);return}let c=B(n.vx,n.vz);if(n.mode===t.GROUND&&s){let e=c>=v;X(n,e?t.SLIDE:t.CROUCH),n.ev|=e?r.SLIDE_START:0}else n.mode===t.SLIDE&&(n.t>=60||c<4.5)?(n.ev|=r.SLIDE_END,X(n,!s&&q(n,i)?t.GROUND:t.CROUCH)):n.mode===t.SLIDE&&!s&&q(n,i)?(n.ev|=r.SLIDE_END,X(n,t.GROUND)):n.mode===t.CROUCH&&!s&&q(n,i)&&X(n,t.GROUND);if(!o){if(n.mode===t.SLIDE){let e=Math.max(0,c-4*A)/c;n.vx*=e,n.vz*=e}else if(n.mode===t.CROUCH)ve(n,_e(n,i,a,_),3);else{let t=(a.keys&e.SPRINT)!==0&&a.fwd;ve(n,_e(n,i,a,h),t?9:6)}}},De=(e,t,n,i)=>{if(e.buffer>0&&(e.coyote>0?Z(e,7):e.jumps>0&&!he(e,t)&&(e.jumps--,Z(e,6),e.ev=e.ev&~r.JUMP|r.DOUBLE)),i||!n.wx&&!n.wz)return;let a=B(e.vx,e.vz);e.vx+=n.wx*14*A,e.vz+=n.wz*14*A,ge(e,Math.max(a,6))},Oe=(n,r,i)=>{n.yaw=F(r.yaw),n.pitch=Math.max(-g,Math.min(g,r.pitch));let a=(r.keys&e.FORWARD?1:0)-(r.keys&e.BACK?1:0),o=(r.keys&e.RIGHT?1:0)-(r.keys&e.LEFT?1:0),s=B(a,o)||1,[c,l]=I(n.yaw),u=e=>(r.keys&e)!==0&&(n.held&e)===0,d={keys:r.keys,jump:u(e.JUMP),dash:u(e.DASH),fwd:a>0,wx:(c*a-l*o)/s,wz:(l*a+c*o)/s,fx:c,fz:l},f=n.mode;if(n.ev=0,n.fall=0,d.jump&&(n.buffer=7),n.dash>0&&(n.dash--,n.dash===50&&ge(n,10)),n.mode===t.HANG&&be(n,i,d),n.mode===t.CLIMB?xe(n,i):n.mode!==t.HANG&&Te(n,i,d),n.y<i.def.floor){let{yaw:e,pitch:t,id:r}=n;Object.assign(n,H(r,i,r),{yaw:e,pitch:t})}n.t=n.mode===f?Math.min(255,n.t+1):n.t,n.buffer=Math.max(0,n.buffer-1),n.mode===t.AIR&&f===t.AIR&&(n.coyote=Math.max(0,n.coyote-1)),n.held=r.keys&(e.JUMP|e.DASH),n.ground=U(n.mode),n.x=L(n.x),n.y=L(n.y),n.z=L(n.z),n.vx=L(n.vx),n.vy=L(n.vy),n.vz=L(n.vz),n.edge=L(n.edge)},ke=20,Ae=2,Q=[`#e6194b`,`#3cb44b`,`#ffe119`,`#4363d8`,`#f58231`,`#911eb4`,`#42d4f4`,`#f032e6`,`#bfef45`,`#fabed4`,`#469990`,`#dcbeff`,`#9a6324`,`#800000`,`#aaffc3`,`#808000`],$=(e,t)=>Array.from(e).slice(0,t).join(``).trim(),je=e=>$((typeof e==`string`?e:``).replace(/\s+/g,` `).replace(/\p{Cc}/gu,``).trim(),16),Me=(e,t)=>{let n=e;for(let r=2;t.includes(n);r++)n=`${$(e,15-`${r}`.length)} ${r}`;return n},Ne=(e,t)=>{let n=setInterval(e,t);return()=>clearInterval(n)},Pe=class{peers=/* @__PURE__ */ new Map;ticks=0;history=[];world;halt;rules;rr=0;constructor(e={},t=ae){this.rules={...re,...e},this.world=se(t)}get size(){return this.players().length}connect(e){this.peers.set(e,null)}receive(e,t){let n=this.peers.get(e);if(typeof t==`string`){let r=p(t);n===null&&r?.t===`join`&&this.join(e,r.name);return}let r=n&&d(t);r&&n.bank>0&&(n.bank--,Oe(n.state,r,this.world),n.ack=r.seq)}disconnect(e){let t=this.peers.get(e);this.peers.delete(e),t&&this.roster()}tick(){let e=this.players();if(!e.length)return;let t=++this.ticks;for(let t of e)t.bank=Math.min(10,t.bank+1);if(t%2==0){for(this.history.push({tick:t,players:e.map(e=>({...e.state}))});this.history[0].tick<t-30;)this.history.shift();let n=f({tick:t,players:e.map(e=>({...e.state,ack:e.ack}))});e.forEach(e=>e.conn.send(n))}}start(e=Ne){if(this.halt)return;let t=1e3/60,n=performance.now(),r=0;this.halt=e(()=>{let e=performance.now();r+=e-n,n=e;for(let e=0;r>=t&&e<ke;e++)this.tick(),r-=t;r%=t},t)}stop(){this.halt?.(),this.halt=void 0}rewind(e,t=0){let n=this.players().filter(t=>t.info.id!==e).map(e=>e.state),[r,i]=[this.history[0],this.history.at(-1)];if(!r||!i)return n;let a=((this.ticks-t+32768)%65536+65536)%65536-32768,o=Math.min(Math.max(this.ticks-a,r.tick),i.tick),s=0;for(;s+1<this.history.length&&this.history[s+1].tick<=o;)s++;let[c,l]=[this.history[s],this.history[s+1]??this.history[s]],u=l.tick>c.tick?(o-c.tick)/(l.tick-c.tick):0,d=(e,t)=>e+(t-e)*u;return n.map(e=>{let t=c.players.find(t=>t.id===e.id),n=l.players.find(t=>t.id===e.id);return t&&n?{...n,x:d(t.x,n.x),y:d(t.y,n.y),z:d(t.z,n.z)}:n??t??e})}place(e,t){let n=this.world.def.spawns.findIndex((n,r)=>{let{x:i,z:a}=H(e,this.world,r);return!t.some(e=>Math.hypot(e.x-i,e.z-a)<Ae)});return H(e,this.world,n<0?this.rr++:n)}players(){return[...this.peers.values()].filter(e=>e!==null)}join(e,t){let n=this.players();if(n.length>=this.rules.maxPlayers){e.send(JSON.stringify({t:`full`}));return}let r=0;for(;n.some(e=>e.info.id===r);)r++;let i=Q.find(e=>!n.some(t=>t.info.color===e))??Q[r%Q.length],a={conn:e,info:{id:r,name:Me(je(t)||`Player ${r}`,n.map(e=>e.info.name)),color:i},state:this.place(r,n.map(e=>e.state)),bank:10,ack:65535};this.peers.set(e,a),this.roster()}roster(){let e=this.players(),t=e.map(e=>e.info).sort((e,t)=>e.id-t.id);e.forEach(e=>e.conn.send(JSON.stringify({t:`roster`,you:e.info.id,players:t})))}},Fe=(e,t)=>{let n=()=>{},r=()=>{n();let r=setInterval(e,t);n=()=>clearInterval(r)};try{let i=URL.createObjectURL(new Blob([`setInterval(()=>postMessage(0),${t})`])),a=new Worker(i);a.onmessage=e,a.onerror=r,n=()=>{a.terminate(),URL.revokeObjectURL(i)}}catch{r()}return()=>n()},Ie=(e,t)=>{let n=`tiny-fps:`+e,r=Math.random().toString(36).slice(2),i=new BroadcastChannel(n),a=new AbortController,o=globalThis.navigator?.locks,s,c,l,u,d=[],f,m=!1,h=e=>i.postMessage({from:r,...e}),g=e=>!m&&S.onmessage?.({data:e}),_={send:e=>queueMicrotask(()=>g(e))},v=()=>{let e=d.length?d:f?[f]:[];return d=[],e},y=e=>{if(m)return e();l=e,u=r,c=/* @__PURE__ */ new Map,s=new Pe(t),s.start(Fe),s.connect(_),v().forEach(e=>s.receive(_,e)),h({kind:`h`})};i.onmessage=({data:e})=>{if(!m){if(s&&c){let{from:t,kind:n}=e,r=c.get(t);n===`q`?h({to:t,kind:`h`}):n===`m`&&!e.to?(r||(r={send:e=>!m&&h({to:t,kind:`m`,data:e})},c.set(t,r),s.connect(r)),s.receive(r,e.data)):n===`b`&&r&&(c.delete(t),s.disconnect(r))}else e.to!==r&&e.to||(e.kind===`m`&&e.to?g(e.data):e.kind===`h`&&e.from!==u&&(u=e.from,v().forEach(e=>h({kind:`m`,data:e}))))}};let b=e=>{m||(typeof e==`string`&&p(e)?.t===`join`&&(f=e),s?s.receive(_,e):u?h({kind:`m`,data:e}):d.push(e))},x=()=>{m||(m=!0,globalThis.removeEventListener?.(`pagehide`,x),s?(s.stop(),l()):(h({kind:`b`}),a.abort()),i.close(),setTimeout(()=>S.onclose?.()))},S={binaryType:`arraybuffer`,onopen:null,onclose:null,onmessage:null,send:b,close:x};return o?o.request(n,{signal:a.signal},()=>new Promise(y)).catch(()=>{}):y(()=>{}),h({kind:`q`}),globalThis.addEventListener?.(`pagehide`,x),setTimeout(()=>!m&&S.onopen?.()),S};export{Ie as localSocket};
1
+ var e={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,SPRINT:32,DASH:64,CROUCH:128},t={GROUND:0,AIR:1,WALLRUN:2,HANG:3,CLIMB:4,SLIDE:5,CROUCH:6},n={NONE:0,EAST:1,WEST:2,SOUTH:3,NORTH:4},r={JUMP:1,DOUBLE:2,DASH:4,LAND:8,GRAB:16,CLIMB:32,WALLRUN_START:64,WALLRUN_END:128,SLIDE_START:256,SLIDE_END:512},i={BRICK:0,TILE:1,LAVA:2,STONE:3,METAL:4,WOOD:5,MOSS:6,GRATE:7},a=65536/(2*Math.PI),o=e=>Math.round(e*a)&65535,s=e=>Math.max(-32768,Math.min(32767,Math.round(e))),c=e=>s(e*1e4),l=e=>e/1e4,u=e=>e/a,d=e=>{if(e.byteLength!==11)return null;let t=new DataView(e);return t.getUint8(0)===1?{seq:t.getUint16(1),keys:t.getUint8(3),yaw:u(t.getUint16(4)),pitch:l(t.getInt16(6)),view:(t.getUint16(8)*256+t.getUint8(10))/256}:null},f=t=>{let n=/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(4+39*t.players.length));return n.setUint8(0,2),n.setUint16(1,t.tick&65535),n.setUint8(3,t.players.length),t.players.forEach((t,r)=>{let i=4+r*39;n.setUint8(i,t.id),n.setFloat32(i+1,t.x),n.setFloat32(i+5,t.y),n.setFloat32(i+9,t.z),n.setFloat32(i+13,t.vx),n.setFloat32(i+17,t.vy),n.setFloat32(i+21,t.vz),n.setFloat32(i+25,t.edge),n.setUint16(i+29,o(t.yaw)),n.setInt16(i+31,c(t.pitch)),n.setUint16(i+33,t.ack&65535),n.setUint8(i+35,t.mode&7|(t.wall&7)<<3|(t.jumps&1)<<6|t.dashes<<7),n.setUint8(i+36,t.t),n.setUint8(i+37,t.dash),n.setUint8(i+38,t.coyote&7|(t.buffer&7)<<3|(t.held&e.JUMP?64:0)|(t.held&e.DASH?128:0))}),n.buffer},p=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},m=.4,h=1.8,g=1.55,_=.9,v=7.5,y=1.5,b=.15,x=.5,S=.9,ee=6.5,te=.2,ne=.03,re=.2,C=5.5,ie={maxPlayers:16},ae=-30,w=(e,t,n,r,a)=>({min:[e,ae,t],max:[n,a,r],top:i.TILE,side:i.BRICK}),T=([e,t,n],[r,i,a],o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c}),oe={name:`Rooftops`,brushes:[w(4,57.7,24,76,10),w(4,36,24,53.5,10),w(4,20,24,36,12.4),w(4,-5,24,7,12.4),w(27,20,47,50,8),w(27,60,47,76,8),T([9,12.2,39],[19,12.6,47],i.METAL,i.METAL),...((e,t)=>[1,2,3,4,5,6].map(n=>T([12,t,e-n],[14,t+.4*n,e-n+1],i.STONE,i.STONE)))(53,10),T([5,10,42],[5.5,14,42.5],i.METAL),T([5,10,50],[5.5,14,50.5],i.METAL),T([8,12.4,24],[20,12.85,24.45],i.METAL),T([36,8,22],[37,14.5,48],i.STONE,i.STONE,[1,.75,.62]),T([30,8,28],[34,10,32],i.STONE,i.BRICK),T([40,8,30],[44,10.2,34],i.STONE,i.BRICK),T([28,9.2,44],[35,12,46],i.METAL,i.GRATE,[.8,.9,1]),T([41.5,7.6,50],[42,8,60],i.METAL),T([30,8,64],[34,9.6,68],i.STONE,i.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]},se=4,E=1024,D=(e,t)=>(e+E)*(2*E)+t+E,O=(e,t)=>Math.min(Math.max(Math.floor(e/t),-1024),1023),ce=(e,t=se)=>{let n=/* @__PURE__ */ new Map;return e.brushes.forEach(({min:e,max:r},i)=>{for(let a=O(e[0],t);a<=O(r[0],t);a++)for(let o=O(e[2],t);o<=O(r[2],t);o++){let e=D(a,o),t=n.get(e);t?t.push(i):n.set(e,[i])}}),{def:e,cell:t,grid:n}},k=(e,t,n,r)=>{let i=[];for(let a=O(t-r,e.cell);a<=O(t+r,e.cell);a++)for(let t=O(n-r,e.cell);t<=O(n+r,e.cell);t++)for(let n of e.grid.get(D(a,t))??[])i.includes(n)||i.push(n);return i},A=1/60,j=Math.PI*2,M=1e-6,N=.01,P=.001,F=e=>(e%j+j)%j,le=e=>[-Math.sin(e),-Math.cos(e)],I=Math.fround,ue=Math.sqrt,L=(e,t,n)=>Math.min(Math.max(e,t),n),R=(e,t)=>ue(e*e+t*t),z=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],de={vx:0,vz:0,mode:t.GROUND,t:0,wall:n.NONE,edge:0,jumps:1,dashes:1,dash:0,coyote:6,buffer:0,held:0,ev:0,fall:0},B=(e,t,n)=>{let{spawns:r}=t.def,[i,a,o,s]=r[(n%r.length+r.length)%r.length];return{id:e,x:I(i),y:I(a),z:I(o),vy:0,yaw:F(s),pitch:0,ground:!0,...de}},V=e=>e===t.GROUND||e===t.SLIDE||e===t.CROUCH,fe=e=>e.mode===t.SLIDE||e.mode===t.CROUCH?_:h,H=(e,t,n)=>e.max[1]>t+.5+N&&e.min[1]<t+n-N,U=(e,t,n)=>[t-L(t,e.min[0],e.max[0]),n-L(n,e.min[2],e.max[2])],pe=(e,t,n)=>{let{brushes:r}=t.def,i=k(t,e.x,e.z,2*m),a=(m-M)**2,[o,s]=[0,0];for(let t=0;t<4;t++){let t=0,c=0,l=0;for(let o of i){let i=r[o];if(!H(i,e.y,n))continue;let[s,u]=U(i,e.x,e.z),d=s*s+u*u;if(d>=a)continue;if(d){let e=ue(d);.4-e>t&&(t=m-e,c=s/e*t,l=u/e*t);continue}let[f,p,h]=[[e.x-i.min[0],-1,0],[i.max[0]-e.x,1,0],[e.z-i.min[2],0,-1],[i.max[2]-e.z,0,1]].reduce((e,t)=>t[0]<e[0]?t:e);f+.4>t&&(t=f+m,[c,l]=[p*t,h*t])}if(!t)break;e.x+=c,e.z+=l,o+=c,s+=l}return[o,s]},W=(e,t,n)=>{let{brushes:r}=t.def,i=(m-M)**2,a=-1/0,o=1/0;for(let s of k(t,e.x,e.z,m)){let t=r[s],[c,l]=U(t,e.x,e.z);c*c+l*l>=i||(t.max[1]<=e.y+.5+N?a=Math.max(a,t.max[1]):t.min[1]>=e.y+n-N&&(o=Math.min(o,t.min[1])))}return[a,o]},G=(e,t)=>{let n=(m-M)**2;return k(t,e.x,e.z,m).every(r=>{let i=t.def.brushes[r],[a,o]=U(i,e.x,e.z);return a*a+o*o>=n||!H(i,e.y,1.8)})},K=(e,t,n,r,i)=>{let a=(m-M)**2;return k(e,t,n,m).every(o=>{let s=e.def.brushes[o],[c,l]=U(s,t,n);return c*c+l*l>=a||s.max[1]<=r||s.min[1]>=i})},q=(e,t)=>{let[n,r]=z[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}},J=(e,t,n,r)=>{let{a:i,o:a,sign:o,c:s,co:c}=q(t,n),l=((o>0?e.min[i]:e.max[i])-s)*o;return l>=.4-P&&l<=.4+r&&c>=e.min[a]&&c<=e.max[a]?l:void 0},Y=(e,t,n)=>{let r;for(let i of k(t,e.x,e.z,m+x)){let a=t.def.brushes[i],o=J(a,e,n,x);o!==void 0&&a.min[1]<e.y+.5&&a.max[1]>e.y+1.8&&(r=Math.min(r??1/0,Math.max(0,o-m)))}return r},me=(e,t)=>{let[n,r]=le(e.yaw),i;for(let a=1;a<=4;a++){let[o,s]=z[a];if(a===e.wall||n*o+r*s<.5)continue;let{a:c,sign:l}=q(e,a);for(let n of k(t,e.x,e.z,m+te)){let r=t.def.brushes[n],o=r.max[1],s=o-e.y;if(J(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*(m+ne),f=u+l*re,[p,h]=c===0?[d,e.z]:[e.x,d],[g,_]=c===0?[f,e.z]:[e.x,f];K(t,p,h,Math.min(e.y,o-2)+N,o+1.8)&&K(t,g,_,o+N,o+1.8)&&(i={side:a,top:o,hang:d})}}return i},he=(e,t)=>{let{a:n,o:r,sign:i,c:a,co:o}=q(e,e.wall);return k(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 I(c.max[1])===e.edge&&o>=c.min[r]&&o<=c.max[r]&&l>=.2})},ge=(e,t)=>{if(e.vy>=0)return!1;let[n]=W(e,t,h),r=6*A;return e.y-n<=-e.vy*r+10*r*r},X=(e,t)=>{e.mode=t,e.t=0},_e=(e,t)=>{let n=R(e.vx,e.vz);n>t&&(e.vx*=t/n,e.vz*=t/n)},ve=(e,t,n,r)=>{let[i,a]=[n.wx,n.wz];for(let n of k(t,e.x,e.z,m+P)){let o=t.def.brushes[n],[s,c]=U(o,e.x,e.z),l=R(s,c);if(l>0&&l<=.4+P&&H(o,e.y,r)){let e=(-i*s-a*c)/l;e>0&&(i+=e*s/l,a+=e*c/l)}}return[i,a]},ye=(e,t,n)=>{let r=R(t[0],t[1]);if(r<M){let t=R(e.vx,e.vz),n=t?Math.max(0,t-45*A)/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=R(s,c);if(l){let e=Math.max(0,l-45*A)/l;[s,c]=[s*e,c*e]}n*=r,o=o<n?Math.min(n,o+(o>=6?3:50)*A):Math.max(n,o-12*A),e.vx=s+o*i,e.vz=c+o*a},be=(e,t,n,r,i)=>{let a=e.y;e.x+=e.vx*A,e.z+=e.vz*A;let[o,s]=pe(e,t,n),c=R(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]=W(e,t,n),d=e.vy-r*20*A;if(e.y+=(e.vy+d)/2*A,e.vy=d,e.y+n>u&&(e.y=u-n,e.vy=Math.min(e.vy,0)),e.vy<=0?e.y<=l+N: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},Z=(e,t)=>{e.vy=t,e.coyote=0,e.buffer=0,e.ev|=r.JUMP},xe=(n,r,i)=>{let[a,o]=z[n.wall],s=e=>{X(n,e),n.edge=0};if(i.keys&(e.BACK|e.CROUCH))s(t.AIR),n.coyote=0;else if(i.jump&&i.fx*a+i.fz*o<0)s(t.AIR),n.vx=-a*4,n.vz=-o*4,Z(n,6);else if(i.jump||i.fwd&&n.t>=6)X(n,t.CLIMB);else if(n.t>=30)s(t.AIR),n.coyote=0;else{let e=Math.max(n.edge-2,W(n,r,h)[0]);n.y+=L(e-n.y,-8*A,8*A)}},Se=(e,i)=>{let[a,o]=z[e.wall];e.y<e.edge?e.y=Math.min(e.edge,e.y+8*A):(e.x+=a*C*A,e.z+=o*C*A),e.y>=e.edge&&he(e,i)?(X(e,t.GROUND),e.vx=a*3,e.vz=o*3,e.vy=0,e.edge=0,e.wall=n.NONE,e.coyote=6,e.ev|=r.CLIMB):e.t>=40&&(X(e,e.y>=e.edge?t.GROUND:t.AIR),e.edge=0,e.wall=n.NONE)},Ce=(e,n,i)=>{let[a,o]=z[e.wall],s=e.vx*a+e.vz*o,[c,l]=[e.vx-s*a,e.vz-s*o],u=R(c,l);if(i.jump)X(e,t.AIR),e.vx=c-a*5,e.vz=l-o*5,Z(e,ee),e.jumps=1,e.dashes=1,e.ev|=r.WALLRUN_END;else{let s=Y(e,n,e.wall);if(s===void 0||!i.fwd||u<3.5||e.t>=60){X(e,t.AIR),e.ev|=r.WALLRUN_END;return}let d=Math.max(0,u-y*A)/u;e.vx=c*d,e.vz=l*d;let f=Math.min(s,4*A);e.x+=a*f,e.z+=o*f}},we=(e,n,i)=>{if(!i.fwd)return;let a=R(e.vx,e.vz);if(!(a<4.5))for(let i=1;i<=4;i++){let[o,s]=z[i],c=e.vx*o+e.vz*s,[l,u]=[e.vx-c*o,e.vz-c*s];if(i!==e.wall&&c<=.75*a&&c>=-.2*a&&Y(e,n,i)!==void 0){let n=R(l,u),o=Math.max(n,S*a)/n;X(e,t.WALLRUN),e.wall=i,[e.vx,e.vz]=[l*o,u*o],e.vy=L(e.vy,2,3),e.jumps=1,e.dashes=1,e.coyote=0,e.ev|=r.WALLRUN_START;return}}},Te=(e,i)=>{X(e,t.HANG),e.wall=i.side,e.edge=I(i.top),i.side<=n.WEST?e.x=i.hang:e.z=i.hang,e.vx=e.vy=e.vz=0,e.jumps=1,e.dashes=1,e.coyote=0,e.buffer=0,e.ev|=r.GRAB},Ee=(i,a,o)=>{let s=i.mode===t.GROUND;if(o.dash&&i.dash===0&&(s||(i.mode===t.AIR||i.mode===t.WALLRUN)&&i.dashes>0)){let[e,n]=o.wx||o.wz?[o.wx,o.wz]:[o.fx,o.fz];s||(i.dashes--,i.vy=0,i.mode===t.WALLRUN&&(X(i,t.AIR),i.ev|=r.WALLRUN_END)),i.vx=e*16,i.vz=n*16,i.dash=60,i.ev|=r.DASH}let c=i.dash>50;i.mode===t.WALLRUN&&Ce(i,a,o),V(i.mode)&&De(i,a,o,c),i.mode===t.AIR&&Oe(i,a,o,c);let l=c&&i.vy<=0?0:i.mode===t.WALLRUN?b:1,u=i.mode,d=be(i,a,fe(i),l,V(u));if(d>=0){if(!V(i.mode)){if(i.ev|=r.LAND|(i.mode===t.WALLRUN?r.WALLRUN_END:0),i.fall=d,i.jumps=1,i.dashes=1,i.wall=n.NONE,o.keys&e.CROUCH){let e=R(i.vx,i.vz)>=v;X(i,e?t.SLIDE:t.CROUCH),i.ev|=e?r.SLIDE_START:0}else X(i,t.GROUND)}i.coyote=6}else V(i.mode)&&(i.ev|=i.mode===t.SLIDE?r.SLIDE_END:0,X(i,t.AIR));if(i.mode===t.AIR){let e=me(i,a);e?Te(i,e):we(i,a,o)}},De=(n,i,a,o)=>{let s=(a.keys&e.CROUCH)!==0;if(n.buffer>0&&(n.mode===t.GROUND||G(n,i))){n.ev|=n.mode===t.SLIDE?r.SLIDE_END:0,X(n,t.AIR),Z(n,7);return}let c=R(n.vx,n.vz);if(n.mode===t.GROUND&&s){let e=c>=v;X(n,e?t.SLIDE:t.CROUCH),n.ev|=e?r.SLIDE_START:0}else n.mode===t.SLIDE&&(n.t>=60||c<4.5)?(n.ev|=r.SLIDE_END,X(n,!s&&G(n,i)?t.GROUND:t.CROUCH)):n.mode===t.SLIDE&&!s&&G(n,i)?(n.ev|=r.SLIDE_END,X(n,t.GROUND)):n.mode===t.CROUCH&&!s&&G(n,i)&&X(n,t.GROUND);if(!o){if(n.mode===t.SLIDE){let e=Math.max(0,c-4*A)/c;n.vx*=e,n.vz*=e}else if(n.mode===t.CROUCH)ye(n,ve(n,i,a,_),3);else{let t=(a.keys&e.SPRINT)!==0&&a.fwd;ye(n,ve(n,i,a,h),t?9:6)}}},Oe=(e,t,n,i)=>{if(e.buffer>0&&(e.coyote>0?Z(e,7):e.jumps>0&&!ge(e,t)&&(e.jumps--,Z(e,6),e.ev=e.ev&~r.JUMP|r.DOUBLE)),i||!n.wx&&!n.wz)return;let a=R(e.vx,e.vz);e.vx+=n.wx*14*A,e.vz+=n.wz*14*A,_e(e,Math.max(a,6))},ke=(n,r,i)=>{n.yaw=F(r.yaw),n.pitch=Math.max(-g,Math.min(g,r.pitch));let a=(r.keys&e.FORWARD?1:0)-(r.keys&e.BACK?1:0),o=(r.keys&e.RIGHT?1:0)-(r.keys&e.LEFT?1:0),s=R(a,o)||1,[c,l]=le(n.yaw),u=e=>(r.keys&e)!==0&&(n.held&e)===0,d={keys:r.keys,jump:u(e.JUMP),dash:u(e.DASH),fwd:a>0,wx:(c*a-l*o)/s,wz:(l*a+c*o)/s,fx:c,fz:l},f=n.mode;if(n.ev=0,n.fall=0,d.jump&&(n.buffer=7),n.dash>0&&(n.dash--,n.dash===50&&_e(n,10)),n.mode===t.HANG&&xe(n,i,d),n.mode===t.CLIMB?Se(n,i):n.mode!==t.HANG&&Ee(n,i,d),n.y<i.def.floor){let{yaw:e,pitch:t,id:r}=n;Object.assign(n,B(r,i,r),{yaw:e,pitch:t})}n.t=n.mode===f?Math.min(255,n.t+1):n.t,n.buffer=Math.max(0,n.buffer-1),n.mode===t.AIR&&f===t.AIR&&(n.coyote=Math.max(0,n.coyote-1)),n.held=r.keys&(e.JUMP|e.DASH),n.ground=V(n.mode),n.x=I(n.x),n.y=I(n.y),n.z=I(n.z),n.vx=I(n.vx),n.vy=I(n.vy),n.vz=I(n.vz),n.edge=I(n.edge)},Ae=20,je=2,Q=[`#e6194b`,`#3cb44b`,`#ffe119`,`#4363d8`,`#f58231`,`#911eb4`,`#42d4f4`,`#f032e6`,`#bfef45`,`#fabed4`,`#469990`,`#dcbeff`,`#9a6324`,`#800000`,`#aaffc3`,`#808000`],$=(e,t)=>Array.from(e).slice(0,t).join(``).trim(),Me=e=>$((typeof e==`string`?e:``).replace(/\s+/g,` `).replace(/\p{Cc}/gu,``).trim(),16),Ne=(e,t)=>{let n=e;for(let r=2;t.includes(n);r++)n=`${$(e,15-`${r}`.length)} ${r}`;return n},Pe=(e,t)=>{let n=setInterval(e,t);return()=>clearInterval(n)},Fe=class{peers=/* @__PURE__ */ new Map;ticks=0;history=[];world;halt;rules;rr=0;constructor(e={},t=oe){this.rules={...ie,...e},this.world=ce(t)}get size(){return this.players().length}connect(e){this.peers.set(e,null)}receive(e,t){let n=this.peers.get(e);if(typeof t==`string`){let r=p(t);n===null&&r?.t===`join`&&this.join(e,r.name);return}let r=n&&d(t);r&&n.bank>0&&(n.bank--,ke(n.state,r,this.world),n.ack=r.seq)}disconnect(e){let t=this.peers.get(e);this.peers.delete(e),t&&this.roster()}tick(){let e=this.players();if(!e.length)return;let t=++this.ticks;for(let t of e)t.bank=Math.min(10,t.bank+1);if(t%2==0){for(this.history.push({tick:t,players:e.map(e=>({...e.state}))});this.history[0].tick<t-30;)this.history.shift();let n=f({tick:t,players:e.map(e=>({...e.state,ack:e.ack}))});e.forEach(e=>e.conn.send(n))}}start(e=Pe){if(this.halt)return;let t=1e3/60,n=performance.now(),r=0;this.halt=e(()=>{let e=performance.now();r+=e-n,n=e;for(let e=0;r>=t&&e<Ae;e++)this.tick(),r-=t;r%=t},t)}stop(){this.halt?.(),this.halt=void 0}rewind(e,t=0){let n=this.players().filter(t=>t.info.id!==e).map(e=>e.state),[r,i]=[this.history[0],this.history.at(-1)];if(!r||!i)return n;let a=((this.ticks-t+32768)%65536+65536)%65536-32768,o=Math.min(Math.max(this.ticks-a,r.tick),i.tick),s=0;for(;s+1<this.history.length&&this.history[s+1].tick<=o;)s++;let[c,l]=[this.history[s],this.history[s+1]??this.history[s]],u=l.tick>c.tick?(o-c.tick)/(l.tick-c.tick):0,d=(e,t)=>e+(t-e)*u;return n.map(e=>{let t=c.players.find(t=>t.id===e.id),n=l.players.find(t=>t.id===e.id);return t&&n?{...n,x:d(t.x,n.x),y:d(t.y,n.y),z:d(t.z,n.z)}:n??t??e})}place(e,t){let n=this.world.def.spawns.findIndex((n,r)=>{let{x:i,z:a}=B(e,this.world,r);return!t.some(e=>Math.hypot(e.x-i,e.z-a)<je)});return B(e,this.world,n<0?this.rr++:n)}players(){return[...this.peers.values()].filter(e=>e!==null)}join(e,t){let n=this.players();if(n.length>=this.rules.maxPlayers){e.send(JSON.stringify({t:`full`}));return}let r=0;for(;n.some(e=>e.info.id===r);)r++;let i=Q.find(e=>!n.some(t=>t.info.color===e))??Q[r%Q.length],a={conn:e,info:{id:r,name:Ne(Me(t)||`Player ${r}`,n.map(e=>e.info.name)),color:i},state:this.place(r,n.map(e=>e.state)),bank:10,ack:65535};this.peers.set(e,a),this.roster()}roster(){let e=this.players(),t=e.map(e=>e.info).sort((e,t)=>e.id-t.id);e.forEach(e=>e.conn.send(JSON.stringify({t:`roster`,you:e.info.id,players:t})))}},Ie=(e,t)=>{let n=()=>{},r=()=>{n();let r=setInterval(e,t);n=()=>clearInterval(r)};try{let i=URL.createObjectURL(new Blob([`setInterval(()=>postMessage(0),${t})`])),a=new Worker(i);a.onmessage=e,a.onerror=r,n=()=>{a.terminate(),URL.revokeObjectURL(i)}}catch{r()}return()=>n()},Le=(e,t)=>{let n=`tiny-fps:`+e,r=Math.random().toString(36).slice(2),i=new BroadcastChannel(n),a=new AbortController,o=globalThis.navigator?.locks,s,c,l,u,d=[],f,m=!1,h=e=>i.postMessage({from:r,...e}),g=e=>!m&&S.onmessage?.({data:e}),_={send:e=>queueMicrotask(()=>g(e))},v=()=>{let e=d.length?d:f?[f]:[];return d=[],e},y=e=>{if(m)return e();l=e,u=r,c=/* @__PURE__ */ new Map,s=new Fe(t),s.start(Ie),s.connect(_),v().forEach(e=>s.receive(_,e)),h({kind:`h`})};i.onmessage=({data:e})=>{if(!m){if(s&&c){let{from:t,kind:n}=e,r=c.get(t);n===`q`?h({to:t,kind:`h`}):n===`m`&&!e.to?(r||(r={send:e=>!m&&h({to:t,kind:`m`,data:e})},c.set(t,r),s.connect(r)),s.receive(r,e.data)):n===`b`&&r&&(c.delete(t),s.disconnect(r))}else e.to!==r&&e.to||(e.kind===`m`&&e.to?g(e.data):e.kind===`h`&&e.from!==u&&(u=e.from,v().forEach(e=>h({kind:`m`,data:e}))))}};let b=e=>{m||(typeof e==`string`&&p(e)?.t===`join`&&(f=e),s?s.receive(_,e):u?h({kind:`m`,data:e}):d.push(e))},x=()=>{m||(m=!0,globalThis.removeEventListener?.(`pagehide`,x),s?(s.stop(),l()):(h({kind:`b`}),a.abort()),i.close(),setTimeout(()=>S.onclose?.()))},S={binaryType:`arraybuffer`,onopen:null,onclose:null,onmessage:null,send:b,close:x};return o?o.request(n,{signal:a.signal},()=>new Promise(y)).catch(()=>{}):y(()=>{}),h({kind:`q`}),globalThis.addEventListener?.(`pagehide`,x),setTimeout(()=>!m&&S.onopen?.()),S};export{Le as localSocket};
package/dist/server.js CHANGED
@@ -10,11 +10,15 @@ var LOW_H = .9;
10
10
  /** Speed from which a crouch is a slide (above RUN_SPEED: only a sprint slides). */
11
11
  var SLIDE_MIN_SPEED = 7.5;
12
12
  /** Speed lost along the wall, m/s². */
13
- var WALLRUN_DRAG = 2.5;
14
- /** Gravity during the run, as a share of GRAVITY, and the fastest rise it starts with. */
13
+ var WALLRUN_DRAG = 1.5;
14
+ /**
15
+ * Gravity during the run, as a share of GRAVITY. The start lifts the rise to at least
16
+ * WALLRUN_LIFT and holds it to at most WALLRUN_VY_MAX (m/s).
17
+ */
15
18
  var WALLRUN_GRAVITY = .15;
16
19
  /** How far from the cylinder a wall still counts as next to it (m). */
17
- var WALL_REACH = .15;
20
+ var WALL_REACH = .5;
21
+ var WALL_TURN_KEEP = .9;
18
22
  var WALL_KICK_UP = 6.5;
19
23
  /** A hand's reach beyond the cylinder (m), and the gap left between the hanging body and the wall. */
20
24
  var GRAB_REACH = .2;
@@ -600,11 +604,19 @@ var faceDist = (b, p, side, reach) => {
600
604
  const dist = ((sign > 0 ? b.min[a] : b.max[a]) - c) * sign;
601
605
  return dist >= .4 - TOUCH && dist <= .4 + reach && co >= b.min[o] && co <= b.max[o] ? dist : void 0;
602
606
  };
603
- /** Whether a wall on `side` covers the body from the knees to the head and is within reach. */
604
- var wallOn = (p, w, side) => near(w, p.x, p.z, PLAYER_R + WALL_REACH).some((i) => {
605
- const b = w.def.brushes[i];
606
- return faceDist(b, p, side, .15) !== void 0 && b.min[1] < p.y + .5 && b.max[1] > p.y + 1.8;
607
- });
607
+ /**
608
+ * The gap between the cylinder and a wall on `side` that covers the body from the knees to the
609
+ * head and is within WALL_REACH (the nearest one), or undefined when there is none.
610
+ */
611
+ var wallGap = (p, w, side) => {
612
+ let best;
613
+ for (const i of near(w, p.x, p.z, PLAYER_R + WALL_REACH)) {
614
+ const b = w.def.brushes[i];
615
+ const d = faceDist(b, p, side, WALL_REACH);
616
+ if (d !== void 0 && b.min[1] < p.y + .5 && b.max[1] > p.y + 1.8) best = Math.min(best ?? Infinity, Math.max(0, d - PLAYER_R));
617
+ }
618
+ return best;
619
+ };
608
620
  /**
609
621
  * The highest ledge the player can catch: on a side he faces and is not locked out of, a top
610
622
  * GRAB_MIN to GRAB_MAX above the feet on a box that goes down at least 0.25 m under it, with the
@@ -823,28 +835,42 @@ var run = (p, w, c) => {
823
835
  p.jumps = 1;
824
836
  p.dashes = 1;
825
837
  p.ev |= EV.WALLRUN_END;
826
- } else if (!c.fwd || s < 5.5 || p.t >= 60 || !wallOn(p, w, p.wall)) {
827
- enter(p, MODE.AIR);
828
- p.ev |= EV.WALLRUN_END;
829
838
  } else {
839
+ const gap = wallGap(p, w, p.wall);
840
+ if (gap === void 0 || !c.fwd || s < 3.5 || p.t >= 60) {
841
+ enter(p, MODE.AIR);
842
+ p.ev |= EV.WALLRUN_END;
843
+ return;
844
+ }
830
845
  const k = Math.max(0, s - WALLRUN_DRAG * DT) / s;
831
846
  p.vx = tx * k;
832
847
  p.vz = tz * k;
848
+ const pull = Math.min(gap, 4 * DT);
849
+ p.x += nx * pull;
850
+ p.z += nz * pull;
833
851
  }
834
852
  };
835
- /** Starts a wall-run if the player is moving fast along a wall he is next to. */
853
+ /**
854
+ * Starts a wall-run if the player, in the air with forward held, runs at least WALLRUN_MIN_SPEED
855
+ * toward or along a wall within reach: at most WALL_PARALLEL of the speed into it (about 49
856
+ * degrees off the wall) and at most WALL_AWAY of it away. The velocity is turned along the wall,
857
+ * keeping WALL_TURN_KEEP of the speed (all of it from a parallel run), with a small lift.
858
+ */
836
859
  var startRun = (p, w, c) => {
837
860
  if (!c.fwd) return;
838
861
  const s = len(p.vx, p.vz);
862
+ if (s < 4.5) return;
839
863
  for (let side = 1; side <= 4; side++) {
840
864
  const [nx, nz] = TOWARD[side];
841
865
  const into = p.vx * nx + p.vz * nz;
842
866
  const [tx, tz] = [p.vx - into * nx, p.vz - into * nz];
843
- if (side !== p.wall && len(tx, tz) >= 7 && Math.abs(into) <= .4 * s && wallOn(p, w, side)) {
867
+ if (side !== p.wall && into <= .75 * s && into >= -.2 * s && wallGap(p, w, side) !== void 0) {
868
+ const t = len(tx, tz);
869
+ const k = Math.max(t, WALL_TURN_KEEP * s) / t;
844
870
  enter(p, MODE.WALLRUN);
845
871
  p.wall = side;
846
- [p.vx, p.vz] = [tx, tz];
847
- p.vy = Math.min(p.vy, 3);
872
+ [p.vx, p.vz] = [tx * k, tz * k];
873
+ p.vy = clamp(p.vy, 2, 3);
848
874
  p.jumps = 1;
849
875
  p.dashes = 1;
850
876
  p.coyote = 0;
@@ -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;
@@ -18,6 +18,6 @@ export interface TinyFps {
18
18
  /**
19
19
  * Mounts the game in a Shadow DOM inside container: one WebGL2 canvas filling it, a click locks the
20
20
  * pointer, the mouse looks, WASD (ZQSD on AZERTY) moves, Shift sprints, Space jumps (again in the
21
- * air for a second jump), E or the right button dashes, C crouches and slides.
21
+ * air for a second jump), C crouches and slides, a direction key pressed twice dashes.
22
22
  */
23
23
  export declare const tinyFps: (container: HTMLElement, opts: TinyFpsOptions) => TinyFps;
@@ -1,3 +1,7 @@
1
+ /** Two presses of the same direction key this close (ms) are a dash that way. */
2
+ export declare const DOUBLE_TAP_MS = 250;
3
+ /** The keys of the step of a dash toward `dir` (a direction bit): only that direction is held with it. */
4
+ export declare const dashKeys: (keys: number, dir: number) => number;
1
5
  /** The KEY bit of a KeyboardEvent.code, 0 for a key the game ignores. */
2
6
  export declare const keyBit: (code: string) => number;
3
7
  /** Live look angles and held keys; the loop reads them once per step and per frame. */
@@ -8,6 +12,12 @@ export interface Controls {
8
12
  pitch: number;
9
13
  /** KEY bits held now. */
10
14
  keys: number;
15
+ /**
16
+ * The KEY bits of the next step, read once per step. Same as `keys`, except for the step right
17
+ * after a double tap: it carries DASH and only the tapped direction, so the dash goes that way
18
+ * whatever else is held, and nothing else is on the wire.
19
+ */
20
+ take(): number;
11
21
  /** The canvas holds the pointer lock. */
12
22
  locked(): boolean;
13
23
  /** Removes every listener. */
@@ -15,6 +25,7 @@ export interface Controls {
15
25
  }
16
26
  /**
17
27
  * Click the canvas to lock the pointer; while locked the mouse looks, the keys move (WASD, Shift
18
- * sprints, Space jumps, E or the right button dashes, C crouches) and M calls `onMute`.
28
+ * sprints, Space jumps, C crouches, a direction key pressed twice within DOUBLE_TAP_MS dashes that
29
+ * way) and M calls `onMute`.
19
30
  */
20
31
  export declare const createInput: (canvas: HTMLCanvasElement, onMute?: () => void) => Controls;
@@ -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
@@ -72,20 +72,35 @@ export declare const SLIDE_END_SPEED = 4.5;
72
72
  export declare const SLIDE_TICKS = 60;
73
73
  /** Top speed of a crouch walk. */
74
74
  export declare const CROUCH_SPEED = 3;
75
- /** Wall-run: moving at least this fast along a wall (m/s) starts it, and under WALLRUN_KEEP it ends. */
76
- export declare const WALLRUN_MIN_SPEED = 7;
77
- export declare const WALLRUN_KEEP_SPEED = 5.5;
75
+ /**
76
+ * Wall-run: in the air with forward held, running at least WALLRUN_MIN_SPEED (m/s, a normal run is
77
+ * 6) toward or along a wall within reach starts it; under WALLRUN_KEEP_SPEED it ends.
78
+ */
79
+ export declare const WALLRUN_MIN_SPEED = 4.5;
80
+ export declare const WALLRUN_KEEP_SPEED = 3.5;
78
81
  /** Speed lost along the wall, m/s². */
79
- export declare const WALLRUN_DRAG = 2.5;
82
+ export declare const WALLRUN_DRAG = 1.5;
80
83
  /** Longest run, in ticks (1 s). */
81
84
  export declare const WALLRUN_TICKS = 60;
82
- /** Gravity during the run, as a share of GRAVITY, and the fastest rise it starts with. */
85
+ /**
86
+ * Gravity during the run, as a share of GRAVITY. The start lifts the rise to at least
87
+ * WALLRUN_LIFT and holds it to at most WALLRUN_VY_MAX (m/s).
88
+ */
83
89
  export declare const WALLRUN_GRAVITY = 0.15;
90
+ export declare const WALLRUN_LIFT = 2;
84
91
  export declare const WALLRUN_VY_MAX = 3;
85
92
  /** How far from the cylinder a wall still counts as next to it (m). */
86
- export declare const WALL_REACH = 0.15;
87
- /** The share of the speed that may point into or away from the wall for it to count as along it. */
88
- export declare const WALL_PARALLEL = 0.4;
93
+ export declare const WALL_REACH = 0.5;
94
+ /**
95
+ * The share of the speed that may point into the wall for a run to start (0.75 is 49 degrees off
96
+ * the wall), and the share that may point away from it. A run starting at an angle is turned
97
+ * along the wall and keeps WALL_TURN_KEEP of its speed (a parallel one keeps all of it).
98
+ */
99
+ export declare const WALL_PARALLEL = 0.75;
100
+ export declare const WALL_AWAY = 0.2;
101
+ export declare const WALL_TURN_KEEP = 0.9;
102
+ /** Speed at which a run draws the body in to the wall when it starts up to WALL_REACH away (m/s). */
103
+ export declare const WALL_PULL = 4;
89
104
  /** A kick-off from the wall: speed away from it and upward (m/s). */
90
105
  export declare const WALL_KICK_SPEED = 5;
91
106
  export declare const WALL_KICK_UP = 6.5;
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.16.0",
6
6
  "type": "module",
7
7
  "files": [
8
8
  "dist"