@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
@@ -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 };
@@ -16,7 +16,6 @@ import { defineInputModifierComponent } from './extended/InputModifier';
16
16
  import { defineLightSourceComponent } from './extended/LightSource';
17
17
  import { defineTriggerAreaComponent } from './extended/TriggerArea';
18
18
  import defineTagsComponent from './manual/Tags';
19
- import defineCreatedBy from './manual/CreatedBy';
20
19
  export * from './generated/index.gen';
21
20
  /* @__PURE__ */
22
21
  export const Transform = (engine) => defineTransformComponent(engine);
@@ -57,13 +56,11 @@ export const SyncComponents = (engine) => defineSyncComponent(engine);
57
56
  /**
58
57
  * @alpha
59
58
  */
59
+ /* @__PURE__ */
60
60
  export const NetworkEntity = (engine) => defineNetworkEntity(engine);
61
61
  /**
62
62
  * @alpha
63
63
  */
64
+ /* @__PURE__ */
64
65
  export const NetworkParent = (engine) => defineNetworkParent(engine);
65
- /**
66
- * @public
67
- */
68
- export const CreatedBy = (engine) => defineCreatedBy(engine);
69
66
  export { MediaState };
@@ -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
  */
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @public
2
+ * @internal
3
3
  */
4
4
  export const COMPONENT_ID = 1;
5
- /** @public */
5
+ /** @internal */
6
6
  export const TRANSFORM_LENGTH = 44;
