@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
@@ -0,0 +1,167 @@
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
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.createPhysicsForceHelper = void 0;
27
+ const components = __importStar(require("../components"));
28
+ const helpers_1 = require("../runtime/helpers");
29
+ const physics_impulse_1 = require("./physics-impulse");
30
+ /** @internal */
31
+ function createPhysicsForceHelper(engine) {
32
+ const PhysicsCombinedForce = components.PhysicsCombinedForce(engine);
33
+ const Transform = components.Transform(engine);
34
+ const timers = (0, helpers_1.createTimers)(engine);
35
+ const durationTimers = new Map();
36
+ // Key = source entity producing the force (not the target); all forces target PlayerEntity.
37
+ const forceSources = new Map();
38
+ const repulsionSources = new Map();
39
+ let lastWrittenForceVector = null;
40
+ function recalcForce() {
41
+ if (forceSources.size === 0) {
42
+ if (PhysicsCombinedForce.has(engine.PlayerEntity)) {
43
+ PhysicsCombinedForce.deleteFrom(engine.PlayerEntity);
44
+ }
45
+ lastWrittenForceVector = null;
46
+ return;
47
+ }
48
+ const current = PhysicsCombinedForce.getOrNull(engine.PlayerEntity);
49
+ if (current && lastWrittenForceVector && current.vector) {
50
+ if (!helpers_1.Vector3.equals(current.vector, lastWrittenForceVector)) {
51
+ console.error('PBPhysicsCombinedForce was modified externally.', 'Expected:', lastWrittenForceVector, 'Found:', current.vector, '-- overwriting with local state.');
52
+ }
53
+ }
54
+ let sum = { x: 0, y: 0, z: 0 };
55
+ for (const v of forceSources.values()) {
56
+ sum = helpers_1.Vector3.add(sum, v);
57
+ }
58
+ PhysicsCombinedForce.createOrReplace(engine.PlayerEntity, { vector: sum });
59
+ lastWrittenForceVector = sum;
60
+ }
61
+ function applyForceToPlayer(source, vector, magnitude) {
62
+ let finalVector;
63
+ if (helpers_1.Vector3.equalsToFloats(vector, 0, 0, 0))
64
+ return;
65
+ if (typeof magnitude === 'number') {
66
+ finalVector = helpers_1.Vector3.scale(helpers_1.Vector3.normalize(vector), magnitude);
67
+ }
68
+ else {
69
+ finalVector = vector;
70
+ }
71
+ forceSources.set(source, finalVector);
72
+ recalcForce();
73
+ }
74
+ function removeForceFromPlayer(source) {
75
+ repulsionSources.delete(source);
76
+ const timerId = durationTimers.get(source);
77
+ if (timerId !== undefined) {
78
+ timers.clearTimeout(timerId);
79
+ durationTimers.delete(source);
80
+ }
81
+ if (!forceSources.has(source))
82
+ return;
83
+ forceSources.delete(source);
84
+ recalcForce();
85
+ }
86
+ function scheduleForceDuration(source, seconds) {
87
+ const existing = durationTimers.get(source);
88
+ if (existing !== undefined) {
89
+ timers.clearTimeout(existing);
90
+ }
91
+ const timerId = timers.setTimeout(() => {
92
+ durationTimers.delete(source);
93
+ removeForceFromPlayer(source);
94
+ }, seconds * 1000);
95
+ durationTimers.set(source, timerId);
96
+ }
97
+ function applyForceToPlayerForDuration(source, duration, vector, magnitude) {
98
+ applyForceToPlayer(source, vector, magnitude);
99
+ scheduleForceDuration(source, duration);
100
+ }
101
+ function computeRepulsionVector(fromPosition, magnitude, radius, falloff) {
102
+ const diff = helpers_1.Vector3.subtract(Transform.get(engine.PlayerEntity).position, fromPosition);
103
+ if (helpers_1.Vector3.equalsToFloats(diff, 0, 0, 0))
104
+ return { x: 0, y: magnitude, z: 0 };
105
+ // Fast path: default params — no need to compute distance
106
+ if (radius === Infinity && falloff === physics_impulse_1.KnockbackFalloff.CONSTANT) {
107
+ return helpers_1.Vector3.scale(helpers_1.Vector3.normalize(diff), magnitude);
108
+ }
109
+ const distance = helpers_1.Vector3.length(diff);
110
+ if (distance > radius)
111
+ return null;
112
+ let effectiveMagnitude;
113
+ switch (falloff) {
114
+ case physics_impulse_1.KnockbackFalloff.LINEAR:
115
+ effectiveMagnitude = magnitude * (1 - distance / radius);
116
+ break;
117
+ case physics_impulse_1.KnockbackFalloff.INVERSE_SQUARE:
118
+ effectiveMagnitude = magnitude / (distance * distance + 1);
119
+ break;
120
+ case physics_impulse_1.KnockbackFalloff.CONSTANT:
121
+ default:
122
+ effectiveMagnitude = magnitude;
123
+ break;
124
+ }
125
+ if (effectiveMagnitude === 0)
126
+ return null;
127
+ // normalize(diff) * effectiveMagnitude in one step
128
+ return helpers_1.Vector3.scale(diff, effectiveMagnitude / distance);
129
+ }
130
+ function applyRepulsionForceToPlayer(source, fromPosition, magnitude, radius = Infinity, falloff = physics_impulse_1.KnockbackFalloff.CONSTANT) {
131
+ repulsionSources.set(source, { fromPosition, magnitude, radius, falloff });
132
+ const vector = computeRepulsionVector(fromPosition, magnitude, radius, falloff);
133
+ if (vector) {
134
+ forceSources.set(source, vector);
135
+ }
136
+ else {
137
+ forceSources.delete(source);
138
+ }
139
+ recalcForce();
140
+ }
141
+ // Background system: recalculate repulsion vectors and clean up stale forces every tick.
142
+ // Stale forces can appear when CRDT sync from another client writes PhysicsCombinedForce
143
+ // externally (entity-1 ambiguity: each client interprets entity 1 as its own player).
144
+ engine.addSystem(() => {
145
+ // Repulsion forces need per-tick direction recalculation as the player moves
146
+ if (repulsionSources.size > 0) {
147
+ for (const [source, { fromPosition, magnitude, radius, falloff }] of repulsionSources) {
148
+ const vector = computeRepulsionVector(fromPosition, magnitude, radius, falloff);
149
+ if (vector) {
150
+ forceSources.set(source, vector);
151
+ }
152
+ else {
153
+ forceSources.delete(source);
154
+ }
155
+ }
156
+ recalcForce();
157
+ return;
158
+ }
159
+ // No local sources — clean up any externally-created component (e.g. from CRDT sync)
160
+ if (forceSources.size === 0 && PhysicsCombinedForce.has(engine.PlayerEntity)) {
161
+ PhysicsCombinedForce.deleteFrom(engine.PlayerEntity);
162
+ lastWrittenForceVector = null;
163
+ }
164
+ });
165
+ return { applyForceToPlayer, removeForceFromPlayer, applyForceToPlayerForDuration, applyRepulsionForceToPlayer };
166
+ }
167
+ exports.createPhysicsForceHelper = createPhysicsForceHelper;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @public
3
+ * Falloff mode for knockback force over distance.
4
+ */
5
+ export declare enum KnockbackFalloff {
6
+ /** Same force at any distance within radius */
7
+ CONSTANT = 0,
8
+ /** Smooth linear decrease to 0 at radius edge: F = magnitude * (1 - distance / radius) */
9
+ LINEAR = 1,
10
+ /** Sharp drop-off, physically realistic: F = magnitude / (distance^2 + 1) */
11
+ INVERSE_SQUARE = 2
12
+ }
@@ -0,0 +1,112 @@
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
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.createPhysicsImpulseHelper = exports.KnockbackFalloff = void 0;
27
+ const components = __importStar(require("../components"));
28
+ const helpers_1 = require("../runtime/helpers");
29
+ /**
30
+ * @public
31
+ * Falloff mode for knockback force over distance.
32
+ */
33
+ var KnockbackFalloff;
34
+ (function (KnockbackFalloff) {
35
+ /** Same force at any distance within radius */
36
+ KnockbackFalloff[KnockbackFalloff["CONSTANT"] = 0] = "CONSTANT";
37
+ /** Smooth linear decrease to 0 at radius edge: F = magnitude * (1 - distance / radius) */
38
+ KnockbackFalloff[KnockbackFalloff["LINEAR"] = 1] = "LINEAR";
39
+ /** Sharp drop-off, physically realistic: F = magnitude / (distance^2 + 1) */
40
+ KnockbackFalloff[KnockbackFalloff["INVERSE_SQUARE"] = 2] = "INVERSE_SQUARE";
41
+ })(KnockbackFalloff = exports.KnockbackFalloff || (exports.KnockbackFalloff = {}));
42
+ /** @internal */
43
+ function createPhysicsImpulseHelper(engine) {
44
+ const PhysicsCombinedImpulse = components.PhysicsCombinedImpulse(engine);
45
+ const Transform = components.Transform(engine);
46
+ const EngineInfo = components.EngineInfo(engine);
47
+ let impulseEventId = 0;
48
+ let lastWrittenEventId = 0;
49
+ let lastWrittenTick = -1;
50
+ function applyImpulseToPlayer(vector, magnitude) {
51
+ let finalVector;
52
+ if (typeof magnitude === 'number') {
53
+ if (helpers_1.Vector3.equalsToFloats(vector, 0, 0, 0))
54
+ return;
55
+ finalVector = helpers_1.Vector3.scale(helpers_1.Vector3.normalize(vector), magnitude);
56
+ }
57
+ else {
58
+ if (helpers_1.Vector3.equalsToFloats(vector, 0, 0, 0))
59
+ return;
60
+ finalVector = vector;
61
+ }
62
+ const currentTick = EngineInfo.getOrNull(engine.RootEntity)?.tickNumber ?? 0;
63
+ const existing = PhysicsCombinedImpulse.getOrNull(engine.PlayerEntity);
64
+ if (existing && existing.eventId !== lastWrittenEventId && lastWrittenEventId !== 0) {
65
+ throw new Error('PBPhysicsCombinedImpulse was modified outside Physics helper. ' +
66
+ 'Do not mix direct component access with Physics.applyImpulseToPlayer().');
67
+ }
68
+ if (lastWrittenTick === currentTick && existing) {
69
+ finalVector = helpers_1.Vector3.add(existing.vector ?? { x: 0, y: 0, z: 0 }, finalVector);
70
+ }
71
+ else {
72
+ lastWrittenEventId = ++impulseEventId;
73
+ }
74
+ lastWrittenTick = currentTick;
75
+ PhysicsCombinedImpulse.createOrReplace(engine.PlayerEntity, {
76
+ vector: finalVector,
77
+ eventId: lastWrittenEventId
78
+ });
79
+ }
80
+ function applyKnockbackToPlayer(fromPosition, magnitude, radius = Infinity, falloff = KnockbackFalloff.CONSTANT) {
81
+ const diff = helpers_1.Vector3.subtract(Transform.get(engine.PlayerEntity).position, fromPosition);
82
+ if (helpers_1.Vector3.equalsToFloats(diff, 0, 0, 0)) {
83
+ applyImpulseToPlayer({ x: 0, y: magnitude, z: 0 });
84
+ return;
85
+ }
86
+ // Fast path: default params — no need to compute distance
87
+ if (radius === Infinity && falloff === KnockbackFalloff.CONSTANT) {
88
+ applyImpulseToPlayer(helpers_1.Vector3.scale(helpers_1.Vector3.normalize(diff), magnitude));
89
+ return;
90
+ }
91
+ const distance = helpers_1.Vector3.length(diff);
92
+ if (distance > radius)
93
+ return;
94
+ let effectiveMagnitude;
95
+ switch (falloff) {
96
+ case KnockbackFalloff.LINEAR:
97
+ effectiveMagnitude = magnitude * (1 - distance / radius);
98
+ break;
99
+ case KnockbackFalloff.INVERSE_SQUARE:
100
+ effectiveMagnitude = magnitude / (distance * distance + 1);
101
+ break;
102
+ case KnockbackFalloff.CONSTANT:
103
+ default:
104
+ effectiveMagnitude = magnitude;
105
+ break;
106
+ }
107
+ // normalize(diff) * effectiveMagnitude in one step
108
+ applyImpulseToPlayer(helpers_1.Vector3.scale(diff, effectiveMagnitude / distance));
109
+ }
110
+ return { applyImpulseToPlayer, applyKnockbackToPlayer };
111
+ }
112
+ exports.createPhysicsImpulseHelper = createPhysicsImpulseHelper;
@@ -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,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPhysicsSystem = exports.KnockbackFalloff = void 0;
4
+ const physics_impulse_1 = require("./physics-impulse");
5
+ const physics_force_1 = require("./physics-force");
6
+ var physics_impulse_2 = require("./physics-impulse");
7
+ Object.defineProperty(exports, "KnockbackFalloff", { enumerable: true, get: function () { return physics_impulse_2.KnockbackFalloff; } });
8
+ /**
9
+ * @internal
10
+ */
11
+ function createPhysicsSystem(engine) {
12
+ const impulse = (0, physics_impulse_1.createPhysicsImpulseHelper)(engine);
13
+ const force = (0, physics_force_1.createPhysicsForceHelper)(engine);
14
+ return {
15
+ applyImpulseToPlayer: impulse.applyImpulseToPlayer,
16
+ applyForceToPlayer: force.applyForceToPlayer,
17
+ removeForceFromPlayer: force.removeForceFromPlayer,
18
+ applyKnockbackToPlayer: impulse.applyKnockbackToPlayer,
19
+ applyForceToPlayerForDuration: force.applyForceToPlayerForDuration,
20
+ applyRepulsionForceToPlayer: force.applyRepulsionForceToPlayer
21
+ };
22
+ }
23
+ exports.createPhysicsSystem = createPhysicsSystem;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dcl/ecs",
3
3
  "description": "Decentraland ECS",
