Skip to content

How it fits together ​

V12 splits a game in two: the engine runs it, the client draws it. They only talk through a session.

   simulation (@v12-engine/engine)                  the player's screen (@v12-engine/client)
 ┌──────────────────────────────┐   snapshots   ┌──────────────────────────────┐
 │ World                        │ ────────────► │ GameClient                   │
 │  units, orders, combat, fog  │               │  3D view, HUD, minimap       │
 │                              │ ◄──────────── │  input, sounds               │
 └──────────────────────────────┘   commands    └──────────────────────────────┘
                ▲                                              ▲
                └──────────────────── GameSession ─────────────┘
  • The engine has no DOM, no renderer, no clock. It runs in a page, a worker, Node or a test.
  • The client never touches the world. It draws snapshots (what the player may see) and sends commands (what the player wants).
  • The session can be in the same page, a worker, or across a network. The client doesn't change. See Sessions.

New to V12's words (copies, levels, scenery, hooks, packs)? The Glossary maps them to the usual game-engine terms.

Server-authoritative ​

One simulation decides the game. Each player is sent only what their team may know. Online, the server runs the world and each page is a screen for it. Unlike lockstep, map hacks are impossible and floating point need not match on every machine. See Multiplayer.

The packages ​

PackageWhat it isRuns
@v12-engine/engineThe world, units, orders, fog, saves, maps, sessions, computer playersAnywhere
@v12-engine/clientThe 3D view (WebGPU), the HUD (Solid), input, sounds, an app of scenesA browser
@v12-engine/editorThe map editorA browser
@v12-engine/createnpm create @v12-engineYour terminal

Each has a few entry points; import only from those. See Entry points.

Three rules for your code ​

  • Rules draw nothing. A game's rules import only @v12-engine/engine: no renderer, Solid or client. They must run on a server.
  • The server entry is for hosting. @v12-engine/engine/server is for the app that hosts games, not for a game's rules.
  • Packages meet by name. Between packages, import only published names. Never reach into another package's folder.

Your project can follow the same split: rules in files that import only the engine, the look and the page in files that import both. The repository checks its own imports with npm run lint.

Reference ​

Layers of the repository ​

LayerWhereMay import
enginepackages/engine/srcnothing of the others, nothing that draws
clientpackages/client/src/clientthe engine, by name
appthe rest of packages/client/srcthe client by path, the engine by name
editorpackages/editor/srcthe client's entries, the engine by name
gameapps/example/src/games/<name>@v12-engine/engine (not its server)
viewgames/<name>/view, games/<name>/game.tsthe engine and client by name, its own rules
examplethe rest of apps/example/srcanything above

Inside a package, paths start at its src: ./x beside, else #engine/…, #client/…, #editor/…, never ../.

Naming ​

Ends inMeansExample
…LookData the client draws byUnitLook
…DefA thing with an id a game declaresAbilityDef, FxDef
…OptionsWhat one call takesLaunchOptions
…InfoWhat the HUD readsHeroPanelInfo
View…A group of the viewViewUnits
…Api, …HostThe face of a class a part is givenGameClientApi, SelectionHost
…RuntimeWhat an app runs withClientRuntime

An ability's effect is an EffectDef (engine); a visual effect is an FxDef (client). What floats over a unit is its unitHud.

The example app ​

apps/example is built on the packages like your own project. Its game is melee (apps/example/src/games/melee), with a dev sandbox, the map editor and a server. apps/desktop wraps a game as a desktop app.