@flare-engine/particles 0.2.1 → 0.3.0

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/dist/index.js CHANGED
@@ -1,245 +1,265 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- ParticleEmitter: () => ParticleEmitter,
24
- ParticlePool: () => ParticlePool
25
- });
26
- module.exports = __toCommonJS(index_exports);
27
-
28
- // src/particle-pool.ts
29
- var import_core = require("@flare-engine/core");
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _flare_engine_core = require("@flare-engine/core");
3
+ //#region src/particle-pool.ts
4
+ /** Create a default (inactive) particle. */
30
5
  function createParticle() {
31
- return {
32
- x: 0,
33
- y: 0,
34
- vx: 0,
35
- vy: 0,
36
- life: 0,
37
- maxLife: 0,
38
- startSize: 1,
39
- endSize: 1,
40
- startAlpha: 1,
41
- endAlpha: 0,
42
- startR: 1,
43
- startG: 1,
44
- startB: 1,
45
- endR: 1,
46
- endG: 1,
47
- endB: 1,
48
- rotation: 0,
49
- angularVelocity: 0,
50
- active: false
51
- };
6
+ return {
7
+ x: 0,
8
+ y: 0,
9
+ vx: 0,
10
+ vy: 0,
11
+ life: 0,
12
+ maxLife: 0,
13
+ startSize: 1,
14
+ endSize: 1,
15
+ startAlpha: 1,
16
+ endAlpha: 0,
17
+ startR: 1,
18
+ startG: 1,
19
+ startB: 1,
20
+ endR: 1,
21
+ endG: 1,
22
+ endB: 1,
23
+ rotation: 0,
24
+ angularVelocity: 0,
25
+ active: false
26
+ };
52
27
  }
28
+ /** Reset a particle to default (inactive) state. */
53
29
  function resetParticle(p) {
54
- p.x = 0;
55
- p.y = 0;
56
- p.vx = 0;
57
- p.vy = 0;
58
- p.life = 0;
59
- p.maxLife = 0;
60
- p.startSize = 1;
61
- p.endSize = 1;
62
- p.startAlpha = 1;
63
- p.endAlpha = 0;
64
- p.startR = 1;
65
- p.startG = 1;
66
- p.startB = 1;
67
- p.endR = 1;
68
- p.endG = 1;
69
- p.endB = 1;
70
- p.rotation = 0;
71
- p.angularVelocity = 0;
72
- p.active = false;
30
+ p.x = 0;
31
+ p.y = 0;
32
+ p.vx = 0;
33
+ p.vy = 0;
34
+ p.life = 0;
35
+ p.maxLife = 0;
36
+ p.startSize = 1;
37
+ p.endSize = 1;
38
+ p.startAlpha = 1;
39
+ p.endAlpha = 0;
40
+ p.startR = 1;
41
+ p.startG = 1;
42
+ p.startB = 1;
43
+ p.endR = 1;
44
+ p.endG = 1;
45
+ p.endB = 1;
46
+ p.rotation = 0;
47
+ p.angularVelocity = 0;
48
+ p.active = false;
73
49
  }
