Documentation
    Preparing search index...

    Class ParticlePool

    Fixed-capacity structure-of-arrays particle storage. See the module documentation for the layout, the allocation policy, and the swap-remove determinism statement.

    Index
    • Allocates every channel for capacity particles. This is the only allocating operation on the type.

      Parameters

      • capacity: number

      Returns ParticlePool

      RangeError if capacity is not a non-negative safe integer. A capacity of 0 is legal and useful (it makes "every spawn is dropped" testable) — a fractional or negative one is always a mistake.

    ages: Float32Array

    Seconds each particle has lived, stride 1.

    capacity: number

    Maximum simultaneously live particles. Fixed at construction — §36's maxParticles is a budget, and growing a pool mid-frame would allocate on the hot path (§7b).

    colors: Float32Array

    Colour ramp endpoints, stride 8 (r₀ g₀ b₀ a₀ r₁ g₁ b₁ a₁).

    lifetimes: Float32Array

    Seconds each particle may live, stride 1.

    positions: Float32Array

    Positions, stride 3 (x, y, z), capacity entries. Slots >= aliveCount are stale.

    sizes: Float32Array

    Size ramp endpoints, stride 2 (size₀, size₁).

    velocities: Float32Array

    Velocities in units/s, stride 3 (x, y, z).

    • get aliveCount(): number

      Live particle count. The live slots are exactly [0, aliveCount).

      Returns number

    • Drops every particle. Channel arrays keep their contents — the slots are simply no longer live, and ParticlePool.spawn zeroes anything it hands back — so this is O(1).

      Returns void

    • Seconds the live particle index has lived.

      Parameters

      • index: number

      Returns number

    • Writes the current colour of the live particle index into out — the ramp evaluated component-wise at ParticlePool.getNormalizedAge, in the same start + (end − start) · t form as ParticlePool.getSize.

      Straight (non-premultiplied) RGBA, interpolated in whatever space the author wrote the endpoints in; §60a colour management is the renderer's business, not the pool's.

      Parameters

      Returns Vector4

    • Writes the colour at age = lifetime of the live particle index into out.

      Parameters

      Returns Vector4

    • Size at age = lifetime for the live particle index.

      Parameters

      • index: number

      Returns number

    • Seconds the live particle index may live.

      Parameters

      • index: number

      Returns number

    • age / lifetime, clamped to [0, 1] — the parameter every over-lifetime ramp is evaluated at.

      A non-positive lifetime reports 1 (fully aged) rather than Infinity or NaN: a zero-lifetime particle is one the next expiry pass removes, and a ramp evaluated at its end is the honest thing to draw in the meantime.

      Parameters

      • index: number

      Returns number

    • Writes the position of the live particle index into out.

      Parameters

      Returns Vector3

    • Current size of the live particle index: the ramp evaluated at ParticlePool.getNormalizedAge, as start + (end − start) · t.

      That form (rather than (1 − t)·start + t·end) is exact at t = 0 and t = 1 for every pair of endpoints, which is what the tests pin.

      Parameters

      • index: number

      Returns number

    • Writes the colour at age 0 of the live particle index into out as (r, g, b, a).

      Parameters

      Returns Vector4

    • Size at age 0 for the live particle index.

      Parameters

      • index: number

      Returns number

    • Writes the velocity (units/s) of the live particle index into out.

      Parameters

      Returns Vector3

    • Removes the particle at index by moving the last live particle into its slot (swap-remove) and decrementing ParticlePool.aliveCount.

      Killing the last live particle is the degenerate case: the "move" is a self-copy, skipped. See the module note on what this does and does not cost.

      Parameters

      • index: number

      Returns void

      RangeError if index is not a live slot.

    • Sets the age (seconds) of the live particle index.

      Parameters

      • index: number
      • age: number

      Returns void

    • Sets both colour ramp endpoints of the live particle index, as straight RGBA.

      Parameters

      • index: number
      • r0: number
      • g0: number
      • b0: number
      • a0: number
      • r1: number
      • g1: number
      • b1: number
      • a1: number

      Returns void

    • Sets the lifetime (seconds) of the live particle index.

      Parameters

      • index: number
      • lifetime: number

      Returns void

    • Sets the position of the live particle index.

      Parameters

      • index: number
      • x: number
      • y: number
      • z: number

      Returns void

    • Sets the size ramp endpoints of the live particle index.

      Parameters

      • index: number
      • start: number
      • end: number

      Returns void

    • Sets the velocity (units/s) of the live particle index.

      Parameters

      • index: number
      • x: number
      • y: number
      • z: number

      Returns void

    • Claims the next free slot and returns its index, or -1 when the pool is full — the caller decides whether that is a dropped spawn (the emitter counts them) or an error.

      The returned slot is zeroed in every channel, so a recycled slot never leaks its previous occupant's state into a caller that forgets to write a channel. Note that a zeroed lifetime means ParticlePool.getNormalizedAge reports 1 until a real lifetime is written.

      Returns number