@flare-engine/particles 0.2.1 → 0.3.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/dist/index.mjs CHANGED
@@ -1,217 +1,263 @@
1
- // src/particle-pool.ts
2
1
  import { Pool } from "@flare-engine/core";
2
+ //#region src/particle-pool.ts
3
+ /** Create a default (inactive) particle. */
3
4
  function createParticle() {
4
- return {
5
- x: 0,
6
- y: 0,
7
- vx: 0,
8
- vy: 0,
9
- life: 0,
10
- maxLife: 0,
11
- startSize: 1,
12
- endSize: 1,
13
- startAlpha: 1,
14
- endAlpha: 0,
15
- startR: 1,
16
- startG: 1,
17
- startB: 1,
18
- endR: 1,
19
- endG: 1,
20
- endB: 1,
21
- rotation: 0,
22
- angularVelocity: 0,
23
- active: false
24
- };
5
+ return {
6
+ x: 0,
7
+ y: 0,
8
+ vx: 0,
9
+ vy: 0,
10
+ life: 0,
11
+ maxLife: 0,
12
+ startSize: 1,
13
+ endSize: 1,
14
+ startAlpha: 1,
15
+ endAlpha: 0,
16
+ startR: 1,
17
+ startG: 1,
18
+ startB: 1,
19
+ endR: 1,
20
+ endG: 1,
21
+ endB: 1,
22
+ rotation: 0,
23
+ angularVelocity: 0,
24
+ active: false
25
+ };
25
26
  }
27
+ /** Reset a particle to default (inactive) state. */
26
28
  function resetParticle(p) {
27
- p.x = 0;
28
- p.y = 0;
29
- p.vx = 0;
30
- p.vy = 0;
31
- p.life = 0;
32
- p.maxLife = 0;
33
- p.startSize = 1;
34
- p.endSize = 1;
35
- p.startAlpha = 1;
36
- p.endAlpha = 0;
37
- p.startR = 1;
38
- p.startG = 1;
39
- p.startB = 1;
40
- p.endR = 1;
41
- p.endG = 1;
42
- p.endB = 1;
43
- p.rotation = 0;
44
- p.angularVelocity = 0;
45
- p.active = false;
29
+ p.x = 0;
30
+ p.y = 0;
31
+ p.vx = 0;
32
+ p.vy = 0;
33
+ p.life = 0;
34
+ p.maxLife = 0;
35
+ p.startSize = 1;
36
+ p.endSize = 1;
37
+ p.startAlpha = 1;
38
+ p.endAlpha = 0;
39
+ p.startR = 1;
40
+ p.startG = 1;
41
+ p.startB = 1;
42
+ p.endR = 1;
43
+ p.endG = 1;
44
+ p.endB = 1;
45
+ p.rotation = 0;
46
+ p.angularVelocity = 0;
47
+ p.active = false;
46
48
  }
