@dcl/ecs 7.29.1-35154657340.commit-e2bbcc9 → 7.29.1-35332187735.commit-5959224
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/components/index.d.ts +0 -5
- package/dist/components/index.js +2 -5
- package/dist/components/manual/Transform.d.ts +0 -9
- package/dist/components/manual/Transform.js +3 -3
- package/dist/components/types.d.ts +0 -1
- package/dist/engine/component.d.ts +1 -52
- package/dist/engine/grow-only-value-set-component-definition.js +2 -45
- package/dist/engine/lww-element-set-component-definition.d.ts +1 -3
- package/dist/engine/lww-element-set-component-definition.js +13 -68
- package/dist/index.d.ts +1 -2
- package/dist/index.js +0 -1
- package/dist/serialization/crdt/index.d.ts +0 -1
- package/dist/serialization/crdt/index.js +0 -1
- package/dist/serialization/crdt/network/utils.d.ts +9 -0
- package/dist/serialization/crdt/network/utils.js +60 -0
- package/dist/serialization/crdt/types.d.ts +3 -25
- package/dist/serialization/crdt/types.js +1 -3
- package/dist/systems/crdt/index.d.ts +1 -0
- package/dist/systems/crdt/index.js +143 -76
- package/dist/systems/crdt/types.d.ts +0 -10
- package/dist-cjs/components/index.d.ts +0 -5
- package/dist-cjs/components/index.js +3 -7
- package/dist-cjs/components/manual/Transform.d.ts +0 -9
- package/dist-cjs/components/manual/Transform.js +3 -3
- package/dist-cjs/components/types.d.ts +0 -1
- package/dist-cjs/engine/component.d.ts +1 -52
- package/dist-cjs/engine/grow-only-value-set-component-definition.js +1 -44
- package/dist-cjs/engine/lww-element-set-component-definition.d.ts +1 -3
- package/dist-cjs/engine/lww-element-set-component-definition.js +14 -71
- package/dist-cjs/index.d.ts +1 -2
- package/dist-cjs/index.js +1 -2
- package/dist-cjs/serialization/crdt/index.d.ts +0 -1
- package/dist-cjs/serialization/crdt/index.js +0 -1
- package/dist-cjs/serialization/crdt/network/utils.d.ts +9 -0
- package/dist-cjs/serialization/crdt/network/utils.js +67 -0
- package/dist-cjs/serialization/crdt/types.d.ts +3 -25
- package/dist-cjs/serialization/crdt/types.js +1 -3
- package/dist-cjs/systems/crdt/index.d.ts +1 -0
- package/dist-cjs/systems/crdt/index.js +166 -76
- package/dist-cjs/systems/crdt/types.d.ts +0 -10
- package/package.json +2 -2
- package/dist/components/manual/CreatedBy.d.ts +0 -9
- package/dist/components/manual/CreatedBy.js +0 -8
- package/dist/serialization/crdt/authoritativePutComponent.d.ts +0 -15
- package/dist/serialization/crdt/authoritativePutComponent.js +0 -47
- package/dist-cjs/components/manual/CreatedBy.d.ts +0 -9
- package/dist-cjs/components/manual/CreatedBy.js +0 -10
- package/dist-cjs/serialization/crdt/authoritativePutComponent.d.ts +0 -15
- package/dist-cjs/serialization/crdt/authoritativePutComponent.js +0 -50
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import { EntityState } from '../../engine/entity';
|
|
2
2
|
import { ReadWriteByteBuffer } from '../../serialization/ByteBuffer';
|
|
3
|
-
import { AppendValueOperation, CrdtMessageProtocol } from '../../serialization/crdt';
|
|
3
|
+
import { AppendValueOperation, CrdtMessageProtocol, DeleteComponentNetwork, DeleteEntityNetwork } from '../../serialization/crdt';
|
|
4
4
|
import { DeleteComponent } from '../../serialization/crdt/deleteComponent';
|
|
5
5
|
import { DeleteEntity } from '../../serialization/crdt/deleteEntity';
|
|
6
6
|
import { PutComponentOperation } from '../../serialization/crdt/putComponent';
|
|
7
|
-
import { AuthoritativePutComponentOperation } from '../../serialization/crdt/authoritativePutComponent';
|
|
8
7
|
import { CrdtMessageType } from '../../serialization/crdt/types';
|
|
8
|
+
import { PutNetworkComponentOperation } from '../../serialization/crdt/network/putComponentNetwork';
|
|
9
|
+
import { NetworkEntity as defineNetworkEntity, NetworkParent as defineNetworkParent, Transform as defineTransform } from '../../components';
|
|
10
|
+
import * as networkUtils from '../../serialization/crdt/network/utils';
|
|
11
|
+
// NetworkMessages can only have a MAX_SIZE of 12kb. So we need to send it in chunks.
|
|
12
|
+
export const LIVEKIT_MAX_SIZE = 12;
|
|
9
13
|
/**
|
|
10
14
|
* @internal
|
|
11
15
|
*/
|
|
12
16
|
export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
13
17
|
const transports = [];
|
|
14
|
-
//
|
|
18
|
+
// Components that we used on this system
|
|
19
|
+
const NetworkEntity = defineNetworkEntity(engine);
|
|
20
|
+
const NetworkParent = defineNetworkParent(engine);
|
|
21
|
+
const Transform = defineTransform(engine);
|
|
15
22
|
// Messages that we received at transport.onMessage waiting to be processed
|
|
16
23
|
const receivedMessages = [];
|
|
17
24
|
// Messages already processed by the engine but that we need to broadcast to other transports.
|
|
@@ -36,20 +43,27 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
36
43
|
if (header.type === CrdtMessageType.DELETE_COMPONENT) {
|
|
37
44
|
message = DeleteComponent.read(buffer);
|
|
38
45
|
}
|
|
46
|
+
else if (header.type === CrdtMessageType.DELETE_COMPONENT_NETWORK) {
|
|
47
|
+
message = DeleteComponentNetwork.read(buffer);
|
|
48
|
+
}
|
|
39
49
|
else if (header.type === CrdtMessageType.PUT_COMPONENT) {
|
|
40
50
|
message = PutComponentOperation.read(buffer);
|
|
41
51
|
}
|
|
42
|
-
else if (header.type === CrdtMessageType.
|
|
43
|
-
message =
|
|
52
|
+
else if (header.type === CrdtMessageType.PUT_COMPONENT_NETWORK) {
|
|
53
|
+
message = PutNetworkComponentOperation.read(buffer);
|
|
44
54
|
}
|
|
45
55
|
else if (header.type === CrdtMessageType.DELETE_ENTITY) {
|
|
46
56
|
message = DeleteEntity.read(buffer);
|
|
47
57
|
}
|
|
58
|
+
else if (header.type === CrdtMessageType.DELETE_ENTITY_NETWORK) {
|
|
59
|
+
message = DeleteEntityNetwork.read(buffer);
|
|
60
|
+
}
|
|
48
61
|
else if (header.type === CrdtMessageType.APPEND_VALUE) {
|
|
49
62
|
message = AppendValueOperation.read(buffer);
|
|
63
|
+
// Unknown message, we skip it
|
|
50
64
|
}
|
|
51
65
|
else {
|
|
52
|
-
//
|
|
66
|
+
// consume the message
|
|
53
67
|
buffer.incrementReadOffset(header.length);
|
|
54
68
|
}
|
|
55
69
|
if (message) {
|
|
@@ -71,12 +85,20 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
71
85
|
return messagesToProcess;
|
|
72
86
|
}
|
|
73
87
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
88
|
+
* Find the local entityId associated to the network component message.
|
|
89
|
+
* It's a mapping Network -> to Local
|
|
90
|
+
* If it's not a network message, return the entityId received by the message
|
|
77
91
|
*/
|
|
78
|
-
function
|
|
79
|
-
|
|
92
|
+
function findNetworkId(msg) {
|
|
93
|
+
const hasNetworkId = 'networkId' in msg;
|
|
94
|
+
if (hasNetworkId) {
|
|
95
|
+
for (const [entityId, network] of engine.getEntitiesWith(NetworkEntity)) {
|
|
96
|
+
if (network.networkId === msg.networkId && network.entityId === msg.entityId) {
|
|
97
|
+
return { entityId, network };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return { entityId: msg.entityId };
|
|
80
102
|
}
|
|
81
103
|
/**
|
|
82
104
|
* This fn will be called on every tick.
|
|
@@ -86,68 +108,46 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
86
108
|
const messagesToProcess = getMessages(receivedMessages);
|
|
87
109
|
const entitiesShouldBeCleaned = [];
|
|
88
110
|
for (const msg of messagesToProcess) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
entitiesShouldBeCleaned.push(msg.entityId);
|
|
111
|
+
let { entityId, network } = findNetworkId(msg);
|
|
112
|
+
// We receive a new Entity. Create the localEntity and map it to the NetworkEntity component
|
|
113
|
+
if (networkUtils.isNetworkMessage(msg) && !network) {
|
|
114
|
+
entityId = engine.addEntity();
|
|
115
|
+
network = { entityId: msg.entityId, networkId: msg.networkId };
|
|
116
|
+
NetworkEntity.createOrReplace(entityId, network);
|
|
117
|
+
}
|
|
118
|
+
if (msg.type === CrdtMessageType.DELETE_ENTITY || msg.type === CrdtMessageType.DELETE_ENTITY_NETWORK) {
|
|
119
|
+
entitiesShouldBeCleaned.push(entityId);
|
|
100
120
|
broadcastMessages.push(msg);
|
|
101
121
|
}
|
|
102
122
|
else {
|
|
103
|
-
const entityState = engine.entityContainer.getEntityState(
|
|
104
|
-
// Skip updates from removed
|
|
123
|
+
const entityState = engine.entityContainer.getEntityState(entityId);
|
|
124
|
+
// Skip updates from removed entityes
|
|
105
125
|
if (entityState === EntityState.Removed)
|
|
106
126
|
continue;
|
|
107
|
-
//
|
|
108
|
-
// which bypasses timestamps entirely) on reserved entities from untrusted
|
|
109
|
-
// transports. Dropping before updateFromCrdt keeps local LWW timestamps
|
|
110
|
-
// unpoisoned by forged high timestamps, and also prevents the
|
|
111
|
-
// unknown-component rebroadcast below from relaying forged reserved-entity
|
|
112
|
-
// data to other transports (including the renderer).
|
|
113
|
-
if (entityState === EntityState.Reserved && !isTrustedForReservedEntities(msg.transportId))
|
|
114
|
-
continue;
|
|
115
|
-
// Entities with unknown state should update its entity state
|
|
127
|
+
// Entities with unknown entities should update its entity state
|
|
116
128
|
if (entityState === EntityState.Unknown) {
|
|
117
|
-
engine.entityContainer.updateUsedEntity(
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
? component.__forceUpdateFromCrdt(msg)
|
|
128
|
-
: component.updateFromCrdt(msg);
|
|
129
|
-
}
|
|
130
|
-
catch (e) {
|
|
131
|
-
console.error('[receiveMessages] ERROR processing message', msg, e);
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
const result = tryUpdate();
|
|
136
|
-
if (!result)
|
|
137
|
-
continue;
|
|
138
|
-
const [conflictMessage, value] = result;
|
|
139
|
-
if (!conflictMessage) {
|
|
140
|
-
// Add message to broadcast queue when no conflict
|
|
141
|
-
broadcastMessages.push(msg);
|
|
142
|
-
onProcessEntityComponentChange && onProcessEntityComponentChange(msg.entityId, msg.type, component, value);
|
|
143
|
-
}
|
|
129
|
+
engine.entityContainer.updateUsedEntity(entityId);
|
|
130
|
+
}
|
|
131
|
+
const component = engine.getComponentOrNull(msg.componentId);
|
|
132
|
+
/* istanbul ignore else */
|
|
133
|
+
if (component) {
|
|
134
|
+
if (msg.type === CrdtMessageType.PUT_COMPONENT &&
|
|
135
|
+
component.componentId === Transform.componentId &&
|
|
136
|
+
NetworkEntity.has(entityId) &&
|
|
137
|
+
NetworkParent.has(entityId)) {
|
|
138
|
+
msg.data = networkUtils.fixTransformParent(msg);
|
|
144
139
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
140
|
+
const [conflictMessage, value] = component.updateFromCrdt({ ...msg, entityId });
|
|
141
|
+
if (!conflictMessage) {
|
|
142
|
+
// Add message to transport queue to be processed by others transports
|
|
148
143
|
broadcastMessages.push(msg);
|
|
144
|
+
onProcessEntityComponentChange && onProcessEntityComponentChange(entityId, msg.type, component, value);
|
|
149
145
|
}
|
|
150
146
|
}
|
|
147
|
+
else {
|
|
148
|
+
// TODO: test this line, it is fundammental to make the editor work
|
|
149
|
+
broadcastMessages.push(msg);
|
|
150
|
+
}
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
// the last stage of the syncrhonization is to delete the entities
|
|
@@ -161,17 +161,16 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
|
-
*
|
|
164
|
+
* Iterates the dirty map and generates crdt messages to be send
|
|
165
165
|
*/
|
|
166
166
|
async function sendMessages(entitiesDeletedThisTick) {
|
|
167
|
-
//
|
|
167
|
+
// CRDT Messages will be the merge between the recieved transport messages and the new crdt messages
|
|
168
168
|
const crdtMessages = getMessages(broadcastMessages);
|
|
169
169
|
const buffer = new ReadWriteByteBuffer();
|
|
170
|
-
// Generate CRDT messages from component updates
|
|
171
170
|
for (const component of engine.componentsIter()) {
|
|
172
171
|
for (const message of component.getCrdtUpdates()) {
|
|
173
172
|
const offset = buffer.currentWriteOffset();
|
|
174
|
-
//
|
|
173
|
+
// Avoid creating messages if there is no transport that will handle it
|
|
175
174
|
if (transports.some((t) => t.filter(message))) {
|
|
176
175
|
if (message.type === CrdtMessageType.PUT_COMPONENT) {
|
|
177
176
|
PutComponentOperation.write(message.entityId, message.timestamp, message.componentId, message.data, buffer);
|
|
@@ -195,7 +194,7 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
195
194
|
}
|
|
196
195
|
}
|
|
197
196
|
}
|
|
198
|
-
//
|
|
197
|
+
// After all updates, I execute the DeletedEntity messages
|
|
199
198
|
for (const entityId of entitiesDeletedThisTick) {
|
|
200
199
|
const offset = buffer.currentWriteOffset();
|
|
201
200
|
DeleteEntity.write(entityId, buffer);
|
|
@@ -206,19 +205,87 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
206
205
|
});
|
|
207
206
|
onProcessEntityComponentChange && onProcessEntityComponentChange(entityId, CrdtMessageType.DELETE_ENTITY);
|
|
208
207
|
}
|
|
209
|
-
//
|
|
210
|
-
|
|
211
|
-
|
|
208
|
+
// Send CRDT messages to transports
|
|
209
|
+
const transportBuffer = new ReadWriteByteBuffer();
|
|
210
|
+
for (const index in transports) {
|
|
211
|
+
const __NetworkMessagesBuffer = [];
|
|
212
|
+
const transportIndex = Number(index);
|
|
213
|
+
const transport = transports[transportIndex];
|
|
214
|
+
const isRendererTransport = transport.type === 'renderer';
|
|
215
|
+
const isNetworkTransport = transport.type === 'network';
|
|
216
|
+
// Reset Buffer for each Transport
|
|
217
|
+
transportBuffer.resetBuffer();
|
|
218
|
+
const buffer = new ReadWriteByteBuffer();
|
|
219
|
+
// Then we send all the new crdtMessages that the transport needs to process
|
|
212
220
|
for (const message of crdtMessages) {
|
|
213
221
|
// Avoid echo messages
|
|
214
|
-
if (message.transportId ===
|
|
222
|
+
if (message.transportId === transportIndex)
|
|
215
223
|
continue;
|
|
216
|
-
//
|
|
217
|
-
if (transport.filter(message))
|
|
218
|
-
|
|
224
|
+
// Redundant message for the transport
|
|
225
|
+
if (!transport.filter(message))
|
|
226
|
+
continue;
|
|
227
|
+
// Check if adding this message would exceed the size limit
|
|
228
|
+
const currentBufferSize = transportBuffer.toBinary().byteLength;
|
|
229
|
+
const messageSize = message.messageBuffer.byteLength;
|
|
230
|
+
if (isNetworkTransport && (currentBufferSize + messageSize) / 1024 > LIVEKIT_MAX_SIZE) {
|
|
231
|
+
// If the current buffer has content, save it as a chunk
|
|
232
|
+
if (currentBufferSize > 0) {
|
|
233
|
+
__NetworkMessagesBuffer.push(transportBuffer.toCopiedBinary());
|
|
234
|
+
transportBuffer.resetBuffer();
|
|
235
|
+
}
|
|
236
|
+
// If the message itself is larger than the limit, we need to handle it specially
|
|
237
|
+
// For now, we'll skip it to prevent infinite loops
|
|
238
|
+
if (messageSize / 1024 > LIVEKIT_MAX_SIZE) {
|
|
239
|
+
console.error(`Message too large (${messageSize} bytes), skipping message for entity ${message.entityId}`);
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
219
242
|
}
|
|
243
|
+
const { entityId } = findNetworkId(message);
|
|
244
|
+
const transformNeedsFix = 'componentId' in message &&
|
|
245
|
+
message.componentId === Transform.componentId &&
|
|
246
|
+
Transform.has(entityId) &&
|
|
247
|
+
NetworkParent.has(entityId) &&
|
|
248
|
+
NetworkEntity.has(entityId);
|
|
249
|
+
// If there was a LOCAL change in the transform. Add the parent to that transform
|
|
250
|
+
if (isRendererTransport && message.type === CrdtMessageType.PUT_COMPONENT && transformNeedsFix) {
|
|
251
|
+
const parent = findNetworkId(NetworkParent.get(entityId));
|
|
252
|
+
const transformData = networkUtils.fixTransformParent(message, Transform.get(entityId), parent.entityId);
|
|
253
|
+
const offset = buffer.currentWriteOffset();
|
|
254
|
+
PutComponentOperation.write(entityId, message.timestamp, message.componentId, transformData, buffer);
|
|
255
|
+
transportBuffer.writeBuffer(buffer.buffer().subarray(offset, buffer.currentWriteOffset()), false);
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (isRendererTransport && networkUtils.isNetworkMessage(message)) {
|
|
259
|
+
// If it's the renderer transport and its a NetworkMessage, we need to fix the entityId field and convert it to a known Message.
|
|
260
|
+
// PUT_NETWORK_COMPONENT -> PUT_COMPONENT
|
|
261
|
+
let transformData = 'data' in message ? message.data : new Uint8Array();
|
|
262
|
+
if (transformNeedsFix) {
|
|
263
|
+
const parent = findNetworkId(NetworkParent.get(entityId));
|
|
264
|
+
transformData = networkUtils.fixTransformParent(message, Transform.get(entityId), parent.entityId);
|
|
265
|
+
}
|
|
266
|
+
networkUtils.networkMessageToLocal({ ...message, data: transformData }, entityId, buffer, transportBuffer);
|
|
267
|
+
// Iterate the next message
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
// If its a network transport and its a PUT_COMPONENT that has a NetworkEntity component, we need to send this message
|
|
271
|
+
// through comms with the EntityID and NetworkID from ther NetworkEntity so everyone can recieve this message and map to their custom entityID.
|
|
272
|
+
if (isNetworkTransport && !networkUtils.isNetworkMessage(message)) {
|
|
273
|
+
const networkData = NetworkEntity.getOrNull(message.entityId);
|
|
274
|
+
// If it has networkData convert the message to PUT_NETWORK_COMPONENT.
|
|
275
|
+
if (networkData) {
|
|
276
|
+
networkUtils.localMessageToNetwork(message, networkData, buffer, transportBuffer);
|
|
277
|
+
// Iterate the next message
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
// Common message
|
|
282
|
+
transportBuffer.writeBuffer(message.messageBuffer, false);
|
|
283
|
+
}
|
|
284
|
+
if (isNetworkTransport && transportBuffer.currentWriteOffset()) {
|
|
285
|
+
__NetworkMessagesBuffer.push(transportBuffer.toBinary());
|
|
220
286
|
}
|
|
221
|
-
|
|
287
|
+
const message = isNetworkTransport ? __NetworkMessagesBuffer : transportBuffer.toBinary();
|
|
288
|
+
await transport.send(message);
|
|
222
289
|
}
|
|
223
290
|
}
|
|
224
291
|
/**
|
|
@@ -29,14 +29,4 @@ export type Transport = {
|
|
|
29
29
|
onmessage?(message: Uint8Array): void;
|
|
30
30
|
filter(message: Omit<TransportMessage, 'messageBuffer'>): boolean;
|
|
31
31
|
type?: string;
|
|
32
|
-
/**
|
|
33
|
-
* Whether this transport is allowed to mutate reserved-range entities
|
|
34
|
-
* (root/player/camera + avatars, entity number below `RESERVED_STATIC_ENTITIES`).
|
|
35
|
-
* Only the trusted host/renderer transport sets this. An inbound DELETE_ENTITY
|
|
36
|
-
* or component operation (PUT_COMPONENT, DELETE_COMPONENT, APPEND_VALUE,
|
|
37
|
-
* AUTHORITATIVE_PUT_COMPONENT) on a reserved entity from a transport without
|
|
38
|
-
* this flag (a comms peer, or any scene-added transport) is rejected — see
|
|
39
|
-
* `receiveMessages`.
|
|
40
|
-
*/
|
|
41
|
-
allowReservedEntities?: boolean;
|
|
42
32
|
};
|
|
@@ -23,7 +23,6 @@ import { TriggerAreaComponentDefinitionExtended } from './extended/TriggerArea';
|
|
|
23
23
|
import { ParticleSystemComponentDefinitionExtended } from './extended/ParticleSystem';
|
|
24
24
|
import { TouchScreenControlsComponentDefinitionExtended } from './extended/TouchScreenControls';
|
|
25
25
|
import { TagsComponentDefinitionExtended } from './manual/Tags';
|
|
26
|
-
import { ICreatedByType } from './manual/CreatedBy';
|
|
27
26
|
export * from './generated/index.gen';
|
|
28
27
|
export type { GrowOnlyValueSetComponentDefinition, LastWriteWinElementSetComponentDefinition, LwwComponentGetter, GSetComponentGetter };
|
|
29
28
|
export declare const Transform: LwwComponentGetter<TransformComponentExtended>;
|
|
@@ -58,9 +57,5 @@ export declare const NetworkEntity: (engine: Pick<IEngine, 'defineComponent'>) =
|
|
|
58
57
|
* @alpha
|
|
59
58
|
*/
|
|
60
59
|
export declare const NetworkParent: (engine: Pick<IEngine, 'defineComponent'>) => LastWriteWinElementSetComponentDefinition<INetowrkParentType>;
|
|
61
|
-
/**
|
|
62
|
-
* @public
|
|
63
|
-
*/
|
|
64
|
-
export declare const CreatedBy: (engine: Pick<IEngine, 'defineComponent'>) => LastWriteWinElementSetComponentDefinition<ICreatedByType>;
|
|
65
60
|
export { MediaState };
|
|
66
61
|
export type { AudioAnalysisView };
|
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.MediaState = exports.
|
|
20
|
+
exports.MediaState = exports.NetworkParent = exports.NetworkEntity = exports.SyncComponents = exports.Tags = exports.Name = exports.TouchScreenControls = exports.ParticleSystem = exports.TriggerArea = exports.LightSource = exports.InputModifier = exports.VirtualCamera = exports.Tween = exports.MeshCollider = exports.MeshRenderer = exports.AudioStream = exports.AudioAnalysis = exports.AudioSource = exports.Animator = exports.Material = exports.Transform = void 0;
|
|
21
21
|
const Animator_1 = require("./extended/Animator");
|
|
22
22
|
const AudioSource_1 = require("./extended/AudioSource");
|
|
23
23
|
const AudioAnalysis_1 = require("./extended/AudioAnalysis");
|
|
@@ -40,7 +40,6 @@ const TriggerArea_1 = require("./extended/TriggerArea");
|
|
|
40
40
|
const ParticleSystem_1 = require("./extended/ParticleSystem");
|
|
41
41
|
const TouchScreenControls_1 = require("./extended/TouchScreenControls");
|
|
42
42
|
const Tags_1 = __importDefault(require("./manual/Tags"));
|
|
43
|
-
const CreatedBy_1 = __importDefault(require("./manual/CreatedBy"));
|
|
44
43
|
__exportStar(require("./generated/index.gen"), exports);
|
|
45
44
|
/* @__PURE__ */
|
|
46
45
|
const Transform = (engine) => (0, Transform_1.defineTransformComponent)(engine);
|
|
@@ -105,15 +104,12 @@ exports.SyncComponents = SyncComponents;
|
|
|
105
104
|
/**
|
|
106
105
|
* @alpha
|
|
107
106
|
*/
|
|
107
|
+
/* @__PURE__ */
|
|
108
108
|
const NetworkEntity = (engine) => (0, NetworkEntity_1.default)(engine);
|
|
109
109
|
exports.NetworkEntity = NetworkEntity;
|
|
110
110
|
/**
|
|
111
111
|
* @alpha
|
|
112
112
|
*/
|
|
113
|
+
/* @__PURE__ */
|
|
113
114
|
const NetworkParent = (engine) => (0, NetworkParent_1.default)(engine);
|
|
114
115
|
exports.NetworkParent = NetworkParent;
|
|
115
|
-
/**
|
|
116
|
-
* @public
|
|
117
|
-
*/
|
|
118
|
-
const CreatedBy = (engine) => (0, CreatedBy_1.default)(engine);
|
|
119
|
-
exports.CreatedBy = CreatedBy;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { LastWriteWinElementSetComponentDefinition, IEngine } from '../../engine';
|
|
2
2
|
import { Entity } from '../../engine/entity';
|
|
3
|
-
import type { ISchema } from '../../schemas/ISchema';
|
|
4
3
|
import type { Vector3Type } from '../../schemas/custom/Vector3';
|
|
5
4
|
/**
|
|
6
5
|
* @public
|
|
@@ -25,10 +24,6 @@ export interface TransformComponentExtended extends TransformComponent {
|
|
|
25
24
|
*/
|
|
26
25
|
localToWorldDirection(entity: Entity, localDirection: Vector3Type): Vector3Type;
|
|
27
26
|
}
|
|
28
|
-
/**
|
|
29
|
-
* @public
|
|
30
|
-
*/
|
|
31
|
-
export declare const COMPONENT_ID = 1;
|
|
32
27
|
/**
|
|
33
28
|
* @public
|
|
34
29
|
*/
|
|
@@ -51,10 +46,6 @@ export type TransformType = {
|
|
|
51
46
|
};
|
|
52
47
|
parent?: Entity;
|
|
53
48
|
};
|
|
54
|
-
/** @public */
|
|
55
|
-
export declare const TRANSFORM_LENGTH = 44;
|
|
56
|
-
/** @public */
|
|
57
|
-
export declare const TransformSchema: ISchema<TransformType>;
|
|
58
49
|
/**
|
|
59
50
|
* @public
|
|
60
51
|
*/
|
|
@@ -29,12 +29,12 @@ exports.defineTransformComponent = exports.TransformSchema = exports.TRANSFORM_L
|
|
|
29
29
|
// getters via __importStar in CJS), so by the time methods are called all exports are available.
|
|
30
30
|
const treeHelpers = __importStar(require("../../runtime/helpers/tree"));
|
|
31
31
|
/**
|
|
32
|
-
* @
|
|
32
|
+
* @internal
|
|
33
33
|
*/
|
|
34
34
|
exports.COMPONENT_ID = 1;
|
|
35
|
-
/** @
|
|
35
|
+
/** @internal */
|
|
36
36
|
exports.TRANSFORM_LENGTH = 44;
|
|
37
|
-
/** @
|
|
37
|
+
/** @internal */
|
|
38
38
|
exports.TransformSchema = {
|
|
39
39
|
serialize(value, builder) {
|
|
40
40
|
const ptr = builder.incrementWriteOffset(exports.TRANSFORM_LENGTH);
|
|
@@ -13,7 +13,6 @@ export type { TagsComponentDefinitionExtended, TagsType } from './manual/Tags';
|
|
|
13
13
|
export type { ISyncComponents, ISyncComponentsType } from './manual/SyncComponents';
|
|
14
14
|
export type { INetowrkEntity, INetowrkEntityType } from './manual/NetworkEntity';
|
|
15
15
|
export type { INetowrkParent, INetowrkParentType } from './manual/NetworkParent';
|
|
16
|
-
export type { ICreatedBy, ICreatedByType } from './manual/CreatedBy';
|
|
17
16
|
export type { InputModifierHelper, InputModifierComponentDefinitionExtended } from './extended/InputModifier';
|
|
18
17
|
export type { LightSourceHelper, LightSourceComponentDefinitionExtended } from './extended/LightSource';
|
|
19
18
|
export type { TriggerAreaComponentDefinitionExtended } from './extended/TriggerArea';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ISchema } from '../schemas';
|
|
2
2
|
import { ByteBuffer } from '../serialization/ByteBuffer';
|
|
3
|
-
import { CrdtMessageBody, DeleteComponentMessageBody,
|
|
3
|
+
import { CrdtMessageBody, DeleteComponentMessageBody, PutComponentMessageBody } from '../serialization/crdt';
|
|
4
4
|
import { Entity } from './entity';
|
|
5
5
|
import { DeepReadonly, DeepReadonlySet } from './readonly';
|
|
6
6
|
/**
|
|
@@ -70,58 +70,7 @@ export interface BaseComponent<T> {
|
|
|
70
70
|
* If the value is undefined, the component was deleted.
|
|
71
71
|
*/
|
|
72
72
|
onChange(entity: Entity, cb: (value: T | undefined) => void): void;
|
|
73
|
-
/**
|
|
74
|
-
* @public
|
|
75
|
-
*
|
|
76
|
-
*/
|
|
77
|
-
validateBeforeChange(entity: Entity, cb: ValidateCallback<T>): void;
|
|
78
|
-
validateBeforeChange(cb: ValidateCallback<T>): void;
|
|
79
|
-
/**
|
|
80
|
-
* Get the CRDT state for an entity (serialized data and timestamp)
|
|
81
|
-
* @param entity - Entity to get the CRDT state for
|
|
82
|
-
* @returns Object with serialized data and timestamp, or null if entity doesn't have the component
|
|
83
|
-
* @public
|
|
84
|
-
*/
|
|
85
|
-
getCrdtState(entity: Entity): {
|
|
86
|
-
data: Uint8Array;
|
|
87
|
-
timestamp: number;
|
|
88
|
-
} | null;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Internal component interface that exposes all internal methods for SDK use
|
|
92
|
-
* This is not exposed to users, only for internal SDK operations
|
|
93
|
-
*/
|
|
94
|
-
export interface InternalBaseComponent<T> extends BaseComponent<T> {
|
|
95
|
-
/**
|
|
96
|
-
* @public
|
|
97
|
-
* Dry run update to check if a CRDT message would be accepted without actually applying it
|
|
98
|
-
*/
|
|
99
|
-
__dry_run_updateFromCrdt(body: CrdtMessageBody): ProcessMessageResultType;
|
|
100
|
-
/**
|
|
101
|
-
* @public
|
|
102
|
-
* Get the iterator to every entity has the component
|
|
103
|
-
*/
|
|
104
|
-
iterator(): Iterable<[Entity, any]>;
|
|
105
|
-
/**
|
|
106
|
-
* @public
|
|
107
|
-
*/
|
|
108
|
-
dirtyIterator(): Iterable<Entity>;
|
|
109
|
-
/**
|
|
110
|
-
* @public
|
|
111
|
-
*/
|
|
112
|
-
__onChangeCallbacks(entity: Entity, value: T): void;
|
|
113
|
-
/**
|
|
114
|
-
* @public
|
|
115
|
-
*/
|
|
116
|
-
__run_validateBeforeChange(entity: Entity, newValue: T | undefined, senderAddress: string, createdBy: string): boolean;
|
|
117
73
|
}
|
|
118
|
-
export type ValidateCallback<T> = (value: {
|
|
119
|
-
entity: Entity;
|
|
120
|
-
currentValue: T | undefined;
|
|
121
|
-
newValue: T | undefined;
|
|
122
|
-
senderAddress: string;
|
|
123
|
-
createdBy: string;
|
|
124
|
-
}) => boolean;
|
|
125
74
|
/**
|
|
126
75
|
* @public
|
|
127
76
|
*/
|
|
@@ -5,7 +5,6 @@ const ByteBuffer_1 = require("../serialization/ByteBuffer");
|
|
|
5
5
|
const crdt_1 = require("../serialization/crdt");
|
|
6
6
|
const invariant_1 = require("../runtime/invariant");
|
|
7
7
|
const emptyReadonlySet = freezeSet(new Set());
|
|
8
|
-
const __GLOBAL_ENTITY = '__GLOBAL_ENTITY';
|
|
9
8
|
function frozenError() {
|
|
10
9
|
throw new Error('The set is frozen');
|
|
11
10
|
}
|
|
@@ -26,7 +25,6 @@ function createValueSetComponentDefinitionFromSchema(componentName, componentId,
|
|
|
26
25
|
const dirtyIterator = new Set();
|
|
27
26
|
const queuedCommands = [];
|
|
28
27
|
const onChangeCallbacks = new Map();
|
|
29
|
-
const validateCallbacks = new Map();
|
|
30
28
|
// only sort the array if the latest (N) element has a timestamp <= N-1
|
|
31
29
|
function shouldSort(row) {
|
|
32
30
|
const len = row.raw.length;
|
|
@@ -85,11 +83,8 @@ function createValueSetComponentDefinitionFromSchema(componentName, componentId,
|
|
|
85
83
|
has(entity) {
|
|
86
84
|
return data.has(entity);
|
|
87
85
|
},
|
|
88
|
-
entityDeleted(entity
|
|
86
|
+
entityDeleted(entity) {
|
|
89
87
|
data.delete(entity);
|
|
90
|
-
if (markAsDirty) {
|
|
91
|
-
// For grow-only sets, we don't need to mark as dirty since deletion doesn't generate CRDT messages
|
|
92
|
-
}
|
|
93
88
|
},
|
|
94
89
|
get(entity) {
|
|
95
90
|
const values = data.get(entity);
|
|
@@ -160,44 +155,6 @@ function createValueSetComponentDefinitionFromSchema(componentName, componentId,
|
|
|
160
155
|
for (const cb of cbs) {
|
|
161
156
|
cb(value);
|
|
162
157
|
}
|
|
163
|
-
},
|
|
164
|
-
__dry_run_updateFromCrdt(_body) {
|
|
165
|
-
return crdt_1.ProcessMessageResultType.StateUpdatedData;
|
|
166
|
-
},
|
|
167
|
-
validateBeforeChange(entityOrCb, cb) {
|
|
168
|
-
if (arguments.length === 1) {
|
|
169
|
-
// Second overload: just callback (global validation)
|
|
170
|
-
validateCallbacks.set(__GLOBAL_ENTITY, entityOrCb);
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
if (cb) {
|
|
174
|
-
validateCallbacks.set(entityOrCb, cb);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
__run_validateBeforeChange(entity, newValue, senderAddress, createdBy) {
|
|
179
|
-
const cb = entity && validateCallbacks.get(entity);
|
|
180
|
-
const globalCb = validateCallbacks.get(__GLOBAL_ENTITY);
|
|
181
|
-
const currentValue = [...this.get(entity).values()];
|
|
182
|
-
const value = { entity, currentValue: currentValue, newValue, senderAddress, createdBy };
|
|
183
|
-
const globalResult = globalCb?.(value) ?? true;
|
|
184
|
-
const entityResult = (globalResult && cb?.(value)) ?? true;
|
|
185
|
-
return globalResult && entityResult;
|
|
186
|
-
},
|
|
187
|
-
getCrdtState(entity) {
|
|
188
|
-
const row = data.get(entity);
|
|
189
|
-
if (!row || row.raw.length === 0) {
|
|
190
|
-
return null;
|
|
191
|
-
}
|
|
192
|
-
// For GrowOnlySet, we need to return the complete CRDT messages for all values
|
|
193
|
-
// This is complex because GrowOnlySet uses APPEND messages, not a single PUT
|
|
194
|
-
// For now, return null to indicate this component type doesn't support simple corrections
|
|
195
|
-
return null;
|
|
196
|
-
},
|
|
197
|
-
__forceUpdateFromCrdt(_msg) {
|
|
198
|
-
// GrowOnlySet doesn't support authoritative corrections in the same way as LWW
|
|
199
|
-
// since it uses APPEND_VALUE messages instead of PUT_COMPONENT messages
|
|
200
|
-
return [null, undefined];
|
|
201
158
|
}
|
|
202
159
|
};
|
|
203
160
|
return ret;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { ISchema } from '../schemas';
|
|
2
2
|
import { ByteBuffer } from '../serialization/ByteBuffer';
|
|
3
|
-
import { PutComponentMessageBody, DeleteComponentMessageBody,
|
|
3
|
+
import { PutComponentMessageBody, DeleteComponentMessageBody, CrdtMessageBody } from '../serialization/crdt';
|
|
4
4
|
import { Entity } from './entity';
|
|
5
5
|
export declare function incrementTimestamp(entity: Entity, timestamps: Map<Entity, number>): number;
|
|
6
6
|
export declare function createDumpLwwFunctionFromCrdt(componentId: number, timestamps: Map<Entity, number>, schema: Pick<ISchema<any>, 'serialize' | 'deserialize'>, data: Map<Entity, unknown>): (buffer: ByteBuffer, filterEntity?: ((entity: Entity) => boolean) | undefined) => void;
|
|
7
|
-
export declare function createCrdtRuleValidator(timestamps: Map<Entity, number>, schema: Pick<ISchema<any>, 'serialize' | 'deserialize'>, data: Map<Entity, unknown>, lastSentData: Map<Entity, Uint8Array>): (message: PutComponentMessageBody | DeleteComponentMessageBody | PutNetworkComponentMessageBody | DeleteComponentNetworkMessageBody) => ProcessMessageResultType;
|
|
8
|
-
export declare function createForceUpdateLwwFromCrdt(componentId: number, timestamps: Map<Entity, number>, schema: Pick<ISchema<any>, 'serialize' | 'deserialize'>, data: Map<Entity, unknown>): (msg: AuthoritativePutComponentMessageBody) => [null, any];
|
|
9
7
|
export declare function createUpdateLwwFromCrdt(componentId: number, timestamps: Map<Entity, number>, schema: Pick<ISchema<any>, 'serialize' | 'deserialize'>, data: Map<Entity, unknown>, lastSentData: Map<Entity, Uint8Array>): (msg: CrdtMessageBody) => [null | PutComponentMessageBody | DeleteComponentMessageBody, any];
|
|
10
8
|
export declare function createGetCrdtMessagesForLww(componentId: number, timestamps: Map<Entity, number>, dirtyIterator: Set<Entity>, schema: Pick<ISchema<any>, 'serialize'>, data: Map<Entity, unknown>, lastSentData: Map<Entity, Uint8Array>): () => Generator<PutComponentMessageBody | DeleteComponentMessageBody, void, unknown>;
|