@dcl/ecs 7.29.1-35039347300.commit-dffaede → 7.29.1-35290475382.commit-201a8a3

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 +2 -45
  8. package/dist/engine/lww-element-set-component-definition.d.ts +1 -3
  9. package/dist/engine/lww-element-set-component-definition.js +13 -68
  10. package/dist/index.d.ts +1 -2
  11. package/dist/index.js +0 -1
  12. package/dist/serialization/crdt/index.d.ts +0 -1
  13. package/dist/serialization/crdt/index.js +0 -1
  14. package/dist/serialization/crdt/network/utils.d.ts +9 -0
  15. package/dist/serialization/crdt/network/utils.js +60 -0
  16. package/dist/serialization/crdt/types.d.ts +3 -25
  17. package/dist/serialization/crdt/types.js +1 -3
  18. package/dist/systems/crdt/index.d.ts +1 -0
  19. package/dist/systems/crdt/index.js +143 -76
  20. package/dist/systems/crdt/types.d.ts +0 -10
  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 +1 -44
  28. package/dist-cjs/engine/lww-element-set-component-definition.d.ts +1 -3
  29. package/dist-cjs/engine/lww-element-set-component-definition.js +14 -71
  30. package/dist-cjs/index.d.ts +1 -2
  31. package/dist-cjs/index.js +1 -2
  32. package/dist-cjs/serialization/crdt/index.d.ts +0 -1
  33. package/dist-cjs/serialization/crdt/index.js +0 -1
  34. package/dist-cjs/serialization/crdt/network/utils.d.ts +9 -0
  35. package/dist-cjs/serialization/crdt/network/utils.js +67 -0
  36. package/dist-cjs/serialization/crdt/types.d.ts +3 -25
  37. package/dist-cjs/serialization/crdt/types.js +1 -3
  38. package/dist-cjs/systems/crdt/index.d.ts +1 -0
  39. package/dist-cjs/systems/crdt/index.js +166 -76
  40. package/dist-cjs/systems/crdt/types.d.ts +0 -10
  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,20 +1,50 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.crdtSceneSystem = void 0;
26
+ exports.crdtSceneSystem = exports.LIVEKIT_MAX_SIZE = void 0;
4
27
  const entity_1 = require("../../engine/entity");
5
28
  const ByteBuffer_1 = require("../../serialization/ByteBuffer");
6
29
  const crdt_1 = require("../../serialization/crdt");
7
30
  const deleteComponent_1 = require("../../serialization/crdt/deleteComponent");
8
31
  const deleteEntity_1 = require("../../serialization/crdt/deleteEntity");
9
32
  const putComponent_1 = require("../../serialization/crdt/putComponent");
10
- const authoritativePutComponent_1 = require("../../serialization/crdt/authoritativePutComponent");
11
33
  const types_1 = require("../../serialization/crdt/types");
34
+ const putComponentNetwork_1 = require("../../serialization/crdt/network/putComponentNetwork");
35
+ const components_1 = require("../../components");
36
+ const networkUtils = __importStar(require("../../serialization/crdt/network/utils"));
37
+ // NetworkMessages can only have a MAX_SIZE of 12kb. So we need to send it in chunks.
38
+ exports.LIVEKIT_MAX_SIZE = 12;
12
39
  /**
13
40
  * @internal
14
41
  */
