@dcl/ecs 7.22.5-24836126953.commit-ddc8da1 → 7.22.5

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 (121) hide show
  1. package/dist/components/extended/ParticleSystem.d.ts +24 -0
  2. package/dist/components/extended/ParticleSystem.js +23 -0
  3. package/dist/components/generated/ParticleSystem.gen.d.ts +1 -0
  4. package/dist/components/generated/ParticleSystem.gen.js +25 -0
  5. package/dist/components/generated/component-names.gen.js +1 -0
  6. package/dist/components/generated/global.gen.d.ts +2 -0
  7. package/dist/components/generated/global.gen.js +1 -0
  8. package/dist/components/generated/index.gen.d.ts +4 -0
  9. package/dist/components/generated/index.gen.js +5 -0
  10. package/dist/components/generated/pb/decentraland/common/colors.gen.d.ts +15 -0
  11. package/dist/components/generated/pb/decentraland/common/colors.gen.js +47 -0
  12. package/dist/components/generated/pb/decentraland/common/floats.gen.d.ts +16 -0
  13. package/dist/components/generated/pb/decentraland/common/floats.gen.js +50 -0
  14. package/dist/components/generated/pb/decentraland/sdk/components/common/input_action.gen.d.ts +10 -1
  15. package/dist/components/generated/pb/decentraland/sdk/components/common/input_action.gen.js +10 -0
  16. package/dist/components/generated/pb/decentraland/sdk/components/particle_system.gen.d.ts +241 -0
  17. package/dist/components/generated/pb/decentraland/sdk/components/particle_system.gen.js +717 -0
  18. package/dist/components/generated/pb/decentraland/sdk/components/pointer_events.gen.d.ts +5 -1
  19. package/dist/components/generated/pb/decentraland/sdk/components/pointer_events.gen.js +20 -1
  20. package/dist/components/generated/types.gen.d.ts +2 -0
  21. package/dist/components/generated/types.gen.js +3 -0
  22. package/dist/components/index.d.ts +2 -5
  23. package/dist/components/index.js +5 -5
  24. package/dist/components/manual/Transform.d.ts +13 -9
  25. package/dist/components/manual/Transform.js +11 -3
  26. package/dist/components/types.d.ts +1 -1
  27. package/dist/engine/component.d.ts +1 -52
  28. package/dist/engine/grow-only-value-set-component-definition.js +2 -45
  29. package/dist/engine/lww-element-set-component-definition.d.ts +3 -5
  30. package/dist/engine/lww-element-set-component-definition.js +35 -70
  31. package/dist/index.d.ts +3 -2
  32. package/dist/index.js +3 -1
  33. package/dist/runtime/helpers/index.d.ts +1 -0
  34. package/dist/runtime/helpers/index.js +1 -0
  35. package/dist/runtime/helpers/tree.d.ts +6 -0
  36. package/dist/runtime/helpers/tree.js +2 -2
  37. package/dist/runtime/helpers/vectors.d.ts +1 -0
  38. package/dist/runtime/helpers/vectors.js +36 -0
  39. package/dist/runtime/initialization/index.d.ts +7 -0
  40. package/dist/runtime/initialization/index.js +6 -0
  41. package/dist/serialization/crdt/index.d.ts +0 -1
  42. package/dist/serialization/crdt/index.js +0 -1
  43. package/dist/serialization/crdt/network/utils.d.ts +9 -0
  44. package/dist/serialization/crdt/network/utils.js +60 -0
  45. package/dist/serialization/crdt/types.d.ts +3 -25
  46. package/dist/serialization/crdt/types.js +1 -3
  47. package/dist/systems/crdt/index.d.ts +1 -0
  48. package/dist/systems/crdt/index.js +146 -55
  49. package/dist/systems/events.d.ts +65 -0
  50. package/dist/systems/events.js +70 -8
  51. package/dist/systems/physics-force.d.ts +1 -0
  52. package/dist/systems/physics-force.js +140 -0
  53. package/dist/systems/physics-impulse.d.ts +12 -0
  54. package/dist/systems/physics-impulse.js +85 -0
  55. package/dist/systems/physics.d.ts +77 -0
  56. package/dist/systems/physics.js +18 -0
  57. package/dist-cjs/components/extended/ParticleSystem.d.ts +24 -0
  58. package/dist-cjs/components/extended/ParticleSystem.js +28 -0
  59. package/dist-cjs/components/generated/ParticleSystem.gen.d.ts +1 -0
  60. package/dist-cjs/components/generated/ParticleSystem.gen.js +28 -0
  61. package/dist-cjs/components/generated/component-names.gen.js +1 -0
  62. package/dist-cjs/components/generated/global.gen.d.ts +2 -0
  63. package/dist-cjs/components/generated/global.gen.js +3 -1
  64. package/dist-cjs/components/generated/index.gen.d.ts +4 -0
  65. package/dist-cjs/components/generated/index.gen.js +8 -2
  66. package/dist-cjs/components/generated/pb/decentraland/common/colors.gen.d.ts +15 -0
  67. package/dist-cjs/components/generated/pb/decentraland/common/colors.gen.js +48 -1
  68. package/dist-cjs/components/generated/pb/decentraland/common/floats.gen.d.ts +16 -0
  69. package/dist-cjs/components/generated/pb/decentraland/common/floats.gen.js +56 -0
  70. package/dist-cjs/components/generated/pb/decentraland/sdk/components/common/input_action.gen.d.ts +10 -1
  71. package/dist-cjs/components/generated/pb/decentraland/sdk/components/common/input_action.gen.js +11 -1
  72. package/dist-cjs/components/generated/pb/decentraland/sdk/components/particle_system.gen.d.ts +241 -0
  73. package/dist-cjs/components/generated/pb/decentraland/sdk/components/particle_system.gen.js +723 -0
  74. package/dist-cjs/components/generated/pb/decentraland/sdk/components/pointer_events.gen.d.ts +5 -1
  75. package/dist-cjs/components/generated/pb/decentraland/sdk/components/pointer_events.gen.js +20 -1
  76. package/dist-cjs/components/generated/types.gen.d.ts +2 -0
  77. package/dist-cjs/components/generated/types.gen.js +5 -0
  78. package/dist-cjs/components/index.d.ts +2 -5
  79. package/dist-cjs/components/index.js +7 -7
  80. package/dist-cjs/components/manual/Transform.d.ts +13 -9
  81. package/dist-cjs/components/manual/Transform.js +34 -3
  82. package/dist-cjs/components/types.d.ts +1 -1
  83. package/dist-cjs/engine/component.d.ts +1 -52
  84. package/dist-cjs/engine/grow-only-value-set-component-definition.js +1 -44
  85. package/dist-cjs/engine/lww-element-set-component-definition.d.ts +3 -5
  86. package/dist-cjs/engine/lww-element-set-component-definition.js +36 -73
  87. package/dist-cjs/index.d.ts +3 -2
  88. package/dist-cjs/index.js +4 -2
  89. package/dist-cjs/runtime/helpers/index.d.ts +1 -0
  90. package/dist-cjs/runtime/helpers/index.js +1 -0
  91. package/dist-cjs/runtime/helpers/tree.d.ts +6 -0
  92. package/dist-cjs/runtime/helpers/tree.js +3 -2
  93. package/dist-cjs/runtime/helpers/vectors.d.ts +1 -0
  94. package/dist-cjs/runtime/helpers/vectors.js +39 -0
  95. package/dist-cjs/runtime/initialization/index.d.ts +7 -0
  96. package/dist-cjs/runtime/initialization/index.js +7 -1
  97. package/dist-cjs/serialization/crdt/index.d.ts +0 -1
  98. package/dist-cjs/serialization/crdt/index.js +0 -1
  99. package/dist-cjs/serialization/crdt/network/utils.d.ts +9 -0
  100. package/dist-cjs/serialization/crdt/network/utils.js +67 -0
  101. package/dist-cjs/serialization/crdt/types.d.ts +3 -25
  102. package/dist-cjs/serialization/crdt/types.js +1 -3
  103. package/dist-cjs/systems/crdt/index.d.ts +1 -0
  104. package/dist-cjs/systems/crdt/index.js +169 -55
  105. package/dist-cjs/systems/events.d.ts +65 -0
  106. package/dist-cjs/systems/events.js +70 -8
  107. package/dist-cjs/systems/physics-force.d.ts +1 -0
  108. package/dist-cjs/systems/physics-force.js +167 -0
  109. package/dist-cjs/systems/physics-impulse.d.ts +12 -0
  110. package/dist-cjs/systems/physics-impulse.js +112 -0
  111. package/dist-cjs/systems/physics.d.ts +77 -0
  112. package/dist-cjs/systems/physics.js +23 -0
  113. package/package.json +3 -2
  114. package/dist/components/manual/CreatedBy.d.ts +0 -9
  115. package/dist/components/manual/CreatedBy.js +0 -8
  116. package/dist/serialization/crdt/authoritativePutComponent.d.ts +0 -15
  117. package/dist/serialization/crdt/authoritativePutComponent.js +0 -47
  118. package/dist-cjs/components/manual/CreatedBy.d.ts +0 -9
  119. package/dist-cjs/components/manual/CreatedBy.js +0 -10
  120. package/dist-cjs/serialization/crdt/authoritativePutComponent.d.ts +0 -15
  121. package/dist-cjs/serialization/crdt/authoritativePutComponent.js +0 -50
