rook/val Public Public: anyone can read this; nobody can change it.
forked from benjivers/val
workbenchthis machine
Files 4990f87c0167ca7cfa9c9a4a67fa43bcfef26454
| 1 | import { drawScene, makeScene } from "../static/scene.js"; |
| 2 | import { gridRows, TILE } from "../src/map.ts"; |
| 3 | const rows = gridRows(); |
| 4 | const solid = (c:number,r:number)=> c<0||r<0||r>=rows.length||c>=rows[0]!.length||rows[r]![c]==="#"; |
| 5 | const world = { solid, tile: TILE }; |
| 6 | const me:any = {id:"me",x:0,y:0,angle:0,alive:true,side:"atk",hp:100,blind:0,ammo:25,reloading:false,planting:0,spike:false,agent:"ember"}; |
| 7 | function ctxOf(){ const c:any={ops:0,fills:0,clips:0}; const noop=()=>{}; |
| 8 | return new Proxy(c,{get(t,p:string){ if(p in t) return t[p]; |
| 9 | if(p==="measureText") return (s:string)=>({width:s.length*6}); |
| 10 | if(p==="createLinearGradient") return ()=>({addColorStop:noop}); |
| 11 | return ()=>{ t.ops++; if(p==="fillRect") t.fills++; if(p==="clip") t.clips++; };},set:(t,p,v)=>{t[p]=v;return true;}}); |
| 12 | } |
| 13 | const spots:[number,number][]=[]; |
| 14 | for (let r=1;r<rows.length-1;r++) for(let c=1;c<rows[0]!.length-1;c++) |
| 15 | if(rows[r]![c]!=="#") spots.push([c*TILE+TILE/2, r*TILE+TILE/2]); |
| 16 | const open = spots.filter((_,i)=>i%5===0); |
| 17 | function run(W:number, bodies:number, marks:number){ |
| 18 | const H = Math.round(W*570/900); |
| 19 | const scene = makeScene(); |
| 20 | const ctx:any = ctxOf(); |
| 21 | let frames=0; |
| 22 | for (const [x,y] of open) for (let a=0;a<4;a++){ |
| 23 | const players = Array.from({length:bodies},(_,i)=>({id:"b"+i,name:"Bot",agent:"sable", |
| 24 | x:x+Math.cos(a+i)*140, y:y+Math.sin(a+i)*140, angle:0, hp:90, alive:true, mate:i%2===0, spike:false, blind:false})); |
| 25 | const mark = Array.from({length:marks},(_,i)=>({id:"m"+i,x:x+Math.cos(a+i)*180,y:y+Math.sin(a+i)*180,angle:0,mate:false,fade:0.6})); |
| 26 | drawScene(ctx, scene, world, {x,y,angle:a}, |
| 27 | {phase:"live",clock:40,result:null,me,players,zones:[],orbs:[],shots:[],spike:{planted:false,carried:false,fuse:0,defuse:0,x:null,y:null}} as any, |
| 28 | {width:W,height:H,look:(p:any)=>p, shown:()=>1, marks:mark}); |
| 29 | frames++; |
| 30 | } |
| 31 | console.log(`W=${String(W).padEnd(5)} bodies=${bodies} marks=${marks} ops/frame=${(ctx.ops/frames).toFixed(0).padEnd(5)} fills=${(ctx.fills/frames).toFixed(0).padEnd(5)} clips=${(ctx.clips/frames).toFixed(1)}`); |
| 32 | } |
| 33 | run(1280,0,0); run(1280,4,0); run(1280,9,3); |
| 34 | run(960,0,0); run(960,4,0); run(960,9,3); |