49
+ /**
50
+ * ParticlePool — pre-allocated pool of particles.
51
+ * Zero GC pressure during steady-state gameplay.
52
+ */
47
53
  var ParticlePool = class {
48
- _pool;
49
- _active = [];
50
- constructor(capacity = 256) {
51
- this._pool = new Pool(createParticle, resetParticle);
52
- this._pool.prewarm(capacity);
53
- }
54
- /** Number of currently active particles. */
55
- get activeCount() {
56
- return this._active.length;
57
- }
58
- /** Read-only access to active particles. */
59
- get particles() {
60
- return this._active;
61
- }
62
- /** Acquire a particle from the pool. */
63
- acquire() {
64
- const p = this._pool.acquire();
65
- p.active = true;
66
- this._active.push(p);
67
- return p;
68
- }
69
- /** Update all active particles. Releases dead particles. */
70
- update(dt, gravityX, gravityY) {
71
- let i = 0;
72
- while (i < this._active.length) {
73
- const p = this._active[i];
74
- p.life -= dt;
75
- if (p.life <= 0) {
76
- p.active = false;
77
- this._pool.release(p);
78
- this._active[i] = this._active[this._active.length - 1];
79
- this._active.pop();
80
- continue;
81
- }
82
- p.vx += gravityX * dt;
83
- p.vy += gravityY * dt;
84
- p.x += p.vx * dt;
85
- p.y += p.vy * dt;
86
- p.rotation += p.angularVelocity * dt;
87
- i++;
88
- }
89
- }
90
- /** Get interpolated size for a particle (0 = start, 1 = end of life). */
91
- getSize(p) {
92
- const t = 1 - p.life / p.maxLife;
93
- return p.startSize + (p.endSize - p.startSize) * t;
94
- }
95
- /** Get interpolated alpha for a particle. */
96
- getAlpha(p) {
97
- const t = 1 - p.life / p.maxLife;
98
- return p.startAlpha + (p.endAlpha - p.startAlpha) * t;
99
- }
100
- /** Shared color buffer — avoids per-call allocation in the render hot path. */
101
- _colorBuf = { r: 1, g: 1, b: 1, a: 1 };
102
- /**
103
- * Get interpolated color for a particle.
104
- *
105
- * Returns a shared buffer — read the values immediately, do not retain the
106
- * reference. For a fresh object call `getColorInto()` with your own out param.
107
- */
108
- getColor(p) {
109
- return this.getColorInto(p, this._colorBuf);
110
- }
111
- /** Zero-alloc variant — writes the interpolated color into `out`. */
112
- getColorInto(p, out) {
113
- const t = 1 - p.life / p.maxLife;
114
- out.r = p.startR + (p.endR - p.startR) * t;
115
- out.g = p.startG + (p.endG - p.startG) * t;
116
- out.b = p.startB + (p.endB - p.startB) * t;
117
- out.a = p.startAlpha + (p.endAlpha - p.startAlpha) * t;
118
- return out;
119
- }
120
- /** Release all active particles back to pool. */
121
- clear() {
122
- for (const p of this._active) {
123
- p.active = false;
124
- this._pool.release(p);
125
- }
126
- this._active.length = 0;
127
- }
54
+ _pool;
55
+ _active = [];
56
+ constructor(capacity = 256) {
57
+ this._pool = new Pool(createParticle, resetParticle, { capacity });
58
+ this._pool.prewarm(capacity);
59
+ }
60
+ /** Number of currently active particles. */
61
+ get activeCount() {
62
+ return this._active.length;
63
+ }
64
+ /**
65
+ * Cumulative factory calls made by the internal pool's acquire()/tryAcquire().
66
+ * prewarm() is excluded: factory calls there pre-fill the free list and are
67
+ * not counted. Intended use: snapshot before and after a frame — a non-zero
68
+ * delta in steady state means unexpected allocation.
69
+ */
70
+ get created() {
71
+ return this._pool.created;
72
+ }
73
+ /** Read-only access to active particles. */
74
+ get particles() {
75
+ return this._active;
76
+ }
77
+ /** Acquire a particle from the pool. */
78
+ acquire() {
79
+ const p = this._pool.acquire();
80
+ p.active = true;
81
+ this._active.push(p);
82
+ return p;
83
+ }
84
+ /**
85
+ * Acquire a particle only if the pool is below capacity.
86
+ * Returns null at cap — no allocation occurs.
87
+ */
88
+ tryAcquire() {
89
+ const p = this._pool.tryAcquire();
90
+ if (!p) return null;
91
+ p.active = true;
92
+ this._active.push(p);
93
+ return p;
94
+ }
95
+ /** Update all active particles. Releases dead particles. */
96
+ update(dt, gravityX, gravityY) {
97
+ let i = 0;
98
+ while (i < this._active.length) {
99
+ const p = this._active[i];
100
+ p.life -= dt;
101
+ if (p.life <= 0) {
102
+ p.active = false;
103
+ this._pool.release(p);
104
+ this._active[i] = this._active[this._active.length - 1];
105
+ this._active.pop();
106
+ continue;
107
+ }
108
+ p.vx += gravityX * dt;
109
+ p.vy += gravityY * dt;
110
+ p.x += p.vx * dt;
111
+ p.y += p.vy * dt;
112
+ p.rotation += p.angularVelocity * dt;
113
+ i++;
114
+ }
115
+ }
116
+ /** Get interpolated size for a particle (0 = start, 1 = end of life). */
117
+ getSize(p) {
118
+ const t = 1 - p.life / p.maxLife;
119
+ return p.startSize + (p.endSize - p.startSize) * t;
120
+ }
121
+ /** Get interpolated alpha for a particle. */
122
+ getAlpha(p) {
123
+ const t = 1 - p.life / p.maxLife;
124
+ return p.startAlpha + (p.endAlpha - p.startAlpha) * t;
125
+ }
126
+ /** Shared color buffer — avoids per-call allocation in the render hot path. */
127
+ _colorBuf = {
128
+ r: 1,
129
+ g: 1,
130
+ b: 1,
131
+ a: 1
132
+ };
133
+ /**
134
+ * Get interpolated color for a particle.
135
+ *
136
+ * Returns a shared buffer — read the values immediately, do not retain the
137
+ * reference. For a fresh object call `getColorInto()` with your own out param.
138
+ */
139
+ getColor(p) {
140
+ return this.getColorInto(p, this._colorBuf);
141
+ }
142
+ /** Zero-alloc variant — writes the interpolated color into `out`. */
143
+ getColorInto(p, out) {
144
+ const t = 1 - p.life / p.maxLife;
145
+ out.r = p.startR + (p.endR - p.startR) * t;
146
+ out.g = p.startG + (p.endG - p.startG) * t;
147
+ out.b = p.startB + (p.endB - p.startB) * t;
148
+ out.a = p.startAlpha + (p.endAlpha - p.startAlpha) * t;
149
+ return out;
150
+ }
151
+ /** Release all active particles back to pool. */
152
+ clear() {
153
+ for (const p of this._active) {
154
+ p.active = false;
155
+ this._pool.release(p);
156
+ }
157
+ this._active.length = 0;
158
+ }
128
159
  };