15
42
  function crdtSceneSystem(engine, onProcessEntityComponentChange) {
16
43
  const transports = [];
17
- // No network components needed - pure CRDT processing only
44
+ // Components that we used on this system
45
+ const NetworkEntity = (0, components_1.NetworkEntity)(engine);
46
+ const NetworkParent = (0, components_1.NetworkParent)(engine);
47
+ const Transform = (0, components_1.Transform)(engine);
18
48
  // Messages that we received at transport.onMessage waiting to be processed
19
49
  const receivedMessages = [];
20
50
  // Messages already processed by the engine but that we need to broadcast to other transports.
@@ -39,20 +69,27 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
39
69
  if (header.type === types_1.CrdtMessageType.DELETE_COMPONENT) {
40
70
  message = deleteComponent_1.DeleteComponent.read(buffer);
41
71
  }
72
+ else if (header.type === types_1.CrdtMessageType.DELETE_COMPONENT_NETWORK) {
73
+ message = crdt_1.DeleteComponentNetwork.read(buffer);
74
+ }
42
75
  else if (header.type === types_1.CrdtMessageType.PUT_COMPONENT) {
43
76
  message = putComponent_1.PutComponentOperation.read(buffer);
44
77
  }
45
- else if (header.type === types_1.CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT) {
46
- message = authoritativePutComponent_1.AuthoritativePutComponentOperation.read(buffer);
78
+ else if (header.type === types_1.CrdtMessageType.PUT_COMPONENT_NETWORK) {
79
+ message = putComponentNetwork_1.PutNetworkComponentOperation.read(buffer);
47
80
  }
48
81
  else if (header.type === types_1.CrdtMessageType.DELETE_ENTITY) {
49
82
  message = deleteEntity_1.DeleteEntity.read(buffer);
50
83
  }
84
+ else if (header.type === types_1.CrdtMessageType.DELETE_ENTITY_NETWORK) {
85
+ message = crdt_1.DeleteEntityNetwork.read(buffer);
86
+ }
51
87
  else if (header.type === types_1.CrdtMessageType.APPEND_VALUE) {
52
88
  message = crdt_1.AppendValueOperation.read(buffer);
89
+ // Unknown message, we skip it
53
90
  }
54
91
  else {
55
- // Unknown message, we skip it (including NETWORK messages)
92
+ // consume the message
56
93
  buffer.incrementReadOffset(header.length);
57
94
  }
58
95
  if (message) {
@@ -74,12 +111,20 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
74
111
  return messagesToProcess;
75
112
  }
76
113
  /**
77
- * Reserved-range entities (root/player/camera + avatars, entity number <
78
- * RESERVED_STATIC_ENTITIES) are host-owned: only a transport flagged with
79
- * `allowReservedEntities` (the host/renderer) may mutate or delete them.
114
+ * Find the local entityId associated to the network component message.
115
+ * It's a mapping Network -> to Local
116
+ * If it's not a network message, return the entityId received by the message
80
117
  */
81
- function isTrustedForReservedEntities(transportId) {
82
- return transportId !== undefined && !!transports[transportId]?.allowReservedEntities;
118
+ function findNetworkId(msg) {
119
+ const hasNetworkId = 'networkId' in msg;
120
+ if (hasNetworkId) {
121
+ for (const [entityId, network] of engine.getEntitiesWith(NetworkEntity)) {
122
+ if (network.networkId === msg.networkId && network.entityId === msg.entityId) {
123
+ return { entityId, network };
124
+ }
125
+ }
126
+ }
127
+ return { entityId: msg.entityId };
83
128
  }
84
129
  /**
85
130
  * This fn will be called on every tick.
@@ -89,68 +134,46 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
89
134
  const messagesToProcess = getMessages(receivedMessages);
90
135
  const entitiesShouldBeCleaned = [];
91
136
  for (const msg of messagesToProcess) {
92
- // Simple CRDT processing - no network logic
93
- if (msg.type === types_1.CrdtMessageType.DELETE_ENTITY) {
94
- // Reject an inbound DELETE_ENTITY on a reserved entity from an untrusted
95
- // transport (a comms peer, or a scene-added transport). The allocator half
96
- // is already guarded (engine.removeEntity is a no-op on this range); this
97
- // closes the receive-side half.
98
- const isReserved = engine.entityContainer.getEntityState(msg.entityId) === entity_1.EntityState.Reserved;
99
- if (isReserved && !isTrustedForReservedEntities(msg.transportId)) {
100
- continue;
101
- }
102
- entitiesShouldBeCleaned.push(msg.entityId);
137
+ let { entityId, network } = findNetworkId(msg);
138
+ // We receive a new Entity. Create the localEntity and map it to the NetworkEntity component
139
+ if (networkUtils.isNetworkMessage(msg) && !network) {
140
+ entityId = engine.addEntity();
141
+ network = { entityId: msg.entityId, networkId: msg.networkId };
142
+ NetworkEntity.createOrReplace(entityId, network);
143
+ }
144
+ if (msg.type === types_1.CrdtMessageType.DELETE_ENTITY || msg.type === types_1.CrdtMessageType.DELETE_ENTITY_NETWORK) {
145
+ entitiesShouldBeCleaned.push(entityId);
103
146
  broadcastMessages.push(msg);
104
147
  }
105
148
  else {
106
- const entityState = engine.entityContainer.getEntityState(msg.entityId);
107
- // Skip updates from removed entities
149
+ const entityState = engine.entityContainer.getEntityState(entityId);
150
+ // Skip updates from removed entityes
108
151
  if (entityState === entity_1.EntityState.Removed)
109
152
  continue;
110
- // Reject component operations (PUT/DELETE/APPEND, including AUTHORITATIVE_PUT
111
- // which bypasses timestamps entirely) on reserved entities from untrusted
112
- // transports. Dropping before updateFromCrdt keeps local LWW timestamps
113
- // unpoisoned by forged high timestamps, and also prevents the
114
- // unknown-component rebroadcast below from relaying forged reserved-entity
115
- // data to other transports (including the renderer).
116
- if (entityState === entity_1.EntityState.Reserved && !isTrustedForReservedEntities(msg.transportId))
117
- continue;
118
- // Entities with unknown state should update its entity state
153
+ // Entities with unknown entities should update its entity state
119
154
  if (entityState === entity_1.EntityState.Unknown) {
120
- engine.entityContainer.updateUsedEntity(msg.entityId);
121
- }
122
- // Only process component-related messages (not DELETE_ENTITY)
123
- if ('componentId' in msg) {
124
- const component = engine.getComponentOrNull(msg.componentId);
125
- if (component) {
126
- // Handle authoritative messages differently - they force the state regardless of timestamp
127
- const tryUpdate = () => {
128
- try {
129
- return msg.type === types_1.CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT
130
- ? component.__forceUpdateFromCrdt(msg)
131
- : component.updateFromCrdt(msg);
132
- }
133
- catch (e) {
134
- console.error('[receiveMessages] ERROR processing message', msg, e);
135
- return null;
136
- }
137
- };
138
- const result = tryUpdate();
139
- if (!result)
140
- continue;
141
- const [conflictMessage, value] = result;
142
- if (!conflictMessage) {
143
- // Add message to broadcast queue when no conflict
144
- broadcastMessages.push(msg);
145
- onProcessEntityComponentChange && onProcessEntityComponentChange(msg.entityId, msg.type, component, value);
146
- }
155
+ engine.entityContainer.updateUsedEntity(entityId);
156
+ }
157
+ const component = engine.getComponentOrNull(msg.componentId);
158
+ /* istanbul ignore else */
159
+ if (component) {
160
+ if (msg.type === types_1.CrdtMessageType.PUT_COMPONENT &&
161
+ component.componentId === Transform.componentId &&
162
+ NetworkEntity.has(entityId) &&
163
+ NetworkParent.has(entityId)) {
164
+ msg.data = networkUtils.fixTransformParent(msg);
147
165
  }
148
- else {
149
- // Component not found - still broadcast for editor compatibility
150
- /* istanbul ignore next */
166
+ const [conflictMessage, value] = component.updateFromCrdt({ ...msg, entityId });
167
+ if (!conflictMessage) {
168
+ // Add message to transport queue to be processed by others transports
151
169
  broadcastMessages.push(msg);
170
+ onProcessEntityComponentChange && onProcessEntityComponentChange(entityId, msg.type, component, value);
152
171
  }
153
172
  }
173
+ else {
174
+ // TODO: test this line, it is fundammental to make the editor work
175
+ broadcastMessages.push(msg);
176
+ }
154
177
  }
155
178
  }
156
179
  // the last stage of the syncrhonization is to delete the entities
@@ -164,17 +187,16 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
164
187
  }
165
188
  }
