@dcl/ecs 7.21.1-22918726402.commit-ee210ee → 7.21.1-23252789519.commit-9f806e1

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 (75) 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 +13 -9
  4. package/dist/components/manual/Transform.js +11 -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 +2 -2
  11. package/dist/index.js +1 -1
  12. package/dist/runtime/helpers/index.d.ts +1 -0
  13. package/dist/runtime/helpers/index.js +1 -0
  14. package/dist/runtime/helpers/tree.d.ts +6 -0
  15. package/dist/runtime/helpers/tree.js +2 -2
  16. package/dist/runtime/helpers/vectors.d.ts +1 -0
  17. package/dist/runtime/helpers/vectors.js +36 -0
  18. package/dist/runtime/initialization/index.d.ts +7 -0
  19. package/dist/runtime/initialization/index.js +6 -0
  20. package/dist/serialization/crdt/index.d.ts +0 -1
  21. package/dist/serialization/crdt/index.js +0 -1
  22. package/dist/serialization/crdt/network/utils.d.ts +9 -0
  23. package/dist/serialization/crdt/network/utils.js +60 -0
  24. package/dist/serialization/crdt/types.d.ts +3 -25
  25. package/dist/serialization/crdt/types.js +1 -3
  26. package/dist/systems/crdt/index.d.ts +1 -0
  27. package/dist/systems/crdt/index.js +146 -55
  28. package/dist/systems/physics-force.d.ts +1 -0
  29. package/dist/systems/physics-force.js +140 -0
  30. package/dist/systems/physics-impulse.d.ts +12 -0
  31. package/dist/systems/physics-impulse.js +85 -0
  32. package/dist/systems/physics.d.ts +77 -0
  33. package/dist/systems/physics.js +18 -0
  34. package/dist-cjs/components/index.d.ts +0 -5
  35. package/dist-cjs/components/index.js +3 -7
  36. package/dist-cjs/components/manual/Transform.d.ts +13 -9
  37. package/dist-cjs/components/manual/Transform.js +34 -3
  38. package/dist-cjs/components/types.d.ts +0 -1
  39. package/dist-cjs/engine/component.d.ts +1 -52
  40. package/dist-cjs/engine/grow-only-value-set-component-definition.js +1 -44
  41. package/dist-cjs/engine/lww-element-set-component-definition.d.ts +1 -3
  42. package/dist-cjs/engine/lww-element-set-component-definition.js +13 -67
  43. package/dist-cjs/index.d.ts +2 -2
  44. package/dist-cjs/index.js +2 -2
  45. package/dist-cjs/runtime/helpers/index.d.ts +1 -0
  46. package/dist-cjs/runtime/helpers/index.js +1 -0
  47. package/dist-cjs/runtime/helpers/tree.d.ts +6 -0
  48. package/dist-cjs/runtime/helpers/tree.js +3 -2
  49. package/dist-cjs/runtime/helpers/vectors.d.ts +1 -0
  50. package/dist-cjs/runtime/helpers/vectors.js +39 -0
  51. package/dist-cjs/runtime/initialization/index.d.ts +7 -0
  52. package/dist-cjs/runtime/initialization/index.js +7 -1
  53. package/dist-cjs/serialization/crdt/index.d.ts +0 -1
  54. package/dist-cjs/serialization/crdt/index.js +0 -1
  55. package/dist-cjs/serialization/crdt/network/utils.d.ts +9 -0
  56. package/dist-cjs/serialization/crdt/network/utils.js +67 -0
  57. package/dist-cjs/serialization/crdt/types.d.ts +3 -25
  58. package/dist-cjs/serialization/crdt/types.js +1 -3
  59. package/dist-cjs/systems/crdt/index.d.ts +1 -0
  60. package/dist-cjs/systems/crdt/index.js +169 -55
  61. package/dist-cjs/systems/physics-force.d.ts +1 -0
  62. package/dist-cjs/systems/physics-force.js +167 -0
  63. package/dist-cjs/systems/physics-impulse.d.ts +12 -0
  64. package/dist-cjs/systems/physics-impulse.js +112 -0
  65. package/dist-cjs/systems/physics.d.ts +77 -0
  66. package/dist-cjs/systems/physics.js +23 -0
  67. package/package.json +3 -2
  68. package/dist/components/manual/CreatedBy.d.ts +0 -9
  69. package/dist/components/manual/CreatedBy.js +0 -8
  70. package/dist/serialization/crdt/authoritativePutComponent.d.ts +0 -15
  71. package/dist/serialization/crdt/authoritativePutComponent.js +0 -47
  72. package/dist-cjs/components/manual/CreatedBy.d.ts +0 -9
  73. package/dist-cjs/components/manual/CreatedBy.js +0 -10
  74. package/dist-cjs/serialization/crdt/authoritativePutComponent.d.ts +0 -15
  75. 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,6 @@
