@flare-engine/particles 0.4.5 → 0.4.7
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.d.mts +7 -15
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +7 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Color } from "@flare-engine/math";
|
|
2
|
-
//#region src/particle-pool.d.ts
|
|
3
2
|
/** A single particle. Managed by ParticlePool — not user-facing. */
|
|
4
3
|
interface Particle {
|
|
5
4
|
/** World position. */
|
|
@@ -36,7 +35,7 @@ interface Particle {
|
|
|
36
35
|
* ParticlePool — pre-allocated pool of particles.
|
|
37
36
|
* Zero GC pressure during steady-state gameplay.
|
|
38
37
|
*/
|
|
39
|
-
declare class ParticlePool {
|
|
38
|
+
export declare class ParticlePool {
|
|
40
39
|
private _pool;
|
|
41
40
|
private _active;
|
|
42
41
|
constructor(capacity?: number);
|
|
@@ -78,8 +77,6 @@ declare class ParticlePool {
|
|
|
78
77
|
/** Release all active particles back to pool. */
|
|
79
78
|
clear(): void;
|
|
80
79
|
}
|
|
81
|
-
//#endregion
|
|
82
|
-
//#region src/draw-particles.d.ts
|
|
83
80
|
/**
|
|
84
81
|
* The frame rectangle within a texture. Structural on purpose: it matches
|
|
85
82
|
* `SpriteFrame` from `@flare-engine/assets` without this package depending on
|
|
@@ -148,9 +145,7 @@ interface DrawParticlesOptions {
|
|
|
148
145
|
* everywhere else in the engine — a frame is a rectangle within a texture and
|
|
149
146
|
* does not carry the texture.
|
|
150
147
|
*/
|
|
151
|
-
declare function drawParticles(pool: ParticlePool, batch: ParticleBatchLike, image: unknown, frame: ParticleFrameLike, options?: DrawParticlesOptions): void;
|
|
152
|
-
//#endregion
|
|
153
|
-
//#region src/emitter-shape.d.ts
|
|
148
|
+
export declare function drawParticles(pool: ParticlePool, batch: ParticleBatchLike, image: unknown, frame: ParticleFrameLike, options?: DrawParticlesOptions): void;
|
|
154
149
|
/**
|
|
155
150
|
* Emitter shapes — where a particle starts, not where it goes.
|
|
156
151
|
*
|
|
@@ -219,14 +214,14 @@ interface ShapeSample {
|
|
|
219
214
|
ny: number;
|
|
220
215
|
}
|
|
221
216
|
/** A fresh, zeroed sample. Allocate once outside the loop and reuse. */
|
|
222
|
-
declare function createShapeSample(): ShapeSample;
|
|
217
|
+
export declare function createShapeSample(): ShapeSample;
|
|
223
218
|
/**
|
|
224
219
|
* Does this shape produce a usable outward normal?
|
|
225
220
|
*
|
|
226
221
|
* True only when the shape is radial *and* opted in. Lets a caller decide
|
|
227
222
|
* between the normal and `config.direction` without inspecting the union.
|
|
228
223
|
*/
|
|
229
|
-
declare function hasRadialNormal(shape: EmitterShape): boolean;
|
|
224
|
+
export declare function hasRadialNormal(shape: EmitterShape): boolean;
|
|
230
225
|
/**
|
|
231
226
|
* Sample a spawn offset into `out`. Zero-alloc: nothing is constructed here, so
|
|
232
227
|
* this is safe to call once per emitted particle in a steady-state loop.
|
|
@@ -238,9 +233,7 @@ declare function hasRadialNormal(shape: EmitterShape): boolean;
|
|
|
238
233
|
*
|
|
239
234
|
* `direction` orients `cone` and is ignored by every other shape.
|
|
240
235
|
*/
|
|
241
|
-
declare function sampleEmitterShape(shape: EmitterShape, rand: () => number, out: ShapeSample, direction?: number): ShapeSample;
|
|
242
|
-
//#endregion
|
|
243
|
-
//#region src/particle-emitter.d.ts
|
|
236
|
+
export declare function sampleEmitterShape(shape: EmitterShape, rand: () => number, out: ShapeSample, direction?: number): ShapeSample;
|
|
244
237
|
/** Configuration for a ParticleEmitter. */
|
|
245
238
|
interface EmitterConfig {
|
|
246
239
|
/** Emission rate in particles per second. */
|
|
@@ -305,7 +298,7 @@ interface EmitterOptions {
|
|
|
305
298
|
*
|
|
306
299
|
* Call `update(dt)` each frame. Read `pool.particles` for rendering.
|
|
307
300
|
*/
|
|
308
|
-
declare class ParticleEmitter {
|
|
301
|
+
export declare class ParticleEmitter {
|
|
309
302
|
readonly config: EmitterConfig;
|
|
310
303
|
readonly pool: ParticlePool;
|
|
311
304
|
/** Emitter world position. */
|
|
@@ -337,6 +330,5 @@ declare class ParticleEmitter {
|
|
|
337
330
|
/** Emit one particle. Returns false when the pool is at cap — caller should stop. */
|
|
338
331
|
private _emitOne;
|
|
339
332
|
}
|
|
340
|
-
|
|
341
|
-
export { type DrawParticlesOptions, type EmitterCircleShape, type EmitterConeShape, type EmitterConfig, type EmitterOptions, type EmitterPointShape, type EmitterRectShape, type EmitterRingShape, type EmitterShape, type Particle, type ParticleBatchLike, ParticleEmitter, type ParticleFrameLike, ParticlePool, type ShapeSample, createShapeSample, drawParticles, hasRadialNormal, sampleEmitterShape };
|
|
333
|
+
export type { DrawParticlesOptions, EmitterCircleShape, EmitterConeShape, EmitterConfig, EmitterOptions, EmitterPointShape, EmitterRectShape, EmitterRingShape, EmitterShape, Particle, ParticleBatchLike, ParticleFrameLike, ShapeSample };
|
|
342
334
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/particle-pool.ts","../src/draw-particles.ts","../src/emitter-shape.ts","../src/particle-emitter.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/particle-pool.ts","../src/draw-particles.ts","../src/emitter-shape.ts","../src/particle-emitter.ts"],"mappings":";;UAIiB;;EAEf;EACA;;EAEA;EACA;;EAEA;;EAEA;;EAEA;EACA;;EAEA;EACA;;EAEA;EACA;EACA;EACA;EACA;EACA;;EAEA;;EAEA;;EAEA;;;;;;qBAuDW;UACH;UACA;EAEI,YAAA;;MAMR;;;;;;;MAUA;;MAKA,sBAAsB;;EAK1B,WAAW;;;;;EA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|
|
2
|
-
//#region src/particle-pool.d.ts
|
|
3
2
|
/** A single particle. Managed by ParticlePool — not user-facing. */
|
|
4
3
|
interface Particle {
|
|
5
4
|
/** World position. */
|
|
@@ -36,7 +35,7 @@ interface Particle {
|
|
|
36
35
|
* ParticlePool — pre-allocated pool of particles.
|
|
37
36
|
* Zero GC pressure during steady-state gameplay.
|
|
38
37
|
*/
|
|
39
|
-
declare class ParticlePool {
|
|
38
|
+
export declare class ParticlePool {
|
|
40
39
|
private _pool;
|
|
41
40
|
private _active;
|
|
42
41
|
constructor(capacity?: number);
|
|
@@ -78,8 +77,6 @@ declare class ParticlePool {
|
|
|
78
77
|
/** Release all active particles back to pool. */
|
|
79
78
|
clear(): void;
|
|
80
79
|
}
|
|
81
|
-
//#endregion
|
|
82
|
-
//#region src/draw-particles.d.ts
|
|
83
80
|
/**
|
|
84
81
|
* The frame rectangle within a texture. Structural on purpose: it matches
|
|
85
82
|
* `SpriteFrame` from `@flare-engine/assets` without this package depending on
|
|
@@ -148,9 +145,7 @@ interface DrawParticlesOptions {
|
|
|
148
145
|
* everywhere else in the engine — a frame is a rectangle within a texture and
|
|
149
146
|
* does not carry the texture.
|
|
150
147
|
*/
|
|
151
|
-
declare function drawParticles(pool: ParticlePool, batch: ParticleBatchLike, image: unknown, frame: ParticleFrameLike, options?: DrawParticlesOptions): void;
|
|
152
|
-
//#endregion
|
|
153
|
-
//#region src/emitter-shape.d.ts
|
|
148
|
+
export declare function drawParticles(pool: ParticlePool, batch: ParticleBatchLike, image: unknown, frame: ParticleFrameLike, options?: DrawParticlesOptions): void;
|
|
154
149
|
/**
|
|
155
150
|
* Emitter shapes — where a particle starts, not where it goes.
|
|
156
151
|
*
|
|
@@ -219,14 +214,14 @@ interface ShapeSample {
|
|
|
219
214
|
ny: number;
|
|
220
215
|
}
|
|
221
216
|
/** A fresh, zeroed sample. Allocate once outside the loop and reuse. */
|
|
222
|
-
declare function createShapeSample(): ShapeSample;
|
|
217
|
+
export declare function createShapeSample(): ShapeSample;
|
|
223
218
|
/**
|
|
224
219
|
* Does this shape produce a usable outward normal?
|
|
225
220
|
*
|
|
226
221
|
* True only when the shape is radial *and* opted in. Lets a caller decide
|
|
227
222
|
* between the normal and `config.direction` without inspecting the union.
|
|
228
223
|
*/
|
|
229
|
-
declare function hasRadialNormal(shape: EmitterShape): boolean;
|
|
224
|
+
export declare function hasRadialNormal(shape: EmitterShape): boolean;
|
|
230
225
|
/**
|
|
231
226
|
* Sample a spawn offset into `out`. Zero-alloc: nothing is constructed here, so
|
|
232
227
|
* this is safe to call once per emitted particle in a steady-state loop.
|
|
@@ -238,9 +233,7 @@ declare function hasRadialNormal(shape: EmitterShape): boolean;
|
|
|
238
233
|
*
|
|
239
234
|
* `direction` orients `cone` and is ignored by every other shape.
|
|
240
235
|
*/
|
|
241
|
-
declare function sampleEmitterShape(shape: EmitterShape, rand: () => number, out: ShapeSample, direction?: number): ShapeSample;
|
|
242
|
-
//#endregion
|
|
243
|
-
//#region src/particle-emitter.d.ts
|
|
236
|
+
export declare function sampleEmitterShape(shape: EmitterShape, rand: () => number, out: ShapeSample, direction?: number): ShapeSample;
|
|
244
237
|
/** Configuration for a ParticleEmitter. */
|
|
245
238
|
interface EmitterConfig {
|
|
246
239
|
/** Emission rate in particles per second. */
|
|
@@ -305,7 +298,7 @@ interface EmitterOptions {
|
|
|
305
298
|
*
|
|
306
299
|
* Call `update(dt)` each frame. Read `pool.particles` for rendering.
|
|
307
300
|
*/
|
|
308
|
-
declare class ParticleEmitter {
|
|
301
|
+
export declare class ParticleEmitter {
|
|
309
302
|
readonly config: EmitterConfig;
|
|
310
303
|
readonly pool: ParticlePool;
|
|
311
304
|
/** Emitter world position. */
|
|
@@ -337,6 +330,5 @@ declare class ParticleEmitter {
|
|
|
337
330
|
/** Emit one particle. Returns false when the pool is at cap — caller should stop. */
|
|
338
331
|
private _emitOne;
|
|
339
332
|
}
|
|
340
|
-
|
|
341
|
-
export { type DrawParticlesOptions, type EmitterCircleShape, type EmitterConeShape, type EmitterConfig, type EmitterOptions, type EmitterPointShape, type EmitterRectShape, type EmitterRingShape, type EmitterShape, type Particle, type ParticleBatchLike, ParticleEmitter, type ParticleFrameLike, ParticlePool, type ShapeSample, createShapeSample, drawParticles, hasRadialNormal, sampleEmitterShape };
|
|
333
|
+
export type { DrawParticlesOptions, EmitterCircleShape, EmitterConeShape, EmitterConfig, EmitterOptions, EmitterPointShape, EmitterRectShape, EmitterRingShape, EmitterShape, Particle, ParticleBatchLike, ParticleFrameLike, ShapeSample };
|
|
342
334
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/particle-pool.ts","../src/draw-particles.ts","../src/emitter-shape.ts","../src/particle-emitter.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/particle-pool.ts","../src/draw-particles.ts","../src/emitter-shape.ts","../src/particle-emitter.ts"],"mappings":";;UAIiB;;EAEf;EACA;;EAEA;EACA;;EAEA;;EAEA;;EAEA;EACA;;EAEA;EACA;;EAEA;EACA;EACA;EACA;EACA;EACA;;EAEA;;EAEA;;EAEA;;;;;;qBAuDW;UACH;UACA;EAEI,YAAA;;MAMR;;;;;;;MAUA;;MAKA,sBAAsB;;EAK1B,WAAW;;;;;EAWX,cAAc;;EASd,OAAO,YAAY,kBAAkB;;EA+BrC,QAAQ,GAAG;;EAMX,SAAS,GAAG;;UAMJ;;;;;;;EAQR,SAAS,GAAG,WAAW;;EAKvB,aAAa,GAAG,UAAU,KAAK,QAAQ;;EAUvC;;;;;;;UCrMe;EACf;EACA;EACA;EACA;;;;;;;;;;UAWe;EACf,QACE,gBACA,cACA,cACA,cACA,cACA,cACA,cACA,cACA,cACA,kBACA,kBACA,kBACA,gBACA,mBACA;;;UAKa;;;;;;;;;;;EAWf;;EAEA;EACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAgCc,cACd,MAAM,cACN,OAAO,mBACP,gBACA,OAAO,mBACP,UAAU;;;;;;;;;;;;UClFK;EACf;EACA;;EAEA;;;UAIe;EACf;EACA;EACA;;EAEA;;;UAIe;EACf;EACA;EACA;;;;;;;;;;UAWe;EACf;EACA;EACA;;EAEA;;;UAIe;EACf;;;KAIU,eACR,oBACA,qBACA,mBACA,mBACA;;;;;;;;;;UAWa;EACf;EACA;EACA;EACA;;;wBAIc,qBAAqB;;;;;;;wBAYrB,gBAAgB,OAAO;;;;;;;;;;;;wBAsBvB,mBACd,OAAO,cACP,oBACA,KAAK,aACL,qBACC;;UCjHc;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;EACA;;EAEA;EACA;;EAEA;EACA;;EAEA,aAAa;;EAEb,WAAW;;EAEX;EACA;;EAEA;;;;;;;;;EASA,QAAQ;;;UAIO;;;;;;EAMf;;;;;EAKA;;;;;;;;qBASW;WACF,QAAQ;WACR,MAAM;;EAGf;EACA;;EAGA;UAEQ;UACA;;mBAES;;mBAEA;EAEL,YAAA,QAAQ,eAAe,OAAO;;EAQ1C,OAAO;;UAKC;;EAQR,OAAO;;EAgBP,MAAM;;EAON;;UAOQ;;UAMA;;UAKA"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let _flare_engine_core = require("@flare-engine/core");
|
|
3
|
-
|
|
3
|
+
// src/draw-particles.ts
|
|
4
4
|
/**
|
|
5
5
|
* Queue every live particle into a caller-owned sprite batch.
|
|
6
6
|
*
|
|
@@ -50,8 +50,7 @@ function drawParticles(pool, batch, image, frame, options) {
|
|
|
50
50
|
batch.drawRaw(image, srcX, srcY, srcW, srcH, p.x, p.y, size, size, effect, anchorX, anchorY, alpha, p.rotation);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
//#region src/emitter-shape.ts
|
|
53
|
+
// src/emitter-shape.ts
|
|
55
54
|
/** A fresh, zeroed sample. Allocate once outside the loop and reuse. */
|
|
56
55
|
function createShapeSample() {
|
|
57
56
|
return {
|
|
@@ -141,8 +140,7 @@ function sampleEmitterShape(shape, rand, out, direction = 0) {
|
|
|
141
140
|
}
|
|
142
141
|
}
|
|
143
142
|
}
|
|
144
|
-
|
|
145
|
-
//#region src/particle-pool.ts
|
|
143
|
+
// src/particle-pool.ts
|
|
146
144
|
/** Create a default (inactive) particle. */
|
|
147
145
|
function createParticle() {
|
|
148
146
|
return {
|
|
@@ -300,8 +298,7 @@ var ParticlePool = class {
|
|
|
300
298
|
this._active.length = 0;
|
|
301
299
|
}
|
|
302
300
|
};
|
|
303
|
-
|
|
304
|
-
//#region src/particle-emitter.ts
|
|
301
|
+
// src/particle-emitter.ts
|
|
305
302
|
/**
|
|
306
303
|
* ParticleEmitter — emits particles based on a configuration.
|
|
307
304
|
* Uses a ParticlePool for zero-GC operation.
|
|
@@ -415,7 +412,6 @@ var ParticleEmitter = class {
|
|
|
415
412
|
return true;
|
|
416
413
|
}
|
|
417
414
|
};
|
|
418
|
-
//#endregion
|
|
419
415
|
exports.ParticleEmitter = ParticleEmitter;
|
|
420
416
|
exports.ParticlePool = ParticlePool;
|
|
421
417
|
exports.createShapeSample = createShapeSample;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Pool"],"sources":["../src/draw-particles.ts","../src/emitter-shape.ts","../src/particle-pool.ts","../src/particle-emitter.ts"],"sourcesContent":["import type { ParticlePool } from './particle-pool.js';\n\n/**\n * The frame rectangle within a texture. Structural on purpose: it matches\n * `SpriteFrame` from `@flare-engine/assets` without this package depending on\n * it — extra members like `name` are simply ignored.\n */\nexport interface ParticleFrameLike {\n x: number;\n y: number;\n w: number;\n h: number;\n}\n\n/**\n * The one method this adapter needs from a sprite batch.\n *\n * Declared structurally so `@flare-engine/particles` keeps its two dependencies\n * (`core`, `math`) and stays usable with no renderer at all. A real\n * `SpriteBatch` from `@flare-engine/render` satisfies it; so does a test double.\n * The parameter list mirrors `SpriteBatch.drawRaw`.\n */\nexport interface ParticleBatchLike {\n drawRaw(\n image: unknown,\n srcX: number,\n srcY: number,\n srcW: number,\n srcH: number,\n dstX: number,\n dstY: number,\n dstW: number,\n dstH: number,\n effect?: unknown,\n anchorX?: number,\n anchorY?: number,\n alpha?: number,\n rotation?: number,\n stretch?: boolean,\n ): void;\n}\n\n/** Options for `drawParticles`. */\nexport interface DrawParticlesOptions {\n /**\n * A single effect applied to every particle in this call.\n *\n * Constant for the whole batch, and deliberately not per-particle: a batch\n * retains the effect *reference* until it flushes, so one mutable object\n * reused across the loop would give every particle the last particle's\n * values. Per-particle effects therefore cost one object per particle per\n * frame, which is exactly what this package exists to avoid — pass a constant\n * here, or build the loop yourself over `pool.particles`.\n */\n effect?: unknown;\n /** Anchor within the destination rect. Defaults to the centre (0.5, 0.5). */\n anchorX?: number;\n anchorY?: number;\n}\n\n/**\n * Queue every live particle into a caller-owned sprite batch.\n *\n * Zero-alloc: the loop reads the pool's active list directly, allocates nothing\n * per particle, and hands each one to `drawRaw` — so a steady-state emitter adds\n * no garbage. Size and alpha come from the pool's own interpolators, and\n * rotation from the particle.\n *\n * The batch is passed in rather than owned so particles share one batch, and one\n * flush, with the rest of the scene — the `drawInto` idiom used elsewhere in the\n * engine.\n *\n * ```ts\n * // once, outside the loop\n * const frame = sheet.frames.find((f) => f.name === 'spark')!;\n * // each frame, before the batch flushes\n * drawParticles(emitter.pool, batch, atlas.image, frame);\n * ```\n *\n * **Colour is not applied per particle.** The pool interpolates\n * `startR/G/B → endR/G/B`, but delivering that to a batch needs one effect\n * object per particle per frame (see `DrawParticlesOptions.effect`). Alpha *is*\n * applied, because `drawRaw` takes it as a number. For per-particle colour today,\n * write the loop yourself over `pool.particles` and accept the allocation.\n *\n * `image` and `frame` are separate parameters because they are separate\n * everywhere else in the engine — a frame is a rectangle within a texture and\n * does not carry the texture.\n */\nexport function drawParticles(\n pool: ParticlePool,\n batch: ParticleBatchLike,\n image: unknown,\n frame: ParticleFrameLike,\n options?: DrawParticlesOptions,\n): void {\n const particles = pool.particles;\n const count = particles.length;\n if (count === 0) return;\n\n const effect = options?.effect;\n const anchorX = options?.anchorX ?? 0.5;\n const anchorY = options?.anchorY ?? 0.5;\n const srcX = frame.x;\n const srcY = frame.y;\n const srcW = frame.w;\n const srcH = frame.h;\n\n for (let i = 0; i < count; i++) {\n const p = particles[i]!;\n const size = pool.getSize(p);\n // A fully shrunk or fully faded particle costs a draw call for nothing.\n if (size <= 0) continue;\n const alpha = pool.getAlpha(p);\n if (alpha <= 0) continue;\n\n batch.drawRaw(\n image,\n srcX,\n srcY,\n srcW,\n srcH,\n p.x,\n p.y,\n size,\n size,\n effect,\n anchorX,\n anchorY,\n alpha,\n p.rotation,\n );\n }\n}\n","/**\n * Emitter shapes — where a particle starts, not where it goes.\n *\n * The split matters, because `EmitterConfig` already owns direction: `direction`\n * plus `spread` describe the velocity cone. A shape samples a **position offset**\n * from the emitter origin and reports the outward normal at that point, so the\n * two compose instead of competing. A shape with a meaningful outward direction\n * can opt velocity into it with `radial: true` — that is what turns a `ring`\n * from a circle of drifting particles into an explosion.\n */\n\n/** A filled disc of radius `radius`, sampled uniformly by area. */\nexport interface EmitterCircleShape {\n kind: 'circle';\n radius: number;\n /** Emit outward from the centre instead of along `config.direction`. */\n radial?: boolean;\n}\n\n/** An annulus at `radius`, `thickness` wide (default 0 — a bare ring). */\nexport interface EmitterRingShape {\n kind: 'ring';\n radius: number;\n thickness?: number;\n /** Emit outward from the centre instead of along `config.direction`. */\n radial?: boolean;\n}\n\n/** An axis-aligned rectangle centred on the emitter, sampled uniformly. */\nexport interface EmitterRectShape {\n kind: 'rect';\n width: number;\n height: number;\n}\n\n/**\n * A sector (wedge) of radius `radius` and half-angle `angle`, centred on\n * `config.direction` and sampled uniformly by area.\n *\n * This is a *position* wedge, which is what keeps it distinct from\n * `config.spread`: `spread` fans the velocity out of a single point, `cone`\n * spreads the spawn points themselves across the wedge.\n */\nexport interface EmitterConeShape {\n kind: 'cone';\n radius: number;\n angle: number;\n /** Emit outward from the apex instead of along `config.direction`. */\n radial?: boolean;\n}\n\n/** The emitter origin — every particle starts at the same point. The default. */\nexport interface EmitterPointShape {\n kind: 'point';\n}\n\n/** Where newly emitted particles are placed, relative to the emitter. */\nexport type EmitterShape =\n | EmitterPointShape\n | EmitterCircleShape\n | EmitterRingShape\n | EmitterRectShape\n | EmitterConeShape;\n\n/**\n * A sampled spawn point: an offset from the emitter origin, plus the outward\n * normal at that offset.\n *\n * `nx`/`ny` are unit length for the radial shapes. For `point` and `rect` there\n * is no meaningful outward direction and both are 0 — a caller honouring\n * `radial` must fall back to `config.direction`, which is what `hasRadialNormal`\n * is for.\n */\nexport interface ShapeSample {\n x: number;\n y: number;\n nx: number;\n ny: number;\n}\n\n/** A fresh, zeroed sample. Allocate once outside the loop and reuse. */\nexport function createShapeSample(): ShapeSample {\n return { x: 0, y: 0, nx: 0, ny: 0 };\n}\n\nconst TAU = Math.PI * 2;\n\n/**\n * Does this shape produce a usable outward normal?\n *\n * True only when the shape is radial *and* opted in. Lets a caller decide\n * between the normal and `config.direction` without inspecting the union.\n */\nexport function hasRadialNormal(shape: EmitterShape): boolean {\n switch (shape.kind) {\n case 'circle':\n case 'ring':\n case 'cone':\n return shape.radial === true;\n default:\n return false;\n }\n}\n\n/**\n * Sample a spawn offset into `out`. Zero-alloc: nothing is constructed here, so\n * this is safe to call once per emitted particle in a steady-state loop.\n *\n * `rand` must return a float in [0, 1). Pass the emitter's seeded generator to\n * keep emission deterministic — every shape draws a fixed number of values per\n * call (`point` 0, `ring`/`rect` 2, `circle`/`cone` 2), so a given seed replays\n * exactly.\n *\n * `direction` orients `cone` and is ignored by every other shape.\n */\nexport function sampleEmitterShape(\n shape: EmitterShape,\n rand: () => number,\n out: ShapeSample,\n direction = 0,\n): ShapeSample {\n switch (shape.kind) {\n case 'point': {\n out.x = 0;\n out.y = 0;\n out.nx = 0;\n out.ny = 0;\n return out;\n }\n case 'circle': {\n const angle = rand() * TAU;\n // sqrt keeps the distribution uniform by area; without it particles\n // bunch toward the centre.\n const r = Math.sqrt(rand()) * Math.max(0, shape.radius);\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n out.x = cos * r;\n out.y = sin * r;\n out.nx = cos;\n out.ny = sin;\n return out;\n }\n case 'ring': {\n const angle = rand() * TAU;\n const thickness = Math.max(0, shape.thickness ?? 0);\n const base = Math.max(0, shape.radius);\n // Uniform across the band rather than by area: a ring is thin by\n // definition, and area-weighting a 1px band buys nothing.\n const r = base + (rand() - 0.5) * thickness;\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n out.x = cos * r;\n out.y = sin * r;\n out.nx = cos;\n out.ny = sin;\n return out;\n }\n case 'rect': {\n const w = Math.max(0, shape.width);\n const h = Math.max(0, shape.height);\n out.x = (rand() - 0.5) * w;\n out.y = (rand() - 0.5) * h;\n out.nx = 0;\n out.ny = 0;\n return out;\n }\n case 'cone': {\n const half = Math.max(0, shape.angle);\n const angle = direction + (rand() * 2 - 1) * half;\n const r = Math.sqrt(rand()) * Math.max(0, shape.radius);\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n out.x = cos * r;\n out.y = sin * r;\n out.nx = cos;\n out.ny = sin;\n return out;\n }\n }\n}\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, { 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 { EmitterShape, ShapeSample } from './emitter-shape.js';\nimport { createShapeSample, hasRadialNormal, sampleEmitterShape } from './emitter-shape.js';\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 * Where particles spawn, relative to the emitter position. Defaults to\n * `{ kind: 'point' }`, which is the pre-existing behaviour — every particle\n * starts exactly at `x`/`y`.\n *\n * A shape samples position only; `direction` and `spread` still govern\n * velocity, unless the shape sets `radial: true` (see `EmitterShape`).\n */\n shape?: EmitterShape;\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 /** Reused spawn-offset buffer — one per emitter, never per particle. */\n private readonly _sample: ShapeSample = createShapeSample();\n /** Bound once at construction; binding per emit would allocate a closure. */\n private readonly _rand = (): number => this._random();\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 // Shape sampling comes first so it consumes its random draws before the\n // velocity draws below — that ordering is what makes a given seed replay\n // identically, and it is why `point` deliberately draws nothing at all\n // (an emitter with no shape produces the exact pre-shape sequence).\n const shape = c.shape;\n if (shape === undefined || shape.kind === 'point') {\n p.x = this.x;\n p.y = this.y;\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 } else {\n const s = sampleEmitterShape(shape, this._rand, this._sample, c.direction);\n p.x = this.x + s.x;\n p.y = this.y + s.y;\n // A radial shape emits along its own outward normal, fanned by `spread`;\n // otherwise `direction` still rules, exactly as for a point emitter.\n const base = hasRadialNormal(shape) ? Math.atan2(s.ny, s.nx) : c.direction;\n const angle = base + 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\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,cACd,MACA,OACA,OACA,OACA,SACM;CACN,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E,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"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["Pool"],"sources":["../src/draw-particles.ts","../src/emitter-shape.ts","../src/particle-pool.ts","../src/particle-emitter.ts"],"sourcesContent":["import type { ParticlePool } from './particle-pool.js';\n\n/**\n * The frame rectangle within a texture. Structural on purpose: it matches\n * `SpriteFrame` from `@flare-engine/assets` without this package depending on\n * it — extra members like `name` are simply ignored.\n */\nexport interface ParticleFrameLike {\n x: number;\n y: number;\n w: number;\n h: number;\n}\n\n/**\n * The one method this adapter needs from a sprite batch.\n *\n * Declared structurally so `@flare-engine/particles` keeps its two dependencies\n * (`core`, `math`) and stays usable with no renderer at all. A real\n * `SpriteBatch` from `@flare-engine/render` satisfies it; so does a test double.\n * The parameter list mirrors `SpriteBatch.drawRaw`.\n */\nexport interface ParticleBatchLike {\n drawRaw(\n image: unknown,\n srcX: number,\n srcY: number,\n srcW: number,\n srcH: number,\n dstX: number,\n dstY: number,\n dstW: number,\n dstH: number,\n effect?: unknown,\n anchorX?: number,\n anchorY?: number,\n alpha?: number,\n rotation?: number,\n stretch?: boolean,\n ): void;\n}\n\n/** Options for `drawParticles`. */\nexport interface DrawParticlesOptions {\n /**\n * A single effect applied to every particle in this call.\n *\n * Constant for the whole batch, and deliberately not per-particle: a batch\n * retains the effect *reference* until it flushes, so one mutable object\n * reused across the loop would give every particle the last particle's\n * values. Per-particle effects therefore cost one object per particle per\n * frame, which is exactly what this package exists to avoid — pass a constant\n * here, or build the loop yourself over `pool.particles`.\n */\n effect?: unknown;\n /** Anchor within the destination rect. Defaults to the centre (0.5, 0.5). */\n anchorX?: number;\n anchorY?: number;\n}\n\n/**\n * Queue every live particle into a caller-owned sprite batch.\n *\n * Zero-alloc: the loop reads the pool's active list directly, allocates nothing\n * per particle, and hands each one to `drawRaw` — so a steady-state emitter adds\n * no garbage. Size and alpha come from the pool's own interpolators, and\n * rotation from the particle.\n *\n * The batch is passed in rather than owned so particles share one batch, and one\n * flush, with the rest of the scene — the `drawInto` idiom used elsewhere in the\n * engine.\n *\n * ```ts\n * // once, outside the loop\n * const frame = sheet.frames.find((f) => f.name === 'spark')!;\n * // each frame, before the batch flushes\n * drawParticles(emitter.pool, batch, atlas.image, frame);\n * ```\n *\n * **Colour is not applied per particle.** The pool interpolates\n * `startR/G/B → endR/G/B`, but delivering that to a batch needs one effect\n * object per particle per frame (see `DrawParticlesOptions.effect`). Alpha *is*\n * applied, because `drawRaw` takes it as a number. For per-particle colour today,\n * write the loop yourself over `pool.particles` and accept the allocation.\n *\n * `image` and `frame` are separate parameters because they are separate\n * everywhere else in the engine — a frame is a rectangle within a texture and\n * does not carry the texture.\n */\nexport function drawParticles(\n pool: ParticlePool,\n batch: ParticleBatchLike,\n image: unknown,\n frame: ParticleFrameLike,\n options?: DrawParticlesOptions,\n): void {\n const particles = pool.particles;\n const count = particles.length;\n if (count === 0) return;\n\n const effect = options?.effect;\n const anchorX = options?.anchorX ?? 0.5;\n const anchorY = options?.anchorY ?? 0.5;\n const srcX = frame.x;\n const srcY = frame.y;\n const srcW = frame.w;\n const srcH = frame.h;\n\n for (let i = 0; i < count; i++) {\n const p = particles[i]!;\n const size = pool.getSize(p);\n // A fully shrunk or fully faded particle costs a draw call for nothing.\n if (size <= 0) continue;\n const alpha = pool.getAlpha(p);\n if (alpha <= 0) continue;\n\n batch.drawRaw(\n image,\n srcX,\n srcY,\n srcW,\n srcH,\n p.x,\n p.y,\n size,\n size,\n effect,\n anchorX,\n anchorY,\n alpha,\n p.rotation,\n );\n }\n}\n","/**\n * Emitter shapes — where a particle starts, not where it goes.\n *\n * The split matters, because `EmitterConfig` already owns direction: `direction`\n * plus `spread` describe the velocity cone. A shape samples a **position offset**\n * from the emitter origin and reports the outward normal at that point, so the\n * two compose instead of competing. A shape with a meaningful outward direction\n * can opt velocity into it with `radial: true` — that is what turns a `ring`\n * from a circle of drifting particles into an explosion.\n */\n\n/** A filled disc of radius `radius`, sampled uniformly by area. */\nexport interface EmitterCircleShape {\n kind: 'circle';\n radius: number;\n /** Emit outward from the centre instead of along `config.direction`. */\n radial?: boolean;\n}\n\n/** An annulus at `radius`, `thickness` wide (default 0 — a bare ring). */\nexport interface EmitterRingShape {\n kind: 'ring';\n radius: number;\n thickness?: number;\n /** Emit outward from the centre instead of along `config.direction`. */\n radial?: boolean;\n}\n\n/** An axis-aligned rectangle centred on the emitter, sampled uniformly. */\nexport interface EmitterRectShape {\n kind: 'rect';\n width: number;\n height: number;\n}\n\n/**\n * A sector (wedge) of radius `radius` and half-angle `angle`, centred on\n * `config.direction` and sampled uniformly by area.\n *\n * This is a *position* wedge, which is what keeps it distinct from\n * `config.spread`: `spread` fans the velocity out of a single point, `cone`\n * spreads the spawn points themselves across the wedge.\n */\nexport interface EmitterConeShape {\n kind: 'cone';\n radius: number;\n angle: number;\n /** Emit outward from the apex instead of along `config.direction`. */\n radial?: boolean;\n}\n\n/** The emitter origin — every particle starts at the same point. The default. */\nexport interface EmitterPointShape {\n kind: 'point';\n}\n\n/** Where newly emitted particles are placed, relative to the emitter. */\nexport type EmitterShape =\n | EmitterPointShape\n | EmitterCircleShape\n | EmitterRingShape\n | EmitterRectShape\n | EmitterConeShape;\n\n/**\n * A sampled spawn point: an offset from the emitter origin, plus the outward\n * normal at that offset.\n *\n * `nx`/`ny` are unit length for the radial shapes. For `point` and `rect` there\n * is no meaningful outward direction and both are 0 — a caller honouring\n * `radial` must fall back to `config.direction`, which is what `hasRadialNormal`\n * is for.\n */\nexport interface ShapeSample {\n x: number;\n y: number;\n nx: number;\n ny: number;\n}\n\n/** A fresh, zeroed sample. Allocate once outside the loop and reuse. */\nexport function createShapeSample(): ShapeSample {\n return { x: 0, y: 0, nx: 0, ny: 0 };\n}\n\nconst TAU = Math.PI * 2;\n\n/**\n * Does this shape produce a usable outward normal?\n *\n * True only when the shape is radial *and* opted in. Lets a caller decide\n * between the normal and `config.direction` without inspecting the union.\n */\nexport function hasRadialNormal(shape: EmitterShape): boolean {\n switch (shape.kind) {\n case 'circle':\n case 'ring':\n case 'cone':\n return shape.radial === true;\n default:\n return false;\n }\n}\n\n/**\n * Sample a spawn offset into `out`. Zero-alloc: nothing is constructed here, so\n * this is safe to call once per emitted particle in a steady-state loop.\n *\n * `rand` must return a float in [0, 1). Pass the emitter's seeded generator to\n * keep emission deterministic — every shape draws a fixed number of values per\n * call (`point` 0, `ring`/`rect` 2, `circle`/`cone` 2), so a given seed replays\n * exactly.\n *\n * `direction` orients `cone` and is ignored by every other shape.\n */\nexport function sampleEmitterShape(\n shape: EmitterShape,\n rand: () => number,\n out: ShapeSample,\n direction = 0,\n): ShapeSample {\n switch (shape.kind) {\n case 'point': {\n out.x = 0;\n out.y = 0;\n out.nx = 0;\n out.ny = 0;\n return out;\n }\n case 'circle': {\n const angle = rand() * TAU;\n // sqrt keeps the distribution uniform by area; without it particles\n // bunch toward the centre.\n const r = Math.sqrt(rand()) * Math.max(0, shape.radius);\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n out.x = cos * r;\n out.y = sin * r;\n out.nx = cos;\n out.ny = sin;\n return out;\n }\n case 'ring': {\n const angle = rand() * TAU;\n const thickness = Math.max(0, shape.thickness ?? 0);\n const base = Math.max(0, shape.radius);\n // Uniform across the band rather than by area: a ring is thin by\n // definition, and area-weighting a 1px band buys nothing.\n const r = base + (rand() - 0.5) * thickness;\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n out.x = cos * r;\n out.y = sin * r;\n out.nx = cos;\n out.ny = sin;\n return out;\n }\n case 'rect': {\n const w = Math.max(0, shape.width);\n const h = Math.max(0, shape.height);\n out.x = (rand() - 0.5) * w;\n out.y = (rand() - 0.5) * h;\n out.nx = 0;\n out.ny = 0;\n return out;\n }\n case 'cone': {\n const half = Math.max(0, shape.angle);\n const angle = direction + (rand() * 2 - 1) * half;\n const r = Math.sqrt(rand()) * Math.max(0, shape.radius);\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n out.x = cos * r;\n out.y = sin * r;\n out.nx = cos;\n out.ny = sin;\n return out;\n }\n }\n}\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, { 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 { EmitterShape, ShapeSample } from './emitter-shape.js';\nimport { createShapeSample, hasRadialNormal, sampleEmitterShape } from './emitter-shape.js';\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 * Where particles spawn, relative to the emitter position. Defaults to\n * `{ kind: 'point' }`, which is the pre-existing behaviour — every particle\n * starts exactly at `x`/`y`.\n *\n * A shape samples position only; `direction` and `spread` still govern\n * velocity, unless the shape sets `radial: true` (see `EmitterShape`).\n */\n shape?: EmitterShape;\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 /** Reused spawn-offset buffer — one per emitter, never per particle. */\n private readonly _sample: ShapeSample = createShapeSample();\n /** Bound once at construction; binding per emit would allocate a closure. */\n private readonly _rand = (): number => this._random();\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 // Shape sampling comes first so it consumes its random draws before the\n // velocity draws below — that ordering is what makes a given seed replay\n // identically, and it is why `point` deliberately draws nothing at all\n // (an emitter with no shape produces the exact pre-shape sequence).\n const shape = c.shape;\n if (shape === undefined || shape.kind === 'point') {\n p.x = this.x;\n p.y = this.y;\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 } else {\n const s = sampleEmitterShape(shape, this._rand, this._sample, c.direction);\n p.x = this.x + s.x;\n p.y = this.y + s.y;\n // A radial shape emits along its own outward normal, fanned by `spread`;\n // otherwise `direction` still rules, exactly as for a point emitter.\n const base = hasRadialNormal(shape) ? Math.atan2(s.ny, s.nx) : c.direction;\n const angle = base + 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\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,cACd,MACA,OACA,OACA,OACA,SACM;CACN,MAAM,YAAY,KAAK;CACvB,MAAM,QAAQ,UAAU;CACxB,IAAI,UAAU,GAAG;CAEjB,MAAM,SAAS,SAAS;CACxB,MAAM,UAAU,SAAS,WAAW;CACpC,MAAM,UAAU,SAAS,WAAW;CACpC,MAAM,OAAO,MAAM;CACnB,MAAM,OAAO,MAAM;CACnB,MAAM,OAAO,MAAM;CACnB,MAAM,OAAO,MAAM;CAEnB,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK;EAC9B,MAAM,IAAI,UAAU;EACpB,MAAM,OAAO,KAAK,QAAQ,CAAC;EAE3B,IAAI,QAAQ,GAAG;EACf,MAAM,QAAQ,KAAK,SAAS,CAAC;EAC7B,IAAI,SAAS,GAAG;EAEhB,MAAM,QACJ,OACA,MACA,MACA,MACA,MACA,EAAE,GACF,EAAE,GACF,MACA,MACA,QACA,SACA,SACA,OACA,EAAE,QACJ;CACF;AACF;;;ACpDA,SAAgB,oBAAiC;CAC/C,OAAO;EAAE,GAAG;EAAG,GAAG;EAAG,IAAI;EAAG,IAAI;CAAE;AACpC;AAEA,M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,OAAO,EAAE,QAAQ,IAAI,EAAE;GACtE,EAAE,KAAK,KAAK,IAAI,KAAK,IAAI;GACzB,EAAE,KAAK,KAAK,IAAI,KAAK,IAAI;EAC3B;EAEA,MAAM,WAAW,EAAE,cAAc,KAAK,aAAa,EAAE,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/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Pool } from "@flare-engine/core";
|
|
2
|
-
|
|
2
|
+
// src/draw-particles.ts
|
|
3
3
|
/**
|
|
4
4
|
* Queue every live particle into a caller-owned sprite batch.
|
|
5
5
|
*
|
|
@@ -49,8 +49,7 @@ function drawParticles(pool, batch, image, frame, options) {
|
|
|
49
49
|
batch.drawRaw(image, srcX, srcY, srcW, srcH, p.x, p.y, size, size, effect, anchorX, anchorY, alpha, p.rotation);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
//#region src/emitter-shape.ts
|
|
52
|
+
// src/emitter-shape.ts
|
|
54
53
|
/** A fresh, zeroed sample. Allocate once outside the loop and reuse. */
|
|
55
54
|
function createShapeSample() {
|
|
56
55
|
return {
|
|
@@ -140,8 +139,7 @@ function sampleEmitterShape(shape, rand, out, direction = 0) {
|
|
|
140
139
|
}
|
|
141
140
|
}
|
|
142
141
|
}
|
|
143
|
-
|
|
144
|
-
//#region src/particle-pool.ts
|
|
142
|
+
// src/particle-pool.ts
|
|
145
143
|
/** Create a default (inactive) particle. */
|
|
146
144
|
function createParticle() {
|
|
147
145
|
return {
|
|
@@ -299,8 +297,7 @@ var ParticlePool = class {
|
|
|
299
297
|
this._active.length = 0;
|
|
300
298
|
}
|
|
301
299
|
};
|
|
302
|
-
|
|
303
|
-
//#region src/particle-emitter.ts
|
|
300
|
+
// src/particle-emitter.ts
|
|
304
301
|
/**
|
|
305
302
|
* ParticleEmitter — emits particles based on a configuration.
|
|
306
303
|
* Uses a ParticlePool for zero-GC operation.
|
|
@@ -414,7 +411,6 @@ var ParticleEmitter = class {
|
|
|
414
411
|
return true;
|
|
415
412
|
}
|
|
416
413
|
};
|
|
417
|
-
//#endregion
|
|
418
414
|
export { ParticleEmitter, ParticlePool, createShapeSample, drawParticles, hasRadialNormal, sampleEmitterShape };
|
|
419
415
|
|
|
420
416
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/draw-particles.ts","../src/emitter-shape.ts","../src/particle-pool.ts","../src/particle-emitter.ts"],"sourcesContent":["import type { ParticlePool } from './particle-pool.js';\n\n/**\n * The frame rectangle within a texture. Structural on purpose: it matches\n * `SpriteFrame` from `@flare-engine/assets` without this package depending on\n * it — extra members like `name` are simply ignored.\n */\nexport interface ParticleFrameLike {\n x: number;\n y: number;\n w: number;\n h: number;\n}\n\n/**\n * The one method this adapter needs from a sprite batch.\n *\n * Declared structurally so `@flare-engine/particles` keeps its two dependencies\n * (`core`, `math`) and stays usable with no renderer at all. A real\n * `SpriteBatch` from `@flare-engine/render` satisfies it; so does a test double.\n * The parameter list mirrors `SpriteBatch.drawRaw`.\n */\nexport interface ParticleBatchLike {\n drawRaw(\n image: unknown,\n srcX: number,\n srcY: number,\n srcW: number,\n srcH: number,\n dstX: number,\n dstY: number,\n dstW: number,\n dstH: number,\n effect?: unknown,\n anchorX?: number,\n anchorY?: number,\n alpha?: number,\n rotation?: number,\n stretch?: boolean,\n ): void;\n}\n\n/** Options for `drawParticles`. */\nexport interface DrawParticlesOptions {\n /**\n * A single effect applied to every particle in this call.\n *\n * Constant for the whole batch, and deliberately not per-particle: a batch\n * retains the effect *reference* until it flushes, so one mutable object\n * reused across the loop would give every particle the last particle's\n * values. Per-particle effects therefore cost one object per particle per\n * frame, which is exactly what this package exists to avoid — pass a constant\n * here, or build the loop yourself over `pool.particles`.\n */\n effect?: unknown;\n /** Anchor within the destination rect. Defaults to the centre (0.5, 0.5). */\n anchorX?: number;\n anchorY?: number;\n}\n\n/**\n * Queue every live particle into a caller-owned sprite batch.\n *\n * Zero-alloc: the loop reads the pool's active list directly, allocates nothing\n * per particle, and hands each one to `drawRaw` — so a steady-state emitter adds\n * no garbage. Size and alpha come from the pool's own interpolators, and\n * rotation from the particle.\n *\n * The batch is passed in rather than owned so particles share one batch, and one\n * flush, with the rest of the scene — the `drawInto` idiom used elsewhere in the\n * engine.\n *\n * ```ts\n * // once, outside the loop\n * const frame = sheet.frames.find((f) => f.name === 'spark')!;\n * // each frame, before the batch flushes\n * drawParticles(emitter.pool, batch, atlas.image, frame);\n * ```\n *\n * **Colour is not applied per particle.** The pool interpolates\n * `startR/G/B → endR/G/B`, but delivering that to a batch needs one effect\n * object per particle per frame (see `DrawParticlesOptions.effect`). Alpha *is*\n * applied, because `drawRaw` takes it as a number. For per-particle colour today,\n * write the loop yourself over `pool.particles` and accept the allocation.\n *\n * `image` and `frame` are separate parameters because they are separate\n * everywhere else in the engine — a frame is a rectangle within a texture and\n * does not carry the texture.\n */\nexport function drawParticles(\n pool: ParticlePool,\n batch: ParticleBatchLike,\n image: unknown,\n frame: ParticleFrameLike,\n options?: DrawParticlesOptions,\n): void {\n const particles = pool.particles;\n const count = particles.length;\n if (count === 0) return;\n\n const effect = options?.effect;\n const anchorX = options?.anchorX ?? 0.5;\n const anchorY = options?.anchorY ?? 0.5;\n const srcX = frame.x;\n const srcY = frame.y;\n const srcW = frame.w;\n const srcH = frame.h;\n\n for (let i = 0; i < count; i++) {\n const p = particles[i]!;\n const size = pool.getSize(p);\n // A fully shrunk or fully faded particle costs a draw call for nothing.\n if (size <= 0) continue;\n const alpha = pool.getAlpha(p);\n if (alpha <= 0) continue;\n\n batch.drawRaw(\n image,\n srcX,\n srcY,\n srcW,\n srcH,\n p.x,\n p.y,\n size,\n size,\n effect,\n anchorX,\n anchorY,\n alpha,\n p.rotation,\n );\n }\n}\n","/**\n * Emitter shapes — where a particle starts, not where it goes.\n *\n * The split matters, because `EmitterConfig` already owns direction: `direction`\n * plus `spread` describe the velocity cone. A shape samples a **position offset**\n * from the emitter origin and reports the outward normal at that point, so the\n * two compose instead of competing. A shape with a meaningful outward direction\n * can opt velocity into it with `radial: true` — that is what turns a `ring`\n * from a circle of drifting particles into an explosion.\n */\n\n/** A filled disc of radius `radius`, sampled uniformly by area. */\nexport interface EmitterCircleShape {\n kind: 'circle';\n radius: number;\n /** Emit outward from the centre instead of along `config.direction`. */\n radial?: boolean;\n}\n\n/** An annulus at `radius`, `thickness` wide (default 0 — a bare ring). */\nexport interface EmitterRingShape {\n kind: 'ring';\n radius: number;\n thickness?: number;\n /** Emit outward from the centre instead of along `config.direction`. */\n radial?: boolean;\n}\n\n/** An axis-aligned rectangle centred on the emitter, sampled uniformly. */\nexport interface EmitterRectShape {\n kind: 'rect';\n width: number;\n height: number;\n}\n\n/**\n * A sector (wedge) of radius `radius` and half-angle `angle`, centred on\n * `config.direction` and sampled uniformly by area.\n *\n * This is a *position* wedge, which is what keeps it distinct from\n * `config.spread`: `spread` fans the velocity out of a single point, `cone`\n * spreads the spawn points themselves across the wedge.\n */\nexport interface EmitterConeShape {\n kind: 'cone';\n radius: number;\n angle: number;\n /** Emit outward from the apex instead of along `config.direction`. */\n radial?: boolean;\n}\n\n/** The emitter origin — every particle starts at the same point. The default. */\nexport interface EmitterPointShape {\n kind: 'point';\n}\n\n/** Where newly emitted particles are placed, relative to the emitter. */\nexport type EmitterShape =\n | EmitterPointShape\n | EmitterCircleShape\n | EmitterRingShape\n | EmitterRectShape\n | EmitterConeShape;\n\n/**\n * A sampled spawn point: an offset from the emitter origin, plus the outward\n * normal at that offset.\n *\n * `nx`/`ny` are unit length for the radial shapes. For `point` and `rect` there\n * is no meaningful outward direction and both are 0 — a caller honouring\n * `radial` must fall back to `config.direction`, which is what `hasRadialNormal`\n * is for.\n */\nexport interface ShapeSample {\n x: number;\n y: number;\n nx: number;\n ny: number;\n}\n\n/** A fresh, zeroed sample. Allocate once outside the loop and reuse. */\nexport function createShapeSample(): ShapeSample {\n return { x: 0, y: 0, nx: 0, ny: 0 };\n}\n\nconst TAU = Math.PI * 2;\n\n/**\n * Does this shape produce a usable outward normal?\n *\n * True only when the shape is radial *and* opted in. Lets a caller decide\n * between the normal and `config.direction` without inspecting the union.\n */\nexport function hasRadialNormal(shape: EmitterShape): boolean {\n switch (shape.kind) {\n case 'circle':\n case 'ring':\n case 'cone':\n return shape.radial === true;\n default:\n return false;\n }\n}\n\n/**\n * Sample a spawn offset into `out`. Zero-alloc: nothing is constructed here, so\n * this is safe to call once per emitted particle in a steady-state loop.\n *\n * `rand` must return a float in [0, 1). Pass the emitter's seeded generator to\n * keep emission deterministic — every shape draws a fixed number of values per\n * call (`point` 0, `ring`/`rect` 2, `circle`/`cone` 2), so a given seed replays\n * exactly.\n *\n * `direction` orients `cone` and is ignored by every other shape.\n */\nexport function sampleEmitterShape(\n shape: EmitterShape,\n rand: () => number,\n out: ShapeSample,\n direction = 0,\n): ShapeSample {\n switch (shape.kind) {\n case 'point': {\n out.x = 0;\n out.y = 0;\n out.nx = 0;\n out.ny = 0;\n return out;\n }\n case 'circle': {\n const angle = rand() * TAU;\n // sqrt keeps the distribution uniform by area; without it particles\n // bunch toward the centre.\n const r = Math.sqrt(rand()) * Math.max(0, shape.radius);\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n out.x = cos * r;\n out.y = sin * r;\n out.nx = cos;\n out.ny = sin;\n return out;\n }\n case 'ring': {\n const angle = rand() * TAU;\n const thickness = Math.max(0, shape.thickness ?? 0);\n const base = Math.max(0, shape.radius);\n // Uniform across the band rather than by area: a ring is thin by\n // definition, and area-weighting a 1px band buys nothing.\n const r = base + (rand() - 0.5) * thickness;\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n out.x = cos * r;\n out.y = sin * r;\n out.nx = cos;\n out.ny = sin;\n return out;\n }\n case 'rect': {\n const w = Math.max(0, shape.width);\n const h = Math.max(0, shape.height);\n out.x = (rand() - 0.5) * w;\n out.y = (rand() - 0.5) * h;\n out.nx = 0;\n out.ny = 0;\n return out;\n }\n case 'cone': {\n const half = Math.max(0, shape.angle);\n const angle = direction + (rand() * 2 - 1) * half;\n const r = Math.sqrt(rand()) * Math.max(0, shape.radius);\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n out.x = cos * r;\n out.y = sin * r;\n out.nx = cos;\n out.ny = sin;\n return out;\n }\n }\n}\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, { 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 { EmitterShape, ShapeSample } from './emitter-shape.js';\nimport { createShapeSample, hasRadialNormal, sampleEmitterShape } from './emitter-shape.js';\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 * Where particles spawn, relative to the emitter position. Defaults to\n * `{ kind: 'point' }`, which is the pre-existing behaviour — every particle\n * starts exactly at `x`/`y`.\n *\n * A shape samples position only; `direction` and `spread` still govern\n * velocity, unless the shape sets `radial: true` (see `EmitterShape`).\n */\n shape?: EmitterShape;\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 /** Reused spawn-offset buffer — one per emitter, never per particle. */\n private readonly _sample: ShapeSample = createShapeSample();\n /** Bound once at construction; binding per emit would allocate a closure. */\n private readonly _rand = (): number => this._random();\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 // Shape sampling comes first so it consumes its random draws before the\n // velocity draws below — that ordering is what makes a given seed replay\n // identically, and it is why `point` deliberately draws nothing at all\n // (an emitter with no shape produces the exact pre-shape sequence).\n const shape = c.shape;\n if (shape === undefined || shape.kind === 'point') {\n p.x = this.x;\n p.y = this.y;\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 } else {\n const s = sampleEmitterShape(shape, this._rand, this._sample, c.direction);\n p.x = this.x + s.x;\n p.y = this.y + s.y;\n // A radial shape emits along its own outward normal, fanned by `spread`;\n // otherwise `direction` still rules, exactly as for a point emitter.\n const base = hasRadialNormal(shape) ? Math.atan2(s.ny, s.nx) : c.direction;\n const angle = base + 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\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,cACd,MACA,OACA,OACA,OACA,SACM;CACN,MAAM,YAAY,KAAK;CACvB,MAAM,QAAQ,UAAU;CACxB,IAAI,UAAU,GAAG;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GACxB,EAAE,kBAAkB,EAAE,qBAClB,KAAK,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,IACzD,EAAE;EAGR,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/draw-particles.ts","../src/emitter-shape.ts","../src/particle-pool.ts","../src/particle-emitter.ts"],"sourcesContent":["import type { ParticlePool } from './particle-pool.js';\n\n/**\n * The frame rectangle within a texture. Structural on purpose: it matches\n * `SpriteFrame` from `@flare-engine/assets` without this package depending on\n * it — extra members like `name` are simply ignored.\n */\nexport interface ParticleFrameLike {\n x: number;\n y: number;\n w: number;\n h: number;\n}\n\n/**\n * The one method this adapter needs from a sprite batch.\n *\n * Declared structurally so `@flare-engine/particles` keeps its two dependencies\n * (`core`, `math`) and stays usable with no renderer at all. A real\n * `SpriteBatch` from `@flare-engine/render` satisfies it; so does a test double.\n * The parameter list mirrors `SpriteBatch.drawRaw`.\n */\nexport interface ParticleBatchLike {\n drawRaw(\n image: unknown,\n srcX: number,\n srcY: number,\n srcW: number,\n srcH: number,\n dstX: number,\n dstY: number,\n dstW: number,\n dstH: number,\n effect?: unknown,\n anchorX?: number,\n anchorY?: number,\n alpha?: number,\n rotation?: number,\n stretch?: boolean,\n ): void;\n}\n\n/** Options for `drawParticles`. */\nexport interface DrawParticlesOptions {\n /**\n * A single effect applied to every particle in this call.\n *\n * Constant for the whole batch, and deliberately not per-particle: a batch\n * retains the effect *reference* until it flushes, so one mutable object\n * reused across the loop would give every particle the last particle's\n * values. Per-particle effects therefore cost one object per particle per\n * frame, which is exactly what this package exists to avoid — pass a constant\n * here, or build the loop yourself over `pool.particles`.\n */\n effect?: unknown;\n /** Anchor within the destination rect. Defaults to the centre (0.5, 0.5). */\n anchorX?: number;\n anchorY?: number;\n}\n\n/**\n * Queue every live particle into a caller-owned sprite batch.\n *\n * Zero-alloc: the loop reads the pool's active list directly, allocates nothing\n * per particle, and hands each one to `drawRaw` — so a steady-state emitter adds\n * no garbage. Size and alpha come from the pool's own interpolators, and\n * rotation from the particle.\n *\n * The batch is passed in rather than owned so particles share one batch, and one\n * flush, with the rest of the scene — the `drawInto` idiom used elsewhere in the\n * engine.\n *\n * ```ts\n * // once, outside the loop\n * const frame = sheet.frames.find((f) => f.name === 'spark')!;\n * // each frame, before the batch flushes\n * drawParticles(emitter.pool, batch, atlas.image, frame);\n * ```\n *\n * **Colour is not applied per particle.** The pool interpolates\n * `startR/G/B → endR/G/B`, but delivering that to a batch needs one effect\n * object per particle per frame (see `DrawParticlesOptions.effect`). Alpha *is*\n * applied, because `drawRaw` takes it as a number. For per-particle colour today,\n * write the loop yourself over `pool.particles` and accept the allocation.\n *\n * `image` and `frame` are separate parameters because they are separate\n * everywhere else in the engine — a frame is a rectangle within a texture and\n * does not carry the texture.\n */\nexport function drawParticles(\n pool: ParticlePool,\n batch: ParticleBatchLike,\n image: unknown,\n frame: ParticleFrameLike,\n options?: DrawParticlesOptions,\n): void {\n const particles = pool.particles;\n const count = particles.length;\n if (count === 0) return;\n\n const effect = options?.effect;\n const anchorX = options?.anchorX ?? 0.5;\n const anchorY = options?.anchorY ?? 0.5;\n const srcX = frame.x;\n const srcY = frame.y;\n const srcW = frame.w;\n const srcH = frame.h;\n\n for (let i = 0; i < count; i++) {\n const p = particles[i]!;\n const size = pool.getSize(p);\n // A fully shrunk or fully faded particle costs a draw call for nothing.\n if (size <= 0) continue;\n const alpha = pool.getAlpha(p);\n if (alpha <= 0) continue;\n\n batch.drawRaw(\n image,\n srcX,\n srcY,\n srcW,\n srcH,\n p.x,\n p.y,\n size,\n size,\n effect,\n anchorX,\n anchorY,\n alpha,\n p.rotation,\n );\n }\n}\n","/**\n * Emitter shapes — where a particle starts, not where it goes.\n *\n * The split matters, because `EmitterConfig` already owns direction: `direction`\n * plus `spread` describe the velocity cone. A shape samples a **position offset**\n * from the emitter origin and reports the outward normal at that point, so the\n * two compose instead of competing. A shape with a meaningful outward direction\n * can opt velocity into it with `radial: true` — that is what turns a `ring`\n * from a circle of drifting particles into an explosion.\n */\n\n/** A filled disc of radius `radius`, sampled uniformly by area. */\nexport interface EmitterCircleShape {\n kind: 'circle';\n radius: number;\n /** Emit outward from the centre instead of along `config.direction`. */\n radial?: boolean;\n}\n\n/** An annulus at `radius`, `thickness` wide (default 0 — a bare ring). */\nexport interface EmitterRingShape {\n kind: 'ring';\n radius: number;\n thickness?: number;\n /** Emit outward from the centre instead of along `config.direction`. */\n radial?: boolean;\n}\n\n/** An axis-aligned rectangle centred on the emitter, sampled uniformly. */\nexport interface EmitterRectShape {\n kind: 'rect';\n width: number;\n height: number;\n}\n\n/**\n * A sector (wedge) of radius `radius` and half-angle `angle`, centred on\n * `config.direction` and sampled uniformly by area.\n *\n * This is a *position* wedge, which is what keeps it distinct from\n * `config.spread`: `spread` fans the velocity out of a single point, `cone`\n * spreads the spawn points themselves across the wedge.\n */\nexport interface EmitterConeShape {\n kind: 'cone';\n radius: number;\n angle: number;\n /** Emit outward from the apex instead of along `config.direction`. */\n radial?: boolean;\n}\n\n/** The emitter origin — every particle starts at the same point. The default. */\nexport interface EmitterPointShape {\n kind: 'point';\n}\n\n/** Where newly emitted particles are placed, relative to the emitter. */\nexport type EmitterShape =\n | EmitterPointShape\n | EmitterCircleShape\n | EmitterRingShape\n | EmitterRectShape\n | EmitterConeShape;\n\n/**\n * A sampled spawn point: an offset from the emitter origin, plus the outward\n * normal at that offset.\n *\n * `nx`/`ny` are unit length for the radial shapes. For `point` and `rect` there\n * is no meaningful outward direction and both are 0 — a caller honouring\n * `radial` must fall back to `config.direction`, which is what `hasRadialNormal`\n * is for.\n */\nexport interface ShapeSample {\n x: number;\n y: number;\n nx: number;\n ny: number;\n}\n\n/** A fresh, zeroed sample. Allocate once outside the loop and reuse. */\nexport function createShapeSample(): ShapeSample {\n return { x: 0, y: 0, nx: 0, ny: 0 };\n}\n\nconst TAU = Math.PI * 2;\n\n/**\n * Does this shape produce a usable outward normal?\n *\n * True only when the shape is radial *and* opted in. Lets a caller decide\n * between the normal and `config.direction` without inspecting the union.\n */\nexport function hasRadialNormal(shape: EmitterShape): boolean {\n switch (shape.kind) {\n case 'circle':\n case 'ring':\n case 'cone':\n return shape.radial === true;\n default:\n return false;\n }\n}\n\n/**\n * Sample a spawn offset into `out`. Zero-alloc: nothing is constructed here, so\n * this is safe to call once per emitted particle in a steady-state loop.\n *\n * `rand` must return a float in [0, 1). Pass the emitter's seeded generator to\n * keep emission deterministic — every shape draws a fixed number of values per\n * call (`point` 0, `ring`/`rect` 2, `circle`/`cone` 2), so a given seed replays\n * exactly.\n *\n * `direction` orients `cone` and is ignored by every other shape.\n */\nexport function sampleEmitterShape(\n shape: EmitterShape,\n rand: () => number,\n out: ShapeSample,\n direction = 0,\n): ShapeSample {\n switch (shape.kind) {\n case 'point': {\n out.x = 0;\n out.y = 0;\n out.nx = 0;\n out.ny = 0;\n return out;\n }\n case 'circle': {\n const angle = rand() * TAU;\n // sqrt keeps the distribution uniform by area; without it particles\n // bunch toward the centre.\n const r = Math.sqrt(rand()) * Math.max(0, shape.radius);\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n out.x = cos * r;\n out.y = sin * r;\n out.nx = cos;\n out.ny = sin;\n return out;\n }\n case 'ring': {\n const angle = rand() * TAU;\n const thickness = Math.max(0, shape.thickness ?? 0);\n const base = Math.max(0, shape.radius);\n // Uniform across the band rather than by area: a ring is thin by\n // definition, and area-weighting a 1px band buys nothing.\n const r = base + (rand() - 0.5) * thickness;\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n out.x = cos * r;\n out.y = sin * r;\n out.nx = cos;\n out.ny = sin;\n return out;\n }\n case 'rect': {\n const w = Math.max(0, shape.width);\n const h = Math.max(0, shape.height);\n out.x = (rand() - 0.5) * w;\n out.y = (rand() - 0.5) * h;\n out.nx = 0;\n out.ny = 0;\n return out;\n }\n case 'cone': {\n const half = Math.max(0, shape.angle);\n const angle = direction + (rand() * 2 - 1) * half;\n const r = Math.sqrt(rand()) * Math.max(0, shape.radius);\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n out.x = cos * r;\n out.y = sin * r;\n out.nx = cos;\n out.ny = sin;\n return out;\n }\n }\n}\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, { 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 { EmitterShape, ShapeSample } from './emitter-shape.js';\nimport { createShapeSample, hasRadialNormal, sampleEmitterShape } from './emitter-shape.js';\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 * Where particles spawn, relative to the emitter position. Defaults to\n * `{ kind: 'point' }`, which is the pre-existing behaviour — every particle\n * starts exactly at `x`/`y`.\n *\n * A shape samples position only; `direction` and `spread` still govern\n * velocity, unless the shape sets `radial: true` (see `EmitterShape`).\n */\n shape?: EmitterShape;\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 /** Reused spawn-offset buffer — one per emitter, never per particle. */\n private readonly _sample: ShapeSample = createShapeSample();\n /** Bound once at construction; binding per emit would allocate a closure. */\n private readonly _rand = (): number => this._random();\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 // Shape sampling comes first so it consumes its random draws before the\n // velocity draws below — that ordering is what makes a given seed replay\n // identically, and it is why `point` deliberately draws nothing at all\n // (an emitter with no shape produces the exact pre-shape sequence).\n const shape = c.shape;\n if (shape === undefined || shape.kind === 'point') {\n p.x = this.x;\n p.y = this.y;\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 } else {\n const s = sampleEmitterShape(shape, this._rand, this._sample, c.direction);\n p.x = this.x + s.x;\n p.y = this.y + s.y;\n // A radial shape emits along its own outward normal, fanned by `spread`;\n // otherwise `direction` still rules, exactly as for a point emitter.\n const base = hasRadialNormal(shape) ? Math.atan2(s.ny, s.nx) : c.direction;\n const angle = base + 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\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,cACd,MACA,OACA,OACA,OACA,SACM;CACN,MAAM,YAAY,KAAK;CACvB,MAAM,QAAQ,UAAU;CACxB,IAAI,UAAU,GAAG;CAEjB,MAAM,SAAS,SAAS;CACxB,MAAM,UAAU,SAAS,WAAW;CACpC,MAAM,UAAU,SAAS,WAAW;CACpC,MAAM,OAAO,MAAM;CACnB,MAAM,OAAO,MAAM;CACnB,MAAM,OAAO,MAAM;CACnB,MAAM,OAAO,MAAM;CAEnB,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK;EAC9B,MAAM,IAAI,UAAU;EACpB,MAAM,OAAO,KAAK,QAAQ,CAAC;EAE3B,IAAI,QAAQ,GAAG;EACf,MAAM,QAAQ,KAAK,SAAS,CAAC;EAC7B,IAAI,SAAS,GAAG;EAEhB,MAAM,QACJ,OACA,MACA,MACA,MACA,MACA,EAAE,GACF,EAAE,GACF,MACA,MACA,QACA,SACA,SACA,OACA,EAAE,QACJ;CACF;AACF;;;ACpDA,SAAgB,oBAAiC;CAC/C,OAAO;EAAE,GAAG;EAAG,GAAG;EAAG,IAAI;EAAG,IAAI;CAAE;AACpC;AAEA,MAAM,MAAM,KAAK,KAAK;;;;;;;AAQtB,SAAgB,gBAAgB,OAA8B;CAC5D,QAAQ,MAAM,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K,KAAK,IAAI,KAAK,IAAI;EAC3B;EAEA,MAAM,WAAW,EAAE,cAAc,KAAK,aAAa,EAAE,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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flare-engine/particles",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.7",
|
|
4
4
|
"description": "Particle emitter, pool, immediate-mode Skia rendering",
|
|
5
5
|
"keywords": ["flare-engine", "particles", "emitter", "skia"],
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"typecheck": "tsc --noEmit"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@flare-engine/core": "^0.4.
|
|
41
|
-
"@flare-engine/math": "^0.4.
|
|
40
|
+
"@flare-engine/core": "^0.4.7",
|
|
41
|
+
"@flare-engine/math": "^0.4.7"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": ">=20"
|