166
189
  /**
167
- * Simple CRDT message broadcasting - no network-specific logic
190
+ * Iterates the dirty map and generates crdt messages to be send
168
191
  */
169
192
  async function sendMessages(entitiesDeletedThisTick) {
170
- // Get messages from broadcast queue and component updates
193
+ // CRDT Messages will be the merge between the recieved transport messages and the new crdt messages
171
194
  const crdtMessages = getMessages(broadcastMessages);
172
195
  const buffer = new ByteBuffer_1.ReadWriteByteBuffer();
173
- // Generate CRDT messages from component updates
174
196
  for (const component of engine.componentsIter()) {
175
197
  for (const message of component.getCrdtUpdates()) {
176
198
  const offset = buffer.currentWriteOffset();
177
- // Only create messages if there's a transport that will handle it
199
+ // Avoid creating messages if there is no transport that will handle it
178
200
  if (transports.some((t) => t.filter(message))) {
179
201
  if (message.type === types_1.CrdtMessageType.PUT_COMPONENT) {
180
202
  putComponent_1.PutComponentOperation.write(message.entityId, message.timestamp, message.componentId, message.data, buffer);
@@ -198,7 +220,7 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
198
220
  }
199
221
  }
200
222
  }
201
- // Handle deleted entities
223
+ // After all updates, I execute the DeletedEntity messages
202
224
  for (const entityId of entitiesDeletedThisTick) {
203
225
  const offset = buffer.currentWriteOffset();
204
226
  deleteEntity_1.DeleteEntity.write(entityId, buffer);
@@ -209,19 +231,87 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
209
231
  });
210
232
  onProcessEntityComponentChange && onProcessEntityComponentChange(entityId, types_1.CrdtMessageType.DELETE_ENTITY);
211
233
  }
