@korial29/tiny-fps 0.10.0 → 0.12.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
@@ -10,15 +10,15 @@
10
10
 
11
11
  **▶ Play it now: https://korial29.github.io/tiny-fps/**
12
12
 
13
- A tiny co-op first-person shooter for the browser, written in TypeScript with raw WebGL2, no game library and no runtime dependency. Players team up against walkers and flyers through five dark levels: find the keys, open the barred gates, reach the goal, then get everyone back to the start. Everything is generated in code: geometry, textures, lights. There are no images, fonts or assets to serve.
13
+ A tiny multiplayer first-person game for the browser, written in TypeScript with raw WebGL2, no game library and no runtime dependency. It is becoming an open-air capture-the-flag between two teams of players on rooftops, inspired by Mirror's Edge: parkour movement, no weapons, no CPU enemies. The game is being rebuilt step by step toward that ([`docs/PLAN.md`](docs/PLAN.md)): today you run and jump around one empty rooftop with the other players in the room. Everything is generated in code: geometry, textures, lights. There are no images, fonts or assets to serve.
14
14
 
15
- It is inspired by carlini's [Yet Another Doom Clone](https://github.com/carlini/js13k2019-yet-another-doom-clone) (js13k 2019), and adds multiplayer. Only the ideas are reused, not the code.
15
+ It started as a co-op shooter inspired by carlini's [Yet Another Doom Clone](https://github.com/carlini/js13k2019-yet-another-doom-clone) (js13k 2019). Only the ideas were reused, not the code. The renderer, the netcode and the sound come from that first game; the screenshots below are from it.
16
16
 
