Platform and display
Skill ferret-platform-display · download all skills · SKILL.md
When to use#
Saving or loading game state, reacting to suspend, sizing for the screen, choosing a quality tier.
The model#
Games never touch OS Beroun or the page directly; they use FerretPlatform, picked by detectPlatform: BerounPlatform (OS), BrowserPlatform (localStorage under storageKey), HeadlessPlatform (tests, in memory, resize() and suspend() to simulate the host).
Steps#
- State:
loadState()(last saved ornull),saveState(obj). - Save in
onSuspend(fn); on OS Beroun the app is closed with about two seconds to save. - Screen:
screen()gives size, density andDeviceClass(console,phone,tablet,desktop); follow withonResize. Display.trackCamera(cam)keeps the field of view right (fovFor);renderScaletrades sharpness for speed;initialTierpicks the starting tier (the console is alwayslow);display.setTier(tier)at run time.- Lay the HUD out in
emfrom the UI scale.
Check afterwards#
Run headless with HeadlessPlatform: save, suspend(), reload, state is back; resize to a phone and a 4K screen, nothing is cut off.
What usually goes wrong#
- Relying on
beforeunloadto save instead ofonSuspend. - Pixel-sized HUD that is unreadable on the console or 4K.
- Requiring Pointer Lock or mouse look: not available on the console.
- Forgetting that physics tiers follow the same names as display tiers (see
ferret-physics-fx-tuning). - The response layer's CPU cost follows the quality regulator through the
ResponseBudgetknobs (response.water|ground|flakes|map); seeferret-physics-response. - The frame is held by the CPU, not the GPU, in a big level: the CPU knobs of
PLAN-GPU-OFFLOADare registered with the quality regulator (quality.reportlists them):levels.still-freeze(active meshes frozen while the camera is still),levels.snapshot(WebGPU: the frame's draw calls recorded once and replayed; a level declaressnapshot: true),levels.occlusion(WebGL2 occlusion queries on big meshes; a level declaresocclusion). The page switch?gpu=webgpumakescreateGameAsyncrun on WebGPU where the browser has an adapter, else WebGL2; no game code changes.LightBudgetDef.clusteredmakes every lamp a real light through clustered lighting (no 8-light limit per material);freezeStatic(world, scene, { root, sequences })freezes a level's static meshes once it is ready.
Files#
reference/platform.md— One interface over OS Beroun and the browser; screen, device class and quality tiers.reference/api-platform.md— every export of@ferret/platformwith signature and doc comment