@series-inc/rundot-syncplay 6.0.0-rc.111 → 6.0.0-rc.112
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/core/runtime.d.ts +7 -1
- package/core/src/physics/physics-profile-wasm-module.generated.mjs +1 -1
- package/core/src/physics/physics-wasm-module.generated.mjs +1 -1
- package/core/src/physics/world.d.mts +0 -2
- package/core/src/physics2d/physics2d-wasm-module.generated.mjs +1 -1
- package/core/world.d.ts +0 -2
- package/dist/api-diagnostics.d.ts +1 -0
- package/dist/authority-room.js +24 -4
- package/dist/local-authority-wire.d.ts +12 -3
- package/dist/local-authority-wire.js +38 -6
- package/dist/networked-client.js +99 -52
- package/dist/physics/3d.js +9 -6
- package/dist/physics/installed-checkpoint3d.d.ts +20 -0
- package/dist/physics/installed-checkpoint3d.js +19 -0
- package/dist/physics/installed-runtime3d.js +5 -5
- package/dist/snapshot-donation-timing.d.ts +13 -1
- package/dist/snapshot-donation-timing.js +24 -3
- package/dist/snapshot-upload.js +3 -3
- package/dist/snapshot-worker.d.ts +46 -5
- package/dist/snapshot-worker.js +231 -83
- package/package.json +4 -4
package/core/runtime.d.ts
CHANGED
|
@@ -10,10 +10,16 @@ export interface KinetixPinnedSnapshot {
|
|
|
10
10
|
release(): void;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Passed to an async snapshot serializer. Hand it to
|
|
15
|
+
* `world.serializeCheckpointAsync` unchanged.
|
|
16
|
+
*/
|
|
13
17
|
export interface SnapshotSerializationWork {
|
|
18
|
+
/** Aborts when the donation is cancelled. */
|
|
14
19
|
readonly signal: AbortSignal;
|
|
15
|
-
|
|
20
|
+
/** Resolves on a later task, to yield the main thread. */
|
|
16
21
|
readonly nextTick: () => Promise<void>;
|
|
22
|
+
/** Measures game packet work that runs after an await. */
|
|
17
23
|
readonly measureGamePacket?: <T>(encode: () => T) => T;
|
|
18
24
|
}
|
|
19
25
|
|
|
@@ -36,7 +36,7 @@ export const physicsProfileWasmMetadata = Object.freeze({
|
|
|
36
36
|
"sourceHash": "4ca971eb52456e0141b37c4700f877b15b776df4be327000ff7a42d0aef106e6",
|
|
37
37
|
"wasmSha256": "4eb4d6848a74b25b5d21c377be92ad1a0d78f1f96f12934ddae683c99a7c0afc",
|
|
38
38
|
"artifact": "profile",
|
|
39
|
-
"packageVersion": "6.0.0-rc.
|
|
39
|
+
"packageVersion": "6.0.0-rc.112",
|
|
40
40
|
"compilerFlags": [
|
|
41
41
|
"-std=c++20",
|
|
42
42
|
"-O3",
|
|
@@ -36,7 +36,7 @@ export const physicsWasmMetadata = Object.freeze({
|
|
|
36
36
|
"sourceHash": "76bbbac134fa1abfc823dc6d324b663da3bcdb80bc09c28fc025736d2d9cc03f",
|
|
37
37
|
"wasmSha256": "19d53336de18d53eed555cd80f25cdb5e9e43c6491c06e93f672be7683737ac7",
|
|
38
38
|
"artifact": "production",
|
|
39
|
-
"packageVersion": "6.0.0-rc.
|
|
39
|
+
"packageVersion": "6.0.0-rc.112",
|
|
40
40
|
"compilerFlags": [
|
|
41
41
|
"-std=c++20",
|
|
42
42
|
"-O3",
|
|
@@ -174,8 +174,6 @@ export interface KinetixNativeRuntimeController {
|
|
|
174
174
|
restoreCheckpoint(checkpoint: KinetixNativeRuntimeCheckpoint): void;
|
|
175
175
|
releaseCheckpoint(checkpoint: KinetixNativeRuntimeCheckpoint): void;
|
|
176
176
|
serializeCheckpoint(checkpoint: KinetixNativeRuntimeCheckpoint): Uint8Array;
|
|
177
|
-
serializeCheckpointTransfer(checkpoint: KinetixNativeRuntimeCheckpoint): Uint8Array;
|
|
178
|
-
stageCheckpointTransfer(checkpoint: KinetixNativeRuntimeCheckpoint): { bytes: Uint8Array; sectionOffset: number };
|
|
179
177
|
digestCheckpoint(checkpoint: KinetixNativeRuntimeCheckpoint): bigint;
|
|
180
178
|
strongDigestCheckpoint(checkpoint: KinetixNativeRuntimeCheckpoint): Uint8Array;
|
|
181
179
|
checkpointInfo(checkpoint: KinetixNativeRuntimeCheckpoint): ReturnType<KinetixNativePhysicsWorld['checkpointInfo']>;
|
|
@@ -50,7 +50,7 @@ export const physics2dWasmMetadata = Object.freeze({
|
|
|
50
50
|
"sourceHash": "b4ae2139eb68bf6c797af143c07cec8b80e732662f9f9cda219bf76de63e0934",
|
|
51
51
|
"wasmSha256": "633aeb98cb199b120cc7b5a855a620e01ab73d5cd8b6427cb7949eafecfdf1f0",
|
|
52
52
|
"artifact": "production",
|
|
53
|
-
"packageVersion": "6.0.0-rc.
|
|
53
|
+
"packageVersion": "6.0.0-rc.112",
|
|
54
54
|
"compilerFlags": [
|
|
55
55
|
"-std=c++20",
|
|
56
56
|
"-O3",
|
package/core/world.d.ts
CHANGED
|
@@ -897,8 +897,6 @@ export interface KinetixNativePhysicsWorld {
|
|
|
897
897
|
captureCheckpoint(): KinetixNativeWorldCheckpoint;
|
|
898
898
|
restoreCheckpoint(checkpoint: KinetixNativeWorldCheckpoint): void;
|
|
899
899
|
serializeCheckpoint(checkpoint: KinetixNativeWorldCheckpoint): Uint8Array;
|
|
900
|
-
serializeCheckpointTransfer(checkpoint: KinetixNativeWorldCheckpoint): Uint8Array;
|
|
901
|
-
stageCheckpointTransfer(checkpoint: KinetixNativeWorldCheckpoint): { bytes: Uint8Array; sectionOffset: number };
|
|
902
900
|
/**
|
|
903
901
|
* The latest outputs of the frame of the checkpoint. `hitEventThreshold` is the threshold that the checkpoint
|
|
904
902
|
* stores; a hit selection of these rows uses it, not the live threshold of the world.
|
|
@@ -8,6 +8,7 @@ export interface SnapshotDonationDiagnostic {
|
|
|
8
8
|
readonly gameSerializerMs: number;
|
|
9
9
|
readonly compressionMs: number;
|
|
10
10
|
readonly digestMs: number;
|
|
11
|
+
readonly digestWaitMs: number;
|
|
11
12
|
readonly longestMainThreadTaskMs: number;
|
|
12
13
|
readonly rawBytes: number;
|
|
13
14
|
readonly outputBytes: number;
|
package/dist/authority-room.js
CHANGED
|
@@ -2,7 +2,7 @@ import { canonicalStringify, defaultChecksum, encodeUtf8 } from './canonical.js'
|
|
|
2
2
|
import { assertKinetixRuntimeIdentity, kinetixRuntimeIdentitiesEqual as equalRuntimeIdentity, kinetixSessionConfigDigest, } from '@series-inc/rundot-syncplay/core/runtime';
|
|
3
3
|
import { invariant } from './errors.js';
|
|
4
4
|
import { createInputAuthority } from './input-authority.js';
|
|
5
|
-
import { createBinaryDeterministicLocalAuthoritySnapshotChunkEnvelope, createBinaryDeterministicLocalAuthoritySnapshotCompleteEnvelope, createBinaryDeterministicLocalAuthoritySnapshotOfferEnvelope, createBinaryDeterministicLocalAuthoritySnapshotRequestEnvelope, createDeterministicLocalAuthoritySnapshotChunkEnvelope, createDeterministicLocalAuthoritySnapshotCompleteEnvelope, createDeterministicLocalAuthoritySnapshotOfferEnvelope, createDeterministicLocalAuthoritySnapshotRequestEnvelope, decodeBinaryDeterministicLocalAuthorityWireEnvelope, decodeDeterministicLocalAuthorityWireEnvelope, } from './local-authority-wire.js';
|
|
5
|
+
import { createBinaryDeterministicLocalAuthoritySnapshotChunkEnvelope, createBinaryDeterministicLocalAuthoritySnapshotCompleteEnvelope, createBinaryDeterministicLocalAuthoritySnapshotOfferEnvelope, createBinaryDeterministicLocalAuthoritySnapshotRefusalEnvelope, createBinaryDeterministicLocalAuthoritySnapshotRequestEnvelope, createDeterministicLocalAuthoritySnapshotChunkEnvelope, createDeterministicLocalAuthoritySnapshotCompleteEnvelope, createDeterministicLocalAuthoritySnapshotOfferEnvelope, createDeterministicLocalAuthoritySnapshotRefusalEnvelope, createDeterministicLocalAuthoritySnapshotRequestEnvelope, decodeBinaryDeterministicLocalAuthorityWireEnvelope, decodeDeterministicLocalAuthorityWireEnvelope, } from './local-authority-wire.js';
|
|
6
6
|
import { DEFAULT_BINARY_SNAPSHOT_CHUNK_SIZE, snapshotHydratedByteLimit, DEFAULT_MAX_SNAPSHOT_BYTES, DEFAULT_SNAPSHOT_CHUNK_SIZE, TEXT_COMPRESSED_SNAPSHOT_PREFIX, createBinarySnapshotTransferFromBytes, createSnapshotTransferCollector, createSnapshotTransferFromBytes, decodeDeterministicStateSnapshotInternal, encodeDeterministicStateSnapshot, encodeTextWrappedBinarySnapshot, deterministicRoomDescriptorHash, restampBinarySnapshotWitnesses, } from './session-snapshot.js';
|
|
7
7
|
import { MAX_KINETIX_SESSION_CONFIG_BYTES, MAX_SYNCPLAY_COMMAND_PAYLOAD_BYTES, MAX_SYNCPLAY_EPHEMERAL_PAYLOAD_BYTES, decodeDeterministicSessionMessage, encodeDeterministicSessionMessage, } from './session-wire.js';
|
|
8
8
|
import { createSyncplaySecretAuthority, } from './secret-authority.js';
|
|
@@ -138,6 +138,15 @@ export function createDeterministicAuthorityRoom(transport, config) {
|
|
|
138
138
|
}
|
|
139
139
|
const sessionMsgType = config.sessionMsgType ?? DEFAULT_SESSION_MSG_TYPE;
|
|
140
140
|
const binarySessionMsgType = config.binarySessionMsgType ?? `${sessionMsgType}-bin`;
|
|
141
|
+
/**
|
|
142
|
+
* The largest snapshot the room stores. A snapshot request carries it only when it is not the default. The
|
|
143
|
+
* default equals the client's default, so a room at the default limit sends no field and its messages stay as
|
|
144
|
+
* before. A host that builds the room from the snapshot policy always sets the limit, often to the default.
|
|
145
|
+
*/
|
|
146
|
+
const storedSnapshotLimitBytes = config.maxSnapshotBytes ?? DEFAULT_MAX_SNAPSHOT_BYTES;
|
|
147
|
+
const requestSnapshotLimitBytes = storedSnapshotLimitBytes === DEFAULT_MAX_SNAPSHOT_BYTES
|
|
148
|
+
? undefined
|
|
149
|
+
: storedSnapshotLimitBytes;
|
|
141
150
|
const historyRetentionTicks = requireTickCount('historyRetentionTicks', config.historyRetentionTicks ?? DEFAULT_HISTORY_RETENTION_TICKS);
|
|
142
151
|
// The ring keeps at least four redundancy windows, see createSessionAuthority.
|
|
143
152
|
const historyRingTicks = Math.max(historyRetentionTicks, config.redundancyWindowTicks * 4);
|
|
@@ -1920,7 +1929,7 @@ export function createDeterministicAuthorityRoom(transport, config) {
|
|
|
1920
1929
|
}
|
|
1921
1930
|
}
|
|
1922
1931
|
const isBinaryTransfer = collected.binarySnapshotBytes !== undefined;
|
|
1923
|
-
const effectiveMaxSnapshotBytes =
|
|
1932
|
+
const effectiveMaxSnapshotBytes = storedSnapshotLimitBytes;
|
|
1924
1933
|
if (decoded.source.kind === 'raw-binary' || decoded.source.kind === 'wrapped-binary') {
|
|
1925
1934
|
const rawBinary = decoded.source.binarySnapshotBytes;
|
|
1926
1935
|
const binarySnapshotBytes = snapshot.v === 3
|
|
@@ -1998,6 +2007,9 @@ export function createDeterministicAuthorityRoom(transport, config) {
|
|
|
1998
2007
|
return;
|
|
1999
2008
|
const failed = pendingTransfer;
|
|
2000
2009
|
pendingTransfer = undefined;
|
|
2010
|
+
// Tell the donor, so it does not upload a snapshot that the room cannot store.
|
|
2011
|
+
if (reason === 'snapshot-too-large' && options?.donorGone !== true)
|
|
2012
|
+
refuseDonorTransfer(failed, reason);
|
|
2001
2013
|
lastSnapshotRejection = reason;
|
|
2002
2014
|
rejectionsSinceStore.add(reason);
|
|
2003
2015
|
if (options?.donorGone === true) {
|
|
@@ -2015,6 +2027,14 @@ export function createDeterministicAuthorityRoom(transport, config) {
|
|
|
2015
2027
|
config.onSnapshotEvent?.({ kind: 'rejected', donorId: failed.donorId, reason });
|
|
2016
2028
|
beginSnapshotAcquisition(true);
|
|
2017
2029
|
}
|
|
2030
|
+
function refuseDonorTransfer(failed, reason) {
|
|
2031
|
+
const identity = { descriptorHash: roomDescriptorHash, configHash: failed.transferRequestId };
|
|
2032
|
+
if (transport.sendBinaryTo !== undefined && binaryCapablePlayers.has(failed.donorId)) {
|
|
2033
|
+
transport.sendBinaryTo(failed.donorId, binarySessionMsgType, createBinaryDeterministicLocalAuthoritySnapshotRefusalEnvelope(nextWireSequence(), identity, reason, storedSnapshotLimitBytes));
|
|
2034
|
+
return;
|
|
2035
|
+
}
|
|
2036
|
+
transport.sendTo(failed.donorId, sessionMsgType, createDeterministicLocalAuthoritySnapshotRefusalEnvelope(nextWireSequence(), identity, reason, storedSnapshotLimitBytes));
|
|
2037
|
+
}
|
|
2018
2038
|
/**
|
|
2019
2039
|
* Start a snapshot transfer to the best target that has a donor left. A
|
|
2020
2040
|
* (tick, donor) pair that failed stays failed until a snapshot is stored,
|
|
@@ -2074,10 +2094,10 @@ export function createDeterministicAuthorityRoom(transport, config) {
|
|
|
2074
2094
|
const requestIdentity = { descriptorHash: roomDescriptorHash, configHash: transferRequestId };
|
|
2075
2095
|
const transferBudgetMs = pendingTransfer.timeoutTicks * 1000 / config.tickRateHz;
|
|
2076
2096
|
if (transport.sendBinaryTo !== undefined && binaryCapablePlayers.has(donorId)) {
|
|
2077
|
-
transport.sendBinaryTo(donorId, binarySessionMsgType, createBinaryDeterministicLocalAuthoritySnapshotRequestEnvelope(nextWireSequence(), requestIdentity, tick + 1, transferBudgetMs));
|
|
2097
|
+
transport.sendBinaryTo(donorId, binarySessionMsgType, createBinaryDeterministicLocalAuthoritySnapshotRequestEnvelope(nextWireSequence(), requestIdentity, tick + 1, transferBudgetMs, requestSnapshotLimitBytes));
|
|
2078
2098
|
return;
|
|
2079
2099
|
}
|
|
2080
|
-
transport.sendTo(donorId, sessionMsgType, createDeterministicLocalAuthoritySnapshotRequestEnvelope(nextWireSequence(), requestIdentity, tick + 1, transferBudgetMs));
|
|
2100
|
+
transport.sendTo(donorId, sessionMsgType, createDeterministicLocalAuthoritySnapshotRequestEnvelope(nextWireSequence(), requestIdentity, tick + 1, transferBudgetMs, requestSnapshotLimitBytes));
|
|
2081
2101
|
}
|
|
2082
2102
|
/**
|
|
2083
2103
|
* The newest fully reported tick above the stored snapshot that has a donor
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare const deterministicLocalAuthorityWireProtocol = "rdm-local-authority/v2";
|
|
2
2
|
export declare const deterministicLocalAuthorityBinaryWireMagic = "SYNWIR02";
|
|
3
|
-
export type DeterministicLocalAuthorityWireKind = 'snapshot-request' | 'snapshot-offer' | 'snapshot-chunk' | 'snapshot-complete'
|
|
3
|
+
export type DeterministicLocalAuthorityWireKind = 'snapshot-request' | 'snapshot-offer' | 'snapshot-chunk' | 'snapshot-complete'
|
|
4
|
+
/** Room to donor: the room refused this transfer. Since 6.0.0-rc.112. */
|
|
5
|
+
| 'snapshot-refusal';
|
|
4
6
|
export interface DeterministicLocalAuthoritySnapshotIdentity {
|
|
5
7
|
readonly descriptorHash: string;
|
|
6
8
|
readonly schemaHash?: string;
|
|
@@ -48,8 +50,15 @@ export declare function encodeBinaryDeterministicLocalAuthorityWireEnvelope(enve
|
|
|
48
50
|
export declare function frameBinaryWireSteps(kindCode: number, sequence: number, headerBytes: Uint8Array, chunk?: Uint8Array): Generator<void, Uint8Array>;
|
|
49
51
|
export declare const binarySnapshotChunkKindCode: number;
|
|
50
52
|
export declare function decodeBinaryDeterministicLocalAuthorityWireEnvelope(encoded: Uint8Array): DeterministicLocalAuthorityWireEnvelope;
|
|
51
|
-
export declare function createDeterministicLocalAuthoritySnapshotRequestEnvelope(sequence: number, identity: DeterministicLocalAuthoritySnapshotIdentity, minFrame: number, transferBudgetMs?: number): string;
|
|
52
|
-
export declare function createBinaryDeterministicLocalAuthoritySnapshotRequestEnvelope(sequence: number, identity: DeterministicLocalAuthoritySnapshotIdentity, minFrame: number, transferBudgetMs?: number): Uint8Array;
|
|
53
|
+
export declare function createDeterministicLocalAuthoritySnapshotRequestEnvelope(sequence: number, identity: DeterministicLocalAuthoritySnapshotIdentity, minFrame: number, transferBudgetMs?: number, maxSnapshotBytes?: number): string;
|
|
54
|
+
export declare function createBinaryDeterministicLocalAuthoritySnapshotRequestEnvelope(sequence: number, identity: DeterministicLocalAuthoritySnapshotIdentity, minFrame: number, transferBudgetMs?: number, maxSnapshotBytes?: number): Uint8Array;
|
|
55
|
+
/**
|
|
56
|
+
* Room to donor: the room refused the transfer of the request with this
|
|
57
|
+
* identity, so the donor stops uploading it. Since 6.0.0-rc.112. An older
|
|
58
|
+
* client ignores the unknown kind.
|
|
59
|
+
*/
|
|
60
|
+
export declare function createDeterministicLocalAuthoritySnapshotRefusalEnvelope(sequence: number, identity: DeterministicLocalAuthoritySnapshotIdentity, reason: string, maxSnapshotBytes: number): string;
|
|
61
|
+
export declare function createBinaryDeterministicLocalAuthoritySnapshotRefusalEnvelope(sequence: number, identity: DeterministicLocalAuthoritySnapshotIdentity, reason: string, maxSnapshotBytes: number): Uint8Array;
|
|
53
62
|
export declare function createDeterministicLocalAuthoritySnapshotOfferEnvelope(sequence: number, transfer: DeterministicLocalAuthoritySnapshotTransfer): string;
|
|
54
63
|
export declare function createBinaryDeterministicLocalAuthoritySnapshotOfferEnvelope(sequence: number, transfer: DeterministicLocalAuthorityBinarySnapshotTransfer): Uint8Array;
|
|
55
64
|
export declare function createDeterministicLocalAuthoritySnapshotChunkEnvelope(sequence: number, transfer: DeterministicLocalAuthoritySnapshotTransfer, chunkIndex: number): string;
|
|
@@ -17,18 +17,21 @@ const KIND_TO_CODE = {
|
|
|
17
17
|
'snapshot-offer': 2,
|
|
18
18
|
'snapshot-chunk': 3,
|
|
19
19
|
'snapshot-complete': 4,
|
|
20
|
+
'snapshot-refusal': 5,
|
|
20
21
|
};
|
|
21
22
|
const CODE_TO_KIND = {
|
|
22
23
|
1: 'snapshot-request',
|
|
23
24
|
2: 'snapshot-offer',
|
|
24
25
|
3: 'snapshot-chunk',
|
|
25
26
|
4: 'snapshot-complete',
|
|
27
|
+
5: 'snapshot-refusal',
|
|
26
28
|
};
|
|
27
29
|
const kinds = new Set([
|
|
28
30
|
'snapshot-request',
|
|
29
31
|
'snapshot-offer',
|
|
30
32
|
'snapshot-chunk',
|
|
31
33
|
'snapshot-complete',
|
|
34
|
+
'snapshot-refusal',
|
|
32
35
|
]);
|
|
33
36
|
export function encodeDeterministicLocalAuthorityWireEnvelope(envelope) {
|
|
34
37
|
assertSequence(envelope.sequence);
|
|
@@ -236,22 +239,51 @@ export function decodeBinaryDeterministicLocalAuthorityWireEnvelope(encoded) {
|
|
|
236
239
|
checksum: expectedDigest.toString(16).padStart(8, '0'),
|
|
237
240
|
};
|
|
238
241
|
}
|
|
239
|
-
|
|
242
|
+
/**
|
|
243
|
+
* `maxSnapshotBytes` (since 6.0.0-rc.112) is the room's stored snapshot
|
|
244
|
+
* limit. A donor without a Worker uses it to choose a payload that fits.
|
|
245
|
+
*/
|
|
246
|
+
function snapshotRequestPayload(identity, minFrame, transferBudgetMs, maxSnapshotBytes) {
|
|
240
247
|
assertIdentity(identity);
|
|
241
248
|
assertFrame(minFrame);
|
|
249
|
+
if (maxSnapshotBytes !== undefined && (!Number.isSafeInteger(maxSnapshotBytes) || maxSnapshotBytes < 1)) {
|
|
250
|
+
throw new Error('Syncplay snapshot request maxSnapshotBytes must be a positive integer');
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
identity, minFrame,
|
|
254
|
+
...(transferBudgetMs === undefined ? {} : { transferBudgetMs }),
|
|
255
|
+
...(maxSnapshotBytes === undefined ? {} : { maxSnapshotBytes }),
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
export function createDeterministicLocalAuthoritySnapshotRequestEnvelope(sequence, identity, minFrame, transferBudgetMs, maxSnapshotBytes) {
|
|
242
259
|
return encodeDeterministicLocalAuthorityWireEnvelope({
|
|
243
260
|
kind: 'snapshot-request',
|
|
244
261
|
sequence,
|
|
245
|
-
payload:
|
|
262
|
+
payload: snapshotRequestPayload(identity, minFrame, transferBudgetMs, maxSnapshotBytes),
|
|
246
263
|
});
|
|
247
264
|
}
|
|
248
|
-
export function createBinaryDeterministicLocalAuthoritySnapshotRequestEnvelope(sequence, identity, minFrame, transferBudgetMs) {
|
|
249
|
-
assertIdentity(identity);
|
|
250
|
-
assertFrame(minFrame);
|
|
265
|
+
export function createBinaryDeterministicLocalAuthoritySnapshotRequestEnvelope(sequence, identity, minFrame, transferBudgetMs, maxSnapshotBytes) {
|
|
251
266
|
return encodeBinaryDeterministicLocalAuthorityWireEnvelope({
|
|
252
267
|
kind: 'snapshot-request',
|
|
253
268
|
sequence,
|
|
254
|
-
payload:
|
|
269
|
+
payload: snapshotRequestPayload(identity, minFrame, transferBudgetMs, maxSnapshotBytes),
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Room to donor: the room refused the transfer of the request with this
|
|
274
|
+
* identity, so the donor stops uploading it. Since 6.0.0-rc.112. An older
|
|
275
|
+
* client ignores the unknown kind.
|
|
276
|
+
*/
|
|
277
|
+
export function createDeterministicLocalAuthoritySnapshotRefusalEnvelope(sequence, identity, reason, maxSnapshotBytes) {
|
|
278
|
+
assertIdentity(identity);
|
|
279
|
+
return encodeDeterministicLocalAuthorityWireEnvelope({
|
|
280
|
+
kind: 'snapshot-refusal', sequence, payload: { identity, reason, maxSnapshotBytes },
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
export function createBinaryDeterministicLocalAuthoritySnapshotRefusalEnvelope(sequence, identity, reason, maxSnapshotBytes) {
|
|
284
|
+
assertIdentity(identity);
|
|
285
|
+
return encodeBinaryDeterministicLocalAuthorityWireEnvelope({
|
|
286
|
+
kind: 'snapshot-refusal', sequence, payload: { identity, reason, maxSnapshotBytes },
|
|
255
287
|
});
|
|
256
288
|
}
|
|
257
289
|
export function createDeterministicLocalAuthoritySnapshotOfferEnvelope(sequence, transfer) {
|
package/dist/networked-client.js
CHANGED
|
@@ -3,14 +3,14 @@ import { canonicalStringify, cloneCanonical, encodeUtf8 } from './canonical.js';
|
|
|
3
3
|
import { sha256Hex } from '@series-inc/rundot-syncplay/core/runtime';
|
|
4
4
|
import { SyncplayError } from './errors.js';
|
|
5
5
|
import { createSnapshotSlicePacing, DEFAULT_SNAPSHOT_SLICE_BUDGET_MS, nextSnapshotTask } from './snapshot-schedule.js';
|
|
6
|
-
import { prepareDonorUpload, releaseSnapshotWorkerBaseline, SnapshotWorkerFailure, warmSnapshotWorker } from './snapshot-worker.js';
|
|
6
|
+
import { encodeDonorSnapshotOffThread, prepareDonorUpload, releaseSnapshotWorkerBaseline, SnapshotWorkerFailure, warmSnapshotWorker, } from './snapshot-worker.js';
|
|
7
7
|
import { digestSnapshotBytes } from './snapshot-upload.js';
|
|
8
8
|
import { parseSyncplayChecksumPolicy, SYNCPLAY_DEFAULT_CHECKSUM_CADENCE_TICKS } from './checksum-policy.js';
|
|
9
9
|
import { createApiDiagnostics, emitSyncplayDiagnostic } from './api-diagnostics.js';
|
|
10
10
|
import { createBinaryDeterministicLocalAuthoritySnapshotChunkEnvelope, createBinaryDeterministicLocalAuthoritySnapshotCompleteEnvelope, createBinaryDeterministicLocalAuthoritySnapshotOfferEnvelope, createDeterministicLocalAuthoritySnapshotChunkEnvelope, createDeterministicLocalAuthoritySnapshotCompleteEnvelope, createDeterministicLocalAuthoritySnapshotOfferEnvelope, decodeBinaryDeterministicLocalAuthorityWireEnvelope, encodeBinaryDeterministicLocalAuthorityWireEnvelope, encodeDeterministicLocalAuthorityWireEnvelope, decodeDeterministicLocalAuthorityWireEnvelope, } from './local-authority-wire.js';
|
|
11
|
-
import { DEFAULT_BINARY_SNAPSHOT_CHUNK_SIZE, DEFAULT_SNAPSHOT_CHUNK_SIZE, TEXT_COMPRESSED_SNAPSHOT_PREFIX, snapshotHydratedByteLimit, createBinarySnapshotTransferFromBytes, createSnapshotTransferCollector, createSnapshotTransferFromBytes, decodeDeterministicStateSnapshotInternal, deterministicRoomDescriptorHash, encodeBinaryDeterministicStateSnapshot,
|
|
11
|
+
import { DEFAULT_BINARY_SNAPSHOT_CHUNK_SIZE, DEFAULT_MAX_SNAPSHOT_BYTES, DEFAULT_SNAPSHOT_CHUNK_SIZE, TEXT_COMPRESSED_SNAPSHOT_PREFIX, snapshotHydratedByteLimit, createBinarySnapshotTransferFromBytes, createSnapshotTransferCollector, createSnapshotTransferFromBytes, decodeDeterministicStateSnapshotInternal, deterministicRoomDescriptorHash, encodeBinaryDeterministicStateSnapshot, encodeTextWrappedBinarySnapshot, } from './session-snapshot.js';
|
|
12
12
|
import { DEFAULT_BASELINE_PAGE_BYTES, decodeSnapshotBaselineDelta, encodeSnapshotBaselineDelta, isBaselineDeltaSnapshotBytes, } from './snapshot-baseline-delta.js';
|
|
13
|
-
import { installedPhysicsRuntimes3D, physicsTransferBaselines3D, legacyVoxelPageDiffRuntimes3D } from './physics/installed-checkpoint3d.js';
|
|
13
|
+
import { attachSnapshotWorkDigest, installedPhysicsRuntimes3D, physicsTransferBaselines3D, legacyVoxelPageDiffRuntimes3D, } from './physics/installed-checkpoint3d.js';
|
|
14
14
|
import { MAX_SYNCPLAY_COMMAND_PAYLOAD_BYTES, decodeDeterministicSessionMessage, encodeDeterministicSessionMessage, } from './session-wire.js';
|
|
15
15
|
import { acquireRuntime, acquireRuntimeResult, invokeRuntimeFactory, isRuntimeFactoryPromise, } from './runtime-lease.js';
|
|
16
16
|
import { createOwnedSyncplaySession } from './sdk-session.js';
|
|
@@ -647,11 +647,19 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
647
647
|
code: 'snapshot.donor', key, message, replacement: '', migration: '',
|
|
648
648
|
});
|
|
649
649
|
}
|
|
650
|
-
function reportWorkerFallback() {
|
|
650
|
+
function reportWorkerFallback(fallback, tick) {
|
|
651
|
+
const replaced = fallback.replaced === undefined ? ''
|
|
652
|
+
: ` The staged checkpoint in LZ4 slices was ${fallback.replaced.outputBytes} bytes, over the`
|
|
653
|
+
+ ` ${fallback.replaced.limitBytes}-byte snapshot limit, so the donor sent its synchronous export instead.`;
|
|
654
|
+
// Report each replacement: it costs one long main-thread task.
|
|
655
|
+
if (fallback.replaced !== undefined && donorEncodingPath === 'sliced') {
|
|
656
|
+
donorDiagnostic('snapshot.synchronous-export', `Syncplay stored a ${fallback.outputBytes}-byte snapshot at tick ${tick} without a Worker.${replaced}`);
|
|
657
|
+
}
|
|
651
658
|
if (donorEncodingPath === 'sliced')
|
|
652
659
|
return;
|
|
653
660
|
donorEncodingPath = 'sliced';
|
|
654
|
-
donorDiagnostic('snapshot.worker-unavailable', 'Syncplay snapshot Worker is unavailable. Snapshot encoding will use main-thread slices.'
|
|
661
|
+
donorDiagnostic('snapshot.worker-unavailable', 'Syncplay snapshot Worker is unavailable. Snapshot encoding will use main-thread slices.'
|
|
662
|
+
+ ` The snapshot at tick ${tick} stored ${fallback.outputBytes} bytes from a ${fallback.payloadBytes}-byte payload.${replaced}`);
|
|
655
663
|
}
|
|
656
664
|
function releaseDonorPin(pin) {
|
|
657
665
|
try {
|
|
@@ -736,7 +744,7 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
736
744
|
return job;
|
|
737
745
|
}
|
|
738
746
|
function retainTickZeroBaseline(active) {
|
|
739
|
-
if (
|
|
747
|
+
if (!baselineDeltaEnabled
|
|
740
748
|
|| tickZeroBaseline !== undefined
|
|
741
749
|
|| tickZeroBaselinePin !== undefined
|
|
742
750
|
|| tickZeroBaselinePromise !== undefined
|
|
@@ -753,7 +761,7 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
753
761
|
tickZeroBaselineFailed = true;
|
|
754
762
|
}
|
|
755
763
|
}
|
|
756
|
-
function captureTickZeroBaselineIfNeeded(forLegacyRestore = false
|
|
764
|
+
function captureTickZeroBaselineIfNeeded(forLegacyRestore = false) {
|
|
757
765
|
if ((!baselineDeltaEnabled && !forLegacyRestore)
|
|
758
766
|
|| tickZeroBaseline !== undefined
|
|
759
767
|
|| tickZeroBaselineFailed
|
|
@@ -764,10 +772,6 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
764
772
|
return;
|
|
765
773
|
}
|
|
766
774
|
if (session.peekSnapshot(0) !== undefined) {
|
|
767
|
-
if (preferAsyncPin) {
|
|
768
|
-
void ensureAsyncTickZeroBaseline(session);
|
|
769
|
-
return;
|
|
770
|
-
}
|
|
771
775
|
try {
|
|
772
776
|
const bytes = session.getSnapshotBytes(0);
|
|
773
777
|
if ((!forLegacyRestore && bytes.byteLength < DEFAULT_BASELINE_PAGE_BYTES)
|
|
@@ -785,9 +789,7 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
785
789
|
}
|
|
786
790
|
if (forLegacyRestore && tickZeroBaselinePin !== undefined) {
|
|
787
791
|
try {
|
|
788
|
-
const serialized =
|
|
789
|
-
? tickZeroBaselinePin.serializeSynchronously()
|
|
790
|
-
: tickZeroBaselinePin.serialize();
|
|
792
|
+
const serialized = tickZeroBaselinePin.serialize();
|
|
791
793
|
if (!(serialized instanceof Uint8Array)) {
|
|
792
794
|
const pin = tickZeroBaselinePin;
|
|
793
795
|
tickZeroBaselinePin = undefined;
|
|
@@ -825,10 +827,13 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
825
827
|
}
|
|
826
828
|
}
|
|
827
829
|
}
|
|
830
|
+
function isGenericOwnedRuntime(runtime) {
|
|
831
|
+
return runtime.capabilities?.ownership === 'lease'
|
|
832
|
+
&& runtime.serializeCheckpointBaselineDelta === undefined
|
|
833
|
+
&& !installedPhysicsRuntimes3D.has(runtime);
|
|
834
|
+
}
|
|
828
835
|
function usesGenericOwnedSnapshotCodec() {
|
|
829
|
-
return activeRuntime
|
|
830
|
-
&& activeRuntime.serializeCheckpointBaselineDelta === undefined
|
|
831
|
-
&& !installedPhysicsRuntimes3D.has(activeRuntime);
|
|
836
|
+
return activeRuntime !== undefined && isGenericOwnedRuntime(activeRuntime);
|
|
832
837
|
}
|
|
833
838
|
function handleEvictFrameZero() {
|
|
834
839
|
if (session === undefined)
|
|
@@ -843,10 +848,9 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
843
848
|
retainTickZeroBaseline(session);
|
|
844
849
|
return;
|
|
845
850
|
}
|
|
846
|
-
|
|
847
|
-
|
|
851
|
+
// A generic owned runtime sends full snapshots only, so it keeps no frame-zero baseline and no pin.
|
|
852
|
+
if (usesGenericOwnedSnapshotCodec())
|
|
848
853
|
return;
|
|
849
|
-
}
|
|
850
854
|
if (options.asyncDonorSnapshot !== false) {
|
|
851
855
|
void ensureAsyncTickZeroBaseline(session);
|
|
852
856
|
return;
|
|
@@ -2494,6 +2498,10 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
2494
2498
|
handleSnapshotRequest(envelope.payload, binaryRequest);
|
|
2495
2499
|
return;
|
|
2496
2500
|
}
|
|
2501
|
+
if (envelope.kind === 'snapshot-refusal') {
|
|
2502
|
+
handleSnapshotRefusal(envelope.payload);
|
|
2503
|
+
return;
|
|
2504
|
+
}
|
|
2497
2505
|
if (envelope.kind === 'snapshot-offer') {
|
|
2498
2506
|
transferCollector.offer(envelope.payload);
|
|
2499
2507
|
return;
|
|
@@ -2509,6 +2517,19 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
2509
2517
|
}
|
|
2510
2518
|
}
|
|
2511
2519
|
}
|
|
2520
|
+
/** The room refused the current donation: stop it, so the donor does not upload a snapshot the room drops. */
|
|
2521
|
+
function handleSnapshotRefusal(payload) {
|
|
2522
|
+
const identity = payload.identity;
|
|
2523
|
+
const configHash = typeof identity === 'object' && identity !== null
|
|
2524
|
+
? identity.configHash : undefined;
|
|
2525
|
+
if (typeof configHash !== 'string' || lastDonorRequest?.id !== configHash)
|
|
2526
|
+
return;
|
|
2527
|
+
const tick = lastDonorRequest.frame - 1;
|
|
2528
|
+
cancelDonorSnapshot();
|
|
2529
|
+
const reason = typeof payload.reason === 'string' ? payload.reason : 'unknown';
|
|
2530
|
+
const limit = typeof payload.maxSnapshotBytes === 'number' ? ` The room stores snapshots up to ${payload.maxSnapshotBytes} bytes.` : '';
|
|
2531
|
+
donorDiagnostic('snapshot.refused', `Syncplay room refused the donor snapshot for tick ${tick}: ${reason}.${limit}`);
|
|
2532
|
+
}
|
|
2512
2533
|
function emitDonorSnapshotTransfer(binarySnapshot, tick, transferSlot, offerIdentity, upload, sendBinary) {
|
|
2513
2534
|
donorTransferCounter += 1;
|
|
2514
2535
|
lastSnapshotSelectedTick = tick;
|
|
@@ -2642,6 +2663,11 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
2642
2663
|
const sendBinary = binaryRequest ? options.transport.sendBinary : undefined;
|
|
2643
2664
|
const transferBudgetMs = typeof payload.transferBudgetMs === 'number' && Number.isFinite(payload.transferBudgetMs)
|
|
2644
2665
|
&& payload.transferBudgetMs > 0 ? payload.transferBudgetMs : 10_000;
|
|
2666
|
+
// A room sends the limit it stores snapshots under when that limit is not the default. So a request without the
|
|
2667
|
+
// field means the default limit, and a donor with a larger limit of its own still fits the room.
|
|
2668
|
+
const roomSnapshotLimit = typeof payload.maxSnapshotBytes === 'number' && Number.isSafeInteger(payload.maxSnapshotBytes)
|
|
2669
|
+
&& payload.maxSnapshotBytes > 0 ? payload.maxSnapshotBytes : DEFAULT_MAX_SNAPSHOT_BYTES;
|
|
2670
|
+
const snapshotLimitBytes = Math.min(roomSnapshotLimit, options.maxSnapshotBytes ?? DEFAULT_MAX_SNAPSHOT_BYTES);
|
|
2645
2671
|
if (lastDonorRequest !== undefined && lastDonorRequest.id === requestConfigHash
|
|
2646
2672
|
&& lastDonorRequest.frame === minFrame && lastDonorRequest.budgetMs === transferBudgetMs
|
|
2647
2673
|
&& lastDonorRequest.binary === binaryRequest && (donorEncodeAbort !== undefined || donorUpload?.hasPending)) {
|
|
@@ -2664,20 +2690,24 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
2664
2690
|
emitDonorRefusal(minTick, minFrame, slot, offerIdentity, binaryRequest, sendBinary, 'SYNCPLAY_DONOR_UPLOAD_TICK_RATE_INVALID');
|
|
2665
2691
|
return;
|
|
2666
2692
|
}
|
|
2667
|
-
|
|
2693
|
+
// Each slow-* warning fires at most once per donation, and one does not hide the other.
|
|
2694
|
+
let warnedSlowPhase = false;
|
|
2695
|
+
let warnedSlowSerializer = false;
|
|
2696
|
+
let asyncPinPath = false;
|
|
2668
2697
|
let sliced = false;
|
|
2669
2698
|
let longestMainThreadTaskMs = 0;
|
|
2670
2699
|
const timing = {
|
|
2671
|
-
nativeSerializationMs: 0, gameSerializerMs: 0, compressionMs: 0, digestMs: 0,
|
|
2700
|
+
nativeSerializationMs: 0, gameSerializerMs: 0, compressionMs: 0, digestMs: 0, digestWaitMs: 0,
|
|
2701
|
+
stagedNativeCheckpoint: false,
|
|
2672
2702
|
};
|
|
2673
2703
|
function recordPhase(phase, durationMs) {
|
|
2674
2704
|
longestMainThreadTaskMs = Math.max(longestMainThreadTaskMs, durationMs);
|
|
2675
2705
|
if (durationMs > (longestDonorSnapshotPhase?.durationMs ?? 0)) {
|
|
2676
2706
|
longestDonorSnapshotPhase = { phase, durationMs };
|
|
2677
2707
|
}
|
|
2678
|
-
if (
|
|
2708
|
+
if (warnedSlowPhase || durationMs <= donorSnapshotWarnMs)
|
|
2679
2709
|
return;
|
|
2680
|
-
|
|
2710
|
+
warnedSlowPhase = true;
|
|
2681
2711
|
const reason = sliced ? ' Reason: no Worker available.' : '';
|
|
2682
2712
|
donorDiagnostic('snapshot.slow-phase', `Syncplay donor snapshot phase "${phase}" took ${durationMs.toFixed(2)} ms at tick ${tick}.${reason}`);
|
|
2683
2713
|
}
|
|
@@ -2690,7 +2720,7 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
2690
2720
|
recordPhase(phase, hostDurationClockMs() - started);
|
|
2691
2721
|
}
|
|
2692
2722
|
}
|
|
2693
|
-
function measureSerializer(run) {
|
|
2723
|
+
function measureSerializer(run, adviseAsyncExport = true) {
|
|
2694
2724
|
const start = hostDurationClockMs();
|
|
2695
2725
|
const nativeBefore = timing.nativeSerializationMs;
|
|
2696
2726
|
try {
|
|
@@ -2699,13 +2729,16 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
2699
2729
|
finally {
|
|
2700
2730
|
const durationMs = hostDurationClockMs() - start;
|
|
2701
2731
|
timing.gameSerializerMs += Math.max(0, durationMs - (timing.nativeSerializationMs - nativeBefore));
|
|
2702
|
-
if (!
|
|
2703
|
-
|
|
2732
|
+
if (!warnedSlowSerializer && durationMs > frameMs) {
|
|
2733
|
+
warnedSlowSerializer = true;
|
|
2734
|
+
// Only the async pin path calls serializeStateAsync, and only a generic owned runtime has that hook.
|
|
2735
|
+
const advice = adviseAsyncExport && asyncPinPath && usesGenericOwnedSnapshotCodec();
|
|
2704
2736
|
emitSyncplayDiagnostic(options.diagnostics, {
|
|
2705
2737
|
code: 'snapshot.donor',
|
|
2706
2738
|
key: 'snapshot.slow-serializer',
|
|
2707
|
-
message: `Syncplay snapshot serializer ran for ${durationMs.toFixed(2)} ms before yielding at tick ${tick}
|
|
2708
|
-
|
|
2739
|
+
message: `Syncplay snapshot serializer ran for ${durationMs.toFixed(2)} ms before yielding at tick ${tick}.`
|
|
2740
|
+
+ (advice ? ' Use world.serializeCheckpointAsync in serializeStateAsync for a 3D checkpoint.' : ''),
|
|
2741
|
+
replacement: advice ? 'serializeStateAsync' : '',
|
|
2709
2742
|
migration: '',
|
|
2710
2743
|
});
|
|
2711
2744
|
}
|
|
@@ -2717,7 +2750,8 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
2717
2750
|
const snapshotDonation = Object.freeze({
|
|
2718
2751
|
tick, wireMode: wireMode ?? 'full', encoding,
|
|
2719
2752
|
nativeSerializationMs: timing.nativeSerializationMs, gameSerializerMs: timing.gameSerializerMs,
|
|
2720
|
-
compressionMs: timing.compressionMs, digestMs: timing.digestMs,
|
|
2753
|
+
compressionMs: timing.compressionMs, digestMs: timing.digestMs, digestWaitMs: timing.digestWaitMs,
|
|
2754
|
+
longestMainThreadTaskMs, rawBytes, outputBytes,
|
|
2721
2755
|
});
|
|
2722
2756
|
emitSyncplayDiagnostic(options.diagnostics, {
|
|
2723
2757
|
code: 'snapshot.donor', key: 'snapshot.donation', message: `Syncplay encoded a donor snapshot at tick ${tick}.`,
|
|
@@ -2725,6 +2759,7 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
2725
2759
|
});
|
|
2726
2760
|
}
|
|
2727
2761
|
if (options.asyncDonorSnapshot !== false && active.pinDonorSnapshot !== undefined) {
|
|
2762
|
+
asyncPinPath = true;
|
|
2728
2763
|
const knownChecksum = confirmedChecksumsByTick.get(tick);
|
|
2729
2764
|
const pinned = measurePhase('pin', () => active.pinDonorSnapshot(snapshot.frame, {
|
|
2730
2765
|
...(options.pinSnapshot !== undefined ? { pinSnapshot: options.pinSnapshot } : {}),
|
|
@@ -2732,9 +2767,8 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
2732
2767
|
...(knownChecksum !== undefined ? { knownWireChecksum: knownChecksum } : {}),
|
|
2733
2768
|
needWireChecksum: knownChecksum === undefined,
|
|
2734
2769
|
}));
|
|
2735
|
-
const baselineJob = baselineDeltaEnabled && typeof pinned.encodeBaselineDelta !== 'function'
|
|
2736
|
-
|
|
2737
|
-
? usesGenericOwnedSnapshotCodec() ? tickZeroBaselinePromise : ensureAsyncTickZeroBaseline(active)
|
|
2770
|
+
const baselineJob = baselineDeltaEnabled && typeof pinned.encodeBaselineDelta !== 'function' && !usesGenericOwnedSnapshotCodec()
|
|
2771
|
+
? ensureAsyncTickZeroBaseline(active)
|
|
2738
2772
|
: undefined;
|
|
2739
2773
|
const confirmedInputsCopy = confirmedAtTick.map((input) => cloneCanonical(input));
|
|
2740
2774
|
const confirmedSeatsCopy = confirmedSeatsAtTick !== undefined
|
|
@@ -2780,9 +2814,9 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
2780
2814
|
const serializationWork = {
|
|
2781
2815
|
signal: abortController.signal,
|
|
2782
2816
|
nextTick: () => nextSnapshotTask(abortController.signal, frameMs),
|
|
2783
|
-
digest: (bytes) => digestSnapshotBytes(bytes, donorSnapshotBudgetMs, abortController.signal, fallbackPacing, false, timing),
|
|
2784
2817
|
measureGamePacket: (encode) => measurePhase('game packet', () => measureSerializer(encode)),
|
|
2785
2818
|
};
|
|
2819
|
+
attachSnapshotWorkDigest(serializationWork, (bytes) => digestSnapshotBytes(bytes, donorSnapshotBudgetMs, abortController.signal, fallbackPacing, false, timing));
|
|
2786
2820
|
trackCheckpointStaging(serializationWork, stage => measurePhase('stage physics', () => {
|
|
2787
2821
|
timing.stagedNativeCheckpoint = true;
|
|
2788
2822
|
return withSnapshotTiming(timing, () => measureSnapshotPhase('nativeSerializationMs', stage));
|
|
@@ -2809,15 +2843,8 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
2809
2843
|
}
|
|
2810
2844
|
else {
|
|
2811
2845
|
rawPayloadBytes = await measurePhase('serialize', () => measureSerializer(() => pinned.serialize(serializationWork)));
|
|
2812
|
-
if (!timing.stagedNativeCheckpoint)
|
|
2813
|
-
|
|
2814
|
-
await baselineJob;
|
|
2815
|
-
if (baselineDeltaEnabled && usesGenericOwnedSnapshotCodec() && pinned.hasCustomAsync) {
|
|
2816
|
-
captureTickZeroBaselineIfNeeded(true, true);
|
|
2817
|
-
if (tickZeroBaselinePromise !== undefined)
|
|
2818
|
-
await tickZeroBaselinePromise;
|
|
2819
|
-
}
|
|
2820
|
-
}
|
|
2846
|
+
if (!timing.stagedNativeCheckpoint && baselineJob !== undefined)
|
|
2847
|
+
await baselineJob;
|
|
2821
2848
|
}
|
|
2822
2849
|
if (!(rawPayloadBytes instanceof Uint8Array)) {
|
|
2823
2850
|
throw new Error('Async donor snapshot serializer must resolve to Uint8Array');
|
|
@@ -2832,7 +2859,9 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
2832
2859
|
const stateChecksum = pinned.wireChecksum;
|
|
2833
2860
|
if (stateChecksum === undefined)
|
|
2834
2861
|
throw new Error('Donor pin has no report checksum');
|
|
2835
|
-
|
|
2862
|
+
let rawBytes = rawPayloadBytes.byteLength;
|
|
2863
|
+
const synchronousFallback = timing.stagedNativeCheckpoint && usesGenericOwnedSnapshotCodec()
|
|
2864
|
+
? pinned.serializeSynchronously?.bind(pinned) : undefined;
|
|
2836
2865
|
const commonFields = {
|
|
2837
2866
|
tick,
|
|
2838
2867
|
sessionFrame: tick + 1,
|
|
@@ -2845,8 +2874,10 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
2845
2874
|
...(presetDeltaMode !== undefined ? { deltaMode: presetDeltaMode } : {}),
|
|
2846
2875
|
...(presetBaselineChecksum !== undefined ? { baselineChecksum: presetBaselineChecksum } : {}),
|
|
2847
2876
|
};
|
|
2848
|
-
|
|
2849
|
-
const
|
|
2877
|
+
// A generic owned runtime sends full snapshots only: a peer may hold no frame-zero baseline.
|
|
2878
|
+
const baseline = timing.stagedNativeCheckpoint || usesGenericOwnedSnapshotCodec()
|
|
2879
|
+
? undefined : physicsTransferBaseline ?? tickZeroBaseline;
|
|
2880
|
+
const encoded = await measurePhase('post snapshot', () => encodeDonorSnapshotOffThread(capturedIdentity.stateDigestDomain === 'syncplay.state-report/2'
|
|
2850
2881
|
? { ...commonFields, v: 3, witnesses: 1 }
|
|
2851
2882
|
: { ...commonFields, v: 2 }, {
|
|
2852
2883
|
...(presetDeltaMode === undefined && baselineDeltaEnabled && baseline !== undefined
|
|
@@ -2876,12 +2907,21 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
2876
2907
|
...(options.diagnostics != null ? { onTiming: (encodedTiming) => {
|
|
2877
2908
|
timing.compressionMs += encodedTiming.compressionMs;
|
|
2878
2909
|
timing.digestMs += encodedTiming.digestMs;
|
|
2910
|
+
timing.digestWaitMs += encodedTiming.digestWaitMs;
|
|
2879
2911
|
} } : {}),
|
|
2880
2912
|
...(timing.stagedNativeCheckpoint ? { lzmaFullPayload: true, retryWorkerFailure: true } : {}),
|
|
2881
2913
|
onWorkerUnavailable: () => {
|
|
2882
2914
|
clearWorkerTimeout();
|
|
2883
2915
|
sliced = true;
|
|
2884
|
-
|
|
2916
|
+
},
|
|
2917
|
+
...(synchronousFallback === undefined ? {} : {
|
|
2918
|
+
// The game already uses serializeStateAsync here, so the slow-serializer advice would be wrong.
|
|
2919
|
+
fallbackPayload: () => measurePhase('synchronous export', () => measureSerializer(synchronousFallback, false)),
|
|
2920
|
+
fallbackPayloadLimitBytes: snapshotLimitBytes,
|
|
2921
|
+
}),
|
|
2922
|
+
onFallbackPayload: (fallback) => {
|
|
2923
|
+
rawBytes = fallback.payloadBytes;
|
|
2924
|
+
reportWorkerFallback(fallback, tick);
|
|
2885
2925
|
},
|
|
2886
2926
|
...(pinned.transferableBytes === true ? { transferInputAfterWorkerStart: true } : {}),
|
|
2887
2927
|
}));
|
|
@@ -3065,16 +3105,21 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
3065
3105
|
const decodedInputs = snapshot.confirmedInputs.map((input) => decodeInputSafe(input));
|
|
3066
3106
|
const pageDiff = snapshot.deltaMode === 'page-diff' || snapshot.deltaMode === 'physics-page-diff'
|
|
3067
3107
|
|| isBaselineDeltaSnapshotBytes(rawPayload);
|
|
3108
|
+
if (usesGenericOwnedSnapshotCodec() && (pageDiff || snapshot.deltaMode !== undefined)) {
|
|
3109
|
+
// Since 6.0.0-rc.112 a generic owned runtime sends full snapshots only, and no peer keeps a baseline for it.
|
|
3110
|
+
throw new SyncplayError('A generic owned runtime accepts full snapshots only. The donor sent a '
|
|
3111
|
+
+ `${snapshot.deltaMode ?? 'page-diff'} snapshot, so it runs a Syncplay build older than 6.0.0-rc.112. `
|
|
3112
|
+
+ 'Run every peer of the room on 6.0.0-rc.112 or later.', {
|
|
3113
|
+
code: 'client.snapshot-owned-delta-unsupported',
|
|
3114
|
+
frame: snapshot.sessionFrame,
|
|
3115
|
+
});
|
|
3116
|
+
}
|
|
3068
3117
|
if (snapshot.deltaMode === 'runtime-hook' || !pageDiff) {
|
|
3069
3118
|
// Restore clears frame 0. Keep its pin so hydration can skip the baseline export.
|
|
3070
3119
|
if (activeRuntime !== undefined && legacyVoxelPageDiffRuntimes3D.has(activeRuntime)) {
|
|
3071
3120
|
retainTickZeroBaseline(active);
|
|
3072
3121
|
}
|
|
3073
|
-
else if (usesGenericOwnedSnapshotCodec()
|
|
3074
|
-
&& (!baselineDeltaEnabled || active.hasAsyncDonorSnapshot?.(0) === true)) {
|
|
3075
|
-
retainTickZeroBaseline(active);
|
|
3076
|
-
}
|
|
3077
|
-
else {
|
|
3122
|
+
else if (!usesGenericOwnedSnapshotCodec()) {
|
|
3078
3123
|
void ensureAsyncTickZeroBaseline(active, false, true);
|
|
3079
3124
|
}
|
|
3080
3125
|
}
|
|
@@ -3162,6 +3207,8 @@ export function createNetworkedSyncplayClient(options) {
|
|
|
3162
3207
|
}
|
|
3163
3208
|
}
|
|
3164
3209
|
catch (error) {
|
|
3210
|
+
if (error instanceof SyncplayError && error.code === 'client.snapshot-owned-delta-unsupported')
|
|
3211
|
+
throw error;
|
|
3165
3212
|
const failureCode = error instanceof Error && 'code' in error ? String(error.code)
|
|
3166
3213
|
: error instanceof Error ? error.message : '';
|
|
3167
3214
|
if (failureCode.includes('CLEANUP_FAILED') || failureCode.includes('RUNTIME_FAILED')) {
|