RemoteSession beta
Class of @v12-engine/engine
export declare class RemoteSession implements GameSessionA player's seat at a world that runs elsewhere, over a transport (see connect). It rebuilds what the host sends as changes (Delta) into whole snapshots, keeping the objects of what did not change, says which ticks it got, and answers the screen's questions from those and its own copy of the map (ClientWorld). No debug access, and no checkpoints: those belong to a simulation in the page
Members
constructor
constructor(transport: Transport, welcome: Extract<GameHostMessage, {
type: 'welcome';
}>, registry: Registry, map: ClientWorld,
limits?: PlayerLimits);Constructs a new instance of the RemoteSession class
alpha
alpha: number;How far, 0..1, the shown tick is between the last two snapshots, for blending the drawing
cameras
readonly cameras: readonly MapCamera[];The map's named camera positions from the welcome
camps
camps(): readonly CampInfo[];The creep camps as the newest frame has them
can
readonly can: SessionCan;A seat over a wire can none of what a game in this page can (SessionCan), but the debug tools' view of the world for a player the host lets use them (inspect, said over the wire)
canPlace
canPlace(unitType: string, point: Vec2): boolean;Whether the player could build this here, as far as they can tell: on their copy of the map, with the structures they know, on ground they have explored. The game's own say (the canPlace hook) is the host's: it may still refuse
debugView
protected get debugView(): SessionDebug | undefined;The debug tools' view of the world, for a player the host lets use them (the welcome's debug)
delay
get delay(): number;How far behind the newest snapshot the screen is shown, in ticks: about two snapshots, and room for the jitter
disconnected
get disconnected(): boolean;Whether the host has gone
dispose
dispose(): void;Stops pinging, closes the connection and frees the navigation made from the ground
doodads
readonly doodads: readonly MapDoodad[];The map's scenery objects from the welcome
environment
readonly environment?: MapEnvironment;The map's look (sky, mist, light) from the welcome, when it has one
failure
failure: {
message: string;
} | null;Why the game ended on an error in its rules, once the host said so
findPath
findPath(from: Vec2, to: Vec2, flying?: boolean): Vec2[] | null;A path over the ground the player has, on the air layer when flying; null when there is none
fog
fog(): FogState;The team's fog as built from what the host sent
formationPlaces
formationPlaces(units: readonly (FormationUnit & {
readonly flying?: boolean;
})[], point: Vec2, facing?: number, formation?: string): Map<EntityId, Vec2>;Where a group would stand sent to a point in a formation, rows when none is named: the rules are the host's (GameSession.formationPlaces)
interval
protected interval: number;Ticks between two snapshots, evened out
jitter
protected jitter: number;How far off the time snapshots arrive at is from the ticks between them, in seconds, evened out
limits
protected readonly limits: PlayerLimits;How much it keeps and how often it asks (ConnectOptions)
observer
readonly observer: boolean;Whether the player only watches, and sees everything
onDisconnect
onDisconnect?: () => void;Told when the connection drops, not by this side's leaving (dispose): to try again (resume), or to say the game is lost
onPause
onPause?: (pause: {
player?: PlayerId;
until?: number;
} | null) => void;Told each time the server pauses the game or lets it go on
onServer
onServer?: ConnectOptions['onServer'];Told of what the host says besides the game: a server's messages (see ConnectOptions.onServer)
paths
readonly paths: readonly MapPath[];The map's named paths from the welcome
pause
pause: {
player?: PlayerId;
until?: number;
} | null;The game paused by the server, for everyone: by a player (player, until a time at most, in Date.now()'s milliseconds) or an admin (neither). Null while it goes on
ping
ping?: number;Milliseconds a message takes to the host and back, evened out: measured every couple of seconds
placeCells
placeCells(unitType: string, point: Vec2): readonly boolean[] | undefined;Which cells of a building's ground are in the way, as canPlace sees them: on the player's copy of the map, explored
playerId
readonly playerId: PlayerId;The player this seat plays, as the host welcomed it
receive
receive(message: HostToPlayer): void;Takes in a message of the host's: what the transport hands it, and what came in while the session was made
regions
readonly regions: readonly MapRegion[];The map's named regions from the welcome
registry
readonly registry: Registry;The definitions of the game, from the rules the player connected with
resume
resume(transport: Transport): Promise<void>;Goes on with the same game over a new connection, once the host has welcomed it there again (a server does, to who comes back with their seat's token): everything known sent again, and the screen catches up. What the host says besides the game before the welcome goes to onServer; a refused fails it with the reason, as does a connection that closes first, or a host that runs another game
send
send(command: PlayerCommand): number;Sends a command to the host and returns the number it was given, which the host's answer names; does nothing once closed
shownAt
get shownAt(): number;The tick the screen is shown at, between two snapshots: behind the newest by delay
snapshot
snapshot(): Snapshot;The newest snapshot the host sent
takeGame
takeGame(game: Rules): void;Takes a new version of the game into this screen's registry (hot reload, a game in a worker): its definitions as the new version has them, what the host changed of them while it ran over them again
team
team: number;The team of that player; updated when a snapshot says it changed
tell
tell(message: {
type: string;
} & Record<string, unknown>): void;Says something to the server beside the game: a lobby's message ({ type: 'resume' })
terrain
readonly terrain: Terrain;The ground, built from the welcome and the parts the host sent
tickRate
readonly tickRate: number;Simulation ticks per second the host runs at, from the welcome
update
update(dt: number): Snapshot[];Lets the screen's clock go on by dt, and gives out the snapshots it has come to, oldest first: the screen draws between the last two (alpha). The time is the host's: the clock follows the snapshots, not the other way around
waiting
get waiting(): number;Snapshots come in and not yet given to the screen (update): a few normally, never more than a few seconds of them, however long the screen does not ask