129
-
130
- // src/particle-emitter.ts
160
+ //#endregion
161
+ //#region src/particle-emitter.ts
162
+ /**
163
+ * ParticleEmitter — emits particles based on a configuration.
164
+ * Uses a ParticlePool for zero-GC operation.
165
+ *
166
+ * Call `update(dt)` each frame. Read `pool.particles` for rendering.
167
+ */
131
168
  var ParticleEmitter = class {
132
- config;
133
- pool;
134
- /** Emitter world position. */
135
- x = 0;
136
- y = 0;
137
- /** Whether the emitter is actively emitting. */
138
- emitting = true;
139
- _emitAccumulator = 0;
140
- _seed = 1;
141
- constructor(config, maxParticles) {
142
- this.config = config;
143
- this.pool = new ParticlePool(maxParticles ?? config.maxParticles ?? 256);
144
- }
145
- /** Update the emitter: emit new particles and update existing ones. */
146
- update(dt) {
147
- if (this.emitting) {
148
- this._emitAccumulator += dt * this.config.rate;
149
- while (this._emitAccumulator >= 1) {
150
- this._emitAccumulator -= 1;
151
- if (this.config.maxParticles && this.pool.activeCount >= this.config.maxParticles) {
152
- this._emitAccumulator = 0;
153
- break;
154
- }
155
- this._emitOne();
156
- }
157
- }
158
- this.pool.update(dt, this.config.gravityX ?? 0, this.config.gravityY ?? 0);
159
- }
160
- /** Emit a burst of particles. */
161
- burst(count) {
162
- for (let i = 0; i < count; i++) {
163
- if (this.config.maxParticles && this.pool.activeCount >= this.config.maxParticles) break;
164
- this._emitOne();
165
- }
166
- }
167
- /** Stop emitting and clear all particles. */
168
- reset() {
169
- this.emitting = false;
170
- this._emitAccumulator = 0;
171
- this.pool.clear();
172
- }
173
- /** Simple seeded pseudo-random for deterministic particles. */
174
- _random() {
175
- this._seed = this._seed * 16807 % 2147483647;
176
- return (this._seed - 1) / 2147483646;
177
- }
178
- /** Random float in [min, max]. */
179
- _randomRange(min, max) {
180
- return min + this._random() * (max - min);
181
- }
182
- _emitOne() {
183
- const c = this.config;
184
- const p = this.pool.acquire();
185
- p.x = this.x;
186
- p.y = this.y;
187
- const angle = c.direction + this._randomRange(-c.spread, c.spread);
188
- const speed = c.speedMax ? this._randomRange(c.speed, c.speedMax) : c.speed;
189
- p.vx = Math.cos(angle) * speed;
190
- p.vy = Math.sin(angle) * speed;
191
- const lifetime = c.lifetimeMax ? this._randomRange(c.lifetime, c.lifetimeMax) : c.lifetime;
192
- p.life = lifetime;
193
- p.maxLife = lifetime;
194
- p.startSize = c.startSize ?? 4;
195
- p.endSize = c.endSize ?? 0;
196
- p.startAlpha = c.startAlpha ?? 1;
197
- p.endAlpha = c.endAlpha ?? 0;
198
- if (c.startColor) {
199
- p.startR = c.startColor.r;
200
- p.startG = c.startColor.g;
201
- p.startB = c.startColor.b;
202
- }
203
- if (c.endColor) {
204
- p.endR = c.endColor.r;
205
- p.endG = c.endColor.g;
206
- p.endB = c.endColor.b;
207
- }
208
- if (c.angularVelocity !== void 0) {
209
- p.angularVelocity = c.angularVelocityMax ? this._randomRange(c.angularVelocity, c.angularVelocityMax) : c.angularVelocity;
210
- }
211
- }
212
- };
213
- export {
214
- ParticleEmitter,
215
- ParticlePool
169
+ config;
170
+ pool;
171
+ /** Emitter world position. */
172
+ x = 0;
173
+ y = 0;
174
+ /** Whether the emitter is actively emitting. */
175
+ emitting = true;
176
+ _emitAccumulator = 0;
177
+ _seed = 0;
178
+ constructor(config, opts) {
179
+ this.config = config;
180
+ const cap = opts?.maxParticles ?? config.maxParticles ?? 256;
181
+ this.pool = new ParticlePool(cap);
182
+ this._setSeed(opts?.seed ?? 1);
183
+ }
184
+ /** Reset the LCG seed — restarts the particle random sequence from this seed. */
185
+ reseed(seed) {
186
+ this._setSeed(seed);
187
+ }
188
+ /** Normalize s into the valid Park-Miller domain [1, 2147483646]. */
189
+ _setSeed(s) {
190
+ let n = Number.isFinite(s) ? Math.floor(s) % 2147483647 : 0;
191
+ if (n < 0) n += 2147483647;
192
+ if (n === 0) n = 1;
193
+ this._seed = n;
194
+ }
195
+ /** Update the emitter: emit new particles and update existing ones. */
196
+ update(dt) {
197
+ if (this.emitting) {
198
+ this._emitAccumulator += dt * this.config.rate;
199
+ while (this._emitAccumulator >= 1) {
200
+ this._emitAccumulator -= 1;
201
+ if (!this._emitOne()) {
202
+ this._emitAccumulator = 0;
203
+ break;
204
+ }
205
+ }
206
+ }
207
+ this.pool.update(dt, this.config.gravityX ?? 0, this.config.gravityY ?? 0);
208
+ }
209
+ /** Emit a burst of particles. */
210
+ burst(count) {
211
+ for (let i = 0; i < count; i++) if (!this._emitOne()) break;
212
+ }
213
+ /** Stop emitting and clear all particles. */
214
+ reset() {
215
+ this.emitting = false;
216
+ this._emitAccumulator = 0;
217
+ this.pool.clear();
218
+ }
219
+ /** Simple seeded pseudo-random for deterministic particles. */
220
+ _random() {
221
+ this._seed = this._seed * 16807 % 2147483647;
222
+ return (this._seed - 1) / 2147483646;
223
+ }
224
+ /** Random float in [min, max]. */
225
+ _randomRange(min, max) {
226
+ return min + this._random() * (max - min);
227
+ }
228
+ /** Emit one particle. Returns false when the pool is at cap — caller should stop. */
229
+ _emitOne() {
230
+ const p = this.pool.tryAcquire();
231
+ if (!p) return false;
232
+ const c = this.config;
233
+ p.x = this.x;
234
+ p.y = this.y;
235
+ const angle = c.direction + this._randomRange(-c.spread, c.spread);
236
+ const speed = c.speedMax ? this._randomRange(c.speed, c.speedMax) : c.speed;
237
+ p.vx = Math.cos(angle) * speed;
238
+ p.vy = Math.sin(angle) * speed;
239
+ const lifetime = c.lifetimeMax ? this._randomRange(c.lifetime, c.lifetimeMax) : c.lifetime;
240
+ p.life = lifetime;
241
+ p.maxLife = lifetime;
242
+ p.startSize = c.startSize ?? 4;
243
+ p.endSize = c.endSize ?? 0;
244
+ p.startAlpha = c.startAlpha ?? 1;
245
+ p.endAlpha = c.endAlpha ?? 0;
246
+ if (c.startColor) {
247
+ p.startR = c.startColor.r;
248
+ p.startG = c.startColor.g;
249
+ p.startB = c.startColor.b;
250
+ }
251
+ if (c.endColor) {
252
+ p.endR = c.endColor.r;
253
+ p.endG = c.endColor.g;
254
+ p.endB = c.endColor.b;
255
+ }
256
+ if (c.angularVelocity !== void 0) p.angularVelocity = c.angularVelocityMax ? this._randomRange(c.angularVelocity, c.angularVelocityMax) : c.angularVelocity;
257
+ return true;
258
+ }
216
259
  };
