@flare-engine/particles 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,106 +1,133 @@
1
- import { Color } from '@flare-engine/math';
2
-
1
+ import { Color } from "@flare-engine/math";
2
+ //#region src/particle-pool.d.ts
3
3
  /** A single particle. Managed by ParticlePool — not user-facing. */
4
4
  interface Particle {
5
- /** World position. */
6
- x: number;
7
- y: number;
8
- /** Velocity in pixels/second. */
9
- vx: number;
10
- vy: number;
11
- /** Time remaining in seconds. */
12
- life: number;
13
- /** Total lifetime for interpolation. */
14
- maxLife: number;
15
- /** Start/end size for interpolation. */
16
- startSize: number;
17
- endSize: number;
18
- /** Start/end alpha for interpolation. */
19
- startAlpha: number;
20
- endAlpha: number;
21
- /** Start/end color components for interpolation. */
22
- startR: number;
23
- startG: number;
24
- startB: number;
25
- endR: number;
26
- endG: number;
27
- endB: number;
28
- /** Rotation in radians. */
29
- rotation: number;
30
- /** Angular velocity in radians/second. */
31
- angularVelocity: number;
32
- /** Whether this particle is active. */
33
- active: boolean;
5
+ /** World position. */
6
+ x: number;
7
+ y: number;
8
+ /** Velocity in pixels/second. */
9
+ vx: number;
10
+ vy: number;
11
+ /** Time remaining in seconds. */
12
+ life: number;
13
+ /** Total lifetime for interpolation. */
14
+ maxLife: number;
15
+ /** Start/end size for interpolation. */
16
+ startSize: number;
17
+ endSize: number;
18
+ /** Start/end alpha for interpolation. */
19
+ startAlpha: number;
20
+ endAlpha: number;
21
+ /** Start/end color components for interpolation. */
22
+ startR: number;
23
+ startG: number;
24
+ startB: number;
25
+ endR: number;
26
+ endG: number;
27
+ endB: number;
28
+ /** Rotation in radians. */
29
+ rotation: number;
30
+ /** Angular velocity in radians/second. */
31
+ angularVelocity: number;
32
+ /** Whether this particle is active. */
33
+ active: boolean;
34
34
  }
35
35
  /**
36
36
  * ParticlePool — pre-allocated pool of particles.
37
37
  * Zero GC pressure during steady-state gameplay.
38
38
  */
39
39
  declare class ParticlePool {
40
- private _pool;
41
- private _active;
42
- constructor(capacity?: number);
43
- /** Number of currently active particles. */
44
- get activeCount(): number;
45
- /** Read-only access to active particles. */
46
- get particles(): readonly Particle[];
47
- /** Acquire a particle from the pool. */
48
- acquire(): Particle;
49
- /** Update all active particles. Releases dead particles. */
50
- update(dt: number, gravityX: number, gravityY: number): void;
51
- /** Get interpolated size for a particle (0 = start, 1 = end of life). */
52
- getSize(p: Particle): number;
53
- /** Get interpolated alpha for a particle. */
54
- getAlpha(p: Particle): number;
55
- /** Shared color buffer — avoids per-call allocation in the render hot path. */
56
- private _colorBuf;
57
- /**
58
- * Get interpolated color for a particle.
59
- *
60
- * Returns a shared buffer — read the values immediately, do not retain the
61
- * reference. For a fresh object call `getColorInto()` with your own out param.
62
- */
63
- getColor(p: Particle): Color;
64
- /** Zero-alloc variant — writes the interpolated color into `out`. */
65
- getColorInto(p: Particle, out: Color): Color;
66
- /** Release all active particles back to pool. */
67
- clear(): void;
40
+ private _pool;
41
+ private _active;
42
+ constructor(capacity?: number);
43
+ /** Number of currently active particles. */
44
+ get activeCount(): number;
45
+ /**
46
+ * Cumulative factory calls made by the internal pool's acquire()/tryAcquire().
47
+ * prewarm() is excluded: factory calls there pre-fill the free list and are
48
+ * not counted. Intended use: snapshot before and after a frame — a non-zero
49
+ * delta in steady state means unexpected allocation.
50
+ */
51
+ get created(): number;
52
+ /** Read-only access to active particles. */
53
+ get particles(): readonly Particle[];
54
+ /** Acquire a particle from the pool. */
55
+ acquire(): Particle;
56
+ /**
57
+ * Acquire a particle only if the pool is below capacity.
58
+ * Returns null at cap — no allocation occurs.
59
+ */
60
+ tryAcquire(): Particle | null;
61
+ /** Update all active particles. Releases dead particles. */
62
+ update(dt: number, gravityX: number, gravityY: number): void;
63
+ /** Get interpolated size for a particle (0 = start, 1 = end of life). */
64
+ getSize(p: Particle): number;
65
+ /** Get interpolated alpha for a particle. */
66
+ getAlpha(p: Particle): number;
67
+ /** Shared color buffer — avoids per-call allocation in the render hot path. */
68
+ private _colorBuf;
69
+ /**
70
+ * Get interpolated color for a particle.
71
+ *
72
+ * Returns a shared buffer — read the values immediately, do not retain the
73
+ * reference. For a fresh object call `getColorInto()` with your own out param.
74
+ */
75
+ getColor(p: Particle): Color;
76
+ /** Zero-alloc variant — writes the interpolated color into `out`. */
77
+ getColorInto(p: Particle, out: Color): Color;
78
+ /** Release all active particles back to pool. */
79
+ clear(): void;
68
80
  }
