FERRETGame engine over Babylon.js
Ferret

Inspecting and testing

Skill ferret-debugging · download all skills · SKILL.md

When to use#

Finding out what a running game holds, driving it from a tool or an agent, writing tests that need no renderer.

The model#

CommandChannel (world.commands) is a list of named commands with a description: list() says what is there, execute(name, args) runs one; each package registers its own when its service starts, so the list is what the running game has loaded. The inspector, the model viewer, the editor and agents all use it, and the tests call the same names.

Steps#

  1. world.commands.list() first; the description of each command is the authority.
  2. World: world.info, world.pause, world.step, world.timeScale. Scene: scene.entities, scene.node, scene.bounds, scene.stats, scene.validate, scene.exportStep (a STEP file for CAD), camera.get|set.
  3. installInspector adds the entity tree and component values.
  4. Physics: physics.info, physics.bodies, body.state (see ferret-physics-host).
  5. Tests: one file for what changed (a headless world with the test helpers, world.step()), or one Ferretic test and probes in a built scene (ferret scene); whole suites only when asked.
  6. The game language: game.*, edit.game.* (ferret-motion).

Check afterwards#

The command you rely on appears in list() for this game; a headless test reproduces the problem in fixed steps.

What usually goes wrong#

  • Command not found: its package or capability was not registered or enabled in this game.
  • Testing against a number seen once instead of a law the code implements.
  • Tests sharing state: make a world per test and dispose it.

Frame breakdown (world.perf) and relevance#

  • world.perf.own('name', fn) times a function of the game; perf.report also gives own: what the game's code costs in the game's thread with its share and what would take it off (see ferret-scheduler).
  • ?perf on a page that wires it shows an overlay; world.commands.execute('perf.report', { top: 25 }) gives, per system, the average and worst ms and the calls a frame; perf.reset clears the window, perf.enable switches it on. A game that runs its own render loop sets world.perf.external = true, brackets its frame with perf.begin()/end(name, t0) and calls perf.endFrame() itself.
  • instrumentScene(profiler, scene, engine) (async) adds Babylon's own numbers: active-mesh evaluation, render targets, render, camera, animations, particles, draw calls and, where the browser has the timer query, the GPU frame time.
  • Headless runs on a busy machine are noisy: trust draw calls, active meshes and counters; read times only as a comparison taken in the same session.
  • relevance.report gives the class counts (view, soon, away, gone), the camera mode in force, the omega and horizon in use and where each value came from; relevance.mode selects or overrides a mode; relevance.classify classifies a sphere now.
  • snapshot.audit lists reads of simulation fields that the snapshot spec does not declare; edit.validate includes it.

Files#

  • reference/world.md — World, the fixed step, entities and components, services, the event bus and registries.
  • reference/scene-runner.md — ferret scene and ferret dev: one headless runner on the video card for commands, Ferretic tests, probes, frames and video; a scene kept open with programs changed live and only the example's own code rebuilt.
  • reference/commands.md — The debug command channel: how a tool, the inspector or an AI agent drives a running game, and the commands each package registers.
  • reference/api-inspector.md — every export of @ferret/inspector with signature and doc comment
  • reference/api-core.md — every export of @ferret/core with signature and doc comment
  • reference/api-core-2.md — every export of @ferret/core with signature and doc comment
  • reference/commands.md — 51 commands of these packages with their arguments