@@ -1,5 +1,5 @@
1
1
  import _m0 from "protobufjs/minimal";
2
- import { InputAction, PointerEventType } from "./common/input_action.gen";
2
+ import { InputAction, InteractionType, PointerEventType } from "./common/input_action.gen";
3
3
  /**
4
4
  * PointerEvents adds configurable pointer-based interactions to the attached Entity.
5
5
  *
@@ -61,6 +61,8 @@ export interface PBPointerEvents_Info {
61
61
  showHighlight?: boolean | undefined;
62
62
  /** range of interaction from the avatar's position (default 0) */
63
63
  maxPlayerDistance?: number | undefined;
64
+ /** resolution order when multiple events overlap, higher wins (default 0) */
65
+ priority?: number | undefined;
64
66
  }
65
67
  /**
66
68
  * @public
@@ -70,6 +72,8 @@ export interface PBPointerEvents_Entry {
70
72
  eventType: PointerEventType;
71
73
  /** additional configuration for this detection */
72
74
  eventInfo: PBPointerEvents_Info | undefined;
75
+ /** the type of interaction source (default 0 == CURSOR) */
76
+ interactionType?: InteractionType | undefined;
73
77
  }
74
78
  /**
75
79
  * @public
@@ -47,6 +47,7 @@ function createBasePBPointerEvents_Info() {
47
47
  showFeedback: undefined,
48
48
  showHighlight: undefined,
49
49
  maxPlayerDistance: undefined,
50
+ priority: undefined,
50
51
  };
51
52
  }
52
53
  /**
@@ -73,6 +74,9 @@ export var PBPointerEvents_Info;
73
74
  if (message.maxPlayerDistance !== undefined) {
74
75
  writer.uint32(53).float(message.maxPlayerDistance);
75
76
  }
77
+ if (message.priority !== undefined) {
78
+ writer.uint32(56).uint32(message.priority);
79
+ }
76
80
  return writer;
77
81
  }
78
82
  PBPointerEvents_Info.encode = encode;
@@ -119,6 +123,12 @@ export var PBPointerEvents_Info;
119
123
  }
120
124
  message.maxPlayerDistance = reader.float();
121
125
  continue;
126
+ case 7:
127
+ if (tag !== 56) {
128
+ break;
129
+ }
130
+ message.priority = reader.uint32();
131
+ continue;
122
132
  }
123
133
  if ((tag & 7) === 4 || tag === 0) {
124
134
  break;
@@ -130,7 +140,7 @@ export var PBPointerEvents_Info;
130
140
  PBPointerEvents_Info.decode = decode;
131
141
  })(PBPointerEvents_Info || (PBPointerEvents_Info = {}));
132
142
  function createBasePBPointerEvents_Entry() {
133
- return { eventType: 0, eventInfo: undefined };
143
+ return { eventType: 0, eventInfo: undefined, interactionType: undefined };
134
144
  }
135
145
  /**
136
146
  * @public
@@ -144,6 +154,9 @@ export var PBPointerEvents_Entry;
144
154
  if (message.eventInfo !== undefined) {
145
155
  PBPointerEvents_Info.encode(message.eventInfo, writer.uint32(18).fork()).ldelim();
146
156
  }
157
+ if (message.interactionType !== undefined) {
158
+ writer.uint32(24).int32(message.interactionType);
159
+ }
147
160
  return writer;
148
161
  }
149
162
  PBPointerEvents_Entry.encode = encode;
@@ -166,6 +179,12 @@ export var PBPointerEvents_Entry;
166
179
  }
167
180
  message.eventInfo = PBPointerEvents_Info.decode(reader, reader.uint32());
168
181
  continue;
182
+ case 3:
183
+ if (tag !== 24) {
184
+ break;
185
+ }
186
+ message.interactionType = reader.int32();
187
+ continue;
169
188
  }
170
189
  if ((tag & 7) === 4 || tag === 0) {
171
190
  break;
@@ -1,5 +1,6 @@
1
1
  export type { Position as PBPosition, Vector2 as PBVector2, Vector3 as PBVector3, Quaternion as PBQuaternion } from './pb/decentraland/common/vectors.gen';
2
2
  export type { Color3 as PBColor3, Color4 as PBColor4 } from './pb/decentraland/common/colors.gen';
3
+ export { ColorRange } from './pb/decentraland/common/colors.gen';
3
4
  export * from './pb/decentraland/sdk/components/common/camera_transition.gen';
4
5
  export * from './pb/decentraland/sdk/components/common/camera_type.gen';
5
6
  export * from './pb/decentraland/sdk/components/common/input_action.gen';
@@ -8,4 +9,5 @@ export * from './pb/decentraland/sdk/components/common/media_state.gen';
8
9
  export * from './pb/decentraland/sdk/components/common/raycast_hit.gen';
9
10
  export * from './pb/decentraland/sdk/components/common/texts.gen';
10
11
  export * from './pb/decentraland/common/border_rect.gen';
12
+ export * from './pb/decentraland/common/floats.gen';
11
13
  export * from './pb/decentraland/common/texture.gen';
@@ -1,3 +1,4 @@
1
+ export { ColorRange } from './pb/decentraland/common/colors.gen';
1
2
  export * from './pb/decentraland/sdk/components/common/camera_transition.gen';
2
3
  // export { PbCameraTransition }
3
4
  export * from './pb/decentraland/sdk/components/common/camera_type.gen';
@@ -14,5 +15,7 @@ export * from './pb/decentraland/sdk/components/common/texts.gen';
14
15
  // export { PbTexts }
15
16
  export * from './pb/decentraland/common/border_rect.gen';
16
17
  // export { PbBorderRect }
18
+ export * from './pb/decentraland/common/floats.gen';
19
+ // export { PbFloats }
17
20
  export * from './pb/decentraland/common/texture.gen';
18
21
  // export { PbTexture }
@@ -18,8 +18,8 @@ import { VirtualCameraComponentDefinitionExtended } from './extended/VirtualCame
18
18
  import { InputModifierComponentDefinitionExtended } from './extended/InputModifier';
19
19
  import { LightSourceComponentDefinitionExtended } from './extended/LightSource';
20
20
  import { TriggerAreaComponentDefinitionExtended } from './extended/TriggerArea';
21
+ import { ParticleSystemComponentDefinitionExtended } from './extended/ParticleSystem';
21
22
  import { TagsComponentDefinitionExtended } from './manual/Tags';
22
- import { ICreatedByType } from './manual/CreatedBy';
23
23
  export * from './generated/index.gen';
24
24
  export type { GrowOnlyValueSetComponentDefinition, LastWriteWinElementSetComponentDefinition, LwwComponentGetter, GSetComponentGetter };
25
25
  export declare const Transform: LwwComponentGetter<TransformComponentExtended>;
@@ -34,6 +34,7 @@ export declare const VirtualCamera: LwwComponentGetter<VirtualCameraComponentDef
34
34
  export declare const InputModifier: LwwComponentGetter<InputModifierComponentDefinitionExtended>;
35
35
  export declare const LightSource: LwwComponentGetter<LightSourceComponentDefinitionExtended>;
36
36
  export declare const TriggerArea: LwwComponentGetter<TriggerAreaComponentDefinitionExtended>;
37
+ export declare const ParticleSystem: LwwComponentGetter<ParticleSystemComponentDefinitionExtended>;
37
38
  /**
38
39
  * @alpha
39
40
  */