4
- "version": "7.22.5-24836126953.commit-ddc8da1",
4
+ "version": "7.22.5",
5
5
  "author": "DCL",
6
6
  "bugs": "https://github.com/decentraland/ecs/issues",
7
7
  "files": [
@@ -31,7 +31,8 @@
31
31
  "displayName": "ECS",
32
32
  "tsconfig": "./tsconfig.json"
33
33
  },
34
+ "dependencies": {},
34
35
  "types": "./dist/index.d.ts",
35
36
  "typings": "./dist/index.d.ts",
36
- "commit": "ddc8da1f80f3b488609d8a2a694f0c9fd5fe2c54"
37
+ "commit": "b6da827dbab8b88795119b50ab578d457e552d0c"
37
38
  }
@@ -1,9 +0,0 @@
1
- import { IEngine, LastWriteWinElementSetComponentDefinition } from '../../engine/types';
2
- export interface ICreatedByType {
3
- address: string;
4
- }
5
- export type ICreatedBy = LastWriteWinElementSetComponentDefinition<ICreatedByType>;
6
- declare function defineCreatedBy(engine: Pick<IEngine, 'defineComponent'>): import("../../engine/types").MapComponentDefinition<import("../..").MapResult<{
7
- address: import("../../schemas").ISchema<string>;
8
- }>>;
9
- export default defineCreatedBy;
@@ -1,8 +0,0 @@
1
- import { Schemas } from '../../schemas';
2
- function defineCreatedBy(engine) {
3
- const CreatedBy = engine.defineComponent('core-schema::Created-By', {
4
- address: Schemas.String
5
- });
6
- return CreatedBy;
7
- }
8
- export default defineCreatedBy;
@@ -1,15 +0,0 @@
1
- import { Entity } from '../../engine/entity';
2
- import { ByteBuffer } from '../ByteBuffer';
3
- import { AuthoritativePutComponentMessage } from './types';
4
- /**
5
- * @public
6
- */
7
- export declare namespace AuthoritativePutComponentOperation {
8
- const MESSAGE_HEADER_LENGTH = 16;
9
- /**
10
- * Call this function for an optimal writing data passing the ByteBuffer
11
- * already allocated
12
- */
13
- function write(entity: Entity, timestamp: number, componentId: number, data: Uint8Array, buf: ByteBuffer): void;
14
- function read(buf: ByteBuffer): AuthoritativePutComponentMessage | null;
15
- }
@@ -1,47 +0,0 @@
1
- import { CrdtMessageProtocol } from './crdtMessageProtocol';
2
- import { CrdtMessageType, CRDT_MESSAGE_HEADER_LENGTH } from './types';
3
- /**
4
- * @public
5
- */
6
- export var AuthoritativePutComponentOperation;
7
- (function (AuthoritativePutComponentOperation) {
8
- AuthoritativePutComponentOperation.MESSAGE_HEADER_LENGTH = 16;
9
- /**
10
- * Call this function for an optimal writing data passing the ByteBuffer
11
- * already allocated
12
- */
13
- function write(entity, timestamp, componentId, data, buf) {
14
- // reserve the beginning
15
- const startMessageOffset = buf.incrementWriteOffset(CRDT_MESSAGE_HEADER_LENGTH + AuthoritativePutComponentOperation.MESSAGE_HEADER_LENGTH);
16
- // write body
17
- buf.writeBuffer(data, false);
18
- const messageLength = buf.currentWriteOffset() - startMessageOffset;
19
- // Write CrdtMessage header
20
- buf.setUint32(startMessageOffset, messageLength);
21
- buf.setUint32(startMessageOffset + 4, CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT);
22
- // Write ComponentOperation header
23
- buf.setUint32(startMessageOffset + 8, entity);
24
- buf.setUint32(startMessageOffset + 12, componentId);
25
- buf.setUint32(startMessageOffset + 16, timestamp);
26
- const newLocal = messageLength - AuthoritativePutComponentOperation.MESSAGE_HEADER_LENGTH - CRDT_MESSAGE_HEADER_LENGTH;
27
- buf.setUint32(startMessageOffset + 20, newLocal);
28
- }
29
- AuthoritativePutComponentOperation.write = write;
30
- function read(buf) {
31
- const header = CrdtMessageProtocol.readHeader(buf);
32
- if (!header) {
33
- return null;
34
- }
35
- if (header.type !== CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT) {
36
- throw new Error('AuthoritativePutComponentOperation tried to read another message type.');
37
- }
38
- return {
39
- ...header,
40
- entityId: buf.readUint32(),
41
- componentId: buf.readUint32(),
42
- timestamp: buf.readUint32(),
43
- data: buf.readBuffer()
44
- };
45
- }
46
- AuthoritativePutComponentOperation.read = read;
47
- })(AuthoritativePutComponentOperation || (AuthoritativePutComponentOperation = {}));
@@ -1,9 +0,0 @@
1
- import { IEngine, LastWriteWinElementSetComponentDefinition } from '../../engine/types';
2
- export interface ICreatedByType {
3
- address: string;
4
- }
5
- export type ICreatedBy = LastWriteWinElementSetComponentDefinition<ICreatedByType>;
6
- declare function defineCreatedBy(engine: Pick<IEngine, 'defineComponent'>): import("../../engine/types").MapComponentDefinition<import("../..").MapResult<{
7
- address: import("../../schemas").ISchema<string>;
8
- }>>;
9
- export default defineCreatedBy;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const schemas_1 = require("../../schemas");
4
- function defineCreatedBy(engine) {
5
- const CreatedBy = engine.defineComponent('core-schema::Created-By', {
6
- address: schemas_1.Schemas.String
7
- });
8
- return CreatedBy;
9
- }
10
- exports.default = defineCreatedBy;
@@ -1,15 +0,0 @@
1
- import { Entity } from '../../engine/entity';
2
- import { ByteBuffer } from '../ByteBuffer';
3
- import { AuthoritativePutComponentMessage } from './types';
4
- /**
5
- * @public
6
- */
7
- export declare namespace AuthoritativePutComponentOperation {
8
- const MESSAGE_HEADER_LENGTH = 16;
9
- /**
10
- * Call this function for an optimal writing data passing the ByteBuffer
11
- * already allocated
12
- */
13
- function write(entity: Entity, timestamp: number, componentId: number, data: Uint8Array, buf: ByteBuffer): void;
14
- function read(buf: ByteBuffer): AuthoritativePutComponentMessage | null;
15
- }
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AuthoritativePutComponentOperation = void 0;
4
- const crdtMessageProtocol_1 = require("./crdtMessageProtocol");
5
- const types_1 = require("./types");
6
- /**
7
- * @public
8
- */
9
- var AuthoritativePutComponentOperation;
10
- (function (AuthoritativePutComponentOperation) {
11
- AuthoritativePutComponentOperation.MESSAGE_HEADER_LENGTH = 16;
12
- /**
13
- * Call this function for an optimal writing data passing the ByteBuffer
14
- * already allocated
15
- */
16
- function write(entity, timestamp, componentId, data, buf) {
17
- // reserve the beginning
18
- const startMessageOffset = buf.incrementWriteOffset(types_1.CRDT_MESSAGE_HEADER_LENGTH + AuthoritativePutComponentOperation.MESSAGE_HEADER_LENGTH);
19
- // write body
20
- buf.writeBuffer(data, false);
21
- const messageLength = buf.currentWriteOffset() - startMessageOffset;
22
- // Write CrdtMessage header
23
- buf.setUint32(startMessageOffset, messageLength);
24
- buf.setUint32(startMessageOffset + 4, types_1.CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT);
25
- // Write ComponentOperation header
26
- buf.setUint32(startMessageOffset + 8, entity);
27
- buf.setUint32(startMessageOffset + 12, componentId);
28
- buf.setUint32(startMessageOffset + 16, timestamp);
29
- const newLocal = messageLength - AuthoritativePutComponentOperation.MESSAGE_HEADER_LENGTH - types_1.CRDT_MESSAGE_HEADER_LENGTH;
30
- buf.setUint32(startMessageOffset + 20, newLocal);
31
- }
32
- AuthoritativePutComponentOperation.write = write;
33
- function read(buf) {
34
- const header = crdtMessageProtocol_1.CrdtMessageProtocol.readHeader(buf);
35
- if (!header) {
36
- return null;
37
- }
38
- if (header.type !== types_1.CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT) {
39
- throw new Error('AuthoritativePutComponentOperation tried to read another message type.');
40
- }
41
- return {
42
- ...header,
43
- entityId: buf.readUint32(),
44
- componentId: buf.readUint32(),
45
- timestamp: buf.readUint32(),
46
- data: buf.readBuffer()
47
- };
48
- }
49
- AuthoritativePutComponentOperation.read = read;
50
- })(AuthoritativePutComponentOperation = exports.AuthoritativePutComponentOperation || (exports.AuthoritativePutComponentOperation = {}));