@pocketrts/lockstep 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +253 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/lockstep.d.ts +365 -0
- package/dist/lockstep.js +842 -0
- package/dist/queue.d.ts +19 -0
- package/dist/queue.js +25 -0
- package/dist/text.d.ts +8 -0
- package/dist/text.js +26 -0
- package/package.json +41 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Junjie Bai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,254 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @pocketrts/lockstep
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Deterministic lockstep turn scheduler for small peer-to-peer games. The host orders every player's commands into turns and broadcasts them on a fixed beat; each peer simulates up to the end of a turn only after receiving it. The package also handles loading, catch-up and waiting for slow peers, checksum comparison, drops, and host migration.
|
|
4
|
+
|
|
5
|
+
It is pure logic: no DOM, no timers, no connections, no game rules. You give it messages, the current time and membership changes; it calls your hooks to send messages and report events. It has no runtime dependencies and does not import `@pocketrts/net`. Extracted from the online play of Pocket War.
|
|
6
|
+
|
|
7
|
+
## When to use it
|
|
8
|
+
|
|
9
|
+
Use it only when **every peer runs the same deterministic simulation and only commands are synchronized**:
|
|
10
|
+
|
|
11
|
+
- The simulation must produce bit-identical results on every device from the same commands (fixed-point or carefully controlled floating point, deterministic iteration order, seeded randomness, no wall-clock reads).
|
|
12
|
+
- The whole match runs at the pace of the slowest device.
|
|
13
|
+
- Commands run about `lead` turns after being issued (0.2 s with the defaults).
|
|
14
|
+
- No joining mid-match and no reconnecting: a dropped peer is out for good.
|
|
15
|
+
|
|
16
|
+
In exchange, bandwidth stays tiny whatever the size of the world, and there is no separate state-sync format to maintain. For turn-based games, lobbies or any game where one peer can own the state, use a host-authoritative model instead (for example `HostState` in `@pocketrts/net`).
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
pnpm add @pocketrts/lockstep
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
ES module, TypeScript types included. Needs `btoa` / `atob` (browsers, Node.js 16+, Workers) only for the text helpers.
|
|
25
|
+
|
|
26
|
+
## Interface
|
|
27
|
+
|
|
28
|
+
| Export | Role |
|
|
29
|
+
|--------|------|
|
|
30
|
+
| `Lockstep` | The scheduler, one per peer per match. |
|
|
31
|
+
| `LockstepConfig` | Start-up data: `self`, `host`, `members`, `authorize`, `dropCommands`, `now`, `options`. |
|
|
32
|
+
| `LockstepHooks` | Callbacks: `send`, `dropped`, `selfDropped`, `dropHost`, `status`. |
|
|
33
|
+
| `LockstepOptions`, `DEFAULT_LOCKSTEP_OPTIONS`, `lockstepOptions()` | Parameters, their defaults, and defaults filled in for a partial object. |
|
|
34
|
+
| `frameSteps()`, `catchupSlots()`, `FrameOptions` | How many slots to advance in a render frame, with catch-up. |
|
|
35
|
+
| `DropReason`, `SelfDropReason`, `DROP_REASONS` | Reason codes. |
|
|
36
|
+
| `LockstepMsg`, `Turn` | Wire messages (plain JSON). |
|
|
37
|
+
| `LockstepQueue<C>`, `CommandCodec<C>` | Optional typed command queue over a `Lockstep`, with your encoder. |
|
|
38
|
+
| `bytesToText()`, `textToBytes()` | Binary command data to base64 text and back (`null` for invalid text). |
|
|
39
|
+
|
|
40
|
+
### `LockstepConfig`
|
|
41
|
+
|
|
42
|
+
| Field | Meaning |
|
|
43
|
+
|-------|---------|
|
|
44
|
+
| `self`, `host` | This peer's member id and the current host's id (from the room session). |
|
|
45
|
+
| `members` | Every member at the start of the match, including `self`. Spectators may be members too. |
|
|
46
|
+
| `authorize(from, data)` | Runs on the host for each member command. Return `false` to drop it (for example: a member may only command its own side, system commands are host-only). The host's own commands and `dropCommands` results are not checked. |
|
|
47
|
+
| `dropCommands?(id, reason)` | Returns system commands to insert into the same turn that announces `id`'s drop. Also called with `(oldHost, 'left')` on the peer that becomes host after a migration. Runs only on the (new) host. It may be called and its result discarded when the drop turns out to be announced already, so keep it free of side effects. Default: no commands. |
|
|
48
|
+
| `now()` | Monotonic clock in milliseconds, for example `() => performance.now()`. |
|
|
49
|
+
| `options?` | `Partial<LockstepOptions>`; every peer must use the same values. |
|
|
50
|
+
|
|
51
|
+
Example: hand a dropped player's side to the computer. `sideOf` and `encodeCommand` are the game's; `authorize` keeps the system command host-only, and the scheduler puts the result in the same turn as the drop, never passes it through `authorize`, and withdraws it if a migration finds the drop already announced, so each side is taken over exactly once on every peer.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
const ls = new Lockstep({
|
|
55
|
+
self, host, members,
|
|
56
|
+
now: () => performance.now(),
|
|
57
|
+
// Members may only command their own side; system commands such as takeover are host-only
|
|
58
|
+
authorize: (from, d) => game.mayIssue(from, d),
|
|
59
|
+
// Called on the host for every drop, and on a new host for the old host (reason 'left')
|
|
60
|
+
dropCommands: id => {
|
|
61
|
+
const side = sideOf(id); // 0 = the member controls no side
|
|
62
|
+
return side ? [bytesToText(encodeCommand({ kind: 'takeover', side }))] : [];
|
|
63
|
+
},
|
|
64
|
+
}, hooks);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### `LockstepHooks`
|
|
68
|
+
|
|
69
|
+
| Hook | When |
|
|
70
|
+
|------|------|
|
|
71
|
+
| `send(to, msg)` | Deliver `msg` reliably and in order to member `to` or to all other members (`'all'`). Messages are plain JSON. It may throw for a turn (for example over a size limit): the scheduler logs it and carries on. |
|
|
72
|
+
| `dropped(id, reason)` | The host's verdict reached this peer: close the link to `id` and remove it from your member list. Called once per dropped member on every remaining peer. |
|
|
73
|
+
| `selfDropped(reason)` | This peer is out of the match (dropped by the host, isolated, or hidden or frozen too long). Called once; the scheduler is closed afterwards. Show the reason and leave. |
|
|
74
|
+
| `dropHost()` | The host was silent for `silentMs`, or proved gone after someone else claimed to be host: ask the connection layer to drop the host. The connection layer then picks the new host and you call `hostChanged`. |
|
|
75
|
+
| `status()` | Something the UI may show changed: `phase`, `waiting`, `migrating`, `loaded`. |
|
|
76
|
+
|
|
77
|
+
### `Lockstep`
|
|
78
|
+
|
|
79
|
+
Inputs:
|
|
80
|
+
|
|
81
|
+
| Method | Call when |
|
|
82
|
+
|--------|-----------|
|
|
83
|
+
| `ready()` | This peer finished building its world. The host starts when everyone is ready or `loadMs` has passed. |
|
|
84
|
+
| `update()` | Every frame, and on a timer (for example every 100 ms) while there is no render loop (loading, background). |
|
|
85
|
+
| `receive(from, msg)` | A lockstep message arrived from member `from`. Malformed messages are ignored. |
|
|
86
|
+
| `memberLost(id)` | The connection layer lost a member that is not the host. |
|
|
87
|
+
| `hostChanged(id)` | The connection layer chose a new host (the old one is gone). |
|
|
88
|
+
| `submit(data)` | A local command (opaque string). |
|
|
89
|
+
| `take()` | Before each simulation step: the commands to run in this slot, or `null` when the next turn has not arrived (do not step). |
|
|
90
|
+
| `stepped()` | After each step: returns the turn number when a turn was just completed, else `null`. |
|
|
91
|
+
| `isCheckTurn(n)` / `checksum(n, v)` | When `stepped()` returned `n` and `isCheckTurn(n)`, compute an integer checksum of your world and pass it. The host drops peers whose value differs from its own. |
|
|
92
|
+
| `visibility(hidden)` | The page was hidden or shown again. |
|
|
93
|
+
| `drop(id, reason)` | Host only: drop a member yourself (for example a kick). Ignored on non-hosts. |
|
|
94
|
+
| `finish()` | This peer's match is over (results screen): stop ordering and stop watching the host. |
|
|
95
|
+
| `close()` | Tear down; nothing is sent or processed afterwards. |
|
|
96
|
+
|
|
97
|
+
State for the UI: `phase` (`'loading' | 'running' | 'over'`), `isHost`, `host`, `members`, `waiting` (members the host is halted for), `migrating`, `loaded` (ready members while loading), `turn`, `available()`, `hostSilentFor()`, `options`.
|
|
98
|
+
|
|
99
|
+
## Minimal usage
|
|
100
|
+
|
|
101
|
+
Run the scheduler on its own sub-channel of a room session, so it can share the session with host state and game messages. This uses `channels(session)` from `@pocketrts/net`; any reliable ordered transport with the same shape works. To play several matches in one session, close the channel when this peer's match ends (`ch.close()`) and open `'lockstep'` again for the next match.
|
|
102
|
+
|
|
103
|
+
Every member must open the `'lockstep'` channel in the same synchronous callback in which it learns that the match starts (for example the handler of your start message), with no `await` in between. A message for a channel name that is not open yet is dropped, so a member that opens it later loses the host's `go` and the first turns, never catches up, and is finally dropped for `stall`. If the scheduler itself is created later (after an `await`, or once your UI has switched screens), open the channel at once anyway and buffer what arrives until then:
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
// In the start handler, synchronously:
|
|
107
|
+
const ch = channels(session).channel('lockstep');
|
|
108
|
+
const early: [number, unknown][] = [];
|
|
109
|
+
ch.onMessage = (from, msg) => void early.push([from, msg]);
|
|
110
|
+
// Later, right after creating the scheduler:
|
|
111
|
+
ch.onMessage = (from, msg) => ls.receive(from, msg as LockstepMsg);
|
|
112
|
+
for (const [from, msg] of early.splice(0)) ls.receive(from, msg as LockstepMsg);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { channels, type RoomSession } from '@pocketrts/net';
|
|
117
|
+
import { Lockstep, LockstepQueue, frameSteps, type LockstepMsg } from '@pocketrts/lockstep';
|
|
118
|
+
|
|
119
|
+
const STEP = 1 / 30; // simulation step (s); with turnTicks 3 one turn is 0.1 s
|
|
120
|
+
|
|
121
|
+
function startMatch(session: RoomSession, game: MyGame) {
|
|
122
|
+
const ch = channels(session).channel('lockstep');
|
|
123
|
+
const ls = new Lockstep(
|
|
124
|
+
{
|
|
125
|
+
self: session.self,
|
|
126
|
+
host: session.host,
|
|
127
|
+
members: [...session.members.keys()],
|
|
128
|
+
authorize: (from, data) => game.mayIssue(from, data),
|
|
129
|
+
dropCommands: (id, reason) => game.commandsOnDrop(id, reason),
|
|
130
|
+
now: () => performance.now(),
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
send: (to, msg) => ch.send(to, msg),
|
|
134
|
+
dropped: id => session.drop(id),
|
|
135
|
+
selfDropped: reason => game.showLeft(reason),
|
|
136
|
+
dropHost: () => session.drop(session.host),
|
|
137
|
+
status: () => game.renderStatus(ls),
|
|
138
|
+
},
|
|
139
|
+
);
|
|
140
|
+
ch.onMessage = (from, msg) => ls.receive(from, msg as LockstepMsg);
|
|
141
|
+
ch.onMember = (id, joined) => {
|
|
142
|
+
// The old host leaving is followed by onHost
|
|
143
|
+
if (!joined && id !== ls.host) ls.memberLost(id);
|
|
144
|
+
};
|
|
145
|
+
ch.onHost = id => ls.hostChanged(id);
|
|
146
|
+
|
|
147
|
+
const queue = new LockstepQueue(ls, game.codec); // or call ls.submit / ls.take with strings yourself
|
|
148
|
+
let acc = 0;
|
|
149
|
+
const timer = setInterval(() => { if (ls.phase !== 'running') ls.update(); }, 100);
|
|
150
|
+
const onVisibility = () => ls.visibility(document.hidden);
|
|
151
|
+
document.addEventListener('visibilitychange', onVisibility);
|
|
152
|
+
|
|
153
|
+
game.build().then(() => ls.ready());
|
|
154
|
+
|
|
155
|
+
game.onFrame = (dt: number) => {
|
|
156
|
+
ls.update();
|
|
157
|
+
const r = frameSteps(acc + dt, STEP, ls.available(), ls.options);
|
|
158
|
+
acc = r.acc;
|
|
159
|
+
for (let k = 0; k < r.steps; k++) {
|
|
160
|
+
const cmds = queue.take();
|
|
161
|
+
if (!cmds) break;
|
|
162
|
+
game.step(cmds);
|
|
163
|
+
const n = ls.stepped();
|
|
164
|
+
if (n !== null && ls.isCheckTurn(n)) ls.checksum(n, game.checksum());
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
game.onCommand = cmd => queue.submit(cmd);
|
|
168
|
+
game.onEnd = () => { ls.finish(); }; // results screen: the match is over for this peer
|
|
169
|
+
game.onClose = () => {
|
|
170
|
+
ls.close();
|
|
171
|
+
ch.close();
|
|
172
|
+
clearInterval(timer);
|
|
173
|
+
document.removeEventListener('visibilitychange', onVisibility);
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Loading a world can freeze a page for many seconds. Let the scheduler's `loadMs` decide who failed to load, and relax the connection layer's heartbeat timeout meanwhile (Pocket War calls `session.setLinkTimeout(loadMs + 5000)` at the start and `setLinkTimeout(null)` once `phase` leaves `'loading'`).
|
|
179
|
+
|
|
180
|
+
## Reason codes
|
|
181
|
+
|
|
182
|
+
Games turn these codes into their own text.
|
|
183
|
+
|
|
184
|
+
| Code | Type | Meaning |
|
|
185
|
+
|------|------|---------|
|
|
186
|
+
| `left` | `DropReason` | The peer left or its connection was lost (also: an old host announced by its successor, a member that never reported to a new host). As `selfDropped`: this peer lost the host (it was the only one cut off). Unknown codes from the wire are read as `left`. |
|
|
187
|
+
| `desync` | `DropReason` | Its checksum differed from the host's. |
|
|
188
|
+
| `stall` | `DropReason` | It blocked everyone and made no progress for `stallMs`. |
|
|
189
|
+
| `load` | `DropReason` | It was not ready within `loadMs`. |
|
|
190
|
+
| `isolated` | `SelfDropReason` only | This peer became host, but no other member reported within `migrateMs` (it cannot tell "everyone else left at once" from "I am cut off", so it leaves). Two-peer matches are not affected. |
|
|
191
|
+
| `hidden` | `SelfDropReason` only | The page stayed in the background for `silentMs` or longer, or its `update` stopped for the freeze limit (see "Freezes" below) while it was hidden. |
|
|
192
|
+
| `frozen` | `SelfDropReason` only | This peer was out of touch for the freeze limit (see "Freezes" below) with the page not hidden: the others may already have replaced or dropped it, so it leaves instead of playing on alone. |
|
|
193
|
+
|
|
194
|
+
## Parameters
|
|
195
|
+
|
|
196
|
+
Every peer in a match must use the same values, except `freezeMarginMs`. Defaults are Pocket War's. `lockstepOptions()` and the `Lockstep` constructor throw a `RangeError` when `turnTicks`, `turnMs`, `lead`, `keepTurns`, `lagTurns`, `checkTurns`, `maxFrameSteps` or `turnBytes` is not a positive finite integer, when any other option is not a non-negative finite number, or when `keepTurns` is not greater than `lead`.
|
|
197
|
+
|
|
198
|
+
| Option | Default | Meaning |
|
|
199
|
+
|--------|---------|---------|
|
|
200
|
+
| `turnTicks` | 3 | Simulation slots per turn. A paused world still consumes slots. |
|
|
201
|
+
| `turnMs` | 100 | Beat length (ms): one turn per beat. Match it to `turnTicks` × your step length. |
|
|
202
|
+
| `lead` | 2 | Turns sent ahead of the beat; commands run about `lead` turns after issue. |
|
|
203
|
+
| `keepTurns` | 600 | Recent turns kept for resending during migration. |
|
|
204
|
+
| `lagTurns` | 8 | The host halts while someone is more than this many turns behind. |
|
|
205
|
+
| `waitShowMs` | 600 | Accumulated halt time before `waiting` is shown. |
|
|
206
|
+
| `waitKeepMs` | 1500 | Members that blocked this recently stay in `waiting`. |
|
|
207
|
+
| `waitBeatMs` | 500 | Wait-list broadcast interval while halted (also the host heartbeat). |
|
|
208
|
+
| `stallMs` | 10000 | A blocker without progress this long is dropped (`stall`). |
|
|
209
|
+
| `silentMs` | 10000 | Host silence before members drop the host; background time before `hidden`; with `freezeMarginMs`, the freeze limit. |
|
|
210
|
+
| `staleMs` | 1500 | How long a rival host claim is held while our host may still speak. |
|
|
211
|
+
| `migrateMs` | 5000 | Time a new host waits for member reports. |
|
|
212
|
+
| `checkTurns` | 10 | Checksums compared at the end of turn n when (n + 1) is a multiple of this. |
|
|
213
|
+
| `frozenMs` | 2000 | A gap between `update` calls above this means this peer was frozen; timers are not charged for it. |
|
|
214
|
+
| `freezeMarginMs` | 2000 | Margin below `silentMs` for the freeze limit (see "Freezes"). Unlike the others, it need not match across peers. |
|
|
215
|
+
| `loadMs` | 60000 | Loading deadline; peers not ready are dropped (`load`). |
|
|
216
|
+
| `loadBeatMs` | 500 | Loading-status broadcast interval (also the host heartbeat). |
|
|
217
|
+
| `turnBytes` | 40000 | Command bytes per turn; the rest waits. Keep it below your transport's message limit (64 KB in `@pocketrts/net`). |
|
|
218
|
+
| `entryBytes` | 32 | Per-command overhead counted toward `turnBytes`. |
|
|
219
|
+
| `maxFrameSteps` | 24 | Upper bound of `frameSteps` per frame. |
|
|
220
|
+
|
|
221
|
+
`frameSteps(acc, dt, avail, options)` advances by accumulated time, takes extra steps when more than `catchupSlots(options)` = (lead + 1) × turnTicks slots are in hand, and never builds up debt while starved.
|
|
222
|
+
|
|
223
|
+
## How it works
|
|
224
|
+
|
|
225
|
+
- Turn n's commands run in its first slot. At the start the host sends turns 0..`lead`, then one turn per beat, so peers normally hold `lead` turns of margin.
|
|
226
|
+
- Members send commands to the host at any time with a per-member sequence number; the host puts them in the next turn. Members keep unconfirmed commands and resend them after a migration; the host deduplicates by sequence number.
|
|
227
|
+
- Each peer reports finished turns. The host halts while someone lags more than `lagTurns`; the wait list goes to everyone after `waitShowMs`.
|
|
228
|
+
- The host's verdicts travel inside turns (`drop`), so every peer applies them at the same point in the command stream, together with the `dropCommands` inserted in that turn.
|
|
229
|
+
- When the host goes, the connection layer picks the next host (Pocket War: the lowest remaining id). The new host asks everyone for their last turn, fills the gaps, announces the old host's drop, and continues. A peer that only lost its own link to the host is told `stale` by the others and leaves.
|
|
230
|
+
|
|
231
|
+
## Freezes
|
|
232
|
+
|
|
233
|
+
A page can stop running (blocked main thread, long garbage collection, a hidden tab) long enough for the others to replace or drop it. Such a peer would otherwise carry on alone once it thaws, and the match would split into two that each believe the other left. So a peer that was out of touch for the freeze limit leaves with `frozen` (or `hidden`, when `visibility(true)` was called meanwhile).
|
|
234
|
+
|
|
235
|
+
- Limit: `silentMs` − `freezeMarginMs`, but never below the host's longest normal gap between broadcasts plus `frozenMs`. 8 s with the defaults.
|
|
236
|
+
- Host: leaves when the time since its last broadcast to everyone reaches the limit, while loading or running (also as a new host during migration). It does not leave in `over` or when it is the only member left.
|
|
237
|
+
- Member: leaves only while running, when the time since its last `update()` (above `frozenMs`) reaches the limit. A freeze while loading is not judged (the connection layer's timeout is relaxed then and `loadMs` rules), except that a `memberLost` / `hostChanged` report right after such a freeze counts it.
|
|
238
|
+
- Checked in `update()`, at the start of `memberLost()` and `hostChanged()`, and on the host at the start of `receive()`, since after a freeze those can run before the first `update()`. A member does not check in `receive()`, so a queued `kicked` still gives its real reason.
|
|
239
|
+
- Keep calling `visibility()` so a hidden page reports `hidden`; a game that drives `update()` only from the render loop is still covered on the host, which counts from its last broadcast.
|
|
240
|
+
- It guarantees no split only while the connection layer's link timeout in a match is at least `silentMs` and `silentMs` − `freezeMarginMs` is above the floor. A freeze between the limit and `silentMs` ends that peer's match although the others might not have replaced it yet; this is accepted.
|
|
241
|
+
- The wire format is unchanged, so peers with and without this behaviour can share a match; only the ones that have it protect themselves.
|
|
242
|
+
|
|
243
|
+
## Limitations
|
|
244
|
+
|
|
245
|
+
- Determinism is your job: the scheduler only guarantees that every peer runs the same commands in the same slot. Use checksums to catch divergence; a diverging peer is dropped, it is never resynchronized.
|
|
246
|
+
- No late join, no reconnect, no spectator catch-up from a snapshot.
|
|
247
|
+
- The connection layer must provide reliable, ordered delivery per peer pair, detect lost peers (`memberLost`) and choose the same new host on every peer (`hostChanged`).
|
|
248
|
+
- With three or more peers, if all others really drop at the same moment, the new host leaves (`isolated`) instead of continuing alone.
|
|
249
|
+
- Commands are strings and travel inside JSON; encode binary data with `bytesToText`. A single command larger than `turnBytes` still goes out alone in one turn, and may exceed the transport's limit.
|
|
250
|
+
- Membership is fixed at the start; members can only leave.
|
|
251
|
+
|
|
252
|
+
## Migrating from Pocket War
|
|
253
|
+
|
|
254
|
+
How Pocket War's scheduler maps onto this package is in [docs/netplay/pocket-war-migration.md](../../docs/netplay/pocket-war-migration.md).
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic lockstep turn scheduling: the host orders commands and broadcasts turns on a fixed beat; every peer
|
|
3
|
+
* simulates up to the end of a turn only after it has received that turn. Pure logic, no DOM and no connections:
|
|
4
|
+
* inputs are "a message arrived", "what time is it" (`update`), "the host changed" and "a member was lost"; outputs go
|
|
5
|
+
* through `LockstepHooks` (send messages, report events). The game wires it to its room session and main loop.
|
|
6
|
+
*
|
|
7
|
+
* - Turns: each turn has `turnTicks` slots (a slot is one simulation step; a paused world still consumes slots, so
|
|
8
|
+
* turn numbers are not world tick numbers). Turn n's commands run in its first slot. At the start the host sends
|
|
9
|
+
* turns 0..lead, then turn k + lead on beat k, so every peer usually holds `lead` turns of margin.
|
|
10
|
+
* - Commands: members send commands to the host at any time; the host puts them in the next broadcast turn (they run
|
|
11
|
+
* about `lead` turns after being issued). Members keep the commands they have not yet seen in a turn and resend them
|
|
12
|
+
* after a host migration; the host deduplicates by the highest sequence number already seen from each member.
|
|
13
|
+
* - Catch-up and waiting: every peer reports each finished turn to the host. When someone lags more than `lagTurns`,
|
|
14
|
+
* the host stops sending new turns (the match runs at the slowest peer's pace); after `waitShowMs` of halting it
|
|
15
|
+
* broadcasts whom it waits for (doubling as the host heartbeat). A blocking member with no progress for `stallMs` is
|
|
16
|
+
* dropped.
|
|
17
|
+
* - Membership: the host's verdict rules. Members the host drops are listed in a turn's `drop`; every peer closes its
|
|
18
|
+
* link to them, and the game's `dropCommands` hook can insert system commands into the same turn.
|
|
19
|
+
* - Host migration: after the connection layer names a new host, the new host asks everyone for the last turn they
|
|
20
|
+
* received, sends missing turns to the peers that lack them, and continues ordering from the next turn; the old
|
|
21
|
+
* host's drop (and its `dropCommands`) goes into the first new turn. If a peer claims to be the new host while the
|
|
22
|
+
* old host is still alive for others (only the claimant lost the old host), they answer `stale` and the claimant
|
|
23
|
+
* drops itself.
|
|
24
|
+
* - Freezes: a peer out of touch long enough that the others may already have replaced or dropped it (a page frozen
|
|
25
|
+
* or hidden for about `silentMs`) leaves on its own instead of playing on alone next to them.
|
|
26
|
+
*/
|
|
27
|
+
/** Tunable parameters. Defaults are `DEFAULT_LOCKSTEP_OPTIONS`. */
|
|
28
|
+
export interface LockstepOptions {
|
|
29
|
+
/** Slots per turn. */
|
|
30
|
+
turnTicks: number;
|
|
31
|
+
/** Length of one beat (ms). */
|
|
32
|
+
turnMs: number;
|
|
33
|
+
/** Turns the host sends ahead of the beat: commands run about `lead` turns after being issued. */
|
|
34
|
+
lead: number;
|
|
35
|
+
/** Recent turns every peer keeps (resent during host migration). */
|
|
36
|
+
keepTurns: number;
|
|
37
|
+
/** The host stops sending new turns while someone lags more than this many turns. */
|
|
38
|
+
lagTurns: number;
|
|
39
|
+
/** Accumulated halt time (ms) before the wait list is shown to everyone. */
|
|
40
|
+
waitShowMs: number;
|
|
41
|
+
/** Members that blocked within this long (ms) stay on the wait list. */
|
|
42
|
+
waitKeepMs: number;
|
|
43
|
+
/** Interval (ms) of the wait list broadcast while halted (doubles as the host heartbeat). */
|
|
44
|
+
waitBeatMs: number;
|
|
45
|
+
/** A blocking member with no progress for this long (ms) is dropped. */
|
|
46
|
+
stallMs: number;
|
|
47
|
+
/**
|
|
48
|
+
* A member that hears nothing from the host for this long (ms) treats the host as gone; a page hidden this long
|
|
49
|
+
* drops itself (a freeze or hidden time noticed by `update` drops it sooner, see `freezeMarginMs`).
|
|
50
|
+
*/
|
|
51
|
+
silentMs: number;
|
|
52
|
+
/** Someone claims to be the new host while ours is still known: wait this long (ms) to see if ours still talks. */
|
|
53
|
+
staleMs: number;
|
|
54
|
+
/** Time (ms) a new host waits for member reports; members that do not report are dropped. */
|
|
55
|
+
migrateMs: number;
|
|
56
|
+
/** Checksums are compared at the end of turn n when (n + 1) is a multiple of this. */
|
|
57
|
+
checkTurns: number;
|
|
58
|
+
/** Two `update` calls further apart than this (ms) mean this peer was frozen. */
|
|
59
|
+
frozenMs: number;
|
|
60
|
+
/**
|
|
61
|
+
* Safety margin (ms) for leaving after a freeze: a peer out of touch so long that the others may already have
|
|
62
|
+
* replaced or dropped it leaves on its own (`frozen`, or `hidden`) once that lasted `silentMs` minus this margin.
|
|
63
|
+
* The margin covers the gap between the host's messages and network delay. The limit never goes below the host's
|
|
64
|
+
* longest normal gap between broadcasts plus `frozenMs`. Need not match across peers. No split is guaranteed only
|
|
65
|
+
* while the connection layer's link timeout in a match is at least `silentMs` and `silentMs - freezeMarginMs` is
|
|
66
|
+
* above that floor.
|
|
67
|
+
*/
|
|
68
|
+
freezeMarginMs: number;
|
|
69
|
+
/** Time (ms) to wait for everyone to load at the start; peers not ready by then are dropped. */
|
|
70
|
+
loadMs: number;
|
|
71
|
+
/** Interval (ms) of the load status broadcast during loading (doubles as the host heartbeat). */
|
|
72
|
+
loadBeatMs: number;
|
|
73
|
+
/** Command data bytes per turn (the rest waits for later turns); leaves room under a 64 KB message limit. */
|
|
74
|
+
turnBytes: number;
|
|
75
|
+
/** Per-command overhead counted toward `turnBytes` (entry tuple, separators, envelope). */
|
|
76
|
+
entryBytes: number;
|
|
77
|
+
/** Most slots `frameSteps` advances in one frame (when catching up). */
|
|
78
|
+
maxFrameSteps: number;
|
|
79
|
+
}
|
|
80
|
+
export declare const DEFAULT_LOCKSTEP_OPTIONS: Readonly<LockstepOptions>;
|
|
81
|
+
/**
|
|
82
|
+
* Fill in defaults; `undefined` fields keep the default. Throws `RangeError` when a turn, slot or byte count or
|
|
83
|
+
* `turnMs` is not a positive finite integer, another field is not a non-negative finite number, or `keepTurns` is not
|
|
84
|
+
* greater than `lead`.
|
|
85
|
+
*/
|
|
86
|
+
export declare function lockstepOptions(options?: Partial<LockstepOptions>): LockstepOptions;
|
|
87
|
+
/** Why the host dropped a member: left (connection lost or left), desync (checksum mismatch), stall, load (timeout). */
|
|
88
|
+
export type DropReason = 'left' | 'desync' | 'stall' | 'load';
|
|
89
|
+
export declare const DROP_REASONS: readonly DropReason[];
|
|
90
|
+
/**
|
|
91
|
+
* Why this peer left the match: a `DropReason` announced by the host, `isolated` (became host but no member reported),
|
|
92
|
+
* `hidden` (the page stayed in the background long enough that the others may have dropped it), or `frozen` (the page
|
|
93
|
+
* froze in the foreground that long).
|
|
94
|
+
*/
|
|
95
|
+
export type SelfDropReason = DropReason | 'isolated' | 'hidden' | 'frozen';
|
|
96
|
+
/** One turn: `c` holds [issuing member, its sequence number, command data] in host order; `drop` lists dropped members. */
|
|
97
|
+
export interface Turn {
|
|
98
|
+
n: number;
|
|
99
|
+
c: [number, number, string][];
|
|
100
|
+
drop?: [number, DropReason][];
|
|
101
|
+
}
|
|
102
|
+
/** Lockstep messages (exchanged between members through the room session). */
|
|
103
|
+
export type LockstepMsg =
|
|
104
|
+
/** member → host: one command */
|
|
105
|
+
{
|
|
106
|
+
k: 'cmd';
|
|
107
|
+
s: number;
|
|
108
|
+
d: string;
|
|
109
|
+
}
|
|
110
|
+
/** host → all */
|
|
111
|
+
| {
|
|
112
|
+
k: 'turn';
|
|
113
|
+
t: Turn;
|
|
114
|
+
}
|
|
115
|
+
/** host → all: waiting for these members (empty: no longer waiting) */
|
|
116
|
+
| {
|
|
117
|
+
k: 'wait';
|
|
118
|
+
ids: number[];
|
|
119
|
+
}
|
|
120
|
+
/** member → host: finished simulating turn n */
|
|
121
|
+
| {
|
|
122
|
+
k: 'at';
|
|
123
|
+
n: number;
|
|
124
|
+
}
|
|
125
|
+
/** member → host: checksum at the end of turn n */
|
|
126
|
+
| {
|
|
127
|
+
k: 'sum';
|
|
128
|
+
n: number;
|
|
129
|
+
v: number;
|
|
130
|
+
}
|
|
131
|
+
/** new host → all: I am the host after migration; the last turn I received is `last` */
|
|
132
|
+
| {
|
|
133
|
+
k: 'mig';
|
|
134
|
+
last: number;
|
|
135
|
+
}
|
|
136
|
+
/** member → new host: a turn the new host lacks, one by one, followed by `rep` */
|
|
137
|
+
| {
|
|
138
|
+
k: 'old';
|
|
139
|
+
t: Turn;
|
|
140
|
+
}
|
|
141
|
+
/** member → new host: last turn received, last turn simulated; run: already running (the old host sent go) */
|
|
142
|
+
| {
|
|
143
|
+
k: 'rep';
|
|
144
|
+
last: number;
|
|
145
|
+
done: number;
|
|
146
|
+
run?: boolean;
|
|
147
|
+
}
|
|
148
|
+
/** the sender spoke as host while our host is still here */
|
|
149
|
+
| {
|
|
150
|
+
k: 'stale';
|
|
151
|
+
}
|
|
152
|
+
/** host → dropped member */
|
|
153
|
+
| {
|
|
154
|
+
k: 'kicked';
|
|
155
|
+
reason: DropReason;
|
|
156
|
+
}
|
|
157
|
+
/** member → host: this peer has loaded */
|
|
158
|
+
| {
|
|
159
|
+
k: 'loaded';
|
|
160
|
+
}
|
|
161
|
+
/** host → all: members that have loaded */
|
|
162
|
+
| {
|
|
163
|
+
k: 'load';
|
|
164
|
+
done: number[];
|
|
165
|
+
}
|
|
166
|
+
/** host → all: everyone loaded, start */
|
|
167
|
+
| {
|
|
168
|
+
k: 'go';
|
|
169
|
+
};
|
|
170
|
+
export interface LockstepHooks {
|
|
171
|
+
/** Deliver a message reliably and in order to one member or to all others (for example over a room sub-channel). */
|
|
172
|
+
send(to: number | 'all', msg: LockstepMsg): void;
|
|
173
|
+
/** The host dropped a member (a turn's `drop`): close the link to it and remove it from the member list. */
|
|
174
|
+
dropped(id: number, reason: DropReason): void;
|
|
175
|
+
/** This peer is out: dropped by the host, isolated, or hidden or frozen too long. Called once; the scheduler is closed. */
|
|
176
|
+
selfDropped(reason: SelfDropReason): void;
|
|
177
|
+
/** The host was silent too long or proved gone: ask the connection layer to treat it as gone (then call `hostChanged`). */
|
|
178
|
+
dropHost(): void;
|
|
179
|
+
/** UI state changed: wait list, migration, loading progress, phase. */
|
|
180
|
+
status(): void;
|
|
181
|
+
}
|
|
182
|
+
export interface LockstepConfig {
|
|
183
|
+
self: number;
|
|
184
|
+
host: number;
|
|
185
|
+
/** Every member at the start of the match, including self. */
|
|
186
|
+
members: number[];
|
|
187
|
+
/**
|
|
188
|
+
* Host-side check of a member's command (for example: may only command its own side; system commands are host-only).
|
|
189
|
+
* The host's own commands and `dropCommands` results are not checked.
|
|
190
|
+
*/
|
|
191
|
+
authorize(from: number, data: string): boolean;
|
|
192
|
+
/**
|
|
193
|
+
* System commands to insert into the same turn that announces a member's drop, including the old host's drop after
|
|
194
|
+
* a migration (reason `left`). Called only on the host (or the peer becoming host). It may be called and its result
|
|
195
|
+
* discarded (when the drop turns out to be announced already), so keep it free of side effects. Default: none.
|
|
196
|
+
*/
|
|
197
|
+
dropCommands?(id: number, reason: DropReason): string[];
|
|
198
|
+
/** Monotonic clock in ms (for example `performance.now`). */
|
|
199
|
+
now(): number;
|
|
200
|
+
options?: Partial<LockstepOptions>;
|
|
201
|
+
}
|
|
202
|
+
export type LockstepPhase = 'loading' | 'running' | 'over';
|
|
203
|
+
export declare class Lockstep {
|
|
204
|
+
private readonly cfg;
|
|
205
|
+
private readonly hooks;
|
|
206
|
+
readonly options: Readonly<LockstepOptions>;
|
|
207
|
+
self: number;
|
|
208
|
+
host: number;
|
|
209
|
+
phase: LockstepPhase;
|
|
210
|
+
/** Members still in the match (including self), changed by the host's verdicts. */
|
|
211
|
+
readonly members: Set<number>;
|
|
212
|
+
/** Members the host halted for (UI: "waiting for ..."). */
|
|
213
|
+
waiting: number[];
|
|
214
|
+
/** Host migration in progress (UI: "host left, switching"). */
|
|
215
|
+
migrating: boolean;
|
|
216
|
+
/** Loading: members that are ready. */
|
|
217
|
+
loaded: Set<number>;
|
|
218
|
+
/** Slots consumed. */
|
|
219
|
+
private slot;
|
|
220
|
+
/** Last turn received in sequence. */
|
|
221
|
+
private recv;
|
|
222
|
+
private readonly turns;
|
|
223
|
+
/** Highest sequence number seen in a turn per member. */
|
|
224
|
+
private readonly seen;
|
|
225
|
+
/** Own commands not yet seen in a turn. */
|
|
226
|
+
private pending;
|
|
227
|
+
private seq;
|
|
228
|
+
private lastHost;
|
|
229
|
+
/** During migration: already reported to the new host (new commands may go to it directly). */
|
|
230
|
+
private reported;
|
|
231
|
+
/** This peer has loaded. */
|
|
232
|
+
private selfReady;
|
|
233
|
+
private closed;
|
|
234
|
+
private hiddenAt;
|
|
235
|
+
/** The page was hidden at some point since the last `update` (a freeze it caused counts as `hidden`). */
|
|
236
|
+
private hiddenSinceUpdate;
|
|
237
|
+
private lastUpdate;
|
|
238
|
+
/** The last freeze `update` noticed (any phase): its length and when it ended. */
|
|
239
|
+
private lastFreeze;
|
|
240
|
+
/** When this peer last sent to everyone (as host: what members measure its silence from). */
|
|
241
|
+
private lastSentAll;
|
|
242
|
+
private nextTurn;
|
|
243
|
+
private inbox;
|
|
244
|
+
/** Highest sequence number accepted (into the inbox or a turn) per member. */
|
|
245
|
+
private accepted;
|
|
246
|
+
private drops;
|
|
247
|
+
private beatAt;
|
|
248
|
+
/** Halted, waiting for someone. */
|
|
249
|
+
private halted;
|
|
250
|
+
/** Accumulated halt time (ms; decays while not halted). */
|
|
251
|
+
private haltMs;
|
|
252
|
+
/** When each member last blocked. */
|
|
253
|
+
private readonly blockedAt;
|
|
254
|
+
private lastCheck;
|
|
255
|
+
private waitSent;
|
|
256
|
+
/** Each member's last finished turn and when it last changed. */
|
|
257
|
+
private readonly progress;
|
|
258
|
+
/** Checksums: turn → member → value. */
|
|
259
|
+
private readonly sums;
|
|
260
|
+
private loadUntil;
|
|
261
|
+
private loadBeat;
|
|
262
|
+
/** New host during migration: members yet to report and the deadline, reported last turns, commands held meanwhile. */
|
|
263
|
+
private mig;
|
|
264
|
+
/** New host: when it became host through migration (-1 when host from the start); `stale` is honoured only within silentMs. */
|
|
265
|
+
private hostSince;
|
|
266
|
+
/** New host: next heartbeat during migration. */
|
|
267
|
+
private migBeat;
|
|
268
|
+
/** New host: members that reported in this migration (their `stale` is honoured too). */
|
|
269
|
+
private readonly reportedBy;
|
|
270
|
+
/** Members that left but whose drop has not appeared in a turn (old hosts etc.): announced by whoever becomes host. */
|
|
271
|
+
private readonly unannounced;
|
|
272
|
+
/** Someone claims to be the new host while ours is still here: hold its messages until ours speaks or stays silent. */
|
|
273
|
+
private claim;
|
|
274
|
+
constructor(cfg: LockstepConfig, hooks: LockstepHooks);
|
|
275
|
+
get isHost(): boolean;
|
|
276
|
+
/** Turns completed (= the next turn to simulate). */
|
|
277
|
+
get turn(): number;
|
|
278
|
+
/** Time (ms) since the last message from the host. */
|
|
279
|
+
hostSilentFor(): number;
|
|
280
|
+
/** Slots that can be advanced right now. */
|
|
281
|
+
available(): number;
|
|
282
|
+
/** A local command: the host puts it in the next turn; a member sends it to the host and keeps a copy. */
|
|
283
|
+
submit(d: string): void;
|
|
284
|
+
/** Commands for the next slot; null when its turn has not arrived (no slot consumed). */
|
|
285
|
+
take(): string[] | null;
|
|
286
|
+
/** Call after advancing a slot: returns the turn number when a turn was just completed (then pass a checksum if `isCheckTurn`). */
|
|
287
|
+
stepped(): number | null;
|
|
288
|
+
/** Whether to compare checksums at the end of turn n (with the default `checkTurns` unless given). */
|
|
289
|
+
static isCheckTurn(n: number, checkTurns?: number): boolean;
|
|
290
|
+
/** Whether to compare checksums at the end of turn n, with this scheduler's `checkTurns`. */
|
|
291
|
+
isCheckTurn(n: number): boolean;
|
|
292
|
+
/** The game's checksum of its world at the end of turn n (an integer). */
|
|
293
|
+
checksum(n: number, v: number): void;
|
|
294
|
+
/** This peer has loaded its world. */
|
|
295
|
+
ready(): void;
|
|
296
|
+
private startRunning;
|
|
297
|
+
/** Host: everyone ready (or timed out), start. */
|
|
298
|
+
private go;
|
|
299
|
+
/** Call every frame (or on a timer). */
|
|
300
|
+
update(): void;
|
|
301
|
+
private hostUpdate;
|
|
302
|
+
/**
|
|
303
|
+
* Leave (`frozen`, or `hidden` when the page was hidden meanwhile) when this peer was out of touch long enough that
|
|
304
|
+
* the others may already have dropped it: carrying on could split the match into two that each believe the other
|
|
305
|
+
* left. Checked in `update`, before acting on a connection layer report, and on the host before handling a message:
|
|
306
|
+
* after a freeze those can be handled before the first `update` (and a host's reply would make it look fresh).
|
|
307
|
+
* - The host is replaced when members hear nothing from it for `silentMs` (or the connection layer's link to it
|
|
308
|
+
* times out, assumed no sooner), so its silence counts from its last broadcast. Unless frozen it broadcasts at
|
|
309
|
+
* least every `loadBeatMs` or so; this also covers a host frozen before its first `update`.
|
|
310
|
+
* - A member is dropped when the host's link to it times out; only a running member's freeze is judged (while
|
|
311
|
+
* loading the link timeout is relaxed and `loadMs` rules), by the time since its last `update`. A connection
|
|
312
|
+
* layer report (`report`) shortly after a freeze also counts that freeze when it ended before the match started:
|
|
313
|
+
* the host may have started meanwhile, restored its link timeout and dropped this member.
|
|
314
|
+
*/
|
|
315
|
+
private leaveIfOutOfTouch;
|
|
316
|
+
private thaw;
|
|
317
|
+
/**
|
|
318
|
+
* The page went to the background / came back: away for `silentMs` or longer drops this peer (`hidden`). When the
|
|
319
|
+
* game's `update` stopped meanwhile, `update` may drop it sooner (see `freezeMarginMs`).
|
|
320
|
+
*/
|
|
321
|
+
visibility(hidden: boolean): void;
|
|
322
|
+
/** This peer's match is over (results screen): stop ordering and stop checking the host's silence. */
|
|
323
|
+
finish(): void;
|
|
324
|
+
close(): void;
|
|
325
|
+
/** Host accepts a command: deduplicate a member's by sequence number (resends are not taken twice) and authorize; own ones are not checked. */
|
|
326
|
+
private accept;
|
|
327
|
+
/** Send the next turn (command data beyond `turnBytes` waits for later turns). */
|
|
328
|
+
private broadcast;
|
|
329
|
+
/** The game's system commands for a drop, sequenced as the host's own. */
|
|
330
|
+
private dropCommands;
|
|
331
|
+
/** Host: announce that `id` is dropped (in the next turn), with the game's drop commands in the same turn. */
|
|
332
|
+
drop(id: number, reason: DropReason): void;
|
|
333
|
+
private setProgress;
|
|
334
|
+
private addSum;
|
|
335
|
+
/** Take a turn (in order only: with a gap it is not taken; the new host fills gaps during migration). */
|
|
336
|
+
private addTurn;
|
|
337
|
+
/** A lockstep message from member `from` (validated here; malformed messages are ignored). */
|
|
338
|
+
receive(from: number, m: LockstepMsg): void;
|
|
339
|
+
private hostReceive;
|
|
340
|
+
/** The connection layer lost a member (host changes go through `hostChanged`): the host drops it, members await the verdict. */
|
|
341
|
+
memberLost(id: number): void;
|
|
342
|
+
/** The connection layer's host changed (the old host is already removed from its member list). */
|
|
343
|
+
hostChanged(id: number): void;
|
|
344
|
+
/** Member: report to the new host, send it the turns it lacks, and resend commands not yet seen in a turn. */
|
|
345
|
+
private reportTo;
|
|
346
|
+
/** New host: once all reports are in (or timed out), resend turns and continue ordering. */
|
|
347
|
+
private finishMigration;
|
|
348
|
+
/** Send to everyone and note when (members measure the host's silence from its messages). */
|
|
349
|
+
private sendAll;
|
|
350
|
+
private setWaiting;
|
|
351
|
+
private die;
|
|
352
|
+
}
|
|
353
|
+
/** Options `frameSteps` reads (defaults from `DEFAULT_LOCKSTEP_OPTIONS`). */
|
|
354
|
+
export type FrameOptions = Pick<LockstepOptions, 'lead' | 'turnTicks' | 'maxFrameSteps'>;
|
|
355
|
+
/** Margin (slots) above which `frameSteps` speeds up to catch up: (lead + 1) × turnTicks. */
|
|
356
|
+
export declare function catchupSlots(options?: Partial<FrameOptions>): number;
|
|
357
|
+
/**
|
|
358
|
+
* How many slots to advance this frame: `acc` is accumulated simulation time (s), `dt` the step length (s), `avail`
|
|
359
|
+
* the slots in hand (`Lockstep.available()`). Pass `lockstep.options` when the scheduler uses non-default options.
|
|
360
|
+
* Returns the steps and the remaining accumulated time.
|
|
361
|
+
*/
|
|
362
|
+
export declare function frameSteps(acc: number, dt: number, avail: number, options?: Partial<FrameOptions>): {
|
|
363
|
+
steps: number;
|
|
364
|
+
acc: number;
|
|
365
|
+
};
|