tickflare 0.0.0-stage → 0.1.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.
Files changed (117) hide show
  1. package/CHANGELOG.md +233 -0
  2. package/LICENSE +21 -0
  3. package/README.md +110 -2
  4. package/dist/binary.d.ts +91 -0
  5. package/dist/binary.js +466 -0
  6. package/dist/binary.js.map +1 -0
  7. package/dist/client/accounts.d.ts +193 -0
  8. package/dist/client/accounts.js +306 -0
  9. package/dist/client/accounts.js.map +1 -0
  10. package/dist/client/draft.d.ts +17 -0
  11. package/dist/client/draft.js +133 -0
  12. package/dist/client/draft.js.map +1 -0
  13. package/dist/client/index.d.ts +161 -0
  14. package/dist/client/index.js +436 -0
  15. package/dist/client/index.js.map +1 -0
  16. package/dist/client/interpolate.d.ts +31 -0
  17. package/dist/client/interpolate.js +59 -0
  18. package/dist/client/interpolate.js.map +1 -0
  19. package/dist/client/lockstep.d.ts +86 -0
  20. package/dist/client/lockstep.js +339 -0
  21. package/dist/client/lockstep.js.map +1 -0
  22. package/dist/client/matchmaking.d.ts +21 -0
  23. package/dist/client/matchmaking.js +55 -0
  24. package/dist/client/matchmaking.js.map +1 -0
  25. package/dist/client/pacer.d.ts +22 -0
  26. package/dist/client/pacer.js +65 -0
  27. package/dist/client/pacer.js.map +1 -0
  28. package/dist/client/predict.d.ts +75 -0
  29. package/dist/client/predict.js +203 -0
  30. package/dist/client/predict.js.map +1 -0
  31. package/dist/client/token.d.ts +10 -0
  32. package/dist/client/token.js +15 -0
  33. package/dist/client/token.js.map +1 -0
  34. package/dist/lockstep.d.ts +154 -0
  35. package/dist/lockstep.js +140 -0
  36. package/dist/lockstep.js.map +1 -0
  37. package/dist/patch.d.ts +54 -0
  38. package/dist/patch.js +186 -0
  39. package/dist/patch.js.map +1 -0
  40. package/dist/protocol.d.ts +230 -0
  41. package/dist/protocol.js +50 -0
  42. package/dist/protocol.js.map +1 -0
  43. package/dist/server/accounts.d.ts +320 -0
  44. package/dist/server/accounts.js +1223 -0
  45. package/dist/server/accounts.js.map +1 -0
  46. package/dist/server/delta.d.ts +50 -0
  47. package/dist/server/delta.js +426 -0
  48. package/dist/server/delta.js.map +1 -0
  49. package/dist/server/frames.d.ts +15 -0
  50. package/dist/server/frames.js +23 -0
  51. package/dist/server/frames.js.map +1 -0
  52. package/dist/server/gateway.d.ts +80 -0
  53. package/dist/server/gateway.js +144 -0
  54. package/dist/server/gateway.js.map +1 -0
  55. package/dist/server/index.d.ts +21 -0
  56. package/dist/server/index.js +22 -0
  57. package/dist/server/index.js.map +1 -0
  58. package/dist/server/limiter.d.ts +12 -0
  59. package/dist/server/limiter.js +43 -0
  60. package/dist/server/limiter.js.map +1 -0
  61. package/dist/server/lockstep.d.ts +126 -0
  62. package/dist/server/lockstep.js +544 -0
  63. package/dist/server/lockstep.js.map +1 -0
  64. package/dist/server/matches.d.ts +31 -0
  65. package/dist/server/matches.js +69 -0
  66. package/dist/server/matches.js.map +1 -0
  67. package/dist/server/matchmaker.d.ts +121 -0
  68. package/dist/server/matchmaker.js +479 -0
  69. package/dist/server/matchmaker.js.map +1 -0
  70. package/dist/server/room.d.ts +383 -0
  71. package/dist/server/room.js +1766 -0
  72. package/dist/server/room.js.map +1 -0
  73. package/dist/server/signals.d.ts +18 -0
  74. package/dist/server/signals.js +37 -0
  75. package/dist/server/signals.js.map +1 -0
  76. package/dist/server/storage.d.ts +117 -0
  77. package/dist/server/storage.js +330 -0
  78. package/dist/server/storage.js.map +1 -0
  79. package/dist/server/tokens.d.ts +74 -0
  80. package/dist/server/tokens.js +117 -0
  81. package/dist/server/tokens.js.map +1 -0
  82. package/dist/server/tracked.d.ts +47 -0
  83. package/dist/server/tracked.js +270 -0
  84. package/dist/server/tracked.js.map +1 -0
  85. package/dist/world.d.ts +20 -0
  86. package/dist/world.js +21 -0
  87. package/dist/world.js.map +1 -0
  88. package/package.json +74 -4
  89. package/src/binary.ts +496 -0
  90. package/src/client/accounts.ts +423 -0
  91. package/src/client/draft.ts +138 -0
  92. package/src/client/index.ts +573 -0
  93. package/src/client/interpolate.ts +60 -0
  94. package/src/client/lockstep.ts +398 -0
  95. package/src/client/matchmaking.ts +61 -0
  96. package/src/client/pacer.ts +67 -0
  97. package/src/client/predict.ts +239 -0
  98. package/src/client/token.ts +22 -0
  99. package/src/lockstep.ts +285 -0
  100. package/src/patch.ts +188 -0
  101. package/src/protocol.ts +260 -0
  102. package/src/server/accounts.ts +1474 -0
  103. package/src/server/delta.ts +467 -0
  104. package/src/server/frames.ts +23 -0
  105. package/src/server/gateway.ts +213 -0
  106. package/src/server/index.ts +85 -0
  107. package/src/server/limiter.ts +41 -0
  108. package/src/server/lockstep.ts +611 -0
  109. package/src/server/matches.ts +99 -0
  110. package/src/server/matchmaker.ts +537 -0
  111. package/src/server/room.ts +1867 -0
  112. package/src/server/signals.ts +46 -0
  113. package/src/server/storage.ts +392 -0
  114. package/src/server/tokens.ts +184 -0
  115. package/src/server/tracked.ts +260 -0
  116. package/src/world.ts +29 -0
  117. package/tools/rooms-report.mjs +168 -0
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Plays items out at a steady pace, however unevenly they arrive.
3
+ *
4
+ * Lockstep turns leave the room at a fixed rate, but a real network delivers
5
+ * them in fits: two together, then a gap. Applying them as they arrive makes
6
+ * the game stutter. The pacer holds a small reserve and releases one item per
7
+ * interval, so the simulation advances evenly. When a hiccup leaves more
8
+ * waiting than the reserve is meant to hold, it plays at double speed until
9
+ * the surplus is gone, instead of keeping it as extra delay for good.
10
+ */
11
+ export class TurnPacer {
12
+ #intervalMs;
13
+ #reserve;
14
+ #play;
15
+ #queue = [];
16
+ #timer;
17
+ /** When the next item is due, in epoch milliseconds. */
18
+ #dueAt = 0;
19
+ /**
20
+ * @param intervalMs time between items at the source
21
+ * @param reserve how many intervals to hold an item back when starting from empty
22
+ * @param play called for each item, in order
23
+ */
24
+ constructor(intervalMs, reserve, play) {
25
+ this.#intervalMs = intervalMs;
26
+ this.#reserve = Math.max(0, reserve);
27
+ this.#play = play;
28
+ }
29
+ push(item) {
30
+ if (this.#reserve === 0) {
31
+ // No reserve asked for: pass straight through.
32
+ this.#play(item);
33
+ return;
34
+ }
35
+ this.#queue.push(item);
36
+ if (this.#timer === undefined) {
37
+ // Starting, or ran dry: build the reserve up again before playing.
38
+ this.#dueAt = Date.now() + this.#intervalMs * this.#reserve;
39
+ this.#arm();
40
+ }
41
+ }
42
+ /** Drop everything waiting and stop. */
43
+ clear() {
44
+ this.#queue = [];
45
+ if (this.#timer !== undefined)
46
+ clearTimeout(this.#timer);
47
+ this.#timer = undefined;
48
+ }
49
+ #arm() {
50
+ this.#timer = setTimeout(() => this.#release(), Math.max(0, this.#dueAt - Date.now()));
51
+ }
52
+ #release() {
53
+ this.#timer = undefined;
54
+ const item = this.#queue.shift();
55
+ // Nothing arrived in time: wait for the next push, which rebuilds the reserve.
56
+ if (item === undefined)
57
+ return;
58
+ this.#play(item);
59
+ // Keep to the clock, not to "now", so timer lateness does not add up.
60
+ const surplus = this.#queue.length > this.#reserve;
61
+ this.#dueAt += surplus ? this.#intervalMs / 2 : this.#intervalMs;
62
+ this.#arm();
63
+ }
64
+ }
65
+ //# sourceMappingURL=pacer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pacer.js","sourceRoot":"","sources":["../../src/client/pacer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,OAAO,SAAS;IACX,WAAW,CAAS;IACpB,QAAQ,CAAS;IACjB,KAAK,CAAoB;IAClC,MAAM,GAAQ,EAAE,CAAC;IACjB,MAAM,CAA4C;IAClD,wDAAwD;IACxD,MAAM,GAAG,CAAC,CAAC;IAEX;;;;OAIG;IACH,YAAY,UAAkB,EAAE,OAAe,EAAE,IAAuB;QACtE,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QACr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,GAAG,IAAI,CAAC,QAAQ,CAAC;QACnD,IAAI,CAAC,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC;QACjE,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,75 @@
1
+ import type { RoomClient } from "./index.js";
2
+ /** How a `Predictor` works out what the room will do with this player's commands. */
3
+ export interface PredictorOptions<View, Command> {
4
+ /**
5
+ * What one of this player's commands does to the state, written the way
6
+ * the room's `onCommand` is: change `state` in place. It is given a draft
7
+ * of the room's state, so the room's state itself is never touched, and
8
+ * `you` is this player's id. If the room would refuse the command, change
9
+ * nothing.
10
+ */
11
+ apply(state: View, command: Command, you: string): void;
12
+ /**
13
+ * What one tick does to what this player controls, written the way the
14
+ * room's `onTick` is. Give it for a game in which a command sets something
15
+ * in motion that the simulation then carries on with, such as a unit that
16
+ * walks to where it was sent: the prediction then runs as far ahead of the
17
+ * room's state as a command takes to come back, and the player's own unit
18
+ * moves the moment they act. Leave the other players' units alone: where
19
+ * they will be is not this player's to know.
20
+ */
21
+ tick?(state: View, you: string): void;
22
+ /**
23
+ * The room's state changed, or a command was sent, applied or refused.
24
+ * With `tick` the prediction also moves on with time: read `state` when
25
+ * you draw, rather than wait for this.
26
+ */
27
+ onState?(state: View): void;
28
+ /** The clock, in milliseconds. Defaults to `Date.now`. */
29
+ now?(): number;
30
+ }
31
+ /**
32
+ * Shows a player the effect of their own commands at once, instead of when
33
+ * the room's answer arrives.
34
+ *
35
+ * `state` is the room's state with this player's unconfirmed commands
36
+ * applied on top, by the `apply` you give. When the room's state arrives it
37
+ * replaces the guess: commands the room has applied are part of it, commands
38
+ * it refused are dropped, and those still on their way are applied again. So
39
+ * a wrong guess lasts until the room's answer, and never longer.
40
+ *
41
+ * const predicted = new Predictor(room, {
42
+ * apply(state, command, you) {
43
+ * if (command.type === "move") state.units[you].target = command.to;
44
+ * },
45
+ * });
46
+ * button.onclick = () => predicted.send({ type: "move", to });
47
+ * draw(predicted.state);
48
+ *
49
+ * Send through `predicted.send`, and draw from `predicted.state` where you
50
+ * drew from `room.state`. Parts of the state the prediction did not change
51
+ * are the same objects as in `room.state`.
52
+ */
53
+ export declare class Predictor<View = unknown, Command = unknown> {
54
+ #private;
55
+ constructor(room: RoomClient<View, Command>, options: PredictorOptions<View, Command>);
56
+ /**
57
+ * The room's state as it will be once the room has applied this player's
58
+ * unconfirmed commands. Undefined until the room's first state arrives.
59
+ */
60
+ get state(): View | undefined;
61
+ /**
62
+ * With `tick`: how many ticks ahead of the room's state the prediction
63
+ * runs, which is how long a command takes to show there. Measured from the
64
+ * commands sent so far; 1 before the first has come back.
65
+ */
66
+ get lead(): number;
67
+ /**
68
+ * Send a command, and show its effect at once. Resolves and rejects as
69
+ * `RoomClient.send` does. If the room refuses the command, its effect is
70
+ * taken back.
71
+ */
72
+ send(command: Command): Promise<void>;
73
+ /** Stop following the room. The room itself stays connected. */
74
+ close(): void;
75
+ }
@@ -0,0 +1,203 @@
1
+ import { produce } from "./draft.js";
2
+ /** How many of the latest frames' arrival times the room's clock is read from. */
3
+ const FRAMES_KEPT = 20;
4
+ /** A frame this much later than the earliest is taken for a room that started ticking again, not for a slow network. */
5
+ const RESTART_MS = 1000;
6
+ /** How many of the latest commands the lead is worked out from. */
7
+ const LEADS_KEPT = 7;
8
+ /**
9
+ * Shows a player the effect of their own commands at once, instead of when
10
+ * the room's answer arrives.
11
+ *
12
+ * `state` is the room's state with this player's unconfirmed commands
13
+ * applied on top, by the `apply` you give. When the room's state arrives it
14
+ * replaces the guess: commands the room has applied are part of it, commands
15
+ * it refused are dropped, and those still on their way are applied again. So
16
+ * a wrong guess lasts until the room's answer, and never longer.
17
+ *
18
+ * const predicted = new Predictor(room, {
19
+ * apply(state, command, you) {
20
+ * if (command.type === "move") state.units[you].target = command.to;
21
+ * },
22
+ * });
23
+ * button.onclick = () => predicted.send({ type: "move", to });
24
+ * draw(predicted.state);
25
+ *
26
+ * Send through `predicted.send`, and draw from `predicted.state` where you
27
+ * drew from `room.state`. Parts of the state the prediction did not change
28
+ * are the same objects as in `room.state`.
29
+ */
30
+ export class Predictor {
31
+ #room;
32
+ #options;
33
+ #stop;
34
+ /** The tick each command of this predictor's was sent at, by the room's reckoning, by command id. */
35
+ #sentAt = new Map();
36
+ /** For the latest frames: when each arrived, less the time its tick stands for. The least is the room's clock. */
37
+ #arrivals = [];
38
+ #lastTick = -1;
39
+ /** How many ticks went by before each of the latest commands showed in the room's state. */
40
+ #leads = [];
41
+ #lead = 1;
42
+ /** The state `onState` was last called with. */
43
+ #told;
44
+ /** The last prediction, and what it was made from. */
45
+ #made;
46
+ constructor(room, options) {
47
+ this.#room = room;
48
+ this.#options = options;
49
+ this.#stop = room.on("state", () => {
50
+ this.#hear();
51
+ this.#changed();
52
+ });
53
+ if (room.state !== undefined)
54
+ this.#hear();
55
+ }
56
+ /**
57
+ * The room's state as it will be once the room has applied this player's
58
+ * unconfirmed commands. Undefined until the room's first state arrives.
59
+ */
60
+ get state() {
61
+ const room = this.#room;
62
+ const base = room.state;
63
+ const pending = room.unconfirmed;
64
+ const { apply, tick } = this.#options;
65
+ const you = room.you ?? "";
66
+ const ticking = tick !== undefined && room.tickRate > 0 && base !== undefined;
67
+ // With `tick`: the prediction is of the tick at which a command sent now would first show.
68
+ let from = 0;
69
+ let to = 0;
70
+ if (ticking) {
71
+ const now = this.#roomTick();
72
+ // If frames have stopped coming, the state is taken to be a few ticks old at most: nothing
73
+ // in this player's view changed in the ticks without a frame.
74
+ from = Math.max(room.tick, now - this.#mostBehind());
75
+ to = now + this.#lead;
76
+ }
77
+ const made = this.#made;
78
+ if (made && made.base === base && made.pending === pending && made.from === from && made.to === to && made.lead === this.#lead) {
79
+ return made.state;
80
+ }
81
+ let state = base;
82
+ if (base !== undefined && (pending.length > 0 || to > from)) {
83
+ state = produce(base, (draft) => {
84
+ let next = 0;
85
+ const applyDue = (before) => {
86
+ while (next < pending.length && (this.#sentAt.get(pending[next].id) ?? 0) + this.#lead <= before) {
87
+ this.#try(() => apply(draft, pending[next].command, you));
88
+ next += 1;
89
+ }
90
+ };
91
+ for (let at = from + 1; at <= to; at++) {
92
+ applyDue(at);
93
+ this.#try(() => tick(draft, you));
94
+ }
95
+ applyDue(Number.POSITIVE_INFINITY);
96
+ });
97
+ }
98
+ this.#made = { base, pending, from, to, lead: this.#lead, state };
99
+ return state;
100
+ }
101
+ /**
102
+ * With `tick`: how many ticks ahead of the room's state the prediction
103
+ * runs, which is how long a command takes to show there. Measured from the
104
+ * commands sent so far; 1 before the first has come back.
105
+ */
106
+ get lead() {
107
+ return this.#lead;
108
+ }
109
+ /**
110
+ * Send a command, and show its effect at once. Resolves and rejects as
111
+ * `RoomClient.send` does. If the room refuses the command, its effect is
112
+ * taken back.
113
+ */
114
+ send(command) {
115
+ const room = this.#room;
116
+ const before = room.unconfirmed;
117
+ const sent = room.send(command);
118
+ // Not sent at all when there is no connection: then there is nothing to predict.
119
+ const id = room.unconfirmed === before ? undefined : room.unconfirmed[room.unconfirmed.length - 1].id;
120
+ const at = Math.max(room.tick, this.#roomTick());
121
+ if (id !== undefined)
122
+ this.#sentAt.set(id, at);
123
+ const settle = (applied) => {
124
+ if (id === undefined)
125
+ return;
126
+ this.#sentAt.delete(id);
127
+ // The room's tick is now the one that first showed the command.
128
+ if (applied && this.#options.tick && room.tickRate > 0)
129
+ this.#learn(room.tick - at);
130
+ this.#changed();
131
+ };
132
+ sent.then(() => settle(true), () => settle(false));
133
+ this.#changed();
134
+ return sent;
135
+ }
136
+ /** Stop following the room. The room itself stays connected. */
137
+ close() {
138
+ this.#stop();
139
+ }
140
+ #changed() {
141
+ const { onState } = this.#options;
142
+ if (!onState)
143
+ return;
144
+ const state = this.state;
145
+ if (state === undefined || state === this.#told)
146
+ return;
147
+ this.#told = state;
148
+ onState(state);
149
+ }
150
+ #try(change) {
151
+ try {
152
+ change();
153
+ }
154
+ catch (err) {
155
+ // A prediction that fails is a prediction not made: the room's answer will show what happened.
156
+ console.warn("[tickflare] a prediction threw, and was left out:", err);
157
+ }
158
+ }
159
+ /** A frame arrived: note when, to tell what tick the room is at between frames. */
160
+ #hear() {
161
+ const room = this.#room;
162
+ if (!this.#options.tick || room.tickRate <= 0 || room.tick === this.#lastTick)
163
+ return;
164
+ this.#lastTick = room.tick;
165
+ const arrival = this.#now() - (room.tick * 1000) / room.tickRate;
166
+ if (this.#arrivals.length > 0 && arrival - Math.min(...this.#arrivals) > RESTART_MS)
167
+ this.#arrivals = [];
168
+ this.#arrivals.push(arrival);
169
+ if (this.#arrivals.length > FRAMES_KEPT)
170
+ this.#arrivals.shift();
171
+ }
172
+ /**
173
+ * The tick the room's latest frame would be of, were one to arrive now.
174
+ * Frames are late by as much as the network holds them up, so the one that
175
+ * was held up least says when ticks happen.
176
+ */
177
+ #roomTick() {
178
+ const room = this.#room;
179
+ if (this.#arrivals.length === 0 || room.tickRate <= 0)
180
+ return room.tick;
181
+ // A hair is added so that the frame the clock was read from is not put a tick early by rounding.
182
+ const ticks = Math.floor(((this.#now() - Math.min(...this.#arrivals)) * room.tickRate) / 1000 + 1e-6);
183
+ return Math.max(room.tick, ticks);
184
+ }
185
+ /** How many ticks without a frame are taken for a frame that is late, rather than for nothing having changed. */
186
+ #mostBehind() {
187
+ return Math.max(2, Math.ceil(this.#room.tickRate / 4));
188
+ }
189
+ /** A command took `ticks` ticks to show in the room's state. The lead is the middle of the latest few. */
190
+ #learn(ticks) {
191
+ if (!Number.isFinite(ticks))
192
+ return;
193
+ this.#leads.push(Math.max(1, Math.min(ticks, 2 * this.#room.tickRate)));
194
+ if (this.#leads.length > LEADS_KEPT)
195
+ this.#leads.shift();
196
+ const sorted = [...this.#leads].sort((a, b) => a - b);
197
+ this.#lead = sorted[Math.floor(sorted.length / 2)];
198
+ }
199
+ #now() {
200
+ return this.#options.now ? this.#options.now() : Date.now();
201
+ }
202
+ }
203
+ //# sourceMapp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C,CAAE,CAAC;IACtD,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;IAC9D,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Where a client gets its join token from. Called before every connection
3
+ * attempt with the id of the room being connected to, so a long session
4
+ * outlives any one token and a token scoped to a room can follow a handover.
5
+ */
6
+ export type TokenSource = (room: string) => string | Promise<string>;
7
+ /** The room a room URL points at: the last segment of its path. */
8
+ export declare function roomIn(url: string): string;
9
+ /** `url` with a token just asked for as its `token` query parameter, replacing any it had. */
10
+ export declare function withFreshToken(url: string, room: string, token: TokenSource): Promise<string>;
@@ -0,0 +1,15 @@
1
+ /** The room a room URL points at: the last segment of its path. */
2
+ export function roomIn(url) {
3
+ return new URL(url).pathname.replace(/\/+$/, "").split("/").pop() ?? "";
4
+ }
5
+ /** `url` with a token just asked for as its `token` query parameter, replacing any it had. */
6
+ export async function withFreshToken(url, room, token) {
7
+ const value = await token(room);
8
+ if (typeof value !== "string" || value === "") {
9
+ throw new TypeError("token() must return a non-empty string");
10
+ }
11
+ const next = new URL(url);
12
+ next.searchParams.set("token", value);
13
+ return next.toString();
14
+ }
15
+ //# sourceMappingURL=token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.js","sourceRoot":"","sources":["../../src/client/token.ts"],"names":[],"mappings":"AAOA,mEAAmE;AACnE,MAAM,UAAU,MAAM,CAAC,GAAW;IAChC,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;AAC1E,CAAC;AAED,8FAA8F;AAC9F,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAW,EAAE,IAAY,EAAE,KAAkB;IAChF,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;QAC9C,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC,CAAC;IAChE,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1B,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACtC,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;AACzB,CAAC"}
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Lockstep: the room does not simulate. It puts everyone's inputs in order,
3
+ * cuts them into numbered turns and sends every player the same turns. Each
4
+ * client runs the same deterministic simulation over them.
5
+ */
6
+ /** One thing that happened in a turn: a player's input, or a player coming or going. */
7
+ export interface TurnEntry<Input = unknown> {
8
+ /** Who it was. */
9
+ player: string;
10
+ /** Their input, as the room's `parseInput` returned it. */
11
+ input?: Input;
12
+ /** Set instead of `input` when the player joined, left, dropped or came back. */
13
+ event?: "join" | "leave" | "disconnect" | "reconnect";
14
+ }
15
+ /** What clients see of a lockstep room. */
16
+ export interface LockstepView<Input = unknown> {
17
+ /** Seed for the simulation's random numbers. The same for every player and every replay. */
18
+ seed: number;
19
+ /** The latest turn. */
20
+ turn: number;
21
+ /** What happened in the latest turn, in the order every client must apply it. */
22
+ entries: TurnEntry<Input>[];
23
+ /** Set once two players reported different hashes for the same turn. */
24
+ desync: {
25
+ /** The first turn two players' hashes differed on. */
26
+ turn: number;
27
+ } | null;
28
+ /**
29
+ * Set to `"players"` by a room whose `turnClock` is `"players"`: the room
30
+ * sleeps between turns, and closes them when a player's client asks.
31
+ */
32
+ clock?: "players";
33
+ /**
34
+ * How many turns go by between snapshots, when the room keeps them: a
35
+ * client whose simulation has `save` and `load` sends one each time the
36
+ * turn is a multiple of this.
37
+ */
38
+ snapshotEvery?: number;
39
+ }
40
+ /**
41
+ * What a room with `turnClock = "players"` sends when it closes turns: turns
42
+ * `n` to `n + c - 1`, all empty but the last, which has `e`.
43
+ */
44
+ export interface TurnsMessage<Input = unknown> {
45
+ /** Marks the message as this one, among any the game sends itself. */
46
+ tickflare: "turns";
47
+ /** The first turn closed. */
48
+ n: number;
49
+ /** How many were closed. */
50
+ c: number;
51
+ /** What happened in the last of them. */
52
+ e: TurnEntry<Input>[];
53
+ /** The player whose request closed them, when it was a request. */
54
+ b?: string;
55
+ }
56
+ /** Everything needed to run a match again: the seed and every turn in which something happened. */
57
+ export interface Replay<Input = unknown> {
58
+ /** Format version. Recordings made before 0.1 are version 1; `runReplay` reads both. */
59
+ v: 2;
60
+ /** The simulation's seed. */
61
+ seed: number;
62
+ /** Turns per second. */
63
+ turnRate: number;
64
+ /** The last turn of the recording. Turns missing from `turns` were empty. */
65
+ turn: number;
66
+ /** Every turn in which something happened, in order, with what happened in it. */
67
+ turns: [turn: number, entries: TurnEntry<Input>[]][];
68
+ }
69
+ /**
70
+ * A simulation as it stood after one turn, saved by a player's client and
71
+ * kept by the room, so that someone joining late starts from it instead of
72
+ * from turn 1.
73
+ */
74
+ export interface Snapshot {
75
+ /** The turn the simulation was at. */
76
+ turn: number;
77
+ /** The simulation's hash at that turn, as the players connected then reported it. */
78
+ hash: string;
79
+ /** What the simulation's `save` returned, as JSON text. */
80
+ data: string;
81
+ }
82
+ /**
83
+ * What a room answers a client that is catching up: the recording, or only
84
+ * the end of it. With `from` set, `turns` has the turns after `from` and
85
+ * nothing earlier: the client continues from the simulation it has, or from
86
+ * `snapshot` when there is one.
87
+ */
88
+ export interface CatchUp<Input = unknown> extends Replay<Input> {
89
+ /** The turn `turns` continues from. Absent when it is the whole recording. */
90
+ from?: number;
91
+ /** A simulation saved at turn `from`, to start from. */
92
+ snapshot?: Snapshot;
93
+ /**
94
+ * Names the run of the room that answered. A client sends it back with
95
+ * the turn its simulation is at, and is given only the turns after that
96
+ * if the room has not restarted since.
97
+ */
98
+ epoch?: string;
99
+ }
100
+ /**
101
+ * A deterministic game: how to start it from a seed and how to advance it by
102
+ * one turn. Clients run it live with `LockstepClient`; `runReplay` runs it
103
+ * over a recording.
104
+ */
105
+ export interface Simulation<Input, Sim> {
106
+ /** Build the simulation at turn 0. Everything random must come from `seed`. */
107
+ create(seed: number): Sim;
108
+ /** Advance by one turn. Must be deterministic: same simulation and entries in, same simulation out. */
109
+ step(sim: Sim, entries: TurnEntry<Input>[], turn: number): void;
110
+ /**
111
+ * The simulation as JSON: everything `step` reads, the random generator's
112
+ * `state` included. With `load`, it lets a player who joins or reloads
113
+ * late start from a recent snapshot instead of from turn 1.
114
+ */
115
+ save?(sim: Sim): unknown;
116
+ /** The simulation `save` was given, rebuilt from what it returned. */
117
+ load?(saved: unknown): Sim;
118
+ }
119
+ /** Runs a recording from the start and returns the simulation as it stands after turn `upTo`. */
120
+ export declare function runReplay<Input, Sim>(replay: Replay<Input>, simulation: Simulation<Input, Sim>, upTo?: number): Sim;
121
+ /**
122
+ * Advances `sim`, which is at turn `from`, to turn `upTo` over a recording.
123
+ * The recording may start anywhere at or before `from`.
124
+ */
125
+ export declare function stepThrough<Input, Sim>(sim: Sim, replay: Replay<Input>, simulation: Simulation<Input, Sim>, from: number, upTo?: number): void;
126
+ /** A generator made by `seededRandom`: call it for the next number in [0, 1). */
127
+ export interface SeededRandom {
128
+ (): number;
129
+ /**
130
+ * Where the generator stands: one whole number. `seededRandom(state)`
131
+ * makes a generator that carries on from here, which is how a simulation's
132
+ * `save` and `load` keep its randomness.
133
+ */
134
+ readonly state: number;
135
+ }
136
+ /**
137
+ * A small deterministic random number generator (mulberry32). `Math.random`
138
+ * differs on every machine; this gives every client the same sequence for the
139
+ * same seed. Returns numbers in [0, 1).
140
+ */
141
+ export declare function seededRandom(seed: number): SeededRandom;
142
+ /**
143
+ * A fingerprint of anything JSON can hold: the first 32 hex digits of the
144
+ * SHA-256 of its JSON text. Two simulations that save to the same JSON have
145
+ * the same one, and nobody can make a different simulation that has it too,
146
+ * which is what makes it the right `hash` for snapshots. It is what
147
+ * `LockstepClient` uses when a simulation has `save` and no `hash`.
148
+ *
149
+ * It reads the whole value each time: about a millisecond for 100 KB of
150
+ * JSON. For a very large simulation, report it less often (`hashEvery`).
151
+ */
152
+ export declare function fingerprint(value: unknown): string;
153
+ /** `fingerprint` of a value whose JSON text is at hand already. */
154
+ export declare function fingerprintOfText(text: string): string;