pixi-reels
Reference
Identity

The frame pipeline

How a result grid becomes the symbols that land, wrap by wrap.

The server tells your game how a spin ends: "reel one shows ace, king, ten". The reel, meanwhile, is a strip of symbols that is longer than the window, scrolling past at thirty cells a second and refilling itself from the top. Somewhere between those two facts, every symbol the server named has to be slipped into the strip at exactly the right moment so that when the reel snaps to the grid, those three are the ones in the window, the half-visible symbols above and below them look plausible, and nothing the player saw a moment ago has changed under their eyes.

The motion page explains where every symbol is at any instant. This page is about which symbol sits in each seat. The answer has three parts: the shape the result arrives in, one column at a time; the small pipeline that turns a column into a complete list of ids for the strip, buffers included; and the random provider that fills in everything the server did not specify. All of it lives under packages/pixi-reels/src/frame/.

ColumnTarget: one column, visible-relative

A column target describes what one reel should end up showing. It is a plain object with a visible array (the symbols in the window, top to bottom) and two optional arrays for the buffer cells, bufferStart for the side with the smaller coordinate (above, on a vertical set) and bufferEnd for the other side. The buffer arrays count outward from the window, so bufferStart[0] is the cell just above the first visible one. Most games only ever fill in visible; the buffers exist for the cases where what peeks out of the window matters, like a big symbol whose tail should be visible before the whole thing has landed.

Figure 1 shows one target addressed three ways, with two buffer cells per side. Read the columns left to right: the strip index, which starts at the furthest buffer above; the cell coordinate, where 0 is the first visible cell and buffers above are negative; and the field of the target each one maps to. Notice that the cell coordinate is the one the public API uses everywhere, because it does not change when you change the buffer size.

strip[i]cellColumnTarget fieldgetTargetSlot(target, cell)0-2bufferStart[1]1-1bufferStart[0]20visible[0]31visible[1]42visible[2]53bufferEnd[0]64bufferEnd[1]bufferStart[-1 - cell]visible[cell]bufferEnd[cell - visible.length]strip[i] = getTargetSlot(target, i - bufferStart)
One ColumnTarget addressed three ways, with bufferStart = 2: by strip index (0 is the furthest buffer-above slot), by cell coordinate (0 is the first visible cell, the dashed outline is the window), and by field.

The formula at the bottom of the figure converts between the two numberings. A strip index counts from the top of the whole array, a cell coordinate counts from the top of the window, and the window starts bufferStart seats down the array, so subtracting bufferStart from a strip index gives the cell coordinate. The strip itself is bufferStart + visible.length + bufferEnd.length ids long. Any slot the target does not name comes back undefined, and the engine fills it with a random symbol. A target entry that lies beyond the reel's buffer capacity would be silently dropped by the conversion, which is why every public entry point runs assertBufferCountsInRange first and refuses it with an error instead.

buffer slotbufferStart[0] is nearest the window top, bufferEnd[0] nearest the bottom
visible slotvisible[0..visibleCells-1]
FrameBuilderproduces the strip
entry pointssetResult, initialFrame, refill

The exact type, in frame/ColumnTarget.ts, is { visible: string[]; bufferStart?: (string | undefined)[]; bufferEnd?: (string | undefined)[] }. It is deliberately plain data with no methods, so it survives structuredClone, JSON and postMessage, and a worker or a server can produce it directly. A handful of exported helpers read and write it; the table lists them with what each is for.

HelperWhat it does
getTargetSlot(target, cell)Reads one slot by cell coordinate. A negative cell reads bufferStart[-1 - cell]; a cell at or past visible.length reads bufferEnd[cell - visible.length]; anything not set comes back undefined.
setTargetSlot(target, cell, id)Writes the same coordinate, creating or extending the buffer arrays as needed. It mutates the target, so take cloneColumnTarget(target) first if you still need the original; the clone is one level deep. Writing undefined (the internal clearTargetSlot) means "random-fill this slot".
columnTargetToStrip(target, bufferStart)Produces the strip form from the figure: strip[i] = getTargetSlot(target, i - bufferStart).
assertColumnTargets(grid, label)Throws a readable TypeError when handed the pre-v2 string[][] shape, with the fix in the message: wrap each column as { visible }.
assertBufferCountsInRange(grid, bufferStartPerReel, bufferEndPerReel, label)Throws a RangeError when the highest defined buffer index is at or past the reel's buffer capacity. Sparse arrays are fine, and an empty buffer is always in range.

