Skip to content

WorkerSession beta ​

Class of @v12-engine/engine

ts
export declare class WorkerSession extends RemoteSession

A seat at a game run in a worker of this page (workerSession): a RemoteSession whose host is a message away, with what a game played in the page has besides: its pace held and stepped (speed, advance), a save of it (save), the checkpoint to start again from, what it says in its log, the debug tools' view, and where its time went

Members ​

about ​

ts
about?: unknown;

What the worker's file said of the world as the game started (ServeWorldOptions.about): plain data, none where it says nothing

advance ​

ts
advance(ticks?: number): void;

Asks the worker to step the held game by this many ticks

can ​

ts
readonly can: SessionCan;

Its pace held and stepped, saves of it, the debug tools' view where they are on, and where its time went and in which systems

checkpoint ​

ts
checkpoint?: {
        label: Message;
        save: WorldSave;
    };

The label and save of the last checkpoint the worker's game took, to retry from

debug ​

ts
get debug(): SessionDebug | undefined;

The debug tools' view of the world, where they are on: over the session's own words, as a server's is

delay ​

ts
get delay(): number;

How far behind the newest tick the screen is shown, in ticks: one, and room for how unevenly they come (a tick that took long comes late). Less than over a wire, where two are kept in hand: there is no line to stall here

dispose ​

ts
dispose(): void;

Ends the game in the worker. The worker is the page's: it stays, for the next game, until the page ends it

heard ​

ts
heard(said: FromWorker): void;

What the worker said that is not the session's own text

log ​

ts
log: Logger;

What the world says (World.log), said again here: the page shows it with its own

onTold ​

ts
onTold(listener: (data: unknown) => void): () => void;

Hears what the worker's code tells the page (WorkerGameContext.tell): plain data, in order with the ticks. What it told before anyone listened is heard by the first listener, at once. Gives back what stops hearing it

received ​

ts
received: number;

Milliseconds the page took to take in what the worker sent, each time, evened out: its share of a game run there

reloadGame ​

ts
reloadGame(): void;

Asks the worker to take a new version of the game (hot reload): it loads the game again itself, as its file says (serveWorld reload), and puts it into its world

save ​

ts
save(): Promise<WorldSave>;

Asks the worker for a save of its world and resolves with it; rejects if the game ends first

speed ​

ts
get speed(): number;

set speed(speed: number);

The simulation speed multiplier the worker's game runs at, 0 pauses; setting it tells the worker

timing ​

ts
timing(): {
        tick: number;
        tickMax: number;
        send: number;
        receive: number;
        systems: SystemTiming[];
    } | undefined;

Where the worker's time went (tick, send and receive milliseconds and each system's), or undefined until it has said

wire ​

ts
wire(post: (message: ToWorker) => void, log: Logger, stop: () => void): void;

What workerSession gives it once it is made: the way to the worker, and what stops hearing it