@dcl/ecs 7.20.2-22169778016.commit-030cbfe → 7.20.2-22231111352.commit-d2f6f0a

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.
Files changed (49) hide show
  1. package/dist/components/index.d.ts +0 -5
  2. package/dist/components/index.js +2 -5
  3. package/dist/components/manual/Transform.d.ts +0 -9
  4. package/dist/components/manual/Transform.js +3 -3
  5. package/dist/components/types.d.ts +0 -1
  6. package/dist/engine/component.d.ts +1 -52
  7. package/dist/engine/grow-only-value-set-component-definition.js +3 -46
  8. package/dist/engine/input.js +3 -2
  9. package/dist/engine/lww-element-set-component-definition.d.ts +1 -3
  10. package/dist/engine/lww-element-set-component-definition.js +12 -65
  11. package/dist/index.d.ts +1 -2
  12. package/dist/index.js +0 -1
  13. package/dist/serialization/crdt/index.d.ts +0 -1
  14. package/dist/serialization/crdt/index.js +0 -1
  15. package/dist/serialization/crdt/network/utils.d.ts +9 -0
  16. package/dist/serialization/crdt/network/utils.js +60 -0
  17. package/dist/serialization/crdt/types.d.ts +3 -25
  18. package/dist/serialization/crdt/types.js +1 -3
  19. package/dist/systems/crdt/index.d.ts +1 -0
  20. package/dist/systems/crdt/index.js +146 -55
  21. package/dist-cjs/components/index.d.ts +0 -5
  22. package/dist-cjs/components/index.js +3 -7
  23. package/dist-cjs/components/manual/Transform.d.ts +0 -9
  24. package/dist-cjs/components/manual/Transform.js +3 -3
  25. package/dist-cjs/components/types.d.ts +0 -1
  26. package/dist-cjs/engine/component.d.ts +1 -52
  27. package/dist-cjs/engine/grow-only-value-set-component-definition.js +2 -45
  28. package/dist-cjs/engine/input.js +3 -2
  29. package/dist-cjs/engine/lww-element-set-component-definition.d.ts +1 -3
  30. package/dist-cjs/engine/lww-element-set-component-definition.js +13 -68
  31. package/dist-cjs/index.d.ts +1 -2
  32. package/dist-cjs/index.js +1 -2
  33. package/dist-cjs/serialization/crdt/index.d.ts +0 -1
  34. package/dist-cjs/serialization/crdt/index.js +0 -1
  35. package/dist-cjs/serialization/crdt/network/utils.d.ts +9 -0
  36. package/dist-cjs/serialization/crdt/network/utils.js +67 -0
  37. package/dist-cjs/serialization/crdt/types.d.ts +3 -25
  38. package/dist-cjs/serialization/crdt/types.js +1 -3
  39. package/dist-cjs/systems/crdt/index.d.ts +1 -0
  40. package/dist-cjs/systems/crdt/index.js +169 -55
  41. package/package.json +2 -2
  42. package/dist/components/manual/CreatedBy.d.ts +0 -9
  43. package/dist/components/manual/CreatedBy.js +0 -8
  44. package/dist/serialization/crdt/authoritativePutComponent.d.ts +0 -15
  45. package/dist/serialization/crdt/authoritativePutComponent.js +0 -47
  46. package/dist-cjs/components/manual/CreatedBy.d.ts +0 -9
  47. package/dist-cjs/components/manual/CreatedBy.js +0 -10
  48. package/dist-cjs/serialization/crdt/authoritativePutComponent.d.ts +0 -15
  49. 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
- // No network components needed - pure CRDT processing only
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.AUTHORITATIVE_PUT_COMPONENT) {
43
- message = AuthoritativePutComponentOperation.read(buffer);
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
- // Unknown message, we skip it (including NETWORK messages)
66
+ // consume the message
53
67
  buffer.incrementReadOffset(header.length);
54
68
  }
55
69
  if (message) {
@@ -70,6 +84,22 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
70
84
  const messagesToProcess = value.splice(0, value.length);
71
85
  return messagesToProcess;
72
86
  }