Big symbols use the same shape with one convention. The server sends the id at the block's anchor cell only, and coordinateBigSymbols (spin/bigSymbolBlocks.ts) checks that each block fits and then paints a sentinel id, OCCUPIED_SENTINEL ('__pixi_reels_occupied__'), into every other cell the block covers, across neighbouring reels too. An anchor may sit in bufferStart with its tail reaching into the window, the "tail-visible" partial landing, and a block anchored on the last visible cell spills its stubs into bufferEnd. The buffer indexing guide has the worked cases.

The middleware chain

Turning a target into a strip is a two-step job: fill every slot with something plausible, then overwrite the slots the target actually names. The FrameBuilder does it as a small middleware chain, the same pattern as an HTTP server: each middleware receives a context object and a next() function, does its part, and calls next() to pass control on. Figure 2 shows the two built-in middlewares and where one of yours would sit. Notice that the chain is ordered by a priority number, and that the built-ins leave room on either side and in between.

FrameContextsymbols: '' x M, target?, metadatareelIndex, visibleCells, buffersrandom-fillpriority 0: every slot drawn by kind'bufferStart', 'spinning', 'bufferEnd'target-placementpriority 10: columnTargetToStrip()overwrites every defined idyour middlewareany priority; sort is stableno next() stops the chain herestring[] stripindex 0 = the furthest buffer-above slot
FrameBuilder.build runs a next()-style chain sorted by ascending priority. The two built-ins fill every slot and then overwrite the defined target slots; yours goes before, between or after them by priority.

The context, FrameContext, is what the middlewares work on. It carries symbols, an array of M empty strings to fill; the optional target; a metadata object that is fresh for every build, for passing notes between middlewares; and the reel's geometry: reelIndex, visibleCells, bufferStart, bufferEnd and isSpinning. The first built-in, random-fill at priority 0, draws an id for every slot. It knows which kind of slot it is filling, buffer above, visible, or buffer below, and draws from the matching pool, so a collectible that should never be half-visible can be excluded from the buffers alone. The second, target-placement at priority 10, converts the target to strip form and overwrites every slot where the target has an id.

Where you put your own middleware changes what it sees. Above priority 10 it sees the finished frame and can inspect or adjust it. Below 0 it runs first and can pre-seed slots; the random fill keeps what it wrote, because the fill only draws into empty strings. Between 0 and 10 it sees the random ids but will be overwritten wherever the target has an id. The sort is lazy and stable, so two middlewares with equal priority keep the order they were registered in. Register with builder.frameMiddleware(mw); FrameBuilder.use(mw), remove(name) and the middleware getter also exist. There is no separate FrameAPI type: FrameContext plus FrameMiddleware { name, priority, process(ctx, next) } is the whole surface. A middleware that does not call next() stops the chain there.

buildAll(reelCount, ...) maps build over the reels. The randomProvider getter is @internal: a middleware that needs a random id should read the slot it is filling, or carry its own provider, rather than reach into the builder's.

When it runs

It is easy to assume the builder runs every time a symbol wraps. It does not. Figure 3 shows the three callers, and each runs it once per reel per result: the builder's initial frame, the spin result, and a cascade refill. Notice that the spin result does not reach the builder straight away; it waits at a gate until every reel is actually in its spin phase, and passes through the big-symbol coordinator first.

ReelSetBuilder.build()the initial frame,seeded by .initialFrame()setResult(grid)asserts the grid, overlayspins, then _resultSymbolsrefill({ grid })cascade: frames builtup front from the gridgateevery reel in 'spin'then begin the stopcoordinateBigSymbolsvalidates block fit,paints OCCUPIED (pure)FrameBuilder.build(...)(reelIndex, cells, bufferStart, bufferEnd, target)once per reel per result
Who calls build(). FrameBuilder is not called per wrap: it runs once per reel per result, from three callers, and the spin result passes the gate and the big-symbol coordinator first.

