# @ferret/game: API

`createGame`: wires platform, Babylon engine, scene, world, display, input and physics into a running game.

7 exports. Generated from the source (`packages/game/src`), so it matches the code.

## Functions

### createGame

*function* · `packages/game/src/index.ts:62`

```ts
function createGame(opts: GameOptions): Game
```

Wire the usual pieces for a game: platform (OS Beroun or browser), Babylon engine, scene, world, display (render scale,
quality, FOV), input and physics. The game then adds its own services, levels and entities and calls `start()`.
On OS Beroun the engine is made the way /lib/beroun-3d.js does it (the console's 640x480 at density 1, no antialiasing).

### createGameAsync

*function* · `packages/game/src/index.ts:87`

```ts
async function createGameAsync(opts: GameAsyncOptions): Promise<GameAsync>
```

`createGame` with the engine chosen at run time: WebGPU when asked for (`gpu: 'webgpu'` or `?gpu=webgpu`) and the browser has an adapter, else the WebGL2 engine
exactly as `createGame` makes it. A game runs unchanged on either. Never on OS Beroun (no WebGPU there).

## Interfaces

### Game

*interface* · `packages/game/src/index.ts:34`

```ts
interface Game
```

- `engine: BABYLON.AbstractEngine`
- `scene: BABYLON.Scene`
- `world: World`
- `host: SceneHost` — the scene host: second worlds on the shared engine (a game's interlude during a travel)
- `platform: FerretPlatform`
- `display: Display`
- `input: InputService`
- `physics: PhysicsService`
- `touch?: TouchControls`
- `quality?: QualityService` — the quality regulator (absent when `quality: false`)
- `xr?: XrService` — the VR session service, once loaded: only when `xr` was set and the browser has WebXR (the package is fetched then, not before)
- `xrReady: Promise<XrService | undefined>` — resolves when the VR service is added (or at once when it is not wanted)
- `start(): void` — Run the render loop (and with it the fixed-step simulation).
- `stop(): void`
- `dispose(): void`

### GameAsync

*interface* · `packages/game/src/index.ts:81`

```ts
interface GameAsync extends Game
```

- `gpu: GpuMode`
- `gpuNote?: string`

### GameAsyncOptions

*interface* · `packages/game/src/index.ts:73`

```ts
interface GameAsyncOptions extends GameOptions
```

- `gpu?: GpuMode` — `'webgpu'` runs on WebGPU where the browser has an adapter (else WebGL2); default `'webgpu'` with an automatic fall back to WebGL2 when the browser has no working WebGPU (scenes made before 2026-11-20 pin `'webgl2'`), and `?gpu=` on the page overrides it
- `twgslUrl?: string` — where the WebGPU shader translator (twgsl.js and twgsl.wasm) is served from; default `lib/twgsl/` beside the page
- `webgpuShaders?: 'glsl' | 'wgsl'` — `'glsl'` (default): the engine's materials stay on GLSL, translated by twgsl, so Ferret's GLSL plugins and shaders work; `'wgsl'`: Babylon's native WGSL materials (the GLSL plugins then cannot attach)

### GameOptions

*interface* · `packages/game/src/index.ts:9`

```ts
interface GameOptions
```

- `canvas: HTMLCanvasElement`
- `input: Omit<InputOptions, 'defaultKind'> & { defaultKind?: InputOptions['defaultKind'] }`
- `platform?: FerretPlatform`
- `storageKey?: string` — key for browser storage (one per game)
- `physicsLayers?: string[]`
- `tier?: QualityTier`
- `touchControls?: boolean` — Touch controls on phones and tablets (default true)
- `clearColor?: [number, number, number]`
- `powerPreference?: 'high-performance' | 'low-power' | 'default'` — which graphics card the browser is asked for: 'high-performance' (the discrete one on a laptop; the default on desktops), 'low-power' (the integrated one; the default on phones, tablets and OS Beroun). A request only: the browser and the system may decide otherwise
- `fov?: { baseVertical?: number; minHorizontal?: number }` — the camera's field of view: the vertical one (radians) at wide aspects, and the horizontal one it never falls below (a game that matches another engine's 90 degrees passes both)
- `xr?: XrOptions` — VR through WebXR: `{ enabled: true }` adds the `xr` service where the browser has WebXR; elsewhere (OS Beroun) nothing is added
- `quality?: QualityOptions | false` — The quality regulator: on by default, it holds the frame rate (the headset's during a VR session, else `targetHz`, 60) by giving up the least visible quality of the side that holds the frame. `false` leaves it out. The page switch `?quality=off` stops it, `?quality=high|medium|low` fixes every knob at the top, the middle or the bottom of its range.

## Types

### GpuMode

*type* · `packages/game/src/index.ts:72`

```ts
type GpuMode = 'webgl2' | 'webgpu'
```

the graphics API a game asks for: the page switch `?gpu=webgpu` (or `webgl2`) wins over the option; the default is WebGPU with a fall back to WebGL2 (owner 2026-11-20); scenes made before that pin `'webgl2'`

