@pylonsync/realtime 0.22.13 → 0.22.15
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/dist/connection.d.ts +6 -1
- package/dist/game.d.ts +5 -2
- package/dist/interpolation.d.ts +8 -0
- package/dist/wire.d.ts +1 -1
- package/package.json +1 -1
- package/src/connection.ts +8 -3
- package/src/game.test.ts +12 -1
- package/src/game.ts +7 -3
- package/src/interpolation.test.ts +18 -0
- package/src/interpolation.ts +15 -0
- package/src/rewind.fixtures.json +3571 -0
- package/src/rewind.test.ts +31 -0
- package/src/wire.ts +7 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import { EntityInterpolator } from "./interpolation";
|
|
4
|
+
import { EntityTable } from "./replication";
|
|
5
|
+
import fixtures from "./rewind.fixtures.json";
|
|
6
|
+
|
|
7
|
+
function bytes(hex: string): Uint8Array {
|
|
8
|
+
const out = new Uint8Array(hex.length / 2);
|
|
9
|
+
for (let i = 0; i < out.length; i++) out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
10
|
+
return out;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// The server's lag compensation (pylon-replication's ViewHistory) places
|
|
14
|
+
// each entity where this interpolator does, for the frames it sent:
|
|
15
|
+
// crates/realtime/tests/rewind_fixtures.rs writes the frames and the
|
|
16
|
+
// server's positions.
|
|
17
|
+
test("the interpolator draws what the server's rewind says it drew", () => {
|
|
18
|
+
const table = new EntityTable();
|
|
19
|
+
const interp = new EntityInterpolator();
|
|
20
|
+
for (const f of fixtures.frames) {
|
|
21
|
+
interp.record(table, table.apply(bytes(f.frame)), f.tick);
|
|
22
|
+
}
|
|
23
|
+
expect(fixtures.queries.length).toBeGreaterThan(40);
|
|
24
|
+
for (const q of fixtures.queries) {
|
|
25
|
+
interp.update(q.tick);
|
|
26
|
+
const want = new Map(q.positions.map(([id, x, y, z]) => [id, [x, y, z]]));
|
|
27
|
+
const got = new Map([...interp.entities].map(([id, e]) => [id, [e.x, e.y, e.z]]));
|
|
28
|
+
expect([...got.keys()].sort((a, b) => a - b)).toEqual([...want.keys()].sort((a, b) => a - b));
|
|
29
|
+
for (const [id, p] of want) expect(got.get(id)).toEqual(p);
|
|
30
|
+
}
|
|
31
|
+
});
|
package/src/wire.ts
CHANGED
|
@@ -151,8 +151,14 @@ export function encodeShardInput(
|
|
|
151
151
|
codec: number | null,
|
|
152
152
|
input: unknown,
|
|
153
153
|
clientSeq: number,
|
|
154
|
+
viewTick?: number,
|
|
154
155
|
): string | Uint8Array {
|
|
155
|
-
const envelope
|
|
156
|
+
const envelope: { input: unknown; client_seq: number; view_tick?: number } = {
|
|
157
|
+
input,
|
|
158
|
+
client_seq: clientSeq,
|
|
159
|
+
};
|
|
160
|
+
// The tick the client was drawing, for a shard with lag compensation.
|
|
161
|
+
if (viewTick !== undefined && Number.isFinite(viewTick)) envelope.view_tick = viewTick;
|
|
156
162
|
if (codec === ShardCodec.MessagePack) return msgpackEncode(envelope);
|
|
157
163
|
return JSON.stringify(envelope);
|
|
158
164
|
}
|