@dcl/ecs 7.29.0 → 7.29.1-34986384248.commit-bb45080
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 +5 -0
- package/dist/components/index.js +5 -2
- package/dist/components/manual/CreatedBy.d.ts +9 -0
- package/dist/components/manual/CreatedBy.js +8 -0
- package/dist/components/manual/Transform.d.ts +9 -0
- package/dist/components/manual/Transform.js +3 -3
- package/dist/components/types.d.ts +1 -0
- package/dist/engine/component.d.ts +52 -1
- package/dist/engine/grow-only-value-set-component-definition.js +45 -2
- package/dist/engine/lww-element-set-component-definition.d.ts +3 -1
- package/dist/engine/lww-element-set-component-definition.js +68 -13
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/serialization/crdt/authoritativePutComponent.d.ts +15 -0
- package/dist/serialization/crdt/authoritativePutComponent.js +47 -0
- package/dist/serialization/crdt/index.d.ts +1 -0
- package/dist/serialization/crdt/index.js +1 -0
- package/dist/serialization/crdt/types.d.ts +25 -3
- package/dist/serialization/crdt/types.js +3 -1
- package/dist/systems/crdt/index.d.ts +0 -1
- package/dist/systems/crdt/index.js +76 -143
- package/dist/systems/crdt/types.d.ts +10 -0
- package/dist-cjs/components/index.d.ts +5 -0
- package/dist-cjs/components/index.js +7 -3
- package/dist-cjs/components/manual/CreatedBy.d.ts +9 -0
- package/dist-cjs/components/manual/CreatedBy.js +10 -0
- package/dist-cjs/components/manual/Transform.d.ts +9 -0
- package/dist-cjs/components/manual/Transform.js +3 -3
- package/dist-cjs/components/types.d.ts +1 -0
- package/dist-cjs/engine/component.d.ts +52 -1
- package/dist-cjs/engine/grow-only-value-set-component-definition.js +44 -1
- package/dist-cjs/engine/lww-element-set-component-definition.d.ts +3 -1
- package/dist-cjs/engine/lww-element-set-component-definition.js +71 -14
- package/dist-cjs/index.d.ts +2 -1
- package/dist-cjs/index.js +2 -1
- package/dist-cjs/serialization/crdt/authoritativePutComponent.d.ts +15 -0
- package/dist-cjs/serialization/crdt/authoritativePutComponent.js +50 -0
- package/dist-cjs/serialization/crdt/index.d.ts +1 -0
- package/dist-cjs/serialization/crdt/index.js +1 -0
- package/dist-cjs/serialization/crdt/types.d.ts +25 -3
- package/dist-cjs/serialization/crdt/types.js +3 -1
- package/dist-cjs/systems/crdt/index.d.ts +0 -1
- package/dist-cjs/systems/crdt/index.js +76 -166
- package/dist-cjs/systems/crdt/types.d.ts +10 -0
- package/package.json +2 -2
- package/dist/serialization/crdt/network/utils.d.ts +0 -9
- package/dist/serialization/crdt/network/utils.js +0 -60
- package/dist-cjs/serialization/crdt/network/utils.d.ts +0 -9
- package/dist-cjs/serialization/crdt/network/utils.js +0 -67
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
import { EntityState } from '../../engine/entity';
|
|
2
2
|
import { ReadWriteByteBuffer } from '../../serialization/ByteBuffer';
|
|
3
|
-
import { AppendValueOperation, CrdtMessageProtocol
|
|
3
|
+
import { AppendValueOperation, CrdtMessageProtocol } 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';
|
|
7
8
|
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;
|
|
13
9
|
/**
|
|
14
10
|
* @internal
|
|
15
11
|
*/
|
|
16
12
|
export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
17
13
|
const transports = [];
|
|
18
|
-
//
|
|
19
|
-
const NetworkEntity = defineNetworkEntity(engine);
|
|
20
|
-
const NetworkParent = defineNetworkParent(engine);
|
|
21
|
-
const Transform = defineTransform(engine);
|
|
14
|
+
// No network components needed - pure CRDT processing only
|
|
22
15
|
// Messages that we received at transport.onMessage waiting to be processed
|
|
23
16
|
const receivedMessages = [];
|
|
24
17
|
// Messages already processed by the engine but that we need to broadcast to other transports.
|
|
@@ -43,27 +36,20 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
43
36
|
if (header.type === CrdtMessageType.DELETE_COMPONENT) {
|
|
44
37
|
message = DeleteComponent.read(buffer);
|
|
45
38
|
}
|
|
46
|
-
else if (header.type === CrdtMessageType.DELETE_COMPONENT_NETWORK) {
|
|
47
|
-
message = DeleteComponentNetwork.read(buffer);
|
|
48
|
-
}
|
|
49
39
|
else if (header.type === CrdtMessageType.PUT_COMPONENT) {
|
|
50
40
|
message = PutComponentOperation.read(buffer);
|
|
51
41
|
}
|
|
52
|
-
else if (header.type === CrdtMessageType.
|
|
53
|
-
message =
|
|
42
|
+
else if (header.type === CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT) {
|
|
43
|
+
message = AuthoritativePutComponentOperation.read(buffer);
|
|
54
44
|
}
|
|
55
45
|
else if (header.type === CrdtMessageType.DELETE_ENTITY) {
|
|
56
46
|
message = DeleteEntity.read(buffer);
|
|
57
47
|
}
|
|
58
|
-
else if (header.type === CrdtMessageType.DELETE_ENTITY_NETWORK) {
|
|
59
|
-
message = DeleteEntityNetwork.read(buffer);
|
|
60
|
-
}
|
|
61
48
|
else if (header.type === CrdtMessageType.APPEND_VALUE) {
|
|
62
49
|
message = AppendValueOperation.read(buffer);
|
|
63
|
-
// Unknown message, we skip it
|
|
64
50
|
}
|
|
65
51
|
else {
|
|
66
|
-
//
|
|
52
|
+
// Unknown message, we skip it (including NETWORK messages)
|
|
67
53
|
buffer.incrementReadOffset(header.length);
|
|
68
54
|
}
|
|
69
55
|
if (message) {
|
|
@@ -85,20 +71,12 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
85
71
|
return messagesToProcess;
|
|
86
72
|
}
|
|
87
73
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
74
|
+
* Reserved-range entities (root/player/camera + avatars, entity number <
|
|
75
|
+
* RESERVED_STATIC_ENTITIES) are host-owned: only a transport flagged with
|
|
76
|
+
* `allowReservedEntities` (the host/renderer) may mutate or delete them.
|
|
91
77
|
*/
|
|
92
|
-
function
|
|
93
|
-
|
|
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 };
|
|
78
|
+
function isTrustedForReservedEntities(transportId) {
|
|
79
|
+
return transportId !== undefined && !!transports[transportId]?.allowReservedEntities;
|
|
102
80
|
}
|
|
103
81
|
/**
|
|
104
82
|
* This fn will be called on every tick.
|
|
@@ -108,46 +86,68 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
108
86
|
const messagesToProcess = getMessages(receivedMessages);
|
|
109
87
|
const entitiesShouldBeCleaned = [];
|
|
110
88
|
for (const msg of messagesToProcess) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
89
|
+
// Simple CRDT processing - no network logic
|
|
90
|
+
if (msg.type === CrdtMessageType.DELETE_ENTITY) {
|
|
91
|
+
// Reject an inbound DELETE_ENTITY on a reserved entity from an untrusted
|
|
92
|
+
// transport (a comms peer, or a scene-added transport). The allocator half
|
|
93
|
+
// is already guarded (engine.removeEntity is a no-op on this range); this
|
|
94
|
+
// closes the receive-side half.
|
|
95
|
+
const isReserved = engine.entityContainer.getEntityState(msg.entityId) === EntityState.Reserved;
|
|
96
|
+
if (isReserved && !isTrustedForReservedEntities(msg.transportId)) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
entitiesShouldBeCleaned.push(msg.entityId);
|
|
120
100
|
broadcastMessages.push(msg);
|
|
121
101
|
}
|
|
122
102
|
else {
|
|
123
|
-
const entityState = engine.entityContainer.getEntityState(entityId);
|
|
124
|
-
// Skip updates from removed
|
|
103
|
+
const entityState = engine.entityContainer.getEntityState(msg.entityId);
|
|
104
|
+
// Skip updates from removed entities
|
|
125
105
|
if (entityState === EntityState.Removed)
|
|
126
106
|
continue;
|
|
127
|
-
//
|
|
107
|
+
// Reject component operations (PUT/DELETE/APPEND, including AUTHORITATIVE_PUT
|
|
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
|
|
128
116
|
if (entityState === EntityState.Unknown) {
|
|
129
|
-
engine.entityContainer.updateUsedEntity(entityId);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
117
|
+
engine.entityContainer.updateUsedEntity(msg.entityId);
|
|
118
|
+
}
|
|
119
|
+
// Only process component-related messages (not DELETE_ENTITY)
|
|
120
|
+
if ('componentId' in msg) {
|
|
121
|
+
const component = engine.getComponentOrNull(msg.componentId);
|
|
122
|
+
if (component) {
|
|
123
|
+
// Handle authoritative messages differently - they force the state regardless of timestamp
|
|
124
|
+
const tryUpdate = () => {
|
|
125
|
+
try {
|
|
126
|
+
return msg.type === CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT
|
|
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
|
+
}
|
|
139
144
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
145
|
+
else {
|
|
146
|
+
// Component not found - still broadcast for editor compatibility
|
|
147
|
+
/* istanbul ignore next */
|
|
143
148
|
broadcastMessages.push(msg);
|
|
144
|
-
onProcessEntityComponentChange && onProcessEntityComponentChange(entityId, msg.type, component, value);
|
|
145
149
|
}
|
|
146
150
|
}
|
|
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,16 +161,17 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
|
-
*
|
|
164
|
+
* Simple CRDT message broadcasting - no network-specific logic
|
|
165
165
|
*/
|
|
166
166
|
async function sendMessages(entitiesDeletedThisTick) {
|
|
167
|
-
//
|
|
167
|
+
// Get messages from broadcast queue and component updates
|
|
168
168
|
const crdtMessages = getMessages(broadcastMessages);
|
|
169
169
|
const buffer = new ReadWriteByteBuffer();
|
|
170
|
+
// Generate CRDT messages from component updates
|
|
170
171
|
for (const component of engine.componentsIter()) {
|
|
171
172
|
for (const message of component.getCrdtUpdates()) {
|
|
172
173
|
const offset = buffer.currentWriteOffset();
|
|
173
|
-
//
|
|
174
|
+
// Only create messages if there's a transport that will handle it
|
|
174
175
|
if (transports.some((t) => t.filter(message))) {
|
|
175
176
|
if (message.type === CrdtMessageType.PUT_COMPONENT) {
|
|
176
177
|
PutComponentOperation.write(message.entityId, message.timestamp, message.componentId, message.data, buffer);
|
|
@@ -194,7 +195,7 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
194
195
|
}
|
|
195
196
|
}
|
|
196
197
|
}
|
|
197
|
-
//
|
|
198
|
+
// Handle deleted entities
|
|
198
199
|
for (const entityId of entitiesDeletedThisTick) {
|
|
199
200
|
const offset = buffer.currentWriteOffset();
|
|
200
201
|
DeleteEntity.write(entityId, buffer);
|
|
@@ -205,87 +206,19 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
205
206
|
});
|
|
206
207
|
onProcessEntityComponentChange && onProcessEntityComponentChange(entityId, CrdtMessageType.DELETE_ENTITY);
|
|
207
208
|
}
|
|
208
|
-
//
|
|
209
|
-
const
|
|
210
|
-
|
|
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
|
|
209
|
+
// Simple transport broadcasting - no network-specific transforms
|
|
210
|
+
for (const transport of transports) {
|
|
211
|
+
const transportBuffer = new ReadWriteByteBuffer();
|
|
220
212
|
for (const message of crdtMessages) {
|
|
221
213
|
// Avoid echo messages
|
|
222
|
-
if (message.transportId ===
|
|
214
|
+
if (message.transportId === transports.indexOf(transport))
|
|
223
215
|
continue;
|
|
224
|
-
//
|
|
225
|
-
if (
|
|
226
|
-
|
|
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
|
-
}
|
|
216
|
+
// Check if transport wants this message
|
|
217
|
+
if (transport.filter(message)) {
|
|
218
|
+
transportBuffer.writeBuffer(message.messageBuffer, false);
|
|
242
219
|
}
|
|
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());
|
|
286
220
|
}
|
|
287
|
-
|
|
288
|
-
await transport.send(message);
|
|
221
|
+
await transport.send(transportBuffer.toBinary());
|
|
289
222
|
}
|
|
290
223
|
}
|
|
291
224
|
/**
|
|
@@ -29,4 +29,14 @@ 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;
|
|
32
42
|
};
|
|
@@ -23,6 +23,7 @@ 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';
|
|
26
27
|
export * from './generated/index.gen';
|
|
27
28
|
export type { GrowOnlyValueSetComponentDefinition, LastWriteWinElementSetComponentDefinition, LwwComponentGetter, GSetComponentGetter };
|
|
28
29
|
export declare const Transform: LwwComponentGetter<TransformComponentExtended>;
|
|
@@ -57,5 +58,9 @@ export declare const NetworkEntity: (engine: Pick<IEngine, 'defineComponent'>) =
|
|
|
57
58
|
* @alpha
|
|
58
59
|
*/
|
|
59
60
|
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>;
|
|
60
65
|
export { MediaState };
|
|
61
66
|
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.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;
|
|
20
|
+
exports.MediaState = exports.CreatedBy = 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,6 +40,7 @@ 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"));
|
|
43
44
|
__exportStar(require("./generated/index.gen"), exports);
|
|
44
45
|
/* @__PURE__ */
|
|
45
46
|
const Transform = (engine) => (0, Transform_1.defineTransformComponent)(engine);
|
|
@@ -104,12 +105,15 @@ exports.SyncComponents = SyncComponents;
|
|
|
104
105
|
/**
|
|
105
106
|
* @alpha
|
|
106
107
|
*/
|
|
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__ */
|
|
114
113
|
const NetworkParent = (engine) => (0, NetworkParent_1.default)(engine);
|
|
115
114
|
exports.NetworkParent = NetworkParent;
|
|
115
|
+
/**
|
|
116
|
+
* @public
|
|
117
|
+
*/
|
|
118
|
+
const CreatedBy = (engine) => (0, CreatedBy_1.default)(engine);
|
|
119
|
+
exports.CreatedBy = CreatedBy;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IEngine, LastWriteWinElementSetComponentDefinition } from '../../engine/types';
|
|
2
|
+
export interface ICreatedByType {
|
|
3
|
+
address: string;
|
|
4
|
+
}
|
|
5
|
+
export type ICreatedBy = LastWriteWinElementSetComponentDefinition<ICreatedByType>;
|
|
6
|
+
declare function defineCreatedBy(engine: Pick<IEngine, 'defineComponent'>): import("../../engine/types").MapComponentDefinition<import("../..").MapResult<{
|
|
7
|
+
address: import("../../schemas").ISchema<string>;
|
|
8
|
+
}>>;
|
|
9
|
+
export default defineCreatedBy;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schemas_1 = require("../../schemas");
|
|
4
|
+
function defineCreatedBy(engine) {
|
|
5
|
+
const CreatedBy = engine.defineComponent('core-schema::Created-By', {
|
|
6
|
+
address: schemas_1.Schemas.String
|
|
7
|
+
});
|
|
8
|
+
return CreatedBy;
|
|
9
|
+
}
|
|
10
|
+
exports.default = defineCreatedBy;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { LastWriteWinElementSetComponentDefinition, IEngine } from '../../engine';
|
|
2
2
|
import { Entity } from '../../engine/entity';
|
|
3
|
+
import type { ISchema } from '../../schemas/ISchema';
|
|
3
4
|
import type { Vector3Type } from '../../schemas/custom/Vector3';
|
|
4
5
|
/**
|
|
5
6
|
* @public
|
|
@@ -24,6 +25,10 @@ export interface TransformComponentExtended extends TransformComponent {
|
|
|
24
25
|
*/
|
|
25
26
|
localToWorldDirection(entity: Entity, localDirection: Vector3Type): Vector3Type;
|
|
26
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export declare const COMPONENT_ID = 1;
|
|
27
32
|
/**
|
|
28
33
|
* @public
|
|
29
34
|
*/
|
|
@@ -46,6 +51,10 @@ export type TransformType = {
|
|
|
46
51
|
};
|
|
47
52
|
parent?: Entity;
|
|
48
53
|
};
|
|
54
|
+
/** @public */
|
|
55
|
+
export declare const TRANSFORM_LENGTH = 44;
|
|
56
|
+
/** @public */
|
|
57
|
+
export declare const TransformSchema: ISchema<TransformType>;
|
|
49
58
|
/**
|
|
50
59
|
* @public
|
|
51
60
|
*/
|
|
@@ -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
|
+
* @public
|
|
33
33
|
*/
|
|
34
34
|
exports.COMPONENT_ID = 1;
|
|
35
|
-
/** @
|
|
35
|
+
/** @public */
|
|
36
36
|
exports.TRANSFORM_LENGTH = 44;
|
|
37
|
-
/** @
|
|
37
|
+
/** @public */
|
|
38
38
|
exports.TransformSchema = {
|
|
39
39
|
serialize(value, builder) {
|
|
40
40
|
const ptr = builder.incrementWriteOffset(exports.TRANSFORM_LENGTH);
|
|
@@ -13,6 +13,7 @@ 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';
|
|
16
17
|
export type { InputModifierHelper, InputModifierComponentDefinitionExtended } from './extended/InputModifier';
|
|
17
18
|
export type { LightSourceHelper, LightSourceComponentDefinitionExtended } from './extended/LightSource';
|
|
18
19
|
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, PutComponentMessageBody } from '../serialization/crdt';
|
|
3
|
+
import { CrdtMessageBody, DeleteComponentMessageBody, ProcessMessageResultType, PutComponentMessageBody } from '../serialization/crdt';
|
|
4
4
|
import { Entity } from './entity';
|
|
5
5
|
import { DeepReadonly, DeepReadonlySet } from './readonly';
|
|
6
6
|
/**
|
|
@@ -70,7 +70,58 @@ 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;
|
|
73
117
|
}
|
|
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;
|
|
74
125
|
/**
|
|
75
126
|
* @public
|
|
76
127
|
*/
|
|
@@ -5,6 +5,7 @@ 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';
|
|
8
9
|
function frozenError() {
|
|
9
10
|
throw new Error('The set is frozen');
|
|
10
11
|
}
|
|
@@ -25,6 +26,7 @@ function createValueSetComponentDefinitionFromSchema(componentName, componentId,
|
|
|
25
26
|
const dirtyIterator = new Set();
|
|
26
27
|
const queuedCommands = [];
|
|
27
28
|
const onChangeCallbacks = new Map();
|
|
29
|
+
const validateCallbacks = new Map();
|
|
28
30
|
// only sort the array if the latest (N) element has a timestamp <= N-1
|
|
29
31
|
function shouldSort(row) {
|
|
30
32
|
const len = row.raw.length;
|
|
@@ -83,8 +85,11 @@ function createValueSetComponentDefinitionFromSchema(componentName, componentId,
|
|
|
83
85
|
has(entity) {
|
|
84
86
|
return data.has(entity);
|
|
85
87
|
},
|
|
86
|
-
entityDeleted(entity) {
|
|
88
|
+
entityDeleted(entity, markAsDirty) {
|
|
87
89
|
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
|
+
}
|
|
88
93
|
},
|
|
89
94
|
get(entity) {
|
|
90
95
|
const values = data.get(entity);
|
|
@@ -155,6 +160,44 @@ function createValueSetComponentDefinitionFromSchema(componentName, componentId,
|
|
|
155
160
|
for (const cb of cbs) {
|
|
156
161
|
cb(value);
|
|
157
162
|
}
|
|
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];
|
|
158
201
|
}
|
|
159
202
|
};
|
|
160
203
|
return ret;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ISchema } from '../schemas';
|
|
2
2
|
import { ByteBuffer } from '../serialization/ByteBuffer';
|
|
3
|
-
import { PutComponentMessageBody, DeleteComponentMessageBody, CrdtMessageBody } from '../serialization/crdt';
|
|
3
|
+
import { PutComponentMessageBody, DeleteComponentMessageBody, ProcessMessageResultType, CrdtMessageBody, PutNetworkComponentMessageBody, DeleteComponentNetworkMessageBody, AuthoritativePutComponentMessageBody } 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];
|
|
7
9
|
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];
|
|
8
10
|
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>;
|