@@ -51,8 +52,4 @@ export declare const NetworkEntity: (engine: Pick<IEngine, 'defineComponent'>) =
51
52
  * @alpha
52
53
  */
53
54
  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
55
  export { MediaState };
@@ -15,8 +15,8 @@ import { defineVirtualCameraComponent } from './extended/VirtualCamera';
15
15
  import { defineInputModifierComponent } from './extended/InputModifier';
16
16
  import { defineLightSourceComponent } from './extended/LightSource';
17
17
  import { defineTriggerAreaComponent } from './extended/TriggerArea';
18
+ import { defineParticleSystemComponent } from './extended/ParticleSystem';
18
19
  import defineTagsComponent from './manual/Tags';
19
- import defineCreatedBy from './manual/CreatedBy';
20
20
  export * from './generated/index.gen';
21
21
  /* @__PURE__ */
22
22
  export const Transform = (engine) => defineTransformComponent(engine);
@@ -42,6 +42,8 @@ export const InputModifier = (engine) => defineInputModifierComponent(engine);
42
42
  export const LightSource = (engine) => defineLightSourceComponent(engine);
43
43
  /* @__PURE__ */
44
44
  export const TriggerArea = (engine) => defineTriggerAreaComponent(engine);
45
+ /* @__PURE__ */
46
+ export const ParticleSystem = (engine) => defineParticleSystemComponent(engine);
45
47
  /**
46
48
  * @alpha
47
49
  */
