@flare-engine/particles 0.1.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/LICENSE +21 -0
- package/README.md +30 -0
- package/dist/index.d.mts +135 -0
- package/dist/index.d.ts +135 -0
- package/dist/index.js +245 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +217 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Grzegorz Otto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @flare-engine/particles
|
|
2
|
+
|
|
3
|
+
Pre-allocated particle pool + emitter. Zero per-frame GC during gameplay — particles are recycled. Target: 200–500 alive particles at 60 fps. This package owns particle data and lifecycle; rendering happens via the host's immediate-mode Skia layer (PictureRecorder).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
bun add @flare-engine/particles
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { ParticleEmitter, ParticlePool } from '@flare-engine/particles';
|
|
15
|
+
|
|
16
|
+
const pool = new ParticlePool(500);
|
|
17
|
+
const emitter = new ParticleEmitter({
|
|
18
|
+
rate: 30, lifetime: 1.2, speed: [80, 160], spread: Math.PI / 4,
|
|
19
|
+
startColor: 0xff_ff_ff_ff, endColor: 0x00_ff_ff_ff,
|
|
20
|
+
startSize: 4, endSize: 0,
|
|
21
|
+
}, pool);
|
|
22
|
+
|
|
23
|
+
emitter.update(dt, gravityX, gravityY);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
See [API spec](../../docs/design/api-specs.md#flare-engineparticles--4kb-gzip) and [skill reference](../../.github/skills/flare-particles/SKILL.md).
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
|
|
30
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Color } from '@flare-engine/math';
|
|
2
|
+
|
|
3
|
+
/** A single particle. Managed by ParticlePool — not user-facing. */
|
|
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;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* ParticlePool — pre-allocated pool of particles.
|
|
37
|
+
* Zero GC pressure during steady-state gameplay.
|
|
38
|
+
*/
|
|
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;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Configuration for a ParticleEmitter. */
|
|
71
|
+
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;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* ParticleEmitter — emits particles based on a configuration.
|
|
107
|
+
* Uses a ParticlePool for zero-GC operation.
|
|
108
|
+
*
|
|
109
|
+
* Call `update(dt)` each frame. Read `pool.particles` for rendering.
|
|
110
|
+
*/
|
|
111
|
+
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;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export { type EmitterConfig, type Particle, ParticleEmitter, ParticlePool };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Color } from '@flare-engine/math';
|
|
2
|
+
|
|
3
|
+
/** A single particle. Managed by ParticlePool — not user-facing. */
|
|
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;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* ParticlePool — pre-allocated pool of particles.
|
|
37
|
+
* Zero GC pressure during steady-state gameplay.
|
|
38
|
+
*/
|
|
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;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Configuration for a ParticleEmitter. */
|
|
71
|
+
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;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* ParticleEmitter — emits particles based on a configuration.
|
|
107
|
+
* Uses a ParticlePool for zero-GC operation.
|
|
108
|
+
*
|
|
109
|
+
* Call `update(dt)` each frame. Read `pool.particles` for rendering.
|
|
110
|
+
*/
|
|
111
|
+
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;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export { type EmitterConfig, type Particle, ParticleEmitter, ParticlePool };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ParticleEmitter: () => ParticleEmitter,
|
|
24
|
+
ParticlePool: () => ParticlePool
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/particle-pool.ts
|
|
29
|
+
var import_core = require("@flare-engine/core");
|
|
30
|
+
function createParticle() {
|
|
31
|
+
return {
|
|
32
|
+
x: 0,
|
|
33
|
+
y: 0,
|
|
34
|
+
vx: 0,
|
|
35
|
+
vy: 0,
|
|
36
|
+
life: 0,
|
|
37
|
+
maxLife: 0,
|
|
38
|
+
startSize: 1,
|
|
39
|
+
endSize: 1,
|
|
40
|
+
startAlpha: 1,
|
|
41
|
+
endAlpha: 0,
|
|
42
|
+
startR: 1,
|
|
43
|
+
startG: 1,
|
|
44
|
+
startB: 1,
|
|
45
|
+
endR: 1,
|
|
46
|
+
endG: 1,
|
|
47
|
+
endB: 1,
|
|
48
|
+
rotation: 0,
|
|
49
|
+
angularVelocity: 0,
|
|
50
|
+
active: false
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function resetParticle(p) {
|
|
54
|
+
p.x = 0;
|
|
55
|
+
p.y = 0;
|
|
56
|
+
p.vx = 0;
|
|
57
|
+
p.vy = 0;
|
|
58
|
+
p.life = 0;
|
|
59
|
+
p.maxLife = 0;
|
|
60
|
+
p.startSize = 1;
|
|
61
|
+
p.endSize = 1;
|
|
62
|
+
p.startAlpha = 1;
|
|
63
|
+
p.endAlpha = 0;
|
|
64
|
+
p.startR = 1;
|
|
65
|
+
p.startG = 1;
|
|
66
|
+
p.startB = 1;
|
|
67
|
+
p.endR = 1;
|
|
68
|
+
p.endG = 1;
|
|
69
|
+
p.endB = 1;
|
|
70
|
+
p.rotation = 0;
|
|
71
|
+
p.angularVelocity = 0;
|
|
72
|
+
p.active = false;
|
|
73
|
+
}
|
|
74
|
+
var ParticlePool = class {
|
|
75
|
+
_pool;
|
|
76
|
+
_active = [];
|
|
77
|
+
constructor(capacity = 256) {
|
|
78
|
+
this._pool = new import_core.Pool(createParticle, resetParticle);
|
|
79
|
+
this._pool.prewarm(capacity);
|
|
80
|
+
}
|
|
81
|
+
/** Number of currently active particles. */
|
|
82
|
+
get activeCount() {
|
|
83
|
+
return this._active.length;
|
|
84
|
+
}
|
|
85
|
+
/** Read-only access to active particles. */
|
|
86
|
+
get particles() {
|
|
87
|
+
return this._active;
|
|
88
|
+
}
|
|
89
|
+
/** Acquire a particle from the pool. */
|
|
90
|
+
acquire() {
|
|
91
|
+
const p = this._pool.acquire();
|
|
92
|
+
p.active = true;
|
|
93
|
+
this._active.push(p);
|
|
94
|
+
return p;
|
|
95
|
+
}
|
|
96
|
+
/** Update all active particles. Releases dead particles. */
|
|
97
|
+
update(dt, gravityX, gravityY) {
|
|
98
|
+
let i = 0;
|
|
99
|
+
while (i < this._active.length) {
|
|
100
|
+
const p = this._active[i];
|
|
101
|
+
p.life -= dt;
|
|
102
|
+
if (p.life <= 0) {
|
|
103
|
+
p.active = false;
|
|
104
|
+
this._pool.release(p);
|
|
105
|
+
this._active[i] = this._active[this._active.length - 1];
|
|
106
|
+
this._active.pop();
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
p.vx += gravityX * dt;
|
|
110
|
+
p.vy += gravityY * dt;
|
|
111
|
+
p.x += p.vx * dt;
|
|
112
|
+
p.y += p.vy * dt;
|
|
113
|
+
p.rotation += p.angularVelocity * dt;
|
|
114
|
+
i++;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/** Get interpolated size for a particle (0 = start, 1 = end of life). */
|
|
118
|
+
getSize(p) {
|
|
119
|
+
const t = 1 - p.life / p.maxLife;
|
|
120
|
+
return p.startSize + (p.endSize - p.startSize) * t;
|
|
121
|
+
}
|
|
122
|
+
/** Get interpolated alpha for a particle. */
|
|
123
|
+
getAlpha(p) {
|
|
124
|
+
const t = 1 - p.life / p.maxLife;
|
|
125
|
+
return p.startAlpha + (p.endAlpha - p.startAlpha) * t;
|
|
126
|
+
}
|
|
127
|
+
/** Shared color buffer — avoids per-call allocation in the render hot path. */
|
|
128
|
+
_colorBuf = { r: 1, g: 1, b: 1, a: 1 };
|
|
129
|
+
/**
|
|
130
|
+
* Get interpolated color for a particle.
|
|
131
|
+
*
|
|
132
|
+
* Returns a shared buffer — read the values immediately, do not retain the
|
|
133
|
+
* reference. For a fresh object call `getColorInto()` with your own out param.
|
|
134
|
+
*/
|
|
135
|
+
getColor(p) {
|
|
136
|
+
return this.getColorInto(p, this._colorBuf);
|
|
137
|
+
}
|
|
138
|
+
/** Zero-alloc variant — writes the interpolated color into `out`. */
|
|
139
|
+
getColorInto(p, out) {
|
|
140
|
+
const t = 1 - p.life / p.maxLife;
|
|
141
|
+
out.r = p.startR + (p.endR - p.startR) * t;
|
|
142
|
+
out.g = p.startG + (p.endG - p.startG) * t;
|
|
143
|
+
out.b = p.startB + (p.endB - p.startB) * t;
|
|
144
|
+
out.a = p.startAlpha + (p.endAlpha - p.startAlpha) * t;
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
/** Release all active particles back to pool. */
|
|
148
|
+
clear() {
|
|
149
|
+
for (const p of this._active) {
|
|
150
|
+
p.active = false;
|
|
151
|
+
this._pool.release(p);
|
|
152
|
+
}
|
|
153
|
+
this._active.length = 0;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// src/particle-emitter.ts
|
|
158
|
+
var ParticleEmitter = class {
|
|
159
|
+
config;
|
|
160
|
+
pool;
|
|
161
|
+
/** Emitter world position. */
|
|
162
|
+
x = 0;
|
|
163
|
+
y = 0;
|
|
164
|
+
/** Whether the emitter is actively emitting. */
|
|
165
|
+
emitting = true;
|
|
166
|
+
_emitAccumulator = 0;
|
|
167
|
+
_seed = 1;
|
|
168
|
+
constructor(config, maxParticles) {
|
|
169
|
+
this.config = config;
|
|
170
|
+
this.pool = new ParticlePool(maxParticles ?? config.maxParticles ?? 256);
|
|
171
|
+
}
|
|
172
|
+
/** Update the emitter: emit new particles and update existing ones. */
|
|
173
|
+
update(dt) {
|
|
174
|
+
if (this.emitting) {
|
|
175
|
+
this._emitAccumulator += dt * this.config.rate;
|
|
176
|
+
while (this._emitAccumulator >= 1) {
|
|
177
|
+
this._emitAccumulator -= 1;
|
|
178
|
+
if (this.config.maxParticles && this.pool.activeCount >= this.config.maxParticles) {
|
|
179
|
+
this._emitAccumulator = 0;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
this._emitOne();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
this.pool.update(dt, this.config.gravityX ?? 0, this.config.gravityY ?? 0);
|
|
186
|
+
}
|
|
187
|
+
/** Emit a burst of particles. */
|
|
188
|
+
burst(count) {
|
|
189
|
+
for (let i = 0; i < count; i++) {
|
|
190
|
+
if (this.config.maxParticles && this.pool.activeCount >= this.config.maxParticles) break;
|
|
191
|
+
this._emitOne();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/** Stop emitting and clear all particles. */
|
|
195
|
+
reset() {
|
|
196
|
+
this.emitting = false;
|
|
197
|
+
this._emitAccumulator = 0;
|
|
198
|
+
this.pool.clear();
|
|
199
|
+
}
|
|
200
|
+
/** Simple seeded pseudo-random for deterministic particles. */
|
|
201
|
+
_random() {
|
|
202
|
+
this._seed = this._seed * 16807 % 2147483647;
|
|
203
|
+
return (this._seed - 1) / 2147483646;
|
|
204
|
+
}
|
|
205
|
+
/** Random float in [min, max]. */
|
|
206
|
+
_randomRange(min, max) {
|
|
207
|
+
return min + this._random() * (max - min);
|
|
208
|
+
}
|
|
209
|
+
_emitOne() {
|
|
210
|
+
const c = this.config;
|
|
211
|
+
const p = this.pool.acquire();
|
|
212
|
+
p.x = this.x;
|
|
213
|
+
p.y = this.y;
|
|
214
|
+
const angle = c.direction + this._randomRange(-c.spread, c.spread);
|
|
215
|
+
const speed = c.speedMax ? this._randomRange(c.speed, c.speedMax) : c.speed;
|
|
216
|
+
p.vx = Math.cos(angle) * speed;
|
|
217
|
+
p.vy = Math.sin(angle) * speed;
|
|
218
|
+
const lifetime = c.lifetimeMax ? this._randomRange(c.lifetime, c.lifetimeMax) : c.lifetime;
|
|
219
|
+
p.life = lifetime;
|
|
220
|
+
p.maxLife = lifetime;
|
|
221
|
+
p.startSize = c.startSize ?? 4;
|
|
222
|
+
p.endSize = c.endSize ?? 0;
|
|
223
|
+
p.startAlpha = c.startAlpha ?? 1;
|
|
224
|
+
p.endAlpha = c.endAlpha ?? 0;
|
|
225
|
+
if (c.startColor) {
|
|
226
|
+
p.startR = c.startColor.r;
|
|
227
|
+
p.startG = c.startColor.g;
|
|
228
|
+
p.startB = c.startColor.b;
|
|
229
|
+
}
|
|
230
|
+
if (c.endColor) {
|
|
231
|
+
p.endR = c.endColor.r;
|
|
232
|
+
p.endG = c.endColor.g;
|
|
233
|
+
p.endB = c.endColor.b;
|
|
234
|
+
}
|
|
235
|
+
if (c.angularVelocity !== void 0) {
|
|
236
|
+
p.angularVelocity = c.angularVelocityMax ? this._randomRange(c.angularVelocity, c.angularVelocityMax) : c.angularVelocity;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
241
|
+
0 && (module.exports = {
|
|
242
|
+
ParticleEmitter,
|
|
243
|
+
ParticlePool
|
|
244
|
+
});
|
|
245
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/particle-pool.ts","../src/particle-emitter.ts"],"sourcesContent":["export {\n type Particle,\n ParticlePool,\n} from './particle-pool.js';\n\nexport {\n type EmitterConfig,\n ParticleEmitter,\n} from './particle-emitter.js';\n","import { Pool } from '@flare-engine/core';\nimport type { Color } from '@flare-engine/math';\n\n/** A single particle. Managed by ParticlePool — not user-facing. */\nexport interface Particle {\n /** World position. */\n x: number;\n y: number;\n /** Velocity in pixels/second. */\n vx: number;\n vy: number;\n /** Time remaining in seconds. */\n life: number;\n /** Total lifetime for interpolation. */\n maxLife: number;\n /** Start/end size for interpolation. */\n startSize: number;\n endSize: number;\n /** Start/end alpha for interpolation. */\n startAlpha: number;\n endAlpha: number;\n /** Start/end color components for interpolation. */\n startR: number;\n startG: number;\n startB: number;\n endR: number;\n endG: number;\n endB: number;\n /** Rotation in radians. */\n rotation: number;\n /** Angular velocity in radians/second. */\n angularVelocity: number;\n /** Whether this particle is active. */\n active: boolean;\n}\n\n/** Create a default (inactive) particle. */\nfunction createParticle(): Particle {\n return {\n x: 0,\n y: 0,\n vx: 0,\n vy: 0,\n life: 0,\n maxLife: 0,\n startSize: 1,\n endSize: 1,\n startAlpha: 1,\n endAlpha: 0,\n startR: 1,\n startG: 1,\n startB: 1,\n endR: 1,\n endG: 1,\n endB: 1,\n rotation: 0,\n angularVelocity: 0,\n active: false,\n };\n}\n\n/** Reset a particle to default (inactive) state. */\nfunction resetParticle(p: Particle): void {\n p.x = 0;\n p.y = 0;\n p.vx = 0;\n p.vy = 0;\n p.life = 0;\n p.maxLife = 0;\n p.startSize = 1;\n p.endSize = 1;\n p.startAlpha = 1;\n p.endAlpha = 0;\n p.startR = 1;\n p.startG = 1;\n p.startB = 1;\n p.endR = 1;\n p.endG = 1;\n p.endB = 1;\n p.rotation = 0;\n p.angularVelocity = 0;\n p.active = false;\n}\n\n/**\n * ParticlePool — pre-allocated pool of particles.\n * Zero GC pressure during steady-state gameplay.\n */\nexport class ParticlePool {\n private _pool: Pool<Particle>;\n private _active: Particle[] = [];\n\n constructor(capacity = 256) {\n this._pool = new Pool(createParticle, resetParticle);\n this._pool.prewarm(capacity);\n }\n\n /** Number of currently active particles. */\n get activeCount(): number {\n return this._active.length;\n }\n\n /** Read-only access to active particles. */\n get particles(): readonly Particle[] {\n return this._active;\n }\n\n /** Acquire a particle from the pool. */\n acquire(): Particle {\n const p = this._pool.acquire();\n p.active = true;\n this._active.push(p);\n return p;\n }\n\n /** Update all active particles. Releases dead particles. */\n update(dt: number, gravityX: number, gravityY: number): void {\n let i = 0;\n while (i < this._active.length) {\n const p = this._active[i]!;\n p.life -= dt;\n\n if (p.life <= 0) {\n // Dead — release and swap-remove\n p.active = false;\n this._pool.release(p);\n this._active[i] = this._active[this._active.length - 1]!;\n this._active.pop();\n continue;\n }\n\n // Apply gravity\n p.vx += gravityX * dt;\n p.vy += gravityY * dt;\n\n // Integrate position\n p.x += p.vx * dt;\n p.y += p.vy * dt;\n\n // Rotate\n p.rotation += p.angularVelocity * dt;\n\n i++;\n }\n }\n\n /** Get interpolated size for a particle (0 = start, 1 = end of life). */\n getSize(p: Particle): number {\n const t = 1 - p.life / p.maxLife;\n return p.startSize + (p.endSize - p.startSize) * t;\n }\n\n /** Get interpolated alpha for a particle. */\n getAlpha(p: Particle): number {\n const t = 1 - p.life / p.maxLife;\n return p.startAlpha + (p.endAlpha - p.startAlpha) * t;\n }\n\n /** Shared color buffer — avoids per-call allocation in the render hot path. */\n private _colorBuf: Color = { r: 1, g: 1, b: 1, a: 1 };\n\n /**\n * Get interpolated color for a particle.\n *\n * Returns a shared buffer — read the values immediately, do not retain the\n * reference. For a fresh object call `getColorInto()` with your own out param.\n */\n getColor(p: Particle): Color {\n return this.getColorInto(p, this._colorBuf);\n }\n\n /** Zero-alloc variant — writes the interpolated color into `out`. */\n getColorInto(p: Particle, out: Color): Color {\n const t = 1 - p.life / p.maxLife;\n out.r = p.startR + (p.endR - p.startR) * t;\n out.g = p.startG + (p.endG - p.startG) * t;\n out.b = p.startB + (p.endB - p.startB) * t;\n out.a = p.startAlpha + (p.endAlpha - p.startAlpha) * t;\n return out;\n }\n\n /** Release all active particles back to pool. */\n clear(): void {\n for (const p of this._active) {\n p.active = false;\n this._pool.release(p);\n }\n this._active.length = 0;\n }\n}\n","import type { Color } from '@flare-engine/math';\nimport type { Particle } from './particle-pool.js';\nimport { ParticlePool } from './particle-pool.js';\n\n/** Configuration for a ParticleEmitter. */\nexport interface EmitterConfig {\n /** Emission rate in particles per second. */\n rate: number;\n /** Particle lifetime in seconds. */\n lifetime: number;\n /** Min lifetime (if set, actual lifetime is random between lifetime and lifetimeMax). */\n lifetimeMax?: number;\n /** Initial speed in pixels/second. */\n speed: number;\n /** Max speed (random range). */\n speedMax?: number;\n /** Emission direction in radians (0 = right). */\n direction: number;\n /** Spread angle in radians (half-angle of the emission cone). */\n spread: number;\n /** Gravity in pixels/second² (applied each frame). */\n gravityX?: number;\n gravityY?: number;\n /** Start size and end size. */\n startSize?: number;\n endSize?: number;\n /** Start alpha and end alpha. */\n startAlpha?: number;\n endAlpha?: number;\n /** Start color. */\n startColor?: Color;\n /** End color. */\n endColor?: Color;\n /** Angular velocity range (radians/second). */\n angularVelocity?: number;\n angularVelocityMax?: number;\n /** Maximum active particles. */\n maxParticles?: number;\n}\n\n/**\n * ParticleEmitter — emits particles based on a configuration.\n * Uses a ParticlePool for zero-GC operation.\n *\n * Call `update(dt)` each frame. Read `pool.particles` for rendering.\n */\nexport class ParticleEmitter {\n readonly config: EmitterConfig;\n readonly pool: ParticlePool;\n\n /** Emitter world position. */\n x = 0;\n y = 0;\n\n /** Whether the emitter is actively emitting. */\n emitting = true;\n\n private _emitAccumulator = 0;\n private _seed = 1;\n\n constructor(config: EmitterConfig, maxParticles?: number) {\n this.config = config;\n this.pool = new ParticlePool(maxParticles ?? config.maxParticles ?? 256);\n }\n\n /** Update the emitter: emit new particles and update existing ones. */\n update(dt: number): void {\n // Emit new particles\n if (this.emitting) {\n this._emitAccumulator += dt * this.config.rate;\n while (this._emitAccumulator >= 1) {\n this._emitAccumulator -= 1;\n if (this.config.maxParticles && this.pool.activeCount >= this.config.maxParticles) {\n this._emitAccumulator = 0;\n break;\n }\n this._emitOne();\n }\n }\n\n // Update all particles\n this.pool.update(dt, this.config.gravityX ?? 0, this.config.gravityY ?? 0);\n }\n\n /** Emit a burst of particles. */\n burst(count: number): void {\n for (let i = 0; i < count; i++) {\n if (this.config.maxParticles && this.pool.activeCount >= this.config.maxParticles) break;\n this._emitOne();\n }\n }\n\n /** Stop emitting and clear all particles. */\n reset(): void {\n this.emitting = false;\n this._emitAccumulator = 0;\n this.pool.clear();\n }\n\n /** Simple seeded pseudo-random for deterministic particles. */\n private _random(): number {\n this._seed = (this._seed * 16807) % 2147483647;\n return (this._seed - 1) / 2147483646;\n }\n\n /** Random float in [min, max]. */\n private _randomRange(min: number, max: number): number {\n return min + this._random() * (max - min);\n }\n\n private _emitOne(): void {\n const c = this.config;\n const p: Particle = this.pool.acquire();\n\n // Position at emitter origin\n p.x = this.x;\n p.y = this.y;\n\n // Random angle within spread\n const angle = c.direction + this._randomRange(-c.spread, c.spread);\n const speed = c.speedMax ? this._randomRange(c.speed, c.speedMax) : c.speed;\n p.vx = Math.cos(angle) * speed;\n p.vy = Math.sin(angle) * speed;\n\n // Lifetime\n const lifetime = c.lifetimeMax ? this._randomRange(c.lifetime, c.lifetimeMax) : c.lifetime;\n p.life = lifetime;\n p.maxLife = lifetime;\n\n // Size\n p.startSize = c.startSize ?? 4;\n p.endSize = c.endSize ?? 0;\n\n // Alpha\n p.startAlpha = c.startAlpha ?? 1;\n p.endAlpha = c.endAlpha ?? 0;\n\n // Colors\n if (c.startColor) {\n p.startR = c.startColor.r;\n p.startG = c.startColor.g;\n p.startB = c.startColor.b;\n }\n if (c.endColor) {\n p.endR = c.endColor.r;\n p.endG = c.endColor.g;\n p.endB = c.endColor.b;\n }\n\n // Angular velocity\n if (c.angularVelocity !== undefined) {\n p.angularVelocity = c.angularVelocityMax\n ? this._randomRange(c.angularVelocity, c.angularVelocityMax)\n : c.angularVelocity;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAqB;AAqCrB,SAAS,iBAA2B;AAClC,SAAO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
return {
|
|
5
|
+
x: 0,
|
|
6
|
+
y: 0,
|
|
7
|
+
vx: 0,
|
|
8
|
+
vy: 0,
|
|
9
|
+
life: 0,
|
|
10
|
+
maxLife: 0,
|
|
11
|
+
startSize: 1,
|
|
12
|
+
endSize: 1,
|
|
13
|
+
startAlpha: 1,
|
|
14
|
+
endAlpha: 0,
|
|
15
|
+
startR: 1,
|
|
16
|
+
startG: 1,
|
|
17
|
+
startB: 1,
|
|
18
|
+
endR: 1,
|
|
19
|
+
endG: 1,
|
|
20
|
+
endB: 1,
|
|
21
|
+
rotation: 0,
|
|
22
|
+
angularVelocity: 0,
|
|
23
|
+
active: false
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function resetParticle(p) {
|
|
27
|
+
p.x = 0;
|
|
28
|
+
p.y = 0;
|
|
29
|
+
p.vx = 0;
|
|
30
|
+
p.vy = 0;
|
|
31
|
+
p.life = 0;
|
|
32
|
+
p.maxLife = 0;
|
|
33
|
+
p.startSize = 1;
|
|
34
|
+
p.endSize = 1;
|
|
35
|
+
p.startAlpha = 1;
|
|
36
|
+
p.endAlpha = 0;
|
|
37
|
+
p.startR = 1;
|
|
38
|
+
p.startG = 1;
|
|
39
|
+
p.startB = 1;
|
|
40
|
+
p.endR = 1;
|
|
41
|
+
p.endG = 1;
|
|
42
|
+
p.endB = 1;
|
|
43
|
+
p.rotation = 0;
|
|
44
|
+
p.angularVelocity = 0;
|
|
45
|
+
p.active = false;
|
|
46
|
+
}
|
|
47
|
+
var ParticlePool = class {
|
|
48
|
+
_pool;
|
|
49
|
+
_active = [];
|
|
50
|
+
constructor(capacity = 256) {
|
|
51
|
+
this._pool = new Pool(createParticle, resetParticle);
|
|
52
|
+
this._pool.prewarm(capacity);
|
|
53
|
+
}
|
|
54
|
+
/** Number of currently active particles. */
|
|
55
|
+
get activeCount() {
|
|
56
|
+
return this._active.length;
|
|
57
|
+
}
|
|
58
|
+
/** Read-only access to active particles. */
|
|
59
|
+
get particles() {
|
|
60
|
+
return this._active;
|
|
61
|
+
}
|
|
62
|
+
/** Acquire a particle from the pool. */
|
|
63
|
+
acquire() {
|
|
64
|
+
const p = this._pool.acquire();
|
|
65
|
+
p.active = true;
|
|
66
|
+
this._active.push(p);
|
|
67
|
+
return p;
|
|
68
|
+
}
|
|
69
|
+
/** Update all active particles. Releases dead particles. */
|
|
70
|
+
update(dt, gravityX, gravityY) {
|
|
71
|
+
let i = 0;
|
|
72
|
+
while (i < this._active.length) {
|
|
73
|
+
const p = this._active[i];
|
|
74
|
+
p.life -= dt;
|
|
75
|
+
if (p.life <= 0) {
|
|
76
|
+
p.active = false;
|
|
77
|
+
this._pool.release(p);
|
|
78
|
+
this._active[i] = this._active[this._active.length - 1];
|
|
79
|
+
this._active.pop();
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
p.vx += gravityX * dt;
|
|
83
|
+
p.vy += gravityY * dt;
|
|
84
|
+
p.x += p.vx * dt;
|
|
85
|
+
p.y += p.vy * dt;
|
|
86
|
+
p.rotation += p.angularVelocity * dt;
|
|
87
|
+
i++;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** Get interpolated size for a particle (0 = start, 1 = end of life). */
|
|
91
|
+
getSize(p) {
|
|
92
|
+
const t = 1 - p.life / p.maxLife;
|
|
93
|
+
return p.startSize + (p.endSize - p.startSize) * t;
|
|
94
|
+
}
|
|
95
|
+
/** Get interpolated alpha for a particle. */
|
|
96
|
+
getAlpha(p) {
|
|
97
|
+
const t = 1 - p.life / p.maxLife;
|
|
98
|
+
return p.startAlpha + (p.endAlpha - p.startAlpha) * t;
|
|
99
|
+
}
|
|
100
|
+
/** Shared color buffer — avoids per-call allocation in the render hot path. */
|
|
101
|
+
_colorBuf = { r: 1, g: 1, b: 1, a: 1 };
|
|
102
|
+
/**
|
|
103
|
+
* Get interpolated color for a particle.
|
|
104
|
+
*
|
|
105
|
+
* Returns a shared buffer — read the values immediately, do not retain the
|
|
106
|
+
* reference. For a fresh object call `getColorInto()` with your own out param.
|
|
107
|
+
*/
|
|
108
|
+
getColor(p) {
|
|
109
|
+
return this.getColorInto(p, this._colorBuf);
|
|
110
|
+
}
|
|
111
|
+
/** Zero-alloc variant — writes the interpolated color into `out`. */
|
|
112
|
+
getColorInto(p, out) {
|
|
113
|
+
const t = 1 - p.life / p.maxLife;
|
|
114
|
+
out.r = p.startR + (p.endR - p.startR) * t;
|
|
115
|
+
out.g = p.startG + (p.endG - p.startG) * t;
|
|
116
|
+
out.b = p.startB + (p.endB - p.startB) * t;
|
|
117
|
+
out.a = p.startAlpha + (p.endAlpha - p.startAlpha) * t;
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
/** Release all active particles back to pool. */
|
|
121
|
+
clear() {
|
|
122
|
+
for (const p of this._active) {
|
|
123
|
+
p.active = false;
|
|
124
|
+
this._pool.release(p);
|
|
125
|
+
}
|
|
126
|
+
this._active.length = 0;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// src/particle-emitter.ts
|
|
131
|
+
var ParticleEmitter = class {
|
|
132
|
+
config;
|
|
133
|
+
pool;
|
|
134
|
+
/** Emitter world position. */
|
|
135
|
+
x = 0;
|
|
136
|
+
y = 0;
|
|
137
|
+
/** Whether the emitter is actively emitting. */
|
|
138
|
+
emitting = true;
|
|
139
|
+
_emitAccumulator = 0;
|
|
140
|
+
_seed = 1;
|
|
141
|
+
constructor(config, maxParticles) {
|
|
142
|
+
this.config = config;
|
|
143
|
+
this.pool = new ParticlePool(maxParticles ?? config.maxParticles ?? 256);
|
|
144
|
+
}
|
|
145
|
+
/** Update the emitter: emit new particles and update existing ones. */
|
|
146
|
+
update(dt) {
|
|
147
|
+
if (this.emitting) {
|
|
148
|
+
this._emitAccumulator += dt * this.config.rate;
|
|
149
|
+
while (this._emitAccumulator >= 1) {
|
|
150
|
+
this._emitAccumulator -= 1;
|
|
151
|
+
if (this.config.maxParticles && this.pool.activeCount >= this.config.maxParticles) {
|
|
152
|
+
this._emitAccumulator = 0;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
this._emitOne();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
this.pool.update(dt, this.config.gravityX ?? 0, this.config.gravityY ?? 0);
|
|
159
|
+
}
|
|
160
|
+
/** Emit a burst of particles. */
|
|
161
|
+
burst(count) {
|
|
162
|
+
for (let i = 0; i < count; i++) {
|
|
163
|
+
if (this.config.maxParticles && this.pool.activeCount >= this.config.maxParticles) break;
|
|
164
|
+
this._emitOne();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/** Stop emitting and clear all particles. */
|
|
168
|
+
reset() {
|
|
169
|
+
this.emitting = false;
|
|
170
|
+
this._emitAccumulator = 0;
|
|
171
|
+
this.pool.clear();
|
|
172
|
+
}
|
|
173
|
+
/** Simple seeded pseudo-random for deterministic particles. */
|
|
174
|
+
_random() {
|
|
175
|
+
this._seed = this._seed * 16807 % 2147483647;
|
|
176
|
+
return (this._seed - 1) / 2147483646;
|
|
177
|
+
}
|
|
178
|
+
/** Random float in [min, max]. */
|
|
179
|
+
_randomRange(min, max) {
|
|
180
|
+
return min + this._random() * (max - min);
|
|
181
|
+
}
|
|
182
|
+
_emitOne() {
|
|
183
|
+
const c = this.config;
|
|
184
|
+
const p = this.pool.acquire();
|
|
185
|
+
p.x = this.x;
|
|
186
|
+
p.y = this.y;
|
|
187
|
+
const angle = c.direction + this._randomRange(-c.spread, c.spread);
|
|
188
|
+
const speed = c.speedMax ? this._randomRange(c.speed, c.speedMax) : c.speed;
|
|
189
|
+
p.vx = Math.cos(angle) * speed;
|
|
190
|
+
p.vy = Math.sin(angle) * speed;
|
|
191
|
+
const lifetime = c.lifetimeMax ? this._randomRange(c.lifetime, c.lifetimeMax) : c.lifetime;
|
|
192
|
+
p.life = lifetime;
|
|
193
|
+
p.maxLife = lifetime;
|
|
194
|
+
p.startSize = c.startSize ?? 4;
|
|
195
|
+
p.endSize = c.endSize ?? 0;
|
|
196
|
+
p.startAlpha = c.startAlpha ?? 1;
|
|
197
|
+
p.endAlpha = c.endAlpha ?? 0;
|
|
198
|
+
if (c.startColor) {
|
|
199
|
+
p.startR = c.startColor.r;
|
|
200
|
+
p.startG = c.startColor.g;
|
|
201
|
+
p.startB = c.startColor.b;
|
|
202
|
+
}
|
|
203
|
+
if (c.endColor) {
|
|
204
|
+
p.endR = c.endColor.r;
|
|
205
|
+
p.endG = c.endColor.g;
|
|
206
|
+
p.endB = c.endColor.b;
|
|
207
|
+
}
|
|
208
|
+
if (c.angularVelocity !== void 0) {
|
|
209
|
+
p.angularVelocity = c.angularVelocityMax ? this._randomRange(c.angularVelocity, c.angularVelocityMax) : c.angularVelocity;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
export {
|
|
214
|
+
ParticleEmitter,
|
|
215
|
+
ParticlePool
|
|
216
|
+
};
|
|
217
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/particle-pool.ts","../src/particle-emitter.ts"],"sourcesContent":["import { Pool } from '@flare-engine/core';\nimport type { Color } from '@flare-engine/math';\n\n/** A single particle. Managed by ParticlePool — not user-facing. */\nexport interface Particle {\n /** World position. */\n x: number;\n y: number;\n /** Velocity in pixels/second. */\n vx: number;\n vy: number;\n /** Time remaining in seconds. */\n life: number;\n /** Total lifetime for interpolation. */\n maxLife: number;\n /** Start/end size for interpolation. */\n startSize: number;\n endSize: number;\n /** Start/end alpha for interpolation. */\n startAlpha: number;\n endAlpha: number;\n /** Start/end color components for interpolation. */\n startR: number;\n startG: number;\n startB: number;\n endR: number;\n endG: number;\n endB: number;\n /** Rotation in radians. */\n rotation: number;\n /** Angular velocity in radians/second. */\n angularVelocity: number;\n /** Whether this particle is active. */\n active: boolean;\n}\n\n/** Create a default (inactive) particle. */\nfunction createParticle(): Particle {\n return {\n x: 0,\n y: 0,\n vx: 0,\n vy: 0,\n life: 0,\n maxLife: 0,\n startSize: 1,\n endSize: 1,\n startAlpha: 1,\n endAlpha: 0,\n startR: 1,\n startG: 1,\n startB: 1,\n endR: 1,\n endG: 1,\n endB: 1,\n rotation: 0,\n angularVelocity: 0,\n active: false,\n };\n}\n\n/** Reset a particle to default (inactive) state. */\nfunction resetParticle(p: Particle): void {\n p.x = 0;\n p.y = 0;\n p.vx = 0;\n p.vy = 0;\n p.life = 0;\n p.maxLife = 0;\n p.startSize = 1;\n p.endSize = 1;\n p.startAlpha = 1;\n p.endAlpha = 0;\n p.startR = 1;\n p.startG = 1;\n p.startB = 1;\n p.endR = 1;\n p.endG = 1;\n p.endB = 1;\n p.rotation = 0;\n p.angularVelocity = 0;\n p.active = false;\n}\n\n/**\n * ParticlePool — pre-allocated pool of particles.\n * Zero GC pressure during steady-state gameplay.\n */\nexport class ParticlePool {\n private _pool: Pool<Particle>;\n private _active: Particle[] = [];\n\n constructor(capacity = 256) {\n this._pool = new Pool(createParticle, resetParticle);\n this._pool.prewarm(capacity);\n }\n\n /** Number of currently active particles. */\n get activeCount(): number {\n return this._active.length;\n }\n\n /** Read-only access to active particles. */\n get particles(): readonly Particle[] {\n return this._active;\n }\n\n /** Acquire a particle from the pool. */\n acquire(): Particle {\n const p = this._pool.acquire();\n p.active = true;\n this._active.push(p);\n return p;\n }\n\n /** Update all active particles. Releases dead particles. */\n update(dt: number, gravityX: number, gravityY: number): void {\n let i = 0;\n while (i < this._active.length) {\n const p = this._active[i]!;\n p.life -= dt;\n\n if (p.life <= 0) {\n // Dead — release and swap-remove\n p.active = false;\n this._pool.release(p);\n this._active[i] = this._active[this._active.length - 1]!;\n this._active.pop();\n continue;\n }\n\n // Apply gravity\n p.vx += gravityX * dt;\n p.vy += gravityY * dt;\n\n // Integrate position\n p.x += p.vx * dt;\n p.y += p.vy * dt;\n\n // Rotate\n p.rotation += p.angularVelocity * dt;\n\n i++;\n }\n }\n\n /** Get interpolated size for a particle (0 = start, 1 = end of life). */\n getSize(p: Particle): number {\n const t = 1 - p.life / p.maxLife;\n return p.startSize + (p.endSize - p.startSize) * t;\n }\n\n /** Get interpolated alpha for a particle. */\n getAlpha(p: Particle): number {\n const t = 1 - p.life / p.maxLife;\n return p.startAlpha + (p.endAlpha - p.startAlpha) * t;\n }\n\n /** Shared color buffer — avoids per-call allocation in the render hot path. */\n private _colorBuf: Color = { r: 1, g: 1, b: 1, a: 1 };\n\n /**\n * Get interpolated color for a particle.\n *\n * Returns a shared buffer — read the values immediately, do not retain the\n * reference. For a fresh object call `getColorInto()` with your own out param.\n */\n getColor(p: Particle): Color {\n return this.getColorInto(p, this._colorBuf);\n }\n\n /** Zero-alloc variant — writes the interpolated color into `out`. */\n getColorInto(p: Particle, out: Color): Color {\n const t = 1 - p.life / p.maxLife;\n out.r = p.startR + (p.endR - p.startR) * t;\n out.g = p.startG + (p.endG - p.startG) * t;\n out.b = p.startB + (p.endB - p.startB) * t;\n out.a = p.startAlpha + (p.endAlpha - p.startAlpha) * t;\n return out;\n }\n\n /** Release all active particles back to pool. */\n clear(): void {\n for (const p of this._active) {\n p.active = false;\n this._pool.release(p);\n }\n this._active.length = 0;\n }\n}\n","import type { Color } from '@flare-engine/math';\nimport type { Particle } from './particle-pool.js';\nimport { ParticlePool } from './particle-pool.js';\n\n/** Configuration for a ParticleEmitter. */\nexport interface EmitterConfig {\n /** Emission rate in particles per second. */\n rate: number;\n /** Particle lifetime in seconds. */\n lifetime: number;\n /** Min lifetime (if set, actual lifetime is random between lifetime and lifetimeMax). */\n lifetimeMax?: number;\n /** Initial speed in pixels/second. */\n speed: number;\n /** Max speed (random range). */\n speedMax?: number;\n /** Emission direction in radians (0 = right). */\n direction: number;\n /** Spread angle in radians (half-angle of the emission cone). */\n spread: number;\n /** Gravity in pixels/second² (applied each frame). */\n gravityX?: number;\n gravityY?: number;\n /** Start size and end size. */\n startSize?: number;\n endSize?: number;\n /** Start alpha and end alpha. */\n startAlpha?: number;\n endAlpha?: number;\n /** Start color. */\n startColor?: Color;\n /** End color. */\n endColor?: Color;\n /** Angular velocity range (radians/second). */\n angularVelocity?: number;\n angularVelocityMax?: number;\n /** Maximum active particles. */\n maxParticles?: number;\n}\n\n/**\n * ParticleEmitter — emits particles based on a configuration.\n * Uses a ParticlePool for zero-GC operation.\n *\n * Call `update(dt)` each frame. Read `pool.particles` for rendering.\n */\nexport class ParticleEmitter {\n readonly config: EmitterConfig;\n readonly pool: ParticlePool;\n\n /** Emitter world position. */\n x = 0;\n y = 0;\n\n /** Whether the emitter is actively emitting. */\n emitting = true;\n\n private _emitAccumulator = 0;\n private _seed = 1;\n\n constructor(config: EmitterConfig, maxParticles?: number) {\n this.config = config;\n this.pool = new ParticlePool(maxParticles ?? config.maxParticles ?? 256);\n }\n\n /** Update the emitter: emit new particles and update existing ones. */\n update(dt: number): void {\n // Emit new particles\n if (this.emitting) {\n this._emitAccumulator += dt * this.config.rate;\n while (this._emitAccumulator >= 1) {\n this._emitAccumulator -= 1;\n if (this.config.maxParticles && this.pool.activeCount >= this.config.maxParticles) {\n this._emitAccumulator = 0;\n break;\n }\n this._emitOne();\n }\n }\n\n // Update all particles\n this.pool.update(dt, this.config.gravityX ?? 0, this.config.gravityY ?? 0);\n }\n\n /** Emit a burst of particles. */\n burst(count: number): void {\n for (let i = 0; i < count; i++) {\n if (this.config.maxParticles && this.pool.activeCount >= this.config.maxParticles) break;\n this._emitOne();\n }\n }\n\n /** Stop emitting and clear all particles. */\n reset(): void {\n this.emitting = false;\n this._emitAccumulator = 0;\n this.pool.clear();\n }\n\n /** Simple seeded pseudo-random for deterministic particles. */\n private _random(): number {\n this._seed = (this._seed * 16807) % 2147483647;\n return (this._seed - 1) / 2147483646;\n }\n\n /** Random float in [min, max]. */\n private _randomRange(min: number, max: number): number {\n return min + this._random() * (max - min);\n }\n\n private _emitOne(): void {\n const c = this.config;\n const p: Particle = this.pool.acquire();\n\n // Position at emitter origin\n p.x = this.x;\n p.y = this.y;\n\n // Random angle within spread\n const angle = c.direction + this._randomRange(-c.spread, c.spread);\n const speed = c.speedMax ? this._randomRange(c.speed, c.speedMax) : c.speed;\n p.vx = Math.cos(angle) * speed;\n p.vy = Math.sin(angle) * speed;\n\n // Lifetime\n const lifetime = c.lifetimeMax ? this._randomRange(c.lifetime, c.lifetimeMax) : c.lifetime;\n p.life = lifetime;\n p.maxLife = lifetime;\n\n // Size\n p.startSize = c.startSize ?? 4;\n p.endSize = c.endSize ?? 0;\n\n // Alpha\n p.startAlpha = c.startAlpha ?? 1;\n p.endAlpha = c.endAlpha ?? 0;\n\n // Colors\n if (c.startColor) {\n p.startR = c.startColor.r;\n p.startG = c.startColor.g;\n p.startB = c.startColor.b;\n }\n if (c.endColor) {\n p.endR = c.endColor.r;\n p.endG = c.endColor.g;\n p.endB = c.endColor.b;\n }\n\n // Angular velocity\n if (c.angularVelocity !== undefined) {\n p.angularVelocity = c.angularVelocityMax\n ? this._randomRange(c.angularVelocity, c.angularVelocityMax)\n : c.angularVelocity;\n }\n }\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAqCrB,SAAS,iBAA2B;AAClC,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,IACH,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,MAAM;AAAA,IACN,SAAS;AAAA,IACT,WAAW;AAAA,IACX,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,UAAU;AAAA,IACV,iBAAiB;AAAA,IACjB,QAAQ;AAAA,EACV;AACF;AAGA,SAAS,cAAc,GAAmB;AACxC,IAAE,IAAI;AACN,IAAE,IAAI;AACN,IAAE,KAAK;AACP,IAAE,KAAK;AACP,IAAE,OAAO;AACT,IAAE,UAAU;AACZ,IAAE,YAAY;AACd,IAAE,UAAU;AACZ,IAAE,aAAa;AACf,IAAE,WAAW;AACb,IAAE,SAAS;AACX,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MAAE,YAAY,EAAE,aAAa;AAC7B,MAAE,UAAU,EAAE,WAAW;AAGzB,MAAE,aAAa,EAAE,cAAc;AAC/B,MAAE,WAAW,EAAE,YAAY;AAG3B,QAAI,EAAE,YAAY;AAChB,QAAE,SAAS,EAAE,WAAW;AACxB,QAAE,SAAS,EAAE,WAAW;AACxB,QAAE,SAAS,EAAE,WAAW;AAAA,IAC1B;AACA,QAAI,EAAE,UAAU;AACd,QAAE,OAAO,EAAE,SAAS;AACpB,QAAE,OAAO,EAAE,SAAS;AACpB,QAAE,OAAO,EAAE,SAAS;AAAA,IACtB;AAGA,QAAI,EAAE,oBAAoB,QAAW;AACnC,QAAE,kBAAkB,EAAE,qBAClB,KAAK,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,IACzD,EAAE;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flare-engine/particles",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Particle emitter, pool, immediate-mode Skia rendering",
|
|
5
|
+
"keywords": ["flare-engine", "particles", "emitter", "skia"],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Grzegorz Otto",
|
|
8
|
+
"homepage": "https://github.com/grzott/flare-engine#readme",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/grzott/flare-engine/issues"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/grzott/flare-engine.git",
|
|
15
|
+
"directory": "packages/particles"
|
|
16
|
+
},
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"module": "dist/index.mjs",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.mjs",
|
|
24
|
+
"require": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup",
|
|
30
|
+
"test": "bun test",
|
|
31
|
+
"lint": "biome check src/",
|
|
32
|
+
"typecheck": "tsc --noEmit"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@flare-engine/core": "^0.1.0",
|
|
36
|
+
"@flare-engine/math": "^0.1.0"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "restricted",
|
|
40
|
+
"registry": "https://registry.npmjs.org/"
|
|
41
|
+
},
|
|
42
|
+
"sideEffects": false
|
|
43
|
+
}
|