17
- ![A dark corridor in the flashlight's beam, a walker at the far end](https://raw.githubusercontent.com/korial29/tiny-fps/master/docs/screenshot-corridor.jpg)
17
+ ![Sector rooms in the flashlight's beam](https://raw.githubusercontent.com/korial29/tiny-fps/master/docs/screenshot-corridor.jpg)
18
18
 
19
- ![The stairs down to the goal room, lit cyan by the goal, with gibs on the floor](https://raw.githubusercontent.com/korial29/tiny-fps/master/docs/screenshot-goal.jpg)
19
+ ![A stair down to a lit room](https://raw.githubusercontent.com/korial29/tiny-fps/master/docs/screenshot-goal.jpg)
20
20
 
21
- ![Back to the start: the open exit glows green at the end of the corridor](https://raw.githubusercontent.com/korial29/tiny-fps/master/docs/screenshot-exit.jpg)
21
+ ![An open doorway glowing green at the end of a corridor](https://raw.githubusercontent.com/korial29/tiny-fps/master/docs/screenshot-exit.jpg)
22
22
 
23
23
  ## Framework-agnostic, light to add
24
24
 
@@ -26,18 +26,18 @@ It is inspired by carlini's [Yet Another Doom Clone](https://github.com/carlini/
26
26
 
27
27
  | Entry | What it is | Size (gzip) |
28
28
  | --------------------------- | ---------------------------------------------------------------------- | ----------- |
29
- | `@korial29/tiny-fps` | The game client: rendering, lights and shadows, input, prediction, HUD | ~18 KB |
30
- | `@korial29/tiny-fps/local` | Same-browser multiplayer, no server: the host runs in a tab | ~9.5 KB |
29
+ | `@korial29/tiny-fps` | The game client: rendering, lights and shadows, input, prediction, HUD | ~15 KB |
30
+ | `@korial29/tiny-fps/local` | Same-browser multiplayer, no server: the host runs in a tab | ~4.3 KB |
31
31
  | `@korial29/tiny-fps/server` | Node WebSocket server (needs `ws`) | Node only |
32
32
 
33
- CI checks the budgets (30 KB and 12 KB) on every pull request.
33
+ CI checks the budgets (40 KB and 16 KB) on every pull request.
34
34
 
35
35
  ## Live demo
36
36
 
37
37
  https://korial29.github.io/tiny-fps/
38
38
 
39
- 1. Open the page, pick a name and play: you are alone against the monsters.
40
- 2. For co-op on one machine, open it in a second tab of the same browser and join with another name: the tabs play together, with no server.
39
+ 1. Open the page, pick a name and play: you have the rooftop to yourself.
40
+ 2. To play with someone on one machine, open it in a second tab of the same browser and join with another name: the tabs play together, with no server.
41
41
  3. To play across devices, pick the server mode and give it the URL of a running `tiny-fps-server`.
42
42
 
43
43
  ---
@@ -171,7 +171,6 @@ The subset of `WebSocket` the client uses: `binaryType`, `onopen`, `onclose`, `o
171
171
  | Look | Mouse (click the game to lock the pointer, Esc to release it) |
172
172
  | Move | WASD, or the arrow keys |
173
173
  | Jump | Space |
174
- | Fire | Left mouse button, held |
175
174
  | Mute | M (remembered) |
176
175
 
177
176
  Keys are read by their position (`KeyboardEvent.code`), so on an AZERTY keyboard WASD is ZQSD with nothing to set.
@@ -180,46 +179,37 @@ Keys are read by their position (`KeyboardEvent.code`), so on an AZERTY keyboard
180
179
 
181
180
  ## How a game plays
182
181
 
183
- - **Co-op**: everyone fights the monsters together; there is no friendly fire. Up to 16 players.
184
- - **Chaingun**: 12 shots a second, at half speed while you fire. The host decides every hit, and moves the targets back to where you saw them (lag compensation).
185
- - **Monsters**:
186
- - Walkers patrol the floors, fire bullets and strike up close.
187
- - Flyers float over steps and pits.
188
- - They spot you within 60° of where they face and never through a wall, then alert their neighbours. One shot kills.
189
- - **Health**: 9 points. A hit takes one, then you can't be hurt for a second. A dead player comes back at the start 3 s later. Every 4th kill leaves a health pack.
190
- - **Keys and gates**: red, blue and yellow keys open the barred gates of their colour, for the whole team.
191
- - **The way out**: the start room locks behind you. Touch the goal to open it, then the level is won once every living player is back inside.
192
- - **Five levels**: Warm-up, Foundry, Cistern, Loop and Citadel. Then the run starts over in hard mode, with faster monsters that strike and fire more often. The end screen shows the time and each player's kills and deaths.
193
- - **Sound**: every sound is synthesised in code and placed left or right by where it comes from; a dark music loops under it. The sound starts with the click that locks the pointer.
194
- - **Dark levels**: your flashlight casts shadows, and so do muzzle flashes. Explosions, hits, bullets, the goal and the open exit light up their surroundings.
182
+ For now the game is the movement and the room; the rules come with the next steps of [`docs/PLAN.md`](docs/PLAN.md).
183
+
184
+ - **The rooftop**: one 40 × 40 m deck under an open sky, with a parapet round the edge, a crate you can jump onto, a block too tall to climb, and a platform with four steps up to it. Up to 16 players share it, each with a name tag and a colour of their own.
185
+ - **Moving**: run, strafe and jump. The host decides where everyone is. Your own moves show at once (the client predicts them) and are corrected to the host's state, to the bit.
186
+ - **The others**: drawn 100 ms in the past, interpolated between snapshots, as soldiers with swinging arms and legs. Each carries a flashlight that casts shadows.
187
+ - **Sound**: a synthesiser and a mixer that places sounds left or right by where they come from, and a dark music loop. The sound starts with the click that locks the pointer. There are no sound effects yet.
188
+ - **Coming**: parkour moves (sprint, double jump, wall-run, ledge grab, slide), a Mirror's Edge look, two teams, flags, a score, and a tackle that makes a carrier drop the flag.
195
189
 
196
190
  ---
197
191
 
198
192
  ## Features
199
193
 
200
- Parity with the js13k game is tracked in [`docs/PARITY.md`](docs/PARITY.md).
201
-
202
194
  - [x] Multiplayer over WebSocket, or between tabs of one browser with no server
203
- - [x] Doom-style sector maps: steps, pits, low ceilings, balconies, eight procedural materials (brick, tile, lava, stone, metal, wood, moss, grating) with bump mapping and per-material highlights, each level themed
195
+ - [x] Doom-style sector maps: steps, pits, low ceilings, balconies, eight procedural materials (brick, tile, lava, stone, metal, wood, moss, grating) with bump mapping and per-material highlights
196
+ - [x] The rooftop map: a deck, a parapet, a crate, a block and a platform with steps
204
197
  - [x] Client-side prediction, exact to the bit, and the other players interpolated
205
- - [x] Chaingun with lag-compensated hitscan, spinning barrels, recoil, muzzle flash, head bob, sparks
206
- - [x] Walkers and flyers: patrol, sight cone, alert, chase, bullets, melee, gibs and explosions
207
- - [x] Health, hit cooldown, death and respawn, health drops, team keys and barred gates
208
- - [x] Five levels, the goal and the way back, hard mode on the next run, end screen with the time
209
- - [x] Flashlights with shadow maps, lit muzzle flashes, explosion, hit, bullet, goal and exit lights
210
- - [x] Atmosphere: a light colour per room, a fog colour per level, flickering lava light, dust in the flashlight beam, soft smoke after explosions
211
- - [x] Post-processing: bloom on flashes, lava and glows, tone mapping, vignette, film grain, 4x antialiasing
212
- - [x] Sound: a jsfxr-style synthesiser (shot, boom, hit, collect, clock, burst), stereo by position, a looped music; M mutes
213
- - [x] HUD and screens: health bar, damage vignette and pickup fades, low-health pulse and heartbeat, title and pause screen, death countdown, end screen with each player's kills and deaths
198
+ - [x] A per-tick history of the players on the host, for lag compensation
199
+ - [x] Flashlights with shadow maps, a light colour per room, a fog colour per map, flickering lava light, dust in the flashlight beam
200
+ - [x] Post-processing: bloom, tone mapping, vignette, film grain, 4x antialiasing
201
+ - [x] A model for the other players: jointed legs and arms that follow their stride
202
+ - [x] Sound: a jsfxr-style synthesiser and a looped music; M mutes
203
+ - [x] A title screen with the controls, a muted mark, a player count and name tags
214
204
  - [x] Shadow DOM, zero runtime dependencies, size-gated in CI
215
205
 
216
206
  ---
217
207
 
218
208
  ## How it works
219
209
 
220
- - **The host is authoritative**: the Node server, or the host tab in local mode. It runs the players, the monsters, the bullets, the pickups and the levels.
210
+ - **The host is authoritative**: the Node server, or the host tab in local mode. It runs the players on the map.
221
211
  - **Inputs, not positions**: each client sends one 11-byte input per step at 60 Hz, holding its keys, view angles and the moment it sees the others at. It predicts its own player at once and replays what the host has not acknowledged yet.
222
- - **Snapshots** go out at 30 Hz: players, shots, monsters, bullets, events and pickups, in a compact binary format. The other players and the monsters are drawn 100 ms in the past, interpolated between snapshots.
212
+ - **Snapshots** go out at 30 Hz: a 4-byte head and 24 bytes per player, in a compact binary format. The other players are drawn 100 ms in the past, interpolated between snapshots.
223
213
  - **Rendering**: one WebGL2 shader program and one vertex buffer, up to 16 lights, with up to 4 shadow maps drawn by the same program.
224
214
 
225
215
  ---
package/dist/index.js CHANGED
@@ -1,9 +1,8 @@
1
- var e=.4,t=1.8,n=1.6,r=1.55,i=.5,a=.02,o=1.8,s=.45,c=.9,l=.15,u={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,FIRE:32},d={WALKER:0,FLYER:1},f={DIE:0,HURT:1,BOOM:2,SWING:3},p={HEALTH:0,KEY_RED:1,KEY_BLUE:2,KEY_YELLOW:3},m={HUNT:0,RETURN:1},h={BRICK:0,TILE:1,LAVA:2,STONE:3,METAL:4,WOOD:5,MOSS:6,GRATE:7},g=e=>{let t=(e,t,n,r)=>`${e},${t},${n},${r}`,n=/* @__PURE__ */ new Map;e.sectors.forEach(({pts:e},r)=>e.forEach(([i,a],o)=>n.set(t(i,a,...e[(o+1)%e.length]),r)));let r={map:e,edges:e.sectors.flatMap(({pts:e},r)=>e.map(([i,a],o)=>{let[s,c]=e[(o+1)%e.length];return{ax:i,az:a,bx:s,bz:c,front:r,back:n.get(t(s,c,i,a))??-1}})),barred:/* @__PURE__ */ new Set};return _(r,0,m.HUNT),r},_=({map:e,barred:t},n,r)=>{t.clear(),e.gates?.forEach(e=>n&1<<e.key||t.add(e.sector)),e.exit!==void 0&&r===m.HUNT&&t.add(e.exit)},v=({pts:e},t,n)=>e.every(([r,i],a)=>{let[o,s]=e[(a+1)%e.length];return(o-r)*(n-i)-(s-i)*(t-r)>=0}),y=({map:e},t,n)=>e.sectors.findIndex(e=>v(e,t,n)),b=({map:e,edges:t},[n,r,i],[a,o,s])=>{let[c,l]=[a-n,s-i];return t.some(t=>{let[a,s]=[t.bx-t.ax,t.bz-t.az],u=c*s-l*a;if(!u)return!1;let d=((t.ax-n)*s-(t.az-i)*a)/u,f=((t.ax-n)*l-(t.az-i)*c)/u;if(d<=0||d>=1||f<0||f>1)return!1;if(t.back<0)return!0;let[p,m]=[e.sectors[t.front],e.sectors[t.back]],h=r+d*(o-r);return h<Math.max(p.floor,m.floor)||h>Math.min(p.ceil,m.ceil)})},x=(e,...t)=>t.map(([t,n,r,i,a,o,s,c,l])=>[t,n,r,i,a,o,s,c,l,e]),S=(e,[t,n,r,i],a,o,s,c,l,u)=>Array.from({length:s},(d,f)=>{let[p,m]=e?[n,i]:[t,r],[h,g,_]=[p+f*(m-p)/s,p+(f+1)*(m-p)/s,+(a+f*o).toFixed(1)];return e?[t,h,r,g,_,c,l,u]:[h,n,g,i,_,c,l,u]}),[C,w,T,E]=[p.HEALTH,p.KEY_RED,p.KEY_BLUE,p.KEY_YELLOW],D=Math.PI/4,O=[1,.82,.6],k=[.6,.75,1],A=(e,t,[n,r,i],a,o,s,c,l)=>{let u=t.map(([e,t,n,r])=>[[e,t],[n,t],[n,r],[e,r]]),f=[...new Map(u.flat().map(e=>[`${e}`,e])).values()];return{name:e,sectors:t.map(([,,,,e,t,n=`103`,r,,i],a)=>({pts:u[a].flatMap((e,t,n)=>{let r=n[(t+1)%4],i=t=>(t[0]-e[0])*(r[0]-e[0])+(t[1]-e[1])*(r[1]-e[1]);return[e,...f.filter(t=>(r[0]-e[0])*(t[1]-e[1])===(r[1]-e[1])*(t[0]-e[0])&&i(t)>0&&i(t)<(r[0]-e[0])**2+(r[1]-e[1])**2).sort((e,t)=>i(e)-i(t))]}),floor:e,ceil:t,ft:+n[0],wt:+n[1],ct:+n[2],light:r,tint:i})),spawns:Array.from({length:16},(e,t)=>[n+t%4*2,r+(t>>2)*2,i*D]),monsters:[...a.map(([e,t,n])=>[e,t,n*D,d.WALKER]),...o.map(([e,t,n])=>[e,t,n*D,d.FLYER])],items:s,gates:t.flatMap(([,,,,,,,,e],t)=>e?[{sector:t,key:e}]:[]),goal:c,exit:0,fog:l}},j=[A(`Warm-up`,[[0,0,10,10,0,4,`103`],[10,4,22,6,0,2.8,`333`,.6],...x([1,.85,.65],[22,0,38,14,0,6,`553`],...S(0,[38,4,42,10],.4,.4,4,6,`553`)),[42,2,52,12,2,6,`103`,.9],...S(1,[46,12,48,22],1.6,-.4,4,4.8,`744`,.7),[38,22,56,36,0,6,`113`]],[2,2,6],[[28,4,3],[34,10,4],[48,6,4],[44,30,0]],[[30,8,0],[52,28,2]],[[26,12,C],[50,10,C],[40,34,C]],[54,34]),A(`Foundry`,[...x([1,.9,.8],[0,14,10,26,0,4,`443`],[10,22,20,24,0,2.8,`744`,.6]),...x([1,.5,.25],[24,8,28,16,0,9,`744`],[20,16,28,30,0,9,`443`],...S(1,[20,8,24,16],2,-.4,5,9,`744`),[28,8,42,18,-1.6,9,`233`,.9],...S(1,[28,18,42,21],-1.2,.4,3,9,`333`),[28,21,50,30,0,9,`744`],[42,8,50,21,0,9,`744`],[20,0,50,8,2.4,9,`744`,.8]),[50,14,51,17,0,3.5,`444`,1,w],...x([.85,.65,.5],[51,8,59,26,0,7,`443`,.6],[59,8,67,26,.4,7,`143`,.8],[57,26,59,36,0,4.8,`744`,.7]),...x([1,.6,.45],[50,36,68,50,0,7,`443`])],[2,16,6],[[46,14,2],[36,26,0],[38,4,2],[56,12,4],[62,20,2],[60,44,0]],[[35,13,0],[60,14,4],[58,42,6]],[[24,26,C],[24,4,C],[64,10,C],[52,46,C],[46,4,w]],[66,48],[.07,.05,.04,.026]),A(`Cistern`,[...x([.45,.9,1],[0,20,10,32,0,4,`363`],[10,26,20,28,0,2.8,`363`,.6],[20,14,56,26,0,11,`363`,.9],[20,26,34,32,0,11,`363`,.9]),...x([.9,.6,.45],[34,26,42,32,-.4,11,`263`]),...x([.45,.9,1],[42,26,56,32,0,11,`363`,.9],[20,32,56,44,0,11,`363`,.9],[36,44,38,54,0,1.9,`000`,.35],[30,54,46,68,0,5,`003`,.7]),[56,28,57,31,0,4,`444`,1,w],...x([.55,.85,1],...S(0,[57,26,65,32],.4,.4,8,10,`333`,.8)),...x([.7,1,.85],[65,22,81,36,3.6,11,`563`]),[71,36,74,37,3.6,7,`444`,1,T],...x([.45,.9,1],[71,37,74,48,3.6,6.4,`363`,.6]),...x([.9,.6,.45],[62,48,82,64,3.6,10,`263`])],[2,22,6],[[30,18,4],[50,20,4],[30,40,0],[50,40,0],[36,60,2],[42,64,0],[76,28,2],[70,58,0]],[[26,24,0],[48,22,0],[36,40,2],[72,56,4]],[[24,40,C],[52,42,C],[44,57,C],[68,34,C],[64,62,C],[38,66,w],[79,24,T]],[80,62],[.04,.11,.1,.034]),A(`Loop`,[...x(O,[0,44,10,56,0,4,`153`],[10,49,20,51,0,2.8,`553`,.6]),[20,30,52,40,0,9,`113`],[20,48,52,58,0,9,`113`,.9],[20,40,32,48,0,9,`113`],[40,40,52,48,0,9,`113`],[20,22,49,30,3.2,9,`743`,.8],...x(O,[34,58,36,66,0,2.8,`553`,.4],[26,66,46,84,0,5,`353`,.5]),[52,42,53,45,0,4,`444`,1,w],...x(O,[53,36,64,54,0,6,`153`,.8],[64,36,70,54,.4,6,`253`,.8]),[60,35,63,36,0,4,`444`,1,T],...x(O,[57,12,77,35,0,8,`053`,.9]),[56,24,57,27,0,4,`444`,1,E],...S(0,[49,22,56,30],2.8,-.4,7,9,`744`,.8),...x(O,[12,24,20,28,3.2,6,`744`,.6],[0,10,12,34,3.2,9,`553`])],[2,46,6],[[30,36,4],[44,36,2],[40,52,0],[40,26,4],[30,74,6],[42,78,2],[56,40,6],[64,50,2],[62,18,4],[72,28,2],[6,22,0]],[[28,48,0],[46,44,4],[36,72,0],[60,45,6],[68,22,4]],[[24,54,C],[24,26,C],[44,80,C],[68,38,C],[74,14,C],[36,82,w],[68,52,T],[74,32,E]],[6,13],[.06,.045,.04,.02]),A(`Citadel`,[...x(k,[0,60,10,72,0,4,`303`],[10,65,24,67,0,2.8,`363`,.6],[24,48,56,84,0,12,`363`],[27,40,31,48,0,3.4,`363`,.4]),...x([.85,.7,.65],[24,16,34,40,0,12,`443`,.9],...S(0,[34,16,40,26],-.4,-.4,3,12,`243`),[34,26,40,30,0,12,`744`],...S(0,[34,30,40,40],-.4,-.4,3,12,`243`),[40,16,60,40,0,12,`443`,.9]),[60,27,61,30,0,4,`444`,1,E],...x([.55,.3,1],[61,10,101,16,0,14,`443`,1],[61,40,101,46,0,14,`443`,1],[61,16,69,40,0,14,`443`,1],[93,16,101,40,0,14,`443`,1],[69,16,93,20,.4,14,`243`,1],[69,36,93,40,.4,14,`243`,1],[69,20,73,36,.4,14,`243`,1],[89,20,93,36,.4,14,`243`,1],[73,20,89,36,.8,14,`744`,1]),[101,26,111,28,0,3.2,`744`,.6],[111,16,131,40,0,8,`163`],[56,66,57,69,0,4,`444`,1,w],...x([1,.5,.45],[57,56,75,80,0,12,`443`,.7],...S(0,[75,60,85,72],.4,.4,5,12,`744`,.8),[85,52,101,80,2.4,12,`543`]),[38,84,42,85,0,4,`444`,1,T],...x([.6,.85,.85],[38,85,42,95,0,1.9,`363`,.35],[28,95,56,115,0,6,`663`,.6])],[2,62,6],[[34,56,4],[50,56,2],[36,76,0],[46,20,4],[54,34,2],[66,60,2],[66,76,0],[92,60,2],[34,100,4],[50,108,2],[70,13,4],[92,13,2],[70,43,0],[92,43,6]],[[30,70,0],[46,68,0],[50,28,0],[76,26,0],[86,30,0],[81,22,0]],[[30,80,C],[56,36,C],[60,78,C],[50,112,C],[64,13,C],[98,43,C],[114,38,C],[52,22,w],[95,66,T],[42,110,E]],[127,36],[.045,.05,.075,.02])],M=65536/(2*Math.PI),N=e=>Math.round(e*M)&65535,P=e=>Math.max(-32768,Math.min(32767,Math.round(e))),F=e=>P(e*1e4),ee=e=>e/1e4,I=e=>e/M,L=(e=0)=>Math.round(e*256)&16777215,R=e=>({...e,yaw:I(N(e.yaw)),pitch:ee(F(e.pitch)),...e.view!==void 0&&{view:L(e.view)/256}}),z=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,N(e.yaw)),t.setInt16(6,F(e.pitch));let n=L(e.view);return t.setUint16(8,n>>8),t.setUint8(10,n&255),t.buffer},B=e=>{if(e.byteLength<7)return null;let t=new DataView(e),n=t.getUint8(3);if(t.getUint8(0)!==2)return null;let r=7+25*n,[i,a,o,s,c]=[14,16,13,14,14].map(n=>{if(e.byteLength<=r)return null;let i=t.getUint8(r),a=r+1;return r=a+n*i,[a,i]});if(!i||!a||!o||!s||!c||e.byteLength!==r)return null;let l=([e,t],n,r)=>Array.from({length:t},(t,i)=>r(e+i*n)),u=[];for(let e=0;e<n;e++){let n=7+e*25;u.push({id:t.getUint8(n),x:t.getFloat32(n+1),y:t.getFloat32(n+5),z:t.getFloat32(n+9),vy:t.getFloat32(n+13),yaw:I(t.getUint16(n+17)),pitch:ee(t.getInt16(n+19)),ack:t.getUint16(n+21),cool:t.getUint8(n+23)>>1,ground:(t.getUint8(n+23)&1)==1,hp:t.getUint8(n+24)})}return{tick:t.getUint16(1),players:u,shots:l(i,14,e=>({id:t.getUint8(e),x:t.getFloat32(e+1),y:t.getFloat32(e+5),z:t.getFloat32(e+9),hit:t.getUint8(e+13)===255?-1:t.getUint8(e+13)})),monsters:l(a,16,e=>({id:t.getUint8(e),kind:t.getUint8(e+1)&1,chase:!!(t.getUint8(e+1)&2),x:t.getFloat32(e+2),y:t.getFloat32(e+6),z:t.getFloat32(e+10),yaw:I(t.getUint16(e+14))})),bullets:l(o,13,e=>({id:t.getUint8(e),x:t.getFloat32(e+1),y:t.getFloat32(e+5),z:t.getFloat32(e+9)})),events:l(s,14,e=>({type:t.getUint8(e),id:t.getUint8(e+1),x:t.getFloat32(e+2),y:t.getFloat32(e+6),z:t.getFloat32(e+10)})),level:t.getUint8(4),hard:(t.getUint8(5)&1)==1,phase:t.getUint8(5)>>1&1,keys:t.getUint8(6),items:l(c,14,e=>({id:t.getUint8(e),kind:t.getUint8(e+1),x:t.getFloat32(e+2),y:t.getFloat32(e+6),z:t.getFloat32(e+10)}))}},te=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},V=44100,H={SHOT:0,BOOM:1,HIT:2,COLLECT:3,CLOCK:4,BURST:5,HEART:6},U=([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},ne=[[[3,7e3,-.5,.002,0,.06,0,.6,0,1,.8],[0,220,-5,.002,0,.075,0,.3,0,1,.5]],[[3,500,-1.5,.004,.05,.8,0,.1,0,1,2.2],[2,110,-1.5,.004,.05,.6,0,1,0,1,.8]],[[1,160,-1.5,.003,.04,.22,.2,.5,0,1,.6],[0,83,-1,.003,.04,.22,0,.3,0,1,.4],[3,3e3,0,.002,0,.12,0,.4,0,1,.5]],[[2,880,.3,.005,.06,.4,0,1,.09,1.5,.8],[2,1760,.3,.005,.06,.35,0,1,.09,1.5,.3]],[[3,4e3,0,.001,0,.025,0,.5,0,1,.7],[2,1300,-1,.001,0,.04,0,1,0,1,.5]],[[3,1200,-1,.002,0,.14,0,.45,0,1,.7],[0,3200,-1,.002,0,.05,0,1,.025,.7,.2]],[[2,55,-1,.01,.01,.12,0,1,0,1,.9],[2,110,-1,.01,0,.08,0,1,0,1,.3],[2,48,-1,.01,.01,.14,0,1,0,1,.6,.22],[2,96,-1,.01,0,.09,0,1,0,1,.2,.22]]],re=e=>{let t=ne[e].map((t,n)=>[U(t,e*9+n),Math.round((t[11]??0)*V)]);return Float32Array.from({length:Math.max(...t.map(([e,t])=>t+e.length))},(e,n)=>Math.tanh(t.reduce((e,[t,r])=>e+(t[n-r]??0),0)))},ie=V*60/108,ae=ie/4,oe=4,se=[2,150,-6,.002,0,.25,0,1,0,1,1],ce=[3,9e3,0,.002,0,.15,0,.5,0,1,.5],W=[3,3e4,0,.001,0,.04,0,.7,0,1,.15],le=()=>{let e=new Float32Array(ie*4*oe),t={},n=(n,r)=>(t[String(r)]??=U(r,1)).forEach((t,r)=>e[(n*ae+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,se),`....x.......x...`[t]==`x`&&n(e,ce),t%2==0){n(e,W);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)},ue=40,de=24,fe=.5,pe=`tiny-fps:muted`,me=()=>{let e=!1;return{unlock:()=>{},listen:()=>{},play:()=>{},mute:t=>{e=t},get muted(){return e},destroy:()=>{}}},he=()=>{let e;try{e=new AudioContext}catch{return me()}let t=(t,n=1)=>{let r=e.createGain();return r.gain.value=n,r.connect(t),r},n=t(e.destination),r=t(n,fe),i=[],a=/* @__PURE__ */ new Set,o=[0,0,0],s=0,c=!1,l=t=>{let n=e.createBuffer(1,t.length,V);return n.getChannelData(0).set(t),n},u=t=>{let n=e.createBufferSource();return n.buffer=t,n};return{unlock(){if(e.resume().catch(()=>{}),!i.length){for(let e of Object.values(H))i[e]=l(re(e));let e=u(l(le()));e.loop=!0,e.connect(r),e.start()}},listen(e,t){[o,s]=[e,t]},play(r,c,l=1){let d=0,f=l;if(c){let[e,t,n]=c.map((e,t)=>e-o[t]),r=Math.hypot(e,t,n);f=Math.max(0,1-r/ue)**2*l,d=(e*Math.cos(s)-n*Math.sin(s))/Math.max(r,1)}let p=i[r];if(!p||!f)return;if(a.size>=de){let e=[...a].reduce((e,t)=>t.vol<e.vol?t:e);if(e.vol>=f)return;e.src.stop(),a.delete(e)}let m=u(p),h=e.createStereoPanner();h.pan.value=d,m.connect(h).connect(t(n,f));let g={vol:f,src:m};a.add(g),m.onended=()=>a.delete(g),m.start()},mute(t){c=t,n.gain.setTargetAtTime(+!t,e.currentTime,.05)},get muted(){return c},destroy:()=>void e.close().catch(()=>{})}},ge=(e,{type:t,id:n,x:r,y:i,z:a},o)=>{let s=[r,i,a];t==f.DIE?e.play(H.BOOM,s):t==f.BOOM?e.play(H.BURST,s):t==f.HURT&&e.play(H.HIT,n==o?void 0:s)},_e=e=>{let t=0;return(n,r)=>{n&&r>=t&&(t=r+1e3,e.play(H.CLOCK))}},ve=e=>{let t=-1/0;return(n,r)=>{if(n<1||n>3)return t=-1/0,0;let i=n>1?800:500;return r-t>=i&&(t=r,e.play(H.HEART,void 0,n>1?.6:1)),1-(r-t)/i}},ye=()=>{try{return localStorage.getItem(pe)==`1`}catch{return!1}},be=e=>{e.mute(!e.muted);try{localStorage.setItem(pe,e.muted?`1`:`0`)}catch{}return e.muted},xe=1/60,G=Math.PI*2,Se=1e-6,Ce=.01,we=e=>(e%G+G)%G,Te=e=>[-Math.sin(e),-Math.cos(e)],Ee=Math.fround,De=(e,t,n)=>Math.min(Math.max(e,t),n),Oe=({map:e,barred:t},n,r,i,a)=>{if(n.back<0||t.has(n.back))return!0;let o=e.sectors[n.front],s=e.sectors[n.back],c=Math.min(o.ceil,s.ceil);return s.floor>r+a+Ce||c-Math.max(o.floor,s.floor)<i-Ce||c<r+i-Ce},ke=(e,t,n,r,i)=>{let a=(n-Se)**2;for(let o=0;o<4;o++){let o=0,s=0,c=0;for(let l of t.edges){let u=l.bx-l.ax,d=l.bz-l.az,f=e.x-l.ax,p=e.z-l.az;if(u*p-d*f<0)continue;let m=De((f*u+p*d)/(u*u+d*d),0,1),h=f-m*u,g=p-m*d,_=h*h+g*g;if(_>=a)continue;let v=Math.sqrt(_);if(n-v<=o||!Oe(t,l,e.y,r,i))continue;o=n-v;let y=v||Math.hypot(u,d);s=(v?h:-d)/y*o,c=(v?g:u)/y*o}if(!o)return;e.x+=s,e.z+=c}},Ae=(e,t,n,r,i,a,o)=>{let{map:s,edges:c}=e,l=Math.max(y(e,t,n),0),{floor:u,ceil:d}=s.sectors[l],f=(i-Se)**2;for(let i of c){if(i.front!==l||i.back<0)continue;let c=i.bx-i.ax,p=i.bz-i.az,m=t-i.ax,h=n-i.az,g=De((m*c+h*p)/(c*c+p*p),0,1);if((m-g*c)**2+(h-g*p)**2<f&&!Oe(e,i,r,a,o)){let e=s.sectors[i.back];u=Math.max(u,e.floor),d=Math.min(d,e.ceil)}}return[u,d]},je=(n,r,a,o,s)=>{n.x+=r,n.z+=a,ke(n,s,e,t,i);let[c,l]=Ae(s,n.x,n.z,n.y,e,t,i);n.ground&&o&&(n.vy=7);let u=n.vy-20*xe;n.y+=(n.vy+u)/2*xe,n.vy=u,n.ground=!1,n.y+1.8>l&&(n.y=l-t,n.vy=Math.min(n.vy,0)),(n.vy<=0?n.y<=c+Ce:n.y<c)&&(n.y=c,n.vy<=0&&(n.vy=0,n.ground=!0)),n.x=Ee(n.x),n.y=Ee(n.y),n.z=Ee(n.z),n.vy=Ee(n.vy)},Me=(e,t,n)=>{let i=(t.keys&u.FIRE)!==0;e.cool=Math.max(0,e.cool-1),e.yaw=we(t.yaw),e.pitch=Math.max(-1.55,Math.min(r,t.pitch));let a=(t.keys&u.FORWARD?1:0)-(t.keys&u.BACK?1:0),o=(t.keys&u.RIGHT?1:0)-(t.keys&u.LEFT?1:0),s=6*xe*(i?.5:1)/(Math.hypot(a,o)||1),[c,l]=Te(e.yaw);return je(e,(c*a-l*o)*s,(l*a+c*o)*s,(t.keys&u.JUMP)!==0,n),i&&!e.cool?(e.cool=5,!0):!1},Ne=.55,Pe=6,Fe=(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*G/t),Math.sin(e*G/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},Ie=e=>{let t=[];for(let n=0;n<Pe;n++){let r=n*G/Pe;t.push(...Fe([[0,0],[.02,0],[.02,.45],[.014,.45],[.014,.55],[0,.55]],e,[Math.cos(r)*.05,Math.sin(r)*.05,0]))}return{barrels:t,body:Fe([[0,-.3],[.08,-.3],[.09,-.26],[.09,0],[.075,0],[.075,.1],[.03,.1],[.03,.4],[0,.4]],e)}},Le=(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]]},K=(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[[-1,-1],[1,-1],[1,1],[-1,-1],[1,1],[-1,1]]){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])}}},Re=(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]}),ze=(e,t,n,[r,i,a],o,s,c=0)=>{let[l,u]=[Math.sin(c),Math.cos(c)],d=(e,t,n)=>[0,1,2].map(o=>r[o]*(e*u-t*l)+i[o]*(e*l+t*u)-a[o]*n),f=[0,1,2].map(e=>n[e]+r[e]*o[0]+i[e]*o[1]+a[e]*o[2]);for(let n=0;n<t.length;n+=10){let r=d(t[n]*s,t[n+1]*s,t[n+2]*s);e.push(f[0]+r[0],f[1]+r[1],f[2]+r[2],...d(t[n+3],t[n+4],t[n+5])),e.push(...t.slice(n+6,n+10))}},Be=.3,Ve=3.6,q={body:[.27,.22,.25],arm:[.4,.26,.22],leg:[.18,.17,.22],head:[.45,.33,.3],shell:[.36,.2,.32],fin:[.5,.25,.25],gore:[.6,.08,.07],calm:[.6,.05,.04],chase:[1,.3,.15],blob:[1,.3,.05],core:[1,.8,.4]},He=[[q.body,q.arm,q.head,q.gore,q.gore,q.chase],[q.shell,q.fin,q.shell,q.gore,q.chase]],Ue=e=>e?q.chase:q.calm,We=({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]},Ge=(e,t,n,r,i,a)=>{let o=[];K(o,[0,-i[1],0],i,0,a),ze(e,o,t,Le(n,r),[0,0,0],1)},Ke=e=>e<.25?-.8*Math.sin(e*4*Math.PI):2*Math.sin((e-.25)*Math.PI/.75),qe=(e,t,n,r)=>{let i=Math.sin(n*Ve)*.6,a=o*.44,s=o*.8,[c,l]=[-1,1].map(e=>We(t,e*.16,a,0));Ge(e,c,t.yaw,i,[.09,a/2,.09],q.leg),Ge(e,l,t.yaw,-i,[.09,a/2,.09],q.leg),Ge(e,We(t,-.35,s,0),t.yaw,-i*.8,[.07,.34,.07],q.arm),Ge(e,We(t,.35,s,0),t.yaw,i*.8+(r>0?Ke(r):0),[.07,.34,.07],q.arm),K(e,We(t,0,1.142,0),[.26,.35,.16],t.yaw,q.body),K(e,We(t,0,1.6500000000000001,0),[.15,.15,.15],t.yaw,q.head);let u=t.chase?.06:.045;for(let n of[-1,1])K(e,We(t,n*.075,1.69,.15),[u,u*.7,.02],t.yaw,Ue(t.chase),-2)},Je=Re(Fe([[0,0],[.18,.06],[s,.32],[s*.93,.5],[.22,.78],[0,c]],8),q.shell),Ye=(e,t,n)=>{let r=Math.sin(n*2+t.id)*.06,i=[t.x,t.y+r,t.z];ze(e,Je,i,Le(0,Math.PI/2),[0,0,0],1);for(let r=0;r<4;r++){let a=n*1.5+r*G/4;K(e,[t.x+Math.cos(a)*.4,i[1]+.35,t.z+Math.sin(a)*.4],[.16,.03,.04],-a,q.fin)}let a=We({...t,y:i[1]},0,c*.45,s*.9),o=t.chase?1.3:1;K(e,a,[.1*o,.07*o,.05],t.yaw,Ue(t.chase),-2)},Xe=(e,t,n)=>{let r=[t.x,t.y,t.z];if(K(e,r,[l*.8,l*.8,l*.8],0,q.blob,-2),K(e,r,[l*.5,l*.5,l*.5],Math.PI/4,q.core,-2),n)for(let t of[1,2]){let i=l*(1-t*.3);K(e,r.map((e,r)=>e-n[r]*t*.2),[i,i,i],0,q.blob,-2)}},Ze=.05,Qe=.3,$e=96,et=64,tt=12,nt=40,rt=[5,1.6,5],it=Math.cos(.436),at=6,ot=.3,st=.45,ct=.4,lt=.5,ut=.9,dt=.3,ft=14,pt=4.4,mt=.035,ht=.03,gt=30,_t=({r:e,t})=>{let n=t/ot;return n<1?e*Math.sqrt(n)*(1-n*n*n):0},vt=({r:e,t,life:n})=>{let r=t/n;return e*(.3+.7*Math.min(1,r*2))*Math.min(1,(1-r)/.3)},yt=({t:e,life:t})=>{let n=e/t;return .85*Math.min(1,n*10)*(1-n)},bt=(e,t,n)=>{let r=[];for(let i=0;i<e.motes.length&&!e.dead;i+=3){let a=[0,1,2].map(n=>e.motes[i+n]-t[n]),o=Math.hypot(...a),s=(a[0]*n[0]+a[1]*n[1]+a[2]*n[2])/o;o<at&&s>it&&r.push(...a.map((e,n)=>t[n]+e),(s-it)/(1-it)*(1-o/at))}return r},xt=(e=64)=>{let t=[];return{clear(){t=[]},push(n,r){t.push(...n.map(e=>({t:r,v:e}))),t.splice(0,t.length-e)},due(e){let n=t.findIndex(({t})=>t+100>e);return t.splice(0,n<0?t.length:n).map(({v:e})=>e)}}},St=(e=Math.random,t)=>{let r=t,i=0,a=0,o=0,s=0,c=0,l=0,d=!0,p=/* @__PURE__ */ new Float32Array(384),m,h=()=>e()*2-1,g=/* @__PURE__ */ new Map,_=(e,t,n,r)=>{C.sparks.length<$e&&C.sparks.push({p:e,v:t,life:n,c:r})},v=(t,n,r,i)=>{for(let a=0;a<n;a++){let[n,a]=[e()*G,h()],o=Math.sqrt(1-a*a)*r*(.5+e()*.5);_(t,[Math.cos(n)*o,a*r,Math.sin(n)*o],Qe*(.6+e()*.4),i)}},x=(t,n,r)=>{for(let i=0;i<n;i++)C.smoke.push({p:t.map(e=>e+h()*.3),v:[h()*.5,.5+e()*.7,h()*.5],r:r*(.7+e()*.6),yaw:e()*G,t:0,life:1.5+e()});C.smoke.splice(0,C.smoke.length-nt)},S=(e,t)=>{C.blasts.push({p:e,r:t,t:0}),C.blasts.splice(0,C.blasts.length-tt)},C={bob:0,roll:0,shakeYaw:0,shakePitch:0,kick:0,spin:0,flash:0,flashes:/* @__PURE__ */ new Map,sparks:[],gibs:[],blasts:[],smoke:[],motes:/* @__PURE__ */ new Float32Array(384),hurt:0,gain:0,gainC:[1,1,1],dead:0,swings:/* @__PURE__ */ new Map,herd:/* @__PURE__ */ new Map,aim:/* @__PURE__ */ new Map,update(e,t,f,g=!1){let _=Math.min(1,f*10),v=e&&m?.ground&&e.ground?Math.hypot(e.x-m.x,e.z-m.z):0;v<1&&(i+=v*pt),a+=(+(v>.5*f&&v<1)-a)*_,m=e,C.dead=Math.max(0,Math.min(1,C.dead+(g?f:-f)/lt));let b=C.dead*C.dead*(3-2*C.dead);C.bob=Math.sin(i)*mt*a-b*(n-dt);let x=+!!(t&u.RIGHT)-!!(t&u.LEFT);s+=(x*ht-s)*Math.min(1,f*8),C.roll=s+b*ut,o*=Math.exp(-f*12),C.shakeYaw=h()*o,C.shakePitch=h()*o,C.kick*=Math.exp(-f*18),C.flash=Math.max(0,C.flash-f);for(let[e,t]of C.flashes)t>f?C.flashes.set(e,t-f):C.flashes.delete(e);c=Math.max(0,Math.min(gt,c+(t&u.FIRE?60:-25)*f)),C.spin=(C.spin+c*f)%G;for(let e of C.sparks)e.v[1]-=9.8*f,e.p=e.p.map((t,n)=>t+e.v[n]*f),e.life-=f;C.sparks=C.sparks.filter(e=>e.life>0),C.hurt=Math.max(0,C.hurt-f),C.gain=Math.max(0,C.gain-f);for(let[e,t]of C.swings)t>f?C.swings.set(e,t-f):C.swings.delete(e);for(let e of C.blasts)e.t+=f;C.blasts=C.blasts.filter(e=>e.t<ot);for(let e of C.gibs)e.life-=f,e.rest||w(e,f);C.gibs=C.gibs.filter(e=>e.life>0);for(let{p:e,v:t}of C.smoke)e.forEach((n,r)=>e[r]=n+t[r]*f),e[1]=Math.min(e[1],r?.map.sectors[y(r,e[0],e[2])]?.ceil??1/0);for(let e of C.smoke)e.t+=f;C.smoke=C.smoke.filter(e=>e.t<e.life),e&&(l+=f,C.motes.forEach((t,r)=>{let[i,a]=[r%3,rt[r%3]],o=i==1?e.y+n:i?e.z:e.x;p[r]=d?h()*.1:p[r];let s=d?o+h()*a:t+(p[r]+Math.sin(l*.8+r)*.05)*f;C.motes[r]=o+((s-o+a)%(2*a)+2*a)%(2*a)-a}),d=!1)},hit(){C.hurt=st},pickup(e){[C.gain,C.gainC]=[ct,e]},reset(e){r=e,C.sparks=[],C.gibs=[],C.blasts=[],C.smoke=[],d=!0,C.flashes.clear(),C.swings.clear(),C.herd.clear(),C.aim.clear(),g.clear(),C.hurt=C.gain=C.flash=0},shot(t,n,r,i=!0){r?(C.kick=1,C.flash=Ze,o=.012):C.flashes.set(t.id,Ze);let a=[t.x,t.y,t.z],s=n.map((e,t)=>e-a[t]),c=Math.hypot(...s);if(i&&c>0&&c<99.99)for(let t=0;t<4;t++){let t=s.map(t=>t/c*(2+e()*2)+h());t[1]+=1,_(a,t,Qe*(.6+e()*.4))}},track(e,t){for(let{id:t,kind:n,x:r,z:i}of e){let e=C.herd.get(t),a=e?Math.hypot(r-e.x,i-e.z):0;C.herd.set(t,{x:r,z:i,kind:n,walked:(e?.walked??0)+(a<1?a:0)})}let n=/* @__PURE__ */ new Map;for(let{id:e,x:r,y:i,z:a}of t){let[t,o]=[g.get(e),[r,i,a]],s=t?Math.hypot(o[0]-t[0],o[1]-t[1],o[2]-t[2]):0;t&&s>1e-4&&C.aim.set(e,o.map((e,n)=>(e-t[n])/s)),n.set(e,o)}g=n;for(let e of C.aim.keys())n.has(e)||C.aim.delete(e)},event({type:t,id:n,x:i,y:a,z:o},s){let c=[i,a,o];if(t==f.DIE){let t=He[C.herd.get(n)?.kind??0]??He[0],s=10+Math.floor(e()*7);for(let n=0;n<s;n++){let n=e()*G,s=1.5+e()*3.5;C.gibs.push({p:[i,a+h()*.3,o],v:[Math.cos(n)*s,2+e()*4,Math.sin(n)*s],yaw:e()*G,size:.05+e()*.08,c:t[Math.floor(e()*t.length)],life:2+e(),floor:r?.map.sectors[y(r,i,o)]?.floor??a,rest:!1})}C.gibs.splice(0,C.gibs.length-et),S(c,.6),v(c,14,5),x(c,6+Math.floor(e()*3),.3)}else t==f.BOOM?(S(c,.25),v(c,8,3),x(c,3,.15)):t==f.HURT?n!=s&&v(c,8,3,[1,.12,.08]):t==f.SWING&&C.swings.set(n,Be)}},w=(e,t)=>{e.v[1]-=ft*t;let n=e.p.map((n,r)=>n+e.v[r]*t);r&&b(r,e.p,n)&&(e.v[0]*=-.3,e.v[2]*=-.3,[n[0],n[2]]=[e.p[0],e.p[2]]);let i=r?.map.sectors[y(r,n[0],n[2])];e.floor=i?.floor??e.floor,i&&n[1]>i.ceil-e.size&&(n[1]=i.ceil-e.size,e.v[1]=Math.min(e.v[1],0)*.3),n[1]<=e.floor+e.size&&(n[1]=e.floor+e.size,e.v[1]<-3?e.v=[e.v[0]*.5,-e.v[1]*.3,e.v[2]*.5]:(e.v=[0,0,0],e.rest=!0)),e.p=n};return C},Ct=[[1,1,1],[.95,.15,.1],[.2,.4,1],[1,.85,.15]],wt=(e,t=1)=>`rgba(${e.map(e=>Math.round(e*255))},${t})`,Tt=.3,Et=[.25,1,.45],Dt=[.85,.1,.1],Ot=[.05,.05,.06],kt=(e,[t,n,r],[i,a,o],s,c,l,u=-1)=>{let[d,f]=[Math.sin(c),Math.cos(c)];K(e,[t+i*f+o*d,n+a,r-i*d+o*f],s,c,l,u)},At=(e,{id:t,kind:n,x:r,y:i,z:a},o)=>{let s=o*2+t,c=[r,i+(n?.55:.4)+Math.sin(o*2.5+t)*.07,a],l=Ct[n];if(n==p.HEALTH){K(e,c,[.2,.2,.2],s,l);for(let t of[[.21,.06,.21],[.06,.21,.21],[.21,.21,.06]])K(e,c,t,s,Dt)}else kt(e,c,[0,.17,0],[.1,.1,.025],s,l,-2),kt(e,c,[0,.17,0],[.04,.04,.035],s,Ot),kt(e,c,[0,-.1,0],[.025,.17,.025],s,l),kt(e,c,[.06,-.24,0],[.05,.03,.025],s,l),kt(e,c,[.045,-.15,0],[.035,.025,.025],s,l)},jt=({map:e},{front:t,back:n})=>{let[r,i]=[e.sectors[t],e.sectors[n]];return[Math.max(r.floor,i.floor),Math.min(r.ceil,i.ceil)]},Mt=(e,t,n,r,i,a,o=-1)=>{let[s,c]=[t.bx-t.ax,t.bz-t.az];K(e,[(t.ax+t.bx)/2,n,(t.az+t.bz)/2],[Math.hypot(s,c)/2,r,i],Math.atan2(-c,s),a,o)},Nt=(e,t,n)=>{let{gates:r=[],exit:i}=t.map;for(let{sector:n,key:i}of r){if(!t.barred.has(n))continue;let r=Ct[i];for(let i of t.edges.filter(e=>e.front==n&&e.back>=0)){let[n,a]=jt(t,i),o=Math.ceil(Math.hypot(i.bx-i.ax,i.bz-i.az)/Tt);for(let t=0;t<o;t++){let s=(t+.5)/o;K(e,[i.ax+(i.bx-i.ax)*s,(n+a)/2,i.az+(i.bz-i.az)*s],[.03,(a-n)/2,.03],0,r)}Mt(e,i,n+.1,.04,.04,r),Mt(e,i,a-.1,.04,.04,r)}}if(i!==void 0&&!t.barred.has(i)){let r=Et.map(e=>e*(.75+.25*Math.sin(n*4)));for(let n of t.edges.filter(e=>e.front==i&&e.back>=0)){let[i,a]=jt(t,n);for(let t of[i+.04,a-.04])Mt(e,n,t,.04,.04,r,-2);for(let[t,o]of[[n.ax,n.az],[n.bx,n.bz]])K(e,[t,(i+a)/2,o],[.05,(a-i)/2,.05],0,r,-2)}}},Pt=(e,t,n)=>{let r=t.map.goal,i=r&&t.map.sectors[y(t,r[0],r[1])]?.floor;if(!r||i===void 0)return;let a=Math.sin(n*4),[o,s]=[1*(.7+a*.07),[1,.85,.25].map(e=>e*(.75+a*.25))];for(let t of[0,1])K(e,[r[0],i+.03+t*.005,r[1]],[o,.03,o],n/2+t*Math.PI/4,s,-2);K(e,[r[0],i+.8+Math.sin(n*2)*.1,r[1]],[.15,.15,.15],n*2,[1,.95,.5],-2)},Ft=(e,t,n,r)=>{for(let t of n)At(e,t,r);Nt(e,t,r),Pt(e,t,r)},It={TITLE:0,NOTE:1},Lt=[2,3,8],Rt=2,zt=.35,Bt=`h1,h2,h4,h5,ul,ol,aside,section,s{position:absolute;margin:0;padding:0;pointer-events:none;user-select:none;white-space:pre-line}h1,h2,h4{left:0;right:0;text-align:center}h1{top:14%;font-size:20px;line-height:1.4}h1::first-line{font-size:44px}h2{top:32%;font-size:22px}h5{top:8px;right:12px;font-size:12px}h4{top:28%;font-size:22px;line-height:1.5;color:#fcc;text-shadow:0 2px 8px #800}h4::first-line{font-size:52px;color:#f33}s{inset:0;opacity:0}s:first-of-type{background:radial-gradient(#d000 45%,#d00 115%)}ul{--f:0;--s:0;--d:0;left:12px;bottom:12px;width:min(40vw,140px);height:22px;border-radius:4px;overflow:hidden;background:#0009;box-shadow:0 0 0 1px #0008,0 0 0 calc(var(--d)*3px) #f22;transform:translateX(calc(var(--s)*1px));filter:brightness(calc(1 + var(--f)*2))}ul li{position:absolute;top:0;bottom:0;left:0;transition:width .15s}ul li+li{right:0;width:auto;text-align:center;line-height:22px;font-size:14px}ol{left:calc(22px + min(40vw,140px));bottom:12px;display:flex;gap:4px;list-style:none}ol li{width:16px;height:22px;border-radius:3px;box-shadow:0 0 0 1px #0008}aside,section{inset:0;z-index:1;display:flex;flex-direction:column;align-items:center;gap:14px;padding:0 12px;text-align:center;background:#000b}aside{justify-content:center}section{padding-top:10%;font-size:20px}:is(aside,section):not([hidden])~:is(h1,h2){visibility:hidden}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)}section h6{font-size:20px;line-height:1.5}section h6::first-line{font-size:48px}strong{font-size:22px}small{font-size:16px;opacity:.8}table{border-collapse:collapse;font-size:16px}td,th{padding:2px 10px}th{opacity:.6}td+td,th+th{text-align:left}td+td+td,th+th+th{text-align:right}aside td:first-child{text-align:right;opacity:.7}`,Vt=e=>{e.insertAdjacentHTML(`beforeend`,`<s></s><s></s><ul><li></li><li></li></ul><ol>${`<li hidden></li>`.repeat(3)}</ol><aside hidden><h6>TINY FPS</h6><span></span><table><tr><td>Mouse<td>look<tr><td>WASD / ZQSD<td>move<tr><td>Space<td>jump<tr><td>Left click<td>fire<tr><td>M<td>mute</table><strong></strong></aside><section hidden><h6></h6><table><thead><tr><th><th>Player<th>Kills<th>Deaths</thead><tbody></tbody></table><small></small></section><h1 hidden></h1><h2 hidden></h2><h4 hidden></h4><h5 hidden>Muted (M)</h5>`);let t=t=>e.querySelector(t),[n,r]=[...e.querySelectorAll(`s`)],[i,a,o]=[t(`ul`),t(`ul li`),t(`ul li+li`)],s=[...e.querySelectorAll(`ol li`)],[c,l,u,d]=[`h4`,`h5`,`section`,`aside`].map(e=>t(e)),[f,p,m]=[`section h6`,`section tbody`,`small`].map(e=>t(e)),[h,g]=[`aside span`,`strong`].map(e=>t(e)),_=[t(`h1`),t(`h2`),u];s.forEach((e,t)=>e.style.background=wt(Ct[t+1]));let v=Lt.map(()=>0),y=0,[b,x]=[0,0],S=(e,t)=>e.textContent!=t&&(e.textContent=t);return{hp(e){y&&(b=e>y?zt:b,x=e<y?zt:x),y=e,a.style.width=`${e/9*100}%`,a.style.background=`hsl(${(Math.max(e,1)-1)/8*110},75%,42%)`,S(o,String(e))},keys:e=>s.forEach((t,n)=>t.hidden=!(e>>n+1&1)),dead(e){c.hidden=!e,e&&S(c,`You died\nRespawn in ${e}`)},fade(e,t,i,a){n.style.opacity=String(Math.max(e*.9,t&&.2+t*.4)),r.style.opacity=String(i*.32),r.style.background=wt(a)},title(e,t){d.hidden=!e,S(h,t),S(g,e)},end(e,t,n){S(f,e),S(m,n),p.replaceChildren(...t.map(([e,t,n,r])=>{let i=document.createElement(`tr`);return[`●`,e,n,r].forEach((e,n)=>{let r=i.insertCell();r.textContent=String(e),r.style.color=n?``:t}),i})),_[Rt].hidden=!1,v[Rt]=Lt[Rt]},mute:e=>l.hidden=!e,say(e,t){_[e].textContent=t,_[e].hidden=!1,v[e]=Lt[e]},update(e){v.forEach((t,n)=>{t>0&&(v[n]=t-e)<=0&&(_[n].hidden=!0)}),b=Math.max(0,b-e),x=Math.max(0,x-e);for(let[e,t]of[[`--f`,b/zt],[`--d`,x/zt],[`--s`,Math.sin(x*90)*8*x/zt]])i.style.setProperty(e,String(t))}}},Ht=.0025,Ut=Math.PI*2,Wt={KeyW:u.FORWARD,ArrowUp:u.FORWARD,KeyS:u.BACK,ArrowDown:u.BACK,KeyA:u.LEFT,ArrowLeft:u.LEFT,KeyD:u.RIGHT,ArrowRight:u.RIGHT,Space:u.JUMP},Gt=e=>Wt[e]??0,Kt=(e,t=()=>{})=>{let n=new AbortController,i=(e,t,r)=>e.addEventListener(t,r,{signal:n.signal}),a={yaw:0,pitch:0,keys:0,locked:()=>e.getRootNode().pointerLockElement==e,destroy:()=>n.abort()};i(e,`click`,()=>{Promise.resolve(e.requestPointerLock()).catch(()=>{})}),i(document,`mousemove`,e=>{a.locked()&&(a.yaw=((a.yaw-e.movementX*Ht)%Ut+Ut)%Ut,a.pitch=Math.max(-1.55,Math.min(r,a.pitch-e.movementY*Ht)))}),i(document,`keydown`,e=>{let n=Gt(e.code);e.code==`KeyM`&&!e.repeat&&a.locked()&&t(),n&&a.locked()&&(a.keys|=n,e.preventDefault())}),i(document,`keyup`,e=>{a.keys&=~Gt(e.code)}),i(document,`mousedown`,e=>{e.button==0&&a.locked()&&(a.keys|=u.FIRE)}),i(document,`mouseup`,e=>{e.button==0&&(a.keys&=~u.FIRE)});let o=()=>{a.keys=0};return i(window,`blur`,o),i(document,`pointerlockchange`,()=>a.locked()||o()),a},qt=e=>{for(let t=0;t<2;t++)e=Math.imul(e^e>>>16,73244475);return(e^e>>>16)>>>0},Jt=(e,t,n)=>{let[r,i,o,s]=[Math.sin(e),Math.cos(e),Math.sin(t),Math.cos(t)],c=qt(n+1),l=(c&65535)/65536*G,u=(c>>>16)/65535,[d,f]=[Math.cos(l)*u*a,Math.sin(l)*u*a],p=[-r*s+i*d+r*o*f,o+s*f,-i*s-r*d+i*o*f],m=Math.hypot(...p);return[p[0]/m,p[1]/m,p[2]/m]},Yt=(e,t,n,r)=>{let{map:i,edges:a}=e,o=Math.max(y(e,t[0],t[2]),0),s=0;for(let e=0;e<=i.sectors.length;e++){let{floor:e,ceil:c}=i.sectors[o],l=1/0,u;for(let e of a){if(e.front!==o)continue;let[r,i]=[e.bx-e.ax,e.bz-e.az],a=n[2]*r-n[0]*i;if(a>=0)continue;let c=Math.max(((t[2]-e.az)*r-(t[0]-e.ax)*i)/-a,s),d=((t[0]+c*n[0]-e.ax)*r+(t[2]+c*n[2]-e.az)*i)/(r*r+i*i);d>-1e-9&&d<1+1e-9&&(c<l-1e-9||c<l+1e-9&&e.back<0)&&([l,u]=[c,e])}let d=n[1]<0?(e-t[1])/n[1]:n[1]>0?(c-t[1])/n[1]:1/0;if(d<=l||!u)return Math.min(Math.max(d,s),r);if(l>=r)return r;let f=t[1]+l*n[1],p=u.back<0?void 0:i.sectors[u.back];if(!p||f<Math.max(e,p.floor)||f>Math.min(c,p.ceil))return l;[o,s]=[u.back,l]}return s},Xt=(e,t,n)=>{let[r,i]=[e[0]-n.x,e[2]-n.z],a=t[0]*t[0]+t[2]*t[2],o=r*t[0]+i*t[2],s=r*r+i*i-n.r*n.r,[c,l]=[0,1/0];if(a>1e-12){let e=o*o-a*s;if(e<0)return 1/0;[c,l]=[Math.max(0,(-o-Math.sqrt(e))/a),(-o+Math.sqrt(e))/a]}else if(s>0)return 1/0;let[u,d]=[n.y-e[1],n.y+n.h-e[1]];if(t[1]){let[e,n]=[u/t[1],d/t[1]];c=Math.max(c,Math.min(e,n)),l=Math.min(l,Math.max(e,n))}else if(u>0||d<0)return 1/0;return c<=l?c:1/0},Zt=({id:n,x:r,y:i,z:a})=>({id:n,x:r,y:i,z:a,r:e,h:t}),Qt=({id:e,kind:t,x:n,y:r,z:i})=>{let a=t===d.WALKER;return{id:e,x:n,y:r,z:i,r:a?.4:s,h:a?o:c}},$t=(e,t,r,i)=>{let a=[t.x,t.y+n,t.z],o=Jt(t.yaw,t.pitch,r),s=Yt(e,a,o,100),c=-1;for(let e of i){let n=e.id===t.id?1/0:Xt(a,o,e);n<s&&([s,c]=[n,e.id])}return{id:t.id,x:a[0]+o[0]*s,y:a[1]+o[1]*s,z:a[2]+o[2]*s,hit:c}},en=120,tn=16,nn=({id:e,x:t,y:n,z:r,vy:i,yaw:a,pitch:o,ground:s,cool:c})=>({id:e,x:t,y:n,z:r,vy:i,yaw:a,pitch:o,ground:s,cool:c}),rn=(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}),an=(e,t,n)=>we(e+(((t-e+Math.PI)%G+G)%G-Math.PI)*n),on=(e,t)=>(t-e&65535)<32768,sn=(e,t,n)=>({...t,...rn(e,t,n),yaw:an(e.yaw,t.yaw,n),pitch:e.pitch+(t.pitch-e.pitch)*n}),cn=e=>{let t=e,n,r=0,i=[],a,o,s,c=!0,l=/* @__PURE__ */ new Map,u=[],d=e=>{let t=e-100,n=0;for(;n+1<u.length&&u[n+1].t<=t;)n++;let r=u[n],i=u[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}},f=e=>{if(!u.length)return;let{a:t,b:n,u:r}=d(e);return(t.s.tick+(n.s.tick-t.s.tick&65535)*r)%65536},p=e=>{let t=u.at(-1);if(!t)return[];let{a:r,b:i,u:a}=d(e);return t.s.players.filter(e=>e.id!==n).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?sn(nn(t),nn(n),a):nn(n??t??e)})},m=(e,t,n)=>{if(!u.length)return[];let{a:r,b:i,u:a}=d(e),o=t(r.s);return t(i.s).map(e=>{let t=o.find(t=>t.id===e.id);return t?n(t,e,a):e})},h=e=>m(e,e=>e.monsters,(e,t,n)=>({...t,...rn(e,t,n),yaw:an(e.yaw,t.yaw,n)}));return{you:e=>{n=e},step:(e,n)=>{let d=R({...e,seq:r,view:n===void 0?void 0:f(n)});if(s=void 0,r=r+1&65535,i.push(d),i.length>en&&i.shift(),a&&(o=nn(a),c&&Me(a,d,t))){let e=n??1/0,r=h(e).filter(e=>!l.has(e.id)),i=u.at(-1)?.s.players??[],o=p(e).filter(e=>i.find(t=>t.id===e.id)?.hp);s=$t(t,a,d.seq,[...o.map(Zt),...r.map(Qt)]),s.hit>=16&&l.set(s.hit,d.seq)}return d},snapshot:(e,r)=>{u.push({t:r,s:e}),u.length>tn&&u.shift(),_(t,e.keys,e.phase);let s=e.players.find(e=>e.id===n);s&&(c=s.hp>0,i=i.filter(e=>!on(e.seq,s.ack)),l.forEach((t,n)=>{let r=e=>e.monsters.some(e=>e.id===n);on(t,s.ack)&&(r(e)||!u.some(e=>r(e.s)))&&l.delete(n)}),a=nn(s),o=nn(a),i.forEach((e,n)=>{n===i.length-1&&(o=nn(a)),c&&Me(a,e,t)}))},monsters:h,bullets:e=>m(e,e=>e.bullets,(e,t,n)=>({...t,...rn(e,t,n)})),level:e=>{t=e,u.length=0,l.clear(),a=o=s=void 0},shot:()=>s,me:e=>a&&o?sn(o,a,Math.max(0,Math.min(1,e))):void 0,others:p}},ln={SPOT:0,POINT:1},un=[1.2,1.1,.9],dn=[3,1.4,.4],fn=Math.cos(.436),pn=.5,mn=2,hn=4,J=(e,t,n)=>({kind:ln.POINT,p:e,d:[0,0,0],cone:0,range:t,color:n,shadow:!1}),gn=(e,t,n,r,i,a=!1)=>({...J(e,r,i),kind:ln.SPOT,d:t,cone:n,shadow:a}),_n=(e,...t)=>e.map((e,n)=>e+t.reduce((e,[t,r])=>e+t[n]*r,0)),vn=(e,t)=>e.map(e=>e*t),yn=4,bn=/* @__PURE__ */ new WeakMap,xn=e=>{let t=bn.get(e);return t||(t=e.map.sectors.filter(e=>e.ft==h.LAVA).map(({pts:e,floor:t})=>{let[n,r]=[0,1].map(t=>e.map(e=>e[t])),[i,a]=[Math.max(...n)-Math.min(...n),Math.max(...r)-Math.min(...r)];return{p:[(Math.max(...n)+Math.min(...n))/2,t+2,(Math.max(...r)+Math.min(...r))/2],range:4+Math.sqrt(i*a)*.6}}),bn.set(e,t)),t},Sn=(e,t)=>{let n=e[0]+e[2];return vn([1.4,.45,.12],1+.18*Math.sin(t*1.3+n)+.1*Math.sin(t*11+n*3)+.06*Math.sin(t*23+n))},Cn=({eye:e,yaw:t,pitch:r,dead:i,others:a,fx:o,bullets:s,lvl:c,t:l})=>{let[u,d,f]=Le(t,r),p=[];i||(p.push(gn(_n(e,[u,.2],[d,-.2]),f,fn,25,un,!0)),o.flash>0&&p.push(gn(_n(e,[u,.26],[d,-.24],[f,.6+Ne*.8]),f,pn,8,dn,!0)));let m=t=>Math.hypot(t[0]-e[0],t[1]-e[1],t[2]-e[2]),h=[];a.map(e=>({p:e,e:[e.x,e.y+n,e.z]})).sort((e,t)=>m(e.e)-m(t.e)).forEach(({p:e,e:t},n)=>{let[r,i,a]=Le(e.yaw,e.pitch);h.push(gn(_n(t,[a,.35]),a,fn,25,un,n<mn)),o.flashes.has(e.id)&&h.push(J(_n([e.x,e.y+1.25,e.z],[r,.36],[i,-.12],[a,.8]),6,dn))});for(let e of o.blasts){let t=_t(e);t>0&&h.push(J(e.p,6,vn(dn,t*6)))}o.hurt>0&&h.push(J(e,4,vn([2,.15,.1],Math.min(1,o.hurt*10)))),s.map(e=>J([e.x,e.y,e.z],3,[1.2,.4,.15])).sort((e,t)=>m(e.p)-m(t.p)).slice(0,hn).forEach(e=>h.push(e)),xn(c).filter(e=>m(e.p)<e.range*2).map(({p:e,range:t})=>J(e,t,Sn(e,l))).sort((e,t)=>m(e.p)-m(t.p)).slice(0,yn).forEach(e=>h.push(e));let{exit:g,goal:_}=c.map;if(g!==void 0){let e=1+.3*Math.sin(l*4);if(c.barred.has(g)){if(_){let t=c.map.sectors[y(c,_[0],_[1])]?.floor??0;h.push(J([_[0],t+1,_[1]],8,vn([.2,1.2,1.5],e)))}}else{let{floor:t}=c.map.sectors[g];for(let{ax:n,az:r,bx:i,bz:a,front:o,back:s}of c.edges)if(o==g&&s>=0){let[o,s]=[i-n,a-r],c=.5/Math.hypot(o,s);h.push(J([(n+i)/2-s*c,t+1.2,(r+a)/2+o*c],8,vn([.2,1.5,.3],e)))}}}return p.concat(h.sort((e,t)=>m(e.p)-m(t.p)).slice(0,16-p.length))},wn=1.5,Tn=(e,t)=>{let n=j[e]?.name;return`Level ${e+1}${n?`: ${n}`:``}${t?` (hard mode)`:``}`},En=e=>{let t=Math.floor(e*10/60);return`${Math.floor(t/600)}:${String(Math.floor(t/10)%60).padStart(2,`0`)}.${t%10}`},Dn=({spawns:e},t,n)=>e.reduce((e,r)=>Math.hypot(r[0]-t,r[1]-n)<Math.hypot(e[0]-t,e[1]-n)?r:e)[2],On=({lvl:e,you:t,roster:n,predictor:r,rd:i,delays:a,fx:o,hud:s,audio:c})=>{let l=-1,u=-1,d=0,f=/* @__PURE__ */ new Map,p={lvl:e,items:[],dead:!1,hp:0,name:Tn(0,!1),returning:!1,alive:e=>f.get(e)!==0,snapshot(e){let n=t(),h=e.level*2+ +e.hard;if(h!=l){let t=j[e.level];if(!t)return;l=h,p.lvl=g(t),p.items=[],f=/* @__PURE__ */ new Map,u=-1,r.level(p.lvl),i?.level(p.lvl),o.reset(p.lvl),a.forEach(e=>e.clear()),p.name=Tn(e.level,e.hard),s.say(It.TITLE,`Level ${e.level+1}${e.hard?`
2
- Hard mode`:``}`)}let _=e.players.find(e=>e.id==n),v=f.get(n);_&&v!==void 0&&_.hp<v&&o.hit(),f=new Map(e.players.map(e=>[e.id,e.hp]));for(let t of p.items)_&&!e.items.some(e=>e.id==t.id)&&Math.hypot(t.x-_.x,t.z-_.z)<wn&&(o.pickup(Ct[t.kind]),c?.play(H.COLLECT));p.items=e.items,e.phase!=u&&(u=e.phase,p.returning=u==m.RETURN,s.say(It.NOTE,u==m.RETURN?`Back to the start!`:`Find the exit`)),_?.hp===0&&!p.dead&&(d=e.tick),p.dead=_?.hp===0,p.hp=_?.hp??0,s.hp(p.hp),s.keys(e.keys);let y=180-(e.tick-d&65535);s.dead(p.dead?Math.max(1,Math.ceil(y/60)):0)},end(e,t,r){let i=new Map(n().map(e=>[e.id,e])),a=r.filter(e=>i.has(e.id)).sort((e,t)=>t.kills-e.kills||e.deaths-t.deaths||e.id-t.id).map(({id:e,kills:t,deaths:n})=>[i.get(e).name,i.get(e).color,t,n]);s.end(`Run complete\n${En(e)}${t?` (hard)`:``}`,a,`Next run: Hard mode`)}};return p},kn=Object.keys(h).length,Y=(e,t,n)=>{let r=Math.imul(e,374761393)+Math.imul(t,668265263)+Math.imul(n,144665)|0;return r=Math.imul(r^r>>>13,1274126177),((r^r>>>16)>>>0)/4294967296},X=(e,t,n,r)=>{let[i,a]=[Math.floor(e),Math.floor(t)],[o,s]=[e-i,t-a].map(e=>e*e*(3-2*e)),c=(e,t)=>Y((i+e)%n,(a+t)%n,r);return(c(0,0)*(1-o)+c(1,0)*o)*(1-s)+(c(0,1)*(1-o)+c(1,1)*o)*s},An=(e,t,n,r,i)=>{let[a,o]=[0,.5];for(let s=0;s<r;s++,o/=2)a+=o*X(e*(1<<s),t*(1<<s),n<<s,i+s);return a/(1-o*2)},jn=(e,t,n)=>e.map((e,r)=>e+(t[r]-e)*n),Z=(e,t)=>e.map(e=>e*t),Q=e=>Math.min(Math.max(e,0),1),Mn=Math.PI*2,$=[];$[h.BRICK]=(e,t)=>{let n=Math.floor(t*8),r=e*4+(n&1)*.5,[i,a,o]=[Math.floor(r)%4,r%1,t*8%1],s=X(e*16,t*16,16,5),c=.8+.4*s;return a<.05||o<.1?[Z([165,160,150],.7+.3*c),.1+.1*s]:[Z([170,78,56],(.8+.4*Y(i,n,1))*c*(.85+.15*o)),.7+.2*s+.1*Q(Math.min(a-.05,o-.1)*12)]},$[h.TILE]=(e,t)=>{let[n,r]=[Math.floor(e*4),Math.floor(t*4)],[i,a]=[e*4%1,t*4%1],o=X(e*16,t*16,16,7),s=.9+.2*o;return i<.05||a<.05?[Z([85,85,80],s),.1]:[Z([196,190,172],s*(.88+.08*(n+r&1)+.1*Y(n,r,2))),.8+.1*o+.1*Q((Math.min(i,a)-.05)*14)]},$[h.LAVA]=(e,t)=>{let n=An(e*4,t*4,4,4,11),r=Math.max(0,1-Math.abs(n-.5)*7)**2;return[jn(jn([55,8,4],[230,70,8],n),[255,215,90],r),.5]},$[h.STONE]=(e,t)=>{let n=An(e*8,t*8,8,4,3);return[Z([128,124,120],.45+.7*(n*1.3+.1*Y(Math.floor(e*128),Math.floor(t*128),4))),Q(n*1.4-.2)]},$[h.METAL]=(e,t)=>{let[n,r,i,a]=[Math.floor(e*2),Math.floor(t*2),e*2%1,t*2%1],o=Q((X(e*8,t*8,8,13)-.68)*6),s=e=>Math.min(Math.max(Math.round((e-.1)/.4),0),2)*.4+.1,[c,l]=[s(i),s(a)],u=c==l&&c==.5?1:Math.hypot(i-c,a-l),d=Q(1-u/.07),f=Z([98,108,124],(.9+.2*X(e*32,t*32,32,9)+.12*Y(n,r,6))*(1+.3*d)*(.65+.35*Q((u-.06)/.04)));return Math.min(i,a,1-i,1-a)<.03?[Z([40,44,50],1+o),.05]:[jn(f,[105,68,45],o*.7),.5+.1*(1-o)+.4*d]},$[h.WOOD]=(e,t)=>{let n=Math.floor(t*8),r=e*2+Y(n,0,8)*2,[i,a,o]=[Math.floor(r)%2,r%1,t*8%1],s=Y(n,i,3),c=.5+.5*Math.sin(Mn*(t*40+2.5*X(e*4,t*4,4,21)+s*7));return o<.08||a<.015?[[28,18,10],.05]:[jn([92,58,32],[158,106,62],c*.6+s*.35),.7+.15*c+.15*Q((o-.08)*15)]},$[h.MOSS]=(e,t)=>{let n=Math.floor(t*4),r=e*2+(n&1)*.5,[i,a,o]=[Math.floor(r)%2,r%1,t*4%1],s=Math.min(a,1-a,(o<.5?o:1-o)*.5),c=a<.04||o<.06,l=Q((.3*An(e*12,t*12,12,3,17)-.03-s)*12),u=X(e*64,t*64,64,19),d=Z([128,126,118],(.7+.4*Y(i,n,5))*(.7+.5*X(e*16,t*16,16,15)));return[jn(c?Z(d,.45):d,jn([52,100,34],[96,148,56],u),l),c?.1+.6*l*u:.6+.2*Q(s*30)+.2*l*u]},$[h.GRATE]=(e,t)=>{let[n,r]=[e*8%1,t*8%1],i=Math.max(Math.abs(n-.5),Math.abs(r-.5)),a=Math.min(Math.abs(n-.5),Math.abs(r-.5))>.43,o=X(e*16,t*16,16,23);return i<.36?[[9,9,12],0]:[Z(jn([104,108,116],[96,80,68],Q((o-.55)*4)),(a?1.25:1)-(.5-i)*2.2+.2*o),a?1:.6+.4*Q((i-.36)*12)]};var Nn=()=>{let e=new Uint8ClampedArray(kn*128*128*4);return $.forEach((t,n)=>{for(let r=0;r<16384;r++){let[i,a]=t(r%128/128,Math.floor(r/128)/128);e.set([...i,a*255],(n*128*128+r)*4)}}),e},Pn=[.05,.045,.05,.02],Fn=1<<18,In=[[-1,-1],[1,-1],[1,1],[-1,-1],[1,1],[-1,1]],Ln=2,Rn=512,zn=.3,Bn=.55,Vn=4,Hn=`#version 300 es
1
+ var e=.4,t=1.8,n=1.6,r=1.55,i=.5,a=e=>{let t=(e,t,n,r)=>`${e},${t},${n},${r}`,n=/* @__PURE__ */ new Map;return e.sectors.forEach(({pts:e},r)=>e.forEach(([i,a],o)=>n.set(t(i,a,...e[(o+1)%e.length]),r))),{map:e,edges:e.sectors.flatMap(({pts:e},r)=>e.map(([i,a],o)=>{let[s,c]=e[(o+1)%e.length];return{ax:i,az:a,bx:s,bz:c,front:r,back:n.get(t(s,c,i,a))??-1}}))}},o=({pts:e},t,n)=>e.every(([r,i],a)=>{let[o,s]=e[(a+1)%e.length];return(o-r)*(n-i)-(s-i)*(t-r)>=0}),s=({map:e},t,n)=>e.sectors.findIndex(e=>o(e,t,n)),c=({map:e,edges:t},[n,r,i],[a,o,s])=>{let[c,l]=[a-n,s-i];return t.some(t=>{let[a,s]=[t.bx-t.ax,t.bz-t.az],u=c*s-l*a;if(!u)return!1;let d=((t.ax-n)*s-(t.az-i)*a)/u,f=((t.ax-n)*l-(t.az-i)*c)/u;if(d<=0||d>=1||f<0||f>1)return!1;if(t.back<0)return!0;let[p,m]=[e.sectors[t.front],e.sectors[t.back]],h=r+d*(o-r);return h<Math.max(p.floor,m.floor)||h>Math.min(p.ceil,m.ceil)})},l={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16},u={BRICK:0,TILE:1,LAVA:2,STONE:3,METAL:4,WOOD:5,MOSS:6,GRATE:7},d=(e,t,n,r,i)=>({pts:e,floor:t,ceil:n,ft:r,wt:u.BRICK,ct:u.STONE,light:i});d([[0,0],[16,0],[16,6],[16,10],[16,16],[0,16]],1,5,u.TILE),d([[16,6],[20,6],[20,10],[16,10]],1,3.5,u.TILE,.6),d([[20,0],[36,0],[36,6],[30,6],[26,6],[20,6]],1,7,u.TILE),d([[20,6],[26,6],[26,10],[20,10]],1,7,u.TILE),d([[30,6],[36,6],[36,10],[30,10]],1,7,u.TILE),d([[20,10],[26,10],[30,10],[36,10],[36,16],[32,16],[28,16],[20,16]],1,7,u.TILE),d([[26,6],[30,6],[30,10],[26,10]],0,7,u.LAVA),d([[28,16],[32,16],[32,17],[28,17]],1.4,7,u.STONE),d([[28,17],[32,17],[32,18],[28,18]],1.8,7,u.STONE),d([[28,18],[32,18],[32,19],[28,19]],2.2,7,u.STONE),d([[24,19],[28,19],[32,19],[36,19],[36,26],[24,26]],2.6,7,u.TILE,.8);var f=[0,1.2,7,9,14,17,23,26,27,31,38.8,40],p=[0,1.2,8,9,10,11,16,18,24,26,38.8,40],m=120,h=[[0,0,40,40,1,u.STONE],[1.2,1.2,38.8,38.8,0,u.TILE],[14,1.2,26,8,1.6,u.TILE],[17,8,23,9,1.2,u.STONE],[17,9,23,10,.8,u.STONE],[17,10,23,11,.4,u.STONE],[7,16,9,18,1,u.WOOD],[27,24,31,26,2,u.METAL]],g={name:`Rooftops`,fog:[.8,.88,1,.02],sectors:f.slice(1).flatMap((e,t)=>p.slice(1).map((n,r)=>{let[i,a]=[f[t],p[r]],[o,s]=[(i+e)/2,(a+n)/2],[,,,,c,l]=h.filter(([e,t,n,r])=>e<o&&o<n&&t<s&&s<r).at(-1);return d([[i,a],[e,a],[e,n],[i,n]],c,m,l)})),spawns:[[6,34,0],[13,34,0],[20,34,0],[27,34,0],[34,34,0],[20,22,0]]},_=65536/(2*Math.PI),v=e=>Math.round(e*_)&65535,y=e=>Math.max(-32768,Math.min(32767,Math.round(e))),b=e=>y(e*1e4),x=e=>e/1e4,S=e=>e/_,C=(e=0)=>Math.round(e*256)&16777215,w=e=>({...e,yaw:S(v(e.yaw)),pitch:x(b(e.pitch)),...e.view!==void 0&&{view:C(e.view)/256}}),T=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,v(e.yaw)),t.setInt16(6,b(e.pitch));let n=C(e.view);return t.setUint16(8,n>>8),t.setUint8(10,n&255),t.buffer},E=e=>{if(e.byteLength<4)return null;let t=new DataView(e),n=t.getUint8(3);if(t.getUint8(0)!==2||e.byteLength!==4+24*n)return null;let r=[];for(let e=0;e<n;e++){let n=4+e*24;r.push({id:t.getUint8(n),x:t.getFloat32(n+1),y:t.getFloat32(n+5),z:t.getFloat32(n+9),vy:t.getFloat32(n+13),yaw:S(t.getUint16(n+17)),pitch:x(t.getInt16(n+19)),ack:t.getUint16(n+21),ground:(t.getUint8(n+23)&1)==1})}return{tick:t.getUint16(1),players:r}},ee=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},D=44100,O=([e,t,n,r,i,a,o,s,c,l,u],d)=>{let f=new Float32Array(Math.ceil((r+i+a)*D)),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/D;p+=t*2**(n*_)*(_>c?l:1)*(1+o*Math.sin(_*44))/D,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},k=[],A=(e,t=k)=>{let n=t[e].map((t,n)=>[O(t,e*9+n),Math.round((t[11]??0)*D)]);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)))},j=D*60/108,M=j/4,N=4,P=[2,150,-6,.002,0,.25,0,1,0,1,1],F=[3,9e3,0,.002,0,.15,0,.5,0,1,.5],I=[3,3e4,0,.001,0,.04,0,.7,0,1,.15],te=()=>{let e=new Float32Array(j*4*N),t={},n=(n,r)=>(t[String(r)]??=O(r,1)).forEach((t,r)=>e[(n*M+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,P),`....x.......x...`[t]==`x`&&n(e,F),t%2==0){n(e,I);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)},ne=40,re=24,ie=.5,ae=`tiny-fps:muted`,oe=()=>{let e=!1;return{unlock:()=>{},listen:()=>{},play:()=>{},mute:t=>{e=t},get muted(){return e},destroy:()=>{}}},se=(e=k)=>{let t;try{t=new AudioContext}catch{return oe()}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,ie),a=[],o=!1,s=/* @__PURE__ */ new Set,c=[0,0,0],l=0,u=!1,d=e=>{let n=t.createBuffer(1,e.length,D);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(A(n,e)));let t=f(d(te()));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/ne)**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>=re){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(()=>{})}},ce=()=>{try{return localStorage.getItem(ae)==`1`}catch{return!1}},le=e=>{e.mute(!e.muted);try{localStorage.setItem(ae,e.muted?`1`:`0`)}catch{}return e.muted},ue=[5,1.6,5],de=Math.cos(.436),fe=6,pe=4.4,me=.035,he=.03,ge=(e,t,n)=>{let r=[];for(let i=0;i<e.motes.length;i+=3){let a=[0,1,2].map(n=>e.motes[i+n]-t[n]),o=Math.hypot(...a),s=(a[0]*n[0]+a[1]*n[1]+a[2]*n[2])/o;o<fe&&s>de&&r.push(...a.map((e,n)=>t[n]+e),(s-de)/(1-de)*(1-o/fe))}return r},_e=(e=Math.random)=>{let t=0,r=0,i=0,a=0,o=!0,s=/* @__PURE__ */ new Float32Array(384),c,u=()=>e()*2-1,d={bob:0,roll:0,motes:/* @__PURE__ */ new Float32Array(384),update(e,f,p){let m=Math.min(1,p*10),h=e&&c?.ground&&e.ground?Math.hypot(e.x-c.x,e.z-c.z):0;h<1&&(t+=h*pe),r+=(+(h>.5*p&&h<1)-r)*m,c=e,d.bob=Math.sin(t)*me*r;let g=+!!(f&l.RIGHT)-!!(f&l.LEFT);i+=(g*he-i)*Math.min(1,p*8),d.roll=i,e&&(a+=p,d.motes.forEach((t,r)=>{let[i,c]=[r%3,ue[r%3]],l=i==1?e.y+n:i?e.z:e.x;s[r]=o?u()*.1:s[r];let f=o?l+u()*c:t+(s[r]+Math.sin(a*.8+r)*.05)*p;d.motes[r]=l+((f-l+c)%(2*c)+2*c)%(2*c)-c}),o=!1)}};return d},ve=`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}`,ye=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>Space<td>jump<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}},be=.0025,xe=Math.PI*2,Se={KeyW:l.FORWARD,ArrowUp:l.FORWARD,KeyS:l.BACK,ArrowDown:l.BACK,KeyA:l.LEFT,ArrowLeft:l.LEFT,KeyD:l.RIGHT,ArrowRight:l.RIGHT,Space:l.JUMP},Ce=e=>Se[e]??0,we=(e,t=()=>{})=>{let n=new AbortController,i=(e,t,r)=>e.addEventListener(t,r,{signal:n.signal}),a={yaw:0,pitch:0,keys:0,locked:()=>e.getRootNode().pointerLockElement==e,destroy:()=>n.abort()};i(e,`click`,()=>{Promise.resolve(e.requestPointerLock()).catch(()=>{})}),i(document,`mousemove`,e=>{a.locked()&&(a.yaw=((a.yaw-e.movementX*be)%xe+xe)%xe,a.pitch=Math.max(-1.55,Math.min(r,a.pitch-e.movementY*be)))}),i(document,`keydown`,e=>{let n=Ce(e.code);e.code==`KeyM`&&!e.repeat&&a.locked()&&t(),n&&a.locked()&&(a.keys|=n,e.preventDefault())}),i(document,`keyup`,e=>{a.keys&=~Ce(e.code)});let o=()=>{a.keys=0};return i(window,`blur`,o),i(document,`pointerlockchange`,()=>a.locked()||o()),a},Te=1/60,L=Math.PI*2,Ee=1e-6,R=.01,De=e=>(e%L+L)%L,Oe=e=>[-Math.sin(e),-Math.cos(e)],z=Math.fround,ke=(e,t,n)=>Math.min(Math.max(e,t),n),Ae=({map:e},t,n,r,i)=>{if(t.back<0)return!0;let a=e.sectors[t.front],o=e.sectors[t.back],s=Math.min(a.ceil,o.ceil);return o.floor>n+i+R||s-Math.max(a.floor,o.floor)<r-R||s<n+r-R},je=(e,t,n,r,i)=>{let a=(n-Ee)**2;for(let o=0;o<4;o++){let o=0,s=0,c=0;for(let l of t.edges){let u=l.bx-l.ax,d=l.bz-l.az,f=e.x-l.ax,p=e.z-l.az;if(u*p-d*f<0)continue;let m=ke((f*u+p*d)/(u*u+d*d),0,1),h=f-m*u,g=p-m*d,_=h*h+g*g;if(_>=a)continue;let v=Math.sqrt(_);if(n-v<=o||!Ae(t,l,e.y,r,i))continue;o=n-v;let y=v||Math.hypot(u,d);s=(v?h:-d)/y*o,c=(v?g:u)/y*o}if(!o)return;e.x+=s,e.z+=c}},Me=(e,t,n,r,i,a,o)=>{let{map:c,edges:l}=e,u=Math.max(s(e,t,n),0),{floor:d,ceil:f}=c.sectors[u],p=(i-Ee)**2;for(let i of l){if(i.front!==u||i.back<0)continue;let s=i.bx-i.ax,l=i.bz-i.az,m=t-i.ax,h=n-i.az,g=ke((m*s+h*l)/(s*s+l*l),0,1);if((m-g*s)**2+(h-g*l)**2<p&&!Ae(e,i,r,a,o)){let e=c.sectors[i.back];d=Math.max(d,e.floor),f=Math.min(f,e.ceil)}}return[d,f]},Ne=(n,r,a,o,s)=>{n.x+=r,n.z+=a,je(n,s,e,t,i);let[c,l]=Me(s,n.x,n.z,n.y,e,t,i);n.ground&&o&&(n.vy=7);let u=n.vy-20*Te;n.y+=(n.vy+u)/2*Te,n.vy=u,n.ground=!1,n.y+1.8>l&&(n.y=l-t,n.vy=Math.min(n.vy,0)),(n.vy<=0?n.y<=c+R:n.y<c)&&(n.y=c,n.vy<=0&&(n.vy=0,n.ground=!0)),n.x=z(n.x),n.y=z(n.y),n.z=z(n.z),n.vy=z(n.vy)},Pe=(e,t,n)=>{e.yaw=De(t.yaw),e.pitch=Math.max(-1.55,Math.min(r,t.pitch));let i=(t.keys&l.FORWARD?1:0)-(t.keys&l.BACK?1:0),a=(t.keys&l.RIGHT?1:0)-(t.keys&l.LEFT?1:0),o=6*Te/(Math.hypot(i,a)||1),[s,c]=Oe(e.yaw);Ne(e,(s*i-c*a)*o,(c*i+s*a)*o,(t.keys&l.JUMP)!==0,n)},Fe=120,Ie=16,B=({id:e,x:t,y:n,z:r,vy:i,yaw:a,pitch:o,ground:s})=>({id:e,x:t,y:n,z:r,vy:i,yaw:a,pitch:o,ground:s}),Le=(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}),Re=(e,t,n)=>De(e+(((t-e+Math.PI)%L+L)%L-Math.PI)*n),ze=(e,t)=>(t-e&65535)<32768,Be=(e,t,n)=>({...t,...Le(e,t,n),yaw:Re(e.yaw,t.yaw,n),pitch:e.pitch+(t.pitch-e.pitch)*n}),Ve=e=>{let t,n=0,r=[],i,a,o=[],s=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}},c=e=>{if(!o.length)return;let{a:t,b:n,u:r}=s(e);return(t.s.tick+(n.s.tick-t.s.tick&65535)*r)%65536};return{you:e=>{t=e},step:(t,o)=>{let s=w({...t,seq:n,view:o===void 0?void 0:c(o)});return n=n+1&65535,r.push(s),r.length>Fe&&r.shift(),i&&(a=B(i),Pe(i,s,e)),s},snapshot:(n,s)=>{o.push({t:s,s:n}),o.length>Ie&&o.shift();let c=n.players.find(e=>e.id===t);c&&(r=r.filter(e=>!ze(e.seq,c.ack)),i=B(c),a=B(i),r.forEach((t,n)=>{n===r.length-1&&(a=B(i)),Pe(i,t,e)}))},me:e=>i&&a?Be(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}=s(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?Be(B(t),B(n),a):B(n??t??e)})}}},V=(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]]},He=[[-1,-1],[1,-1],[1,1],[-1,-1],[1,1],[-1,1]],H=(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 He){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])}}},Ue=(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*L/t),Math.sin(e*L/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},We=(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]}),Ge=(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])}},Ke=(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]},U={SPOT:0,POINT:1},qe=[1.2,1.1,.9],Je=Math.cos(.436),Ye=2,Xe=(e,t,n)=>({kind:U.POINT,p:e,d:[0,0,0],cone:0,range:t,color:n,shadow:!1}),Ze=(e,t,n,r,i,a=!1)=>({...Xe(e,r,i),kind:U.SPOT,d:t,cone:n,shadow:a}),Qe=(e,...t)=>e.map((e,n)=>e+t.reduce((e,[t,r])=>e+t[n]*r,0)),$e=(e,t)=>e.map(e=>e*t),et=4,tt=/* @__PURE__ */ new WeakMap,nt=e=>{let t=tt.get(e);return t||(t=e.map.sectors.filter(e=>e.ft==u.LAVA).map(({pts:e,floor:t})=>{let[n,r]=[0,1].map(t=>e.map(e=>e[t])),[i,a]=[Math.max(...n)-Math.min(...n),Math.max(...r)-Math.min(...r)];return{p:[(Math.max(...n)+Math.min(...n))/2,t+2,(Math.max(...r)+Math.min(...r))/2],range:4+Math.sqrt(i*a)*.6}}),tt.set(e,t)),t},rt=(e,t)=>{let n=e[0]+e[2];return $e([1.4,.45,.12],1+.18*Math.sin(t*1.3+n)+.1*Math.sin(t*11+n*3)+.06*Math.sin(t*23+n))},it=({eye:e,yaw:t,pitch:r,others:i,lvl:a,t:o})=>{let[s,c,l]=V(t,r),u=[Ze(Qe(e,[s,.2],[c,-.2]),l,Je,25,qe,!0)],d=t=>Math.hypot(t[0]-e[0],t[1]-e[1],t[2]-e[2]),f=[];return i.map(e=>({p:e,e:[e.x,e.y+n,e.z]})).sort((e,t)=>d(e.e)-d(t.e)).forEach(({p:e,e:t},n)=>{let r=V(e.yaw,e.pitch)[2];f.push(Ze(Qe(t,[r,.35]),r,Je,25,qe,n<Ye))}),nt(a).filter(e=>d(e.p)<e.range*2).map(({p:e,range:t})=>Xe(e,t,rt(e,o))).sort((e,t)=>d(e.p)-d(t.p)).slice(0,et).forEach(e=>f.push(e)),u.concat(f.sort((e,t)=>d(e.p)-d(t.p)).slice(0,16-u.length))},at=3.6,W=({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},st=e=>Math.min(1,Math.hypot(e.vx,e.vz)/2),G=(e,t)=>We(Ue(e,t),[1,1,1]),ct=G([[0,0],[1,.05],[.65,1],[0,1]],5),lt=G([[0,0],[.8,.05],[.55,.7],[1,.8],[.5,1],[0,1]],5),ut=G([[0,0],[.15,0],[.13,.25],[.22,.7],[.2,.95],[0,1]],6),dt=G([[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);Ge(e,t,r,Ke(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,W(n,...r),W(n,...i),a,o,s),pt=([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)]]},mt=(e,t,n)=>{let r=.55*Math.sin(t)*n;return pt(e,r,r-.9*Math.max(0,-Math.sin(t+.5))*n,.43,.45)},ht=.88,gt=(e,n,r,i,a)=>{let o=i*at,s=ht-.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,ut,n,u,d,1,r,1.25),K(e,dt,n,d,[0,t,.02],1.1,c);let f=r.map(e=>.35+.65*e);H(e,W(n,0,d[1]+.17,.17),[.11,.035,.03],n.yaw,f,-2),H(e,W(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]=mt(i,o+(t>0?Math.PI:0),a);K(e,ct,n,i,u,.1,c),K(e,ct,n,u,d,.08,c),H(e,W(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]=pt(f,p,p+.3,.34,.36);K(e,ct,n,f,m,.07,r),K(e,lt,n,m,h,.06,c)}},_t=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),yt=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(yt*(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 bt=()=>{let e=new Uint8ClampedArray(_t*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},xt=[.05,.045,.05,.02],St=1<<18,Ct=2,$=512,wt=.3,Tt=4,Et=`#version 300 es
3
2
  layout(location=0)in vec3 p;layout(location=1)in vec3 n;layout(location=2)in vec4 c;
4
3
  uniform mat4 m;out vec3 P,N;out vec4 C;
5
- void main(){P=p;N=n;C=c;gl_Position=m*vec4(p,1);}`,Un=`#version 300 es
6
- out vec2 U;void main(){U=vec2(gl_VertexID&1,gl_VertexID>>1)*2.;gl_Position=vec4(U*2.-1.,0,1);}`,Wn=`#version 300 es
4
+ void main(){P=p;N=n;C=c;gl_Position=m*vec4(p,1);}`,Dt=`#version 300 es
5
+ out vec2 U;void main(){U=vec2(gl_VertexID&1,gl_VertexID>>1)*2.;gl_Position=vec4(U*2.-1.,0,1);}`,Ot=`#version 300 es
7
6
  precision highp float;uniform sampler2D S[4];uniform vec4 Y;in vec2 U;out vec4 o;
8
7
  vec3 b(vec2 x){vec3 c=texture(S[0],x).rgb;return c*smoothstep(.65,1.3,max(c.r,max(c.g,c.b)));}
9
8
  #define T(k)texture(S[0],U+Y.xy*(k)).rgb
@@ -17,23 +16,23 @@ vec2 q=U-.5;
17
16
  c=min(c,.6)+.4*(1.-exp(-max(c-.6,0.)/.4));
18
17
  c*=1.-.7*dot(q,q);
19
18
  c=pow(c,vec3(.92))+(fract(sin(dot(gl_FragCoord.xy+Y.w,vec2(12.9898,78.233)))*43758.5453)-.5)*.03;}