Once a strip exists it has to reach the reel at the right moment, which is not when the result arrives but when that reel begins to stop. Figure 4 follows one strip from the builder to the wrap callback. Notice the cache in the middle: the strip is built as soon as the result is accepted, parked per reel, and only read when the stop phase for that reel starts, which may be seconds later for the last reel.

FrameBuilder.build(...)one string[] per reel_cachedFrames[i]held reels get []StopPhase.targetFrame_frameFor(i), at stop timeReel.setStopFrame(frame)the spinOut stepStopSequencer.setFrame()forward: end-first, cursor M-1reverse: head-first, cursor 0Reel._onSymbolWrapped()next() once per wrap while stopping
From the cached strip to the sequencer. The strip is cached per reel, read at stop time, loaded into the StopSequencer with the reel's feed edge, and consumed one id per wrap.

The three callers in detail. The builder makes the initial frame when you call build(), seeded by whatever you passed to .initialFrame(). The spin result is built once every reel that is not held has entered its spin phase, in _tryBeginStopSequence in packages/pixi-reels/src/spin/SpinController.ts; on a MultiWays set it uses the pending shape for the per-reel cell count, so a reshape lands the right number of symbols. A cascade refill builds all its frames up front from the grid you pass. In every case the output is a string[], the same format Reel.placeStrip accepts when a skip, a turbo stop or a cascade places a whole strip at once; placeStrip random-fills any undefined entry by slot kind. The last box in figure 4 is the join with the motion page: while a reel is stopping, each wrap consumes one id from the sequencer, and every other wrap draws from the provider directly. The gate and the phases around it are on the spin lifecycle page.

RandomSymbolProvider: layered pools

Everything the server did not specify, which is most of what scrolls past during a spin, comes from the RandomSymbolProvider. At its simplest it is a weighted draw: every registered symbol has a weight, and a heavier symbol appears more often. On top of that base you can layer pools, each of which adjusts weights or excludes ids for one scope: all reels or one reel, and the spinning slots or the buffer slots. Figure 5 shows the layers in the order they are applied, widest first, so that a narrower scope always wins over a wider one. Notice that a draw for a visible slot stops after three layers, while a draw for a buffer slot runs through all seven.

base weightssymbolData[id].weightglobal spinningset(pool) or { slots: 'spinning' }per-reel spinning{ reel: i }global buffer{ slots: 'buffer' }per-reel buffer{ reel: i, slots: 'buffer' }global side{ slots: 'bufferStart' | 'bufferEnd' }per-reel side{ reel: i, slots: 'bufferStart' | ... }'spinning' draws stop here'buffer': both sides inheritside draws run all seven
One draw resolves the base weights through up to six pool layers, widest first. A 'spinning' draw stops after the third layer; a 'bufferStart' or 'bufferEnd' draw runs all seven, the 'buffer' layers being what both sides inherit.

Resolving the layers on every draw would be slow, so the provider compiles each scope into a table once and caches it. Figure 6 shows the compile and the draw. A weight set by a later layer replaces the earlier one for that id; an exclusion can only ever remove an id, never bring it back; the result is a list of ids with cumulative weights, and a draw is one random number and a binary search.

_resolve(slots, reel)layer weights override idsexcluded ids end at 0DrawTableids, cumulative, totalcached per slots:reelnext(slot, reel)rand = rng() * totalfirst cumulative > rand
The compiled table. Weights override per id, exclusions only accumulate, and the result is a cumulative table that next() binary-searches with one rng() call.

The provider (frame/RandomSymbolProvider.ts, internal, implementing RandomSymbolControl) is built from the symbol data and a random function that defaults to Math.random. Regulated or provably fair deployments inject a seeded generator with builder.rng(fn); the cheats package ships a Mulberry32 for tests. The constructor throws if there are no symbols or the total weight is not positive. A draw names one of three slot kinds, 'spinning', 'bufferStart' or 'bufferEnd'; 'buffer' is a layer you configure that both sides inherit, never a kind you draw from. Tables are cached under `${slots}:${reel ?? '*'}` with zero-weight ids dropped, and the whole cache is cleared on any change to the pools. The table lists the ways the pools can change.

