@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
@@ -0,0 +1,77 @@
1
+ import { Entity } from '../engine';
2
+ import { Vector3Type } from '../schemas';
3
+ import { KnockbackFalloff } from './physics-impulse';
4
+ export { KnockbackFalloff } from './physics-impulse';
5
+ /**
6
+ * @public
7
+ */
8
+ export interface PhysicsSystem {
9
+ /**
10
+ * Apply a one-shot impulse to the player entity.
11
+ * Multiple calls within the same frame are accumulated (summed).
12
+ *
13
+ * @param vector - a single `vector` whose length encodes the strength.
14
+ * or use overload for `direction` with a separate `magnitude` — the direction will be normalized before scaling.
15
+ */
16
+ applyImpulseToPlayer(vector: Vector3Type): void;
17
+ applyImpulseToPlayer(direction: Vector3Type, magnitude: number): void;
18
+ /**
19
+ * Apply a continuous force to the player from a given source entity.
20
+ * Multiple sources are accumulated: the registry sums all active forces
21
+ * and writes a single PBPhysicsCombinedForce component.
22
+ * Calling again with the same source replaces its previous force.
23
+ *
24
+ * @param source - Entity key identifying this force source
25
+ * @param vector - single `vector` whose length encodes the strength
26
+ * or use overload for `direction` with a separate `magnitude` — the direction will be normalized before scaling.
27
+ */
28
+ applyForceToPlayer(source: Entity, vector: Vector3Type): void;
29
+ applyForceToPlayer(source: Entity, direction: Vector3Type, magnitude: number): void;
30
+ /**
31
+ * Remove a continuous force from the player. Remaining sources are
32
+ * re-summed; if none remain the force is cleared. No-op if the source
33
+ * is not registered.
34
+ *
35
+ * @param source - Entity key identifying the force source to remove
36
+ */
37
+ removeForceFromPlayer(source: Entity): void;
38
+ /**
39
+ * Push the player away from a point. Computes direction from
40
+ * `fromPosition` to the player, applies falloff, and delegates
41
+ * to applyImpulseToPlayer.
42
+ *
43
+ * If the player is exactly at `fromPosition`, pushes upward.
44
+ *
45
+ * @param fromPosition - world-space origin of the knockback (explosion center, enemy position, etc.)
46
+ * @param magnitude - base impulse strength
47
+ * @param radius - max distance of effect (default: Infinity)
48
+ * @param falloff - how force decreases with distance (default: CONSTANT)
49
+ */
50
+ applyKnockbackToPlayer(fromPosition: Vector3Type, magnitude: number, radius?: number, falloff?: KnockbackFalloff): void;
51
+ /**
52
+ * Apply a continuous force to the player for a limited duration.
53
+ * After `duration` seconds the force is automatically removed.
54
+ * Calling again with the same source resets the timer.
55
+ *
56
+ * @param source - Entity key identifying this force source
57
+ * @param duration - how long the force lasts, in seconds
58
+ * @param vector - single `vector` whose length encodes the strength
59
+ * or use overload for `direction` with a separate `magnitude` — the direction will be normalized before scaling.
60
+ */
61
+ applyForceToPlayerForDuration(source: Entity, duration: number, vector: Vector3Type): void;
62
+ applyForceToPlayerForDuration(source: Entity, duration: number, direction: Vector3Type, magnitude: number): void;
63
+ /**
64
+ * Apply a continuous repulsion force that pushes the player away from a point,
65
+ * recalculating direction every tick as the player moves.
66
+ * Remove with `removeForceFromPlayer(source)`.
67
+ *
68
+ * Negative magnitude = attraction (pulls toward the source).
69
+ *
70
+ * @param source - Entity key identifying this force source
71
+ * @param fromPosition - world-space origin of repulsion
72
+ * @param magnitude - base force strength
73
+ * @param radius - max distance of effect (default: Infinity)
74
+ * @param falloff - how force decreases with distance (default: CONSTANT)
75
+ */
76
+ applyRepulsionForceToPlayer(source: Entity, fromPosition: Vector3Type, magnitude: number, radius?: number, falloff?: KnockbackFalloff): void;
77
+ }
@@ -0,0 +1,18 @@
1
+ import { createPhysicsImpulseHelper } from './physics-impulse';
2
+ import { createPhysicsForceHelper } from './physics-force';
3
+ export { KnockbackFalloff } from './physics-impulse';
4
+ /**
5
+ * @internal
6
+ */
7
+ export function createPhysicsSystem(engine) {
8
+ const impulse = createPhysicsImpulseHelper(engine);
9
+ const force = createPhysicsForceHelper(engine);
10
+ return {
11
+ applyImpulseToPlayer: impulse.applyImpulseToPlayer,
12
+ applyForceToPlayer: force.applyForceToPlayer,
13
+ removeForceFromPlayer: force.removeForceFromPlayer,
14
+ applyKnockbackToPlayer: impulse.applyKnockbackToPlayer,
15
+ applyForceToPlayerForDuration: force.applyForceToPlayerForDuration,
16
+ applyRepulsionForceToPlayer: force.applyRepulsionForceToPlayer
17
+ };
18
+ }
@@ -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 };
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.MediaState = exports.CreatedBy = exports.NetworkParent = exports.NetworkEntity = exports.SyncComponents = exports.Tags = exports.Name = exports.TriggerArea = exports.LightSource = exports.InputModifier = exports.VirtualCamera = exports.Tween = exports.MeshCollider = exports.MeshRenderer = exports.AudioStream = exports.AudioSource = exports.Animator = exports.Material = exports.Transform = void 0;
20
+ exports.MediaState = exports.NetworkParent = exports.NetworkEntity = exports.SyncComponents = exports.Tags = exports.Name = exports.TriggerArea = exports.LightSource = exports.InputModifier = exports.VirtualCamera = exports.Tween = exports.MeshCollider = exports.MeshRenderer = exports.AudioStream = exports.AudioSource = exports.Animator = exports.Material = exports.Transform = void 0;
21
21
  const Animator_1 = require("./extended/Animator");