50
+ /**
51
+ * ParticlePool — pre-allocated pool of particles.
52
+ * Zero GC pressure during steady-state gameplay.
53
+ */
74
54
  var ParticlePool = class {
75
- _pool;
76
- _active = [];
77
- constructor(capacity = 256) {
78
- this._pool = new import_core.Pool(createParticle, resetParticle);
79
- this._pool.prewarm(capacity);
80
- }
81
- /** Number of currently active particles. */
82
- get activeCount() {
83
- return this._active.length;
84
- }
85
- /** Read-only access to active particles. */
86
- get particles() {
87
- return this._active;
88
- }
89
- /** Acquire a particle from the pool. */
90
- acquire() {
91
- const p = this._pool.acquire();
92
- p.active = true;
93
- this._active.push(p);
94
- return p;
95
- }
96
- /** Update all active particles. Releases dead particles. */
97
- update(dt, gravityX, gravityY) {
98
- let i = 0;
99
- while (i < this._active.length) {
100
- const p = this._active[i];
101
- p.life -= dt;
102
- if (p.life <= 0) {
103
- p.active = false;
104
- this._pool.release(p);
105
- this._active[i] = this._active[this._active.length - 1];
106
- this._active.pop();
107
- continue;
108
- }
109
- p.vx += gravityX * dt;
110
- p.vy += gravityY * dt;
111
- p.x += p.vx * dt;
112
- p.y += p.vy * dt;
113
- p.rotation += p.angularVelocity * dt;
114
- i++;
115
- }
116
- }
117
- /** Get interpolated size for a particle (0 = start, 1 = end of life). */
118
- getSize(p) {
119
- const t = 1 - p.life / p.maxLife;
120
- return p.startSize + (p.endSize - p.startSize) * t;
121
- }
122
- /** Get interpolated alpha for a particle. */
123
- getAlpha(p) {
124
- const t = 1 - p.life / p.maxLife;
125
- return p.startAlpha + (p.endAlpha - p.startAlpha) * t;
126
- }
127
- /** Shared color buffer — avoids per-call allocation in the render hot path. */
128
- _colorBuf = { r: 1, g: 1, b: 1, a: 1 };
129
- /**
130
- * Get interpolated color for a particle.
131
- *
132
- * Returns a shared buffer — read the values immediately, do not retain the
133
- * reference. For a fresh object call `getColorInto()` with your own out param.
134
- */
135
- getColor(p) {
136
- return this.getColorInto(p, this._colorBuf);
137
- }
138
- /** Zero-alloc variant — writes the interpolated color into `out`. */
139
- getColorInto(p, out) {
140
- const t = 1 - p.life / p.maxLife;
141
- out.r = p.startR + (p.endR - p.startR) * t;
142
- out.g = p.startG + (p.endG - p.startG) * t;
143
- out.b = p.startB + (p.endB - p.startB) * t;
144
- out.a = p.startAlpha + (p.endAlpha - p.startAlpha) * t;
145
- return out;
146
- }
147
- /** Release all active particles back to pool. */
148
- clear() {
149
- for (const p of this._active) {
150
- p.active = false;
151
- this._pool.release(p);
152
- }
153
- this._active.length = 0;
154
- }
55
+ _pool;
56
+ _active = [];
57
+ constructor(capacity = 256) {
58
+ this._pool = new _flare_engine_core.Pool(createParticle, resetParticle, { capacity });
59
+ this._pool.prewarm(capacity);
60
+ }
61
+ /** Number of currently active particles. */
62
+ get activeCount() {
63
+ return this._active.length;
64
+ }
65
+ /**
66
+ * Cumulative factory calls made by the internal pool's acquire()/tryAcquire().
67
+ * prewarm() is excluded: factory calls there pre-fill the free list and are
68
+ * not counted. Intended use: snapshot before and after a frame — a non-zero
69
+ * delta in steady state means unexpected allocation.
70
+ */
71
+ get created() {
72
+ return this._pool.created;
73
+ }
74
+ /** Read-only access to active particles. */
75
+ get particles() {
76
+ return this._active;
77
+ }
78
+ /** Acquire a particle from the pool. */
79
+ acquire() {
80
+ const p = this._pool.acquire();
81
+ p.active = true;
82
+ this._active.push(p);
83
+ return p;
84
+ }
85
+ /**
86
+ * Acquire a particle only if the pool is below capacity.
87
+ * Returns null at cap — no allocation occurs.
88
+ */
89
+ tryAcquire() {
90
+ const p = this._pool.tryAcquire();
91
+ if (!p) return null;
92
+ p.active = true;
93
+ this._active.push(p);
94
+ return p;
95
+ }
96
+ /** Update all active particles. Releases dead particles. */
97
+ update(dt, gravityX, gravityY) {
98
+ let i = 0;
99
+ while (i < this._active.length) {
100
+ const p = this._active[i];
101
+ p.life -= dt;
102
+ if (p.life <= 0) {
103
+ p.active = false;
104
+ this._pool.release(p);
105
+ this._active[i] = this._active[this._active.length - 1];
106
+ this._active.pop();
107
+ continue;
108
+ }
109
+ p.vx += gravityX * dt;
110
+ p.vy += gravityY * dt;
111
+ p.x += p.vx * dt;
112
+ p.y += p.vy * dt;
113
+ p.rotation += p.angularVelocity * dt;
114
+ i++;
115
+ }
116
+ }
117
+ /** Get interpolated size for a particle (0 = start, 1 = end of life). */
118
+ getSize(p) {
119
+ const t = 1 - p.life / p.maxLife;
120
+ return p.startSize + (p.endSize - p.startSize) * t;
121
+ }
122
+ /** Get interpolated alpha for a particle. */
123
+ getAlpha(p) {
124
+ const t = 1 - p.life / p.maxLife;
125
+ return p.startAlpha + (p.endAlpha - p.startAlpha) * t;
126
+ }
127
+ /** Shared color buffer — avoids per-call allocation in the render hot path. */
128
+ _colorBuf = {
129
+ r: 1,
130
+ g: 1,
131
+ b: 1,
132
+ a: 1
133
+ };
134
+ /**
135
+ * Get interpolated color for a particle.
136
+ *
137
+ * Returns a shared buffer — read the values immediately, do not retain the
138
+ * reference. For a fresh object call `getColorInto()` with your own out param.
139
+ */
140
+ getColor(p) {
141
+ return this.getColorInto(p, this._colorBuf);
142
+ }
143
+ /** Zero-alloc variant — writes the interpolated color into `out`. */
144
+ getColorInto(p, out) {
145
+ const t = 1 - p.life / p.maxLife;
146
+ out.r = p.startR + (p.endR - p.startR) * t;
147
+ out.g = p.startG + (p.endG - p.startG) * t;
148
+ out.b = p.startB + (p.endB - p.startB) * t;
149
+ out.a = p.startAlpha + (p.endAlpha - p.startAlpha) * t;
150
+ return out;
151
+ }
152
+ /** Release all active particles back to pool. */
153
+ clear() {
154
+ for (const p of this._active) {
155
+ p.active = false;
156
+ this._pool.release(p);
157
+ }
158
+ this._active.length = 0;
159
+ }
155
160
  };