@@ -57,13 +59,11 @@ export const SyncComponents = (engine) => defineSyncComponent(engine);
57
59
  /**
58
60
  * @alpha
59
61
  */
62
+ /* @__PURE__ */
60
63
  export const NetworkEntity = (engine) => defineNetworkEntity(engine);
61
64
  /**
62
65
  * @alpha
63
66
  */
67
+ /* @__PURE__ */
64
68
  export const NetworkParent = (engine) => defineNetworkParent(engine);
65
- /**
66
- * @public
67
- */
68
- export const CreatedBy = (engine) => defineCreatedBy(engine);
69
69
  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,7 @@ 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';
18
+ export type { ParticleSystemHelper, ParticleSystemComponentDefinitionExtended, ParticleSystemBlendMode, ParticleSystemPlaybackState } from './extended/ParticleSystem';
@@ -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
- 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
- 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>;
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];
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>;
@@ -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, lastSentData) {
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 &&
@@ -115,9 +96,11 @@ export function createUpdateLwwFromCrdt(componentId, timestamps, schema, data) {
115
96
  if (msg.type === CrdtMessageType.PUT_COMPONENT || msg.type === CrdtMessageType.PUT_COMPONENT_NETWORK) {
116
97
  const buf = new ReadWriteByteBuffer(msg.data);
117
98
  data.set(entity, schema.deserialize(buf));
99
+ lastSentData.set(entity, new Uint8Array(msg.data));
118
100
  }
119
101
  else {
120
102
  data.delete(entity);
103
+ lastSentData.delete(entity);
121
104
  }
122
105
  return [null, data.get(entity)];
123
106
  }
@@ -153,23 +136,34 @@ export function createUpdateLwwFromCrdt(componentId, timestamps, schema, data) {
153
136
  return [null, data.get(entity)];
154
137
  };
155
138
  }