260
+ //#endregion
261
+ export { ParticleEmitter, ParticlePool };
262
+
217
263
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"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);\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,SAAS,YAAY;AAqCrB,SAAS,iBAA2B;AAClC,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,IACH,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,MAAM;AAAA,IACN,SAAS;AAAA,IACT,WAAW;AAAA,IACX,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,UAAU;AAAA,IACV,iBAAiB;AAAA,IACjB,QAAQ;AAAA,EACV;AACF;AAGA,SAAS,cAAc,GAAmB;AACxC,IAAE,IAAI;AACN,IAAE,IAAI;AACN,IAAE,KAAK;AACP,IAAE,KAAK;AACP,IAAE,OAAO;AACT,IAAE,UAAU;AACZ,IAAE,YAAY;AACd,IAAE,UAAU;AACZ,IAAE,aAAa;AACf,IAAE,WAAW;AACb,IAAE,SAAS;AACX,IAAE,SAAS;AACX,IAAE,SAAS;AACX,IAAE,OAAO;AACT,IAAE,OAAO;AACT,IAAE,OAAO;AACT,IAAE,WAAW;AACb,IAAE,kBAAkB;AACpB,IAAE,SAAS;AACb;AAMO,IAAM,eAAN,MAAmB;AAAA,EAChB;AAAA,EACA,UAAsB,CAAC;AAAA,EAE/B,YAAY,WAAW,KAAK;AAC1B,SAAK,QAAQ,IAAI,KAAK,gBAAgB,aAAa;AACnD,SAAK,MAAM,QAAQ,QAAQ;AAAA,EAC7B;AAAA;AAAA,EAGA,IAAI,cAAsB;AACxB,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA;AAAA,EAGA,IAAI,YAAiC;AACnC,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EA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E,kBAAkB,IACzD,EAAE;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"file":"index.mjs","names":[],"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,aAA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E,UAAU,EAAE,WAAW,IAAI,EAAE;EAClF,EAAE,OAAO;EACT,EAAE,UAAU;EAEZ,EAAE,YAAY,EAAE,aAAa;EAC7B,EAAE,UAAU,EAAE,WAAW;EAEzB,EAAE,aAAa,EAAE,cAAc;EAC/B,EAAE,WAAW,EAAE,YAAY;EAE3B,IAAI,EAAE,YAAY;GAChB,EAAE,SAAS,EAAE,WAAW;GACxB,EAAE,SAAS,EAAE,WAAW;GACxB,EAAE,SAAS,EAAE,WAAW;EAC1B;EACA,IAAI,EAAE,UAAU;GACd,EAAE,OAAO,EAAE,SAAS;GACpB,EAAE,OAAO,EAAE,SAAS;GACpB,EAAE,OAAO,EAAE,SAAS;EACtB;EAEA,IAAI,EAAE,oBAAoB,KAAA,GACxB,EAAE,kBAAkB,EAAE,qBAClB,KAAK,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,IACzD,EAAE;EAGR,OAAO;CACT;AACF"}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@flare-engine/particles",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "description": "Particle emitter, pool, immediate-mode Skia rendering",
5
5
  "keywords": ["flare-engine", "particles", "emitter", "skia"],
