@woosh/meep-engine 2.138.0 → 2.138.1
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/build/bundle-worker-image-decoder.js +1 -1
- package/build/bundle-worker-terrain.js +1 -1
- package/package.json +1 -1
- package/src/core/assert.d.ts +6 -0
- package/src/core/assert.d.ts.map +1 -1
- package/src/core/assert.js +16 -3
- package/src/core/binary/half_to_float_uint16.js +1 -1
- package/src/core/binary/to_half_float_uint16.d.ts.map +1 -1
- package/src/core/binary/to_half_float_uint16.js +9 -4
- package/src/core/collection/table/RowFirstTableSpec.js +1 -1
- package/src/core/events/signal/Signal.d.ts.map +1 -1
- package/src/core/events/signal/Signal.js +53 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.d.ts +3 -3
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.js +3 -3
- package/src/engine/Clock.d.ts +2 -2
- package/src/engine/Clock.js +2 -2
- package/src/engine/graphics/ecs/highlight/system/RenderableHighlightSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/highlight/system/RenderableHighlightSystem.js +17 -29
- package/src/engine/graphics/ecs/highlight/system/ShadedGeometryHighlightSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/highlight/system/ShadedGeometryHighlightSystem.js +18 -31
- package/src/engine/network/NetworkSession.d.ts +386 -0
- package/src/engine/network/NetworkSession.d.ts.map +1 -0
- package/src/engine/network/NetworkSession.js +1841 -0
- package/src/engine/network/PriorityFetch.d.ts.map +1 -1
- package/src/engine/network/PriorityFetch.js +3 -2
- package/src/engine/network/adapters/QuaternionInterpolationAdapter.d.ts +14 -0
- package/src/engine/network/adapters/QuaternionInterpolationAdapter.d.ts.map +1 -0
- package/src/engine/network/adapters/QuaternionInterpolationAdapter.js +44 -0
- package/src/engine/network/adapters/TransformInterpolationAdapter.d.ts +18 -0
- package/src/engine/network/adapters/TransformInterpolationAdapter.d.ts.map +1 -0
- package/src/engine/network/adapters/TransformInterpolationAdapter.js +79 -0
- package/src/engine/network/adapters/TransformReplicationAdapter.d.ts +37 -0
- package/src/engine/network/adapters/TransformReplicationAdapter.d.ts.map +1 -0
- package/src/engine/network/adapters/TransformReplicationAdapter.js +87 -0
- package/src/engine/network/adapters/Vector3InterpolationAdapter.d.ts +18 -0
- package/src/engine/network/adapters/Vector3InterpolationAdapter.d.ts.map +1 -0
- package/src/engine/network/adapters/Vector3InterpolationAdapter.js +46 -0
- package/src/engine/network/convertPathToURL.js +107 -107
- package/src/engine/network/core/quantize/quantize_float.d.ts +54 -0
- package/src/engine/network/core/quantize/quantize_float.d.ts.map +1 -0
- package/src/engine/network/core/quantize/quantize_float.js +66 -0
- package/src/engine/network/core/quantize/quantize_position.d.ts +44 -0
- package/src/engine/network/core/quantize/quantize_position.d.ts.map +1 -0
- package/src/engine/network/core/quantize/quantize_position.js +54 -0
- package/src/engine/network/core/sequence/ack_bitfield.d.ts +47 -0
- package/src/engine/network/core/sequence/ack_bitfield.d.ts.map +1 -0
- package/src/engine/network/core/sequence/ack_bitfield.js +77 -0
- package/src/engine/network/core/sequence/seq16.d.ts +53 -0
- package/src/engine/network/core/sequence/seq16.d.ts.map +1 -0
- package/src/engine/network/core/sequence/seq16.js +69 -0
- package/src/engine/network/core/sequence/seq32.d.ts +55 -0
- package/src/engine/network/core/sequence/seq32.d.ts.map +1 -0
- package/src/engine/network/core/sequence/seq32.js +73 -0
- package/src/engine/network/diagnostics/BandwidthMeter.d.ts +76 -0
- package/src/engine/network/diagnostics/BandwidthMeter.d.ts.map +1 -0
- package/src/engine/network/diagnostics/BandwidthMeter.js +155 -0
- package/src/engine/network/diagnostics/ReplayLog.d.ts +74 -0
- package/src/engine/network/diagnostics/ReplayLog.d.ts.map +1 -0
- package/src/engine/network/diagnostics/ReplayLog.js +137 -0
- package/src/engine/network/diagnostics/SyncTest.d.ts +74 -0
- package/src/engine/network/diagnostics/SyncTest.d.ts.map +1 -0
- package/src/engine/network/diagnostics/SyncTest.js +151 -0
- package/src/engine/network/ecs/NetworkSystem.d.ts +57 -0
- package/src/engine/network/ecs/NetworkSystem.d.ts.map +1 -0
- package/src/engine/network/ecs/NetworkSystem.js +84 -0
- package/src/engine/network/ecs/components/NetworkIdentity.d.ts +58 -0
- package/src/engine/network/ecs/components/NetworkIdentity.d.ts.map +1 -0
- package/src/engine/network/ecs/components/NetworkIdentity.js +73 -0
- package/src/engine/network/ecs/serialization/NetworkIdentitySerializationAdapter.d.ts +40 -0
- package/src/engine/network/ecs/serialization/NetworkIdentitySerializationAdapter.d.ts.map +1 -0
- package/src/engine/network/ecs/serialization/NetworkIdentitySerializationAdapter.js +64 -0
- package/src/engine/network/orchestrator/NetworkPeer.d.ts +389 -0
- package/src/engine/network/orchestrator/NetworkPeer.d.ts.map +1 -0
- package/src/engine/network/orchestrator/NetworkPeer.js +1107 -0
- package/src/engine/network/orchestrator/ServerAuthoritativeClient.d.ts +260 -0
- package/src/engine/network/orchestrator/ServerAuthoritativeClient.d.ts.map +1 -0
- package/src/engine/network/orchestrator/ServerAuthoritativeClient.js +425 -0
- package/src/engine/network/orchestrator/ServerAuthoritativeServer.d.ts +217 -0
- package/src/engine/network/orchestrator/ServerAuthoritativeServer.d.ts.map +1 -0
- package/src/engine/network/orchestrator/ServerAuthoritativeServer.js +562 -0
- package/src/engine/network/replication/Replicator.d.ts +134 -0
- package/src/engine/network/replication/Replicator.d.ts.map +1 -0
- package/src/engine/network/replication/Replicator.js +334 -0
- package/src/engine/network/replication/ScopeFilter.d.ts +64 -0
- package/src/engine/network/replication/ScopeFilter.d.ts.map +1 -0
- package/src/engine/network/replication/ScopeFilter.js +71 -0
- package/src/engine/network/sim/ActionLog.d.ts +94 -0
- package/src/engine/network/sim/ActionLog.d.ts.map +1 -0
- package/src/engine/network/sim/ActionLog.js +189 -0
- package/src/engine/network/sim/BinaryInterpolationAdapter.d.ts +58 -0
- package/src/engine/network/sim/BinaryInterpolationAdapter.d.ts.map +1 -0
- package/src/engine/network/sim/BinaryInterpolationAdapter.js +56 -0
- package/src/engine/network/sim/InterpolationLog.d.ts +165 -0
- package/src/engine/network/sim/InterpolationLog.d.ts.map +1 -0
- package/src/engine/network/sim/InterpolationLog.js +583 -0
- package/src/engine/network/sim/ReplicatedComponentRegistry.d.ts +59 -0
- package/src/engine/network/sim/ReplicatedComponentRegistry.d.ts.map +1 -0
- package/src/engine/network/sim/ReplicatedComponentRegistry.js +140 -0
- package/src/engine/network/sim/RewindEngine.d.ts +66 -0
- package/src/engine/network/sim/RewindEngine.d.ts.map +1 -0
- package/src/engine/network/sim/RewindEngine.js +182 -0
- package/src/engine/network/sim/SimAction.d.ts +133 -0
- package/src/engine/network/sim/SimAction.d.ts.map +1 -0
- package/src/engine/network/sim/SimAction.js +273 -0
- package/src/engine/network/sim/SimActionExecutor.d.ts +109 -0
- package/src/engine/network/sim/SimActionExecutor.d.ts.map +1 -0
- package/src/engine/network/sim/SimActionExecutor.js +238 -0
- package/src/engine/network/sim/SimActionRegistry.d.ts +60 -0
- package/src/engine/network/sim/SimActionRegistry.d.ts.map +1 -0
- package/src/engine/network/sim/SimActionRegistry.js +128 -0
- package/src/engine/network/sim/SmoothingState.d.ts +87 -0
- package/src/engine/network/sim/SmoothingState.d.ts.map +1 -0
- package/src/engine/network/sim/SmoothingState.js +223 -0
- package/src/engine/network/sim/Snapshotter.d.ts +98 -0
- package/src/engine/network/sim/Snapshotter.d.ts.map +1 -0
- package/src/engine/network/sim/Snapshotter.js +206 -0
- package/src/engine/network/sim/SpeculationLog.d.ts +53 -0
- package/src/engine/network/sim/SpeculationLog.d.ts.map +1 -0
- package/src/engine/network/sim/SpeculationLog.js +84 -0
- package/src/engine/network/state/Baseline.d.ts +48 -0
- package/src/engine/network/state/Baseline.d.ts.map +1 -0
- package/src/engine/network/state/Baseline.js +83 -0
- package/src/engine/network/state/ChangedEntitySet.d.ts +94 -0
- package/src/engine/network/state/ChangedEntitySet.d.ts.map +1 -0
- package/src/engine/network/state/ChangedEntitySet.js +256 -0
- package/src/engine/network/state/InputRing.d.ts +90 -0
- package/src/engine/network/state/InputRing.d.ts.map +1 -0
- package/src/engine/network/state/InputRing.js +173 -0
- package/src/engine/network/state/MutationLedger.d.ts +82 -0
- package/src/engine/network/state/MutationLedger.d.ts.map +1 -0
- package/src/engine/network/state/MutationLedger.js +182 -0
- package/src/engine/network/state/PriorityAccumulator.d.ts +104 -0
- package/src/engine/network/state/PriorityAccumulator.d.ts.map +1 -0
- package/src/engine/network/state/PriorityAccumulator.js +180 -0
- package/src/engine/network/state/ReplicationSlotTable.d.ts +78 -0
- package/src/engine/network/state/ReplicationSlotTable.d.ts.map +1 -0
- package/src/engine/network/state/ReplicationSlotTable.js +211 -0
- package/src/engine/network/time/AdaptiveRenderDelay.d.ts +128 -0
- package/src/engine/network/time/AdaptiveRenderDelay.d.ts.map +1 -0
- package/src/engine/network/time/AdaptiveRenderDelay.js +258 -0
- package/src/engine/network/time/JitterBuffer.d.ts +58 -0
- package/src/engine/network/time/JitterBuffer.d.ts.map +1 -0
- package/src/engine/network/time/JitterBuffer.js +116 -0
- package/src/engine/network/time/TimeDilation.d.ts +49 -0
- package/src/engine/network/time/TimeDilation.d.ts.map +1 -0
- package/src/engine/network/time/TimeDilation.js +62 -0
- package/src/engine/network/time/TimeSync.d.ts +68 -0
- package/src/engine/network/time/TimeSync.d.ts.map +1 -0
- package/src/engine/network/time/TimeSync.js +153 -0
- package/src/engine/network/transport/Channel.d.ts +74 -0
- package/src/engine/network/transport/Channel.d.ts.map +1 -0
- package/src/engine/network/transport/Channel.js +272 -0
- package/src/engine/network/transport/LoopbackTransport.d.ts +59 -0
- package/src/engine/network/transport/LoopbackTransport.d.ts.map +1 -0
- package/src/engine/network/transport/LoopbackTransport.js +194 -0
- package/src/engine/network/transport/ReliableCommandPipeline.d.ts +139 -0
- package/src/engine/network/transport/ReliableCommandPipeline.d.ts.map +1 -0
- package/src/engine/network/transport/ReliableCommandPipeline.js +291 -0
- package/src/engine/network/transport/Transport.d.ts +109 -0
- package/src/engine/network/transport/Transport.d.ts.map +1 -0
- package/src/engine/network/transport/Transport.js +119 -0
- package/src/engine/network/transport/adapters/NodeUDPTransport.d.ts +60 -0
- package/src/engine/network/transport/adapters/NodeUDPTransport.d.ts.map +1 -0
- package/src/engine/network/transport/adapters/NodeUDPTransport.js +206 -0
- package/src/engine/network/transport/adapters/SimulatedTransport.d.ts +110 -0
- package/src/engine/network/transport/adapters/SimulatedTransport.d.ts.map +1 -0
- package/src/engine/network/transport/adapters/SimulatedTransport.js +252 -0
- package/src/engine/network/transport/adapters/WebRTCDataChannelTransport.d.ts +33 -0
- package/src/engine/network/transport/adapters/WebRTCDataChannelTransport.d.ts.map +1 -0
- package/src/engine/network/transport/adapters/WebRTCDataChannelTransport.js +131 -0
- package/src/engine/network/transport/adapters/WebSocketTransport.d.ts +49 -0
- package/src/engine/network/transport/adapters/WebSocketTransport.d.ts.map +1 -0
- package/src/engine/network/transport/adapters/WebSocketTransport.js +180 -0
- package/src/engine/network/transport/adapters/WebTransportTransport.d.ts +73 -0
- package/src/engine/network/transport/adapters/WebTransportTransport.d.ts.map +1 -0
- package/src/engine/network/transport/adapters/WebTransportTransport.js +210 -0
- package/src/engine/network/transport/fragments/FragmentAssembler.d.ts +104 -0
- package/src/engine/network/transport/fragments/FragmentAssembler.d.ts.map +1 -0
- package/src/engine/network/transport/fragments/FragmentAssembler.js +291 -0
- package/src/engine/network/transport/fragments/FragmentRetention.d.ts +103 -0
- package/src/engine/network/transport/fragments/FragmentRetention.d.ts.map +1 -0
- package/src/engine/network/transport/fragments/FragmentRetention.js +194 -0
- package/src/engine/network/transport/fragments/fragment_send.d.ts +53 -0
- package/src/engine/network/transport/fragments/fragment_send.d.ts.map +1 -0
- package/src/engine/network/transport/fragments/fragment_send.js +147 -0
- package/src/engine/network/transport/fragments/packet_size.d.ts +93 -0
- package/src/engine/network/transport/fragments/packet_size.d.ts.map +1 -0
- package/src/engine/network/transport/fragments/packet_size.js +101 -0
- package/src/engine/network/xhr.js +23 -23
- package/src/engine/simulation/Ticker.d.ts +7 -0
- package/src/engine/simulation/Ticker.d.ts.map +1 -1
- package/src/engine/simulation/Ticker.js +15 -4
- package/src/engine/network/DataChannel.js +0 -1210
- package/src/engine/network/RemoteController.d.ts +0 -23
- package/src/engine/network/RemoteController.d.ts.map +0 -1
- package/src/engine/network/RemoteController.js +0 -114
- package/src/engine/network/remoteEditor.d.ts +0 -2
- package/src/engine/network/remoteEditor.d.ts.map +0 -1
- package/src/engine/network/remoteEditor.js +0 -142
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Roles a session can occupy. The orchestrator it wires up underneath is
|
|
3
|
+
* uniquely determined by the role.
|
|
4
|
+
*
|
|
5
|
+
* - `'client'` → {@link ServerAuthoritativeClient }: predicts locally
|
|
6
|
+
* when an input sampler is registered; reconciles to
|
|
7
|
+
* server-authoritative state arriving via AUTH_STATE.
|
|
8
|
+
* With no input sampler, a client is a pure spectator
|
|
9
|
+
* — it receives the action stream, smooths via
|
|
10
|
+
* interpolation, and never predicts or rewinds. This
|
|
11
|
+
* is the default role and covers both "playing" and
|
|
12
|
+
* "spectating" use cases.
|
|
13
|
+
* - `'host'` → {@link ServerAuthoritativeServer }: simulation
|
|
14
|
+
* authority for one or more clients; runs the optional
|
|
15
|
+
* server-side input buffer (`simulation_delay_ticks`).
|
|
16
|
+
*/
|
|
17
|
+
export type NetworkSessionRole = string;
|
|
18
|
+
/**
|
|
19
|
+
* Roles a session can occupy. The orchestrator it wires up underneath is
|
|
20
|
+
* uniquely determined by the role.
|
|
21
|
+
*
|
|
22
|
+
* - `'client'` → {@link ServerAuthoritativeClient}: predicts locally
|
|
23
|
+
* when an input sampler is registered; reconciles to
|
|
24
|
+
* server-authoritative state arriving via AUTH_STATE.
|
|
25
|
+
* With no input sampler, a client is a pure spectator
|
|
26
|
+
* — it receives the action stream, smooths via
|
|
27
|
+
* interpolation, and never predicts or rewinds. This
|
|
28
|
+
* is the default role and covers both "playing" and
|
|
29
|
+
* "spectating" use cases.
|
|
30
|
+
* - `'host'` → {@link ServerAuthoritativeServer}: simulation
|
|
31
|
+
* authority for one or more clients; runs the optional
|
|
32
|
+
* server-side input buffer (`simulation_delay_ticks`).
|
|
33
|
+
*
|
|
34
|
+
* @readonly @enum {string}
|
|
35
|
+
*/
|
|
36
|
+
export const NetworkSessionRole: Readonly<{
|
|
37
|
+
Client: "client";
|
|
38
|
+
Host: "host";
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* High-level networking facade. Wraps the orchestrator + state machinery
|
|
42
|
+
* into one config + lifecycle surface. The lower-level orchestrators
|
|
43
|
+
* remain reachable through `session.server` / `session.client` /
|
|
44
|
+
* `session.peer` for callers that need to override defaults post-hoc.
|
|
45
|
+
*
|
|
46
|
+
* Replication is component-driven: attaching a {@link NetworkIdentity}
|
|
47
|
+
* to an entity registers it with the session via an `EntityObserver`.
|
|
48
|
+
* Mutation is event-driven: callers fire
|
|
49
|
+
* `dataset.sendEvent(entity, "net_mutate_component", payload)`.
|
|
50
|
+
*
|
|
51
|
+
* Per-tick driving is a single `session.tick(dt_seconds)`. The session
|
|
52
|
+
* runs fixed-timestep stepping, client time dilation, server-side input
|
|
53
|
+
* buffer, AUTH_STATE dispatch, time-dilation feedback, and interpolated
|
|
54
|
+
* rendering for remote-owned entities.
|
|
55
|
+
*
|
|
56
|
+
* @author Alex Goldring
|
|
57
|
+
* @copyright Company Named Limited (c) 2025
|
|
58
|
+
*/
|
|
59
|
+
export class NetworkSession {
|
|
60
|
+
/**
|
|
61
|
+
* @param {{
|
|
62
|
+
* entity_manager: EntityManager,
|
|
63
|
+
* transport?: object,
|
|
64
|
+
* transport_factory?: (() => object),
|
|
65
|
+
* role?: 'client'|'host',
|
|
66
|
+
* local_peer_id?: number,
|
|
67
|
+
* simulation_delay_ticks?: number,
|
|
68
|
+
* tick_rate_hz?: number,
|
|
69
|
+
* binary_registry?: BinarySerializationRegistry,
|
|
70
|
+
* scope_filter?: object,
|
|
71
|
+
* time_dilation?: TimeDilation,
|
|
72
|
+
* adaptive_render_delay?: AdaptiveRenderDelay,
|
|
73
|
+
* server_resume_grace_ms?: number,
|
|
74
|
+
* reconnect?: {
|
|
75
|
+
* enabled?: boolean,
|
|
76
|
+
* max_attempts?: number,
|
|
77
|
+
* base_delay_ms?: number,
|
|
78
|
+
* max_delay_ms?: number,
|
|
79
|
+
* exponential_factor?: number,
|
|
80
|
+
* total_timeout_ms?: number,
|
|
81
|
+
* accept_state_resync?: boolean,
|
|
82
|
+
* },
|
|
83
|
+
* }} options
|
|
84
|
+
*
|
|
85
|
+
* - `transport` is not connected at construction — call {@link connect}
|
|
86
|
+
* with an explicit remote peer id after {@link start}.
|
|
87
|
+
* - `transport_factory` (client role): zero-arg function that returns
|
|
88
|
+
* a fresh `Transport` on each reconnect attempt. Required for
|
|
89
|
+
* automatic reconnect; without it, transport-level disconnects fall
|
|
90
|
+
* straight through to `onConnectionPermanentlyLost`.
|
|
91
|
+
* - `role` defaults to `'client'`. See {@link NetworkSessionRole}.
|
|
92
|
+
* - `local_peer_id` defaults to 0 for host, 1 for client. Must be
|
|
93
|
+
* unique across peers.
|
|
94
|
+
* - `simulation_delay_ticks` is honored only under `role: 'host'`.
|
|
95
|
+
* Default 4. See {@link ServerAuthoritativeServer}.
|
|
96
|
+
* - `tick_rate_hz` defaults to 60.
|
|
97
|
+
* - `scope_filter` defaults to {@link OwnerAwareScope} on the host.
|
|
98
|
+
* - `server_resume_grace_ms` (host role): how long peer state is
|
|
99
|
+
* retained after a transport drop before being freed. Default 30s.
|
|
100
|
+
* - `reconnect` (client role): policy for the reconnect ladder. See
|
|
101
|
+
* {@link DEFAULT_RECONNECT_POLICY}. Set `enabled: false` to opt
|
|
102
|
+
* out entirely.
|
|
103
|
+
*/
|
|
104
|
+
constructor({ entity_manager, transport, transport_factory, role, local_peer_id, simulation_delay_ticks, tick_rate_hz, binary_registry, scope_filter, time_dilation, adaptive_render_delay, server_resume_grace_ms, reconnect, }?: {
|
|
105
|
+
entity_manager: EntityManager;
|
|
106
|
+
transport?: object;
|
|
107
|
+
transport_factory?: (() => object);
|
|
108
|
+
role?: 'client' | 'host';
|
|
109
|
+
local_peer_id?: number;
|
|
110
|
+
simulation_delay_ticks?: number;
|
|
111
|
+
tick_rate_hz?: number;
|
|
112
|
+
binary_registry?: BinarySerializationRegistry;
|
|
113
|
+
scope_filter?: object;
|
|
114
|
+
time_dilation?: TimeDilation;
|
|
115
|
+
adaptive_render_delay?: AdaptiveRenderDelay;
|
|
116
|
+
server_resume_grace_ms?: number;
|
|
117
|
+
reconnect?: {
|
|
118
|
+
enabled?: boolean;
|
|
119
|
+
max_attempts?: number;
|
|
120
|
+
base_delay_ms?: number;
|
|
121
|
+
max_delay_ms?: number;
|
|
122
|
+
exponential_factor?: number;
|
|
123
|
+
total_timeout_ms?: number;
|
|
124
|
+
accept_state_resync?: boolean;
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
/**
|
|
128
|
+
* Set after `#render_interpolated_entities` writes interp values into
|
|
129
|
+
* live components; cleared by `normalize_if_dirty`. Drives the
|
|
130
|
+
* canonical-form invariant: live is canonical when this is false,
|
|
131
|
+
* polluted (smooth) when true.
|
|
132
|
+
* @private @type {boolean}
|
|
133
|
+
*/
|
|
134
|
+
private render_dirty;
|
|
135
|
+
/**
|
|
136
|
+
* Server-issued session token (raw UUID v1 bytes). Set on first
|
|
137
|
+
* INITIAL_SYNC arrival; refreshed on every Tier-3 resync. Sent in
|
|
138
|
+
* `RESUME_HELLO` to claim continuity with a prior session record.
|
|
139
|
+
* Observable to game code for diagnostics; not auth-grade.
|
|
140
|
+
* @type {UUID|null}
|
|
141
|
+
*/
|
|
142
|
+
session_token: UUID | null;
|
|
143
|
+
/**
|
|
144
|
+
* Host: a connected peer's transport reported a disconnect (the peer
|
|
145
|
+
* has entered the grace window). Args: `(peer_id, reason)`.
|
|
146
|
+
* @type {Signal}
|
|
147
|
+
*/
|
|
148
|
+
onPeerLost: Signal;
|
|
149
|
+
/**
|
|
150
|
+
* Host: a peer has been permanently freed — either via
|
|
151
|
+
* `drop_peer()`, a grace-window timeout, or a peer-initiated
|
|
152
|
+
* DISCONNECT. Args: `(peer_id, reason)`.
|
|
153
|
+
* @type {Signal}
|
|
154
|
+
*/
|
|
155
|
+
onPeerPermanentlyDropped: Signal;
|
|
156
|
+
/**
|
|
157
|
+
* Client: the transport has reported a disconnect, and the
|
|
158
|
+
* reconnect ladder has started. Args: `(reason)`.
|
|
159
|
+
* @type {Signal}
|
|
160
|
+
*/
|
|
161
|
+
onConnectionLost: Signal;
|
|
162
|
+
/**
|
|
163
|
+
* Client: about to rebuild the transport and dial the host. Args:
|
|
164
|
+
* `(attempt_number)`.
|
|
165
|
+
* @type {Signal}
|
|
166
|
+
*/
|
|
167
|
+
onReconnectAttempt: Signal;
|
|
168
|
+
/**
|
|
169
|
+
* Client: reconnect succeeded. Args: `({ state_resynced: boolean })` —
|
|
170
|
+
* `state_resynced` is `true` if we fell through to Tier-3 (server
|
|
171
|
+
* had purged our state and re-sent INITIAL_SYNC), `false` for the
|
|
172
|
+
* happy Tier-2 path where the action stream just resumed.
|
|
173
|
+
* @type {Signal}
|
|
174
|
+
*/
|
|
175
|
+
onReconnected: Signal;
|
|
176
|
+
/**
|
|
177
|
+
* Client: the reconnect ladder is exhausted, or the host explicitly
|
|
178
|
+
* kicked us with a DISCONNECT packet, or `reconnect.enabled` is
|
|
179
|
+
* false and the link dropped. Args: `(reason)`.
|
|
180
|
+
* @type {Signal}
|
|
181
|
+
*/
|
|
182
|
+
onConnectionPermanentlyLost: Signal;
|
|
183
|
+
/**
|
|
184
|
+
* @readonly
|
|
185
|
+
* @type {EntityManager}
|
|
186
|
+
*/
|
|
187
|
+
readonly entity_manager: EntityManager;
|
|
188
|
+
/**
|
|
189
|
+
* @readonly
|
|
190
|
+
* @type {EntityComponentDataset}
|
|
191
|
+
*/
|
|
192
|
+
readonly world: EntityComponentDataset;
|
|
193
|
+
/**
|
|
194
|
+
* @readonly
|
|
195
|
+
* @type {NetworkSessionRole|string}
|
|
196
|
+
*/
|
|
197
|
+
readonly role: NetworkSessionRole | string;
|
|
198
|
+
/**
|
|
199
|
+
* @readonly
|
|
200
|
+
* @type {number}
|
|
201
|
+
*/
|
|
202
|
+
readonly tick_period_ms: number;
|
|
203
|
+
/**
|
|
204
|
+
* @readonly
|
|
205
|
+
* @type {number}
|
|
206
|
+
*/
|
|
207
|
+
readonly simulation_delay_ticks: number;
|
|
208
|
+
/**
|
|
209
|
+
* @readonly
|
|
210
|
+
* @type {number}
|
|
211
|
+
*/
|
|
212
|
+
readonly local_peer_id: number;
|
|
213
|
+
/**
|
|
214
|
+
* @readonly
|
|
215
|
+
* @type {BinarySerializationRegistry}
|
|
216
|
+
*/
|
|
217
|
+
readonly binary_registry: BinarySerializationRegistry;
|
|
218
|
+
/**
|
|
219
|
+
* Register a component class for network replication.
|
|
220
|
+
*
|
|
221
|
+
* The component must have a {@link BinaryClassSerializationAdapter}
|
|
222
|
+
* registered for its `typeName` in the session's `binary_registry`
|
|
223
|
+
* before {@link start} is called — that adapter handles the wire
|
|
224
|
+
* format and rewind capture.
|
|
225
|
+
*
|
|
226
|
+
* `interpolator` is optional. When omitted, the component's state
|
|
227
|
+
* snaps on each received update (no sub-tick smoothing). When
|
|
228
|
+
* provided, it must extend {@link BinaryInterpolationAdapter} with
|
|
229
|
+
* `kind = InterpolationKind.Linear` — Discrete and Cubic are
|
|
230
|
+
* reserved for future support and currently throw.
|
|
231
|
+
*
|
|
232
|
+
* The order of `replicate()` calls must match across all peers in
|
|
233
|
+
* the session: AUTH_STATE payload layout iterates components in
|
|
234
|
+
* insertion order.
|
|
235
|
+
*
|
|
236
|
+
* @param {Function} ComponentClass
|
|
237
|
+
* @param {BinaryInterpolationAdapter} [interpolator]
|
|
238
|
+
*/
|
|
239
|
+
replicate(ComponentClass: Function, interpolator?: BinaryInterpolationAdapter): void;
|
|
240
|
+
/**
|
|
241
|
+
* Register a user-defined {@link SimAction} subclass with the
|
|
242
|
+
* session. The action's `type_id` is assigned by the underlying
|
|
243
|
+
* registry when {@link start} runs. Calling code constructs
|
|
244
|
+
* instances directly (`new MyAction(...)`) and dispatches via
|
|
245
|
+
* {@link send} or returns them from the input sampler.
|
|
246
|
+
*
|
|
247
|
+
* @param {Function} SimActionClass class extending SimAction
|
|
248
|
+
*/
|
|
249
|
+
defineAction(SimActionClass: Function): void;
|
|
250
|
+
/**
|
|
251
|
+
* Install a per-tick input sampler (client role only). The sampler
|
|
252
|
+
* is called once per local sim tick at predict time and must return
|
|
253
|
+
* an array of {@link SimAction} instances representing the local
|
|
254
|
+
* peer's inputs for that frame. The session executes them locally
|
|
255
|
+
* (predict), records their serialized bytes for replay, and forwards
|
|
256
|
+
* them over the action stream.
|
|
257
|
+
*
|
|
258
|
+
* The sampler is NOT called during reconciliation replay — the
|
|
259
|
+
* recorded bytes are deserialized and re-executed instead, so the
|
|
260
|
+
* action set faithfully reproduces what the user originally
|
|
261
|
+
* sampled at that frame.
|
|
262
|
+
*
|
|
263
|
+
* Return `[]` (or `null`) for ticks with no inputs.
|
|
264
|
+
*
|
|
265
|
+
* @param {(frame: number) => Array<SimAction>|null} sampler_fn
|
|
266
|
+
*/
|
|
267
|
+
defineInputSampler(sampler_fn: (frame: number) => Array<SimAction> | null): void;
|
|
268
|
+
/**
|
|
269
|
+
* Wire the session to the engine. After this, the EntityObserver
|
|
270
|
+
* is active, the right orchestrator is constructed, and a
|
|
271
|
+
* {@link NetworkSystem} is attached. Subsequent {@link replicate}
|
|
272
|
+
* / {@link defineAction} / {@link defineInputSampler} calls throw.
|
|
273
|
+
*
|
|
274
|
+
* Pre-condition: every component class passed to {@link replicate}
|
|
275
|
+
* must already have a `BinaryClassSerializationAdapter` registered
|
|
276
|
+
* in the session's binary_registry.
|
|
277
|
+
*/
|
|
278
|
+
start(): Promise<void>;
|
|
279
|
+
/**
|
|
280
|
+
* Connect to a remote peer. Host can connect many peers (one per
|
|
281
|
+
* client); client typically connects one (the server). Called both
|
|
282
|
+
* for first-time connects and reconnect attempts — the session
|
|
283
|
+
* detects which based on whether a `session_token` is cached
|
|
284
|
+
* (client) or whether the peer is in the grace window (host).
|
|
285
|
+
*
|
|
286
|
+
* @param {number} remote_peer_id
|
|
287
|
+
* @param {object} transport
|
|
288
|
+
*/
|
|
289
|
+
connect(remote_peer_id: number, transport: object): void;
|
|
290
|
+
/**
|
|
291
|
+
* Host-only: forcibly free a peer's state, regardless of whether
|
|
292
|
+
* they are actively connected, in the grace window, or already
|
|
293
|
+
* unknown. Fires `onPeerPermanentlyDropped(peer_id, reason)`.
|
|
294
|
+
* Sends a DISCONNECT packet if the peer is still actively
|
|
295
|
+
* connected so the remote can short-circuit its reconnect attempts.
|
|
296
|
+
*
|
|
297
|
+
* Policy for *when* to drop (high server load, anti-cheat, admin
|
|
298
|
+
* kick, etc.) is the caller's; the session provides the mechanism.
|
|
299
|
+
*
|
|
300
|
+
* @param {number} peer_id
|
|
301
|
+
* @param {string} [reason]
|
|
302
|
+
*/
|
|
303
|
+
drop_peer(peer_id: number, reason?: string): void;
|
|
304
|
+
/**
|
|
305
|
+
* Client-only: voluntarily disconnect from the server. Sends a
|
|
306
|
+
* DISCONNECT packet so the host can free state immediately and
|
|
307
|
+
* skip the grace window. Disables reconnect for this session.
|
|
308
|
+
*
|
|
309
|
+
* @param {string} [reason]
|
|
310
|
+
*/
|
|
311
|
+
disconnect(reason?: string): void;
|
|
312
|
+
/**
|
|
313
|
+
* Tear down. Idempotent — safe to call from cleanup paths.
|
|
314
|
+
*/
|
|
315
|
+
stop(): void;
|
|
316
|
+
/**
|
|
317
|
+
* Fixed-timestep accumulator-driven step. Catch-up bounded by
|
|
318
|
+
* `MAX_FIXED_STEPS_PER_TICK`. Under `role: 'client'` the local frame
|
|
319
|
+
* advances at `1 / dilation_factor` per fixed step.
|
|
320
|
+
*
|
|
321
|
+
* @param {number} dt_seconds elapsed wall seconds since the previous call
|
|
322
|
+
*/
|
|
323
|
+
tick(dt_seconds: number): void;
|
|
324
|
+
/**
|
|
325
|
+
* Undo render-time interpolation on remote-owned components by
|
|
326
|
+
* restoring each from its latest InterpolationLog entry. Idempotent
|
|
327
|
+
* via the `render_dirty` flag — cheap when false.
|
|
328
|
+
*
|
|
329
|
+
* Called from `tick()` (top), `executor.before_execute` (per-action
|
|
330
|
+
* applies, including transport-delivered action stream), and
|
|
331
|
+
* `client.onBeforeReconcile` (before the rewind walk).
|
|
332
|
+
*
|
|
333
|
+
* @private
|
|
334
|
+
*/
|
|
335
|
+
private normalize_if_dirty;
|
|
336
|
+
/**
|
|
337
|
+
* Dispatch one user-defined action. Equivalent to
|
|
338
|
+
* `peer.executor.execute(action, this.local_peer_id)` but exposed
|
|
339
|
+
* at the session level so callers don't need a reference to the
|
|
340
|
+
* executor or to know the local peer id.
|
|
341
|
+
*
|
|
342
|
+
* @param {SimAction} action_instance
|
|
343
|
+
*/
|
|
344
|
+
send(action_instance: SimAction): void;
|
|
345
|
+
/**
|
|
346
|
+
* @returns {ServerAuthoritativeServer|null}
|
|
347
|
+
*/
|
|
348
|
+
get server(): ServerAuthoritativeServer;
|
|
349
|
+
/**
|
|
350
|
+
* @returns {ServerAuthoritativeClient|null}
|
|
351
|
+
*/
|
|
352
|
+
get client(): ServerAuthoritativeClient;
|
|
353
|
+
/**
|
|
354
|
+
* @returns {NetworkPeer|null}
|
|
355
|
+
*/
|
|
356
|
+
get peer(): NetworkPeer;
|
|
357
|
+
/**
|
|
358
|
+
* @returns {InterpolationLog|null}
|
|
359
|
+
*/
|
|
360
|
+
get interpolation_log(): InterpolationLog;
|
|
361
|
+
/**
|
|
362
|
+
* @returns {AdaptiveRenderDelay}
|
|
363
|
+
*/
|
|
364
|
+
get adaptive_render_delay(): AdaptiveRenderDelay;
|
|
365
|
+
/**
|
|
366
|
+
* @returns {TimeDilation}
|
|
367
|
+
*/
|
|
368
|
+
get time_dilation(): TimeDilation;
|
|
369
|
+
/**
|
|
370
|
+
* Most recent locally-completed sim frame.
|
|
371
|
+
*/
|
|
372
|
+
get current_frame(): number;
|
|
373
|
+
#private;
|
|
374
|
+
}
|
|
375
|
+
import { UUID } from "../ecs/guid/UUID.js";
|
|
376
|
+
import Signal from "../../core/events/signal/Signal.js";
|
|
377
|
+
import { BinarySerializationRegistry } from "../ecs/storage/binary/BinarySerializationRegistry.js";
|
|
378
|
+
import { BinaryInterpolationAdapter } from "./sim/BinaryInterpolationAdapter.js";
|
|
379
|
+
import { SimAction } from "./sim/SimAction.js";
|
|
380
|
+
import { ServerAuthoritativeServer } from "./orchestrator/ServerAuthoritativeServer.js";
|
|
381
|
+
import { ServerAuthoritativeClient } from "./orchestrator/ServerAuthoritativeClient.js";
|
|
382
|
+
import { NetworkPeer } from "./orchestrator/NetworkPeer.js";
|
|
383
|
+
import { InterpolationLog } from "./sim/InterpolationLog.js";
|
|
384
|
+
import { AdaptiveRenderDelay } from "./time/AdaptiveRenderDelay.js";
|
|
385
|
+
import { TimeDilation } from "./time/TimeDilation.js";
|
|
386
|
+
//# sourceMappingURL=NetworkSession.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NetworkSession.d.ts","sourceRoot":"","sources":["../../../../src/engine/network/NetworkSession.js"],"names":[],"mappings":"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"}
|