@dcl/ecs 7.23.2-25521226778.commit-1828100 → 7.23.2-25802088407.commit-15e8697

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 (51) 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 +12 -64
  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 +146 -55
  20. package/dist/systems/triggerArea.d.ts +5 -0
  21. package/dist/systems/triggerArea.js +129 -42
  22. package/dist-cjs/components/index.d.ts +0 -5
  23. package/dist-cjs/components/index.js +3 -7
  24. package/dist-cjs/components/manual/Transform.d.ts +0 -9
  25. package/dist-cjs/components/manual/Transform.js +3 -3
  26. package/dist-cjs/components/types.d.ts +0 -1
  27. package/dist-cjs/engine/component.d.ts +1 -52
  28. package/dist-cjs/engine/grow-only-value-set-component-definition.js +1 -44
  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 -67
  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/dist-cjs/systems/triggerArea.d.ts +5 -0
  42. package/dist-cjs/systems/triggerArea.js +129 -42
  43. package/package.json +2 -2
  44. package/dist/components/manual/CreatedBy.d.ts +0 -9
  45. package/dist/components/manual/CreatedBy.js +0 -8
  46. package/dist/serialization/crdt/authoritativePutComponent.d.ts +0 -15
  47. package/dist/serialization/crdt/authoritativePutComponent.js +0 -47
  48. package/dist-cjs/components/manual/CreatedBy.d.ts +0 -9
  49. package/dist-cjs/components/manual/CreatedBy.js +0 -10
  50. package/dist-cjs/serialization/crdt/authoritativePutComponent.d.ts +0 -15
  51. package/dist-cjs/serialization/crdt/authoritativePutComponent.js +0 -50
@@ -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
  }
@@ -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;
@@ -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>, lastSentData: Map<Entity, Uint8Array>): (message: PutComponentMessageBody | DeleteComponentMessageBody | PutNetworkComponentMessageBody | DeleteComponentNetworkMessageBody) => ProcessMessageResultType;
8
- export declare function createForceUpdateLwwFromCrdt(componentId: number, timestamps: Map<Entity, number>, schema: Pick<ISchema<any>, 'serialize' | 'deserialize'>, data: Map<Entity, unknown>): (msg: AuthoritativePutComponentMessageBody) => [null, any];
9
7
  export declare function createUpdateLwwFromCrdt(componentId: number, timestamps: Map<Entity, number>, schema: Pick<ISchema<any>, 'serialize' | 'deserialize'>, data: Map<Entity, unknown>, lastSentData: Map<Entity, Uint8Array>): (msg: CrdtMessageBody) => [null | PutComponentMessageBody | DeleteComponentMessageBody, any];
10
8
  export declare function createGetCrdtMessagesForLww(componentId: number, timestamps: Map<Entity, number>, dirtyIterator: Set<Entity>, schema: Pick<ISchema<any>, 'serialize'>, data: Map<Entity, unknown>, lastSentData: Map<Entity, Uint8Array>): () => Generator<PutComponentMessageBody | DeleteComponentMessageBody, void, unknown>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createComponentDefinitionFromSchema = exports.createGetCrdtMessagesForLww = exports.createUpdateLwwFromCrdt = exports.createForceUpdateLwwFromCrdt = exports.createCrdtRuleValidator = exports.createDumpLwwFunctionFromCrdt = exports.incrementTimestamp = void 0;
3
+ exports.createComponentDefinitionFromSchema = exports.createGetCrdtMessagesForLww = exports.createUpdateLwwFromCrdt = exports.createDumpLwwFunctionFromCrdt = exports.incrementTimestamp = void 0;
4
4
  const ByteBuffer_1 = require("../serialization/ByteBuffer");
5
5
  const crdt_1 = require("../serialization/crdt");
6
6
  const utils_1 = require("../systems/crdt/utils");
@@ -35,12 +35,16 @@ function createDumpLwwFunctionFromCrdt(componentId, timestamps, schema, data) {
35
35
  };
36
36
  }
37
37
  exports.createDumpLwwFunctionFromCrdt = createDumpLwwFunctionFromCrdt;
