@dcl/ecs 7.22.4 → 7.22.5-24779418349.commit-111fd7e

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/generated/component-names.gen.js +0 -1
  2. package/dist/components/generated/global.gen.d.ts +0 -2
  3. package/dist/components/generated/global.gen.js +0 -1
  4. package/dist/components/generated/index.gen.d.ts +0 -4
  5. package/dist/components/generated/index.gen.js +0 -5
  6. package/dist/components/generated/pb/decentraland/common/colors.gen.d.ts +0 -15
  7. package/dist/components/generated/pb/decentraland/common/colors.gen.js +0 -47
  8. package/dist/components/generated/pb/decentraland/sdk/components/common/input_action.gen.d.ts +1 -10
  9. package/dist/components/generated/pb/decentraland/sdk/components/common/input_action.gen.js +0 -10
  10. package/dist/components/generated/pb/decentraland/sdk/components/pointer_events.gen.d.ts +1 -5
  11. package/dist/components/generated/pb/decentraland/sdk/components/pointer_events.gen.js +1 -20
  12. package/dist/components/generated/types.gen.d.ts +0 -2
  13. package/dist/components/generated/types.gen.js +0 -3
  14. package/dist/components/index.d.ts +5 -2
  15. package/dist/components/index.js +5 -5
  16. package/dist/components/manual/CreatedBy.d.ts +9 -0
  17. package/dist/components/manual/CreatedBy.js +8 -0
  18. package/dist/components/manual/Transform.d.ts +9 -13
  19. package/dist/components/manual/Transform.js +3 -11
  20. package/dist/components/types.d.ts +1 -1
  21. package/dist/engine/component.d.ts +52 -1
  22. package/dist/engine/grow-only-value-set-component-definition.js +45 -2
  23. package/dist/engine/lww-element-set-component-definition.d.ts +5 -3
  24. package/dist/engine/lww-element-set-component-definition.js +70 -35
  25. package/dist/index.d.ts +2 -3
  26. package/dist/index.js +1 -3
  27. package/dist/runtime/helpers/index.d.ts +0 -1
  28. package/dist/runtime/helpers/index.js +0 -1
  29. package/dist/runtime/helpers/tree.d.ts +0 -6
  30. package/dist/runtime/helpers/tree.js +2 -2
  31. package/dist/runtime/initialization/index.d.ts +0 -7
  32. package/dist/runtime/initialization/index.js +0 -6
  33. package/dist/serialization/crdt/authoritativePutComponent.d.ts +15 -0
  34. package/dist/serialization/crdt/authoritativePutComponent.js +47 -0
  35. package/dist/serialization/crdt/index.d.ts +1 -0
  36. package/dist/serialization/crdt/index.js +1 -0
  37. package/dist/serialization/crdt/types.d.ts +25 -3
  38. package/dist/serialization/crdt/types.js +3 -1
  39. package/dist/systems/crdt/index.d.ts +0 -1
  40. package/dist/systems/crdt/index.js +55 -146
  41. package/dist/systems/events.d.ts +0 -65
  42. package/dist/systems/events.js +8 -70
  43. package/dist-cjs/components/generated/component-names.gen.js +0 -1
  44. package/dist-cjs/components/generated/global.gen.d.ts +0 -2
  45. package/dist-cjs/components/generated/global.gen.js +1 -3
  46. package/dist-cjs/components/generated/index.gen.d.ts +0 -4
  47. package/dist-cjs/components/generated/index.gen.js +2 -8
  48. package/dist-cjs/components/generated/pb/decentraland/common/colors.gen.d.ts +0 -15
  49. package/dist-cjs/components/generated/pb/decentraland/common/colors.gen.js +1 -48
  50. package/dist-cjs/components/generated/pb/decentraland/sdk/components/common/input_action.gen.d.ts +1 -10
  51. package/dist-cjs/components/generated/pb/decentraland/sdk/components/common/input_action.gen.js +1 -11
  52. package/dist-cjs/components/generated/pb/decentraland/sdk/components/pointer_events.gen.d.ts +1 -5
  53. package/dist-cjs/components/generated/pb/decentraland/sdk/components/pointer_events.gen.js +1 -20
  54. package/dist-cjs/components/generated/types.gen.d.ts +0 -2
  55. package/dist-cjs/components/generated/types.gen.js +0 -5
  56. package/dist-cjs/components/index.d.ts +5 -2
  57. package/dist-cjs/components/index.js +7 -7
  58. package/dist-cjs/components/manual/CreatedBy.d.ts +9 -0
  59. package/dist-cjs/components/manual/CreatedBy.js +10 -0
  60. package/dist-cjs/components/manual/Transform.d.ts +9 -13
  61. package/dist-cjs/components/manual/Transform.js +3 -34
  62. package/dist-cjs/components/types.d.ts +1 -1
  63. package/dist-cjs/engine/component.d.ts +52 -1
  64. package/dist-cjs/engine/grow-only-value-set-component-definition.js +44 -1
  65. package/dist-cjs/engine/lww-element-set-component-definition.d.ts +5 -3
  66. package/dist-cjs/engine/lww-element-set-component-definition.js +73 -36
  67. package/dist-cjs/index.d.ts +2 -3
  68. package/dist-cjs/index.js +2 -4
  69. package/dist-cjs/runtime/helpers/index.d.ts +0 -1
  70. package/dist-cjs/runtime/helpers/index.js +0 -1
  71. package/dist-cjs/runtime/helpers/tree.d.ts +0 -6
  72. package/dist-cjs/runtime/helpers/tree.js +2 -3
  73. package/dist-cjs/runtime/initialization/index.d.ts +0 -7
  74. package/dist-cjs/runtime/initialization/index.js +1 -7
  75. package/dist-cjs/serialization/crdt/authoritativePutComponent.d.ts +15 -0
  76. package/dist-cjs/serialization/crdt/authoritativePutComponent.js +50 -0
  77. package/dist-cjs/serialization/crdt/index.d.ts +1 -0
  78. package/dist-cjs/serialization/crdt/index.js +1 -0
  79. package/dist-cjs/serialization/crdt/types.d.ts +25 -3
  80. package/dist-cjs/serialization/crdt/types.js +3 -1
  81. package/dist-cjs/systems/crdt/index.d.ts +0 -1
  82. package/dist-cjs/systems/crdt/index.js +55 -169
  83. package/dist-cjs/systems/events.d.ts +0 -65
  84. package/dist-cjs/systems/events.js +8 -70
  85. package/package.json +2 -3
  86. package/dist/components/extended/ParticleSystem.d.ts +0 -24
  87. package/dist/components/extended/ParticleSystem.js +0 -23
  88. package/dist/components/generated/ParticleSystem.gen.d.ts +0 -1
  89. package/dist/components/generated/ParticleSystem.gen.js +0 -25
  90. package/dist/components/generated/pb/decentraland/common/floats.gen.d.ts +0 -16
  91. package/dist/components/generated/pb/decentraland/common/floats.gen.js +0 -50
  92. package/dist/components/generated/pb/decentraland/sdk/components/particle_system.gen.d.ts +0 -241
  93. package/dist/components/generated/pb/decentraland/sdk/components/particle_system.gen.js +0 -717
  94. package/dist/runtime/helpers/vectors.d.ts +0 -1
  95. package/dist/runtime/helpers/vectors.js +0 -36
  96. package/dist/serialization/crdt/network/utils.d.ts +0 -9
  97. package/dist/serialization/crdt/network/utils.js +0 -60
  98. package/dist/systems/physics-force.d.ts +0 -1
  99. package/dist/systems/physics-force.js +0 -140
  100. package/dist/systems/physics-impulse.d.ts +0 -12
  101. package/dist/systems/physics-impulse.js +0 -85
  102. package/dist/systems/physics.d.ts +0 -77
  103. package/dist/systems/physics.js +0 -18
  104. package/dist-cjs/components/extended/ParticleSystem.d.ts +0 -24
  105. package/dist-cjs/components/extended/ParticleSystem.js +0 -28
  106. package/dist-cjs/components/generated/ParticleSystem.gen.d.ts +0 -1
  107. package/dist-cjs/components/generated/ParticleSystem.gen.js +0 -28
  108. package/dist-cjs/components/generated/pb/decentraland/common/floats.gen.d.ts +0 -16
  109. package/dist-cjs/components/generated/pb/decentraland/common/floats.gen.js +0 -56
  110. package/dist-cjs/components/generated/pb/decentraland/sdk/components/particle_system.gen.d.ts +0 -241
  111. package/dist-cjs/components/generated/pb/decentraland/sdk/components/particle_system.gen.js +0 -723
  112. package/dist-cjs/runtime/helpers/vectors.d.ts +0 -1
  113. package/dist-cjs/runtime/helpers/vectors.js +0 -39
  114. package/dist-cjs/serialization/crdt/network/utils.d.ts +0 -9
  115. package/dist-cjs/serialization/crdt/network/utils.js +0 -67
  116. package/dist-cjs/systems/physics-force.d.ts +0 -1
  117. package/dist-cjs/systems/physics-force.js +0 -167
  118. package/dist-cjs/systems/physics-impulse.d.ts +0 -12
  119. package/dist-cjs/systems/physics-impulse.js +0 -112
  120. package/dist-cjs/systems/physics.d.ts +0 -77
  121. package/dist-cjs/systems/physics.js +0 -23