22
22
  const AudioSource_1 = require("./extended/AudioSource");
23
23
  const Material_1 = require("./extended/Material");
@@ -37,7 +37,6 @@ const InputModifier_1 = require("./extended/InputModifier");
37
37
  const LightSource_1 = require("./extended/LightSource");
38
38
  const TriggerArea_1 = require("./extended/TriggerArea");
39
39
  const Tags_1 = __importDefault(require("./manual/Tags"));
40
- const CreatedBy_1 = __importDefault(require("./manual/CreatedBy"));
41
40
  __exportStar(require("./generated/index.gen"), exports);
42
41
  /* @__PURE__ */
43
42
  const Transform = (engine) => (0, Transform_1.defineTransformComponent)(engine);
@@ -93,15 +92,12 @@ exports.SyncComponents = SyncComponents;
93
92
  /**
94
93
  * @alpha
95
94
  */
95
+ /* @__PURE__ */
96
96
  const NetworkEntity = (engine) => (0, NetworkEntity_1.default)(engine);
97
97
  exports.NetworkEntity = NetworkEntity;
98
98
  /**
99
99
  * @alpha
100
100
  */
101
+ /* @__PURE__ */
101
102
  const NetworkParent = (engine) => (0, NetworkParent_1.default)(engine);
102
103
  exports.NetworkParent = NetworkParent;
103
- /**
104
- * @public
105
- */
106
- const CreatedBy = (engine) => (0, CreatedBy_1.default)(engine);
107
- exports.CreatedBy = CreatedBy;
@@ -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,13 +1,40 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.defineTransformComponent = exports.TransformSchema = exports.TRANSFORM_LENGTH = exports.COMPONENT_ID = void 0;
27
+ // Use import * to safely handle circular dependency (tree.ts → components → Transform.ts → tree.ts).
28
+ // With import *, the namespace object's properties are resolved at access time (live bindings in ESM,
29
+ // getters via __importStar in CJS), so by the time methods are called all exports are available.
30
+ const treeHelpers = __importStar(require("../../runtime/helpers/tree"));
4
31
  /**
5
- * @public
32
+ * @internal
6
33
  */
7
34
  exports.COMPONENT_ID = 1;
8
- /** @public */
35
+ /** @internal */
9
36
  exports.TRANSFORM_LENGTH = 44;