38
- const __GLOBAL_ENTITY = '__GLOBAL_ENTITY';
39
- function createCrdtRuleValidator(timestamps, schema, data, lastSentData) {
38
+ function createUpdateLwwFromCrdt(componentId, timestamps, schema, data, lastSentData) {
40
39
  /**
41
- * Shared CRDT conflict resolution logic
42
- * @public
43
- */
40
+ * Process the received message only if the lamport number recieved is higher
41
+ * than the stored one. If its lower, we spread it to the network to correct the peer.
42
+ * If they are equal, the bigger raw data wins.
43
+
44
+ * Returns the recieved data if the lamport number was bigger than ours.
45
+ * If it was an outdated message, then we return void
46
+ * @public
47
+ */
44
48
  function crdtRuleForCurrentState(message) {
45
49
  const { entityId, timestamp } = message;
46
50
  const currentTimestamp = timestamps.get(entityId);
@@ -50,6 +54,7 @@ function createCrdtRuleValidator(timestamps, schema, data, lastSentData) {
50
54
  }
51
55
  // Outdated Message. Resend our state message through the wire.
52
56
  if (currentTimestamp > timestamp) {
57
+ // console.log('2', currentTimestamp, timestamp)
53
58
  return crdt_1.ProcessMessageResultType.StateOutdatedTimestamp;
54
59
  }
55
60
  // Deletes are idempotent
@@ -66,6 +71,7 @@ function createCrdtRuleValidator(timestamps, schema, data, lastSentData) {
66
71
  currentDataGreater = (0, utils_1.dataCompare)(null, message.data);
67
72
  }
68
73
  // Same data, same timestamp. Weirdo echo message.
74
+ // console.log('3', currentDataGreater, writeBuffer.toBinary(), (message as any).data || null)
69
75
  if (currentDataGreater === 0) {
70
76
  return crdt_1.ProcessMessageResultType.NoChanges;
71
77
  }
@@ -74,37 +80,10 @@ function createCrdtRuleValidator(timestamps, schema, data, lastSentData) {
74
80
  return crdt_1.ProcessMessageResultType.StateOutdatedData;
75
81
  }
76
82
  else {
77
- // Current data is lower
83
+ // Curent data is lower
78
84
  return crdt_1.ProcessMessageResultType.StateUpdatedData;
79
85
  }
80
86
  }
81
- return crdtRuleForCurrentState;
82
- }
83
- exports.createCrdtRuleValidator = createCrdtRuleValidator;
84
- function createForceUpdateLwwFromCrdt(componentId, timestamps, schema, data) {
85
- /**
86
- * Force update component state regardless of timestamp - used for server authoritative messages
87
- */
88
- return (msg) => {
89
- const buffer = new ByteBuffer_1.ReadWriteByteBuffer(msg.data);
90
- const deserializedValue = schema.deserialize(buffer);
91
- data.set(msg.entityId, deserializedValue);
92
- timestamps.set(msg.entityId, msg.timestamp);
93
- return [null, deserializedValue];
94
- };
95
- }
96
- exports.createForceUpdateLwwFromCrdt = createForceUpdateLwwFromCrdt;
97
- function createUpdateLwwFromCrdt(componentId, timestamps, schema, data, lastSentData) {
98
- /**
99
- * Process the received message only if the lamport number recieved is higher
100
- * than the stored one. If its lower, we spread it to the network to correct the peer.
101
- * If they are equal, the bigger raw data wins.
102
-
103
- * Returns the recieved data if the lamport number was bigger than ours.
104
- * If it was an outdated message, then we return void
105
- * @public
106
- */
107
- const crdtRuleForCurrentState = createCrdtRuleValidator(timestamps, schema, data, lastSentData);
108
87
  return (msg) => {
109
88
  /* istanbul ignore next */
110
89
  if (msg.type !== crdt_1.CrdtMessageType.PUT_COMPONENT &&
@@ -213,7 +192,6 @@ function createComponentDefinitionFromSchema(componentName, componentId, schema)
213
192
  const timestamps = new Map();
214
193
  const lastSentData = new Map();
215
194
  const onChangeCallbacks = new Map();
216
- const validateCallbacks = new Map();
217
195
  return {
218
196
  get componentId() {
219
197
  return componentId;
@@ -308,39 +286,7 @@ function createComponentDefinitionFromSchema(componentName, componentId, schema)
308
286
  },
309
287
  getCrdtUpdates: createGetCrdtMessagesForLww(componentId, timestamps, dirtyIterator, schema, data, lastSentData),
310
288
  updateFromCrdt: createUpdateLwwFromCrdt(componentId, timestamps, schema, data, lastSentData),
311
- __forceUpdateFromCrdt: createForceUpdateLwwFromCrdt(componentId, timestamps, schema, data),
312
- __dry_run_updateFromCrdt: createCrdtRuleValidator(timestamps, schema, data, lastSentData),
313
289
  dumpCrdtStateToBuffer: createDumpLwwFunctionFromCrdt(componentId, timestamps, schema, data),
314
- validateBeforeChange(entityOrCb, cb) {
315
- if (arguments.length === 1) {
316
- // Second overload: just callback (global validation)
317
- validateCallbacks.set(__GLOBAL_ENTITY, entityOrCb);
318
- }
319
- else {
320
- if (cb) {
321
- validateCallbacks.set(entityOrCb, cb);
322
- }
323
- }
324
- },
325
- __run_validateBeforeChange(entity, newValue, senderAddress, createdBy) {
326
- const cb = entity && validateCallbacks.get(entity);
327
- const globalCb = validateCallbacks.get(__GLOBAL_ENTITY);
328
- const currentValue = data.get(entity);
329
- const value = { entity, currentValue, newValue, senderAddress, createdBy };
330
- const globalResult = globalCb?.(value) ?? true;
331
- const entityResult = (globalResult && cb?.(value)) ?? true;
332
- return globalResult && entityResult;
333
- },
334
- getCrdtState(entity) {
335
- const componentData = data.get(entity);
336
- const timestamp = timestamps.get(entity);
337
- if (componentData && timestamp !== undefined) {
338
- const buffer = new ByteBuffer_1.ReadWriteByteBuffer();
339
- schema.serialize((0, readonly_1.deepReadonly)(componentData), buffer);
340
- return { data: buffer.toBinary(), timestamp };
341
- }
342
- return null;
343
- },
344
290
  onChange(entity, cb) {
345
291
  const cbs = onChangeCallbacks.get(entity) ?? [];
346
292
  cbs.push(cb);
@@ -15,7 +15,7 @@ export * from './systems/triggerArea';
15
15
  export * from './systems/physics';
16
16
  export * from './engine/entity';
17
17
  export * from './components/types';
18
- import { MaterialComponentDefinitionExtended, MeshColliderComponentDefinitionExtended, MeshRendererComponentDefinitionExtended, TransformComponentExtended, AnimatorComponentDefinitionExtended, AudioSourceComponentDefinitionExtended, AudioAnalysisComponentDefinitionExtended, AudioStreamComponentDefinitionExtended, ISyncComponents, TweenComponentDefinitionExtended, INetowrkEntity, INetowrkParent, VirtualCameraComponentDefinitionExtended, InputModifierComponentDefinitionExtended, LightSourceComponentDefinitionExtended, TriggerAreaComponentDefinitionExtended, ParticleSystemComponentDefinitionExtended, ICreatedBy } from './components/types';
18
+ import { MaterialComponentDefinitionExtended, MeshColliderComponentDefinitionExtended, MeshRendererComponentDefinitionExtended, TransformComponentExtended, AnimatorComponentDefinitionExtended, AudioSourceComponentDefinitionExtended, AudioAnalysisComponentDefinitionExtended, AudioStreamComponentDefinitionExtended, ISyncComponents, TweenComponentDefinitionExtended, INetowrkEntity, INetowrkParent, VirtualCameraComponentDefinitionExtended, InputModifierComponentDefinitionExtended, LightSourceComponentDefinitionExtended, TriggerAreaComponentDefinitionExtended, ParticleSystemComponentDefinitionExtended } from './components/types';
19
19
  import { NameComponent } from './components/manual/Name';
20
20
  import { TagsComponentDefinitionExtended } from './components/manual/Tags';
21
21
  export declare const Transform: TransformComponentExtended;
@@ -50,7 +50,6 @@ export declare const NetworkEntity: INetowrkEntity;
50
50
  * Tag a entity to be syncronized through comms
51
51
  */
52
52
  export declare const NetworkParent: INetowrkParent;
53
- export declare const CreatedBy: ICreatedBy;
54
53
  export * from './components/generated/global.gen';
55
54
  export * from './components/generated/types.gen';
56
55
  export * from './serialization/crdt';
package/dist-cjs/index.js CHANGED
@@ -26,7 +26,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
26
26
  return result;
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.CreatedBy = exports.NetworkParent = exports.NetworkEntity = exports.SyncComponents = exports.ParticleSystem = exports.TriggerArea = exports.LightSource = exports.InputModifier = exports.VirtualCamera = exports.Tween = exports.Tags = exports.Name = exports.MeshCollider = exports.MeshRenderer = exports.Material = exports.AudioStream = exports.AudioAnalysis = exports.AudioSource = exports.Animator = exports.Transform = exports.components = exports.cyclicParentingChecker = void 0;
29
+ exports.NetworkParent = exports.NetworkEntity = exports.SyncComponents = exports.ParticleSystem = exports.TriggerArea = exports.LightSource = exports.InputModifier = exports.VirtualCamera = exports.Tween = exports.Tags = exports.Name = exports.MeshCollider = exports.MeshRenderer = exports.Material = exports.AudioStream = exports.AudioAnalysis = exports.AudioSource = exports.Animator = exports.Transform = exports.components = exports.cyclicParentingChecker = void 0;
30
30
  // The order of the following imports matters. Please do not auto-sort
31
31
  __exportStar(require("./engine"), exports);
32
32
  __exportStar(require("./schemas"), exports);
@@ -84,7 +84,6 @@ exports.NetworkEntity = components.NetworkEntity(initialization_1.engine);
84
84
  * Tag a entity to be syncronized through comms
85
85
  */
86
86
  exports.NetworkParent = components.NetworkParent(initialization_1.engine);
87
- exports.CreatedBy = components.CreatedBy(initialization_1.engine);
88
87
  // export components for global engine
89
88
  __exportStar(require("./components/generated/global.gen"), exports);
90
89
  __exportStar(require("./components/generated/types.gen"), exports);
@@ -7,4 +7,3 @@ export * from './network/deleteComponentNetwork';
7
7
  export * from './network/deleteEntityNetwork';
8
8
  export * from './types';
9
9
  export * from './crdtMessageProtocol';
10
- export * from './authoritativePutComponent';
@@ -23,4 +23,3 @@ __exportStar(require("./network/deleteComponentNetwork"), exports);
23
23
  __exportStar(require("./network/deleteEntityNetwork"), exports);
24
24
  __exportStar(require("./types"), exports);
25
25
  __exportStar(require("./crdtMessageProtocol"), exports);
26
- __exportStar(require("./authoritativePutComponent"), exports);
@@ -0,0 +1,9 @@
1
+ import { Entity } from '../../../engine';
2
+ import { ReceiveMessage, TransformType } from '../../../runtime/types';
3
+ import { ReceiveNetworkMessage } from '../../../systems/crdt/types';
4
+ import { ByteBuffer } from '../../ByteBuffer';
5
+ import { INetowrkEntityType } from '../../../components/types';
6
+ export declare function isNetworkMessage(message: ReceiveMessage): message is ReceiveNetworkMessage;
7
+ export declare function networkMessageToLocal(message: ReceiveNetworkMessage, localEntityId: Entity, buffer: ByteBuffer, destinationBuffer: ByteBuffer): void;
8
+ export declare function localMessageToNetwork(message: ReceiveMessage, network: INetowrkEntityType, buffer: ByteBuffer, destinationBuffer: ByteBuffer): void;
9
+ export declare function fixTransformParent(message: ReceiveMessage, transformValue?: TransformType, parent?: Entity): Uint8Array;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fixTransformParent = exports.localMessageToNetwork = exports.networkMessageToLocal = exports.isNetworkMessage = void 0;
4
+ const ByteBuffer_1 = require("../../ByteBuffer");
5
+ const putComponent_1 = require("../putComponent");
6
+ const types_1 = require("../types");
7
+ const deleteComponent_1 = require("../deleteComponent");
8
+ const deleteEntity_1 = require("../deleteEntity");
9
+ const putComponentNetwork_1 = require("./putComponentNetwork");
10
+ const deleteComponentNetwork_1 = require("./deleteComponentNetwork");
11
+ const deleteEntityNetwork_1 = require("./deleteEntityNetwork");
12
+ const Transform_1 = require("../../../components/manual/Transform");
13
+ /* istanbul ignore next */
14
+ function isNetworkMessage(message) {
15
+ return [
16
+ types_1.CrdtMessageType.DELETE_COMPONENT_NETWORK,
17
+ types_1.CrdtMessageType.DELETE_ENTITY_NETWORK,
18
+ types_1.CrdtMessageType.PUT_COMPONENT_NETWORK
19
+ ].includes(message.type);
20
+ }
21
+ exports.isNetworkMessage = isNetworkMessage;
22
+ /* istanbul ignore next */
23
+ function networkMessageToLocal(message, localEntityId, buffer, destinationBuffer) {
24
+ const offset = buffer.currentWriteOffset();
25
+ if (message.type === types_1.CrdtMessageType.PUT_COMPONENT_NETWORK) {
26
+ putComponent_1.PutComponentOperation.write(localEntityId, message.timestamp, message.componentId, message.data, buffer);
27
+ }
28
+ else if (message.type === types_1.CrdtMessageType.DELETE_COMPONENT_NETWORK) {
29
+ deleteComponent_1.DeleteComponent.write(localEntityId, message.componentId, message.timestamp, buffer);
30
+ }
31
+ else if (message.type === types_1.CrdtMessageType.DELETE_ENTITY_NETWORK) {
32
+ deleteEntity_1.DeleteEntity.write(localEntityId, buffer);
33
+ }
34
+ destinationBuffer.writeBuffer(buffer.buffer().subarray(offset, buffer.currentWriteOffset()), false);
35
+ }
36
+ exports.networkMessageToLocal = networkMessageToLocal;
37
+ /* istanbul ignore next */
38
+ function localMessageToNetwork(message, network, buffer, destinationBuffer) {
39
+ const offset = buffer.currentWriteOffset();
40
+ if (message.type === types_1.CrdtMessageType.PUT_COMPONENT) {
41
+ putComponentNetwork_1.PutNetworkComponentOperation.write(network.entityId, message.timestamp, message.componentId, network.networkId, message.data, buffer);
42
+ }
43
+ else if (message.type === types_1.CrdtMessageType.DELETE_COMPONENT) {
44
+ deleteComponentNetwork_1.DeleteComponentNetwork.write(network.entityId, message.componentId, message.timestamp, network.networkId, buffer);
45
+ }
46
+ else if (message.type === types_1.CrdtMessageType.DELETE_ENTITY) {
47
+ deleteEntityNetwork_1.DeleteEntityNetwork.write(network.entityId, network.networkId, buffer);
48
+ }
49
+ destinationBuffer.writeBuffer(buffer.buffer().subarray(offset, buffer.currentWriteOffset()), false);
50
+ }
51
+ exports.localMessageToNetwork = localMessageToNetwork;
52
+ const buffer = new ByteBuffer_1.ReadWriteByteBuffer();
53
+ /* istanbul ignore next */
54
+ function fixTransformParent(message, transformValue, parent) {
55
+ buffer.resetBuffer();
56
+ let transform = transformValue;
57
+ if (!transform && 'data' in message) {
58
+ transform = Transform_1.TransformSchema.deserialize(new ByteBuffer_1.ReadWriteByteBuffer(message.data));
59
+ }
60
+ if (!transform)
61
+ throw new Error('Invalid parent transform');
62
+ // Generate new transform raw data with the parent
63
+ const newTransform = { ...transform, parent };
64
+ Transform_1.TransformSchema.serialize(newTransform, buffer);
65
+ return buffer.toBinary();
66
+ }
67
+ exports.fixTransformParent = fixTransformParent;
@@ -11,8 +11,7 @@ export declare enum CrdtMessageType {
11
11
  PUT_COMPONENT_NETWORK = 5,
12
12
  DELETE_COMPONENT_NETWORK = 6,
13
13
  DELETE_ENTITY_NETWORK = 7,
14
- AUTHORITATIVE_PUT_COMPONENT = 8,
15
- MAX_MESSAGE_TYPE = 9
14
+ MAX_MESSAGE_TYPE = 8
16
15
  }
17
16
  /**
18
17
  * Min length = 8 bytes
@@ -49,23 +48,6 @@ export type PutNetworkComponentMessageBody = Omit<PutComponentMessageBody, 'type
49
48
  type: CrdtMessageType.PUT_COMPONENT_NETWORK;
50
49
  networkId: number;
51
50
  };
52
- /**
53
- * Server authoritative message - identical to PutComponentMessageBody but with forced processing
54
- * Min. length = header (8 bytes) + 16 bytes = 24 bytes
55
- *
56
- * @param entity - Uint32 number of the entity
57
- * @param componentId - Uint32 number of id
58
- * @param timestamp - Uint32 Lamport timestamp (server's authoritative timestamp)
59
- * @param data - Uint8[] data of component => length(4 bytes) + block of bytes[0..length-1]
60
- * @public
61
- */
62
- export type AuthoritativePutComponentMessageBody = {
63
- type: CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT;
64
- entityId: Entity;
65
- componentId: number;
66
- timestamp: number;
67
- data: Uint8Array;
68
- };
69
51
  /**
70
52
  * Min. length = header (8 bytes) + 16 bytes = 24 bytes
71
53
  *
@@ -132,10 +114,6 @@ export type AppendValueMessage = CrdtMessageHeader & AppendValueMessageBody;
132
114
  * @public
133
115
  */
134
116
  export type PutComponentMessage = CrdtMessageHeader & PutComponentMessageBody;
135
- /**
136
- * @public
137
- */
138
- export type AuthoritativePutComponentMessage = CrdtMessageHeader & AuthoritativePutComponentMessageBody;
139
117
  /**
140
118
  * @public
141
119
  */
@@ -159,7 +137,7 @@ export type DeleteEntityNetworkMessage = CrdtMessageHeader & DeleteEntityNetwork
159
137
  /**
160
138
  * @public
161
139
  */
162
- export type CrdtMessage = PutComponentMessage | AuthoritativePutComponentMessage | DeleteComponentMessage | AppendValueMessage | DeleteEntityMessage | PutNetworkComponentMessage | DeleteComponentNetworkMessage | DeleteEntityNetworkMessage;
140
+ export type CrdtMessage = PutComponentMessage | DeleteComponentMessage | AppendValueMessage | DeleteEntityMessage | PutNetworkComponentMessage | DeleteComponentNetworkMessage | DeleteEntityNetworkMessage;
163
141
  /**
164
142
  * @public
165
143
  */
@@ -167,7 +145,7 @@ export type CrdtNetworkMessageBody = PutNetworkComponentMessageBody | DeleteComp
167
145
  /**
168
146
  * @public
169
147
  */
170
- export type CrdtMessageBody = PutComponentMessageBody | AuthoritativePutComponentMessageBody | DeleteComponentMessageBody | DeleteEntityMessageBody | AppendValueMessageBody | CrdtNetworkMessageBody;
148
+ export type CrdtMessageBody = PutComponentMessageBody | DeleteComponentMessageBody | DeleteEntityMessageBody | AppendValueMessageBody | CrdtNetworkMessageBody;
171
149
  export declare enum ProcessMessageResultType {
172
150
  /**
173
151
  * Typical message and new state set.
@@ -16,9 +16,7 @@ var CrdtMessageType;
16
16
  CrdtMessageType[CrdtMessageType["PUT_COMPONENT_NETWORK"] = 5] = "PUT_COMPONENT_NETWORK";
17
17
  CrdtMessageType[CrdtMessageType["DELETE_COMPONENT_NETWORK"] = 6] = "DELETE_COMPONENT_NETWORK";
18
18
  CrdtMessageType[CrdtMessageType["DELETE_ENTITY_NETWORK"] = 7] = "DELETE_ENTITY_NETWORK";
19
- // Server authoritative operation - forces component state regardless of timestamp
20
- CrdtMessageType[CrdtMessageType["AUTHORITATIVE_PUT_COMPONENT"] = 8] = "AUTHORITATIVE_PUT_COMPONENT";
21
- CrdtMessageType[CrdtMessageType["MAX_MESSAGE_TYPE"] = 9] = "MAX_MESSAGE_TYPE";
19
+ CrdtMessageType[CrdtMessageType["MAX_MESSAGE_TYPE"] = 8] = "MAX_MESSAGE_TYPE";
22
20
  })(CrdtMessageType = exports.CrdtMessageType || (exports.CrdtMessageType = {}));
23
21
  /**
24
22
  * @public
@@ -1,6 +1,7 @@
1
1
  import { Entity } from '../../engine/entity';
2
2
  import type { ComponentDefinition } from '../../engine';
3
3
  import { CrdtMessageType } from '../../serialization/crdt/types';
4
+ export declare const LIVEKIT_MAX_SIZE = 12;
4
5
  /**
5
6
  * @public
6
7
  */