156
-
157
- // src/particle-emitter.ts
161
+ //#endregion
162
+ //#region src/particle-emitter.ts
163
+ /**
164
+ * ParticleEmitter — emits particles based on a configuration.
165
+ * Uses a ParticlePool for zero-GC operation.
166
+ *
167
+ * Call `update(dt)` each frame. Read `pool.particles` for rendering.
168
+ */
158
169
  var ParticleEmitter = class {
159
- config;
160
- pool;
161
- /** Emitter world position. */
162
- x = 0;
163
- y = 0;
164
- /** Whether the emitter is actively emitting. */
165
- emitting = true;
166
- _emitAccumulator = 0;
167
- _seed = 1;
168
- constructor(config, maxParticles) {
169
- this.config = config;
170
- this.pool = new ParticlePool(maxParticles ?? config.maxParticles ?? 256);
171
- }
172
- /** Update the emitter: emit new particles and update existing ones. */
173
- update(dt) {
174
- if (this.emitting) {
175
- this._emitAccumulator += dt * this.config.rate;
176
- while (this._emitAccumulator >= 1) {
177
- this._emitAccumulator -= 1;
178
- if (this.config.maxParticles && this.pool.activeCount >= this.config.maxParticles) {
179
- this._emitAccumulator = 0;
180
- break;
181
- }
182
- this._emitOne();
183
- }
184
- }
185
- this.pool.update(dt, this.config.gravityX ?? 0, this.config.gravityY ?? 0);
186
- }
187
- /** Emit a burst of particles. */
188
- burst(count) {
189
- for (let i = 0; i < count; i++) {
190
- if (this.config.maxParticles && this.pool.activeCount >= this.config.maxParticles) break;
191
- this._emitOne();
192
- }
193
- }
194
- /** Stop emitting and clear all particles. */
195
- reset() {
196
- this.emitting = false;
197
- this._emitAccumulator = 0;
198
- this.pool.clear();
199
- }
200
- /** Simple seeded pseudo-random for deterministic particles. */
201
- _random() {
202
- this._seed = this._seed * 16807 % 2147483647;
203
- return (this._seed - 1) / 2147483646;
204
- }
205
- /** Random float in [min, max]. */
206
- _randomRange(min, max) {
207
- return min + this._random() * (max - min);
208
- }
209
- _emitOne() {
210
- const c = this.config;
211
- const p = this.pool.acquire();
212
- p.x = this.x;
213
- p.y = this.y;
214
- const angle = c.direction + this._randomRange(-c.spread, c.spread);
215
- const speed = c.speedMax ? this._randomRange(c.speed, c.speedMax) : c.speed;
216
- p.vx = Math.cos(angle) * speed;
217
- p.vy = Math.sin(angle) * speed;
218
- const lifetime = c.lifetimeMax ? this._randomRange(c.lifetime, c.lifetimeMax) : c.lifetime;
219
- p.life = lifetime;
220
- p.maxLife = lifetime;
221
- p.startSize = c.startSize ?? 4;
222
- p.endSize = c.endSize ?? 0;
223
- p.startAlpha = c.startAlpha ?? 1;
224
- p.endAlpha = c.endAlpha ?? 0;
225
- if (c.startColor) {
226
- p.startR = c.startColor.r;
227
- p.startG = c.startColor.g;
228
- p.startB = c.startColor.b;
229
- }
230
- if (c.endColor) {
231
- p.endR = c.endColor.r;
232
- p.endG = c.endColor.g;
233
- p.endB = c.endColor.b;
234
- }
235
- if (c.angularVelocity !== void 0) {
236
- p.angularVelocity = c.angularVelocityMax ? this._randomRange(c.angularVelocity, c.angularVelocityMax) : c.angularVelocity;
237
- }
238
- }
170
+ config;
171
+ pool;
172
+ /** Emitter world position. */
173
+ x = 0;
174
+ y = 0;
175
+ /** Whether the emitter is actively emitting. */
176
+ emitting = true;
177
+ _emitAccumulator = 0;
178
+ _seed = 0;
179
+ constructor(config, opts) {
180
+ this.config = config;
181
+ const cap = opts?.maxParticles ?? config.maxParticles ?? 256;
182
+ this.pool = new ParticlePool(cap);
183
+ this._setSeed(opts?.seed ?? 1);
184
+ }
185
+ /** Reset the LCG seed — restarts the particle random sequence from this seed. */
186
+ reseed(seed) {
187
+ this._setSeed(seed);
188
+ }
189
+ /** Normalize s into the valid Park-Miller domain [1, 2147483646]. */
190
+ _setSeed(s) {
191
+ let n = Number.isFinite(s) ? Math.floor(s) % 2147483647 : 0;
192
+ if (n < 0) n += 2147483647;
193
+ if (n === 0) n = 1;
194
+ this._seed = n;
195
+ }
196
+ /** Update the emitter: emit new particles and update existing ones. */
197
+ update(dt) {
198
+ if (this.emitting) {
199
+ this._emitAccumulator += dt * this.config.rate;
200
+ while (this._emitAccumulator >= 1) {
201
+ this._emitAccumulator -= 1;
202
+ if (!this._emitOne()) {
203
+ this._emitAccumulator = 0;
204
+ break;
205
+ }
206
+ }
207
+ }
208
+ this.pool.update(dt, this.config.gravityX ?? 0, this.config.gravityY ?? 0);
209
+ }
210
+ /** Emit a burst of particles. */
211
+ burst(count) {
212
+ for (let i = 0; i < count; i++) if (!this._emitOne()) break;
213
+ }
214
+ /** Stop emitting and clear all particles. */
215
+ reset() {
216
+ this.emitting = false;
217
+ this._emitAccumulator = 0;
218
+ this.pool.clear();
219
+ }
220
+ /** Simple seeded pseudo-random for deterministic particles. */
221
+ _random() {
222
+ this._seed = this._seed * 16807 % 2147483647;
223
+ return (this._seed - 1) / 2147483646;
224
+ }
225
+ /** Random float in [min, max]. */
226
+ _randomRange(min, max) {
227
+ return min + this._random() * (max - min);
228
+ }
229
+ /** Emit one particle. Returns false when the pool is at cap — caller should stop. */
230
+ _emitOne() {
231
+ const p = this.pool.tryAcquire();
232
+ if (!p) return false;
233
+ const c = this.config;
234
+ p.x = this.x;
235
+ p.y = this.y;
236
+ const angle = c.direction + this._randomRange(-c.spread, c.spread);
237
+ const speed = c.speedMax ? this._randomRange(c.speed, c.speedMax) : c.speed;
238
+ p.vx = Math.cos(angle) * speed;
239
+ p.vy = Math.sin(angle) * speed;
240
+ const lifetime = c.lifetimeMax ? this._randomRange(c.lifetime, c.lifetimeMax) : c.lifetime;
241
+ p.life = lifetime;
242
+ p.maxLife = lifetime;
243
+ p.startSize = c.startSize ?? 4;
244
+ p.endSize = c.endSize ?? 0;
245
+ p.startAlpha = c.startAlpha ?? 1;
246
+ p.endAlpha = c.endAlpha ?? 0;
247
+ if (c.startColor) {
248
+ p.startR = c.startColor.r;
249
+ p.startG = c.startColor.g;
250
+ p.startB = c.startColor.b;
251
+ }
252
+ if (c.endColor) {
253
+ p.endR = c.endColor.r;
254
+ p.endG = c.endColor.g;
255
+ p.endB = c.endColor.b;
256
+ }
257
+ if (c.angularVelocity !== void 0) p.angularVelocity = c.angularVelocityMax ? this._randomRange(c.angularVelocity, c.angularVelocityMax) : c.angularVelocity;
258
+ return true;
259
+ }
239
260
  };
