FastLED 3.9.15
Loading...
Searching...
No Matches
chasing_spiral_state.h
Go to the documentation of this file.
1#pragma once
2
3// Per-animation persistent cache for Chasing Spirals variants.
4// Holds the SoA (Structure-of-Arrays) pixel geometry and the Perlin fade LUT.
5//
6// Lifetime: declared as a module-level global in chasing_spirals.cpp.hpp.
7// Assumes single-threaded access (no locking).
8// Future: convert to a class with private instance data when multiple
9// concurrent animation instances are needed.
10
11#include "fl/stl/align.h"
12#include "fl/stl/stdint.h"
13#include "fl/stl/vector.h"
14
15namespace fl {
16
17// FL_ALIGNAS(16): aligns the struct itself to 16 bytes, satisfying SSE2
18// requirements for load_u32_4_aligned at BOUNDARY A in the SIMD inner loop.
19//
20// The fl::vector heap buffers inside this struct rely on the platform allocator
21// providing >= 16-byte alignment for allocations >= 16 bytes (guaranteed by
22// glibc, musl, Darwin, Windows CRT, and ESP-IDF heap on all SIMD-capable targets).
23struct FL_ALIGNAS(16) ChasingSpiralState {
24 // SoA pixel geometry — built once when grid size changes, reused every frame.
25 // Each array has `count` valid entries, padded to the next multiple of 4
26 // (so SIMD loads never read past the allocation).
27 fl::vector<fl::i32> base_angle; // 3*theta - dist/3, raw s16x16
28 fl::vector<fl::i32> dist_scaled; // distance * 0.1, raw s16x16
29 fl::vector<fl::i32> rf3; // 3 * radial_filter, raw s16x16 (red)
30 fl::vector<fl::i32> rf_half; // radial_filter / 2, raw s16x16 (green)
31 fl::vector<fl::i32> rf_quarter; // radial_filter / 4, raw s16x16 (blue)
32 fl::vector<fl::u16> pixel_idx; // pre-mapped xyMap(x,y) LED index
33 int count = 0;
34
35 // Perlin fade LUT (257 entries, Q8.24 format).
36 // FL_ALIGNAS(16): enables aligned SIMD loads in pnoise2d_raw_simd4_vec.
37 FL_ALIGNAS(16) fl::i32 fade_lut[257];
38 bool fade_lut_initialized = false;
39
40 ChasingSpiralState() : fade_lut{}, fade_lut_initialized(false) {}
41};
42
43} // namespace fl
Alignment macros and utilities for FastLED.
struct FL_ALIGNAS(4) Wave3BitExpansionLut
Lookup table for nibble-to-waveform expansion in wave3 format (32 bytes)
Definition wave3.h:31
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_ALIGNAS(N)