Skip to content

Commit 3fd5e19

Browse files
committed
reduce memory needs of popcorn effect
On a matrix with 52 columns, popcorn was requesting around 30Kb of segment data. This patch reduces the data to the actually necessary amount based on the "intensity" slider. If intensity is increased, it means that the effect will get a bigger chunk of data allocated - zero'd out but this does not hurt much.
1 parent 019cafc commit 3fd5e19

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

wled00/FX.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3194,7 +3194,13 @@ static uint16_t mode_popcorn_core(bool useaudio) {
31943194
if (SEGLEN == 1) return mode_static();
31953195
//allocate segment data
31963196
uint16_t strips = SEGMENT.nrOfVStrips();
3197-
uint16_t dataSize = sizeof(spark) * maxNumPopcorn;
3197+
size_t dataSize = sizeof(spark) * maxNumPopcorn;
3198+
uint8_t neededPopcorn = maxNumPopcorn; // WLEDMM
3199+
if (strips > 8) { // WLEDMM more than 8 virtual strips --> reduce memory requirements to minimum necessary
3200+
neededPopcorn = (SEGMENT.intensity*maxNumPopcorn)/255;
3201+
neededPopcorn = min(max(neededPopcorn, uint8_t(2)), uint8_t(maxNumPopcorn));
3202+
dataSize = sizeof(spark) * neededPopcorn;
3203+
}
31983204
if (!SEGENV.allocateData(dataSize * strips)) return mode_static(); //allocation failed
31993205

32003206
Spark* popcorn = reinterpret_cast<Spark*>(SEGENV.data);
@@ -3212,7 +3218,7 @@ static uint16_t mode_popcorn_core(bool useaudio) {
32123218

32133219
struct virtualStrip {
32143220
static void runStrip(uint16_t stripNr, Spark* popcorn, bool useaudio, um_data_t *um_data) { // WLEDMM added useaudio and um_data
3215-
float gravity = -0.0001 - (SEGMENT.speed/200000.0); // m/s/s
3221+
float gravity = -0.0001f - (SEGMENT.speed/200000.0f); // m/s/s
32163222
gravity *= SEGLEN;
32173223

32183224
uint8_t numPopcorn = SEGMENT.intensity*maxNumPopcorn/255;
@@ -3267,7 +3273,7 @@ static uint16_t mode_popcorn_core(bool useaudio) {
32673273
};
32683274

32693275
for (int stripNr=0; stripNr<strips; stripNr++)
3270-
virtualStrip::runStrip(stripNr, &popcorn[stripNr * maxNumPopcorn], useaudio, um_data); // WLEDMM added useaudio and um_data
3276+
virtualStrip::runStrip(stripNr, &popcorn[stripNr * neededPopcorn], useaudio, um_data); // WLEDMM added useaudio and um_data
32713277

32723278
return FRAMETIME;
32733279
}

0 commit comments

Comments
 (0)