Modules / Networking

interestaddon

Each seat sent only the rows near it.

Putting it in a scene

The scene file has an interest block at its top level, beside world and prefabs. The code that runs the truth calls interest once with the truth and a lookup that says which row a seat plays as. A scene given interest and no block is refused.

"interest": { "radius": 12, "always": ["manager", "tilemap"], "at": "hero" }

A seat is then sent a row only when the row's pos is within radius of the seat's centre row, measured on x and y. A row that walks out of the radius is in the seat's next packet's ended, and one that walks back in is in its born, as if it had been spawned again.

A row is always sent, wherever it is, when its kind is in always or when it has no pos: a manager, a tilemap, anything that is not a thing on the ground. A seat whose centre row does not exist or has no pos is sent only those rows. A row's pos is its data.pos, [x, y] or [x, y, h] in cells, and h is never read.

Properties

Read from the scene file's interest block. Any other key in the block is refused.

.radius : number

The distance in world units, cells, a seat sees rows out to. A number above 0. A row at exactly radius is sent.

.always : string[]

Kinds sent to every seat wherever their rows are. Required, and may be empty. Each must be a kind the scene has a prefab for.

.at : string

Optional. Without it a seat's centre is the row the seat plays as, its own player row, which is sent by its pos like any other row. With it, the centre is the row whose id the player row holds in data[at]. A seat plays as a player row that names the hero that walks, and "at": "hero" centres the seat on the hero.

Methods

interest( truth, possessed )

Attaches interest to a truth, reading the scene's interest block. possessed(seat) returns the row the seat plays as, or undefined. The engine does not say which row a seat plays, so the caller hands the lookup over.

In the guide