212
- // Simple transport broadcasting - no network-specific transforms
213
- for (const transport of transports) {
214
- const transportBuffer = new ByteBuffer_1.ReadWriteByteBuffer();
234
+ // Send CRDT messages to transports
235
+ const transportBuffer = new ByteBuffer_1.ReadWriteByteBuffer();
236
+ for (const index in transports) {
237
+ const __NetworkMessagesBuffer = [];
238
+ const transportIndex = Number(index);
239
+ const transport = transports[transportIndex];
240
+ const isRendererTransport = transport.type === 'renderer';
241
+ const isNetworkTransport = transport.type === 'network';
242
+ // Reset Buffer for each Transport
243
+ transportBuffer.resetBuffer();
244
+ const buffer = new ByteBuffer_1.ReadWriteByteBuffer();
245
+ // Then we send all the new crdtMessages that the transport needs to process
215
246
  for (const message of crdtMessages) {
216
247
  // Avoid echo messages
217
- if (message.transportId === transports.indexOf(transport))
248
+ if (message.transportId === transportIndex)
249
+ continue;
250
+ // Redundant message for the transport
251
+ if (!transport.filter(message))
252
+ continue;
253
+ // Check if adding this message would exceed the size limit
254
+ const currentBufferSize = transportBuffer.toBinary().byteLength;
255
+ const messageSize = message.messageBuffer.byteLength;
256
+ if (isNetworkTransport && (currentBufferSize + messageSize) / 1024 > exports.LIVEKIT_MAX_SIZE) {
257
+ // If the current buffer has content, save it as a chunk
258
+ if (currentBufferSize > 0) {
259
+ __NetworkMessagesBuffer.push(transportBuffer.toCopiedBinary());
260
+ transportBuffer.resetBuffer();
261
+ }
262
+ // If the message itself is larger than the limit, we need to handle it specially
263
+ // For now, we'll skip it to prevent infinite loops
264
+ if (messageSize / 1024 > exports.LIVEKIT_MAX_SIZE) {
265
+ console.error(`Message too large (${messageSize} bytes), skipping message for entity ${message.entityId}`);
266
+ continue;
267
+ }
268
+ }
269
+ const { entityId } = findNetworkId(message);
270
+ const transformNeedsFix = 'componentId' in message &&
271
+ message.componentId === Transform.componentId &&
272
+ Transform.has(entityId) &&
273
+ NetworkParent.has(entityId) &&
274
+ NetworkEntity.has(entityId);
275
+ // If there was a LOCAL change in the transform. Add the parent to that transform
276
+ if (isRendererTransport && message.type === types_1.CrdtMessageType.PUT_COMPONENT && transformNeedsFix) {
277
+ const parent = findNetworkId(NetworkParent.get(entityId));
278
+ const transformData = networkUtils.fixTransformParent(message, Transform.get(entityId), parent.entityId);
279
+ const offset = buffer.currentWriteOffset();
280
+ putComponent_1.PutComponentOperation.write(entityId, message.timestamp, message.componentId, transformData, buffer);
281
+ transportBuffer.writeBuffer(buffer.buffer().subarray(offset, buffer.currentWriteOffset()), false);
218
282
  continue;
219
- // Check if transport wants this message
220
- if (transport.filter(message)) {
221
- transportBuffer.writeBuffer(message.messageBuffer, false);
222
283
  }
284
+ if (isRendererTransport && networkUtils.isNetworkMessage(message)) {
285
+ // If it's the renderer transport and its a NetworkMessage, we need to fix the entityId field and convert it to a known Message.
286
+ // PUT_NETWORK_COMPONENT -> PUT_COMPONENT
287
+ let transformData = 'data' in message ? message.data : new Uint8Array();
288
+ if (transformNeedsFix) {
289
+ const parent = findNetworkId(NetworkParent.get(entityId));
290
+ transformData = networkUtils.fixTransformParent(message, Transform.get(entityId), parent.entityId);
291
+ }
292
+ networkUtils.networkMessageToLocal({ ...message, data: transformData }, entityId, buffer, transportBuffer);
293
+ // Iterate the next message
294
+ continue;
295
+ }
296
+ // If its a network transport and its a PUT_COMPONENT that has a NetworkEntity component, we need to send this message
297
+ // through comms with the EntityID and NetworkID from ther NetworkEntity so everyone can recieve this message and map to their custom entityID.
298
+ if (isNetworkTransport && !networkUtils.isNetworkMessage(message)) {
299
+ const networkData = NetworkEntity.getOrNull(message.entityId);
300
+ // If it has networkData convert the message to PUT_NETWORK_COMPONENT.
301
+ if (networkData) {
302
+ networkUtils.localMessageToNetwork(message, networkData, buffer, transportBuffer);
303
+ // Iterate the next message
304
+ continue;
305
+ }
306
+ }
307
+ // Common message
308
+ transportBuffer.writeBuffer(message.messageBuffer, false);
309
+ }
310
+ if (isNetworkTransport && transportBuffer.currentWriteOffset()) {
311
+ __NetworkMessagesBuffer.push(transportBuffer.toBinary());
223
312
  }
224
- await transport.send(transportBuffer.toBinary());
313
+ const message = isNetworkTransport ? __NetworkMessagesBuffer : transportBuffer.toBinary();
314
+ await transport.send(message);
225
315
  }
226
316
  }
227
317
  /**
@@ -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
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dcl/ecs",
3
3
  "description": "Decentraland ECS",
4
- "version": "7.29.1-35039347300.commit-dffaede",
4
+ "version": "7.29.1-35290475382.commit-201a8a3",
5
5
  "author": "DCL",
6
6
  "bugs": "https://github.com/decentraland/ecs/issues",
7
7
  "files": [
@@ -34,5 +34,5 @@
34
34
  "dependencies": {},
35
35
  "types": "./dist/index.d.ts",
36
36
  "typings": "./dist/index.d.ts",
37
- "commit": "dffaede67b4ff56bdfc4af6e6d5d729ee1308767"
37
+ "commit": "201a8a3552e90504b10e426177f1e4c681a68f74"
38
38
  }
@@ -1,9 +0,0 @@
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;
@@ -1,8 +0,0 @@
1
- import { Schemas } from '../../schemas';
2
- function defineCreatedBy(engine) {
3
- const CreatedBy = engine.defineComponent('core-schema::Created-By', {
4
- address: Schemas.String
5
- });
6
- return CreatedBy;
7
- }
8
- export default defineCreatedBy;
@@ -1,15 +0,0 @@
1
- import { Entity } from '../../engine/entity';
2
- import { ByteBuffer } from '../ByteBuffer';
3
- import { AuthoritativePutComponentMessage } from './types';
4
- /**
5
- * @public
6
- */
7
- export declare namespace AuthoritativePutComponentOperation {
8
- const MESSAGE_HEADER_LENGTH = 16;
9
- /**
10
- * Call this function for an optimal writing data passing the ByteBuffer
11
- * already allocated
12
- */
13
- function write(entity: Entity, timestamp: number, componentId: number, data: Uint8Array, buf: ByteBuffer): void;
14
- function read(buf: ByteBuffer): AuthoritativePutComponentMessage | null;
15
- }
@@ -1,47 +0,0 @@
1
- import { CrdtMessageProtocol } from './crdtMessageProtocol';
2
- import { CrdtMessageType, CRDT_MESSAGE_HEADER_LENGTH } from './types';
3
- /**
4
- * @public
5
- */
6
- export var AuthoritativePutComponentOperation;
7
- (function (AuthoritativePutComponentOperation) {
8
- AuthoritativePutComponentOperation.MESSAGE_HEADER_LENGTH = 16;
9
- /**
10
- * Call this function for an optimal writing data passing the ByteBuffer
11
- * already allocated
12
- */
13
- function write(entity, timestamp, componentId, data, buf) {
14
- // reserve the beginning
15
- const startMessageOffset = buf.incrementWriteOffset(CRDT_MESSAGE_HEADER_LENGTH + AuthoritativePutComponentOperation.MESSAGE_HEADER_LENGTH);
16
- // write body
17
- buf.writeBuffer(data, false);
18
- const messageLength = buf.currentWriteOffset() - startMessageOffset;
19
- // Write CrdtMessage header
20
- buf.setUint32(startMessageOffset, messageLength);
21
- buf.setUint32(startMessageOffset + 4, CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT);
22
- // Write ComponentOperation header
23
- buf.setUint32(startMessageOffset + 8, entity);
24
- buf.setUint32(startMessageOffset + 12, componentId);
25
- buf.setUint32(startMessageOffset + 16, timestamp);
26
- const newLocal = messageLength - AuthoritativePutComponentOperation.MESSAGE_HEADER_LENGTH - CRDT_MESSAGE_HEADER_LENGTH;
27
- buf.setUint32(startMessageOffset + 20, newLocal);
28
- }
29
- AuthoritativePutComponentOperation.write = write;
30
- function read(buf) {
31
- const header = CrdtMessageProtocol.readHeader(buf);
32
- if (!header) {
33
- return null;
34
- }
35
- if (header.type !== CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT) {
36
- throw new Error('AuthoritativePutComponentOperation tried to read another message type.');
37
- }
38
- return {
39
- ...header,
40
- entityId: buf.readUint32(),
41
- componentId: buf.readUint32(),
42
- timestamp: buf.readUint32(),
43
- data: buf.readBuffer()
44
- };
45
- }
46
- AuthoritativePutComponentOperation.read = read;
47
- })(AuthoritativePutComponentOperation || (AuthoritativePutComponentOperation = {}));
@@ -1,9 +0,0 @@
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;
@@ -1,10 +0,0 @@
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,15 +0,0 @@
1
- import { Entity } from '../../engine/entity';
2
- import { ByteBuffer } from '../ByteBuffer';
3
- import { AuthoritativePutComponentMessage } from './types';
4
- /**
5
- * @public
6
- */
7
- export declare namespace AuthoritativePutComponentOperation {
8
- const MESSAGE_HEADER_LENGTH = 16;
9
- /**
10
- * Call this function for an optimal writing data passing the ByteBuffer
11
- * already allocated
12
- */
13
- function write(entity: Entity, timestamp: number, componentId: number, data: Uint8Array, buf: ByteBuffer): void;
14
- function read(buf: ByteBuffer): AuthoritativePutComponentMessage | null;
15
- }
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AuthoritativePutComponentOperation = void 0;
4
- const crdtMessageProtocol_1 = require("./crdtMessageProtocol");
5
- const types_1 = require("./types");
6
- /**
7
- * @public
8
- */
9
- var AuthoritativePutComponentOperation;
10
- (function (AuthoritativePutComponentOperation) {
11
- AuthoritativePutComponentOperation.MESSAGE_HEADER_LENGTH = 16;
12
- /**
13
- * Call this function for an optimal writing data passing the ByteBuffer
14
- * already allocated
15
- */
16
- function write(entity, timestamp, componentId, data, buf) {
17
- // reserve the beginning
18
- const startMessageOffset = buf.incrementWriteOffset(types_1.CRDT_MESSAGE_HEADER_LENGTH + AuthoritativePutComponentOperation.MESSAGE_HEADER_LENGTH);
19
- // write body
20
- buf.writeBuffer(data, false);
21
- const messageLength = buf.currentWriteOffset() - startMessageOffset;
22
- // Write CrdtMessage header
23
- buf.setUint32(startMessageOffset, messageLength);
24
- buf.setUint32(startMessageOffset + 4, types_1.CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT);
25
- // Write ComponentOperation header
26
- buf.setUint32(startMessageOffset + 8, entity);
27
- buf.setUint32(startMessageOffset + 12, componentId);
28
- buf.setUint32(startMessageOffset + 16, timestamp);
29
- const newLocal = messageLength - AuthoritativePutComponentOperation.MESSAGE_HEADER_LENGTH - types_1.CRDT_MESSAGE_HEADER_LENGTH;
30
- buf.setUint32(startMessageOffset + 20, newLocal);
31
- }
32
- AuthoritativePutComponentOperation.write = write;
33
- function read(buf) {
34
- const header = crdtMessageProtocol_1.CrdtMessageProtocol.readHeader(buf);
35
- if (!header) {
36
- return null;
37
- }
38
- if (header.type !== types_1.CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT) {
39
- throw new Error('AuthoritativePutComponentOperation tried to read another message type.');
40
- }
41
- return {
42
- ...header,
43
- entityId: buf.readUint32(),
44
- componentId: buf.readUint32(),
45
- timestamp: buf.readUint32(),
46
- data: buf.readBuffer()
47
- };
48
- }
49
- AuthoritativePutComponentOperation.read = read;
50
- })(AuthoritativePutComponentOperation = exports.AuthoritativePutComponentOperation || (exports.AuthoritativePutComponentOperation = {}));