6
- "license": "MIT",
6
+ "license": "Apache-2.0",
7
7
  "author": "Grzegorz Otto",
8
8
  "homepage": "https://github.com/grzott/flare-engine#readme",
9
9
  "bugs": {
@@ -19,21 +19,29 @@
19
19
  "types": "dist/index.d.ts",
20
20
  "exports": {
21
21
  ".": {
22
- "types": "./dist/index.d.ts",
23
- "import": "./dist/index.mjs",
24
- "require": "./dist/index.js"
22
+ "import": {
23
+ "types": "./dist/index.d.mts",
24
+ "default": "./dist/index.mjs"
25
+ },
26
+ "require": {
27
+ "types": "./dist/index.d.ts",
28
+ "default": "./dist/index.js"
29
+ }
25
30
  }
26
31
  },
27
- "files": ["dist", "README.md", "LICENSE"],
32
+ "files": ["dist", "README.md", "LICENSE", "NOTICE"],
28
33
  "scripts": {
29
- "build": "tsup",
34
+ "build": "tsdown",
30
35
  "test": "bun test",
31
36
  "lint": "biome check src/",
32
37
  "typecheck": "tsc --noEmit"
33
38
  },
34
39
  "dependencies": {
35
- "@flare-engine/core": "^0.2.1",
36
- "@flare-engine/math": "^0.2.1"
40
+ "@flare-engine/core": "^0.3.1",
41
+ "@flare-engine/math": "^0.3.1"
42
+ },
43
+ "engines": {
44
+ "node": ">=20"
37
45
  },
38
46
  "publishConfig": {
39
47
  "access": "restricted",