@series-inc/rundot-syncplay 5.23.0-beta.7
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/README.md +610 -0
- package/dist/animation.d.ts +119 -0
- package/dist/animation.js +488 -0
- package/dist/asset-cooking.d.ts +82 -0
- package/dist/asset-cooking.js +364 -0
- package/dist/authority-room.d.ts +217 -0
- package/dist/authority-room.js +701 -0
- package/dist/bot-documents.d.ts +115 -0
- package/dist/bot-documents.js +549 -0
- package/dist/bot-primitives.d.ts +152 -0
- package/dist/bot-primitives.js +472 -0
- package/dist/browser.d.ts +57 -0
- package/dist/browser.js +53 -0
- package/dist/canonical.d.ts +12 -0
- package/dist/canonical.js +288 -0
- package/dist/certification.d.ts +455 -0
- package/dist/certification.js +1855 -0
- package/dist/chaos-certification.d.ts +56 -0
- package/dist/chaos-certification.js +1397 -0
- package/dist/cjs/animation.js +495 -0
- package/dist/cjs/asset-cooking.js +372 -0
- package/dist/cjs/authority-room.js +704 -0
- package/dist/cjs/bot-documents.js +556 -0
- package/dist/cjs/bot-primitives.js +482 -0
- package/dist/cjs/browser.js +96 -0
- package/dist/cjs/canonical.js +299 -0
- package/dist/cjs/certification.js +1860 -0
- package/dist/cjs/chaos-certification.js +1402 -0
- package/dist/cjs/collections.js +36 -0
- package/dist/cjs/collision.js +96 -0
- package/dist/cjs/commands.js +987 -0
- package/dist/cjs/config-bundle.js +491 -0
- package/dist/cjs/creator.js +30 -0
- package/dist/cjs/deterministic-primitives.js +134 -0
- package/dist/cjs/deterministic-session.js +1410 -0
- package/dist/cjs/ecs-lite.js +155 -0
- package/dist/cjs/effects-adapter.js +97 -0
- package/dist/cjs/engine-complete.js +2297 -0
- package/dist/cjs/engine-core-proof.js +70 -0
- package/dist/cjs/engine-parity-matrix.js +874 -0
- package/dist/cjs/engine-parity.js +3183 -0
- package/dist/cjs/engine-runtime.js +3141 -0
- package/dist/cjs/errors.js +22 -0
- package/dist/cjs/events.js +247 -0
- package/dist/cjs/examples/counter-duel.js +157 -0
- package/dist/cjs/examples/fixed-arena.js +368 -0
- package/dist/cjs/index.js +229 -0
- package/dist/cjs/input-authority.js +150 -0
- package/dist/cjs/input-button.js +256 -0
- package/dist/cjs/input-timeline.js +418 -0
- package/dist/cjs/instant-replay.js +66 -0
- package/dist/cjs/lag-compensation3d.js +837 -0
- package/dist/cjs/local-authority-server-runner.js +1121 -0
- package/dist/cjs/local-authority-wire.js +1497 -0
- package/dist/cjs/local-authority.js +817 -0
- package/dist/cjs/local-ws-adapter.js +150 -0
- package/dist/cjs/match-log.js +61 -0
- package/dist/cjs/math.js +157 -0
- package/dist/cjs/mock-network-adapter.js +26 -0
- package/dist/cjs/movement.js +703 -0
- package/dist/cjs/movement3d.js +1246 -0
- package/dist/cjs/multiclient-authority.js +308 -0
- package/dist/cjs/multiplayer-service.js +434 -0
- package/dist/cjs/navigation.js +347 -0
- package/dist/cjs/navmesh.js +1437 -0
- package/dist/cjs/networked-client.js +691 -0
- package/dist/cjs/networked-input-authority.js +443 -0
- package/dist/cjs/node.js +47 -0
- package/dist/cjs/number-lab.js +78 -0
- package/dist/cjs/offline-session.js +370 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/pause-resume.js +43 -0
- package/dist/cjs/physics-cert.js +426 -0
- package/dist/cjs/physics2d.js +751 -0
- package/dist/cjs/physics3d.js +1996 -0
- package/dist/cjs/prediction-culling.js +203 -0
- package/dist/cjs/protocol-lab.js +1299 -0
- package/dist/cjs/r3f-render-adapter.js +209 -0
- package/dist/cjs/random.js +59 -0
- package/dist/cjs/replay-bundle.js +1598 -0
- package/dist/cjs/replay-inspect.js +236 -0
- package/dist/cjs/replay-scoring.js +68 -0
- package/dist/cjs/replay.js +356 -0
- package/dist/cjs/reports.js +181 -0
- package/dist/cjs/rollback-history.js +251 -0
- package/dist/cjs/runtime-guards.js +111 -0
- package/dist/cjs/sample-lab.js +145 -0
- package/dist/cjs/sample-scenes.js +752 -0
- package/dist/cjs/schema-artifacts.js +359 -0
- package/dist/cjs/schema-codegen.js +544 -0
- package/dist/cjs/schema-dsl-binary.js +655 -0
- package/dist/cjs/schema.js +319 -0
- package/dist/cjs/sdk-offline.js +99 -0
- package/dist/cjs/session-promotion.js +74 -0
- package/dist/cjs/session-snapshot.js +265 -0
- package/dist/cjs/session-wire.js +216 -0
- package/dist/cjs/signals.js +103 -0
- package/dist/cjs/sparse-set.js +169 -0
- package/dist/cjs/synctest.js +136 -0
- package/dist/cjs/system-lifecycle.js +286 -0
- package/dist/cjs/timers.js +61 -0
- package/dist/cjs/tools/static-checker.js +1468 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/venus-mp-budget.js +125 -0
- package/dist/cjs/ws-frame.js +255 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +11379 -0
- package/dist/collections.d.ts +9 -0
- package/dist/collections.js +30 -0
- package/dist/collision.d.ts +25 -0
- package/dist/collision.js +85 -0
- package/dist/commands.d.ts +137 -0
- package/dist/commands.js +977 -0
- package/dist/config-bundle.d.ts +89 -0
- package/dist/config-bundle.js +483 -0
- package/dist/creator.d.ts +20 -0
- package/dist/creator.js +11 -0
- package/dist/deterministic-primitives.d.ts +59 -0
- package/dist/deterministic-primitives.js +126 -0
- package/dist/deterministic-session.d.ts +197 -0
- package/dist/deterministic-session.js +1401 -0
- package/dist/ecs-lite.d.ts +26 -0
- package/dist/ecs-lite.js +152 -0
- package/dist/effects-adapter.d.ts +21 -0
- package/dist/effects-adapter.js +94 -0
- package/dist/engine-complete.d.ts +45 -0
- package/dist/engine-complete.js +2292 -0
- package/dist/engine-core-proof.d.ts +26 -0
- package/dist/engine-core-proof.js +66 -0
- package/dist/engine-parity-matrix.d.ts +300 -0
- package/dist/engine-parity-matrix.js +869 -0
- package/dist/engine-parity.d.ts +74 -0
- package/dist/engine-parity.js +3178 -0
- package/dist/engine-runtime.d.ts +351 -0
- package/dist/engine-runtime.js +3123 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.js +17 -0
- package/dist/events.d.ts +45 -0
- package/dist/events.js +242 -0
- package/dist/examples/counter-duel.d.ts +43 -0
- package/dist/examples/counter-duel.js +150 -0
- package/dist/examples/fixed-arena.d.ts +110 -0
- package/dist/examples/fixed-arena.js +356 -0
- package/dist/index.d.ts +101 -0
- package/dist/index.js +66 -0
- package/dist/input-authority.d.ts +82 -0
- package/dist/input-authority.js +147 -0
- package/dist/input-button.d.ts +36 -0
- package/dist/input-button.js +249 -0
- package/dist/input-timeline.d.ts +65 -0
- package/dist/input-timeline.js +412 -0
- package/dist/instant-replay.d.ts +59 -0
- package/dist/instant-replay.js +62 -0
- package/dist/lag-compensation3d.d.ts +146 -0
- package/dist/lag-compensation3d.js +827 -0
- package/dist/local-authority-server-runner.d.ts +79 -0
- package/dist/local-authority-server-runner.js +1118 -0
- package/dist/local-authority-wire.d.ts +142 -0
- package/dist/local-authority-wire.js +1477 -0
- package/dist/local-authority.d.ts +160 -0
- package/dist/local-authority.js +810 -0
- package/dist/local-ws-adapter.d.ts +14 -0
- package/dist/local-ws-adapter.js +146 -0
- package/dist/match-log.d.ts +74 -0
- package/dist/match-log.js +57 -0
- package/dist/math.d.ts +41 -0
- package/dist/math.js +154 -0
- package/dist/mock-network-adapter.d.ts +13 -0
- package/dist/mock-network-adapter.js +23 -0
- package/dist/movement.d.ts +155 -0
- package/dist/movement.js +694 -0
- package/dist/movement3d.d.ts +195 -0
- package/dist/movement3d.js +1238 -0
- package/dist/multiclient-authority.d.ts +30 -0
- package/dist/multiclient-authority.js +305 -0
- package/dist/multiplayer-service.d.ts +153 -0
- package/dist/multiplayer-service.js +429 -0
- package/dist/navigation.d.ts +91 -0
- package/dist/navigation.js +338 -0
- package/dist/navmesh.d.ts +236 -0
- package/dist/navmesh.js +1423 -0
- package/dist/networked-client.d.ts +124 -0
- package/dist/networked-client.js +688 -0
- package/dist/networked-input-authority.d.ts +51 -0
- package/dist/networked-input-authority.js +439 -0
- package/dist/node.d.ts +22 -0
- package/dist/node.js +19 -0
- package/dist/number-lab.d.ts +15 -0
- package/dist/number-lab.js +75 -0
- package/dist/offline-session.d.ts +2 -0
- package/dist/offline-session.js +367 -0
- package/dist/pause-resume.d.ts +48 -0
- package/dist/pause-resume.js +40 -0
- package/dist/physics-cert.d.ts +40 -0
- package/dist/physics-cert.js +389 -0
- package/dist/physics2d.d.ts +142 -0
- package/dist/physics2d.js +741 -0
- package/dist/physics3d.d.ts +285 -0
- package/dist/physics3d.js +1979 -0
- package/dist/prediction-culling.d.ts +34 -0
- package/dist/prediction-culling.js +200 -0
- package/dist/protocol-lab.d.ts +115 -0
- package/dist/protocol-lab.js +1295 -0
- package/dist/r3f-render-adapter.d.ts +61 -0
- package/dist/r3f-render-adapter.js +203 -0
- package/dist/random.d.ts +13 -0
- package/dist/random.js +55 -0
- package/dist/replay-bundle.d.ts +150 -0
- package/dist/replay-bundle.js +1586 -0
- package/dist/replay-inspect.d.ts +60 -0
- package/dist/replay-inspect.js +228 -0
- package/dist/replay-scoring.d.ts +28 -0
- package/dist/replay-scoring.js +65 -0
- package/dist/replay.d.ts +17 -0
- package/dist/replay.js +351 -0
- package/dist/reports.d.ts +176 -0
- package/dist/reports.js +174 -0
- package/dist/rollback-history.d.ts +46 -0
- package/dist/rollback-history.js +247 -0
- package/dist/runtime-guards.d.ts +1 -0
- package/dist/runtime-guards.js +108 -0
- package/dist/sample-lab.d.ts +32 -0
- package/dist/sample-lab.js +134 -0
- package/dist/sample-scenes.d.ts +86 -0
- package/dist/sample-scenes.js +745 -0
- package/dist/schema-artifacts.d.ts +49 -0
- package/dist/schema-artifacts.js +356 -0
- package/dist/schema-codegen.d.ts +21 -0
- package/dist/schema-codegen.js +538 -0
- package/dist/schema-dsl-binary.d.ts +75 -0
- package/dist/schema-dsl-binary.js +648 -0
- package/dist/schema.d.ts +87 -0
- package/dist/schema.js +315 -0
- package/dist/sdk-offline.d.ts +34 -0
- package/dist/sdk-offline.js +96 -0
- package/dist/session-promotion.d.ts +26 -0
- package/dist/session-promotion.js +70 -0
- package/dist/session-snapshot.d.ts +95 -0
- package/dist/session-snapshot.js +255 -0
- package/dist/session-wire.d.ts +89 -0
- package/dist/session-wire.js +211 -0
- package/dist/signals.d.ts +31 -0
- package/dist/signals.js +99 -0
- package/dist/sparse-set.d.ts +34 -0
- package/dist/sparse-set.js +165 -0
- package/dist/synctest.d.ts +31 -0
- package/dist/synctest.js +133 -0
- package/dist/system-lifecycle.d.ts +72 -0
- package/dist/system-lifecycle.js +281 -0
- package/dist/timers.d.ts +17 -0
- package/dist/timers.js +53 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.js +4 -0
- package/dist/tools/static-checker.d.ts +31 -0
- package/dist/tools/static-checker.js +1462 -0
- package/dist/tools/vite-plugin.d.ts +69 -0
- package/dist/tools/vite-plugin.js +203 -0
- package/dist/types.d.ts +148 -0
- package/dist/types.js +1 -0
- package/dist/venus-mp-budget.d.ts +29 -0
- package/dist/venus-mp-budget.js +122 -0
- package/dist/ws-frame.d.ts +49 -0
- package/dist/ws-frame.js +247 -0
- package/package.json +169 -0
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runDeterministicMulticlientAuthorityFixture = runDeterministicMulticlientAuthorityFixture;
|
|
4
|
+
const canonical_js_1 = require("./canonical.js");
|
|
5
|
+
const engine_runtime_js_1 = require("./engine-runtime.js");
|
|
6
|
+
const projectionModulo = 2_147_483_647;
|
|
7
|
+
function runDeterministicMulticlientAuthorityFixture(players, frames, seed) {
|
|
8
|
+
const authorityHistory = new Array(frames + 1).fill(0);
|
|
9
|
+
const authorityDeltas = new Array(frames).fill(0);
|
|
10
|
+
const clientStates = new Array(players).fill(0);
|
|
11
|
+
const clientHistories = Array.from({ length: players }, () => new Array(frames + 1).fill(0));
|
|
12
|
+
const clientPredictedDeltas = Array.from({ length: players }, () => new Array(frames).fill(0));
|
|
13
|
+
const lastAuthorityFrameByClient = new Array(players).fill(0);
|
|
14
|
+
const rollbackDepths = [];
|
|
15
|
+
const frameCosts = [];
|
|
16
|
+
let authorityState = 0;
|
|
17
|
+
let authoritySnapshotsDelivered = 0;
|
|
18
|
+
let predictionMismatches = 0;
|
|
19
|
+
let correctionsApplied = 0;
|
|
20
|
+
let resimulatedFrames = 0;
|
|
21
|
+
let convergedSnapshots = 0;
|
|
22
|
+
for (let frame = 0; frame < frames; frame += 1) {
|
|
23
|
+
const authorityDelta = authorityFrameDelta(players, frame, seed);
|
|
24
|
+
authorityDeltas[frame] = authorityDelta;
|
|
25
|
+
authorityState = addProjection(authorityState, authorityDelta);
|
|
26
|
+
authorityHistory[frame + 1] = authorityState;
|
|
27
|
+
for (let slot = 0; slot < players; slot += 1) {
|
|
28
|
+
const predictedDelta = addProjection(authorityDelta, predictionError(slot, frame, seed));
|
|
29
|
+
clientPredictedDeltas[slot][frame] = predictedDelta;
|
|
30
|
+
clientStates[slot] = addProjection(clientStates[slot], predictedDelta);
|
|
31
|
+
clientHistories[slot][frame + 1] = clientStates[slot];
|
|
32
|
+
}
|
|
33
|
+
const currentFrameExclusive = frame + 1;
|
|
34
|
+
for (let slot = 0; slot < players; slot += 1) {
|
|
35
|
+
const confirmedFrame = currentFrameExclusive - snapshotDelay(slot, frame);
|
|
36
|
+
if (confirmedFrame > lastAuthorityFrameByClient[slot]) {
|
|
37
|
+
for (let frameToApply = lastAuthorityFrameByClient[slot] + 1; frameToApply <= confirmedFrame; frameToApply += 1) {
|
|
38
|
+
const applied = applyClientAuthoritySnapshot({
|
|
39
|
+
slot,
|
|
40
|
+
confirmedFrame: frameToApply,
|
|
41
|
+
currentFrameExclusive,
|
|
42
|
+
authorityHistory,
|
|
43
|
+
clientStates,
|
|
44
|
+
clientHistories,
|
|
45
|
+
clientPredictedDeltas,
|
|
46
|
+
});
|
|
47
|
+
authoritySnapshotsDelivered += 1;
|
|
48
|
+
lastAuthorityFrameByClient[slot] = frameToApply;
|
|
49
|
+
if (applied.rollbackDepth === 0) {
|
|
50
|
+
convergedSnapshots += 1;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
predictionMismatches += 1;
|
|
54
|
+
correctionsApplied += 1;
|
|
55
|
+
resimulatedFrames += applied.resimulatedFrames;
|
|
56
|
+
rollbackDepths.push(applied.rollbackDepth);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
frameCosts.push((players + authoritySnapshotsDelivered + correctionsApplied) / 100_000);
|
|
62
|
+
}
|
|
63
|
+
for (let slot = 0; slot < players; slot += 1) {
|
|
64
|
+
for (let confirmedFrame = lastAuthorityFrameByClient[slot] + 1; confirmedFrame <= frames; confirmedFrame += 1) {
|
|
65
|
+
const applied = applyClientAuthoritySnapshot({
|
|
66
|
+
slot,
|
|
67
|
+
confirmedFrame,
|
|
68
|
+
currentFrameExclusive: frames,
|
|
69
|
+
authorityHistory,
|
|
70
|
+
clientStates,
|
|
71
|
+
clientHistories,
|
|
72
|
+
clientPredictedDeltas,
|
|
73
|
+
});
|
|
74
|
+
authoritySnapshotsDelivered += 1;
|
|
75
|
+
lastAuthorityFrameByClient[slot] = confirmedFrame;
|
|
76
|
+
if (applied.rollbackDepth === 0) {
|
|
77
|
+
convergedSnapshots += 1;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
predictionMismatches += 1;
|
|
81
|
+
correctionsApplied += 1;
|
|
82
|
+
resimulatedFrames += applied.resimulatedFrames;
|
|
83
|
+
rollbackDepths.push(applied.rollbackDepth);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const finalAuthorityProjection = authorityHistory[frames];
|
|
88
|
+
const finalClientProjectionChecksum = (0, canonical_js_1.defaultChecksum)(clientStates);
|
|
89
|
+
const convergence = clientStates.every((state) => state === finalAuthorityProjection);
|
|
90
|
+
const allClientsReachedFinalAuthorityFrame = lastAuthorityFrameByClient.every((frame) => frame === frames);
|
|
91
|
+
const runtimeBacked = runRuntimeBackedMulticlientAuthorityFixture(players, frames, seed);
|
|
92
|
+
const metrics = {
|
|
93
|
+
players,
|
|
94
|
+
frames,
|
|
95
|
+
predictedClientRunners: players,
|
|
96
|
+
authoritySnapshotsDelivered,
|
|
97
|
+
predictionMismatches,
|
|
98
|
+
correctionsApplied,
|
|
99
|
+
resimulatedFrames,
|
|
100
|
+
convergedSnapshots,
|
|
101
|
+
rollbackDepthP95: percentile(rollbackDepths, 95),
|
|
102
|
+
rollbackDepthMax: rollbackDepths.length === 0 ? 0 : Math.max(...rollbackDepths),
|
|
103
|
+
finalAuthorityProjection,
|
|
104
|
+
finalClientProjectionChecksum,
|
|
105
|
+
convergence,
|
|
106
|
+
allClientsReachedFinalAuthorityFrame,
|
|
107
|
+
runtimeBackedClients: runtimeBacked.clients,
|
|
108
|
+
runtimeBackedFrames: runtimeBacked.frames,
|
|
109
|
+
runtimeBackedAuthoritySnapshots: runtimeBacked.authoritySnapshots,
|
|
110
|
+
runtimeBackedPredictionMismatches: runtimeBacked.predictionMismatches,
|
|
111
|
+
runtimeBackedCorrectionsApplied: runtimeBacked.correctionsApplied,
|
|
112
|
+
runtimeBackedResimulatedFrames: runtimeBacked.resimulatedFrames,
|
|
113
|
+
runtimeBackedReplayVerifiedClients: runtimeBacked.replayVerifiedClients,
|
|
114
|
+
runtimeBackedAuthorityChecksum: runtimeBacked.authorityChecksum,
|
|
115
|
+
runtimeBackedClientChecksum: runtimeBacked.clientChecksum,
|
|
116
|
+
runtimeBackedConvergence: runtimeBacked.convergence,
|
|
117
|
+
p95FrameCost: percentile(frameCosts, 95),
|
|
118
|
+
p99FrameCost: percentile(frameCosts, 99),
|
|
119
|
+
};
|
|
120
|
+
return {
|
|
121
|
+
...metrics,
|
|
122
|
+
checksum: (0, canonical_js_1.defaultChecksum)(metrics),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function runRuntimeBackedMulticlientAuthorityFixture(players, frames, seed) {
|
|
126
|
+
const descriptor = createRuntimeBackedAuthorityDescriptor();
|
|
127
|
+
const systems = createRuntimeBackedAuthoritySystems();
|
|
128
|
+
const authority = (0, engine_runtime_js_1.createDeterministicFrameRuntime)(descriptor, seed);
|
|
129
|
+
const clients = Array.from({ length: players }, () => (0, engine_runtime_js_1.createDeterministicFrameRuntime)(descriptor, seed));
|
|
130
|
+
initializeRuntimeBackedProjection(authority);
|
|
131
|
+
for (const client of clients) {
|
|
132
|
+
initializeRuntimeBackedProjection(client);
|
|
133
|
+
}
|
|
134
|
+
const lastAuthorityFrameByClient = new Array(players).fill(0);
|
|
135
|
+
const clientSnapshotHistory = clients.map((client) => [client.snapshot()]);
|
|
136
|
+
const clientPredictedDeltas = clients.map(() => new Array(frames).fill(0));
|
|
137
|
+
const authoritySnapshots = [authority.snapshot()];
|
|
138
|
+
let authoritySnapshotsDelivered = 0;
|
|
139
|
+
let predictionMismatches = 0;
|
|
140
|
+
let correctionsApplied = 0;
|
|
141
|
+
let resimulatedFrames = 0;
|
|
142
|
+
for (let frame = 0; frame < frames; frame += 1) {
|
|
143
|
+
const authorityDelta = authorityFrameDelta(players, frame, seed);
|
|
144
|
+
stepRuntimeBackedAuthority(authority, systems, authorityDelta);
|
|
145
|
+
authoritySnapshots[frame + 1] = authority.snapshot();
|
|
146
|
+
for (let slot = 0; slot < players; slot += 1) {
|
|
147
|
+
const predictedDelta = addProjection(authorityDelta, predictionError(slot, frame, seed));
|
|
148
|
+
clientPredictedDeltas[slot][frame] = predictedDelta;
|
|
149
|
+
stepRuntimeBackedAuthority(clients[slot], systems, predictedDelta);
|
|
150
|
+
clientSnapshotHistory[slot][frame + 1] = clients[slot].snapshot();
|
|
151
|
+
}
|
|
152
|
+
const currentFrameExclusive = frame + 1;
|
|
153
|
+
for (let slot = 0; slot < players; slot += 1) {
|
|
154
|
+
const confirmedFrame = currentFrameExclusive - snapshotDelay(slot, frame);
|
|
155
|
+
if (confirmedFrame > 0 && confirmedFrame % 16 === 0) {
|
|
156
|
+
const authoritySnapshot = authoritySnapshots[confirmedFrame];
|
|
157
|
+
authoritySnapshotsDelivered += 1;
|
|
158
|
+
lastAuthorityFrameByClient[slot] = confirmedFrame;
|
|
159
|
+
const applied = applyRuntimeBackedAuthoritySnapshot({
|
|
160
|
+
client: clients[slot],
|
|
161
|
+
systems,
|
|
162
|
+
authoritySnapshot,
|
|
163
|
+
confirmedFrame,
|
|
164
|
+
currentFrameExclusive,
|
|
165
|
+
clientSnapshotHistory: clientSnapshotHistory[slot],
|
|
166
|
+
clientPredictedDeltas: clientPredictedDeltas[slot],
|
|
167
|
+
});
|
|
168
|
+
if (applied.mismatch) {
|
|
169
|
+
predictionMismatches += 1;
|
|
170
|
+
correctionsApplied += 1;
|
|
171
|
+
resimulatedFrames += applied.resimulatedFrames;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
for (let slot = 0; slot < players; slot += 1) {
|
|
177
|
+
for (let confirmedFrame = lastAuthorityFrameByClient[slot] + 1; confirmedFrame <= frames; confirmedFrame += 1) {
|
|
178
|
+
const authoritySnapshot = authoritySnapshots[confirmedFrame];
|
|
179
|
+
authoritySnapshotsDelivered += 1;
|
|
180
|
+
lastAuthorityFrameByClient[slot] = confirmedFrame;
|
|
181
|
+
const applied = applyRuntimeBackedAuthoritySnapshot({
|
|
182
|
+
client: clients[slot],
|
|
183
|
+
systems,
|
|
184
|
+
authoritySnapshot,
|
|
185
|
+
confirmedFrame,
|
|
186
|
+
currentFrameExclusive: frames,
|
|
187
|
+
clientSnapshotHistory: clientSnapshotHistory[slot],
|
|
188
|
+
clientPredictedDeltas: clientPredictedDeltas[slot],
|
|
189
|
+
});
|
|
190
|
+
if (applied.mismatch) {
|
|
191
|
+
predictionMismatches += 1;
|
|
192
|
+
correctionsApplied += 1;
|
|
193
|
+
resimulatedFrames += applied.resimulatedFrames;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const finalAuthoritySnapshot = authority.snapshot();
|
|
198
|
+
const clientChecksums = clients.map((client) => client.snapshot().checksum);
|
|
199
|
+
const replayVerifiedClients = clientChecksums.filter((checksum) => checksum === finalAuthoritySnapshot.checksum).length;
|
|
200
|
+
return {
|
|
201
|
+
clients: players,
|
|
202
|
+
frames,
|
|
203
|
+
authoritySnapshots: authoritySnapshotsDelivered,
|
|
204
|
+
predictionMismatches,
|
|
205
|
+
correctionsApplied,
|
|
206
|
+
resimulatedFrames,
|
|
207
|
+
replayVerifiedClients,
|
|
208
|
+
authorityChecksum: finalAuthoritySnapshot.checksum,
|
|
209
|
+
clientChecksum: (0, canonical_js_1.defaultChecksum)(clientChecksums),
|
|
210
|
+
convergence: replayVerifiedClients === players,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function applyRuntimeBackedAuthoritySnapshot(options) {
|
|
214
|
+
const clientSnapshot = options.clientSnapshotHistory[options.confirmedFrame];
|
|
215
|
+
if (clientSnapshot?.checksum === options.authoritySnapshot.checksum) {
|
|
216
|
+
return { mismatch: false, resimulatedFrames: 0 };
|
|
217
|
+
}
|
|
218
|
+
options.client.restore(options.authoritySnapshot);
|
|
219
|
+
options.clientSnapshotHistory[options.confirmedFrame] = options.client.snapshot();
|
|
220
|
+
let resimulatedFrames = 0;
|
|
221
|
+
for (let resimFrame = options.confirmedFrame; resimFrame < options.currentFrameExclusive; resimFrame += 1) {
|
|
222
|
+
stepRuntimeBackedAuthority(options.client, options.systems, options.clientPredictedDeltas[resimFrame]);
|
|
223
|
+
options.clientSnapshotHistory[resimFrame + 1] = options.client.snapshot();
|
|
224
|
+
resimulatedFrames += 1;
|
|
225
|
+
}
|
|
226
|
+
return { mismatch: true, resimulatedFrames };
|
|
227
|
+
}
|
|
228
|
+
function createRuntimeBackedAuthorityDescriptor() {
|
|
229
|
+
return {
|
|
230
|
+
id: 'runtime-backed-multiclient-authority',
|
|
231
|
+
tickRate: 60,
|
|
232
|
+
components: [
|
|
233
|
+
{ id: 'projection', singleton: true, fields: [{ name: 'value', kind: 'int', defaultValue: 0 }] },
|
|
234
|
+
{ id: 'frameInput', singleton: true, fields: [{ name: 'delta', kind: 'int', defaultValue: 0 }] },
|
|
235
|
+
],
|
|
236
|
+
systems: [{ id: 'simulate', group: 'simulation', order: 0 }],
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function createRuntimeBackedAuthoritySystems() {
|
|
240
|
+
return {
|
|
241
|
+
simulate(ctx) {
|
|
242
|
+
const projection = ctx.getSingleton('projection');
|
|
243
|
+
const input = ctx.getSingleton('frameInput');
|
|
244
|
+
ctx.setSingleton('projection', { value: addProjection(Number(projection.value), Number(input.delta)) });
|
|
245
|
+
ctx.setSingleton('frameInput', { delta: 0 });
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
function stepRuntimeBackedAuthority(runtime, systems, delta) {
|
|
250
|
+
runtime.setSingleton('frameInput', { delta });
|
|
251
|
+
runtime.step(systems);
|
|
252
|
+
}
|
|
253
|
+
function initializeRuntimeBackedProjection(runtime) {
|
|
254
|
+
runtime.setSingleton('projection', { value: 0 });
|
|
255
|
+
runtime.setSingleton('frameInput', { delta: 0 });
|
|
256
|
+
}
|
|
257
|
+
function applyClientAuthoritySnapshot(options) {
|
|
258
|
+
const expected = options.authorityHistory[options.confirmedFrame];
|
|
259
|
+
const history = options.clientHistories[options.slot];
|
|
260
|
+
if (history[options.confirmedFrame] === expected) {
|
|
261
|
+
return { rollbackDepth: 0, resimulatedFrames: 0 };
|
|
262
|
+
}
|
|
263
|
+
let state = expected;
|
|
264
|
+
history[options.confirmedFrame] = state;
|
|
265
|
+
let resimulatedFrames = 0;
|
|
266
|
+
for (let frame = options.confirmedFrame; frame < options.currentFrameExclusive; frame += 1) {
|
|
267
|
+
state = addProjection(state, options.clientPredictedDeltas[options.slot][frame]);
|
|
268
|
+
history[frame + 1] = state;
|
|
269
|
+
resimulatedFrames += 1;
|
|
270
|
+
}
|
|
271
|
+
options.clientStates[options.slot] = state;
|
|
272
|
+
return {
|
|
273
|
+
rollbackDepth: options.currentFrameExclusive - options.confirmedFrame,
|
|
274
|
+
resimulatedFrames,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
function authorityFrameDelta(players, frame, seed) {
|
|
278
|
+
let delta = 0;
|
|
279
|
+
for (let slot = 0; slot < players; slot += 1) {
|
|
280
|
+
const value = ((seed + frame * 17 + slot * 13) % 19) - 9;
|
|
281
|
+
delta = addProjection(delta, value * (slot + 1));
|
|
282
|
+
}
|
|
283
|
+
return delta;
|
|
284
|
+
}
|
|
285
|
+
function predictionError(slot, frame, seed) {
|
|
286
|
+
if ((seed + slot * 3 + frame * 5) % 11 === 0) {
|
|
287
|
+
return slot + 1;
|
|
288
|
+
}
|
|
289
|
+
if ((seed + slot + frame * 7) % 17 === 0) {
|
|
290
|
+
return -slot - 1;
|
|
291
|
+
}
|
|
292
|
+
return 0;
|
|
293
|
+
}
|
|
294
|
+
function snapshotDelay(slot, frame) {
|
|
295
|
+
return 2 + ((slot + frame) % 5);
|
|
296
|
+
}
|
|
297
|
+
function addProjection(left, right) {
|
|
298
|
+
const sum = (left + right) % projectionModulo;
|
|
299
|
+
return sum < 0 ? sum + projectionModulo : sum;
|
|
300
|
+
}
|
|
301
|
+
function percentile(values, percentileValue) {
|
|
302
|
+
if (values.length === 0) {
|
|
303
|
+
return 0;
|
|
304
|
+
}
|
|
305
|
+
const sorted = [...values].sort((left, right) => left - right);
|
|
306
|
+
const index = Math.min(sorted.length - 1, Math.floor((percentileValue / 100) * sorted.length));
|
|
307
|
+
return sorted[index];
|
|
308
|
+
}
|