Skip to content

Commit 71301dd

Browse files
authored
using segment buffer instead of local buffer for PS (#4776)
- using segment buffer instead of local buffer to save FX ram - fix rendering if gamma correction is disabled - some code cleanup - Fix for low RAM: reduce number of particles dynamically - updated add and scale color functions to not use references - FPS is now more consistent and on average about 15% faster
1 parent c30c7e1 commit 71301dd

File tree

5 files changed

+193
-211
lines changed

5 files changed

+193
-211
lines changed

wled00/FX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8837,7 +8837,7 @@ uint16_t mode_particleGEQ(void) {
88378837
//set particle properties TODO: could also use the spray...
88388838
PartSys->particles[i].ttl = 20 + map(SEGMENT.intensity, 0,255, emitspeed>>1, emitspeed + hw_random16(emitspeed)) ; // set particle alive, particle lifespan is in number of frames
88398839
PartSys->particles[i].x = xposition + hw_random16(binwidth) - (binwidth>>1); // position randomly, deviating half a bin width
8840-
PartSys->particles[i].y = PS_P_RADIUS; // start at the bottom (PS_P_RADIUS is minimum position a particle is fully in frame)
8840+
PartSys->particles[i].y = 0; // start at the bottom
88418841
PartSys->particles[i].vx = hw_random16(SEGMENT.custom1>>1)-(SEGMENT.custom1>>2) ; //x-speed variation: +/- custom1/4
88428842
PartSys->particles[i].vy = emitspeed;
88438843
PartSys->particles[i].hue = (bin<<4) + hw_random16(17) - 8; // color from palette according to bin

wled00/FX.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ class Segment {
686686

687687
// 1D strip
688688
uint16_t virtualLength() const;
689+
uint16_t maxMappingLength() const;
689690
[[gnu::hot]] void setPixelColor(int n, uint32_t c) const; // set relative pixel within segment with color
690691
inline void setPixelColor(unsigned n, uint32_t c) const { setPixelColor(int(n), c); }
691692
inline void setPixelColor(int n, byte r, byte g, byte b, byte w = 0) const { setPixelColor(n, RGBW32(r,g,b,w)); }
@@ -808,6 +809,8 @@ class Segment {
808809
inline void wu_pixel(uint32_t x, uint32_t y, CRGB c) {}
809810
#endif
810811
friend class WS2812FX;
812+
friend class ParticleSystem2D;
813+
friend class ParticleSystem1D;
811814
};
812815

813816
// main "strip" class (108 bytes)

wled00/FX_fcn.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,14 @@ uint16_t Segment::virtualLength() const {
645645
return vLength;
646646
}
647647

648+
#ifndef WLED_DISABLE_2D
649+
// maximum length of a mapped 1D segment, used in PS for buffer allocation
650+
uint16_t Segment::maxMappingLength() const {
651+
uint32_t vW = virtualWidth();
652+
uint32_t vH = virtualHeight();
653+
return max(sqrt32_bw(vH*vH + vW*vW), (uint32_t)getPinwheelLength(vW, vH)); // use diagonal
654+
}
655+
#endif
648656
// pixel is clipped if it falls outside clipping range
649657
// if clipping start > stop the clipping range is inverted
650658
bool IRAM_ATTR_YN Segment::isPixelClipped(int i) const {

0 commit comments

Comments
 (0)