87
+ /**
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
91
+ */
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 };
102
+ }
73
103
  /**
74
104
  * This fn will be called on every tick.
75
105
  * Process all the messages queue received by the transport
@@ -78,52 +108,46 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
78
108
  const messagesToProcess = getMessages(receivedMessages);
79
109
  const entitiesShouldBeCleaned = [];
80
110
  for (const msg of messagesToProcess) {
81
- // Simple CRDT processing - no network logic
82
- if (msg.type === CrdtMessageType.DELETE_ENTITY) {
83
- 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);
84
120
  broadcastMessages.push(msg);
85
121
  }
86
122
  else {
87
- const entityState = engine.entityContainer.getEntityState(msg.entityId);
88
- // Skip updates from removed entities
123
+ const entityState = engine.entityContainer.getEntityState(entityId);
124
+ // Skip updates from removed entityes
89
125
  if (entityState === EntityState.Removed)
90
126
  continue;
91
- // Entities with unknown state should update its entity state
127
+ // Entities with unknown entities should update its entity state
92
128
  if (entityState === EntityState.Unknown) {
93
- engine.entityContainer.updateUsedEntity(msg.entityId);
94
- }
95
- // Only process component-related messages (not DELETE_ENTITY)
96
- if ('componentId' in msg) {
97
- const component = engine.getComponentOrNull(msg.componentId);
98
- if (component) {
99
- // Handle authoritative messages differently - they force the state regardless of timestamp
100
- const tryUpdate = () => {
101
- try {
102
- return msg.type === CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT
103
- ? component.__forceUpdateFromCrdt(msg)
104
- : component.updateFromCrdt(msg);
105
- }
106
- catch (e) {
107
- console.error('[receiveMessages] ERROR processing message', msg, e);
108
- return null;
109
- }
110
- };
111
- const result = tryUpdate();
112
- if (!result)
113
- continue;
114
- const [conflictMessage, value] = result;
115
- if (!conflictMessage) {
116
- // Add message to broadcast queue when no conflict
117
- broadcastMessages.push(msg);
118
- onProcessEntityComponentChange && onProcessEntityComponentChange(msg.entityId, msg.type, component, value);
119
- }
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);
120
139
  }
121
- else {
122
- // Component not found - still broadcast for editor compatibility
123
- /* istanbul ignore next */
140
+ const [conflictMessage, value] = component.updateFromCrdt({ ...msg, entityId });
141
+ if (!conflictMessage) {
142
+ // Add message to transport queue to be processed by others transports
124
143
  broadcastMessages.push(msg);
144
+ onProcessEntityComponentChange && onProcessEntityComponentChange(entityId, msg.type, component, value);
125
145
  }
126
146
  }
147
+ else {
148
+ // TODO: test this line, it is fundammental to make the editor work
149
+ broadcastMessages.push(msg);
150
+ }
127
151
  }
128
152
  }
129
153
  // the last stage of the syncrhonization is to delete the entities
@@ -137,17 +161,16 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
137
161
  }
138
162
  }
139
163
  /**
140
- * Simple CRDT message broadcasting - no network-specific logic
164
+ * Iterates the dirty map and generates crdt messages to be send
141
165
  */
142
166
  async function sendMessages(entitiesDeletedThisTick) {
143
- // Get messages from broadcast queue and component updates
167
+ // CRDT Messages will be the merge between the recieved transport messages and the new crdt messages
144
168
  const crdtMessages = getMessages(broadcastMessages);
145
169
  const buffer = new ReadWriteByteBuffer();
146
- // Generate CRDT messages from component updates
147
170
  for (const component of engine.componentsIter()) {
148
171
  for (const message of component.getCrdtUpdates()) {
149
172
  const offset = buffer.currentWriteOffset();
150
- // Only create messages if there's a transport that will handle it
173
+ // Avoid creating messages if there is no transport that will handle it
151
174
  if (transports.some((t) => t.filter(message))) {
152
175
  if (message.type === CrdtMessageType.PUT_COMPONENT) {
153
176
  PutComponentOperation.write(message.entityId, message.timestamp, message.componentId, message.data, buffer);
@@ -171,7 +194,7 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
171
194
  }
172
195
  }
173
196
  }
174
- // Handle deleted entities
197
+ // After all updates, I execute the DeletedEntity messages
175
198
  for (const entityId of entitiesDeletedThisTick) {
176
199
  const offset = buffer.currentWriteOffset();
177
200
  DeleteEntity.write(entityId, buffer);
@@ -182,19 +205,87 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
182
205
  });
183
206
  onProcessEntityComponentChange && onProcessEntityComponentChange(entityId, CrdtMessageType.DELETE_ENTITY);
184
207
  }