240
- // Annotate the CommonJS export names for ESM import in node:
241
- 0 && (module.exports = {
242
- ParticleEmitter,
243
- ParticlePool
244
- });
261
+ //#endregion
262
+ exports.ParticleEmitter = ParticleEmitter;
263
+ exports.ParticlePool = ParticlePool;
264
+
245
265
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/particle-pool.ts","../src/particle-emitter.ts"],"sourcesContent":["export {\n type Particle,\n ParticlePool,\n} from './particle-pool.js';\n\nexport {\n type EmitterConfig,\n ParticleEmitter,\n} from './particle-emitter.js';\n","import { Pool } from '@flare-engine/core';\nimport type { Color } from '@flare-engine/math';\n\n/** A single particle. Managed by ParticlePool — not user-facing. */\nexport interface Particle {\n /** World position. */\n x: number;\n y: number;\n /** Velocity in pixels/second. */\n vx: number;\n vy: number;\n /** Time remaining in seconds. */\n life: number;\n /** Total lifetime for interpolation. */\n maxLife: number;\n /** Start/end size for interpolation. */\n startSize: number;\n endSize: number;\n /** Start/end alpha for interpolation. */\n startAlpha: number;\n endAlpha: number;\n /** Start/end color components for interpolation. */\n startR: number;\n startG: number;\n startB: number;\n endR: number;\n endG: number;\n endB: number;\n /** Rotation in radians. */\n rotation: number;\n /** Angular velocity in radians/second. */\n angularVelocity: number;\n /** Whether this particle is active. */\n active: boolean;\n}\n\n/** Create a default (inactive) particle. */\nfunction createParticle(): Particle {\n return {\n x: 0,\n y: 0,\n vx: 0,\n vy: 0,\n life: 0,\n maxLife: 0,\n startSize: 1,\n endSize: 1,\n startAlpha: 1,\n endAlpha: 0,\n startR: 1,\n startG: 1,\n startB: 1,\n endR: 1,\n endG: 1,\n endB: 1,\n rotation: 0,\n angularVelocity: 0,\n active: false,\n };\n}\n\n/** Reset a particle to default (inactive) state. */\nfunction resetParticle(p: Particle): void {\n p.x = 0;\n p.y = 0;\n p.vx = 0;\n p.vy = 0;\n p.life = 0;\n p.maxLife = 0;\n p.startSize = 1;\n p.endSize = 1;\n p.startAlpha = 1;\n p.endAlpha = 0;\n p.startR = 1;\n p.startG = 1;\n p.startB = 1;\n p.endR = 1;\n p.endG = 1;\n p.endB = 1;\n p.rotation = 0;\n p.angularVelocity = 0;\n p.active = false;\n}\n\n/**\n * ParticlePool — pre-allocated pool of particles.\n * Zero GC pressure during steady-state gameplay.\n */\nexport class ParticlePool {\n private _pool: Pool<Particle>;\n private _active: Particle[] = [];\n\n constructor(capacity = 256) {\n this._pool = new Pool(createParticle, resetParticle);\n this._pool.prewarm(capacity);\n }\n\n /** Number of currently active particles. */\n get activeCount(): number {\n return this._active.length;\n }\n\n /** Read-only access to active particles. */\n get particles(): readonly Particle[] {\n return this._active;\n }\n\n /** Acquire a particle from the pool. */\n acquire(): Particle {\n const p = this._pool.acquire();\n p.active = true;\n this._active.push(p);\n return p;\n }\n\n /** Update all active particles. Releases dead particles. */\n update(dt: number, gravityX: number, gravityY: number): void {\n let i = 0;\n while (i < this._active.length) {\n const p = this._active[i]!;\n p.life -= dt;\n\n if (p.life <= 0) {\n // Dead — release and swap-remove\n p.active = false;\n this._pool.release(p);\n this._active[i] = this._active[this._active.length - 1]!;\n this._active.pop();\n continue;\n }\n\n // Apply gravity\n p.vx += gravityX * dt;\n p.vy += gravityY * dt;\n\n // Integrate position\n p.x += p.vx * dt;\n p.y += p.vy * dt;\n\n // Rotate\n p.rotation += p.angularVelocity * dt;\n\n i++;\n }\n }\n\n /** Get interpolated size for a particle (0 = start, 1 = end of life). */\n getSize(p: Particle): number {\n const t = 1 - p.life / p.maxLife;\n return p.startSize + (p.endSize - p.startSize) * t;\n }\n\n /** Get interpolated alpha for a particle. */\n getAlpha(p: Particle): number {\n const t = 1 - p.life / p.maxLife;\n return p.startAlpha + (p.endAlpha - p.startAlpha) * t;\n }\n\n /** Shared color buffer — avoids per-call allocation in the render hot path. */\n private _colorBuf: Color = { r: 1, g: 1, b: 1, a: 1 };\n\n /**\n * Get interpolated color for a particle.\n *\n * Returns a shared buffer — read the values immediately, do not retain the\n * reference. For a fresh object call `getColorInto()` with your own out param.\n */\n getColor(p: Particle): Color {\n return this.getColorInto(p, this._colorBuf);\n }\n\n /** Zero-alloc variant — writes the interpolated color into `out`. */\n getColorInto(p: Particle, out: Color): Color {\n const t = 1 - p.life / p.maxLife;\n out.r = p.startR + (p.endR - p.startR) * t;\n out.g = p.startG + (p.endG - p.startG) * t;\n out.b = p.startB + (p.endB - p.startB) * t;\n out.a = p.startAlpha + (p.endAlpha - p.startAlpha) * t;\n return out;\n }\n\n /** Release all active particles back to pool. */\n clear(): void {\n for (const p of this._active) {\n p.active = false;\n this._pool.release(p);\n }\n this._active.length = 0;\n }\n}\n","import type { Color } from '@flare-engine/math';\nimport type { Particle } from './particle-pool.js';\nimport { ParticlePool } from './particle-pool.js';\n\n/** Configuration for a ParticleEmitter. */\nexport interface EmitterConfig {\n /** Emission rate in particles per second. */\n rate: number;\n /** Particle lifetime in seconds. */\n lifetime: number;\n /** Min lifetime (if set, actual lifetime is random between lifetime and lifetimeMax). */\n lifetimeMax?: number;\n /** Initial speed in pixels/second. */\n speed: number;\n /** Max speed (random range). */\n speedMax?: number;\n /** Emission direction in radians (0 = right). */\n direction: number;\n /** Spread angle in radians (half-angle of the emission cone). */\n spread: number;\n /** Gravity in pixels/second² (applied each frame). */\n gravityX?: number;\n gravityY?: number;\n /** Start size and end size. */\n startSize?: number;\n endSize?: number;\n /** Start alpha and end alpha. */\n startAlpha?: number;\n endAlpha?: number;\n /** Start color. */\n startColor?: Color;\n /** End color. */\n endColor?: Color;\n /** Angular velocity range (radians/second). */\n angularVelocity?: number;\n angularVelocityMax?: number;\n /** Maximum active particles. */\n maxParticles?: number;\n}\n\n/**\n * ParticleEmitter — emits particles based on a configuration.\n * Uses a ParticlePool for zero-GC operation.\n *\n * Call `update(dt)` each frame. Read `pool.particles` for rendering.\n */\nexport class ParticleEmitter {\n readonly config: EmitterConfig;\n readonly pool: ParticlePool;\n\n /** Emitter world position. */\n x = 0;\n y = 0;\n\n /** Whether the emitter is actively emitting. */\n emitting = true;\n\n private _emitAccumulator = 0;\n private _seed = 1;\n\n constructor(config: EmitterConfig, maxParticles?: number) {\n this.config = config;\n this.pool = new ParticlePool(maxParticles ?? config.maxParticles ?? 256);\n }\n\n /** Update the emitter: emit new particles and update existing ones. */\n update(dt: number): void {\n // Emit new particles\n if (this.emitting) {\n this._emitAccumulator += dt * this.config.rate;\n while (this._emitAccumulator >= 1) {\n this._emitAccumulator -= 1;\n if (this.config.maxParticles && this.pool.activeCount >= this.config.maxParticles) {\n this._emitAccumulator = 0;\n break;\n }\n this._emitOne();\n }\n }\n\n // Update all particles\n this.pool.update(dt, this.config.gravityX ?? 0, this.config.gravityY ?? 0);\n }\n\n /** Emit a burst of particles. */\n burst(count: number): void {\n for (let i = 0; i < count; i++) {\n if (this.config.maxParticles && this.pool.activeCount >= this.config.maxParticles) break;\n this._emitOne();\n }\n }\n\n /** Stop emitting and clear all particles. */\n reset(): void {\n this.emitting = false;\n this._emitAccumulator = 0;\n this.pool.clear();\n }\n\n /** Simple seeded pseudo-random for deterministic particles. */\n private _random(): number {\n this._seed = (this._seed * 16807) % 2147483647;\n return (this._seed - 1) / 2147483646;\n }\n\n /** Random float in [min, max]. */\n private _randomRange(min: number, max: number): number {\n return min + this._random() * (max - min);\n }\n\n private _emitOne(): void {\n const c = this.config;\n const p: Particle = this.pool.acquire();\n\n // Position at emitter origin\n p.x = this.x;\n p.y = this.y;\n\n // Random angle within spread\n const angle = c.direction + this._randomRange(-c.spread, c.spread);\n const speed = c.speedMax ? this._randomRange(c.speed, c.speedMax) : c.speed;\n p.vx = Math.cos(angle) * speed;\n p.vy = Math.sin(angle) * speed;\n\n // Lifetime\n const lifetime = c.lifetimeMax ? this._randomRange(c.lifetime, c.lifetimeMax) : c.lifetime;\n p.life = lifetime;\n p.maxLife = lifetime;\n\n // Size\n p.startSize = c.startSize ?? 4;\n p.endSize = c.endSize ?? 0;\n\n // Alpha\n p.startAlpha = c.startAlpha ?? 1;\n p.endAlpha = c.endAlpha ?? 0;\n\n // Colors\n if (c.startColor) {\n p.startR = c.startColor.r;\n p.startG = c.startColor.g;\n p.startB = c.startColor.b;\n }\n if (c.endColor) {\n p.endR = c.endColor.r;\n p.endG = c.endColor.g;\n p.endB = c.endColor.b;\n }\n\n // Angular velocity\n if (c.angularVelocity !== undefined) {\n p.angularVelocity = c.angularVelocityMax\n ? this._randomRange(c.angularVelocity, c.angularVelocityMax)\n : c.angularVelocity;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAqB;AAqCrB,SAAS,iBAA2B;AAClC,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,IACH,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,MAAM;A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Q,WAAiB;AACvB,UAAM,IAAI,KAAK;AACf,UAAM,IAAc,KAAK,KAAK,QAAQ;AAGtC,MAAE,IAAI,KAAK;AACX,MAAE,IAAI,KAAK;AAGX,UAAM,QAAQ,EAAE,YAAY,KAAK,aAAa,CAAC,EAAE,QAAQ,EAAE,MAAM;AACjE,UAAM,QAAQ,EAAE,WAAW,KAAK,aAAa,EAAE,OAAO,EAAE,QAAQ,IAAI,EAAE;AACtE,MAAE,KAAK,KAAK,IAAI,KAAK,IAAI;AACzB,MAAE,KAAK,KAAK,IAAI,KAAK,IAAI;AAGzB,UAAM,WAAW,EAAE,cAAc,KAAK,aAAa,EAAE,UAAU,EAAE,WAAW,IAAI,EAAE;AAClF,MAAE,OAAO;AACT,MAAE,UAAU;AAGZ,MAAE,YAAY,EAAE,aAAa;AAC7B,MAAE,UAAU,EAAE,WAAW;AAGzB,MAAE,aAAa,EAAE,cAAc;AAC/B,MAAE,WAAW,EAAE,YAAY;AAG3B,QAAI,EAAE,YAAY;AAChB,QAAE,SAAS,EAAE,WAAW;AACxB,QAAE,SAAS,EAAE,WAAW;AACxB,QAAE,SAAS,EAAE,WAAW;AAAA,IAC1B;AACA,QAAI,EAAE,UAAU;AACd,QAAE,OAAO,EAAE,SAAS;AACpB,QAAE,OAAO,EAAE,SAAS;AACpB,QAAE,OAAO,EAAE,SAAS;AAAA,IACtB;AAGA,QAAI,EAAE,oBAAoB,QAAW;AACnC,QAAE,kBAAkB,EAAE,qBAClB,KAAK,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,IACzD,EAAE;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"file":"index.js","names":["Pool"],"sources":["../src/particle-pool.ts","../src/particle-emitter.ts"],"sourcesContent":["import { Pool } from '@flare-engine/core';\nimport type { Color } from '@flare-engine/math';\n\n/** A single particle. Managed by ParticlePool — not user-facing. */\nexport interface Particle {\n /** World position. */\n x: number;\n y: number;\n /** Velocity in pixels/second. */\n vx: number;\n vy: number;\n /** Time remaining in seconds. */\n life: number;\n /** Total lifetime for interpolation. */\n maxLife: number;\n /** Start/end size for interpolation. */\n startSize: number;\n endSize: number;\n /** Start/end alpha for interpolation. */\n startAlpha: number;\n endAlpha: number;\n /** Start/end color components for interpolation. */\n startR: number;\n startG: number;\n startB: number;\n endR: number;\n endG: number;\n endB: number;\n /** Rotation in radians. */\n rotation: number;\n /** Angular velocity in radians/second. */\n angularVelocity: number;\n /** Whether this particle is active. */\n active: boolean;\n}\n\n/** Create a default (inactive) particle. */\nfunction createParticle(): Particle {\n return {\n x: 0,\n y: 0,\n vx: 0,\n vy: 0,\n life: 0,\n maxLife: 0,\n startSize: 1,\n endSize: 1,\n startAlpha: 1,\n endAlpha: 0,\n startR: 1,\n startG: 1,\n startB: 1,\n endR: 1,\n endG: 1,\n endB: 1,\n rotation: 0,\n angularVelocity: 0,\n active: false,\n };\n}\n\n/** Reset a particle to default (inactive) state. */\nfunction resetParticle(p: Particle): void {\n p.x = 0;\n p.y = 0;\n p.vx = 0;\n p.vy = 0;\n p.life = 0;\n p.maxLife = 0;\n p.startSize = 1;\n p.endSize = 1;\n p.startAlpha = 1;\n p.endAlpha = 0;\n p.startR = 1;\n p.startG = 1;\n p.startB = 1;\n p.endR = 1;\n p.endG = 1;\n p.endB = 1;\n p.rotation = 0;\n p.angularVelocity = 0;\n p.active = false;\n}\n\n/**\n * ParticlePool — pre-allocated pool of particles.\n * Zero GC pressure during steady-state gameplay.\n */\nexport class ParticlePool {\n private _pool: Pool<Particle>;\n private _active: Particle[] = [];\n\n constructor(capacity = 256) {\n this._pool = new Pool(createParticle, resetParticle, { capacity });\n this._pool.prewarm(capacity);\n }\n\n /** Number of currently active particles. */\n get activeCount(): number {\n return this._active.length;\n }\n\n /**\n * Cumulative factory calls made by the internal pool's acquire()/tryAcquire().\n * prewarm() is excluded: factory calls there pre-fill the free list and are\n * not counted. Intended use: snapshot before and after a frame — a non-zero\n * delta in steady state means unexpected allocation.\n */\n get created(): number {\n return this._pool.created;\n }\n\n /** Read-only access to active particles. */\n get particles(): readonly Particle[] {\n return this._active;\n }\n\n /** Acquire a particle from the pool. */\n acquire(): Particle {\n const p = this._pool.acquire();\n p.active = true;\n this._active.push(p);\n return p;\n }\n\n /**\n * Acquire a particle only if the pool is below capacity.\n * Returns null at cap — no allocation occurs.\n */\n tryAcquire(): Particle | null {\n const p = this._pool.tryAcquire();\n if (!p) return null;\n p.active = true;\n this._active.push(p);\n return p;\n }\n\n /** Update all active particles. Releases dead particles. */\n update(dt: number, gravityX: number, gravityY: number): void {\n let i = 0;\n while (i < this._active.length) {\n const p = this._active[i]!;\n p.life -= dt;\n\n if (p.life <= 0) {\n // Dead — release and swap-remove\n p.active = false;\n this._pool.release(p);\n this._active[i] = this._active[this._active.length - 1]!;\n this._active.pop();\n continue;\n }\n\n // Apply gravity\n p.vx += gravityX * dt;\n p.vy += gravityY * dt;\n\n // Integrate position\n p.x += p.vx * dt;\n p.y += p.vy * dt;\n\n // Rotate\n p.rotation += p.angularVelocity * dt;\n\n i++;\n }\n }\n\n /** Get interpolated size for a particle (0 = start, 1 = end of life). */\n getSize(p: Particle): number {\n const t = 1 - p.life / p.maxLife;\n return p.startSize + (p.endSize - p.startSize) * t;\n }\n\n /** Get interpolated alpha for a particle. */\n getAlpha(p: Particle): number {\n const t = 1 - p.life / p.maxLife;\n return p.startAlpha + (p.endAlpha - p.startAlpha) * t;\n }\n\n /** Shared color buffer — avoids per-call allocation in the render hot path. */\n private _colorBuf: Color = { r: 1, g: 1, b: 1, a: 1 };\n\n /**\n * Get interpolated color for a particle.\n *\n * Returns a shared buffer — read the values immediately, do not retain the\n * reference. For a fresh object call `getColorInto()` with your own out param.\n */\n getColor(p: Particle): Color {\n return this.getColorInto(p, this._colorBuf);\n }\n\n /** Zero-alloc variant — writes the interpolated color into `out`. */\n getColorInto(p: Particle, out: Color): Color {\n const t = 1 - p.life / p.maxLife;\n out.r = p.startR + (p.endR - p.startR) * t;\n out.g = p.startG + (p.endG - p.startG) * t;\n out.b = p.startB + (p.endB - p.startB) * t;\n out.a = p.startAlpha + (p.endAlpha - p.startAlpha) * t;\n return out;\n }\n\n /** Release all active particles back to pool. */\n clear(): void {\n for (const p of this._active) {\n p.active = false;\n this._pool.release(p);\n }\n this._active.length = 0;\n }\n}\n","import type { Color } from '@flare-engine/math';\nimport type { Particle } from './particle-pool.js';\nimport { ParticlePool } from './particle-pool.js';\n\n/** Configuration for a ParticleEmitter. */\nexport interface EmitterConfig {\n /** Emission rate in particles per second. */\n rate: number;\n /** Particle lifetime in seconds. */\n lifetime: number;\n /** Min lifetime (if set, actual lifetime is random between lifetime and lifetimeMax). */\n lifetimeMax?: number;\n /** Initial speed in pixels/second. */\n speed: number;\n /** Max speed (random range). */\n speedMax?: number;\n /** Emission direction in radians (0 = right). */\n direction: number;\n /** Spread angle in radians (half-angle of the emission cone). */\n spread: number;\n /** Gravity in pixels/second² (applied each frame). */\n gravityX?: number;\n gravityY?: number;\n /** Start size and end size. */\n startSize?: number;\n endSize?: number;\n /** Start alpha and end alpha. */\n startAlpha?: number;\n endAlpha?: number;\n /** Start color. */\n startColor?: Color;\n /** End color. */\n endColor?: Color;\n /** Angular velocity range (radians/second). */\n angularVelocity?: number;\n angularVelocityMax?: number;\n /** Maximum active particles (used as pool capacity default when no opts.maxParticles given). */\n maxParticles?: number;\n}\n\n/** Construction options for ParticleEmitter. */\nexport interface EmitterOptions {\n /**\n * Hard cap on simultaneously active particles.\n * Overrides config.maxParticles when provided.\n * Defaults to config.maxParticles ?? 256.\n */\n maxParticles?: number;\n /**\n * Initial LCG seed for deterministic particle randomness.\n * Defaults to 1. Call reseed() at any time to restart the sequence.\n */\n seed?: number;\n}\n\n/**\n * ParticleEmitter — emits particles based on a configuration.\n * Uses a ParticlePool for zero-GC operation.\n *\n * Call `update(dt)` each frame. Read `pool.particles` for rendering.\n */\nexport class ParticleEmitter {\n readonly config: EmitterConfig;\n readonly pool: ParticlePool;\n\n /** Emitter world position. */\n x = 0;\n y = 0;\n\n /** Whether the emitter is actively emitting. */\n emitting = true;\n\n private _emitAccumulator = 0;\n private _seed = 0;\n\n constructor(config: EmitterConfig, opts?: EmitterOptions) {\n this.config = config;\n const cap = opts?.maxParticles ?? config.maxParticles ?? 256;\n this.pool = new ParticlePool(cap);\n this._setSeed(opts?.seed ?? 1);\n }\n\n /** Reset the LCG seed — restarts the particle random sequence from this seed. */\n reseed(seed: number): void {\n this._setSeed(seed);\n }\n\n /** Normalize s into the valid Park-Miller domain [1, 2147483646]. */\n private _setSeed(s: number): void {\n let n = Number.isFinite(s) ? Math.floor(s) % 2147483647 : 0;\n if (n < 0) n += 2147483647;\n if (n === 0) n = 1;\n this._seed = n;\n }\n\n /** Update the emitter: emit new particles and update existing ones. */\n update(dt: number): void {\n if (this.emitting) {\n this._emitAccumulator += dt * this.config.rate;\n while (this._emitAccumulator >= 1) {\n this._emitAccumulator -= 1;\n if (!this._emitOne()) {\n this._emitAccumulator = 0;\n break;\n }\n }\n }\n\n this.pool.update(dt, this.config.gravityX ?? 0, this.config.gravityY ?? 0);\n }\n\n /** Emit a burst of particles. */\n burst(count: number): void {\n for (let i = 0; i < count; i++) {\n if (!this._emitOne()) break;\n }\n }\n\n /** Stop emitting and clear all particles. */\n reset(): void {\n this.emitting = false;\n this._emitAccumulator = 0;\n this.pool.clear();\n }\n\n /** Simple seeded pseudo-random for deterministic particles. */\n private _random(): number {\n this._seed = (this._seed * 16807) % 2147483647;\n return (this._seed - 1) / 2147483646;\n }\n\n /** Random float in [min, max]. */\n private _randomRange(min: number, max: number): number {\n return min + this._random() * (max - min);\n }\n\n /** Emit one particle. Returns false when the pool is at cap — caller should stop. */\n private _emitOne(): boolean {\n const p: Particle | null = this.pool.tryAcquire();\n if (!p) return false;\n\n const c = this.config;\n\n p.x = this.x;\n p.y = this.y;\n\n const angle = c.direction + this._randomRange(-c.spread, c.spread);\n const speed = c.speedMax ? this._randomRange(c.speed, c.speedMax) : c.speed;\n p.vx = Math.cos(angle) * speed;\n p.vy = Math.sin(angle) * speed;\n\n const lifetime = c.lifetimeMax ? this._randomRange(c.lifetime, c.lifetimeMax) : c.lifetime;\n p.life = lifetime;\n p.maxLife = lifetime;\n\n p.startSize = c.startSize ?? 4;\n p.endSize = c.endSize ?? 0;\n\n p.startAlpha = c.startAlpha ?? 1;\n p.endAlpha = c.endAlpha ?? 0;\n\n if (c.startColor) {\n p.startR = c.startColor.r;\n p.startG = c.startColor.g;\n p.startB = c.startColor.b;\n }\n if (c.endColor) {\n p.endR = c.endColor.r;\n p.endG = c.endColor.g;\n p.endB = c.endColor.b;\n }\n\n if (c.angularVelocity !== undefined) {\n p.angularVelocity = c.angularVelocityMax\n ? this._randomRange(c.angularVelocity, c.angularVelocityMax)\n : c.angularVelocity;\n }\n\n return true;\n }\n}\n"],"mappings":";;;;AAqCA,SAAS,iBAA2B;CAClC,OAAO;EACL,GAAG;EACH,GAAG;EACH,IAAI;EACJ,IAAI;EACJ,MAAM;EACN,SAAS;EACT,WAAW;EACX,SAAS;EACT,YAAY;EACZ,UAAU;EACV,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,MAAM;EACN,MAAM;EACN,MAAM;EACN,UAAU;EACV,iBAAiB;EACjB,QAAQ;CACV;AACF;;AAGA,SAAS,cAAc,GAAmB;CACxC,EAAE,IAAI;CACN,EAAE,IAAI;CACN,EAAE,KAAK;CACP,EAAE,KAAK;CACP,EAAE,OAAO;CACT,EAAE,UAAU;CACZ,EAAE,YAAY;CACd,EAAE,UAAU;CACZ,EAAE,aAAa;CACf,EAAE,WAAW;CACb,EAAE,SAAS;CACX,EAAE,SAAS;CACX,EAAE,SAAS;CACX,EAAE,OAAO;CACT,EAAE,OAAO;CACT,EAAE,OAAO;CACT,EAAE,WAAW;CACb,EAAE,kBAAkB;CACpB,EAAE,SAAS;AACb;;;;;AAMA,IAAa,eAAb,MAA0B;CACxB;CACA,UAA8B,CAAC;CAE/B,YAAY,WAAW,KAAK;EAC1B,KAAK,QAAQ,IA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