@@ -1 +0,0 @@
1
- export {};
@@ -1,36 +0,0 @@
1
- /**
2
- * Lightweight Vector3 math utilities for internal use.
3
- * Mirrors the subset of @dcl/ecs-math Vector3 API used by the physics helpers.
4
- *
5
- * TEMPORARY WORKAROUND: @dcl/ecs-math ships ESM-only, which breaks the dist-cjs build.
6
- * The proper fix is to add a CJS build to @dcl/ecs-math upstream, then replace this
7
- * file with `import { Vector3 } from '@dcl/ecs-math'`.
8
- *
9
- * @internal
10
- */
11
- export const Vector3 = {
12
- add(a, b) {
13
- return { x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
14
- },
15
- subtract(a, b) {
16
- return { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
17
- },
18
- scale(v, s) {
19
- return { x: v.x * s, y: v.y * s, z: v.z * s };
20
- },
21
- length(v) {
22
- return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
23
- },
24
- normalize(v) {
25
- const len = Vector3.length(v);
26
- if (len === 0)
27
- return { x: 0, y: 0, z: 0 };
28
- return { x: v.x / len, y: v.y / len, z: v.z / len };
29
- },
30
- equals(a, b) {
31
- return a.x === b.x && a.y === b.y && a.z === b.z;
32
- },
33
- equalsToFloats(v, x, y, z) {
34
- return v.x === x && v.y === y && v.z === z;
35
- }
36
- };
@@ -1,9 +0,0 @@
1
- import { Entity } from '../../../engine';
2
- import { ReceiveMessage, TransformType } from '../../../runtime/types';
3
- import { ReceiveNetworkMessage } from '../../../systems/crdt/types';
4
- import { ByteBuffer } from '../../ByteBuffer';
5
- import { INetowrkEntityType } from '../../../components/types';
6
- export declare function isNetworkMessage(message: ReceiveMessage): message is ReceiveNetworkMessage;
7
- export declare function networkMessageToLocal(message: ReceiveNetworkMessage, localEntityId: Entity, buffer: ByteBuffer, destinationBuffer: ByteBuffer): void;
8
- export declare function localMessageToNetwork(message: ReceiveMessage, network: INetowrkEntityType, buffer: ByteBuffer, destinationBuffer: ByteBuffer): void;
9
- export declare function fixTransformParent(message: ReceiveMessage, transformValue?: TransformType, parent?: Entity): Uint8Array;
@@ -1,60 +0,0 @@
1
- import { ReadWriteByteBuffer } from '../../ByteBuffer';
2
- import { PutComponentOperation } from '../putComponent';
3
- import { CrdtMessageType } from '../types';
4
- import { DeleteComponent } from '../deleteComponent';
5
- import { DeleteEntity } from '../deleteEntity';
6
- import { PutNetworkComponentOperation } from './putComponentNetwork';
7
- import { DeleteComponentNetwork } from './deleteComponentNetwork';
8
- import { DeleteEntityNetwork } from './deleteEntityNetwork';
9
- import { TransformSchema } from '../../../components/manual/Transform';
10
- /* istanbul ignore next */
11
- export function isNetworkMessage(message) {
12
- return [
13
- CrdtMessageType.DELETE_COMPONENT_NETWORK,
14
- CrdtMessageType.DELETE_ENTITY_NETWORK,
15
- CrdtMessageType.PUT_COMPONENT_NETWORK
16
- ].includes(message.type);
17
- }
18
- /* istanbul ignore next */
19
- export function networkMessageToLocal(message, localEntityId, buffer, destinationBuffer) {
20
- const offset = buffer.currentWriteOffset();
21
- if (message.type === CrdtMessageType.PUT_COMPONENT_NETWORK) {
22
- PutComponentOperation.write(localEntityId, message.timestamp, message.componentId, message.data, buffer);
23
- }
24
- else if (message.type === CrdtMessageType.DELETE_COMPONENT_NETWORK) {
25
- DeleteComponent.write(localEntityId, message.componentId, message.timestamp, buffer);
26
- }
27
- else if (message.type === CrdtMessageType.DELETE_ENTITY_NETWORK) {
28
- DeleteEntity.write(localEntityId, buffer);
29
- }
30
- destinationBuffer.writeBuffer(buffer.buffer().subarray(offset, buffer.currentWriteOffset()), false);
31
- }
32
- /* istanbul ignore next */
33
- export function localMessageToNetwork(message, network, buffer, destinationBuffer) {
34
- const offset = buffer.currentWriteOffset();
35
- if (message.type === CrdtMessageType.PUT_COMPONENT) {
36
- PutNetworkComponentOperation.write(network.entityId, message.timestamp, message.componentId, network.networkId, message.data, buffer);
37
- }
38
- else if (message.type === CrdtMessageType.DELETE_COMPONENT) {
39
- DeleteComponentNetwork.write(network.entityId, message.componentId, message.timestamp, network.networkId, buffer);
40
- }
41
- else if (message.type === CrdtMessageType.DELETE_ENTITY) {
42
- DeleteEntityNetwork.write(network.entityId, network.networkId, buffer);
43
- }
44
- destinationBuffer.writeBuffer(buffer.buffer().subarray(offset, buffer.currentWriteOffset()), false);
45
- }
46
- const buffer = new ReadWriteByteBuffer();
47
- /* istanbul ignore next */
48
- export function fixTransformParent(message, transformValue, parent) {
49
- buffer.resetBuffer();
50
- let transform = transformValue;
51
- if (!transform && 'data' in message) {
52
- transform = TransformSchema.deserialize(new ReadWriteByteBuffer(message.data));
53
- }
54
- if (!transform)
55
- throw new Error('Invalid parent transform');
56
- // Generate new transform raw data with the parent
57
- const newTransform = { ...transform, parent };
58
- TransformSchema.serialize(newTransform, buffer);
59
- return buffer.toBinary();
60
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,140 +0,0 @@
1
- import * as components from '../components';
2
- import { Vector3, createTimers } from '../runtime/helpers';
3
- import { KnockbackFalloff } from './physics-impulse';
4
- /** @internal */
5
- export function createPhysicsForceHelper(engine) {
6
- const PhysicsCombinedForce = components.PhysicsCombinedForce(engine);
7
- const Transform = components.Transform(engine);
8
- const timers = createTimers(engine);
9
- const durationTimers = new Map();
10
- // Key = source entity producing the force (not the target); all forces target PlayerEntity.
11
- const forceSources = new Map();
12
- const repulsionSources = new Map();
13
- let lastWrittenForceVector = null;
14
- function recalcForce() {
15
- if (forceSources.size === 0) {
16
- if (PhysicsCombinedForce.has(engine.PlayerEntity)) {
17
- PhysicsCombinedForce.deleteFrom(engine.PlayerEntity);
18
- }
19
- lastWrittenForceVector = null;
20
- return;
21
- }
22
- const current = PhysicsCombinedForce.getOrNull(engine.PlayerEntity);
23
- if (current && lastWrittenForceVector && current.vector) {
24
- if (!Vector3.equals(current.vector, lastWrittenForceVector)) {
25
- console.error('PBPhysicsCombinedForce was modified externally.', 'Expected:', lastWrittenForceVector, 'Found:', current.vector, '-- overwriting with local state.');
26
- }
27
- }
28
- let sum = { x: 0, y: 0, z: 0 };
29
- for (const v of forceSources.values()) {
30
- sum = Vector3.add(sum, v);
31
- }
32
- PhysicsCombinedForce.createOrReplace(engine.PlayerEntity, { vector: sum });
33
- lastWrittenForceVector = sum;
34
- }
35
- function applyForceToPlayer(source, vector, magnitude) {
36
- let finalVector;
37
- if (Vector3.equalsToFloats(vector, 0, 0, 0))
38
- return;
39
- if (typeof magnitude === 'number') {
40
- finalVector = Vector3.scale(Vector3.normalize(vector), magnitude);
41
- }
42
- else {
43
- finalVector = vector;
44
- }
45
- forceSources.set(source, finalVector);
46
- recalcForce();
47
- }
48
- function removeForceFromPlayer(source) {
49
- repulsionSources.delete(source);
50
- const timerId = durationTimers.get(source);
51
- if (timerId !== undefined) {
52
- timers.clearTimeout(timerId);
53
- durationTimers.delete(source);
54
- }
55
- if (!forceSources.has(source))
56
- return;
57
- forceSources.delete(source);
58
- recalcForce();
59
- }
60
- function scheduleForceDuration(source, seconds) {
61
- const existing = durationTimers.get(source);
62
- if (existing !== undefined) {
63
- timers.clearTimeout(existing);
64
- }
65
- const timerId = timers.setTimeout(() => {
66
- durationTimers.delete(source);
67
- removeForceFromPlayer(source);
68
- }, seconds * 1000);
69
- durationTimers.set(source, timerId);
70
- }
71
- function applyForceToPlayerForDuration(source, duration, vector, magnitude) {
72
- applyForceToPlayer(source, vector, magnitude);
73
- scheduleForceDuration(source, duration);
74
- }
75
- function computeRepulsionVector(fromPosition, magnitude, radius, falloff) {
76
- const diff = Vector3.subtract(Transform.get(engine.PlayerEntity).position, fromPosition);
77
- if (Vector3.equalsToFloats(diff, 0, 0, 0))
78
- return { x: 0, y: magnitude, z: 0 };
79
- // Fast path: default params — no need to compute distance
80
- if (radius === Infinity && falloff === KnockbackFalloff.CONSTANT) {
81
- return Vector3.scale(Vector3.normalize(diff), magnitude);
82
- }
83
- const distance = Vector3.length(diff);
84
- if (distance > radius)
85
- return null;
86
- let effectiveMagnitude;
87
- switch (falloff) {
88
- case KnockbackFalloff.LINEAR:
89
- effectiveMagnitude = magnitude * (1 - distance / radius);
90
- break;
91
- case KnockbackFalloff.INVERSE_SQUARE:
92
- effectiveMagnitude = magnitude / (distance * distance + 1);
93
- break;
94
- case KnockbackFalloff.CONSTANT:
95
- default:
96
- effectiveMagnitude = magnitude;
97
- break;
98
- }
99
- if (effectiveMagnitude === 0)
100
- return null;
101
- // normalize(diff) * effectiveMagnitude in one step
102
- return Vector3.scale(diff, effectiveMagnitude / distance);
103
- }
104
- function applyRepulsionForceToPlayer(source, fromPosition, magnitude, radius = Infinity, falloff = KnockbackFalloff.CONSTANT) {
105
- repulsionSources.set(source, { fromPosition, magnitude, radius, falloff });
106
- const vector = computeRepulsionVector(fromPosition, magnitude, radius, falloff);
107
- if (vector) {
108
- forceSources.set(source, vector);
109
- }
110
- else {
111
- forceSources.delete(source);
112
- }
113
- recalcForce();
114
- }
115
- // Background system: recalculate repulsion vectors and clean up stale forces every tick.
116
- // Stale forces can appear when CRDT sync from another client writes PhysicsCombinedForce
117
- // externally (entity-1 ambiguity: each client interprets entity 1 as its own player).
118
- engine.addSystem(() => {
119
- // Repulsion forces need per-tick direction recalculation as the player moves
120
- if (repulsionSources.size > 0) {
121
- for (const [source, { fromPosition, magnitude, radius, falloff }] of repulsionSources) {
122
- const vector = computeRepulsionVector(fromPosition, magnitude, radius, falloff);
123
- if (vector) {
124
- forceSources.set(source, vector);
125
- }
126
- else {
127
- forceSources.delete(source);
128
- }
129
- }
130
- recalcForce();
131
- return;
132
- }
133
- // No local sources — clean up any externally-created component (e.g. from CRDT sync)
134
- if (forceSources.size === 0 && PhysicsCombinedForce.has(engine.PlayerEntity)) {
135
- PhysicsCombinedForce.deleteFrom(engine.PlayerEntity);
136
- lastWrittenForceVector = null;
137
- }
138
- });
139
- return { applyForceToPlayer, removeForceFromPlayer, applyForceToPlayerForDuration, applyRepulsionForceToPlayer };
140
- }
@@ -1,12 +0,0 @@
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
- }
@@ -1,85 +0,0 @@
1
- import * as components from '../components';
2
- import { Vector3 } from '../runtime/helpers';
3
- /**
4
- * @public
5
- * Falloff mode for knockback force over distance.
6
- */
7
- export var KnockbackFalloff;
8
- (function (KnockbackFalloff) {
9
- /** Same force at any distance within radius */
10
- KnockbackFalloff[KnockbackFalloff["CONSTANT"] = 0] = "CONSTANT";
11
- /** Smooth linear decrease to 0 at radius edge: F = magnitude * (1 - distance / radius) */
12
- KnockbackFalloff[KnockbackFalloff["LINEAR"] = 1] = "LINEAR";
13
- /** Sharp drop-off, physically realistic: F = magnitude / (distance^2 + 1) */
14
- KnockbackFalloff[KnockbackFalloff["INVERSE_SQUARE"] = 2] = "INVERSE_SQUARE";
15
- })(KnockbackFalloff || (KnockbackFalloff = {}));
16
- /** @internal */
17
- export function createPhysicsImpulseHelper(engine) {
18
- const PhysicsCombinedImpulse = components.PhysicsCombinedImpulse(engine);
19
- const Transform = components.Transform(engine);
20
- const EngineInfo = components.EngineInfo(engine);
21
- let impulseEventId = 0;
22
- let lastWrittenEventId = 0;
23
- let lastWrittenTick = -1;
24
- function applyImpulseToPlayer(vector, magnitude) {
25
- let finalVector;
26
- if (typeof magnitude === 'number') {
27
- if (Vector3.equalsToFloats(vector, 0, 0, 0))
28
- return;
29
- finalVector = Vector3.scale(Vector3.normalize(vector), magnitude);
30
- }
31
- else {
32
- if (Vector3.equalsToFloats(vector, 0, 0, 0))
33
- return;
34
- finalVector = vector;
35
- }
36
- const currentTick = EngineInfo.getOrNull(engine.RootEntity)?.tickNumber ?? 0;
37
- const existing = PhysicsCombinedImpulse.getOrNull(engine.PlayerEntity);
38
- if (existing && existing.eventId !== lastWrittenEventId && lastWrittenEventId !== 0) {
39
- throw new Error('PBPhysicsCombinedImpulse was modified outside Physics helper. ' +
40
- 'Do not mix direct component access with Physics.applyImpulseToPlayer().');
41
- }
42
- if (lastWrittenTick === currentTick && existing) {
43
- finalVector = Vector3.add(existing.vector ?? { x: 0, y: 0, z: 0 }, finalVector);
44
- }
45
- else {
46
- lastWrittenEventId = ++impulseEventId;
47
- }
48
- lastWrittenTick = currentTick;
49
- PhysicsCombinedImpulse.createOrReplace(engine.PlayerEntity, {
50
- vector: finalVector,
51
- eventId: lastWrittenEventId
52
- });
53
- }
54
- function applyKnockbackToPlayer(fromPosition, magnitude, radius = Infinity, falloff = KnockbackFalloff.CONSTANT) {
55
- const diff = Vector3.subtract(Transform.get(engine.PlayerEntity).position, fromPosition);
56
- if (Vector3.equalsToFloats(diff, 0, 0, 0)) {
57
- applyImpulseToPlayer({ x: 0, y: magnitude, z: 0 });
58
- return;
59
- }
60
- // Fast path: default params — no need to compute distance
61
- if (radius === Infinity && falloff === KnockbackFalloff.CONSTANT) {
62
- applyImpulseToPlayer(Vector3.scale(Vector3.normalize(diff), magnitude));
63
- return;
64
- }
65
- const distance = Vector3.length(diff);
66
- if (distance > radius)
67
- return;
68
- let effectiveMagnitude;
69
- switch (falloff) {
70
- case KnockbackFalloff.LINEAR:
71
- effectiveMagnitude = magnitude * (1 - distance / radius);
72
- break;
73
- case KnockbackFalloff.INVERSE_SQUARE:
74
- effectiveMagnitude = magnitude / (distance * distance + 1);
75
- break;
76
- case KnockbackFalloff.CONSTANT:
77
- default:
78
- effectiveMagnitude = magnitude;
79
- break;
80
- }
81
- // normalize(diff) * effectiveMagnitude in one step
82
- applyImpulseToPlayer(Vector3.scale(diff, effectiveMagnitude / distance));
83
- }
84
- return { applyImpulseToPlayer, applyKnockbackToPlayer };
85
- }
@@ -1,77 +0,0 @@
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
- }
@@ -1,18 +0,0 @@
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
- }
@@ -1,24 +0,0 @@
1
- import { IEngine, LastWriteWinElementSetComponentDefinition } from '../../engine';
2
- import { PBParticleSystem, PBParticleSystem_BlendMode, PBParticleSystem_PlaybackState, PBParticleSystem_Point, PBParticleSystem_Sphere, PBParticleSystem_Cone, PBParticleSystem_Box } from '../generated/index.gen';
3
- export { PBParticleSystem_BlendMode as ParticleSystemBlendMode, PBParticleSystem_PlaybackState as ParticleSystemPlaybackState };
4
- /**
5
- * @public
6
- */
7
- export interface ParticleSystemHelper {
8
- /** Emit from a single point */
9
- Point: (point?: PBParticleSystem_Point) => PBParticleSystem['shape'];
10
- /** Emit from the surface or volume of a sphere */
11
- Sphere: (sphere?: PBParticleSystem_Sphere) => PBParticleSystem['shape'];
12
- /** Emit from the base of a cone, projecting outward */
13
- Cone: (cone?: PBParticleSystem_Cone) => PBParticleSystem['shape'];
14
- /** Emit from the surface or volume of a box */
15
- Box: (box?: PBParticleSystem_Box) => PBParticleSystem['shape'];
16
- }
17
- /**
18
- * @public
19
- */
20
- export interface ParticleSystemComponentDefinitionExtended extends LastWriteWinElementSetComponentDefinition<PBParticleSystem> {
21
- /** Helpers for constructing emitter shapes */
22
- Shape: ParticleSystemHelper;
23
- }
24
- export declare function defineParticleSystemComponent(engine: Pick<IEngine, 'defineComponentFromSchema'>): ParticleSystemComponentDefinitionExtended;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineParticleSystemComponent = exports.ParticleSystemPlaybackState = exports.ParticleSystemBlendMode = void 0;
4
- const index_gen_1 = require("../generated/index.gen");
5
- Object.defineProperty(exports, "ParticleSystemBlendMode", { enumerable: true, get: function () { return index_gen_1.PBParticleSystem_BlendMode; } });
6
- Object.defineProperty(exports, "ParticleSystemPlaybackState", { enumerable: true, get: function () { return index_gen_1.PBParticleSystem_PlaybackState; } });
7
- const ParticleSystemShapeHelper = {
8
- Point(point = {}) {
9
- return { $case: 'point', point };
10
- },
11
- Sphere(sphere = {}) {
12
- return { $case: 'sphere', sphere };
13
- },
14
- Cone(cone = {}) {
15
- return { $case: 'cone', cone };
16
- },
17
- Box(box = {}) {
18
- return { $case: 'box', box };
19
- }
20
- };
21
- function defineParticleSystemComponent(engine) {
22
- const theComponent = (0, index_gen_1.ParticleSystem)(engine);
23
- return {
24
- ...theComponent,
25
- Shape: ParticleSystemShapeHelper
26
- };
27
- }
28
- exports.defineParticleSystemComponent = defineParticleSystemComponent;
@@ -1 +0,0 @@
1
- export {};
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ParticleSystemSchema = void 0;
4
- const particle_system_gen_1 = require("./pb/decentraland/sdk/components/particle_system.gen");
5
- /**
6
- * @internal
7
- */
8
- exports.ParticleSystemSchema = {
9
- COMPONENT_ID: 1217,
10
- serialize(value, builder) {
11
- const writer = particle_system_gen_1.PBParticleSystem.encode(value);
12
- const buffer = new Uint8Array(writer.finish(), 0, writer.len);
13
- builder.writeBuffer(buffer, false);
14
- },
15
- deserialize(reader) {
16
- return particle_system_gen_1.PBParticleSystem.decode(reader.buffer(), reader.remainingBytes());
17
- },
18
- create() {
19
- // TODO: this is a hack.
20
- return particle_system_gen_1.PBParticleSystem.decode(new Uint8Array());
21
- },
22
- jsonSchema: {
23
- type: "object",
24
- properties: {},
25
- serializationType: "protocol-buffer",
26
- protocolBuffer: "PBParticleSystem"
27
- }
28
- };
@@ -1,16 +0,0 @@
1
- import _m0 from "protobufjs/minimal";
2
- /** A range of float values. Randomized or lerped between start and end. */
3
- /**
4
- * @public
5
- */
6
- export interface FloatRange {
7
- start: number;
8
- end: number;
9
- }
10
- /**
11
- * @public
12
- */
13
- export declare namespace FloatRange {
14
- function encode(message: FloatRange, writer?: _m0.Writer): _m0.Writer;
15
- function decode(input: _m0.Reader | Uint8Array, length?: number): FloatRange;
16
- }
@@ -1,56 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.FloatRange = void 0;
7
- /* eslint-disable */
8
- const minimal_1 = __importDefault(require("protobufjs/minimal"));
9
- const protobufPackageSarasa = "decentraland.common";
10
- function createBaseFloatRange() {
11
- return { start: 0, end: 0 };
12
- }
13
- /**
14
- * @public
15
- */
16
- var FloatRange;
17
- (function (FloatRange) {
18
- function encode(message, writer = minimal_1.default.Writer.create()) {
19
- if (message.start !== 0) {
20
- writer.uint32(13).float(message.start);
21
- }
22
- if (message.end !== 0) {
23
- writer.uint32(21).float(message.end);
24
- }
25
- return writer;
26
- }
27
- FloatRange.encode = encode;
28
- function decode(input, length) {
29
- const reader = input instanceof minimal_1.default.Reader ? input : minimal_1.default.Reader.create(input);
30
- let end = length === undefined ? reader.len : reader.pos + length;
31
- const message = createBaseFloatRange();
32
- while (reader.pos < end) {
33
- const tag = reader.uint32();
34
- switch (tag >>> 3) {
35
- case 1:
36
- if (tag !== 13) {
37
- break;
38
- }
39
- message.start = reader.float();
40
- continue;
41
- case 2:
42
- if (tag !== 21) {
43
- break;
44
- }
45
- message.end = reader.float();
46
- continue;
47
- }
48
- if ((tag & 7) === 4 || tag === 0) {
49
- break;
50
- }
51
- reader.skipType(tag & 7);
52
- }
53
- return message;
54
- }
55
- FloatRange.decode = decode;
56
- })(FloatRange = exports.FloatRange || (exports.FloatRange = {}));