@tsparticles/engine 4.0.5 → 4.1.1
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.
- package/browser/Core/CanvasManager.js +72 -72
- package/browser/Core/Container.js +85 -85
- package/browser/Core/Engine.js +11 -11
- package/browser/Core/Particle.js +142 -63
- package/browser/Core/ParticlesManager.js +138 -138
- package/browser/Core/RenderManager.js +110 -110
- package/browser/Core/Retina.js +3 -4
- package/browser/Core/Utils/EventListeners.js +31 -31
- package/browser/Core/Utils/PluginManager.js +26 -26
- package/browser/Core/Utils/SpatialHashGrid.js +36 -36
- package/browser/Core/Utils/Vectors.js +3 -3
- package/browser/Options/Classes/Options.js +13 -13
- package/browser/Options/Classes/Particles/ParticlesOptions.js +11 -19
- package/browser/Utils/EventDispatcher.js +10 -10
- package/browser/exports.js +0 -4
- package/cjs/Core/CanvasManager.js +72 -72
- package/cjs/Core/Container.js +85 -85
- package/cjs/Core/Engine.js +11 -11
- package/cjs/Core/Particle.js +142 -63
- package/cjs/Core/ParticlesManager.js +138 -138
- package/cjs/Core/RenderManager.js +110 -110
- package/cjs/Core/Retina.js +3 -4
- package/cjs/Core/Utils/EventListeners.js +31 -31
- package/cjs/Core/Utils/PluginManager.js +26 -26
- package/cjs/Core/Utils/SpatialHashGrid.js +36 -36
- package/cjs/Core/Utils/Vectors.js +3 -3
- package/cjs/Options/Classes/Options.js +13 -13
- package/cjs/Options/Classes/Particles/ParticlesOptions.js +11 -19
- package/cjs/Utils/EventDispatcher.js +10 -10
- package/cjs/exports.js +0 -4
- package/esm/Core/CanvasManager.js +72 -72
- package/esm/Core/Container.js +85 -85
- package/esm/Core/Engine.js +11 -11
- package/esm/Core/Particle.js +142 -63
- package/esm/Core/ParticlesManager.js +138 -138
- package/esm/Core/RenderManager.js +110 -110
- package/esm/Core/Retina.js +3 -4
- package/esm/Core/Utils/EventListeners.js +31 -31
- package/esm/Core/Utils/PluginManager.js +26 -26
- package/esm/Core/Utils/SpatialHashGrid.js +36 -36
- package/esm/Core/Utils/Vectors.js +3 -3
- package/esm/Options/Classes/Options.js +13 -13
- package/esm/Options/Classes/Particles/ParticlesOptions.js +11 -19
- package/esm/Utils/EventDispatcher.js +10 -10
- package/esm/exports.js +0 -4
- package/package.json +1 -1
- package/report.html +1 -1
- package/tsparticles.engine.js +690 -697
- package/tsparticles.engine.min.js +1 -1
- package/types/Core/CanvasManager.d.ts +1 -16
- package/types/Core/Container.d.ts +1 -18
- package/types/Core/Engine.d.ts +1 -3
- package/types/Core/Interfaces/IEffectDrawer.d.ts +2 -0
- package/types/Core/Interfaces/IParticleCanvasBounds.d.ts +16 -0
- package/types/Core/Interfaces/IParticleUpdater.d.ts +1 -0
- package/types/Core/Interfaces/IShapeDrawer.d.ts +2 -0
- package/types/Core/Particle.d.ts +5 -13
- package/types/Core/ParticlesManager.d.ts +1 -28
- package/types/Core/RenderManager.d.ts +1 -23
- package/types/Core/Retina.d.ts +1 -1
- package/types/Core/Utils/EventListeners.d.ts +1 -8
- package/types/Core/Utils/PluginManager.d.ts +1 -8
- package/types/Core/Utils/SpatialHashGrid.d.ts +1 -12
- package/types/Core/Utils/Vectors.d.ts +1 -1
- package/types/Options/Classes/Options.d.ts +1 -4
- package/types/Options/Classes/Particles/ParticlesOptions.d.ts +1 -7
- package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +0 -4
- package/types/Utils/EventDispatcher.d.ts +1 -1
- package/types/export-types.d.ts +1 -4
- package/types/exports.d.ts +0 -4
- package/browser/Options/Classes/Particles/Opacity/Opacity.js +0 -21
- package/browser/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -20
- package/browser/Options/Classes/Particles/Size/Size.js +0 -21
- package/browser/Options/Classes/Particles/Size/SizeAnimation.js +0 -20
- package/browser/Options/Interfaces/Particles/Size/ISizeAnimation.js +0 -1
- package/cjs/Options/Classes/Particles/Opacity/Opacity.js +0 -21
- package/cjs/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -20
- package/cjs/Options/Classes/Particles/Size/Size.js +0 -21
- package/cjs/Options/Classes/Particles/Size/SizeAnimation.js +0 -20
- package/cjs/Options/Interfaces/Particles/Opacity/IOpacity.js +0 -1
- package/cjs/Options/Interfaces/Particles/Opacity/IOpacityAnimation.js +0 -1
- package/cjs/Options/Interfaces/Particles/Size/ISize.js +0 -1
- package/cjs/Options/Interfaces/Particles/Size/ISizeAnimation.js +0 -1
- package/esm/Options/Classes/Particles/Opacity/Opacity.js +0 -21
- package/esm/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -20
- package/esm/Options/Classes/Particles/Size/Size.js +0 -21
- package/esm/Options/Classes/Particles/Size/SizeAnimation.js +0 -20
- package/esm/Options/Interfaces/Particles/Opacity/IOpacity.js +0 -1
- package/esm/Options/Interfaces/Particles/Opacity/IOpacityAnimation.js +0 -1
- package/esm/Options/Interfaces/Particles/Size/ISize.js +0 -1
- package/esm/Options/Interfaces/Particles/Size/ISizeAnimation.js +0 -1
- package/types/Options/Classes/Particles/Opacity/Opacity.d.ts +0 -10
- package/types/Options/Classes/Particles/Opacity/OpacityAnimation.d.ts +0 -10
- package/types/Options/Classes/Particles/Size/Size.d.ts +0 -10
- package/types/Options/Classes/Particles/Size/SizeAnimation.d.ts +0 -10
- package/types/Options/Interfaces/Particles/Opacity/IOpacity.d.ts +0 -5
- package/types/Options/Interfaces/Particles/Opacity/IOpacityAnimation.d.ts +0 -5
- package/types/Options/Interfaces/Particles/Size/ISize.d.ts +0 -5
- package/types/Options/Interfaces/Particles/Size/ISizeAnimation.d.ts +0 -5
- /package/browser/{Options/Interfaces/Particles/Opacity/IOpacity.js → Core/Interfaces/IParticleCanvasBounds.js} +0 -0
- /package/{browser/Options/Interfaces/Particles/Opacity/IOpacityAnimation.js → cjs/Core/Interfaces/IParticleCanvasBounds.js} +0 -0
- /package/{browser/Options/Interfaces/Particles/Size/ISize.js → esm/Core/Interfaces/IParticleCanvasBounds.js} +0 -0
|
@@ -8,44 +8,44 @@ import { loadParticlesOptions } from "../Utils/OptionsUtils.js";
|
|
|
8
8
|
export class ParticlesManager {
|
|
9
9
|
checkParticlePositionPlugins;
|
|
10
10
|
grid;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
#array;
|
|
12
|
+
#container;
|
|
13
|
+
#groupLimits;
|
|
14
|
+
#limit;
|
|
15
|
+
#nextId;
|
|
16
|
+
#particleBuckets;
|
|
17
|
+
#particleResetPlugins;
|
|
18
|
+
#particleUpdatePlugins;
|
|
19
|
+
#pluginManager;
|
|
20
|
+
#pool;
|
|
21
|
+
#postParticleUpdatePlugins;
|
|
22
|
+
#postUpdatePlugins;
|
|
23
|
+
#resizeFactor;
|
|
24
|
+
#updatePlugins;
|
|
25
|
+
#zBuckets;
|
|
26
26
|
constructor(pluginManager, container) {
|
|
27
|
-
this
|
|
28
|
-
this
|
|
29
|
-
this
|
|
30
|
-
this
|
|
31
|
-
this
|
|
32
|
-
this
|
|
33
|
-
this
|
|
34
|
-
this
|
|
35
|
-
this
|
|
27
|
+
this.#pluginManager = pluginManager;
|
|
28
|
+
this.#container = container;
|
|
29
|
+
this.#nextId = 0;
|
|
30
|
+
this.#array = [];
|
|
31
|
+
this.#pool = [];
|
|
32
|
+
this.#limit = 0;
|
|
33
|
+
this.#groupLimits = new Map();
|
|
34
|
+
this.#particleBuckets = new Map();
|
|
35
|
+
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
36
36
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
37
37
|
this.checkParticlePositionPlugins = [];
|
|
38
|
-
this
|
|
39
|
-
this
|
|
40
|
-
this
|
|
41
|
-
this
|
|
42
|
-
this
|
|
38
|
+
this.#particleResetPlugins = [];
|
|
39
|
+
this.#particleUpdatePlugins = [];
|
|
40
|
+
this.#postUpdatePlugins = [];
|
|
41
|
+
this.#postParticleUpdatePlugins = [];
|
|
42
|
+
this.#updatePlugins = [];
|
|
43
43
|
}
|
|
44
44
|
get count() {
|
|
45
|
-
return this.
|
|
45
|
+
return this.#array.length;
|
|
46
46
|
}
|
|
47
47
|
addParticle(position, overrideOptions, group, initializer) {
|
|
48
|
-
const limitMode = this.
|
|
48
|
+
const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
|
|
49
49
|
if (limit > minLimit) {
|
|
50
50
|
switch (limitMode) {
|
|
51
51
|
case LimitMode.delete: {
|
|
@@ -65,20 +65,20 @@ export class ParticlesManager {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
try {
|
|
68
|
-
const particle = this.
|
|
69
|
-
particle.init(this
|
|
68
|
+
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
69
|
+
particle.init(this.#nextId, position, overrideOptions, group);
|
|
70
70
|
let canAdd = true;
|
|
71
71
|
if (initializer) {
|
|
72
72
|
canAdd = initializer(particle);
|
|
73
73
|
}
|
|
74
74
|
if (!canAdd) {
|
|
75
|
-
this.
|
|
75
|
+
this.#pool.push(particle);
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
|
-
this.
|
|
79
|
-
this
|
|
80
|
-
this
|
|
81
|
-
this.
|
|
78
|
+
this.#array.push(particle);
|
|
79
|
+
this.#insertParticleIntoBucket(particle);
|
|
80
|
+
this.#nextId++;
|
|
81
|
+
this.#container.dispatchEvent(EventType.particleAdded, {
|
|
82
82
|
particle,
|
|
83
83
|
});
|
|
84
84
|
return particle;
|
|
@@ -89,25 +89,25 @@ export class ParticlesManager {
|
|
|
89
89
|
return undefined;
|
|
90
90
|
}
|
|
91
91
|
clear() {
|
|
92
|
-
this
|
|
93
|
-
this.
|
|
94
|
-
this
|
|
92
|
+
this.#array = [];
|
|
93
|
+
this.#particleBuckets.clear();
|
|
94
|
+
this.#resetBuckets(this.#container.zLayers);
|
|
95
95
|
}
|
|
96
96
|
destroy() {
|
|
97
|
-
this
|
|
98
|
-
this.
|
|
99
|
-
this.
|
|
100
|
-
this
|
|
97
|
+
this.#array = [];
|
|
98
|
+
this.#pool.length = 0;
|
|
99
|
+
this.#particleBuckets.clear();
|
|
100
|
+
this.#zBuckets = [];
|
|
101
101
|
this.checkParticlePositionPlugins = [];
|
|
102
|
-
this
|
|
103
|
-
this
|
|
104
|
-
this
|
|
105
|
-
this
|
|
106
|
-
this
|
|
102
|
+
this.#particleResetPlugins = [];
|
|
103
|
+
this.#particleUpdatePlugins = [];
|
|
104
|
+
this.#postUpdatePlugins = [];
|
|
105
|
+
this.#postParticleUpdatePlugins = [];
|
|
106
|
+
this.#updatePlugins = [];
|
|
107
107
|
}
|
|
108
108
|
drawParticles(delta) {
|
|
109
|
-
for (let i = this.
|
|
110
|
-
const bucket = this
|
|
109
|
+
for (let i = this.#zBuckets.length - one; i >= minIndex; i--) {
|
|
110
|
+
const bucket = this.#zBuckets[i];
|
|
111
111
|
if (!bucket) {
|
|
112
112
|
continue;
|
|
113
113
|
}
|
|
@@ -117,24 +117,24 @@ export class ParticlesManager {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
filter(condition) {
|
|
120
|
-
return this.
|
|
120
|
+
return this.#array.filter(condition);
|
|
121
121
|
}
|
|
122
122
|
find(condition) {
|
|
123
|
-
return this.
|
|
123
|
+
return this.#array.find(condition);
|
|
124
124
|
}
|
|
125
125
|
get(index) {
|
|
126
|
-
return this
|
|
126
|
+
return this.#array[index];
|
|
127
127
|
}
|
|
128
128
|
async init() {
|
|
129
|
-
const container = this
|
|
129
|
+
const container = this.#container, options = container.actualOptions;
|
|
130
130
|
this.checkParticlePositionPlugins = [];
|
|
131
|
-
this
|
|
132
|
-
this
|
|
133
|
-
this
|
|
134
|
-
this
|
|
135
|
-
this
|
|
136
|
-
this.
|
|
137
|
-
this
|
|
131
|
+
this.#updatePlugins = [];
|
|
132
|
+
this.#particleUpdatePlugins = [];
|
|
133
|
+
this.#postUpdatePlugins = [];
|
|
134
|
+
this.#particleResetPlugins = [];
|
|
135
|
+
this.#postParticleUpdatePlugins = [];
|
|
136
|
+
this.#particleBuckets.clear();
|
|
137
|
+
this.#resetBuckets(container.zLayers);
|
|
138
138
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
139
139
|
for (const plugin of container.plugins) {
|
|
140
140
|
if (plugin.redrawInit) {
|
|
@@ -144,26 +144,26 @@ export class ParticlesManager {
|
|
|
144
144
|
this.checkParticlePositionPlugins.push(plugin);
|
|
145
145
|
}
|
|
146
146
|
if (plugin.update) {
|
|
147
|
-
this.
|
|
147
|
+
this.#updatePlugins.push(plugin);
|
|
148
148
|
}
|
|
149
149
|
if (plugin.particleUpdate) {
|
|
150
|
-
this.
|
|
150
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
151
151
|
}
|
|
152
152
|
if (plugin.postUpdate) {
|
|
153
|
-
this.
|
|
153
|
+
this.#postUpdatePlugins.push(plugin);
|
|
154
154
|
}
|
|
155
155
|
if (plugin.particleReset) {
|
|
156
|
-
this.
|
|
156
|
+
this.#particleResetPlugins.push(plugin);
|
|
157
157
|
}
|
|
158
158
|
if (plugin.postParticleUpdate) {
|
|
159
|
-
this.
|
|
159
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
-
await this.
|
|
163
|
-
for (const drawer of this.
|
|
162
|
+
await this.#container.initDrawersAndUpdaters();
|
|
163
|
+
for (const drawer of this.#container.effectDrawers.values()) {
|
|
164
164
|
await drawer.init?.(container);
|
|
165
165
|
}
|
|
166
|
-
for (const drawer of this.
|
|
166
|
+
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
167
167
|
await drawer.init?.(container);
|
|
168
168
|
}
|
|
169
169
|
let handled = false;
|
|
@@ -197,10 +197,10 @@ export class ParticlesManager {
|
|
|
197
197
|
async redraw() {
|
|
198
198
|
this.clear();
|
|
199
199
|
await this.init();
|
|
200
|
-
this.
|
|
200
|
+
this.#container.canvas.render.drawParticles({ value: 0, factor: 0 });
|
|
201
201
|
}
|
|
202
202
|
remove(particle, group, override) {
|
|
203
|
-
this.removeAt(this.
|
|
203
|
+
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
204
204
|
}
|
|
205
205
|
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
206
206
|
if (index < minIndex || index > this.count) {
|
|
@@ -208,7 +208,7 @@ export class ParticlesManager {
|
|
|
208
208
|
}
|
|
209
209
|
let deleted = 0;
|
|
210
210
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
211
|
-
if (this
|
|
211
|
+
if (this.#removeParticle(i, group, override)) {
|
|
212
212
|
i--;
|
|
213
213
|
deleted++;
|
|
214
214
|
}
|
|
@@ -218,9 +218,9 @@ export class ParticlesManager {
|
|
|
218
218
|
this.removeAt(minIndex, quantity, group);
|
|
219
219
|
}
|
|
220
220
|
setDensity() {
|
|
221
|
-
const options = this.
|
|
221
|
+
const options = this.#container.actualOptions, groups = options.particles.groups;
|
|
222
222
|
let pluginsCount = 0;
|
|
223
|
-
for (const plugin of this.
|
|
223
|
+
for (const plugin of this.#container.plugins) {
|
|
224
224
|
if (plugin.particlesDensityCount) {
|
|
225
225
|
pluginsCount += plugin.particlesDensityCount();
|
|
226
226
|
}
|
|
@@ -230,51 +230,51 @@ export class ParticlesManager {
|
|
|
230
230
|
if (!groupData) {
|
|
231
231
|
continue;
|
|
232
232
|
}
|
|
233
|
-
const groupDataOptions = loadParticlesOptions(this
|
|
234
|
-
this
|
|
233
|
+
const groupDataOptions = loadParticlesOptions(this.#pluginManager, this.#container, groupData);
|
|
234
|
+
this.#applyDensity(groupDataOptions, pluginsCount, group);
|
|
235
235
|
}
|
|
236
|
-
this
|
|
236
|
+
this.#applyDensity(options.particles, pluginsCount);
|
|
237
237
|
}
|
|
238
238
|
setResizeFactor(factor) {
|
|
239
|
-
this
|
|
239
|
+
this.#resizeFactor = factor;
|
|
240
240
|
}
|
|
241
241
|
update(delta) {
|
|
242
242
|
this.grid.clear();
|
|
243
|
-
for (const plugin of this
|
|
243
|
+
for (const plugin of this.#updatePlugins) {
|
|
244
244
|
plugin.update?.(delta);
|
|
245
245
|
}
|
|
246
|
-
const particlesToDelete = this
|
|
247
|
-
for (const plugin of this
|
|
246
|
+
const particlesToDelete = this.#updateParticlesPhase1(delta);
|
|
247
|
+
for (const plugin of this.#postUpdatePlugins) {
|
|
248
248
|
plugin.postUpdate?.(delta);
|
|
249
249
|
}
|
|
250
|
-
this
|
|
250
|
+
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
251
251
|
if (particlesToDelete.size) {
|
|
252
252
|
for (const particle of particlesToDelete) {
|
|
253
253
|
this.remove(particle);
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
|
-
|
|
256
|
+
this.#resizeFactor = undefined;
|
|
257
257
|
}
|
|
258
|
-
|
|
259
|
-
this.
|
|
258
|
+
#addToPool = (...particles) => {
|
|
259
|
+
this.#pool.push(...particles);
|
|
260
260
|
};
|
|
261
|
-
|
|
261
|
+
#applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
262
262
|
const numberOptions = options.number;
|
|
263
263
|
if (!numberOptions.density.enable) {
|
|
264
264
|
if (group === undefined) {
|
|
265
|
-
this
|
|
265
|
+
this.#limit = numberOptions.limit.value;
|
|
266
266
|
}
|
|
267
267
|
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
268
|
-
this.
|
|
268
|
+
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
269
269
|
}
|
|
270
270
|
return;
|
|
271
271
|
}
|
|
272
|
-
const densityFactor = this
|
|
272
|
+
const densityFactor = this.#initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, optParticlesLimit = numberOptions.limit.value > minLimit ? numberOptions.limit.value : optParticlesNumber, particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + pluginsCount, particlesCount = Math.min(this.count, this.filter(t => t.group === group).length);
|
|
273
273
|
if (group === undefined) {
|
|
274
|
-
this
|
|
274
|
+
this.#limit = numberOptions.limit.value * densityFactor;
|
|
275
275
|
}
|
|
276
276
|
else {
|
|
277
|
-
this.
|
|
277
|
+
this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
278
278
|
}
|
|
279
279
|
if (particlesCount < particlesNumber) {
|
|
280
280
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -283,18 +283,18 @@ export class ParticlesManager {
|
|
|
283
283
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
284
284
|
}
|
|
285
285
|
};
|
|
286
|
-
|
|
286
|
+
#createBuckets = (zLayers) => {
|
|
287
287
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
288
288
|
return Array.from({ length: bucketCount }, () => []);
|
|
289
289
|
};
|
|
290
|
-
|
|
291
|
-
const maxBucketIndex = this.
|
|
290
|
+
#getBucketIndex = (zIndex) => {
|
|
291
|
+
const maxBucketIndex = this.#zBuckets.length - one;
|
|
292
292
|
if (maxBucketIndex <= minIndex) {
|
|
293
293
|
return minIndex;
|
|
294
294
|
}
|
|
295
295
|
return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
|
|
296
296
|
};
|
|
297
|
-
|
|
297
|
+
#getParticleInsertIndex = (bucket, particleId) => {
|
|
298
298
|
let start = minIndex, end = bucket.length;
|
|
299
299
|
while (start < end) {
|
|
300
300
|
const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
|
|
@@ -311,8 +311,8 @@ export class ParticlesManager {
|
|
|
311
311
|
}
|
|
312
312
|
return start;
|
|
313
313
|
};
|
|
314
|
-
|
|
315
|
-
const container = this
|
|
314
|
+
#initDensityFactor = densityOptions => {
|
|
315
|
+
const container = this.#container;
|
|
316
316
|
if (!densityOptions.enable) {
|
|
317
317
|
return defaultDensityFactor;
|
|
318
318
|
}
|
|
@@ -322,82 +322,82 @@ export class ParticlesManager {
|
|
|
322
322
|
}
|
|
323
323
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
324
324
|
};
|
|
325
|
-
|
|
326
|
-
const bucketIndex = this
|
|
325
|
+
#insertParticleIntoBucket = (particle) => {
|
|
326
|
+
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
327
327
|
if (!bucket) {
|
|
328
328
|
return;
|
|
329
329
|
}
|
|
330
|
-
bucket.splice(this
|
|
331
|
-
this.
|
|
330
|
+
bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
|
|
331
|
+
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
332
332
|
};
|
|
333
|
-
|
|
334
|
-
const particle = this
|
|
333
|
+
#removeParticle = (index, group, override) => {
|
|
334
|
+
const particle = this.#array[index];
|
|
335
335
|
if (!particle) {
|
|
336
336
|
return false;
|
|
337
337
|
}
|
|
338
338
|
if (particle.group !== group) {
|
|
339
339
|
return false;
|
|
340
340
|
}
|
|
341
|
-
this.
|
|
342
|
-
this
|
|
341
|
+
this.#array.splice(index, deleteCount);
|
|
342
|
+
this.#removeParticleFromBucket(particle);
|
|
343
343
|
particle.destroy(override);
|
|
344
|
-
this.
|
|
344
|
+
this.#container.dispatchEvent(EventType.particleRemoved, {
|
|
345
345
|
particle,
|
|
346
346
|
});
|
|
347
|
-
this
|
|
347
|
+
this.#addToPool(particle);
|
|
348
348
|
return true;
|
|
349
349
|
};
|
|
350
|
-
|
|
351
|
-
const bucketIndex = this.
|
|
350
|
+
#removeParticleFromBucket = (particle) => {
|
|
351
|
+
const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
352
352
|
if (!bucket) {
|
|
353
|
-
this.
|
|
353
|
+
this.#particleBuckets.delete(particle.id);
|
|
354
354
|
return;
|
|
355
355
|
}
|
|
356
|
-
const particleIndex = this
|
|
356
|
+
const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
|
|
357
357
|
if (bucket[particleIndex]?.id !== particle.id) {
|
|
358
|
-
this.
|
|
358
|
+
this.#particleBuckets.delete(particle.id);
|
|
359
359
|
return;
|
|
360
360
|
}
|
|
361
361
|
bucket.splice(particleIndex, deleteCount);
|
|
362
|
-
this.
|
|
362
|
+
this.#particleBuckets.delete(particle.id);
|
|
363
363
|
};
|
|
364
|
-
|
|
364
|
+
#resetBuckets = (zLayers) => {
|
|
365
365
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
366
|
-
if (this.
|
|
367
|
-
this
|
|
366
|
+
if (this.#zBuckets.length !== bucketCount) {
|
|
367
|
+
this.#zBuckets = this.#createBuckets(bucketCount);
|
|
368
368
|
return;
|
|
369
369
|
}
|
|
370
|
-
for (const bucket of this
|
|
370
|
+
for (const bucket of this.#zBuckets) {
|
|
371
371
|
bucket.length = minIndex;
|
|
372
372
|
}
|
|
373
373
|
};
|
|
374
|
-
|
|
375
|
-
const newBucketIndex = this
|
|
374
|
+
#updateParticleBucket = (particle) => {
|
|
375
|
+
const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
|
|
376
376
|
if (currentBucketIndex === undefined) {
|
|
377
|
-
this
|
|
377
|
+
this.#insertParticleIntoBucket(particle);
|
|
378
378
|
return;
|
|
379
379
|
}
|
|
380
380
|
if (currentBucketIndex === newBucketIndex) {
|
|
381
381
|
return;
|
|
382
382
|
}
|
|
383
|
-
const currentBucket = this
|
|
383
|
+
const currentBucket = this.#zBuckets[currentBucketIndex];
|
|
384
384
|
if (currentBucket) {
|
|
385
|
-
const particleIndex = this
|
|
385
|
+
const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
|
|
386
386
|
if (currentBucket[particleIndex]?.id === particle.id) {
|
|
387
387
|
currentBucket.splice(particleIndex, deleteCount);
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
|
-
const newBucket = this
|
|
390
|
+
const newBucket = this.#zBuckets[newBucketIndex];
|
|
391
391
|
if (!newBucket) {
|
|
392
|
-
this.
|
|
392
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
393
393
|
return;
|
|
394
394
|
}
|
|
395
|
-
newBucket.splice(this
|
|
396
|
-
this.
|
|
395
|
+
newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
|
|
396
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
397
397
|
};
|
|
398
|
-
|
|
399
|
-
const particlesToDelete = new Set(), resizeFactor = this
|
|
400
|
-
for (const particle of this
|
|
398
|
+
#updateParticlesPhase1 = (delta) => {
|
|
399
|
+
const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
|
|
400
|
+
for (const particle of this.#array) {
|
|
401
401
|
if (resizeFactor && !particle.ignoresResizeRatio) {
|
|
402
402
|
particle.position.x *= resizeFactor.width;
|
|
403
403
|
particle.position.y *= resizeFactor.height;
|
|
@@ -405,10 +405,10 @@ export class ParticlesManager {
|
|
|
405
405
|
particle.initialPosition.y *= resizeFactor.height;
|
|
406
406
|
}
|
|
407
407
|
particle.ignoresResizeRatio = false;
|
|
408
|
-
for (const plugin of this
|
|
408
|
+
for (const plugin of this.#particleResetPlugins) {
|
|
409
409
|
plugin.particleReset?.(particle);
|
|
410
410
|
}
|
|
411
|
-
for (const plugin of this
|
|
411
|
+
for (const plugin of this.#particleUpdatePlugins) {
|
|
412
412
|
if (particle.destroyed) {
|
|
413
413
|
break;
|
|
414
414
|
}
|
|
@@ -422,21 +422,21 @@ export class ParticlesManager {
|
|
|
422
422
|
}
|
|
423
423
|
return particlesToDelete;
|
|
424
424
|
};
|
|
425
|
-
|
|
426
|
-
for (const particle of this
|
|
425
|
+
#updateParticlesPhase2 = (delta, particlesToDelete) => {
|
|
426
|
+
for (const particle of this.#array) {
|
|
427
427
|
if (particle.destroyed) {
|
|
428
428
|
particlesToDelete.add(particle);
|
|
429
429
|
continue;
|
|
430
430
|
}
|
|
431
|
-
for (const updater of this.
|
|
431
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
432
432
|
updater.update(particle, delta);
|
|
433
433
|
}
|
|
434
434
|
if (!particle.spawning) {
|
|
435
|
-
for (const plugin of this
|
|
435
|
+
for (const plugin of this.#postParticleUpdatePlugins) {
|
|
436
436
|
plugin.postParticleUpdate?.(particle, delta);
|
|
437
437
|
}
|
|
438
438
|
}
|
|
439
|
-
this
|
|
439
|
+
this.#updateParticleBucket(particle);
|
|
440
440
|
}
|
|
441
441
|
};
|
|
442
442
|
}
|