MutationWhat it does
set(pool | null, scope)Checks every id is registered, stores a copy, clears the cached tables, then compiles every scope that could be drawn from. If any scope would have nothing left to draw it rolls back and throws "No symbol left to draw for ... cells on reel N", so a bad pool never reaches a spin.
setExcludeSpinning(ids), setExcludeBuffer(ids)Sugar over set() that keeps the existing weights on the global pool and only changes the exclusions.
updateWeights(symbolsData)Re-reads the base weights, for a game-mode switch, and prunes any pool entry that names an id no longer present, so stale exclusions do not linger.

Four places draw from it. A wrap on a spinning reel draws 'spinning' (Reel._onSymbolWrapped). A buffer refill in placeStrip and the padding for a nudge draw 'bufferStart' or 'bufferEnd'. And a pin backfill draws through the ReelSet.

Pool scopes and the public control

A pool, SymbolPool in frame/SymbolPool.ts, is { weights?: Record<id, number>; exclude?: string[] }; a weight of 0 removes an id as completely as excluding it. Its scope, SymbolPoolScope, is { reel?: number; slots?: SymbolPoolSlots }, where the slots are 'spinning', 'buffer', 'bufferStart' or 'bufferEnd' and default to 'spinning'. 'bufferStart' is always the side with the smaller coordinate, above on a vertical set and left on a horizontal one, whichever way the reel travels. The typical buffer-only pool is { exclude: ['COIN'] }, so a collectible never peeks in half-visible and raises a hope the result will not pay. These random-draw pools are a different thing from the object pools on the symbols page, which recycle symbol instances.

At runtime you reach the pools through reelSet.randomSymbols, the RandomSymbolControl: set(pool | null, scope?) replaces the pool for one scope, clear() drops them all, and weights(scope?) reports the effective weights with excluded ids shown as 0 ('buffer' reports what both sides inherit). At build time the same pools come from builder.randomSymbols(pool, scope).

OffsetCalculator is dead code

If you open frame/OffsetCalculator.ts you will find a class that computes a cross-axis offset per [reel][cell], either 'none' or a 'trapezoid' interpolated from startFactor to endFactor. It is not exported, nothing in the package constructs it, and builder.offsetConfig() stores a value that nothing reads. It plays no part in big symbols, per-reel geometry or curvature; those are handled by Reel._blockSize and _finalizeFrame, mainOffset and reelExtents, and ReelCurve respectively. Do not design against it.

Defaults

The values this page relies on, with the file each one is set in.

ItemValueWhere
Built-in middleware prioritiesrandom-fill 0, target-placement 10frame/FrameBuilder.ts
rngMath.random (inject with builder.rng(fn))frame/RandomSymbolProvider.ts
Symbol weight if unset10core/ReelSetBuilder.ts
Pool scope slots'spinning'frame/SymbolPool.ts
Buffer symbols per side1config/defaults.ts
Big-symbol size{ reels: 1, cells: 1 }config/types.ts
OCCUPIED_SENTINEL'__pixi_reels_occupied__'core/Reel.ts
isSpinning passed to build()never (always false)spin/SpinController.ts
Table cache key`${slots}:${reel ?? "*"}`, cleared on any mutationframe/RandomSymbolProvider.ts

Where this lives

packages/pixi-reels/src/frame/
  • ColumnTarget.ts the shape, getTargetSlot, setTargetSlot, columnTargetToStrip, cloneColumnTarget, assertColumnTargets, assertBufferCountsInRange
  • FrameBuilder.ts FrameContext, FrameMiddleware, build, buildAll, the two built-ins
  • RandomSymbolProvider.ts next, set, tables, layer resolution
  • SymbolPool.ts SymbolPool, SymbolPoolSlots, SymbolPoolScope, RandomSymbolControl
  • OffsetCalculator.ts dead code
callers
  • spin/SpinController.ts _tryBeginStopSequence, _cachedFrames, _frameFor, refill
  • spin/bigSymbolBlocks.ts coordinateBigSymbols
  • spin/phases/StopPhase.ts setStopFrame in the spinOut step
  • core/StopSequencer.ts setFrame(frame, feedEdge), next
  • core/Reel.ts _onSymbolWrapped, placeStrip, nudge padding
  • core/ReelSetBuilder.ts initialFrame, frameMiddleware, randomSymbols, rng, weights