1
1
  import { LastWriteWinElementSetComponentDefinition, IEngine } from '../../engine';
2
2
  import { Entity } from '../../engine/entity';
3
- import type { ISchema } from '../../schemas/ISchema';
3
+ import type { Vector3Type } from '../../schemas/custom/Vector3';
4
4
  /**
5
5
  * @public
6
6
  */
@@ -11,11 +11,19 @@ export type TransformComponent = LastWriteWinElementSetComponentDefinition<Trans
11
11
  export interface TransformComponentExtended extends TransformComponent {
12
12
  create(entity: Entity, val?: TransformTypeWithOptionals): TransformType;
13
13
  createOrReplace(entity: Entity, val?: TransformTypeWithOptionals): TransformType;
14
+ /**
15
+ * Transforms a direction vector from an entity's local coordinate space
16
+ * to world space, accounting for the full parent hierarchy.
17
+ *
18
+ * This applies only rotation (not translation or scale) — suitable for
19
+ * direction vectors like force/impulse directions.
20
+ *
21
+ * @param entity - The source entity whose local space defines the direction
22
+ * @param localDirection - Direction vector in the entity's local coordinates
23
+ * @returns The direction vector in world coordinates
24
+ */
25
+ localToWorldDirection(entity: Entity, localDirection: Vector3Type): Vector3Type;
14
26
  }
15
- /**
16
- * @public
17
- */
18
- export declare const COMPONENT_ID = 1;
19
27
  /**
20
28
  * @public
21
29
  */
@@ -38,10 +46,6 @@ export type TransformType = {
38
46
  };
39
47
  parent?: Entity;
40
48
  };
41
- /** @public */
42
- export declare const TRANSFORM_LENGTH = 44;
43
- /** @public */
44
- export declare const TransformSchema: ISchema<TransformType>;
45
49
  /**
46
50
  * @public
47
51
  */
@@ -1,10 +1,14 @@
1
+ // Use import * to safely handle circular dependency (tree.ts → components → Transform.ts → tree.ts).
2
+ // With import *, the namespace object's properties are resolved at access time (live bindings in ESM,
3
+ // getters via __importStar in CJS), so by the time methods are called all exports are available.
4
+ import * as treeHelpers from '../../runtime/helpers/tree';
1
5
  /**
2
- * @public
6
+ * @internal
3
7
  */
4
8
  export const COMPONENT_ID = 1;
5
- /** @public */
9
+ /** @internal */
6
10
  export const TRANSFORM_LENGTH = 44;
7
- /** @public */
11
+ /** @internal */
8
12
  export const TransformSchema = {
9
13
  serialize(value, builder) {
10
14
  const ptr = builder.incrementWriteOffset(TRANSFORM_LENGTH);
@@ -101,6 +105,10 @@ export function defineTransformComponent(engine) {
101
105
  },
102
106
  createOrReplace(entity, val) {
103
107
  return transformDef.createOrReplace(entity, TransformSchema.extend(val));
108
+ },
109
+ localToWorldDirection(entity, localDirection) {
110
+ const worldRotation = treeHelpers.getWorldRotation(engine, entity);
111
+ return treeHelpers.rotateVectorByQuaternion(localDirection, worldRotation);
104
112
  }
105
113
  };
106
114
  }