7
- /** @public */
7
+ /** @internal */
8
8
  export const TransformSchema = {
9
9
  serialize(value, builder) {
10
10
  const ptr = builder.incrementWriteOffset(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
  */
@@ -1,8 +1,7 @@
1
1
  import { ReadWriteByteBuffer } from '../serialization/ByteBuffer';
2
- import { AppendValueOperation, CrdtMessageType, ProcessMessageResultType } from '../serialization/crdt';
2
+ import { AppendValueOperation, CrdtMessageType } from '../serialization/crdt';
3
3
  import { __DEV__ } from '../runtime/invariant';
4
4
  const emptyReadonlySet = freezeSet(new Set());
5
- const __GLOBAL_ENTITY = '__GLOBAL_ENTITY';
6
5
  function frozenError() {
7
6
  throw new Error('The set is frozen');
8
7
  }
@@ -13,7 +12,7 @@ function freezeSet(set) {
13
12
  return set;
14
13
  }
15
14
  function sortByTimestamp(a, b) {
16
- return a.timestamp > b.timestamp ? 1 : -1;
15
+ return a.timestamp - b.timestamp;
17
16
  }
18
17
  /**
19
18
  * @internal
@@ -23,7 +22,6 @@ export function createValueSetComponentDefinitionFromSchema(componentName, compo
23
22
  const dirtyIterator = new Set();
24
23
  const queuedCommands = [];
25
24
  const onChangeCallbacks = new Map();
26
- const validateCallbacks = new Map();
27
25
  // only sort the array if the latest (N) element has a timestamp <= N-1
28
26
  function shouldSort(row) {
29
27
  const len = row.raw.length;
@@ -82,11 +80,8 @@ export function createValueSetComponentDefinitionFromSchema(componentName, compo
82
80
  has(entity) {
83
81
  return data.has(entity);
84
82
  },
85
- entityDeleted(entity, markAsDirty) {
83
+ entityDeleted(entity) {
86
84
  data.delete(entity);
87
- if (markAsDirty) {
88
- // For grow-only sets, we don't need to mark as dirty since deletion doesn't generate CRDT messages
89
- }
90
85
  },
91
86
  get(entity) {
92
87
  const values = data.get(entity);
@@ -157,44 +152,6 @@ export function createValueSetComponentDefinitionFromSchema(componentName, compo
157
152
  for (const cb of cbs) {
158
153
  cb(value);
159
154
  }
160
- },
161
- __dry_run_updateFromCrdt(_body) {
162
- return ProcessMessageResultType.StateUpdatedData;
163
- },
164
- validateBeforeChange(entityOrCb, cb) {
165
- if (arguments.length === 1) {
166
- // Second overload: just callback (global validation)
167
- validateCallbacks.set(__GLOBAL_ENTITY, entityOrCb);
168
- }
169
- else {
170
- if (cb) {
171
- validateCallbacks.set(entityOrCb, cb);
172
- }
173
- }
174
- },
175
- __run_validateBeforeChange(entity, newValue, senderAddress, createdBy) {
176
- const cb = entity && validateCallbacks.get(entity);
177
- const globalCb = validateCallbacks.get(__GLOBAL_ENTITY);
178
- const currentValue = [...this.get(entity).values()];
179
- const value = { entity, currentValue: currentValue, newValue, senderAddress, createdBy };
180
- const globalResult = globalCb?.(value) ?? true;
181
- const entityResult = (globalResult && cb?.(value)) ?? true;
182
- return globalResult && entityResult;
183
- },
184
- getCrdtState(entity) {
185
- const row = data.get(entity);
186
- if (!row || row.raw.length === 0) {
187
- return null;
188
- }
189
- // For GrowOnlySet, we need to return the complete CRDT messages for all values
190
- // This is complex because GrowOnlySet uses APPEND messages, not a single PUT
191
- // For now, return null to indicate this component type doesn't support simple corrections
192
- return null;
193
- },
194
- __forceUpdateFromCrdt(_msg) {
195
- // GrowOnlySet doesn't support authoritative corrections in the same way as LWW
196
- // since it uses APPEND_VALUE messages instead of PUT_COMPONENT messages
197
- return [null, undefined];
198
155
  }
199
156
  };
200
157
  return ret;
@@ -118,8 +118,9 @@ export function createInputSystem(engine) {
118
118
  }
119
119
  if (!up || !down)
120
120
  return null;
121
- // If the DOWN command has happen before the UP commands, it means that that a clicked has happen
122
- if (down.timestamp < up.timestamp && timestampIsCurrentFrame(up.timestamp)) {
121
+ // If the DOWN command has happened before or at the same time as the UP command, a click has happened.
122
+ // Same-timestamp is possible when both events are produced within the same renderer tick.
123
+ if (down.timestamp <= up.timestamp && timestampIsCurrentFrame(up.timestamp)) {
123
124
  return { up, down };
124
125
  }
125
126
  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>;
@@ -30,12 +30,16 @@ export function createDumpLwwFunctionFromCrdt(componentId, timestamps, schema, d
30
30
  }
31
31
  };
32
32
  }
33
- const __GLOBAL_ENTITY = '__GLOBAL_ENTITY';
34
- export function createCrdtRuleValidator(timestamps, schema, data) {
33
+ export function createUpdateLwwFromCrdt(componentId, timestamps, schema, data) {
35
34
  /**
36
- * Shared CRDT conflict resolution logic
37
- * @public
38
- */
35
+ * Process the received message only if the lamport number recieved is higher
36
+ * than the stored one. If its lower, we spread it to the network to correct the peer.
37
+ * If they are equal, the bigger raw data wins.
38
+
39
+ * Returns the recieved data if the lamport number was bigger than ours.
40
+ * If it was an outdated message, then we return void
41
+ * @public
42
+ */
39
43
  function crdtRuleForCurrentState(message) {
40
44
  const { entityId, timestamp } = message;
41
45
  const currentTimestamp = timestamps.get(entityId);
@@ -45,6 +49,7 @@ export function createCrdtRuleValidator(timestamps, schema, data) {
45
49
  }
46
50
  // Outdated Message. Resend our state message through the wire.
47
51
  if (currentTimestamp > timestamp) {
52
+ // console.log('2', currentTimestamp, timestamp)
48
53
  return ProcessMessageResultType.StateOutdatedTimestamp;
49
54
  }
50
55
  // Deletes are idempotent
@@ -61,6 +66,7 @@ export function createCrdtRuleValidator(timestamps, schema, data) {
61
66
  currentDataGreater = dataCompare(null, message.data);
62
67
  }
63
68
  // Same data, same timestamp. Weirdo echo message.
69
+ // console.log('3', currentDataGreater, writeBuffer.toBinary(), (message as any).data || null)
64
70
  if (currentDataGreater === 0) {
65
71
  return ProcessMessageResultType.NoChanges;
66
72
  }
@@ -69,36 +75,10 @@ export function createCrdtRuleValidator(timestamps, schema, data) {
69
75
  return ProcessMessageResultType.StateOutdatedData;
70
76
  }
71
77
  else {
72
- // Current data is lower
78
+ // Curent data is lower
73
79
  return ProcessMessageResultType.StateUpdatedData;
74
80
  }
75
81
  }
76
- return crdtRuleForCurrentState;
77
- }
78
- export function createForceUpdateLwwFromCrdt(componentId, timestamps, schema, data) {
79
- /**
80
- * Force update component state regardless of timestamp - used for server authoritative messages
81
- */
82
- return (msg) => {
83
- console.log('[ BOEDO ] [ CASLA ] ', msg);
84
- const buffer = new ReadWriteByteBuffer(msg.data);
85
- const deserializedValue = schema.deserialize(buffer);
86
- data.set(msg.entityId, deserializedValue);
87
- timestamps.set(msg.entityId, msg.timestamp);
88
- return [null, deserializedValue];
89
- };
90
- }
91
- export function createUpdateLwwFromCrdt(componentId, timestamps, schema, data) {
92
- /**
93
- * Process the received message only if the lamport number recieved is higher
94
- * than the stored one. If its lower, we spread it to the network to correct the peer.
95
- * If they are equal, the bigger raw data wins.
96
-
97
- * Returns the recieved data if the lamport number was bigger than ours.
98
- * If it was an outdated message, then we return void
99
- * @public
100
- */
101
- const crdtRuleForCurrentState = createCrdtRuleValidator(timestamps, schema, data);
102
82
  return (msg) => {
103
83
  /* istanbul ignore next */
104
84
  if (msg.type !== CrdtMessageType.PUT_COMPONENT &&
@@ -191,7 +171,6 @@ export function createComponentDefinitionFromSchema(componentName, componentId,
191
171
  const dirtyIterator = new Set();
192
172
  const timestamps = new Map();
193
173
  const onChangeCallbacks = new Map();
194
- const validateCallbacks = new Map();
195
174
  return {
196
175
  get componentId() {
197
176
  return componentId;
@@ -283,39 +262,7 @@ export function createComponentDefinitionFromSchema(componentName, componentId,
283
262
  },
284
263
  getCrdtUpdates: createGetCrdtMessagesForLww(componentId, timestamps, dirtyIterator, schema, data),
285
264
  updateFromCrdt: createUpdateLwwFromCrdt(componentId, timestamps, schema, data),
286
- __forceUpdateFromCrdt: createForceUpdateLwwFromCrdt(componentId, timestamps, schema, data),
287
- __dry_run_updateFromCrdt: createCrdtRuleValidator(timestamps, schema, data),
288
265
  dumpCrdtStateToBuffer: createDumpLwwFunctionFromCrdt(componentId, timestamps, schema, data),
289
- validateBeforeChange(entityOrCb, cb) {
290
- if (arguments.length === 1) {
291
- // Second overload: just callback (global validation)
292
- validateCallbacks.set(__GLOBAL_ENTITY, entityOrCb);
293
- }
294
- else {
295
- if (cb) {
296
- validateCallbacks.set(entityOrCb, cb);
297
- }
298
- }
299
- },
300
- __run_validateBeforeChange(entity, newValue, senderAddress, createdBy) {
301
- const cb = entity && validateCallbacks.get(entity);
302
- const globalCb = validateCallbacks.get(__GLOBAL_ENTITY);
303
- const currentValue = data.get(entity);
304
- const value = { entity, currentValue, newValue, senderAddress, createdBy };
305
- const globalResult = globalCb?.(value) ?? true;
306
- const entityResult = (globalResult && cb?.(value)) ?? true;
307
- return globalResult && entityResult;
308
- },
309
- getCrdtState(entity) {
310
- const componentData = data.get(entity);
311
- const timestamp = timestamps.get(entity);
312
- if (componentData && timestamp !== undefined) {
313
- const buffer = new ReadWriteByteBuffer();
314
- schema.serialize(deepReadonly(componentData), buffer);
315
- return { data: buffer.toBinary(), timestamp };
316
- }
317
- return null;
318
- },
319
266
  onChange(entity, cb) {
320
267
  const cbs = onChangeCallbacks.get(entity) ?? [];
321
268
  cbs.push(cb);
package/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@ export * from './systems/tween';
13
13
  export * from './systems/triggerArea';
14
14
  export * from './engine/entity';
15
15
  export * from './components/types';
16
- import { MaterialComponentDefinitionExtended, MeshColliderComponentDefinitionExtended, MeshRendererComponentDefinitionExtended, TransformComponentExtended, AnimatorComponentDefinitionExtended, AudioSourceComponentDefinitionExtended, AudioStreamComponentDefinitionExtended, ISyncComponents, TweenComponentDefinitionExtended, INetowrkEntity, INetowrkParent, VirtualCameraComponentDefinitionExtended, InputModifierComponentDefinitionExtended, LightSourceComponentDefinitionExtended, TriggerAreaComponentDefinitionExtended, ICreatedBy } from './components/types';
16
+ import { MaterialComponentDefinitionExtended, MeshColliderComponentDefinitionExtended, MeshRendererComponentDefinitionExtended, TransformComponentExtended, AnimatorComponentDefinitionExtended, AudioSourceComponentDefinitionExtended, AudioStreamComponentDefinitionExtended, ISyncComponents, TweenComponentDefinitionExtended, INetowrkEntity, INetowrkParent, VirtualCameraComponentDefinitionExtended, InputModifierComponentDefinitionExtended, LightSourceComponentDefinitionExtended, TriggerAreaComponentDefinitionExtended } from './components/types';
17
17
  import { NameComponent } from './components/manual/Name';
18
18
  import { TagsComponentDefinitionExtended } from './components/manual/Tags';
19
19
  export declare const Transform: TransformComponentExtended;
@@ -46,7 +46,6 @@ export declare const NetworkEntity: INetowrkEntity;
46
46
  * Tag a entity to be syncronized through comms
47
47
  */
48
48
  export declare const NetworkParent: INetowrkParent;
49
- export declare const CreatedBy: ICreatedBy;
50
49
  export * from './components/generated/global.gen';
51
50
  export * from './components/generated/types.gen';
52
51
  export * from './serialization/crdt';
package/dist/index.js CHANGED
@@ -50,7 +50,6 @@ export const NetworkEntity = /* @__PURE__*/ components.NetworkEntity(engine);
50
50
  * Tag a entity to be syncronized through comms
51
51
  */
52
52
  export const NetworkParent = /* @__PURE__*/ components.NetworkParent(engine);
53
- export const CreatedBy = /* @__PURE__*/ components.CreatedBy(engine);
54
53
  // export components for global engine
55
54
  export * from './components/generated/global.gen';
56
55
  export * from './components/generated/types.gen';
@@ -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';
@@ -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';
@@ -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,60 @@
1
+ import { ReadWriteByteBuffer } from '../../ByteBuffer';
2
+ import { PutComponentOperation } from '../putComponent';
3
+ import { CrdtMessageType } from '../types';
4
+ import { DeleteComponent } from '../deleteComponent';
5
+ import { DeleteEntity } from '../deleteEntity';
6
+ import { PutNetworkComponentOperation } from './putComponentNetwork';
7
+ import { DeleteComponentNetwork } from './deleteComponentNetwork';
8
+ import { DeleteEntityNetwork } from './deleteEntityNetwork';
9
+ import { TransformSchema } from '../../../components/manual/Transform';
10
+ /* istanbul ignore next */
11
+ export function isNetworkMessage(message) {
12
+ return [
13
+ CrdtMessageType.DELETE_COMPONENT_NETWORK,
14
+ CrdtMessageType.DELETE_ENTITY_NETWORK,
15
+ CrdtMessageType.PUT_COMPONENT_NETWORK
16
+ ].includes(message.type);
17
+ }
18
+ /* istanbul ignore next */
19
+ export function networkMessageToLocal(message, localEntityId, buffer, destinationBuffer) {
20
+ const offset = buffer.currentWriteOffset();
21
+ if (message.type === CrdtMessageType.PUT_COMPONENT_NETWORK) {
22
+ PutComponentOperation.write(localEntityId, message.timestamp, message.componentId, message.data, buffer);
23
+ }
24
+ else if (message.type === CrdtMessageType.DELETE_COMPONENT_NETWORK) {
25
+ DeleteComponent.write(localEntityId, message.componentId, message.timestamp, buffer);
26
+ }
27
+ else if (message.type === CrdtMessageType.DELETE_ENTITY_NETWORK) {
28
+ DeleteEntity.write(localEntityId, buffer);
29
+ }
30
+ destinationBuffer.writeBuffer(buffer.buffer().subarray(offset, buffer.currentWriteOffset()), false);
31
+ }
32
+ /* istanbul ignore next */
33
+ export function localMessageToNetwork(message, network, buffer, destinationBuffer) {
34
+ const offset = buffer.currentWriteOffset();
35
+ if (message.type === CrdtMessageType.PUT_COMPONENT) {
36
+ PutNetworkComponentOperation.write(network.entityId, message.timestamp, message.componentId, network.networkId, message.data, buffer);
37
+ }
38
+ else if (message.type === CrdtMessageType.DELETE_COMPONENT) {
39
+ DeleteComponentNetwork.write(network.entityId, message.componentId, message.timestamp, network.networkId, buffer);
40
+ }
41
+ else if (message.type === CrdtMessageType.DELETE_ENTITY) {
42
+ DeleteEntityNetwork.write(network.entityId, network.networkId, buffer);
43
+ }
44
+ destinationBuffer.writeBuffer(buffer.buffer().subarray(offset, buffer.currentWriteOffset()), false);
45
+ }
46
+ const buffer = new ReadWriteByteBuffer();
47
+ /* istanbul ignore next */
48
+ export function fixTransformParent(message, transformValue, parent) {
49
+ buffer.resetBuffer();
50
+ let transform = transformValue;
51
+ if (!transform && 'data' in message) {
52
+ transform = TransformSchema.deserialize(new ReadWriteByteBuffer(message.data));
53
+ }
54
+ if (!transform)
55
+ throw new Error('Invalid parent transform');
56
+ // Generate new transform raw data with the parent
57
+ const newTransform = { ...transform, parent };
58
+ TransformSchema.serialize(newTransform, buffer);
59
+ return buffer.toBinary();
60
+ }
@@ -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.
@@ -13,9 +13,7 @@ export var CrdtMessageType;
13
13
  CrdtMessageType[CrdtMessageType["PUT_COMPONENT_NETWORK"] = 5] = "PUT_COMPONENT_NETWORK";
14
14
  CrdtMessageType[CrdtMessageType["DELETE_COMPONENT_NETWORK"] = 6] = "DELETE_COMPONENT_NETWORK";
15
15
  CrdtMessageType[CrdtMessageType["DELETE_ENTITY_NETWORK"] = 7] = "DELETE_ENTITY_NETWORK";
16
- // Server authoritative operation - forces component state regardless of timestamp
17
- CrdtMessageType[CrdtMessageType["AUTHORITATIVE_PUT_COMPONENT"] = 8] = "AUTHORITATIVE_PUT_COMPONENT";
18
- CrdtMessageType[CrdtMessageType["MAX_MESSAGE_TYPE"] = 9] = "MAX_MESSAGE_TYPE";
16
+ CrdtMessageType[CrdtMessageType["MAX_MESSAGE_TYPE"] = 8] = "MAX_MESSAGE_TYPE";
19
17
  })(CrdtMessageType || (CrdtMessageType = {}));
20
18
  /**
21
19
  * @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
  */