gnikoloff / wasm-snake

Classic Snake in direct WebAssembly

Home Page:https://gnikoloff.github.io/wasm-snake/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Classic Snake in WebAssembly

Snake preview

Snake written in WebAssembly Text (WAT) format and compiled to WASM bytecode.

All of the game graphics, state and logic are written in WebAssembly Text. The host environment (Javascript) is responsible for:

  1. Game tick loop
  2. User input
  3. Providing characters "0123456789GAMEOVER" byte data on game startup
  4. Blitting the pixel buffer to the display with WebGL2

The game uses 3 virtual pages of memory (64kb each) for a total of 192kb. Within those exist the pixel buffer contents, the characters data and snake positions. For more detailed breakdown you can check src/snake.wat.

The memory is shared between WASM and JS. On each game tick, the pixel buffer region of the memory is transferred to a WebGL2 texture, uploaded to the GPU and blitted to the screen.

References and readings

About

Classic Snake in direct WebAssembly

https://gnikoloff.github.io/wasm-snake/


Languages

Language:WebAssembly 55.5%Language:TypeScript 22.3%Language:HTML 21.9%Language:JavaScript 0.3%