185
- // Simple transport broadcasting - no network-specific transforms
186
- for (const transport of transports) {
187
- const transportBuffer = new ReadWriteByteBuffer();
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
188
220
  for (const message of crdtMessages) {
221
+ // Check if adding this message would exceed the size limit
222
+ const currentBufferSize = transportBuffer.toBinary().byteLength;
223
+ const messageSize = message.messageBuffer.byteLength;
224
+ if (isNetworkTransport && (currentBufferSize + messageSize) / 1024 > LIVEKIT_MAX_SIZE) {
225
+ // If the current buffer has content, save it as a chunk
226
+ if (currentBufferSize > 0) {
227
+ __NetworkMessagesBuffer.push(transportBuffer.toCopiedBinary());
228
+ transportBuffer.resetBuffer();
229
+ }
230
+ // If the message itself is larger than the limit, we need to handle it specially
231
+ // For now, we'll skip it to prevent infinite loops
232
+ if (messageSize / 1024 > LIVEKIT_MAX_SIZE) {
233
+ console.error(`Message too large (${messageSize} bytes), skipping message for entity ${message.entityId}`);
234
+ continue;
235
+ }
236
+ }
189
237
  // Avoid echo messages
190
- if (message.transportId === transports.indexOf(transport))
238
+ if (message.transportId === transportIndex)
239
+ continue;
240
+ // Redundant message for the transport
241
+ if (!transport.filter(message))
242
+ continue;
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);
191
256
  continue;
192
- // Check if transport wants this message
193
- if (transport.filter(message)) {
194
- transportBuffer.writeBuffer(message.messageBuffer, false);
195
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());
196
286
  }
197
- await transport.send(transportBuffer.toBinary());
287
+ const message = isNetworkTransport ? __NetworkMessagesBuffer : transportBuffer.toBinary();
288
+ await transport.send(message);
198
289
  }
199
290
  }
200
291
  /**
@@ -19,7 +19,6 @@ import { InputModifierComponentDefinitionExtended } from './extended/InputModifi
19
19
  import { LightSourceComponentDefinitionExtended } from './extended/LightSource';
20
20
  import { TriggerAreaComponentDefinitionExtended } from './extended/TriggerArea';
21
21
  import { TagsComponentDefinitionExtended } from './manual/Tags';
22
- import { ICreatedByType } from './manual/CreatedBy';
23
22
  export * from './generated/index.gen';
24
23
  export type { GrowOnlyValueSetComponentDefinition, LastWriteWinElementSetComponentDefinition, LwwComponentGetter, GSetComponentGetter };
25
24
  export declare const Transform: LwwComponentGetter<TransformComponentExtended>;
@@ -51,8 +50,4 @@ export declare const NetworkEntity: (engine: Pick<IEngine, 'defineComponent'>) =
51
50
  * @alpha
52
51
  */
53
52
  export declare const NetworkParent: (engine: Pick<IEngine, 'defineComponent'>) => LastWriteWinElementSetComponentDefinition<INetowrkParentType>;
54
- /**
55
- * @public
56
- */
57
- export declare const CreatedBy: (engine: Pick<IEngine, 'defineComponent'>) => LastWriteWinElementSetComponentDefinition<ICreatedByType>;
58
53
  export { MediaState };
@@ -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.CreatedBy = exports.NetworkParent = exports.NetworkEntity = exports.SyncComponents = exports.Tags = exports.Name = exports.TriggerArea = exports.LightSource = exports.InputModifier = exports.VirtualCamera = exports.Tween = exports.MeshCollider = exports.MeshRenderer = exports.AudioStream = exports.AudioSource = exports.Animator = exports.Material = exports.Transform = void 0;
20
+ exports.MediaState = exports.NetworkParent = exports.NetworkEntity = exports.SyncComponents = exports.Tags = exports.Name = exports.TriggerArea = exports.LightSource = exports.InputModifier = exports.VirtualCamera = exports.Tween = exports.MeshCollider = exports.MeshRenderer = exports.AudioStream = 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 Material_1 = require("./extended/Material");
@@ -37,7 +37,6 @@ const InputModifier_1 = require("./extended/InputModifier");
37
37
  const LightSource_1 = require("./extended/LightSource");
38
38
  const TriggerArea_1 = require("./extended/TriggerArea");
39
39
  const Tags_1 = __importDefault(require("./manual/Tags"));
40
- const CreatedBy_1 = __importDefault(require("./manual/CreatedBy"));
41
40
  __exportStar(require("./generated/index.gen"), exports);
42
41
  /* @__PURE__ */
43
42
  const Transform = (engine) => (0, Transform_1.defineTransformComponent)(engine);
@@ -93,15 +92,12 @@ exports.SyncComponents = SyncComponents;
93
92
  /**
94
93
  * @alpha
95
94
  */
95
+ /* @__PURE__ */
96
96
  const NetworkEntity = (engine) => (0, NetworkEntity_1.default)(engine);