156
- export function createGetCrdtMessagesForLww(componentId, timestamps, dirtyIterator, schema, data) {
139
+ export function createGetCrdtMessagesForLww(componentId, timestamps, dirtyIterator, schema, data, lastSentData) {
157
140
  return function* () {
141
+ const writeBuffer = new ReadWriteByteBuffer();
158
142
  for (const entity of dirtyIterator) {
159
- const newTimestamp = incrementTimestamp(entity, timestamps);
160
143
  if (data.has(entity)) {
161
- const writeBuffer = new ReadWriteByteBuffer();
144
+ writeBuffer.resetBuffer();
162
145
  schema.serialize(data.get(entity), writeBuffer);
146
+ // Compare against last-sent snapshot using the zero-copy subarray view.
147
+ // Only allocate a copy when bytes actually differ.
148
+ const previousBytes = lastSentData.get(entity);
149
+ if (previousBytes && dataCompare(writeBuffer.toBinary(), previousBytes) === 0) {
150
+ continue;
151
+ }
152
+ const currentBytes = writeBuffer.toCopiedBinary();
153
+ const newTimestamp = incrementTimestamp(entity, timestamps);
154
+ lastSentData.set(entity, currentBytes);
163
155
  const msg = {
164
156
  type: CrdtMessageType.PUT_COMPONENT,
165
157
  componentId,
166
158
  entityId: entity,
167
- data: writeBuffer.toBinary(),
159
+ data: currentBytes,
168
160
  timestamp: newTimestamp
169
161
  };
170
162
  yield msg;
171
163
  }
172
164
  else {
165
+ lastSentData.delete(entity);
166
+ const newTimestamp = incrementTimestamp(entity, timestamps);
173
167
  const msg = {
174
168
  type: CrdtMessageType.DELETE_COMPONENT,
175
169
  componentId,
@@ -189,8 +183,8 @@ export function createComponentDefinitionFromSchema(componentName, componentId,
189
183
  const data = new Map();
190
184
  const dirtyIterator = new Set();
191
185
  const timestamps = new Map();
186
+ const lastSentData = new Map();
192
187
  const onChangeCallbacks = new Map();
193
- const validateCallbacks = new Map();
194
188
  return {
195
189
  get componentId() {
196
190
  return componentId;
@@ -211,12 +205,14 @@ export function createComponentDefinitionFromSchema(componentName, componentId,
211
205
  if (data.delete(entity) && markAsDirty) {
212
206
  dirtyIterator.add(entity);
213
207
  }
208
+ lastSentData.delete(entity);
214
209
  return component || null;
215
210
  },
216
211
  entityDeleted(entity, markAsDirty) {
217
212
  if (data.delete(entity) && markAsDirty) {
218
213
  dirtyIterator.add(entity);
219
214
  }
215
+ lastSentData.delete(entity);
220
216
  },
221
217
  getOrNull(entity) {
222
218
  const component = data.get(entity);
@@ -243,6 +239,7 @@ export function createComponentDefinitionFromSchema(componentName, componentId,
243
239
  const usedValue = value === undefined ? schema.create() : schema.extend ? schema.extend(value) : value;
244
240
  data.set(entity, usedValue);
245
241
  dirtyIterator.add(entity);
242
+ lastSentData.delete(entity);
246
243
  return usedValue;
247
244
  },
248
245
  getMutableOrNull(entity) {
@@ -280,41 +277,9 @@ export function createComponentDefinitionFromSchema(componentName, componentId,
280
277
  yield entity;
281
278
  }
282
279
  },
283
- getCrdtUpdates: createGetCrdtMessagesForLww(componentId, timestamps, dirtyIterator, schema, data),
284
- updateFromCrdt: createUpdateLwwFromCrdt(componentId, timestamps, schema, data),
285
- __forceUpdateFromCrdt: createForceUpdateLwwFromCrdt(componentId, timestamps, schema, data),
286
- __dry_run_updateFromCrdt: createCrdtRuleValidator(timestamps, schema, data),
280
+ getCrdtUpdates: createGetCrdtMessagesForLww(componentId, timestamps, dirtyIterator, schema, data, lastSentData),
281
+ updateFromCrdt: createUpdateLwwFromCrdt(componentId, timestamps, schema, data, lastSentData),
287
282
  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
283
  onChange(entity, cb) {
319
284
  const cbs = onChangeCallbacks.get(entity) ?? [];
320
285
  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, ParticleSystemComponentDefinitionExtended } 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;
@@ -31,6 +32,7 @@ export declare const VirtualCamera: VirtualCameraComponentDefinitionExtended;
31
32
  export declare const InputModifier: InputModifierComponentDefinitionExtended;
32
33
  export declare const LightSource: LightSourceComponentDefinitionExtended;
33
34
  export declare const TriggerArea: TriggerAreaComponentDefinitionExtended;
35
+ export declare const ParticleSystem: ParticleSystemComponentDefinitionExtended;
34
36
  /**
35
37
  * @alpha
36
38
  * This is going to be used for sync components through a server.
@@ -47,7 +49,6 @@ export declare const NetworkEntity: INetowrkEntity;
47
49
  * Tag a entity to be syncronized through comms
48
50
  */
49
51
  export declare const NetworkParent: INetowrkParent;
50
- export declare const CreatedBy: ICreatedBy;
51
52
  export * from './components/generated/global.gen';
52
53
  export * from './components/generated/types.gen';
53
54
  export * from './serialization/crdt';