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
| Package | What it is | Runs |
|---|---|---|
@v12-engine/engine | The world, units, orders, fog, saves, maps, sessions, computer players | Anywhere |
@v12-engine/client | The 3D view (WebGPU), the HUD (Solid), input, sounds, an app of scenes | A browser |
@v12-engine/editor | The map editor | A browser |
@v12-engine/create | npm create @v12-engine | Your 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/serveris 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
| Layer | Where | May import |
|---|---|---|
| engine | packages/engine/src | nothing of the others, nothing that draws |
| client | packages/client/src/client | the engine, by name |
| app | the rest of packages/client/src | the client by path, the engine by name |
| editor | packages/editor/src | the client's entries, the engine by name |
| game | apps/example/src/games/<name> | @v12-engine/engine (not its server) |
| view | games/<name>/view, games/<name>/game.ts | the engine and client by name, its own rules |
| example | the rest of apps/example/src | anything above |
Inside a package, paths start at its src: ./x beside, else #engine/…, #client/…, #editor/…, never ../.
Naming
| Ends in | Means | Example |
|---|---|---|
…Look | Data the client draws by | UnitLook |
…Def | A thing with an id a game declares | AbilityDef, FxDef |
…Options | What one call takes | LaunchOptions |
…Info | What the HUD reads | HeroPanelInfo |
View… | A group of the view | ViewUnits |
…Api, …Host | The face of a class a part is given | GameClientApi, SelectionHost |
…Runtime | What an app runs with | ClientRuntime |
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.