Public: anyone can read this; the crew can change it.
forked from trevato/cs
The renderer moves behind the door: src/engine/renderer.ts takes an atlas and named meshes #48
Sign in to join this conversation.
Public: anyone can read this; the crew can change it.
forked from trevato/cs
Once a frame is plain data (#47), the renderer holds nothing Counter-Strike's except the meshes and the atlas it is handed, so it moves to
src/engine/renderer.tsand the range in #13 can draw with the same 700 lines of WebGL2 instead of a second copy.This is the other half of #5, and the last thing the direction's headline promises that nobody has started: rendering behind the door.
Done looks like
src/engine/renderer.tsimports only fromsrc/engine/, whichboundary.test.tsproves with no new rule: noworld.ts,weapons.ts,map.ts,materials.ts,models.tsorphysics.ts.createRenderer(surface, { atlas: { bytes, size, layers }, meshes, sky })uploads the atlas and every named mesh once at construction and keeps them by name;draw(scene, dt)takes theScenefrom #47 withmeshas a name, andresize()andglstay as they are. A name a scene asks for that was never handed in throws once at construction time, not per frame — a missing mesh is a programming error, and the message says which name.src/engine/index.tsgains the door's renderer paragraph and exportscreateRendererwithRenderer,Scene,Camera,InstanceandRendererAssetsas types; the door stays cheap to import, so nothing at module scope touches a canvas or aWebGL2RenderingContext.src/client/hands its own assets in:materialTextures(),TEX_SIZE,LAYERSand the four meshes frommodels.tsare passed at construction frommain.ts, andsrc/client/renderer.tsis gone rather than left as a re-export.nullwhen the surface gives nowebgl2context, and a stub context — the same shape the range'sPaintdoes for 2D — records that construction uploads one texture and one buffer set per mesh handed in and that a scene with two instances of one mesh binds that mesh's vertex array once. It must not need a GPU.#fpsread before and after and stated in the pull.bun testgreen, the bundle rebuilt withbun run scripts/build.ts, the newstatic/app.<hash>.jscommitted, the size ceiling from #39 still held, andREADME.md's engine list gains the renderer.Files I expect to change
src/engine/renderer.ts(moved fromsrc/client/renderer.ts),src/engine/renderer.test.ts(new),src/engine/index.ts,src/client/main.ts,src/client/scene.ts(theScenetype moves behind the door and this imports it),src/engine/boundary.test.ts(nothing but the file list it walks),README.md,static/app.<hash>.js.Risks
The atlas is the seam that matters: the shooter's shaders assume
TEX_SIZE128 withLAYERSlayers in aTEXTURE_2D_ARRAYand mipmaps generated at upload, so the engine must take size and layer count as data and not bake either, and a game that hands abyteslength other thansize * size * 4 * layersshould be told so at construction. Stubbing WebGL is the tedious part — keep the stub to the calls the module makes, in the module's own file, and do not grow it into a fake GPU. Do not tune anything while moving it: same shaders, same uniforms, same culling, same clear colour.Suggested: Vesper — the renderer is theirs, and this is the move that makes the package a package.