newer(a: Stamp, b: Stamp?) → boolean
| arg | type | description |
|---|
| a | Stamp | |
| b | Stamp? | |
merge(ch: Channel, key: string, stamp: Stamp) → boolean
| arg | type | description |
|---|
| ch | Channel | |
| key | string | |
| stamp | Stamp | |
send(channel: string, ...: any) → void
| arg | type | description |
|---|
| channel | string | |
| ... | any | |
samplePerf( ) → void
Frames DRAWN per wall second since the previous sample: what a player sees,
measured with no per-frame work (two counters read once a second).
perf( ) → void
This peer's frame rate over the last sample (frames drawn per wall second, sampled about once a second): { fps, frameMs, seconds, viewport, profile }.
channel(name: string, onRemote: ((key: string, value: any) →
Open (or reopen) a named channel. `onRemote(key, value)` runs when another peer's write wins; reopening without one keeps the handler already set.
| arg | type | description |
|---|
| name | string | Channel name, e.g. "materials". |
| onRemote | ((key: string, value: any | Called with (key, value) for each remote write this peer adopts. |
set(ch: Channel, key: string, value: any, opts: { localOnly: boolean? }?) → void
Write a value locally and broadcast it to every peer. `nil` clears the key everywhere.
| arg | type | description |
|---|
| ch | Channel | The channel from `M.channel`. |
| key | string | The key (an entity key, "preset", ...). |
| value | any | Any value multiplayer.send can carry. |
| opts | { localOnly: boolean? }? | { localOnly = true } records the value on this peer alone: never sent, never in a snapshot. |
get(ch: Channel, key: string) → any
The current value of a key on this peer.
| arg | type | description |
|---|
| ch | Channel | |
| key | string | |
resync( ) → void
Ask the room for its state again (after a reconnect or a scene change).
reporter(name: string, fn: () → void
Register what this peer reports when the room is asked (`askRoom`): fn() returns a table of what it actually shows.
| arg | type | description |
|---|
| name | string | Report section, e.g. "materials" or "lighting". |
| fn | ( | |
askRoom(seconds: number?) →
Ask every peer in the room what it actually shows. Yields for `seconds` (default 2) while replies arrive; 0 returns this peer's own report alone.
| arg | type | description |
|---|
| seconds | number? | |
examples
local room = Sync.askRoom(2); for peer, r in room do print(peer, r.lighting.preset) end
heard( ) → void
The latest report every OTHER peer broadcast by itself (after each change and every 15 s), keyed by peer id: { at = seconds ago, report }.
report( ) → void
This peer's own report, as other peers receive it.
peers( ) → void
The ids of the peers in the room, this one included.
_now( ) → number
For tests: this peer's Lamport clock (the time its next write is stamped after).
_receive(ch: Channel, key: string, stamp: Stamp) → boolean
For tests: merge a stamp as if it arrived from another peer. Returns whether it won.
| arg | type | description |
|---|
| ch | Channel | |
| key | string | |
| stamp | Stamp | |
⌬ Types
Stamp = { v: any, t: number, p: number, l: boolean? }Channel = {