97
97
  exports.NetworkEntity = NetworkEntity;
98
98
  /**
99
99
  * @alpha
100
100
  */
101
+ /* @__PURE__ */
101
102
  const NetworkParent = (engine) => (0, NetworkParent_1.default)(engine);
102
103
  exports.NetworkParent = NetworkParent;
103
- /**
104
- * @public
105
- */
106
- const CreatedBy = (engine) => (0, CreatedBy_1.default)(engine);
107
- 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
  /**
5
4
  * @public
6
5
  */
@@ -12,10 +11,6 @@ export interface TransformComponentExtended extends TransformComponent {
12
11
  create(entity: Entity, val?: TransformTypeWithOptionals): TransformType;
13
12
  createOrReplace(entity: Entity, val?: TransformTypeWithOptionals): TransformType;
14
13
  }
15
- /**
16
- * @public
17
- */
18
- export declare const COMPONENT_ID = 1;
19
14
  /**
20
15
  * @public
21
16
  */
@@ -38,10 +33,6 @@ export type TransformType = {
38
33
  };
39
34
  parent?: Entity;
40
35
  };
41
- /** @public */
42
- export declare const TRANSFORM_LENGTH = 44;
43
- /** @public */
44
- export declare const TransformSchema: ISchema<TransformType>;
45
36
  /**
46
37
  * @public
47
38
  */
@@ -2,12 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defineTransformComponent = exports.TransformSchema = exports.TRANSFORM_LENGTH = exports.COMPONENT_ID = void 0;
4
4
  /**
5
- * @public
5
+ * @internal
6
6
  */
7
7
  exports.COMPONENT_ID = 1;
8
- /** @public */
8
+ /** @internal */
9
9
  exports.TRANSFORM_LENGTH = 44;
10
- /** @public */
10
+ /** @internal */
11
11
  exports.TransformSchema = {
12
12
  serialize(value, builder) {
13
13
  const ptr = builder.incrementWriteOffset(exports.TRANSFORM_LENGTH);
@@ -12,7 +12,6 @@ export type { TagsComponentDefinitionExtended, TagsType } from './manual/Tags';
12
12
  export type { ISyncComponents, ISyncComponentsType } from './manual/SyncComponents';
13
13
  export type { INetowrkEntity, INetowrkEntityType } from './manual/NetworkEntity';
14
14
  export type { INetowrkParent, INetowrkParentType } from './manual/NetworkParent';
15
- export type { ICreatedBy, ICreatedByType } from './manual/CreatedBy';
16
15
  export type { InputModifierHelper, InputModifierComponentDefinitionExtended } from './extended/InputModifier';
17
16
  export type { LightSourceHelper, LightSourceComponentDefinitionExtended } from './extended/LightSource';
18
17
  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, ProcessMessageResultType, PutComponentMessageBody } from '../serialization/crdt';
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
  }
@@ -16,7 +15,7 @@ function freezeSet(set) {
16
15
  return set;
17
16
  }
18
17
  function sortByTimestamp(a, b) {
19
- return a.timestamp > b.timestamp ? 1 : -1;
18
+ return a.timestamp - b.timestamp;
20
19
  }
21
20
  /**
22
21
  * @internal
@@ -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, markAsDirty) {
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;
@@ -144,8 +144,9 @@ function createInputSystem(engine) {
144
144
  }
145
145
  if (!up || !down)
146
146
  return null;
147
- // If the DOWN command has happen before the UP commands, it means that that a clicked has happen
148
- if (down.timestamp < up.timestamp && timestampIsCurrentFrame(up.timestamp)) {
147
+ // If the DOWN command has happened before or at the same time as the UP command, a click has happened.
148
+ // Same-timestamp is possible when both events are produced within the same renderer tick.
149
+ if (down.timestamp <= up.timestamp && timestampIsCurrentFrame(up.timestamp)) {
149
150
  return { up, down };
150
151
  }
151
152
  return null;
@@ -1,10 +1,8 @@
1
1
  import { ISchema } from '../schemas';
2
2
  import { ByteBuffer } from '../serialization/ByteBuffer';
3
- import { PutComponentMessageBody, DeleteComponentMessageBody, ProcessMessageResultType, CrdtMessageBody, PutNetworkComponentMessageBody, DeleteComponentNetworkMessageBody, AuthoritativePutComponentMessageBody } from '../serialization/crdt';
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>): (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>): (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>): () => Generator<PutComponentMessageBody | DeleteComponentMessageBody, void, unknown>;