20
- o=vec4(c,1);}`,Gn=[[.04,8],[.25,30],[0,1],[.08,10],[.8,48],[.06,12],[.3,20],[.7,40],[.1,24]],Kn=`#version 300 es
19
+ o=vec4(c,1);}`,kt=[[.04,8],[.25,30],[0,1],[.08,10],[.8,48],[.06,12],[.3,20],[.7,40],[.1,24]],At=`#version 300 es
21
20
  precision highp float;precision highp sampler2DArray;precision highp sampler2DArrayShadow;
22
21
  in vec3 P,N;in vec4 C;uniform vec3 E;uniform float T,Z;uniform int Q;
23
22
  uniform vec4 A[16],B[16],K[16],F;uniform vec3 G[16];uniform mat4 M[4];
24
23
  uniform sampler2DArray S;uniform sampler2DArrayShadow D;out vec4 o;
25
- const vec2 SP[${Gn.length}]=vec2[](${Gn.map(([e,t])=>`vec2(${e},${t})`)});
24
+ const vec2 SP[${kt.length}]=vec2[](${kt.map(([e,t])=>`vec2(${e},${t})`)});
26
25
  vec3 e(vec3 x){return 2.*(1.-exp(-.5*x));}
27
26
  void main(){
28
27
  if(Z<0.)return;
29
- float L=C.z,s=step(0.,L),I=floor(C.w*.5),y=step(L,-2.5),g=step(abs(L-${h.LAVA}.),.5)+step(L,-1.5)*(1.-y);
30
- vec4 t=texture(S,vec3(C.xy/${Ln}.+vec2(g*T*.01,0),max(L,0.)));
31
- vec3 c=y>0.?vec3(.6):mix(vec3(C.xy,C.w),t.rgb,s);
28
+ float L=C.z,s=step(0.,L),I=floor(C.w*.5),g=step(abs(L-${u.LAVA}.),.5)+step(L,-1.5);
29
+ vec4 t=texture(S,vec3(C.xy/${Ct}.+vec2(g*T*.01,0),max(L,0.)));
30
+ vec3 c=mix(vec3(C.xy,C.w),t.rgb,s);
32
31
  vec3 n=normalize(N),dx=dFdx(P),dy=dFdy(P),a=cross(dy,n),b=cross(n,dx);
33
32
  float h=t.a*s*0.06,det=dot(dx,a);
34
- float f=1.-smoothstep(.6,2.5,${128/Ln}.*max(length(dFdx(C.xy)),length(dFdy(C.xy))));
33
+ float f=1.-smoothstep(.6,2.5,${128/Ct}.*max(length(dFdx(C.xy)),length(dFdy(C.xy))));
35
34
  vec3 m=normalize(abs(det)*n-sign(det)*f*(dFdx(h)*a+dFdy(h)*b)+n*1e-9);
36
- vec2 R=SP[int(s>0.?L+.5:${kn}.)];
35
+ vec2 R=SP[int(s>0.?L+.5:${_t}.)];
37
36
  vec3 l=mix(vec3(1),G[int(min(I,15.))]*(C.w-2.*I),s)*Z*(.45+.55*max(dot(normalize(n+m),normalize(vec3(.4,.8,.3))),0.)),sp=vec3(0),V=normalize(E-P);
38
37
  for(int i=0;i<16;i++){
39
38
  if(i>=Q||g>0.)break;
@@ -44,9 +43,9 @@ w*=w*smoothstep(u,u+(1.-u)*.4,-dot(d,B[i].xyz))*max(dot(m,d),0.);
44
43
  if(w>0.&&k>=0.){
45
44
  vec4 q=M[int(k)]*vec4(P+n*.03,1);q.xyz=q.xyz/q.w*.5+.5;
46
45
  float v=0.;
47
- for(int j=0;j<4;j++)v+=texture(D,vec4(q.xy+(vec2(j&1,j>>1)*2.-1.)*${.75/Rn},k,q.z-.0005));
46
+ for(int j=0;j<4;j++)v+=texture(D,vec4(q.xy+(vec2(j&1,j>>1)*2.-1.)*${.75/$},k,q.z-.0005));
48
47
  w*=v/4.;}
49
48
  l+=K[i].rgb*w;
50
49
  sp+=K[i].rgb*w*pow(max(dot(m,normalize(d+V)),0.),R.y);}
51
50
  c=c*mix(e(l),vec3(1.4),g)+e(sp*R.x*(.4+.6*mix(1.,t.a,s)));
52
- o=vec4(mix(c,F.rgb,1.-exp(-F.a*length(P-E))),y>0.?C.w*(1.-smoothstep(.2,1.,length(C.xy))):1.);}`,qn=(e,t,n,r,i=0,a=Math.tan(70*Math.PI/360),[o,s]=[.1,200])=>{let[c,l,u]=Le(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])},Jn=(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)]},Yn=({p:e,d:t,cone:n,range:r})=>qn(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]),Xn=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==ln.SPOT&&a<4?a++:-1;t.set([...e.p,e.range],o*4),n.set([...e.d,e.kind==ln.POINT?-9:e.cone],o*4),r.set([...e.color,s],o*4),s>=0&&i.set(Yn(e),s*16)}),{n:o.length,maps:a,a:t,b:n,k:r,m:i}},Zn=({map:e},{front:t,back:n})=>{let r=e.sectors[t];if(n<0)return[[r.floor,r.ceil]];let i=e.sectors[n];return[[r.floor,i.floor],[i.ceil,r.ceil]].filter(([e,t])=>t>e)},Qn=({map:e})=>[...new Map([[`1,1,1`,[1,1,1]],...e.sectors.flatMap(({tint:e})=>e?[[`${e}`,e]]:[])]).values()].slice(0,16),$n=e=>{let t=[],n=Qn(e).map(String),r=({light:e=1,tint:t})=>e+2*Math.max(0,n.indexOf(`${t}`));for(let n of e.map.sectors){let{pts:e,floor:i,ceil:a,ft:o,ct:s}=n,c=r(n);for(let[n,r,l]of[[i,1,o],[a,-1,s]])for(let i=1;i<e.length-1;i++)for(let[a,o]of[e[0],e[i],e[i+1]])t.push(a,n,o,0,r,0,a,o,l,c)}for(let n of e.edges){let{ax:i,az:a,bx:o,bz:s,front:c}=n,{wt:l}=e.map.sectors[c],u=r(e.map.sectors[c]),d=Math.hypot(o-i,s-a),[f,p]=[(o-i)/d,(s-a)/d];for(let[r,c]of Zn(e,n))for(let[e,n,d]of[[i,a,r],[o,s,r],[o,s,c],[i,a,r],[o,s,c],[i,a,c]])t.push(e,d,n,-p,0,f,e*f+n*p,d,l,u)}return t},er=2073600,tr=(e,t,n)=>{let r=Math.min(n,2,Math.sqrt(er/(e*t||1)));return[Math.round(e*r),Math.round(t*r)]},nr=(n,r)=>{let i=r,a=n.getContext(`webgl2`,{antialias:!1,depth:!1});if(!a)throw Error(`WebGL2 is not available`);let o=document.createElement(`canvas`).getContext(`2d`),s=/* @__PURE__ */ new Map,c=e=>{let t=s.get(e);if(!t){o.fillStyle=`#888`,o.fillStyle=e;let n=parseInt(o.fillStyle.slice(1),16),r=n>=0?n:8947848;s.set(e,t=[r>>16,r>>8&255,r&255].map(e=>e/255))}return t},l=()=>tr(n.clientWidth,n.clientHeight,devicePixelRatio),u=$n(i),f=Nn(),p=u.length*4,m=p+Fn,[h,g]=[[.55,.55,.6],[.2,.2,.23]],_={barrels:Re(Ie(10).barrels,h),body:Re(Ie(10).body,g)},v={barrels:Re(Ie(5).barrels,h),body:Re(Ie(5).body,g)},y=[],b=[];for(let e of[[.1,.01,.03],[.01,.1,.03],[.03,.03,.05]])K(y,[0,0,-Ne-.04],e,0,[1,.85,.4],-2),K(b,[0,0,-Ne-.12],e.map(e=>e*3),0,[1,.85,.4],-2);let x={},S,C,w,T,E={},D,O,k,A,j=[0,0],M=[],N=!1,P=/* @__PURE__ */ new Float32Array(16),F=()=>{a.bufferData(a.ARRAY_BUFFER,m,a.DYNAMIC_DRAW),a.bufferSubData(a.ARRAY_BUFFER,0,new Float32Array(u))},ee=(e,t,n)=>{let r=a.createProgram();for(let[n,i]of[[a.VERTEX_SHADER,e],[a.FRAGMENT_SHADER,t]]){let e=a.createShader(n);a.shaderSource(e,i),a.compileShader(e),a.attachShader(r,e)}return a.linkProgram(r),a.useProgram(r),[r,Object.fromEntries(n.map(e=>[e,a.getUniformLocation(r,e)]))]},I=(e,t)=>{let n=a.createTexture();a.bindTexture(a.TEXTURE_2D,n),a.texStorage2D(a.TEXTURE_2D,1,D,e,t),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE);let r=a.createFramebuffer();return a.bindFramebuffer(a.FRAMEBUFFER,r),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,n,0),M.push(()=>a.deleteTexture(n),()=>a.deleteFramebuffer(r)),{t:n,f:r,w:e,h:t}},L=(e,t)=>{M.splice(0).forEach(e=>e()),j=[e,t],k=I(e,t),A=[1,2,3].map(n=>[0,1].map(()=>I(e>>n||1,t>>n||1)));let n=n=>{let r=a.createRenderbuffer();return a.bindRenderbuffer(a.RENDERBUFFER,r),a.renderbufferStorageMultisample(a.RENDERBUFFER,Vn,n,e,t),M.push(()=>a.deleteRenderbuffer(r)),r};a.bindFramebuffer(a.FRAMEBUFFER,O=a.createFramebuffer()),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.RENDERBUFFER,n(D)),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,a.RENDERBUFFER,n(a.DEPTH_COMPONENT24)),M.push(()=>a.deleteFramebuffer(O))},R=(e,t,n,r,...i)=>{a.bindFramebuffer(a.FRAMEBUFFER,e?.f??null),a.viewport(0,0,e?.w??j[0],e?.h??j[1]),i.forEach((e,t)=>{a.activeTexture(a.TEXTURE0+t),a.bindTexture(a.TEXTURE_2D,e.t)}),a.uniform4f(E.Y,n,r,t,performance.now()%1e4),a.drawArrays(a.TRIANGLES,0,3)},z=()=>{D=a.getExtension(`EXT_color_buffer_float`)?a.RGBA16F:a.RGBA8,M.length=0,j=[0,0],[T,E]=ee(Un,Wn,[`S`,`Y`]),a.uniform1iv(E.S,[0,1,2,3]),[w,x]=ee(Hn,Kn,[`m`,`E`,`T`,`Z`,`Q`,`A`,`B`,`K`,`M`,`D`,`F`,`G`]),a.uniform1i(x.D,1),a.bindBuffer(a.ARRAY_BUFFER,a.createBuffer()),F(),[3,3,4].reduce((e,t,n)=>(a.enableVertexAttribArray(n),a.vertexAttribPointer(n,t,a.FLOAT,!1,40,e*4),e+t),0),a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D_ARRAY,S=a.createTexture()),a.texStorage3D(a.TEXTURE_2D_ARRAY,1,a.DEPTH_COMPONENT24,Rn,Rn,4);for(let[e,t]of[[a.TEXTURE_MIN_FILTER,a.LINEAR],[a.TEXTURE_MAG_FILTER,a.LINEAR],[a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE],[a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE],[a.TEXTURE_COMPARE_MODE,a.COMPARE_REF_TO_TEXTURE]])a.texParameteri(a.TEXTURE_2D_ARRAY,e,t);a.bindFramebuffer(a.FRAMEBUFFER,C=a.createFramebuffer()),a.drawBuffers([a.NONE]),a.bindFramebuffer(a.FRAMEBUFFER,null),a.polygonOffset(2,4),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D_ARRAY,a.createTexture()),a.texImage3D(a.TEXTURE_2D_ARRAY,0,a.RGBA8,128,128,kn,0,a.RGBA,a.UNSIGNED_BYTE,f),a.generateMipmap(a.TEXTURE_2D_ARRAY),a.texParameteri(a.TEXTURE_2D_ARRAY,a.TEXTURE_MIN_FILTER,a.LINEAR_MIPMAP_LINEAR);let e=a.getExtension(`EXT_texture_filter_anisotropic`);e&&a.texParameterf(a.TEXTURE_2D_ARRAY,e.TEXTURE_MAX_ANISOTROPY_EXT,8),a.enable(a.DEPTH_TEST),a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),B();let[t,n]=l();t&&n&&L(t,n)},B=()=>{let e=i.map.fog??Pn,t=Qn(i);a.uniform4fv(x.F,e),a.uniform3fv(x.G,Float32Array.from({length:48},(e,n)=>t[n/3|0]?.[n%3]??1)),a.clearColor(e[0],e[1],e[2],1)};z();let te=e=>{e.preventDefault(),N=!0},V=()=>{z(),N=!1};return n.addEventListener(`webglcontextlost`,te),n.addEventListener(`webglcontextrestored`,V),{level(e){i=e,u=$n(i),p=u.length*4,m=p+Fn,N||(F(),B())},frame(r,o,s,f,h,g,E,D,M,ee){let[I,z]=l();if(N||!I||!z)return;(n.width!=I||n.height!=z)&&(n.width=I,n.height=z),(j[0]!=I||j[1]!=z)&&L(I,z),P=qn(r,o,s,I/z,g.roll);let B=[];for(let n of f){let[r,i]=Te(n.yaw),a=e*.8,o=1.4500000000000002;K(B,[n.x,n.y+o/2,n.z],[a,o/2,a],n.yaw,[...c(h.get(n.id)??`#888`)]);let s=[n.x,n.y+t-.17,n.z];K(B,s,[.17,.17,.17],n.yaw,[.95,.8,.65]),K(B,[s[0]+r*.17,s[1]+.03,s[2]+i*.17],[.13,.05,.03],n.yaw,[.1,.1,.12]);let l=[n.x,n.y+1.25,n.z],u=Le(n.yaw,n.pitch);for(let e of[v.barrels,v.body,g.flashes.has(n.id)?b:[]])ze(B,e,l,u,[.36,-.12,.3],.8)}let te=performance.now()/1e3;for(let e of E)if(e.kind==d.FLYER)Ye(B,e,te);else{let t=g.swings.get(e.id);qe(B,e,g.herd.get(e.id)?.walked??0,t?1-t/Be:0)}Ft(B,i,M,te);for(let{p:e,yaw:t,size:n,c:r,life:i}of g.gibs){let a=n*Math.min(1,i*2);K(B,e,[a,a,a],t,r)}let V=B.length;for(let e of D)Xe(B,e,g.aim.get(e.id));let H=Le(o,s,g.roll),[U,ne,re]=H,ie=bt(g,r,re);for(let e=0;e<ie.length;e+=4){let[t,n]=[Math.sqrt(ie[e+3]),.01+.025*ie[e+3]];K(B,ie.slice(e,e+3),[n,n,n],0,[t,t*.9,t*.7],-2)}for(let{p:e,c:t}of g.sparks)K(B,e,[.025,.025,.025],0,t??[1,.8,.3],-2);for(let e of g.blasts){let[t,n]=[_t(e),e.t/ot],r=[1,.9-n*.7,.5-n*.45];for(let n of[0,Math.PI/4])K(B,e.p,[t,t,t],n,r,-2)}let ae=B.length,oe=e=>Math.hypot(e.p[0]-r[0],e.p[1]-r[1],e.p[2]-r[2]);for(let e of[...g.smoke].sort((e,t)=>oe(t)-oe(e))){let[t,n]=[vt(e)*1.6,yt(e)];for(let[r,i]of In)B.push(...[0,1,2].map(n=>e.p[n]+(U[n]*r+ne[n]*i)*t),...re.map(e=>-e),r,i,-3,n)}let se=B.length,ce=[.26,-.24+g.kick*.01,.6-g.kick*.06];g.dead||(ze(B,_.body,r,H,ce,.8),ze(B,_.barrels,r,H,ce,.8,g.spin),g.flash>0&&ze(B,y,r,H,ce,.8,g.spin*3)),p+B.length*4>m&&(m=p+B.length*8,F()),a.bufferSubData(a.ARRAY_BUFFER,p,new Float32Array(B));let W=Xn(ee),le=u.length/10;if(W.maps){a.uniform1f(x.Z,-1),a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D_ARRAY,null),a.bindFramebuffer(a.FRAMEBUFFER,C),a.viewport(0,0,Rn,Rn),a.enable(a.POLYGON_OFFSET_FILL);for(let e=0;e<W.maps;e++)a.framebufferTextureLayer(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,S,0,e),a.uniformMatrix4fv(x.m,!1,W.m.subarray(e*16,e*16+16)),a.clear(a.DEPTH_BUFFER_BIT),a.drawArrays(a.TRIANGLES,0,le+V/10);a.disable(a.POLYGON_OFFSET_FILL),a.bindTexture(a.TEXTURE_2D_ARRAY,S),a.activeTexture(a.TEXTURE0)}a.bindFramebuffer(a.FRAMEBUFFER,O),a.viewport(0,0,I,z),a.uniformMatrix4fv(x.m,!1,P),a.uniform3fv(x.E,r),a.uniform1f(x.T,performance.now()/1e3),a.uniform1f(x.Z,zn),a.uniform1i(x.Q,W.n),a.uniform4fv(x.A,W.a),a.uniform4fv(x.B,W.b),a.uniform4fv(x.K,W.k),a.uniformMatrix4fv(x.M,!1,W.m),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT),a.drawArrays(a.TRIANGLES,0,le+ae/10),se>ae&&(a.enable(a.BLEND),a.depthMask(!1),a.drawArrays(a.TRIANGLES,le+ae/10,(se-ae)/10),a.depthMask(!0),a.disable(a.BLEND)),a.clear(a.DEPTH_BUFFER_BIT),a.uniform1f(x.Z,Bn),a.drawArrays(a.TRIANGLES,le+se/10,(B.length-se)/10),a.bindFramebuffer(a.READ_FRAMEBUFFER,O),a.bindFramebuffer(a.DRAW_FRAMEBUFFER,k.f),a.blitFramebuffer(0,0,I,z,0,0,I,z,a.COLOR_BUFFER_BIT,a.NEAREST),a.useProgram(T),R(A[0][0],0,1/I,1/z,k),A.forEach(([e,t],n)=>{R(t,1,1/t.w,0,A[n&&n-1][0]),R(e,1,0,1/e.h,t)}),R(void 0,2,0,0,k,...A.map(e=>e[0]));for(let e=3;e>0;e--)a.activeTexture(a.TEXTURE0+e),a.bindTexture(a.TEXTURE_2D,null);a.activeTexture(a.TEXTURE0),a.useProgram(w)},project:(e,t,n)=>Jn(P,e,t,n),destroy(){n.removeEventListener(`webglcontextlost`,te),n.removeEventListener(`webglcontextrestored`,V),a.getExtension(`WEBGL_lose_context`)?.loseContext()}}},rr=1/60,ir=5,ar=(e,i)=>{let a=document.createElement(`div`),o=a.attachShadow({mode:`open`});o.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}`+Bt+`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(a);let s=o.querySelector(`canvas`),c=o.querySelector(`p`),l=o.querySelector(`div`),u=Vt(l),d={roster:[],open:[],close:[]},f=e=>d[e].forEach(e=>e()),p=g(j[0]),m=cn(p),h=he();h.mute(ye()),u.mute(h.muted);let _=_e(h),v=ve(h),y=Kt(s,()=>u.mute(be(h)));s.addEventListener(`click`,()=>h.unlock());let x=St(Math.random,p),S=xt(),C=xt(),w=-1,T;try{T=nr(s,p)}catch{}let E=On({lvl:p,you:()=>w,roster:()=>D,predictor:m,rd:T,delays:[S,C],fx:x,hud:u,audio:h}),D=[],O=/* @__PURE__ */ new Map,k=/* @__PURE__ */ new Map,A=/* @__PURE__ */ new Map,M=!1,N=T?``:`WebGL2 is not available`,P=!1,F=-1,ee=!1,I=performance.now(),L=0,R=0,V=!1,U=i.socket??new WebSocket(i.url);U.binaryType=`arraybuffer`,U.onopen=()=>{M=!0,U.send(JSON.stringify({t:`join`,name:i.name})),f(`open`)},U.onclose=()=>{M=!1,N||=`Connection closed`,f(`close`)},U.onmessage=({data:e})=>{if(typeof e!=`string`){let t=B(e);if(t){let e=performance.now();E.snapshot(t),m.snapshot(t,e);let n=t.players.find(e=>e.id==w),r=t.level*2+ +t.hard;n?.hp&&(r!=F||!ee)&&([y.yaw,y.pitch]=[Dn(E.lvl.map,n.x,n.z),0]),[F,ee]=[r,!!n?.hp],S.push(t.shots.filter(e=>e.id!=w),e),C.push(t.events,e)}return}let t=te(e);t?.t==`roster`?(D=t.players,O=new Map(D.map(e=>[e.id,e.color])),k=new Map(D.map(e=>[e.id,e.name])),m.you(w=t.you),c.textContent=`Players: ${D.length}`,f(`roster`)):t?.t==`full`?N=`Room is full`:t?.t==`end`&&E.end(t.ticks,t.hard,t.stats)};let ne=e=>{let t=A.get(e);return t||(A.set(e,t=document.createElement(`b`)),l.append(t)),t},re=()=>{R=requestAnimationFrame(re);let e=performance.now(),i=I;if(L=Math.min(L+(e-I)/1e3,ir*rr),I=e,!P){let e=m.me(0);e&&([y.yaw,y.pitch,P]=[e.yaw,e.pitch,!0]),L=0}for(;P&&L>=rr;L-=rr){let t=E.dead?0:y.keys,r=m.step({keys:t,yaw:y.yaw,pitch:y.pitch},e);M&&U.send(z(r));let i=m.shot(),a=i&&m.me(1);i&&a&&(x.shot(i,[a.x,a.y+n,a.z],!0),h.play(H.SHOT))}let a=m.me(L/rr),o=m.others(e).filter(e=>E.alive(e.id)),s=m.monsters(e),c=m.bullets(e),l=a?[a.x,a.y+n,a.z]:[0,0,0];x.track(s,c),h.listen(l,y.yaw);for(let t of S.due(e)){let e=o.find(e=>e.id==t.id);if(e){let r=[e.x,e.y+n,e.z];x.shot(t,r,!1,t.hit!=w),h.play(H.SHOT,r)}}for(let t of C.due(e))x.event(t,w),ge(h,t,w);_(E.returning,e);let d=Math.min((e-i)/1e3,.1);if(x.update(a,y.keys,d,E.dead),u.update(d),a&&T){let t=Math.max(-1.55,Math.min(r,y.pitch+x.shakePitch));T.frame([l[0],l[1]+x.bob,l[2]],y.yaw+x.shakeYaw,t,o,O,x,s,c,E.items,Cn({eye:[l[0],l[1]+x.bob,l[2]],yaw:y.yaw,pitch:y.pitch,dead:E.dead,others:o,fx:x,bullets:c,lvl:E.lvl,t:e/1e3}))}let f=/* @__PURE__ */ new Set;for(let e of o){let n=[e.x,e.y+t+.3,e.z],r=a&&!b(E.lvl,l,n)?T?.project(...n):void 0,i=ne(e.id);f.add(e.id),i.hidden=!r,r&&(i.style.left=r[0]*100+`%`,i.style.top=r[1]*100+`%`);let o=k.get(e.id)??``;i.textContent!=o&&(i.textContent=o)}for(let[e,t]of A)f.has(e)||(t.remove(),A.delete(e));u.fade(x.hurt/st,v(E.hp,e),x.gain/ct,x.gainC),u.title(N||(M?P?y.locked()?``:`Click to play`:`Joining…`:`Connecting…`),E.name)};return R=requestAnimationFrame(re),{on:(e,t)=>void d[e].push(t),players:()=>D,destroy(){V||(V=!0,cancelAnimationFrame(R),y.destroy(),h.destroy(),T?.destroy(),U.onopen=U.onclose=U.onmessage=null,U.close(),document.exitPointerLock(),a.remove())}}};export{ar as tinyFps};
51
+ o=vec4(mix(c,F.rgb,1.-exp(-F.a*length(P-E))),1.);}`,jt=(e,t,n,r,i=0,a=Math.tan(70*Math.PI/360),[o,s]=[.1,200])=>{let[c,l,u]=V(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])},Mt=(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)]},Nt=({p:e,d:t,cone:n,range:r})=>jt(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]),Pt=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==U.SPOT&&a<4?a++:-1;t.set([...e.p,e.range],o*4),n.set([...e.d,e.kind==U.POINT?-9:e.cone],o*4),r.set([...e.color,s],o*4),s>=0&&i.set(Nt(e),s*16)}),{n:o.length,maps:a,a:t,b:n,k:r,m:i}},Ft=({map:e},{front:t,back:n})=>{let r=e.sectors[t];if(n<0)return[[r.floor,r.ceil]];let i=e.sectors[n];return[[r.floor,i.floor],[i.ceil,r.ceil]].filter(([e,t])=>t>e)},It=({map:e})=>[...new Map([[`1,1,1`,[1,1,1]],...e.sectors.flatMap(({tint:e})=>e?[[`${e}`,e]]:[])]).values()].slice(0,16),Lt=e=>{let t=[],n=It(e).map(String),r=({light:e=1,tint:t})=>e+2*Math.max(0,n.indexOf(`${t}`));for(let n of e.map.sectors){let{pts:e,floor:i,ceil:a,ft:o,ct:s}=n,c=r(n);for(let[n,r,l]of[[i,1,o],[a,-1,s]])for(let i=1;i<e.length-1;i++)for(let[a,o]of[e[0],e[i],e[i+1]])t.push(a,n,o,0,r,0,a,o,l,c)}for(let n of e.edges){let{ax:i,az:a,bx:o,bz:s,front:c}=n,{wt:l}=e.map.sectors[c],u=r(e.map.sectors[c]),d=Math.hypot(o-i,s-a),[f,p]=[(o-i)/d,(s-a)/d];for(let[r,c]of Ft(e,n))for(let[e,n,d]of[[i,a,r],[o,s,r],[o,s,c],[i,a,r],[o,s,c],[i,a,c]])t.push(e,d,n,-p,0,f,e*f+n*p,d,l,u)}return t},Rt=2073600,zt=(e,t,n)=>{let r=Math.min(n,2,Math.sqrt(Rt/(e*t||1)));return[Math.round(e*r),Math.round(t*r)]},Bt=(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=()=>zt(e.clientWidth,e.clientHeight,devicePixelRatio),l=Lt(t),u=bt(),d=l.length*4,f=d+St,p={},m,h,g,_,v={},y,b,x,S,C=[0,0],w=[],T=!1,E=/* @__PURE__ */ new Float32Array(16),ee=()=>{i.bufferData(i.ARRAY_BUFFER,f,i.DYNAMIC_DRAW),i.bufferSubData(i.ARRAY_BUFFER,0,new Float32Array(l))},D=(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)]))]},O=(e,t)=>{let n=i.createTexture();i.bindTexture(i.TEXTURE_2D,n),i.texStorage2D(i.TEXTURE_2D,1,y,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),w.push(()=>i.deleteTexture(n),()=>i.deleteFramebuffer(r)),{t:n,f:r,w:e,h:t}},k=(e,t)=>{w.splice(0).forEach(e=>e()),C=[e,t],x=O(e,t),S=[1,2,3].map(n=>[0,1].map(()=>O(e>>n||1,t>>n||1)));let n=n=>{let r=i.createRenderbuffer();return i.bindRenderbuffer(i.RENDERBUFFER,r),i.renderbufferStorageMultisample(i.RENDERBUFFER,Tt,n,e,t),w.push(()=>i.deleteRenderbuffer(r)),r};i.bindFramebuffer(i.FRAMEBUFFER,b=i.createFramebuffer()),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.RENDERBUFFER,n(y)),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.RENDERBUFFER,n(i.DEPTH_COMPONENT24)),w.push(()=>i.deleteFramebuffer(b))},A=(e,t,n,r,...a)=>{i.bindFramebuffer(i.FRAMEBUFFER,e?.f??null),i.viewport(0,0,e?.w??C[0],e?.h??C[1]),a.forEach((e,t)=>{i.activeTexture(i.TEXTURE0+t),i.bindTexture(i.TEXTURE_2D,e.t)}),i.uniform4f(v.Y,n,r,t,performance.now()%1e4),i.drawArrays(i.TRIANGLES,0,3)},j=()=>{y=i.getExtension(`EXT_color_buffer_float`)?i.RGBA16F:i.RGBA8,w.length=0,C=[0,0],[_,v]=D(Dt,Ot,[`S`,`Y`]),i.uniform1iv(v.S,[0,1,2,3]),[g,p]=D(Et,At,[`m`,`E`,`T`,`Z`,`Q`,`A`,`B`,`K`,`M`,`D`,`F`,`G`]),i.uniform1i(p.D,1),i.bindBuffer(i.ARRAY_BUFFER,i.createBuffer()),ee(),[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,m=i.createTexture()),i.texStorage3D(i.TEXTURE_2D_ARRAY,1,i.DEPTH_COMPONENT24,$,$,4);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,h=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,_t,0,i.RGBA,i.UNSIGNED_BYTE,u),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),M();let[t,n]=c();t&&n&&k(t,n)},M=()=>{let e=t.map.fog??xt,n=It(t);i.uniform4fv(p.F,e),i.uniform3fv(p.G,Float32Array.from({length:48},(e,t)=>n[t/3|0]?.[t%3]??1)),i.clearColor(e[0],e[1],e[2],1)};j();let N=e=>{e.preventDefault(),T=!0},P=()=>{j(),T=!1};return e.addEventListener(`webglcontextlost`,N),e.addEventListener(`webglcontextrestored`,P),{frame(t,a,o,u,v,y,w){let[D,O]=c();if(T||!D||!O)return;(e.width!=D||e.height!=O)&&(e.width=D,e.height=O),(C[0]!=D||C[1]!=O)&&k(D,O),E=jt(t,a,o,D/O,y.roll);let j=[],M=performance.now()/1e3,N=Math.min(.1,M-r);r=M;for(let e of u){let t=ot(n,e.id,e.x,e.z,N);gt(j,e,s(v.get(e.id)??`#888`),t.walked,st(t))}let P=j.length,F=ge(y,t,V(a,o,y.roll)[2]);for(let e=0;e<F.length;e+=4){let[t,n]=[Math.sqrt(F[e+3]),.01+.025*F[e+3]];H(j,F.slice(e,e+3),[n,n,n],0,[t,t*.9,t*.7],-2)}d+j.length*4>f&&(f=d+j.length*8,ee()),i.bufferSubData(i.ARRAY_BUFFER,d,new Float32Array(j));let I=Pt(w),te=l.length/10;if(I.maps){i.uniform1f(p.Z,-1),i.activeTexture(i.TEXTURE1),i.bindTexture(i.TEXTURE_2D_ARRAY,null),i.bindFramebuffer(i.FRAMEBUFFER,h),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,m,0,e),i.uniformMatrix4fv(p.m,!1,I.m.subarray(e*16,e*16+16)),i.clear(i.DEPTH_BUFFER_BIT),i.drawArrays(i.TRIANGLES,0,te+P/10);i.disable(i.POLYGON_OFFSET_FILL),i.bindTexture(i.TEXTURE_2D_ARRAY,m),i.activeTexture(i.TEXTURE0)}i.bindFramebuffer(i.FRAMEBUFFER,b),i.viewport(0,0,D,O),i.uniformMatrix4fv(p.m,!1,E),i.uniform3fv(p.E,t),i.uniform1f(p.T,performance.now()/1e3),i.uniform1f(p.Z,wt),i.uniform1i(p.Q,I.n),i.uniform4fv(p.A,I.a),i.uniform4fv(p.B,I.b),i.uniform4fv(p.K,I.k),i.uniformMatrix4fv(p.M,!1,I.m),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),i.drawArrays(i.TRIANGLES,0,te+j.length/10),i.bindFramebuffer(i.READ_FRAMEBUFFER,b),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,x.f),i.blitFramebuffer(0,0,D,O,0,0,D,O,i.COLOR_BUFFER_BIT,i.NEAREST),i.useProgram(_),A(S[0][0],0,1/D,1/O,x),S.forEach(([e,t],n)=>{A(t,1,1/t.w,0,S[n&&n-1][0]),A(e,1,0,1/e.h,t)}),A(void 0,2,0,0,x,...S.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(g)},project:(e,t,n)=>Mt(E,e,t,n),destroy(){e.removeEventListener(`webglcontextlost`,N),e.removeEventListener(`webglcontextrestored`,P),i.getExtension(`WEBGL_lose_context`)?.loseContext()}}},Vt=1/60,Ht=5,Ut=(e,r)=>{let i=document.createElement(`div`),o=i.attachShadow({mode:`open`});o.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}`+ve+`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(i);let s=o.querySelector(`canvas`),l=o.querySelector(`p`),u=o.querySelector(`div`),d=ye(u),f={roster:[],open:[],close:[]},p=e=>f[e].forEach(e=>e()),m=a(g),h=Ve(m),_=se();_.mute(ce()),d.mute(_.muted);let v=we(s,()=>d.mute(le(_)));s.addEventListener(`click`,()=>_.unlock());let y=_e(),b;try{b=Bt(s,m)}catch{}let x=[],S=/* @__PURE__ */ new Map,C=/* @__PURE__ */ new Map,w=/* @__PURE__ */ new Map,D=!1,O=b?``:`WebGL2 is not available`,k=!1,A=performance.now(),j=0,M=0,N=!1,P=r.socket??new WebSocket(r.url);P.binaryType=`arraybuffer`,P.onopen=()=>{D=!0,P.send(JSON.stringify({t:`join`,name:r.name})),p(`open`)},P.onclose=()=>{D=!1,O||=`Connection closed`,p(`close`)},P.onmessage=({data:e})=>{if(typeof e!=`string`){let t=E(e);t&&h.snapshot(t,performance.now());return}let t=ee(e);t?.t==`roster`?(x=t.players,S=new Map(x.map(e=>[e.id,e.color])),C=new Map(x.map(e=>[e.id,e.name])),h.you(t.you),l.textContent=`Players: ${x.length}`,p(`roster`)):t?.t==`full`&&(O=`Room is full`)};let F=e=>{let t=w.get(e);return t||(w.set(e,t=document.createElement(`b`)),u.append(t)),t},I=()=>{M=requestAnimationFrame(I);let e=performance.now(),r=A;if(j=Math.min(j+(e-A)/1e3,Ht*Vt),A=e,!k){let e=h.me(0);e&&([v.yaw,v.pitch,k]=[e.yaw,e.pitch,!0]),j=0}for(;k&&j>=Vt;j-=Vt){let t=h.step({keys:v.keys,yaw:v.yaw,pitch:v.pitch},e);D&&P.send(T(t))}let i=h.me(j/Vt),a=h.others(e),o=i?[i.x,i.y+n,i.z]:[0,0,0];_.listen(o,v.yaw);let s=Math.min((e-r)/1e3,.1);y.update(i,v.keys,s),i&&b&&b.frame([o[0],o[1]+y.bob,o[2]],v.yaw,v.pitch,a,S,y,it({eye:[o[0],o[1]+y.bob,o[2]],yaw:v.yaw,pitch:v.pitch,others:a,lvl:m,t:e/1e3}));let l=/* @__PURE__ */ new Set;for(let e of a){let n=[e.x,e.y+t+.3,e.z],r=i&&!c(m,o,n)?b?.project(...n):void 0,a=F(e.id);l.add(e.id),a.hidden=!r,r&&(a.style.left=r[0]*100+`%`,a.style.top=r[1]*100+`%`);let s=C.get(e.id)??``;a.textContent!=s&&(a.textContent=s)}for(let[e,t]of w)l.has(e)||(t.remove(),w.delete(e));d.title(O||(D?k?v.locked()?``:`Click to play`:`Joining…`:`Connecting…`),m.map.name??``)};return M=requestAnimationFrame(I),{on:(e,t)=>void f[e].push(t),players:()=>x,destroy(){N||(N=!0,cancelAnimationFrame(M),v.destroy(),_.destroy(),b?.destroy(),P.onopen=P.onclose=P.onmessage=null,P.close(),document.exitPointerLock(),i.remove())}}};export{Ut as tinyFps};
package/dist/local.js CHANGED
@@ -1 +1 @@
1
- var e=65536/(2*Math.PI),t=t=>Math.round(t*e)&65535,n=e=>Math.max(-32768,Math.min(32767,Math.round(e))),r=e=>n(e*1e4),i=e=>e/1e4,a=t=>t/e,o=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:a(t.getUint16(4)),pitch:i(t.getInt16(6)),view:(t.getUint16(8)*256+t.getUint8(10))/256}:null},s=e=>{let n=7+25*e.players.length,i=n+1+14*e.shots.length,a=i+1+16*e.monsters.length,o=a+1+13*e.bullets.length,s=o+1+14*e.events.length,c=new DataView(new ArrayBuffer(s+1+14*e.items.length));return c.setUint8(0,2),c.setUint16(1,e.tick&65535),c.setUint8(3,e.players.length),c.setUint8(4,e.level),c.setUint8(5,+e.hard|(e.phase&1)<<1),c.setUint8(6,e.keys),e.players.forEach((e,n)=>{let i=7+n*25;c.setUint8(i,e.id),c.setFloat32(i+1,e.x),c.setFloat32(i+5,e.y),c.setFloat32(i+9,e.z),c.setFloat32(i+13,e.vy),c.setUint16(i+17,t(e.yaw)),c.setInt16(i+19,r(e.pitch)),c.setUint16(i+21,e.ack&65535),c.setUint8(i+23,+e.ground|e.cool<<1),c.setUint8(i+24,e.hp)}),c.setUint8(n,e.shots.length),e.shots.forEach((e,t)=>{let r=n+1+t*14;c.setUint8(r,e.id),c.setFloat32(r+1,e.x),c.setFloat32(r+5,e.y),c.setFloat32(r+9,e.z),c.setUint8(r+13,e.hit&255)}),c.setUint8(i,e.monsters.length),e.monsters.forEach((e,n)=>{let r=i+1+n*16;c.setUint8(r,e.id),c.setUint8(r+1,e.kind&1|e.chase<<1),c.setFloat32(r+2,e.x),c.setFloat32(r+6,e.y),c.setFloat32(r+10,e.z),c.setUint16(r+14,t(e.yaw))}),c.setUint8(a,e.bullets.length),e.bullets.forEach((e,t)=>{let n=a+1+t*13;c.setUint8(n,e.id),c.setFloat32(n+1,e.x),c.setFloat32(n+5,e.y),c.setFloat32(n+9,e.z)}),c.setUint8(o,e.events.length),e.events.forEach((e,t)=>{let n=o+1+t*14;c.setUint8(n,e.type),c.setUint8(n+1,e.id),c.setFloat32(n+2,e.x),c.setFloat32(n+6,e.y),c.setFloat32(n+10,e.z)}),c.setUint8(s,e.items.length),e.items.forEach((e,t)=>{let n=s+1+t*14;c.setUint8(n,e.id),c.setUint8(n+1,e.kind),c.setFloat32(n+2,e.x),c.setFloat32(n+6,e.y),c.setFloat32(n+10,e.z)}),c.buffer},c=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},l=.4,u=1.8,d=1.6,f=1.55,p=.5,m=.5,h=.02,g=.4,_=1.8,v=2.5,y=.45,b=.9,x=1.2,S=3.5,ee=Math.cos(Math.PI/6),C=.15,te=1.3,ne=.6,w={maxPlayers:16},T={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,FIRE:32},E={WALKER:0,FLYER:1},D={DIE:0,HURT:1,BOOM:2,SWING:3},O={HEALTH:0,KEY_RED:1,KEY_BLUE:2,KEY_YELLOW:3},k={HUNT:0,RETURN:1},A=e=>{let t=(e,t,n,r)=>`${e},${t},${n},${r}`,n=/* @__PURE__ */ new Map;e.sectors.forEach(({pts:e},r)=>e.forEach(([i,a],o)=>n.set(t(i,a,...e[(o+1)%e.length]),r)));let r={map:e,edges:e.sectors.flatMap(({pts:e},r)=>e.map(([i,a],o)=>{let[s,c]=e[(o+1)%e.length];return{ax:i,az:a,bx:s,bz:c,front:r,back:n.get(t(s,c,i,a))??-1}})),barred:/* @__PURE__ */ new Set};return j(r,0,k.HUNT),r},j=({map:e,barred:t},n,r)=>{t.clear(),e.gates?.forEach(e=>n&1<<e.key||t.add(e.sector)),e.exit!==void 0&&r===k.HUNT&&t.add(e.exit)},M=({pts:e},t,n)=>e.every(([r,i],a)=>{let[o,s]=e[(a+1)%e.length];return(o-r)*(n-i)-(s-i)*(t-r)>=0}),N=({map:e},t,n)=>e.sectors.findIndex(e=>M(e,t,n)),P=({map:e,edges:t},[n,r,i],[a,o,s])=>{let[c,l]=[a-n,s-i];return t.some(t=>{let[a,s]=[t.bx-t.ax,t.bz-t.az],u=c*s-l*a;if(!u)return!1;let d=((t.ax-n)*s-(t.az-i)*a)/u,f=((t.ax-n)*l-(t.az-i)*c)/u;if(d<=0||d>=1||f<0||f>1)return!1;if(t.back<0)return!0;let[p,m]=[e.sectors[t.front],e.sectors[t.back]],h=r+d*(o-r);return h<Math.max(p.floor,m.floor)||h>Math.min(p.ceil,m.ceil)})},F=(e,...t)=>t.map(([t,n,r,i,a,o,s,c,l])=>[t,n,r,i,a,o,s,c,l,e]),I=(e,[t,n,r,i],a,o,s,c,l,u)=>Array.from({length:s},(d,f)=>{let[p,m]=e?[n,i]:[t,r],[h,g,_]=[p+f*(m-p)/s,p+(f+1)*(m-p)/s,+(a+f*o).toFixed(1)];return e?[t,h,r,g,_,c,l,u]:[h,n,g,i,_,c,l,u]}),[L,R,z,B]=[O.HEALTH,O.KEY_RED,O.KEY_BLUE,O.KEY_YELLOW],V=Math.PI/4,H=[1,.82,.6],re=[.6,.75,1],U=(e,t,[n,r,i],a,o,s,c,l)=>{let u=t.map(([e,t,n,r])=>[[e,t],[n,t],[n,r],[e,r]]),d=[...new Map(u.flat().map(e=>[`${e}`,e])).values()];return{name:e,sectors:t.map(([,,,,e,t,n=`103`,r,,i],a)=>({pts:u[a].flatMap((e,t,n)=>{let r=n[(t+1)%4],i=t=>(t[0]-e[0])*(r[0]-e[0])+(t[1]-e[1])*(r[1]-e[1]);return[e,...d.filter(t=>(r[0]-e[0])*(t[1]-e[1])===(r[1]-e[1])*(t[0]-e[0])&&i(t)>0&&i(t)<(r[0]-e[0])**2+(r[1]-e[1])**2).sort((e,t)=>i(e)-i(t))]}),floor:e,ceil:t,ft:+n[0],wt:+n[1],ct:+n[2],light:r,tint:i})),spawns:Array.from({length:16},(e,t)=>[n+t%4*2,r+(t>>2)*2,i*V]),monsters:[...a.map(([e,t,n])=>[e,t,n*V,E.WALKER]),...o.map(([e,t,n])=>[e,t,n*V,E.FLYER])],items:s,gates:t.flatMap(([,,,,,,,,e],t)=>e?[{sector:t,key:e}]:[]),goal:c,exit:0,fog:l}},ie=[U(`Warm-up`,[[0,0,10,10,0,4,`103`],[10,4,22,6,0,2.8,`333`,.6],...F([1,.85,.65],[22,0,38,14,0,6,`553`],...I(0,[38,4,42,10],.4,.4,4,6,`553`)),[42,2,52,12,2,6,`103`,.9],...I(1,[46,12,48,22],1.6,-.4,4,4.8,`744`,.7),[38,22,56,36,0,6,`113`]],[2,2,6],[[28,4,3],[34,10,4],[48,6,4],[44,30,0]],[[30,8,0],[52,28,2]],[[26,12,L],[50,10,L],[40,34,L]],[54,34]),U(`Foundry`,[...F([1,.9,.8],[0,14,10,26,0,4,`443`],[10,22,20,24,0,2.8,`744`,.6]),...F([1,.5,.25],[24,8,28,16,0,9,`744`],[20,16,28,30,0,9,`443`],...I(1,[20,8,24,16],2,-.4,5,9,`744`),[28,8,42,18,-1.6,9,`233`,.9],...I(1,[28,18,42,21],-1.2,.4,3,9,`333`),[28,21,50,30,0,9,`744`],[42,8,50,21,0,9,`744`],[20,0,50,8,2.4,9,`744`,.8]),[50,14,51,17,0,3.5,`444`,1,R],...F([.85,.65,.5],[51,8,59,26,0,7,`443`,.6],[59,8,67,26,.4,7,`143`,.8],[57,26,59,36,0,4.8,`744`,.7]),...F([1,.6,.45],[50,36,68,50,0,7,`443`])],[2,16,6],[[46,14,2],[36,26,0],[38,4,2],[56,12,4],[62,20,2],[60,44,0]],[[35,13,0],[60,14,4],[58,42,6]],[[24,26,L],[24,4,L],[64,10,L],[52,46,L],[46,4,R]],[66,48],[.07,.05,.04,.026]),U(`Cistern`,[...F([.45,.9,1],[0,20,10,32,0,4,`363`],[10,26,20,28,0,2.8,`363`,.6],[20,14,56,26,0,11,`363`,.9],[20,26,34,32,0,11,`363`,.9]),...F([.9,.6,.45],[34,26,42,32,-.4,11,`263`]),...F([.45,.9,1],[42,26,56,32,0,11,`363`,.9],[20,32,56,44,0,11,`363`,.9],[36,44,38,54,0,1.9,`000`,.35],[30,54,46,68,0,5,`003`,.7]),[56,28,57,31,0,4,`444`,1,R],...F([.55,.85,1],...I(0,[57,26,65,32],.4,.4,8,10,`333`,.8)),...F([.7,1,.85],[65,22,81,36,3.6,11,`563`]),[71,36,74,37,3.6,7,`444`,1,z],...F([.45,.9,1],[71,37,74,48,3.6,6.4,`363`,.6]),...F([.9,.6,.45],[62,48,82,64,3.6,10,`263`])],[2,22,6],[[30,18,4],[50,20,4],[30,40,0],[50,40,0],[36,60,2],[42,64,0],[76,28,2],[70,58,0]],[[26,24,0],[48,22,0],[36,40,2],[72,56,4]],[[24,40,L],[52,42,L],[44,57,L],[68,34,L],[64,62,L],[38,66,R],[79,24,z]],[80,62],[.04,.11,.1,.034]),U(`Loop`,[...F(H,[0,44,10,56,0,4,`153`],[10,49,20,51,0,2.8,`553`,.6]),[20,30,52,40,0,9,`113`],[20,48,52,58,0,9,`113`,.9],[20,40,32,48,0,9,`113`],[40,40,52,48,0,9,`113`],[20,22,49,30,3.2,9,`743`,.8],...F(H,[34,58,36,66,0,2.8,`553`,.4],[26,66,46,84,0,5,`353`,.5]),[52,42,53,45,0,4,`444`,1,R],...F(H,[53,36,64,54,0,6,`153`,.8],[64,36,70,54,.4,6,`253`,.8]),[60,35,63,36,0,4,`444`,1,z],...F(H,[57,12,77,35,0,8,`053`,.9]),[56,24,57,27,0,4,`444`,1,B],...I(0,[49,22,56,30],2.8,-.4,7,9,`744`,.8),...F(H,[12,24,20,28,3.2,6,`744`,.6],[0,10,12,34,3.2,9,`553`])],[2,46,6],[[30,36,4],[44,36,2],[40,52,0],[40,26,4],[30,74,6],[42,78,2],[56,40,6],[64,50,2],[62,18,4],[72,28,2],[6,22,0]],[[28,48,0],[46,44,4],[36,72,0],[60,45,6],[68,22,4]],[[24,54,L],[24,26,L],[44,80,L],[68,38,L],[74,14,L],[36,82,R],[68,52,z],[74,32,B]],[6,13],[.06,.045,.04,.02]),U(`Citadel`,[...F(re,[0,60,10,72,0,4,`303`],[10,65,24,67,0,2.8,`363`,.6],[24,48,56,84,0,12,`363`],[27,40,31,48,0,3.4,`363`,.4]),...F([.85,.7,.65],[24,16,34,40,0,12,`443`,.9],...I(0,[34,16,40,26],-.4,-.4,3,12,`243`),[34,26,40,30,0,12,`744`],...I(0,[34,30,40,40],-.4,-.4,3,12,`243`),[40,16,60,40,0,12,`443`,.9]),[60,27,61,30,0,4,`444`,1,B],...F([.55,.3,1],[61,10,101,16,0,14,`443`,1],[61,40,101,46,0,14,`443`,1],[61,16,69,40,0,14,`443`,1],[93,16,101,40,0,14,`443`,1],[69,16,93,20,.4,14,`243`,1],[69,36,93,40,.4,14,`243`,1],[69,20,73,36,.4,14,`243`,1],[89,20,93,36,.4,14,`243`,1],[73,20,89,36,.8,14,`744`,1]),[101,26,111,28,0,3.2,`744`,.6],[111,16,131,40,0,8,`163`],[56,66,57,69,0,4,`444`,1,R],...F([1,.5,.45],[57,56,75,80,0,12,`443`,.7],...I(0,[75,60,85,72],.4,.4,5,12,`744`,.8),[85,52,101,80,2.4,12,`543`]),[38,84,42,85,0,4,`444`,1,z],...F([.6,.85,.85],[38,85,42,95,0,1.9,`363`,.35],[28,95,56,115,0,6,`663`,.6])],[2,62,6],[[34,56,4],[50,56,2],[36,76,0],[46,20,4],[54,34,2],[66,60,2],[66,76,0],[92,60,2],[34,100,4],[50,108,2],[70,13,4],[92,13,2],[70,43,0],[92,43,6]],[[30,70,0],[46,68,0],[50,28,0],[76,26,0],[86,30,0],[81,22,0]],[[30,80,L],[56,36,L],[60,78,L],[50,112,L],[64,13,L],[98,43,L],[114,38,L],[52,22,R],[95,66,z],[42,110,B]],[127,36],[.045,.05,.075,.02])],W=1/60,G=Math.PI*2,ae=1e-6,K=.01,q=e=>(e%G+G)%G,J=e=>[-Math.sin(e),-Math.cos(e)],Y=Math.fround,oe=(e,t,n)=>Math.min(Math.max(e,t),n),se=({map:e,barred:t},n,r,i,a)=>{if(n.back<0||t.has(n.back))return!0;let o=e.sectors[n.front],s=e.sectors[n.back],c=Math.min(o.ceil,s.ceil);return s.floor>r+a+K||c-Math.max(o.floor,s.floor)<i-K||c<r+i-K},ce=(e,t,n,r,i)=>{let a=(n-ae)**2;for(let o=0;o<4;o++){let o=0,s=0,c=0;for(let l of t.edges){let u=l.bx-l.ax,d=l.bz-l.az,f=e.x-l.ax,p=e.z-l.az;if(u*p-d*f<0)continue;let m=oe((f*u+p*d)/(u*u+d*d),0,1),h=f-m*u,g=p-m*d,_=h*h+g*g;if(_>=a)continue;let v=Math.sqrt(_);if(n-v<=o||!se(t,l,e.y,r,i))continue;o=n-v;let y=v||Math.hypot(u,d);s=(v?h:-d)/y*o,c=(v?g:u)/y*o}if(!o)return;e.x+=s,e.z+=c}},le=(e,t,n,r,i,a,o)=>{let{map:s,edges:c}=e,l=Math.max(N(e,t,n),0),{floor:u,ceil:d}=s.sectors[l],f=(i-ae)**2;for(let i of c){if(i.front!==l||i.back<0)continue;let c=i.bx-i.ax,p=i.bz-i.az,m=t-i.ax,h=n-i.az,g=oe((m*c+h*p)/(c*c+p*p),0,1);if((m-g*c)**2+(h-g*p)**2<f&&!se(e,i,r,a,o)){let e=s.sectors[i.back];u=Math.max(u,e.floor),d=Math.min(d,e.ceil)}}return[u,d]},X=(e,t,n,r,i)=>{e.x+=t,e.z+=n,ce(e,i,l,u,p);let[a,o]=le(i,e.x,e.z,e.y,l,u,p);e.ground&&r&&(e.vy=7);let s=e.vy-20*W;e.y+=(e.vy+s)/2*W,e.vy=s,e.ground=!1,e.y+1.8>o&&(e.y=o-u,e.vy=Math.min(e.vy,0)),(e.vy<=0?e.y<=a+K:e.y<a)&&(e.y=a,e.vy<=0&&(e.vy=0,e.ground=!0)),e.x=Y(e.x),e.y=Y(e.y),e.z=Y(e.z),e.vy=Y(e.vy)},ue=(e,t,n,r,i)=>{e.x+=t,e.z+=r,ce(e,i,y,b,0);let[a,o]=le(i,e.x,e.z,e.y,y,b,0),s=Math.min(a+x,o-b),c=Math.max(a,Math.min(s,e.y+S*W));e.y=Math.min(Math.max(e.y+n,c),o-b),e.x=Y(e.x),e.y=Y(e.y),e.z=Y(e.z)},de=(e,t,n)=>{let r=(t.keys&T.FIRE)!==0;e.cool=Math.max(0,e.cool-1),e.yaw=q(t.yaw),e.pitch=Math.max(-f,Math.min(f,t.pitch));let i=(t.keys&T.FORWARD?1:0)-(t.keys&T.BACK?1:0),a=(t.keys&T.RIGHT?1:0)-(t.keys&T.LEFT?1:0),o=6*W*(r?m:1)/(Math.hypot(i,a)||1),[s,c]=J(e.yaw);return X(e,(s*i-c*a)*o,(c*i+s*a)*o,(t.keys&T.JUMP)!==0,n),r&&!e.cool?(e.cool=5,!0):!1},fe=(e,t,n)=>{let{spawns:r,sectors:i}=t.map,[a,o,s]=r[(n%r.length+r.length)%r.length],c=i[Math.max(N(t,a,o),0)].floor;return{id:e,x:Y(a),y:Y(c),z:Y(o),vy:0,yaw:q(s),pitch:0,ground:!0,cool:0}},pe=e=>{for(let t=0;t<2;t++)e=Math.imul(e^e>>>16,73244475);return(e^e>>>16)>>>0},me=(e,t,n)=>{let[r,i,a,o]=[Math.sin(e),Math.cos(e),Math.sin(t),Math.cos(t)],s=pe(n+1),c=(s&65535)/65536*G,l=(s>>>16)/65535,[u,d]=[Math.cos(c)*l*h,Math.sin(c)*l*h],f=[-r*o+i*u+r*a*d,a+o*d,-i*o-r*u+i*a*d],p=Math.hypot(...f);return[f[0]/p,f[1]/p,f[2]/p]},he=(e,t,n,r)=>{let{map:i,edges:a}=e,o=Math.max(N(e,t[0],t[2]),0),s=0;for(let e=0;e<=i.sectors.length;e++){let{floor:e,ceil:c}=i.sectors[o],l=1/0,u;for(let e of a){if(e.front!==o)continue;let[r,i]=[e.bx-e.ax,e.bz-e.az],a=n[2]*r-n[0]*i;if(a>=0)continue;let c=Math.max(((t[2]-e.az)*r-(t[0]-e.ax)*i)/-a,s),d=((t[0]+c*n[0]-e.ax)*r+(t[2]+c*n[2]-e.az)*i)/(r*r+i*i);d>-1e-9&&d<1+1e-9&&(c<l-1e-9||c<l+1e-9&&e.back<0)&&([l,u]=[c,e])}let d=n[1]<0?(e-t[1])/n[1]:n[1]>0?(c-t[1])/n[1]:1/0;if(d<=l||!u)return Math.min(Math.max(d,s),r);if(l>=r)return r;let f=t[1]+l*n[1],p=u.back<0?void 0:i.sectors[u.back];if(!p||f<Math.max(e,p.floor)||f>Math.min(c,p.ceil))return l;[o,s]=[u.back,l]}return s},ge=(e,t,n)=>{let[r,i]=[e[0]-n.x,e[2]-n.z],a=t[0]*t[0]+t[2]*t[2],o=r*t[0]+i*t[2],s=r*r+i*i-n.r*n.r,[c,l]=[0,1/0];if(a>1e-12){let e=o*o-a*s;if(e<0)return 1/0;[c,l]=[Math.max(0,(-o-Math.sqrt(e))/a),(-o+Math.sqrt(e))/a]}else if(s>0)return 1/0;let[u,d]=[n.y-e[1],n.y+n.h-e[1]];if(t[1]){let[e,n]=[u/t[1],d/t[1]];c=Math.max(c,Math.min(e,n)),l=Math.min(l,Math.max(e,n))}else if(u>0||d<0)return 1/0;return c<=l?c:1/0},_e=({id:e,x:t,y:n,z:r})=>({id:e,x:t,y:n,z:r,r:l,h:u}),Z=({id:e,kind:t,x:n,y:r,z:i})=>{let a=t===E.WALKER;return{id:e,x:n,y:r,z:i,r:a?g:y,h:a?_:b}},ve=(e,t,n,r)=>{let i=[t.x,t.y+d,t.z],a=me(t.yaw,t.pitch,n),o=he(e,i,a,100),s=-1;for(let e of r){let n=e.id===t.id?1/0:ge(i,a,e);n<o&&([o,s]=[n,e.id])}return{id:t.id,x:i[0]+a[0]*o,y:i[1]+a[1]*o,z:i[2]+a[2]*o,hit:s}},Q=1/60,ye=.05,be=.4,$=1,xe=15,Se=1.2,Ce=255,we=e=>{let t=e|0;return()=>{t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}},Te=(e,t,n=!1)=>{let r=(e.map.monsters??[]).slice(0,64),[i,a]=n?[te,ne]:[1,1],[o,s]=[v*i,S*i],[c,f]=[90,45].map(e=>Math.round(e*a)),m=[],h=[],g=0,_=0,y=r.map(([n,r,i,a],o)=>{let{floor:s,ceil:l}=e.map.sectors[Math.max(N(e,n,r),0)],u=a===E.FLYER;return{id:16+o,kind:a,x:Math.fround(n),y:Math.fround(u?Math.min(s+x,l-b):s),z:Math.fround(r),yaw:q(i),chase:!1,vy:0,ground:!0,target:-1,turn:Math.floor(t()*240),melee:0,swing:0,shoot:Math.floor(t()*c)}}),w=e=>e.y+Z(e).h/2,T=e=>[e.x,e.kind===E.WALKER?e.y+d:w(e),e.z],O=e=>[e.x,e.y+d,e.z],k=(e,t)=>{e.target=t,e.chase=t>=0},A=(t,n)=>{for(let r of y)r!==t&&!r.chase&&Math.hypot(r.x-t.x,r.z-t.z)<12&&!P(e,T(t),T(r))&&k(r,n)},j=(t,n)=>{let[r,i]=J(t.yaw),a,o=1/0;for(let s of n){let[n,c]=[s.x-t.x,s.z-t.z],l=Math.hypot(n,c);l<=30&&l<o&&n*r+c*i>=ee*l&&!P(e,T(t),O(s))&&([a,o]=[s,l])}if(a){let e=!t.chase;k(t,a.id),e&&A(t,a.id)}},M=(e,t)=>{let n=((t-e.yaw+Math.PI)%G+G)%G-Math.PI;e.yaw=q(e.yaw+Math.max(-.05,Math.min(ye,n)))},F=(t,n)=>e.map.sectors[Math.max(N(e,t.x,t.z),0)].floor<n-p,I=n=>{let r=(n.kind===E.WALKER?o:s)*be*Q,[i,a]=J(n.yaw),c={x:n.x,y:n.y,z:n.z,vy:n.vy,ground:n.ground};n.kind===E.WALKER?X(n,i*r,a*r,!1,e):ue(n,i*r,-r,a*r,e);let l=n.kind===E.WALKER&&F(n,c.y);l||Math.hypot(n.x-c.x,n.z-c.z)<r/2?(l&&Object.assign(n,c),n.yaw=q(n.yaw+t()*G)):--n.turn<=0&&(n.turn=120+Math.floor(t()*240),n.yaw=q(n.yaw+(t()-.5)*Math.PI))},L=(n,r)=>{let[i,a,o]=T(n);if(m.length>=Ce||P(e,[i,a,o],O(r))){n.shoot=0;return}let s=[r.x-i,r.y+Se-a,r.z-o],l=12*Q/Math.hypot(...s);m.push({id:_++&255,x:i,y:a,z:o,vx:s[0]*l,vy:s[1]*l,vz:s[2]*l,life:300}),n.shoot=c+Math.floor((t()-.5)*20)},R=(t,n)=>{let[r,i]=[n.x-t.x,n.z-t.z],a=Math.hypot(r,i);if(a>1e-6&&M(t,Math.atan2(-r,-i)),t.kind===E.WALKER){let[n,r]=J(t.yaw),i=a>$?o*Q:0;X(t,n*i,r*i,!1,e)}else{let o=n.y+Se-b/2-t.y,c=Math.min(1,s*Q/(Math.hypot(a,o)||1));ue(t,a>$?r*c:0,o*c,a>$?i*c:0,e)}let c=Math.hypot(n.x-t.x,n.z-t.z)<=1.4&&t.y<n.y+1.8&&n.y<t.y+Z(t).h;if(t.melee=Math.max(0,t.melee-1),t.swing&&!--t.swing&&c){let[e,r]=J(t.yaw);(n.x-t.x)*e+(n.z-t.z)*r>0&&h.push({type:D.HURT,id:n.id,x:n.x,y:n.y+Se,z:n.z})}c&&!t.melee&&(h.push({type:D.SWING,id:t.id,x:t.x,y:w(t),z:t.z}),[t.melee,t.swing]=[f,xe]),t.kind===E.WALKER&&t.shoot--<=0&&a<=30&&L(t,n)},z=(t,n)=>{let r=Math.hypot(t.vx,t.vy,t.vz),i=[t.x,t.y,t.z],a=[t.vx/r,t.vy/r,t.vz/r],o=he(e,i,a,r),s=-1;for(let e of n){let t=ge(i,a,{id:e.id,x:e.x,y:e.y-C,z:e.z,r:l+C,h:u+2*C});t<o&&([o,s]=[t,e.id])}return[t.x,t.y,t.z]=[i[0]+a[0]*o,i[1]+a[1]*o,i[2]+a[2]*o],s>=0?h.push({type:D.HURT,id:s,x:t.x,y:t.y,z:t.z}):o<r&&h.push({type:D.BOOM,id:t.id,x:t.x,y:t.y,z:t.z}),s<0&&o>=r&&--t.life>0};return{monsters:()=>y.map(({id:e,kind:t,x:n,y:r,z:i,yaw:a,chase:o})=>({id:e,kind:t,x:n,y:r,z:i,yaw:a,chase:o})),bullets:()=>m.map(({id:e,x:t,y:n,z:r})=>({id:e,x:t,y:n,z:r})),events:h,step:e=>{g++;for(let t of y){(g+t.id)%60==0&&j(t,e);let n=e.find(e=>e.id===t.target);t.chase&&!n&&k(t,-1),n?R(t,n):I(t)}m=m.filter(t=>z(t,e))},kill:(e,t)=>{let n=y.findIndex(t=>t.id===e);if(n<0)return;let[r]=y.splice(n,1);return h.push({type:D.DIE,id:e,x:r.x,y:w(r),z:r.z}),A(r,t),r}}},Ee=20,De=.5,Oe=2,ke=[`#e6194b`,`#3cb44b`,`#ffe119`,`#4363d8`,`#f58231`,`#911eb4`,`#42d4f4`,`#f032e6`,`#bfef45`,`#fabed4`,`#469990`,`#dcbeff`,`#9a6324`,`#800000`,`#aaffc3`,`#808000`],Ae=(e,t)=>Array.from(e).slice(0,t).join(``).trim(),je=e=>Ae((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=`${Ae(e,15-`${r}`.length)} ${r}`;return n},Ne=(e,t,n,r,i)=>Math.hypot(e.x-t,e.z-r)<=i&&e.y<n+De&&n<e.y+1.8,Pe=(e,t)=>{let n=setInterval(e,t);return()=>clearInterval(n)},Fe=class{peers=/* @__PURE__ */ new Map;ticks=0;history=[];maps;lvl;horde;rand;level=0;hard=!1;phase=k.HUNT;keys=0;items=[];nextItem=0;kills=0;runStart=0;shots=[];halt;rules;rr=0;constructor(e={},t=Date.now(),n=ie){this.rules={...w,...e},this.rand=we(t),this.maps=n.map(A),this.load(0)}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=c(t);n===null&&r?.t===`join`&&this.join(e,r.name);return}let r=n&&o(t);if(r&&n.bank>0){if(n.bank--,n.hp&&de(n.state,r,this.lvl)){let e=ve(this.lvl,n.state,r.seq,this.rewind(n,r.view));if(this.shots.push(e),e.hit>=16){let t=this.horde.kill(e.hit,n.state.id);t&&n.kills++,t&&++this.kills%4==0&&this.drop(O.HEALTH,t.x,t.z)}}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 n of e)n.bank=Math.min(10,n.bank+1),!n.hp&&t-n.hurt>=180&&(n.hp=9,n.state=this.place(n.info.id,e.filter(e=>e.hp&&e!==n).map(e=>e.state)));let{events:n}=this.horde,r=n.length;if(this.horde.step(e.filter(e=>e.hp).map(e=>e.state)),n.push(...n.splice(r).filter(e=>e.type!==D.HURT||this.wound(e.id,t))),this.progress(e.filter(e=>e.hp)),t%2==0){let n=this.horde.monsters();for(this.history.push({tick:t,players:e.map(e=>({...e.state})),monsters:n});this.history[0].tick<t-30;)this.history.shift();let r=s({tick:t,players:e.map(e=>({...e.state,ack:e.ack,hp:e.hp})),shots:this.shots,monsters:n,bullets:this.horde.bullets(),events:this.horde.events.splice(0,255),level:this.level,hard:this.hard,phase:this.phase,keys:this.keys,items:this.items});this.shots=[],e.forEach(e=>e.conn.send(r))}}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<Ee;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!==e&&t.hp).map(e=>e.state),r=this.horde.monsters(),[i,a]=[this.history[0],this.history.at(-1)];if(!i||!a)return[...n.map(_e),...r.map(Z)];let o=((this.ticks-t+32768)%65536+65536)%65536-32768,s=Math.min(Math.max(this.ticks-o,i.tick),a.tick),c=0;for(;c+1<this.history.length&&this.history[c+1].tick<=s;)c++;let[l,u]=[this.history[c],this.history[c+1]??this.history[c]],d=u.tick>l.tick?(s-l.tick)/(u.tick-l.tick):0,f=(e,t)=>e+(t-e)*d,p=(e,t)=>e.map(e=>{let n=t(l).find(t=>t.id===e.id),r=t(u).find(t=>t.id===e.id);return n&&r?{...r,x:f(n.x,r.x),y:f(n.y,r.y),z:f(n.z,r.z)}:r??n??e});return[...p(n,e=>e.players).map(_e),...p(r,e=>e.monsters).map(Z)]}load(e){this.level=e,this.lvl=this.maps[e],this.keys=0,this.phase=k.HUNT,j(this.lvl,0,k.HUNT),this.horde=Te(this.lvl,this.rand,this.hard),this.items=[],this.nextItem=0,this.kills=0,this.lvl.map.items?.forEach(([e,t,n])=>this.drop(n,e,t)),this.shots=[],this.history=[];let t=[];for(let e of this.players())e.hp=9,e.state=this.place(e.info.id,t),t.push(e.state)}place(e,t){let n=this.lvl.map.spawns.findIndex((n,r)=>{let{x:i,z:a}=fe(e,this.lvl,r);return!t.some(e=>Math.hypot(e.x-i,e.z-a)<Oe)});return fe(e,this.lvl,n<0?this.rr++:n)}floor(e,t){return this.lvl.map.sectors[Math.max(N(this.lvl,e,t),0)].floor}drop(e,t,n){let r=Math.fround;this.items.push({id:this.nextItem++,kind:e,x:r(t),y:r(this.floor(t,n)),z:r(n)})}wound(e,t){let n=this.players().find(t=>t.info.id===e);return!n?.hp||t-n.hurt<60?!1:([n.hp,n.hurt]=[n.hp-1,t],n.deaths+=+!n.hp,!0)}progress(e){let{sectors:t,goal:n,exit:r}=this.lvl.map,i=!1;if(this.items=this.items.filter(t=>{let n=e.find(e=>Ne(e.state,t.x,t.y,t.z,.8)&&(t.kind!==O.HEALTH||e.hp<9));return n&&t.kind===O.HEALTH?n.hp=Math.min(9,n.hp+3):n&&(this.keys|=1<<t.kind,i=!0),!n}),this.phase===k.HUNT)n&&e.some(e=>Ne(e.state,n[0],this.floor(...n),n[1],1))&&(this.phase=k.RETURN,i=!0);else if(r!==void 0&&e.length&&e.every(e=>M(t[r],e.state.x,e.state.z)))return this.win();i&&j(this.lvl,this.keys,this.phase)}win(){if(this.level+1<this.maps.length){this.load(this.level+1);return}let e=JSON.stringify({t:`end`,ticks:this.ticks-this.runStart,hard:this.hard,stats:this.players().map(e=>({id:e.info.id,kills:e.kills,deaths:e.deaths}))});this.players().forEach(t=>t.conn.send(e)),this.players().forEach(e=>e.kills=e.deaths=0),[this.hard,this.runStart]=[!0,this.ticks],this.load(0)}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=ke.find(e=>!n.some(t=>t.info.color===e))??ke[r%ke.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.filter(e=>e.hp).map(e=>e.state)),bank:10,ack:65535,hp:9,hurt:-60,kills:0,deaths:0};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,l,u,d,f=[],p,m=!1,h=e=>i.postMessage({from:r,...e}),g=e=>!m&&S.onmessage?.({data:e}),_={send:e=>queueMicrotask(()=>g(e))},v=()=>{let e=f.length?f:p?[p]:[];return f=[],e},y=e=>{if(m)return e();u=e,d=r,l=/* @__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&&l){let{from:t,kind:n}=e,r=l.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})},l.set(t,r),s.connect(r)),s.receive(r,e.data)):n===`b`&&r&&(l.delete(t),s.disconnect(r))}else e.to!==r&&e.to||(e.kind===`m`&&e.to?g(e.data):e.kind===`h`&&e.from!==d&&(d=e.from,v().forEach(e=>h({kind:`m`,data:e}))))}};let b=e=>{m||(typeof e==`string`&&c(e)?.t===`join`&&(p=e),s?s.receive(_,e):d?h({kind:`m`,data:e}):f.push(e))},x=()=>{m||(m=!0,globalThis.removeEventListener?.(`pagehide`,x),s?(s.stop(),u()):(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};
1
+ var e=65536/(2*Math.PI),t=t=>Math.round(t*e)&65535,n=e=>Math.max(-32768,Math.min(32767,Math.round(e))),r=e=>n(e*1e4),i=e=>e/1e4,a=t=>t/e,o=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:a(t.getUint16(4)),pitch:i(t.getInt16(6)),view:(t.getUint16(8)*256+t.getUint8(10))/256}:null},s=e=>{let n=/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(4+24*e.players.length));return n.setUint8(0,2),n.setUint16(1,e.tick&65535),n.setUint8(3,e.players.length),e.players.forEach((e,i)=>{let a=4+i*24;n.setUint8(a,e.id),n.setFloat32(a+1,e.x),n.setFloat32(a+5,e.y),n.setFloat32(a+9,e.z),n.setFloat32(a+13,e.vy),n.setUint16(a+17,t(e.yaw)),n.setInt16(a+19,r(e.pitch)),n.setUint16(a+21,e.ack&65535),n.setUint8(a+23,+e.ground)}),n.buffer},c=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},l=.4,u=1.8,d=1.55,f=.5,p={maxPlayers:16},m=e=>{let t=(e,t,n,r)=>`${e},${t},${n},${r}`,n=/* @__PURE__ */ new Map;return e.sectors.forEach(({pts:e},r)=>e.forEach(([i,a],o)=>n.set(t(i,a,...e[(o+1)%e.length]),r))),{map:e,edges:e.sectors.flatMap(({pts:e},r)=>e.map(([i,a],o)=>{let[s,c]=e[(o+1)%e.length];return{ax:i,az:a,bx:s,bz:c,front:r,back:n.get(t(s,c,i,a))??-1}}))}},h=({pts:e},t,n)=>e.every(([r,i],a)=>{let[o,s]=e[(a+1)%e.length];return(o-r)*(n-i)-(s-i)*(t-r)>=0}),g=({map:e},t,n)=>e.sectors.findIndex(e=>h(e,t,n)),_={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16},v={BRICK:0,TILE:1,LAVA:2,STONE:3,METAL:4,WOOD:5,MOSS:6,GRATE:7},y=(e,t,n,r,i)=>({pts:e,floor:t,ceil:n,ft:r,wt:v.BRICK,ct:v.STONE,light:i});y([[0,0],[16,0],[16,6],[16,10],[16,16],[0,16]],1,5,v.TILE),y([[16,6],[20,6],[20,10],[16,10]],1,3.5,v.TILE,.6),y([[20,0],[36,0],[36,6],[30,6],[26,6],[20,6]],1,7,v.TILE),y([[20,6],[26,6],[26,10],[20,10]],1,7,v.TILE),y([[30,6],[36,6],[36,10],[30,10]],1,7,v.TILE),y([[20,10],[26,10],[30,10],[36,10],[36,16],[32,16],[28,16],[20,16]],1,7,v.TILE),y([[26,6],[30,6],[30,10],[26,10]],0,7,v.LAVA),y([[28,16],[32,16],[32,17],[28,17]],1.4,7,v.STONE),y([[28,17],[32,17],[32,18],[28,18]],1.8,7,v.STONE),y([[28,18],[32,18],[32,19],[28,19]],2.2,7,v.STONE),y([[24,19],[28,19],[32,19],[36,19],[36,26],[24,26]],2.6,7,v.TILE,.8);var b=[0,1.2,7,9,14,17,23,26,27,31,38.8,40],x=[0,1.2,8,9,10,11,16,18,24,26,38.8,40],S=120,C=[[0,0,40,40,1,v.STONE],[1.2,1.2,38.8,38.8,0,v.TILE],[14,1.2,26,8,1.6,v.TILE],[17,8,23,9,1.2,v.STONE],[17,9,23,10,.8,v.STONE],[17,10,23,11,.4,v.STONE],[7,16,9,18,1,v.WOOD],[27,24,31,26,2,v.METAL]],w={name:`Rooftops`,fog:[.8,.88,1,.02],sectors:b.slice(1).flatMap((e,t)=>x.slice(1).map((n,r)=>{let[i,a]=[b[t],x[r]],[o,s]=[(i+e)/2,(a+n)/2],[,,,,c,l]=C.filter(([e,t,n,r])=>e<o&&o<n&&t<s&&s<r).at(-1);return y([[i,a],[e,a],[e,n],[i,n]],c,S,l)})),spawns:[[6,34,0],[13,34,0],[20,34,0],[27,34,0],[34,34,0],[20,22,0]]},T=1/60,E=Math.PI*2,D=1e-6,O=.01,k=e=>(e%E+E)%E,A=e=>[-Math.sin(e),-Math.cos(e)],j=Math.fround,M=(e,t,n)=>Math.min(Math.max(e,t),n),N=({map:e},t,n,r,i)=>{if(t.back<0)return!0;let a=e.sectors[t.front],o=e.sectors[t.back],s=Math.min(a.ceil,o.ceil);return o.floor>n+i+O||s-Math.max(a.floor,o.floor)<r-O||s<n+r-O},P=(e,t,n,r,i)=>{let a=(n-D)**2;for(let o=0;o<4;o++){let o=0,s=0,c=0;for(let l of t.edges){let u=l.bx-l.ax,d=l.bz-l.az,f=e.x-l.ax,p=e.z-l.az;if(u*p-d*f<0)continue;let m=M((f*u+p*d)/(u*u+d*d),0,1),h=f-m*u,g=p-m*d,_=h*h+g*g;if(_>=a)continue;let v=Math.sqrt(_);if(n-v<=o||!N(t,l,e.y,r,i))continue;o=n-v;let y=v||Math.hypot(u,d);s=(v?h:-d)/y*o,c=(v?g:u)/y*o}if(!o)return;e.x+=s,e.z+=c}},F=(e,t,n,r,i,a,o)=>{let{map:s,edges:c}=e,l=Math.max(g(e,t,n),0),{floor:u,ceil:d}=s.sectors[l],f=(i-D)**2;for(let i of c){if(i.front!==l||i.back<0)continue;let c=i.bx-i.ax,p=i.bz-i.az,m=t-i.ax,h=n-i.az,g=M((m*c+h*p)/(c*c+p*p),0,1);if((m-g*c)**2+(h-g*p)**2<f&&!N(e,i,r,a,o)){let e=s.sectors[i.back];u=Math.max(u,e.floor),d=Math.min(d,e.ceil)}}return[u,d]},I=(e,t,n,r,i)=>{e.x+=t,e.z+=n,P(e,i,l,u,f);let[a,o]=F(i,e.x,e.z,e.y,l,u,f);e.ground&&r&&(e.vy=7);let s=e.vy-20*T;e.y+=(e.vy+s)/2*T,e.vy=s,e.ground=!1,e.y+1.8>o&&(e.y=o-u,e.vy=Math.min(e.vy,0)),(e.vy<=0?e.y<=a+O:e.y<a)&&(e.y=a,e.vy<=0&&(e.vy=0,e.ground=!0)),e.x=j(e.x),e.y=j(e.y),e.z=j(e.z),e.vy=j(e.vy)},L=(e,t,n)=>{e.yaw=k(t.yaw),e.pitch=Math.max(-d,Math.min(d,t.pitch));let r=(t.keys&_.FORWARD?1:0)-(t.keys&_.BACK?1:0),i=(t.keys&_.RIGHT?1:0)-(t.keys&_.LEFT?1:0),a=6*T/(Math.hypot(r,i)||1),[o,s]=A(e.yaw);I(e,(o*r-s*i)*a,(s*r+o*i)*a,(t.keys&_.JUMP)!==0,n)},R=(e,t,n)=>{let{spawns:r,sectors:i}=t.map,[a,o,s]=r[(n%r.length+r.length)%r.length],c=i[Math.max(g(t,a,o),0)].floor;return{id:e,x:j(a),y:j(c),z:j(o),vy:0,yaw:k(s),pitch:0,ground:!0}},z=20,B=2,V=[`#e6194b`,`#3cb44b`,`#ffe119`,`#4363d8`,`#f58231`,`#911eb4`,`#42d4f4`,`#f032e6`,`#bfef45`,`#fabed4`,`#469990`,`#dcbeff`,`#9a6324`,`#800000`,`#aaffc3`,`#808000`],H=(e,t)=>Array.from(e).slice(0,t).join(``).trim(),U=e=>H((typeof e==`string`?e:``).replace(/\s+/g,` `).replace(/\p{Cc}/gu,``).trim(),16),W=(e,t)=>{let n=e;for(let r=2;t.includes(n);r++)n=`${H(e,15-`${r}`.length)} ${r}`;return n},G=(e,t)=>{let n=setInterval(e,t);return()=>clearInterval(n)},K=class{peers=/* @__PURE__ */ new Map;ticks=0;history=[];lvl;halt;rules;rr=0;constructor(e={},t=w){this.rules={...p,...e},this.lvl=m(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=c(t);n===null&&r?.t===`join`&&this.join(e,r.name);return}let r=n&&o(t);r&&n.bank>0&&(n.bank--,L(n.state,r,this.lvl),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=s({tick:t,players:e.map(e=>({...e.state,ack:e.ack}))});e.forEach(e=>e.conn.send(n))}}start(e=G){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<z;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.lvl.map.spawns.findIndex((n,r)=>{let{x:i,z:a}=R(e,this.lvl,r);return!t.some(e=>Math.hypot(e.x-i,e.z-a)<B)});return R(e,this.lvl,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=V.find(e=>!n.some(t=>t.info.color===e))??V[r%V.length],a={conn:e,info:{id:r,name:W(U(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})))}},q=(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()},J=(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,l,u,d,f=[],p,m=!1,h=e=>i.postMessage({from:r,...e}),g=e=>!m&&S.onmessage?.({data:e}),_={send:e=>queueMicrotask(()=>g(e))},v=()=>{let e=f.length?f:p?[p]:[];return f=[],e},y=e=>{if(m)return e();u=e,d=r,l=/* @__PURE__ */ new Map,s=new K(t),s.start(q),s.connect(_),v().forEach(e=>s.receive(_,e)),h({kind:`h`})};i.onmessage=({data:e})=>{if(!m){if(s&&l){let{from:t,kind:n}=e,r=l.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})},l.set(t,r),s.connect(r)),s.receive(r,e.data)):n===`b`&&r&&(l.delete(t),s.disconnect(r))}else e.to!==r&&e.to||(e.kind===`m`&&e.to?g(e.data):e.kind===`h`&&e.from!==d&&(d=e.from,v().forEach(e=>h({kind:`m`,data:e}))))}};let b=e=>{m||(typeof e==`string`&&c(e)?.t===`join`&&(p=e),s?s.receive(_,e):d?h({kind:`m`,data:e}):f.push(e))},x=()=>{m||(m=!0,globalThis.removeEventListener?.(`pagehide`,x),s?(s.stop(),u()):(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{J as localSocket};