69
-
81
+ //#endregion
82
+ //#region src/particle-emitter.d.ts
70
83
  /** Configuration for a ParticleEmitter. */
71
84
  interface EmitterConfig {
72
- /** Emission rate in particles per second. */
73
- rate: number;
74
- /** Particle lifetime in seconds. */
75
- lifetime: number;
76
- /** Min lifetime (if set, actual lifetime is random between lifetime and lifetimeMax). */
77
- lifetimeMax?: number;
78
- /** Initial speed in pixels/second. */
79
- speed: number;
80
- /** Max speed (random range). */
81
- speedMax?: number;
82
- /** Emission direction in radians (0 = right). */
83
- direction: number;
84
- /** Spread angle in radians (half-angle of the emission cone). */
85
- spread: number;
86
- /** Gravity in pixels/second² (applied each frame). */
87
- gravityX?: number;
88
- gravityY?: number;
89
- /** Start size and end size. */
90
- startSize?: number;
91
- endSize?: number;
92
- /** Start alpha and end alpha. */
93
- startAlpha?: number;
94
- endAlpha?: number;
95
- /** Start color. */
96
- startColor?: Color;
97
- /** End color. */
98
- endColor?: Color;
99
- /** Angular velocity range (radians/second). */
100
- angularVelocity?: number;
101
- angularVelocityMax?: number;
102
- /** Maximum active particles. */
103
- maxParticles?: number;
85
+ /** Emission rate in particles per second. */
86
+ rate: number;
87
+ /** Particle lifetime in seconds. */
88
+ lifetime: number;
89
+ /** Min lifetime (if set, actual lifetime is random between lifetime and lifetimeMax). */
90
+ lifetimeMax?: number;
91
+ /** Initial speed in pixels/second. */
92
+ speed: number;
93
+ /** Max speed (random range). */
94
+ speedMax?: number;
95
+ /** Emission direction in radians (0 = right). */
96
+ direction: number;
97
+ /** Spread angle in radians (half-angle of the emission cone). */
98
+ spread: number;
99
+ /** Gravity in pixels/second² (applied each frame). */
100
+ gravityX?: number;
101
+ gravityY?: number;
102
+ /** Start size and end size. */
103
+ startSize?: number;
104
+ endSize?: number;
105
+ /** Start alpha and end alpha. */
106
+ startAlpha?: number;
107
+ endAlpha?: number;
108
+ /** Start color. */
109
+ startColor?: Color;
110
+ /** End color. */
111
+ endColor?: Color;
112
+ /** Angular velocity range (radians/second). */
113
+ angularVelocity?: number;
114
+ angularVelocityMax?: number;
115
+ /** Maximum active particles (used as pool capacity default when no opts.maxParticles given). */
116
+ maxParticles?: number;
117
+ }
118
+ /** Construction options for ParticleEmitter. */
119
+ interface EmitterOptions {
120
+ /**
121
+ * Hard cap on simultaneously active particles.
122
+ * Overrides config.maxParticles when provided.
123
+ * Defaults to config.maxParticles ?? 256.
124
+ */
125
+ maxParticles?: number;
126
+ /**
127
+ * Initial LCG seed for deterministic particle randomness.
128
+ * Defaults to 1. Call reseed() at any time to restart the sequence.
129
+ */
130
+ seed?: number;
104
131
  }