@@ -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
  }
@@ -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;
@@ -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,35 +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
- const buffer = new ReadWriteByteBuffer(msg.data);
84
- const deserializedValue = schema.deserialize(buffer);
85
- data.set(msg.entityId, deserializedValue);
86
- timestamps.set(msg.entityId, msg.timestamp);
87
- return [null, deserializedValue];
88
- };
89
- }
90
- export function createUpdateLwwFromCrdt(componentId, timestamps, schema, data) {
91
- /**
92
- * Process the received message only if the lamport number recieved is higher
93
- * than the stored one. If its lower, we spread it to the network to correct the peer.
94
- * If they are equal, the bigger raw data wins.
95
-
96
- * Returns the recieved data if the lamport number was bigger than ours.
97
- * If it was an outdated message, then we return void
98
- * @public
99
- */
100
- const crdtRuleForCurrentState = createCrdtRuleValidator(timestamps, schema, data);
101
82
  return (msg) => {
102
83
  /* istanbul ignore next */
103
84
  if (msg.type !== CrdtMessageType.PUT_COMPONENT &&
@@ -190,7 +171,6 @@ export function createComponentDefinitionFromSchema(componentName, componentId,
190
171
  const dirtyIterator = new Set();
191
172
  const timestamps = new Map();
192
173
  const onChangeCallbacks = new Map();
193
- const validateCallbacks = new Map();
194
174
  return {
195
175
  get componentId() {
196
176
  return componentId;
@@ -282,39 +262,7 @@ export function createComponentDefinitionFromSchema(componentName, componentId,
282
262
  },
283
263
  getCrdtUpdates: createGetCrdtMessagesForLww(componentId, timestamps, dirtyIterator, schema, data),
284
264
  updateFromCrdt: createUpdateLwwFromCrdt(componentId, timestamps, schema, data),
285
- __forceUpdateFromCrdt: createForceUpdateLwwFromCrdt(componentId, timestamps, schema, data),
286
- __dry_run_updateFromCrdt: createCrdtRuleValidator(timestamps, schema, data),
287
265
  dumpCrdtStateToBuffer: createDumpLwwFunctionFromCrdt(componentId, timestamps, schema, data),
288
- validateBeforeChange(entityOrCb, cb) {
289
- if (arguments.length === 1) {
290
- // Second overload: just callback (global validation)
291
- validateCallbacks.set(__GLOBAL_ENTITY, entityOrCb);
292
- }
293
- else {
294
- if (cb) {
295
- validateCallbacks.set(entityOrCb, cb);
296
- }
297
- }
298
- },
299
- __run_validateBeforeChange(entity, newValue, senderAddress, createdBy) {
300
- const cb = entity && validateCallbacks.get(entity);
301
- const globalCb = validateCallbacks.get(__GLOBAL_ENTITY);
302
- const currentValue = data.get(entity);
303
- const value = { entity, currentValue, newValue, senderAddress, createdBy };
304
- const globalResult = globalCb?.(value) ?? true;
305
- const entityResult = (globalResult && cb?.(value)) ?? true;
306
- return globalResult && entityResult;
307
- },
308
- getCrdtState(entity) {
309
- const componentData = data.get(entity);
310
- const timestamp = timestamps.get(entity);
311
- if (componentData && timestamp !== undefined) {
312
- const buffer = new ReadWriteByteBuffer();
313
- schema.serialize(deepReadonly(componentData), buffer);
314
- return { data: buffer.toBinary(), timestamp };
315
- }
316
- return null;
317
- },
318
266
  onChange(entity, cb) {
319
267
  const cbs = onChangeCallbacks.get(entity) ?? [];
320
268
  cbs.push(cb);
package/dist/index.d.ts CHANGED
@@ -12,9 +12,10 @@ export * from './systems/assetLoad';
12
12
  export * from './systems/async-task';
13
13
  export * from './systems/tween';
14
14
  export * from './systems/triggerArea';
15
+ export * from './systems/physics';
15
16
  export * from './engine/entity';
16
17
  export * from './components/types';
17
- import { MaterialComponentDefinitionExtended, MeshColliderComponentDefinitionExtended, MeshRendererComponentDefinitionExtended, TransformComponentExtended, AnimatorComponentDefinitionExtended, AudioSourceComponentDefinitionExtended, AudioStreamComponentDefinitionExtended, ISyncComponents, TweenComponentDefinitionExtended, INetowrkEntity, INetowrkParent, VirtualCameraComponentDefinitionExtended, InputModifierComponentDefinitionExtended, LightSourceComponentDefinitionExtended, TriggerAreaComponentDefinitionExtended, ICreatedBy } from './components/types';
18
+ import { MaterialComponentDefinitionExtended, MeshColliderComponentDefinitionExtended, MeshRendererComponentDefinitionExtended, TransformComponentExtended, AnimatorComponentDefinitionExtended, AudioSourceComponentDefinitionExtended, AudioStreamComponentDefinitionExtended, ISyncComponents, TweenComponentDefinitionExtended, INetowrkEntity, INetowrkParent, VirtualCameraComponentDefinitionExtended, InputModifierComponentDefinitionExtended, LightSourceComponentDefinitionExtended, TriggerAreaComponentDefinitionExtended } from './components/types';
18
19
  import { NameComponent } from './components/manual/Name';
19
20
  import { TagsComponentDefinitionExtended } from './components/manual/Tags';
20
21
  export declare const Transform: TransformComponentExtended;
@@ -47,7 +48,6 @@ export declare const NetworkEntity: INetowrkEntity;
47
48
  * Tag a entity to be syncronized through comms
48
49
  */
49
50
  export declare const NetworkParent: INetowrkParent;
50
- export declare const CreatedBy: ICreatedBy;
51
51
  export * from './components/generated/global.gen';
52
52
  export * from './components/generated/types.gen';
53
53
  export * from './serialization/crdt';
package/dist/index.js CHANGED
@@ -13,6 +13,7 @@ export * from './systems/assetLoad';
13
13
  export * from './systems/async-task';
14
14
  export * from './systems/tween';
15
15
  export * from './systems/triggerArea';
16
+ export * from './systems/physics';
16
17
  export * from './engine/entity';
17
18
  export * from './components/types';
18
19
  // @internal
@@ -51,7 +52,6 @@ export const NetworkEntity = /* @__PURE__*/ components.NetworkEntity(engine);
51
52
  * Tag a entity to be syncronized through comms
52
53
  */
53
54
  export const NetworkParent = /* @__PURE__*/ components.NetworkParent(engine);
54
- export const CreatedBy = /* @__PURE__*/ components.CreatedBy(engine);
55
55
  // export components for global engine
56
56
  export * from './components/generated/global.gen';
57
57
  export * from './components/generated/types.gen';
@@ -1,3 +1,4 @@
1
1
  export * from './coordinates';
2
2
  export * from './tree';
3
+ export * from './vectors';
3
4
  export { createTimers, Timers, TimerId, TimerCallback } from './timers';
@@ -1,3 +1,4 @@
1
1
  export * from './coordinates';
2
2
  export * from './tree';
3
+ export * from './vectors';
3
4
  export { createTimers } from './timers';
@@ -2,6 +2,12 @@ import { Entity } from '../../engine/entity';
2
2
  import { ComponentDefinition, IEngine } from '../../engine';
3
3
  import { Vector3Type } from '../../schemas/custom/Vector3';
4
4
  import { QuaternionType } from '../../schemas/custom/Quaternion';
5
+ /**
6
+ * @public
7
+ * Rotate a vector by a quaternion
8
+ * Uses the formula: v' = q * v * q^(-1), optimized version
9
+ */
10
+ export declare function rotateVectorByQuaternion(v: Vector3Type, q: QuaternionType): Vector3Type;
5
11
  /**
6
12
  * Get an iterator of entities that follow a tree structure for a component
7
13
  * @public
@@ -35,11 +35,11 @@ function multiplyQuaternions(q1, q2) {
35
35
  };
36
36
  }
37
37
  /**
38
- * @internal
38
+ * @public
39
39
  * Rotate a vector by a quaternion
40
40
  * Uses the formula: v' = q * v * q^(-1), optimized version
41
41
  */
42
- function rotateVectorByQuaternion(v, q) {
42
+ export function rotateVectorByQuaternion(v, q) {
43
43
  // Extract quaternion components
44
44
  const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
45
45
  // Calculate cross product terms (q.xyz × v) * 2
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Lightweight Vector3 math utilities for internal use.
3
+ * Mirrors the subset of @dcl/ecs-math Vector3 API used by the physics helpers.
4
+ *
5
+ * TEMPORARY WORKAROUND: @dcl/ecs-math ships ESM-only, which breaks the dist-cjs build.
6
+ * The proper fix is to add a CJS build to @dcl/ecs-math upstream, then replace this
7
+ * file with `import { Vector3 } from '@dcl/ecs-math'`.
8
+ *
9
+ * @internal
10
+ */
11
+ export const Vector3 = {
12
+ add(a, b) {
13
+ return { x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
14
+ },
15
+ subtract(a, b) {
16
+ return { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
17
+ },
18
+ scale(v, s) {
19
+ return { x: v.x * s, y: v.y * s, z: v.z * s };
20
+ },
21
+ length(v) {
22
+ return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
23
+ },
24
+ normalize(v) {
25
+ const len = Vector3.length(v);
26
+ if (len === 0)
27
+ return { x: 0, y: 0, z: 0 };
28
+ return { x: v.x / len, y: v.y / len, z: v.z / len };
29
+ },
30
+ equals(a, b) {
31
+ return a.x === b.x && a.y === b.y && a.z === b.z;
32
+ },
33
+ equalsToFloats(v, x, y, z) {
34
+ return v.x === x && v.y === y && v.z === z;
35
+ }
36
+ };
@@ -12,6 +12,7 @@ import { AssetLoadLoadingStateSystem } from '../../systems/assetLoad';
12
12
  import { TweenSystem } from '../../systems/tween';
13
13
  import { TriggerAreaEventsSystem } from '../../systems/triggerArea';
14
14
  import { createTimers, Timers } from '../helpers/timers';
15
+ import { PhysicsSystem } from '../../systems/physics';
15
16
  /**
16
17
  * @public
17
18
  * The engine is the part of the scene that sits in the middle and manages all of the other parts.
@@ -77,6 +78,12 @@ export { TriggerAreaEventsSystem };
77
78
  */
78
79
  export declare const timers: Timers;
79
80
  export { Timers, createTimers };
81
+ /**
82
+ * @public
83
+ * Physics helpers for applying impulses and forces to the player.
84
+ */
85
+ export declare const Physics: PhysicsSystem;
86
+ export { PhysicsSystem };
80
87
  /**
81
88
  * @public
82
89
  * Runs an async function
@@ -14,6 +14,7 @@ import { pointerEventColliderChecker } from '../../systems/pointer-event-collide
14
14
  import { createTriggerAreaEventsSystem } from '../../systems/triggerArea';
15
15
  import { createTimers } from '../helpers/timers';
16
16
  import { setGlobalPolyfill } from '../globals';
17
+ import { createPhysicsSystem } from '../../systems/physics';
17
18
  /**
18
19
  * @public
19
20
  * The engine is the part of the scene that sits in the middle and manages all of the other parts.
@@ -77,6 +78,11 @@ setGlobalPolyfill('setTimeout', timers.setTimeout);
77
78
  setGlobalPolyfill('clearTimeout', timers.clearTimeout);
78
79
  setGlobalPolyfill('setInterval', timers.setInterval);
79
80
  setGlobalPolyfill('clearInterval', timers.clearInterval);
81
+ /**
82
+ * @public
83
+ * Physics helpers for applying impulses and forces to the player.
84
+ */
85
+ export const Physics = /* @__PURE__ */ createPhysicsSystem(engine);
80
86
  /**
81
87
  * Adds pointer event collider system only in DEV env
82
88
  */
@@ -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
+ }