Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(replication): ghost snapshot interpolation — RC11 N3

esengined8c31d379729
diff --git a/sdk/src/net/replication/ReplicationPlugin.ts b/sdk/src/net/replication/ReplicationPlugin.ts
index ef0933797..43ec906fe 100644
--- a/sdk/src/net/replication/ReplicationPlugin.ts
+++ b/sdk/src/net/replication/ReplicationPlugin.ts
@@ -14,7 +14,7 @@ import { defineSystem, Schedule } from '../../system';
import { defineResource, Res, Time, type TimeData } from '../../resource';
import type { NetTransport } from '../NetChannel';
import { ReplicationServer } from './server';
-import { ReplicationClient } from './client';
+import { ReplicationClient, type ReplicationClientOptions } from './client';
import { ensureReplicationComponentsRegistered } from './components';
export type NetRoleKind = 'offline' | 'server' | 'client';
@@ -47,9 +47,9 @@ export class NetSession {
}
/** Become a replica: handshake over the given transport. */
- async connect(transport: NetTransport): Promise<ReplicationClient> {
+ async connect(transport: NetTransport, options?: ReplicationClientOptions): Promise<ReplicationClient> {
if (this.role_ !== 'offline') throw new Error(`[repl] session already ${this.role_}`);
- const client = new ReplicationClient(this.app_.world);
+ const client = new ReplicationClient(this.app_.world, options);
await client.connect(transport);
this.role_ = 'client';
this.client_ = client;
@@ -97,6 +97,20 @@ export class ReplicationPlugin implements Plugin {
),
{ runIf: () => session.role === 'server' },
);
+
+ app.addSystemToSchedule(
+ Schedule.PostUpdate,
+ defineSystem(
+ [Res(Time)],
+ (time: TimeData) => {
+ session.client?.sampleInterpolation(
+ time.fixedDelta > 0 ? time.delta / time.fixedDelta : 0,
+ );
+ },
+ { name: 'ReplicationInterpolateSystem' },
+ ),
+ { runIf: () => session.role === 'client' },
+ );
}
}
diff --git a/sdk/src/net/replication/client.ts b/sdk/src/net/replication/client.ts
index 2206dd954..839e63652 100644
--- a/sdk/src/net/replication/client.ts
+++ b/sdk/src/net/replication/client.ts
@@ -26,6 +26,16 @@ import {
} from './codec';
import { NetGhost } from './components';
import { NetIds } from './NetIds';
+import { InterpolationState } from './interpolation';
+
+export interface ReplicationClientOptions {
+ /**
+ * How many server ticks the presented state trails the newest received
+ * data. Two ticks absorbs one lost/late delivery without a visible hitch;
+ * 0 disables buffering (state applies the moment it drains).
+ */
+ interpolationDelayTicks?: number;
+}
export class ReplicationClient {
private readonly world_: World;
@@ -37,9 +47,12 @@ export class ReplicationClient {
private readonly pendingFrames_: Uint8Array[] = [];
private readonly pendingSpawns_: ReplSpawnBatch[] = [];
private readonly pendingDespawns_: ReplDespawnBatch[] = [];
+ private readonly interp_: InterpolationState | null;
- constructor(world: World) {
+ constructor(world: World, options: ReplicationClientOptions = {}) {
this.world_ = world;
+ const delay = options.interpolationDelayTicks ?? 2;
+ this.interp_ = delay > 0 ? new InterpolationState(delay) : null;
world.onDespawn((e) => this.netIds_.unregisterEntity(e));
}
@@ -170,6 +183,7 @@ export class ReplicationClient {
for (const netId of batch.netIds) {
const e = this.netIds_.entityOf(netId);
this.netIds_.unregister(netId);
+ this.interp_?.drop(netId);
if (e !== undefined && this.world_.valid(e)) {
this.world_.despawn(e);
}
@@ -179,22 +193,68 @@ export class ReplicationClient {
private applyStateFrame_(frame: StateFrame): void {
if (frame.tick > this.serverTick_) this.serverTick_ = frame.tick;
for (const entry of frame.entries) {
- const e = this.netIds_.entityOf(entry.netId);
- if (e === undefined || !this.world_.valid(e)) continue;
- const te = this.table.entries[entry.componentId];
- if (!te) continue;
- const existing = this.world_.tryGet(e, te.def) as Record<string, unknown> | null;
- const target = existing ?? {};
- let v = 0;
- for (let i = 0; i < te.fields.length; i++) {
- if (entry.fieldMask & (1 << i)) {
- target[te.fields[i]] = entry.values[v++];
+ if (this.interp_) {
+ let v = 0;
+ const te = this.table.entries[entry.componentId];
+ if (!te) continue;
+ for (let i = 0; i < te.fields.length; i++) {
+ if (entry.fieldMask & (1 << i)) {
+ this.interp_.push(entry.netId, entry.componentId, i, frame.tick, entry.values[v++]);
+ }
}
- }
- if (existing) {
- this.world_.set(e, te.def, target);
} else {
- this.world_.insert(e, te.def, target);
+ this.applyEntryNow_(entry.netId, entry.componentId, entry.fieldMask, entry.values);
+ }
+ }
+ }
+
+ private applyEntryNow_(netId: number, componentId: number, fieldMask: number, values: unknown[]): void {
+ const e = this.netIds_.entityOf(netId);
+ if (e === undefined || !this.world_.valid(e)) return;
+ const te = this.table.entries[componentId];
+ if (!te) return;
+ const existing = this.world_.tryGet(e, te.def) as Record<string, unknown> | null;
+ const target = existing ?? {};
+ let v = 0;
+ for (let i = 0; i < te.fields.length; i++) {
+ if (fieldMask & (1 << i)) {
+ target[te.fields[i]] = values[v++];
+ }
+ }
+ if (existing) {
+ this.world_.set(e, te.def, target);
+ } else {
+ this.world_.insert(e, te.def, target);
+ }
+ }
+
+ /** Present the buffered state at the trailing render clock. Runs each
+ * render frame (PostUpdate); `deltaTicks` = render delta in tick units. */
+ sampleInterpolation(deltaTicks: number): void {
+ if (!this.interp_ || this.interp_.newestTick === 0) return;
+ const t = this.interp_.advance(deltaTicks);
+ for (const [netId, perComp] of this.interp_.buffers) {
+ const e = this.netIds_.entityOf(netId);
+ if (e === undefined || !this.world_.valid(e)) continue;
+ for (const [componentId, buf] of perComp) {
+ const te = this.table.entries[componentId];
+ if (!te) continue;
+ const existing = this.world_.tryGet(e, te.def) as Record<string, unknown> | null;
+ const target = existing ?? {};
+ let changed = false;
+ for (const [fieldIndex, series] of buf.byField) {
+ const value = series.sample(te.shapes[fieldIndex], t);
+ if (value !== undefined) {
+ target[te.fields[fieldIndex]] = value;
+ changed = true;
+ }
+ }
+ if (!changed) continue;
+ if (existing) {
+ this.world_.set(e, te.def, target);
+ } else {
+ this.world_.insert(e, te.def, target);
+ }
}
}
}
diff --git a/sdk/src/net/replication/index.ts b/sdk/src/net/replication/index.ts
index 9e068f1fc..292057743 100644
--- a/sdk/src/net/replication/index.ts
+++ b/sdk/src/net/replication/index.ts
@@ -31,7 +31,8 @@ export {
export { Replicated, NetGhost, type ReplicatedData } from './components';
export { NetIds } from './NetIds';
export { ReplicationServer } from './server';
-export { ReplicationClient } from './client';
+export { ReplicationClient, type ReplicationClientOptions } from './client';
+export { lerpValue, InterpolationState, ComponentBuffer } from './interpolation';
export {
ReplicationPlugin,
replicationPlugin,
diff --git a/sdk/src/net/replication/interpolation.ts b/sdk/src/net/replication/interpolation.ts
new file mode 100644
index 000000000..3c3da886a
--- /dev/null
+++ b/sdk/src/net/replication/interpolation.ts
@@ -0,0 +1,180 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file interpolation.ts
+ * @brief Snapshot interpolation for NetGhost state. Delta frames land as
+ * per-field time series (sparse deltas need no full-snapshot
+ * reconstruction — a field simply has samples at the ticks it
+ * changed); the render clock trails the newest server tick by a
+ * fixed delay and samples each series there, so motion stays smooth
+ * across frame-rate mismatch and delivery jitter. Continuous values
+ * lerp (f32 scalars, f32 leaves of vectors, quats via nlerp);
+ * discrete values hold until their sample time passes.
+ */
+import type { FieldShape } from './codec';
+
+interface Sample {
+ tick: number;
+ value: unknown;
+}
+
+function isQuatKeys(keys: string[]): boolean {
+ if (keys.length !== 4) return false;
+ const set = new Set(keys);
+ return set.has('x') && set.has('y') && set.has('z') && set.has('w');
+}
+
+function lerp(a: number, b: number, t: number): number {
+ return a + (b - a) * t;
+}
+
+function nlerpQuat(a: Record<string, number>, b: Record<string, number>, t: number): Record<string, number> {
+ // Component-wise lerp toward the nearer cover (negate on negative dot),
+ // then normalize — exact enough for replication smoothing.
+ const dot = a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
+ const s = dot < 0 ? -1 : 1;
+ let x = lerp(a.x, b.x * s, t);
+ let y = lerp(a.y, b.y * s, t);
+ let z = lerp(a.z, b.z * s, t);
+ let w = lerp(a.w, b.w * s, t);
+ const len = Math.hypot(x, y, z, w);
+ if (len > 1e-8) { x /= len; y /= len; z /= len; w /= len; }
+ return { x, y, z, w };
+}
+
+/** Interpolate between two decoded values of one shape at t ∈ [0,1].
+ * Non-continuous values hold the older sample. */
+export function lerpValue(shape: FieldShape, a: unknown, b: unknown, t: number): unknown {
+ switch (shape.kind) {
+ case 'f32':
+ return lerp(a as number, b as number, t);
+ case 'object': {
+ const ra = a as Record<string, unknown>;
+ const rb = b as Record<string, unknown>;
+ if (isQuatKeys(shape.keys)) {
+ return nlerpQuat(ra as Record<string, number>, rb as Record<string, number>, t);
+ }
+ const out: Record<string, unknown> = {};
+ for (let i = 0; i < shape.keys.length; i++) {
+ const k = shape.keys[i];
+ out[k] = lerpValue(shape.shapes[i], ra[k], rb[k], t);
+ }
+ return out;
+ }
+ default:
+ return a;
+ }
+}
+
+/** One field's sample series (ticks strictly increasing). */
+class FieldSeries {
+ readonly samples: Sample[] = [];
+
+ push(tick: number, value: unknown): void {
+ const last = this.samples[this.samples.length - 1];
+ if (last && tick <= last.tick) {
+ // Redelivery / reorder of an already-seen tick: newest write wins.
+ last.value = value;
+ return;
+ }
+ this.samples.push({ tick, value });
+ }
+
+ /** Drop samples that can no longer bracket any time ≥ `beforeTick`
+ * (keep one sample at/below it as the hold/lerp base). */
+ trim(beforeTick: number): void {
+ let drop = 0;
+ while (drop < this.samples.length - 1 && this.samples[drop + 1].tick <= beforeTick) drop++;
+ if (drop > 0) this.samples.splice(0, drop);
+ }
+
+ /** Sample at time t (in ticks). Returns undefined before the first sample. */
+ sample(shape: FieldShape, t: number): unknown {
+ const s = this.samples;
+ if (s.length === 0) return undefined;
+ if (t <= s[0].tick) return t === s[0].tick ? s[0].value : undefined;
+ for (let i = s.length - 1; i >= 0; i--) {
+ if (s[i].tick <= t) {
+ const a = s[i];
+ const b = s[i + 1];
+ if (!b) return a.value; // newest known — hold
+ return lerpValue(shape, a.value, b.value, (t - a.tick) / (b.tick - a.tick));
+ }
+ }
+ return undefined;
+ }
+}
+
+/** All buffered series for one ghost component: fieldIndex → series. */
+export class ComponentBuffer {
+ readonly byField = new Map<number, FieldSeries>();
+
+ push(fieldIndex: number, tick: number, value: unknown): void {
+ let series = this.byField.get(fieldIndex);
+ if (!series) {
+ series = new FieldSeries();
+ this.byField.set(fieldIndex, series);
+ }
+ series.push(tick, value);
+ }
+}
+
+/**
+ * The client-side buffer of everything received but not yet (fully) shown.
+ * The render clock trails `newestTick` by `delayTicks`, advancing on render
+ * time with a soft correction toward the target so delivery jitter bends the
+ * clock instead of snapping the world.
+ */
+export class InterpolationState {
+ /** netId → componentId → buffer. */
+ readonly buffers = new Map<number, Map<number, ComponentBuffer>>();
+ newestTick = 0;
+ private renderTime_: number | null = null;
+
+ constructor(public delayTicks: number) {}
+
+ push(netId: number, componentId: number, fieldIndex: number, tick: number, value: unknown): void {
+ if (tick > this.newestTick) this.newestTick = tick;
+ let perComp = this.buffers.get(netId);
+ if (!perComp) {
+ perComp = new Map();
+ this.buffers.set(netId, perComp);
+ }
+ let buf = perComp.get(componentId);
+ if (!buf) {
+ buf = new ComponentBuffer();
+ perComp.set(componentId, buf);
+ }
+ buf.push(fieldIndex, tick, value);
+ }
+
+ drop(netId: number): void {
+ this.buffers.delete(netId);
+ }
+
+ /** Advance the render clock by `deltaTicks` of render time; returns the
+ * time (in server ticks) to sample the series at. */
+ advance(deltaTicks: number): number {
+ const target = this.newestTick - this.delayTicks;
+ if (this.renderTime_ === null) {
+ this.renderTime_ = target;
+ } else {
+ this.renderTime_ += deltaTicks;
+ // Soft-sync toward the target so late/early bursts bend the clock.
+ this.renderTime_ += (target - this.renderTime_) * 0.1;
+ // Never extrapolate past the newest data; never fall further than
+ // one extra delay behind.
+ const max = this.newestTick;
+ const min = target - this.delayTicks;
+ if (this.renderTime_ > max) this.renderTime_ = max;
+ if (this.renderTime_ < min) this.renderTime_ = min;
+ }
+ // Retire series history behind the clock.
+ for (const perComp of this.buffers.values()) {
+ for (const buf of perComp.values()) {
+ for (const series of buf.byField.values()) series.trim(this.renderTime_);
+ }
+ }
+ return this.renderTime_;
+ }
+}
diff --git a/sdk/tests/replication-interp.test.ts b/sdk/tests/replication-interp.test.ts
new file mode 100644
index 000000000..1e840d604
--- /dev/null
+++ b/sdk/tests/replication-interp.test.ts
@@ -0,0 +1,198 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file RC11 N3: ghost snapshot interpolation. The render clock trails the
+ * newest server tick; continuous fields lerp between bracketing
+ * samples, discrete fields hold, and bursty delivery (jitter) bends
+ * the clock instead of teleporting the ghost.
+ */
+import { describe, it, expect, beforeEach } from 'vitest';
+import { App } from '../src/app';
+import { defineComponent, clearUserComponents } from '../src/component';
+import { MemoryTransport } from '../src/net/MemoryTransport';
+import {
+ replicationPlugin, Net, Replicated,
+ lerpValue, InterpolationState,
+} from '../src/net/replication';
+
+const STEP = 1 / 60;
+
+let NetPos: ReturnType<typeof defineComponent<{ x: number; y: number; mode: string }>>;
+
+beforeEach(() => {
+ clearUserComponents();
+ NetPos = defineComponent('NetPos', { x: 0, y: 0, mode: '' }, {
+ replicatedFields: ['x', 'y', 'mode'],
+ });
+});
+
+function makeApp(): App {
+ const app = App.new();
+ app.addPlugin(replicationPlugin);
+ return app;
+}
+
+describe('lerpValue', () => {
+ it('lerps f32 scalars and f32 leaves of vectors', () => {
+ expect(lerpValue({ kind: 'f32' }, 0, 10, 0.25)).toBe(2.5);
+ const vec = lerpValue(
+ { kind: 'object', keys: ['x', 'y'], shapes: [{ kind: 'f32' }, { kind: 'f32' }] },
+ { x: 0, y: 100 }, { x: 10, y: 200 }, 0.5,
+ );
+ expect(vec).toEqual({ x: 5, y: 150 });
+ });
+
+ it('nlerps quaternions through the shorter cover', () => {
+ const shape = { kind: 'object', keys: ['x', 'y', 'z', 'w'], shapes: Array(4).fill({ kind: 'f32' }) } as const;
+ const a = { x: 0, y: 0, z: 0, w: 1 };
+ const b = { x: 0, y: 0, z: 0, w: -1 }; // same rotation, opposite cover
+ const mid = lerpValue(shape as never, a, b, 0.5) as Record<string, number>;
+ // Nlerp negates the far cover: stays the identity, never a degenerate zero quat.
+ expect(mid.w).toBeCloseTo(1);
+ expect(Math.hypot(mid.x, mid.y, mid.z, mid.w)).toBeCloseTo(1);
+ });
+
+ it('holds discrete values at the older sample', () => {
+ expect(lerpValue({ kind: 'string' }, 'walk', 'run', 0.9)).toBe('walk');
+ expect(lerpValue({ kind: 'bool' }, true, false, 0.9)).toBe(true);
+ });
+});
+
+describe('InterpolationState', () => {
+ it('samples between sparse per-field samples and holds past the newest', () => {
+ const s = new InterpolationState(2);
+ s.push(1, 0, 0, 10, 100); // netId 1, comp 0, field 0
+ s.push(1, 0, 0, 14, 300); // sparse: nothing at 11-13
+ s.newestTick = 14;
+ const buf = s.buffers.get(1)!.get(0)!;
+ const series = buf.byField.get(0)!;
+ expect(series.sample({ kind: 'f32' }, 12)).toBe(200);
+ expect(series.sample({ kind: 'f32' }, 14)).toBe(300);
+ expect(series.sample({ kind: 'f32' }, 99)).toBe(300); // hold
+ expect(series.sample({ kind: 'f32' }, 5)).toBeUndefined(); // before history
+ });
+
+ it('the render clock trails newest data and converges onto it when quiet', () => {
+ const s = new InterpolationState(2);
+ s.push(7, 0, 0, 10, 1);
+ let t = s.advance(1);
+ expect(t).toBe(8); // first advance snaps to newest - delay
+ for (let i = 0; i < 60; i++) t = s.advance(1);
+ expect(t).toBe(10); // clamped at the newest tick — final state presented
+ });
+});
+
+describe('ghost interpolation end-to-end', () => {
+ async function movingPair() {
+ const serverApp = makeApp();
+ const clientApp = makeApp();
+ const server = serverApp.getResource(Net).startServer();
+ const [ta, tb] = MemoryTransport.pair();
+ server.attachConnection(ta);
+ await clientApp.getResource(Net).connect(tb); // default delay: 2 ticks
+ return { serverApp, clientApp };
+ }
+
+ it('a moving ghost trails the server smoothly and converges when motion stops', async () => {
+ const { serverApp, clientApp } = await movingPair();
+
+ const e = serverApp.world.spawn('mover');
+ serverApp.world.insert(e, Replicated, {});
+ serverApp.world.insert(e, NetPos, { x: 0, y: 0, mode: 'walk' });
+ await serverApp.tick(STEP);
+ await clientApp.tick(STEP);
+ const ghost = clientApp.world.getEntitiesWithComponents([Replicated])[0];
+
+ const samples: number[] = [];
+ let serverX = 0;
+ for (let i = 0; i < 12; i++) {
+ serverX += 10;
+ const pos = serverApp.world.tryGet(e, NetPos)!;
+ pos.x = serverX;
+ serverApp.world.set(e, NetPos, pos);
+ await serverApp.tick(STEP);
+ await clientApp.tick(STEP);
+ samples.push(clientApp.world.tryGet(ghost, NetPos)!.x);
+ }
+
+ // Monotone, never ahead of the authority, and actually moving.
+ for (let i = 1; i < samples.length; i++) {
+ expect(samples[i]).toBeGreaterThanOrEqual(samples[i - 1]);
+ }
+ expect(samples[samples.length - 1]).toBeLessThanOrEqual(serverX);
+ expect(samples[samples.length - 1]).toBeGreaterThan(0);
+ // Trails by roughly the interpolation delay while moving.
+ expect(samples[samples.length - 1]).toBeLessThan(serverX);
+
+ // Server goes quiet → the ghost converges onto the exact final value.
+ for (let i = 0; i < 90; i++) await clientApp.tick(STEP);
+ expect(clientApp.world.tryGet(ghost, NetPos)!.x).toBe(serverX);
+ });
+
+ it('bursty delivery still presents monotone motion', async () => {
+ const serverApp = makeApp();
+ const clientApp = makeApp();
+ const server = serverApp.getResource(Net).startServer();
+ const [ta, tb] = MemoryTransport.pair({ manualFlush: true });
+ server.attachConnection(ta);
+ const connectP = clientApp.getResource(Net).connect(tb);
+ for (let i = 0; i < 8; i++) { ta.flush(); tb.flush(); await Promise.resolve(); }
+ await connectP;
+
+ const e = serverApp.world.spawn('jittery');
+ serverApp.world.insert(e, Replicated, {});
+ serverApp.world.insert(e, NetPos, { x: 0, y: 0, mode: '' });
+ await serverApp.tick(STEP);
+ ta.flush();
+ await clientApp.tick(STEP);
+ const ghost = clientApp.world.getEntitiesWithComponents([Replicated])[0];
+
+ const samples: number[] = [];
+ let serverX = 0;
+ for (let burst = 0; burst < 4; burst++) {
+ // Three server ticks arrive as one burst (network jitter).
+ for (let i = 0; i < 3; i++) {
+ serverX += 10;
+ const pos = serverApp.world.tryGet(e, NetPos)!;
+ pos.x = serverX;
+ serverApp.world.set(e, NetPos, pos);
+ await serverApp.tick(STEP);
+ }
+ ta.flush();
+ for (let i = 0; i < 3; i++) {
+ await clientApp.tick(STEP);
+ samples.push(clientApp.world.tryGet(ghost, NetPos)!.x);
+ }
+ }
+
+ for (let i = 1; i < samples.length; i++) {
+ expect(samples[i]).toBeGreaterThanOrEqual(samples[i - 1]);
+ }
+ expect(samples[samples.length - 1]).toBeGreaterThan(0);
+ expect(samples[samples.length - 1]).toBeLessThanOrEqual(serverX);
+ });
+
+ it('discrete fields step to their sample value, never blend', async () => {
+ const { serverApp, clientApp } = await movingPair();
+ const e = serverApp.world.spawn('walker');
+ serverApp.world.insert(e, Replicated, {});
+ serverApp.world.insert(e, NetPos, { x: 0, y: 0, mode: 'walk' });
+ await serverApp.tick(STEP);
+ await clientApp.tick(STEP);
+ const ghost = clientApp.world.getEntitiesWithComponents([Replicated])[0];
+
+ const pos = serverApp.world.tryGet(e, NetPos)!;
+ pos.mode = 'run';
+ serverApp.world.set(e, NetPos, pos);
+ await serverApp.tick(STEP);
+
+ const seen = new Set<string>();
+ for (let i = 0; i < 60; i++) {
+ await clientApp.tick(STEP);
+ seen.add(clientApp.world.tryGet(ghost, NetPos)!.mode);
+ }
+ // Only ever the two authored values — and it does arrive.
+ expect([...seen].every((m) => m === 'walk' || m === 'run')).toBe(true);
+ expect(seen.has('run')).toBe(true);
+ });
+});
diff --git a/sdk/tests/replication-wasm.test.ts b/sdk/tests/replication-wasm.test.ts
index a286d2117..42aa3aecf 100644
--- a/sdk/tests/replication-wasm.test.ts
+++ b/sdk/tests/replication-wasm.test.ts
@@ -39,7 +39,7 @@ describe.skipIf(!HAS_WASM)('replication over the wasm boundary (Transform)', ()
const server = serverApp.getResource(Net).startServer();
const [ta, tb] = MemoryTransport.pair();
server.attachConnection(ta);
- await clientApp.getResource(Net).connect(tb);
+ await clientApp.getResource(Net).connect(tb, { interpolationDelayTicks: 0 });
const e = serverApp.world.spawn('hero');
serverApp.world.insert(e, Transform, { position: { x: 10.5, y: -3.25, z: 0 } });
diff --git a/sdk/tests/replication.test.ts b/sdk/tests/replication.test.ts
index fc0726c81..b2a471d52 100644
--- a/sdk/tests/replication.test.ts
+++ b/sdk/tests/replication.test.ts
@@ -37,7 +37,7 @@ async function makePair() {
const server = serverApp.getResource(Net).startServer();
const [ta, tb] = MemoryTransport.pair();
server.attachConnection(ta);
- const client = await clientApp.getResource(Net).connect(tb);
+ const client = await clientApp.getResource(Net).connect(tb, { interpolationDelayTicks: 0 });
return { serverApp, clientApp, server, client };
}
@@ -142,7 +142,7 @@ describe('spawn / state / despawn replication', () => {
// Manual flush so the test can observe exactly what each tick emits.
const [ta, tb] = MemoryTransport.pair();
server.attachConnection(ta);
- const connectP = clientApp.getResource(Net).connect(tb);
+ const connectP = clientApp.getResource(Net).connect(tb, { interpolationDelayTicks: 0 });
await connectP;
const e = serverApp.world.spawn('mover');
@@ -176,7 +176,7 @@ describe('spawn / state / despawn replication', () => {
server.attachConnection(ta);
const clientApp = makeApp();
- const connectP = clientApp.getResource(Net).connect(tb);
+ const connectP = clientApp.getResource(Net).connect(tb, { interpolationDelayTicks: 0 });
// Manual flush: pump the handshake both ways.
for (let i = 0; i < 8; i++) { ta.flush(); tb.flush(); await Promise.resolve(); }
await connectP;
@@ -216,7 +216,7 @@ describe('spawn / state / despawn replication', () => {
const clientA = makeApp();
const [a1, a2] = MemoryTransport.pair();
server.attachConnection(a1);
- await clientA.getResource(Net).connect(a2);
+ await clientA.getResource(Net).connect(a2, { interpolationDelayTicks: 0 });
const e = serverApp.world.spawn('veteran');
serverApp.world.insert(e, Replicated, {});
@@ -233,7 +233,7 @@ describe('spawn / state / despawn replication', () => {
const clientB = makeApp();
const [b1, b2] = MemoryTransport.pair();
server.attachConnection(b1);
- await clientB.getResource(Net).connect(b2);
+ await clientB.getResource(Net).connect(b2, { interpolationDelayTicks: 0 });
await clientB.tick(STEP);
const ghosts = clientB.world.getEntitiesWithComponents([Replicated]);