10
- /** @public */
37
+ /** @internal */
11
38
  exports.TransformSchema = {
12
39
  serialize(value, builder) {
13
40
  const ptr = builder.incrementWriteOffset(exports.TRANSFORM_LENGTH);
@@ -104,6 +131,10 @@ function defineTransformComponent(engine) {
104
131
  },
105
132
  createOrReplace(entity, val) {
106
133
  return transformDef.createOrReplace(entity, exports.TransformSchema.extend(val));
134
+ },
135
+ localToWorldDirection(entity, localDirection) {
136
+ const worldRotation = treeHelpers.getWorldRotation(engine, entity);
137
+ return treeHelpers.rotateVectorByQuaternion(localDirection, worldRotation);
107
138
  }
108
139
  };
109
140
  }
@@ -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
  */
@@ -5,7 +5,6 @@ const ByteBuffer_1 = require("../serialization/ByteBuffer");
5
5
  const crdt_1 = require("../serialization/crdt");
6
6
  const invariant_1 = require("../runtime/invariant");
7
7
  const emptyReadonlySet = freezeSet(new Set());
8
- const __GLOBAL_ENTITY = '__GLOBAL_ENTITY';
9
8
  function frozenError() {
10
9
  throw new Error('The set is frozen');
11
10
  }
@@ -26,7 +25,6 @@ function createValueSetComponentDefinitionFromSchema(componentName, componentId,
26
25
  const dirtyIterator = new Set();
27
26
  const queuedCommands = [];
28
27
  const onChangeCallbacks = new Map();
29
- const validateCallbacks = new Map();
30
28
  // only sort the array if the latest (N) element has a timestamp <= N-1
31
29
  function shouldSort(row) {
32
30
  const len = row.raw.length;
@@ -85,11 +83,8 @@ function createValueSetComponentDefinitionFromSchema(componentName, componentId,
85
83
  has(entity) {
86
84
  return data.has(entity);
87
85
  },
88
- entityDeleted(entity, markAsDirty) {
86
+ entityDeleted(entity) {
89
87
  data.delete(entity);
90
- if (markAsDirty) {
91
- // For grow-only sets, we don't need to mark as dirty since deletion doesn't generate CRDT messages
92
- }
93
88
  },
94
89
  get(entity) {
95
90
  const values = data.get(entity);
@@ -160,44 +155,6 @@ function createValueSetComponentDefinitionFromSchema(componentName, componentId,
160
155
  for (const cb of cbs) {
161
156
  cb(value);
162
157
  }
163
- },
164
- __dry_run_updateFromCrdt(_body) {
165
- return crdt_1.ProcessMessageResultType.StateUpdatedData;
166
- },
167
- validateBeforeChange(entityOrCb, cb) {
168
- if (arguments.length === 1) {
169
- // Second overload: just callback (global validation)
170
- validateCallbacks.set(__GLOBAL_ENTITY, entityOrCb);
171
- }
172
- else {
173
- if (cb) {
174
- validateCallbacks.set(entityOrCb, cb);
175
- }
176
- }
177
- },
178
- __run_validateBeforeChange(entity, newValue, senderAddress, createdBy) {
179
- const cb = entity && validateCallbacks.get(entity);
180
- const globalCb = validateCallbacks.get(__GLOBAL_ENTITY);
181
- const currentValue = [...this.get(entity).values()];
182
- const value = { entity, currentValue: currentValue, newValue, senderAddress, createdBy };
183
- const globalResult = globalCb?.(value) ?? true;
184
- const entityResult = (globalResult && cb?.(value)) ?? true;
185
- return globalResult && entityResult;
186
- },
187
- getCrdtState(entity) {
188
- const row = data.get(entity);
189
- if (!row || row.raw.length === 0) {
190
- return null;
191
- }
192
- // For GrowOnlySet, we need to return the complete CRDT messages for all values
193
- // This is complex because GrowOnlySet uses APPEND messages, not a single PUT
194
- // For now, return null to indicate this component type doesn't support simple corrections
195
- return null;
196
- },
197
- __forceUpdateFromCrdt(_msg) {
198
- // GrowOnlySet doesn't support authoritative corrections in the same way as LWW
199
- // since it uses APPEND_VALUE messages instead of PUT_COMPONENT messages
200
- return [null, undefined];
201
158
  }
202
159
  };
203
160
  return ret;
@@ -1,10 +1,8 @@
1
1
  import { ISchema } from '../schemas';
2
2
  import { ByteBuffer } from '../serialization/ByteBuffer';
3
- import { PutComponentMessageBody, DeleteComponentMessageBody, ProcessMessageResultType, CrdtMessageBody, PutNetworkComponentMessageBody, DeleteComponentNetworkMessageBody, AuthoritativePutComponentMessageBody } from '../serialization/crdt';
3
+ import { PutComponentMessageBody, DeleteComponentMessageBody, CrdtMessageBody } from '../serialization/crdt';
4
4
  import { Entity } from './entity';
5
5
  export declare function incrementTimestamp(entity: Entity, timestamps: Map<Entity, number>): number;
6
6
  export declare function createDumpLwwFunctionFromCrdt(componentId: number, timestamps: Map<Entity, number>, schema: Pick<ISchema<any>, 'serialize' | 'deserialize'>, data: Map<Entity, unknown>): (buffer: ByteBuffer, filterEntity?: ((entity: Entity) => boolean) | undefined) => void;
7
- export declare function createCrdtRuleValidator(timestamps: Map<Entity, number>, schema: Pick<ISchema<any>, 'serialize' | 'deserialize'>, data: Map<Entity, unknown>): (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>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createComponentDefinitionFromSchema = exports.createGetCrdtMessagesForLww = exports.createUpdateLwwFromCrdt = exports.createForceUpdateLwwFromCrdt = exports.createCrdtRuleValidator = exports.createDumpLwwFunctionFromCrdt = exports.incrementTimestamp = void 0;
3
+ exports.createComponentDefinitionFromSchema = exports.createGetCrdtMessagesForLww = exports.createUpdateLwwFromCrdt = exports.createDumpLwwFunctionFromCrdt = exports.incrementTimestamp = void 0;
4
4
  const ByteBuffer_1 = require("../serialization/ByteBuffer");
5
5
  const crdt_1 = require("../serialization/crdt");
6
6
  const utils_1 = require("../systems/crdt/utils");
@@ -35,12 +35,16 @@ function createDumpLwwFunctionFromCrdt(componentId, timestamps, schema, data) {
35
35
  };
36
36
  }
37
37
  exports.createDumpLwwFunctionFromCrdt = createDumpLwwFunctionFromCrdt;
38
- const __GLOBAL_ENTITY = '__GLOBAL_ENTITY';
39
- function createCrdtRuleValidator(timestamps, schema, data) {
38
+ function createUpdateLwwFromCrdt(componentId, timestamps, schema, data) {
40
39
  /**
41
- * Shared CRDT conflict resolution logic
42
- * @public
43
- */
40
+ * Process the received message only if the lamport number recieved is higher
41
+ * than the stored one. If its lower, we spread it to the network to correct the peer.
42
+ * If they are equal, the bigger raw data wins.
43
+
44
+ * Returns the recieved data if the lamport number was bigger than ours.
45
+ * If it was an outdated message, then we return void
46
+ * @public
47
+ */
44
48
  function crdtRuleForCurrentState(message) {
45
49
  const { entityId, timestamp } = message;
46
50
  const currentTimestamp = timestamps.get(entityId);
@@ -50,6 +54,7 @@ function createCrdtRuleValidator(timestamps, schema, data) {
50
54
  }
51
55
  // Outdated Message. Resend our state message through the wire.
52
56
  if (currentTimestamp > timestamp) {
57
+ // console.log('2', currentTimestamp, timestamp)
53
58
  return crdt_1.ProcessMessageResultType.StateOutdatedTimestamp;
54
59
  }
55
60
  // Deletes are idempotent
@@ -66,6 +71,7 @@ function createCrdtRuleValidator(timestamps, schema, data) {
66
71
  currentDataGreater = (0, utils_1.dataCompare)(null, message.data);
67
72
  }
68
73
  // Same data, same timestamp. Weirdo echo message.
74
+ // console.log('3', currentDataGreater, writeBuffer.toBinary(), (message as any).data || null)
69
75
  if (currentDataGreater === 0) {
70
76
  return crdt_1.ProcessMessageResultType.NoChanges;
71
77
  }
@@ -74,37 +80,10 @@ function createCrdtRuleValidator(timestamps, schema, data) {
74
80
  return crdt_1.ProcessMessageResultType.StateOutdatedData;
75
81
  }
76
82
  else {
77
- // Current data is lower
83
+ // Curent data is lower
78
84
  return crdt_1.ProcessMessageResultType.StateUpdatedData;
79
85
  }
80
86
  }
81
- return crdtRuleForCurrentState;
82
- }
83
- exports.createCrdtRuleValidator = createCrdtRuleValidator;
84
- function createForceUpdateLwwFromCrdt(componentId, timestamps, schema, data) {
85
- /**
86
- * Force update component state regardless of timestamp - used for server authoritative messages
87
- */
88
- return (msg) => {
89
- const buffer = new ByteBuffer_1.ReadWriteByteBuffer(msg.data);
90
- const deserializedValue = schema.deserialize(buffer);
91
- data.set(msg.entityId, deserializedValue);
92
- timestamps.set(msg.entityId, msg.timestamp);
93
- return [null, deserializedValue];
94
- };
95
- }
96
- exports.createForceUpdateLwwFromCrdt = createForceUpdateLwwFromCrdt;
97
- function createUpdateLwwFromCrdt(componentId, timestamps, schema, data) {
98
- /**
99
- * Process the received message only if the lamport number recieved is higher
100
- * than the stored one. If its lower, we spread it to the network to correct the peer.
101
- * If they are equal, the bigger raw data wins.
102
-
103
- * Returns the recieved data if the lamport number was bigger than ours.
104
- * If it was an outdated message, then we return void
105
- * @public
106
- */
107
- const crdtRuleForCurrentState = createCrdtRuleValidator(timestamps, schema, data);
108
87
  return (msg) => {
109
88
  /* istanbul ignore next */
110
89
  if (msg.type !== crdt_1.CrdtMessageType.PUT_COMPONENT &&
@@ -199,7 +178,6 @@ function createComponentDefinitionFromSchema(componentName, componentId, schema)
199
178
  const dirtyIterator = new Set();
200
179
  const timestamps = new Map();
201
180
  const onChangeCallbacks = new Map();
202
- const validateCallbacks = new Map();
203
181
  return {
204
182
  get componentId() {
205
183
  return componentId;
@@ -291,39 +269,7 @@ function createComponentDefinitionFromSchema(componentName, componentId, schema)
291
269
  },
292
270
  getCrdtUpdates: createGetCrdtMessagesForLww(componentId, timestamps, dirtyIterator, schema, data),
293
271
  updateFromCrdt: createUpdateLwwFromCrdt(componentId, timestamps, schema, data),
294
- __forceUpdateFromCrdt: createForceUpdateLwwFromCrdt(componentId, timestamps, schema, data),
295
- __dry_run_updateFromCrdt: createCrdtRuleValidator(timestamps, schema, data),
296
272
  dumpCrdtStateToBuffer: createDumpLwwFunctionFromCrdt(componentId, timestamps, schema, data),
297
- validateBeforeChange(entityOrCb, cb) {
298
- if (arguments.length === 1) {
299
- // Second overload: just callback (global validation)
300
- validateCallbacks.set(__GLOBAL_ENTITY, entityOrCb);
301
- }
302
- else {
303
- if (cb) {
304
- validateCallbacks.set(entityOrCb, cb);
305
- }
306
- }
307
- },
308
- __run_validateBeforeChange(entity, newValue, senderAddress, createdBy) {
309
- const cb = entity && validateCallbacks.get(entity);
310
- const globalCb = validateCallbacks.get(__GLOBAL_ENTITY);
311
- const currentValue = data.get(entity);
312
- const value = { entity, currentValue, newValue, senderAddress, createdBy };
313
- const globalResult = globalCb?.(value) ?? true;
314
- const entityResult = (globalResult && cb?.(value)) ?? true;
315
- return globalResult && entityResult;
316
- },
317
- getCrdtState(entity) {
318
- const componentData = data.get(entity);
319
- const timestamp = timestamps.get(entity);
320
- if (componentData && timestamp !== undefined) {
321
- const buffer = new ByteBuffer_1.ReadWriteByteBuffer();
322
- schema.serialize((0, readonly_1.deepReadonly)(componentData), buffer);
323
- return { data: buffer.toBinary(), timestamp };
324
- }
325
- return null;
326
- },
327
273
  onChange(entity, cb) {
328
274
  const cbs = onChangeCallbacks.get(entity) ?? [];
329
275
  cbs.push(cb);
@@ -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-cjs/index.js CHANGED
@@ -26,7 +26,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
26
26
  return result;
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.CreatedBy = exports.NetworkParent = exports.NetworkEntity = exports.SyncComponents = exports.TriggerArea = exports.LightSource = exports.InputModifier = exports.VirtualCamera = exports.Tween = exports.Tags = exports.Name = exports.MeshCollider = exports.MeshRenderer = exports.Material = exports.AudioStream = exports.AudioSource = exports.Animator = exports.Transform = exports.components = exports.cyclicParentingChecker = void 0;
29
+ exports.NetworkParent = exports.NetworkEntity = exports.SyncComponents = exports.TriggerArea = exports.LightSource = exports.InputModifier = exports.VirtualCamera = exports.Tween = exports.Tags = exports.Name = exports.MeshCollider = exports.MeshRenderer = exports.Material = exports.AudioStream = exports.AudioSource = exports.Animator = exports.Transform = exports.components = exports.cyclicParentingChecker = void 0;
30
30
  // The order of the following imports matters. Please do not auto-sort
31
31
  __exportStar(require("./engine"), exports);
32
32
  __exportStar(require("./schemas"), exports);
@@ -43,6 +43,7 @@ __exportStar(require("./systems/assetLoad"), exports);
43
43
  __exportStar(require("./systems/async-task"), exports);
44
44
  __exportStar(require("./systems/tween"), exports);
45
45
  __exportStar(require("./systems/triggerArea"), exports);
46
+ __exportStar(require("./systems/physics"), exports);
46
47
  __exportStar(require("./engine/entity"), exports);
47
48
  __exportStar(require("./components/types"), exports);
48
49
  // @internal
@@ -80,7 +81,6 @@ exports.NetworkEntity = components.NetworkEntity(initialization_1.engine);
80
81
  * Tag a entity to be syncronized through comms
81
82
  */
82
83
  exports.NetworkParent = components.NetworkParent(initialization_1.engine);
83
- exports.CreatedBy = components.CreatedBy(initialization_1.engine);
84
84
  // export components for global engine
85
85
  __exportStar(require("./components/generated/global.gen"), exports);
86
86
  __exportStar(require("./components/generated/types.gen"), exports);
@@ -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';
@@ -17,5 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.createTimers = void 0;
18
18
  __exportStar(require("./coordinates"), exports);
19
19
  __exportStar(require("./tree"), exports);
20
+ __exportStar(require("./vectors"), exports);
20
21
  var timers_1 = require("./timers");
21
22
  Object.defineProperty(exports, "createTimers", { enumerable: true, get: function () { return timers_1.createTimers; } });
@@ -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
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getWorldRotation = exports.getWorldPosition = exports.getEntitiesWithParent = exports.removeEntityWithChildren = exports.getComponentEntityTree = void 0;
26
+ exports.getWorldRotation = exports.getWorldPosition = exports.getEntitiesWithParent = exports.removeEntityWithChildren = exports.getComponentEntityTree = exports.rotateVectorByQuaternion = void 0;
27
27
  const components = __importStar(require("../../components"));
28
28
  /**
29
29
  * @internal
@@ -61,7 +61,7 @@ function multiplyQuaternions(q1, q2) {
61
61
  };
62
62
  }
63
63
  /**
64
- * @internal
64
+ * @public
65
65
  * Rotate a vector by a quaternion
66
66
  * Uses the formula: v' = q * v * q^(-1), optimized version
67
67
  */
@@ -80,6 +80,7 @@ function rotateVectorByQuaternion(v, q) {
80
80
  z: iz * qw + iw * -qz + ix * -qy - iy * -qx
81
81
  };
82
82
  }
83
+ exports.rotateVectorByQuaternion = rotateVectorByQuaternion;
83
84
  /** @internal Identity transform values */
84
85
  const IDENTITY_POSITION = { x: 0, y: 0, z: 0 };
85
86
  const IDENTITY_ROTATION = { x: 0, y: 0, z: 0, w: 1 };
@@ -0,0 +1 @@
1
+ export {};