How kripken/bananabread works
Project type and purpose
• This is BananaBread, a port of the Cube 2/Sauerbraten 3D game engine to the web.
• Its purpose is to compile C++ engine code (rendering, physics, AI, game logic) to JavaScript/WebAssembly via Emscripten, enabling a complete FPS in the browser using WebGL.
File structure
• Top-level:
• assets/ – 3D models, textures, sounds, weapon assets
• cube2/ – engine source, demos, web build, native build, assets, packages
• tools/ – auxiliary scripts (e.g. socket_relay.py, websockify)
• cube2/src:
• engine/ – core engine modules (rendering, world, physics, sound)
• fpsgame/ – game rules, AI, entities, weapons, server/client code
• shared/ – cross-platform code (serialization, command handling, i/o)
• src/web/ – Emscripten build targets, web glue code (bb.js, HTML entry points)
• src/native/ & src/vcpp/ & src/xcode/ – native build configurations (SDL)
• src/enet/ – networking library reused by engine
• README.md: describes features, build steps (emmake make client), running via Python SimpleHTTPServer.
Key architecture insights from README
• Single codebase for native and web, with platform-specific “glue” layers.
• Build pipeline: Emscripten transforms C++ → asm.js/wasm + JavaScript glue.
• Runtime: browser hosts bb.html, loads wasm, assets, calls into engine API via Module.cwrap.
• Assets and packages (maps/models) are loaded at runtime over HTTP.
Components
a. Build Pipeline
• Source code (C++ engine, game, shared, enet)
• Emscripten toolchain
• Outputs: bb.js, bb.wasm, HTML shell, supporting JS (glue)
b. Asset Pipeline
• assets/, cube2/packages/
• Optional Blender source files → exported .iqm/.dds/.ogz
• Static file hosting (SimpleHTTPServer or any web server)
c. Runtime Environment
• Browser:
• WebAssembly module + JS glue
• WebGL context for rendering
• Web Audio / HTML5 Audio for sounds
• DOM / Canvas for input and display
• Engine modules at runtime:
• Rendering (shaders, water, particles)
• Physics (collision, ragdoll)
• AI/Bot subsystem
• Game logic (entities, scoring, weapons)
• Networking stub (enet) for future multiplayer
d. Development Tools
• Python SimpleHTTPServer (or custom HTTP server)
• websockify/socket_relay for remote streaming or debugging
• Native build targets (Linux, Windows, macOS via SDL)
Relationships and data flow
• Source code → (emmake) → JS/WASM build
• Assets & packages served by HTTP server → fetched by client on startup
• Browser initializes WebGL + Audio, loads wasm, then calls into engine main()
• Optional future: Engine calls enet networking layer → WebSocket/server relay
Architectural patterns / design principles
• Modular layering:
• Core engine (platform-agnostic)
• Platform abstraction layers (SDL for native, Emscripten/HTML5 for web)
• Game logic plugin layer (fpsgame)
• Single-source, multi-target build
• Asset decoupling: static files, loaded at runtime
• Separation of concerns: rendering vs physics vs audio vs AI
Essential details without clutter
• Major layers (source, build, runtime, assets)
• Data/control flow: how code and assets move from source to user’s browser to in-memory engine components.