105
132
  /**
106
133
  * ParticleEmitter — emits particles based on a configuration.
@@ -109,27 +136,33 @@ interface EmitterConfig {
109
136
  * Call `update(dt)` each frame. Read `pool.particles` for rendering.
110
137
  */
111
138
  declare class ParticleEmitter {
112
- readonly config: EmitterConfig;
113
- readonly pool: ParticlePool;
114
- /** Emitter world position. */
115
- x: number;
116
- y: number;
117
- /** Whether the emitter is actively emitting. */
118
- emitting: boolean;
119
- private _emitAccumulator;
120
- private _seed;
121
- constructor(config: EmitterConfig, maxParticles?: number);
122
- /** Update the emitter: emit new particles and update existing ones. */
123
- update(dt: number): void;
124
- /** Emit a burst of particles. */
125
- burst(count: number): void;
126
- /** Stop emitting and clear all particles. */
127
- reset(): void;
128
- /** Simple seeded pseudo-random for deterministic particles. */
129
- private _random;
130
- /** Random float in [min, max]. */
131
- private _randomRange;
132
- private _emitOne;
139
+ readonly config: EmitterConfig;
140
+ readonly pool: ParticlePool;
141
+ /** Emitter world position. */
142
+ x: number;
143
+ y: number;
144
+ /** Whether the emitter is actively emitting. */
145
+ emitting: boolean;
146
+ private _emitAccumulator;
147
+ private _seed;
148
+ constructor(config: EmitterConfig, opts?: EmitterOptions);
149
+ /** Reset the LCG seed — restarts the particle random sequence from this seed. */
150
+ reseed(seed: number): void;
151
+ /** Normalize s into the valid Park-Miller domain [1, 2147483646]. */
152
+ private _setSeed;
153
+ /** Update the emitter: emit new particles and update existing ones. */
154
+ update(dt: number): void;
155
+ /** Emit a burst of particles. */
156
+ burst(count: number): void;
157
+ /** Stop emitting and clear all particles. */
158
+ reset(): void;
159
+ /** Simple seeded pseudo-random for deterministic particles. */
160
+ private _random;
161
+ /** Random float in [min, max]. */
162
+ private _randomRange;
163
+ /** Emit one particle. Returns false when the pool is at cap — caller should stop. */
164
+ private _emitOne;
133
165
  }
134
-
135
- export { type EmitterConfig, type Particle, ParticleEmitter, ParticlePool };
166
+ //#endregion
167
+ export { type EmitterConfig, type EmitterOptions, type Particle, ParticleEmitter, ParticlePool };
168
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/particle-pool.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;;;;;;cAuDW;UACH;UACA;cAEI;;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;;;;;UCvMe;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;EACA;;EAEA;EACA;;EAEA;EACA;;EAEA,aAAa;;EAEb,WAAW;;EAEX;EACA;;EAEA;;;UAIe;;;;;;EAMf;;;;;EAKA;;;;;;;;cASW;WACF,QAAQ;WACR,MAAM;;EAGf;EACA;;EAGA;UAEQ;UACA;cAEI,QAAQ,eAAe,OAAO;;EAQ1C,OAAO;;UAKC;;EAQR,OAAO;;EAgBP,MAAM;;EAON;;UAOQ;;UAMA;;UAKA"}