From 3fd5e190c499a5765a9660d042ec233d82398c5c Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Tue, 16 Apr 2024 20:07:51 +0200 Subject: [PATCH] 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. --- wled00/FX.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index c4b1e0e9..5fa0a0fe 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -3194,7 +3194,13 @@ static uint16_t mode_popcorn_core(bool useaudio) { if (SEGLEN == 1) return mode_static(); //allocate segment data uint16_t strips = SEGMENT.nrOfVStrips(); - uint16_t dataSize = sizeof(spark) * maxNumPopcorn; + size_t dataSize = sizeof(spark) * maxNumPopcorn; + uint8_t neededPopcorn = maxNumPopcorn; // WLEDMM + if (strips > 8) { // WLEDMM more than 8 virtual strips --> reduce memory requirements to minimum necessary + neededPopcorn = (SEGMENT.intensity*maxNumPopcorn)/255; + neededPopcorn = min(max(neededPopcorn, uint8_t(2)), uint8_t(maxNumPopcorn)); + dataSize = sizeof(spark) * neededPopcorn; + } if (!SEGENV.allocateData(dataSize * strips)) return mode_static(); //allocation failed Spark* popcorn = reinterpret_cast(SEGENV.data); @@ -3212,7 +3218,7 @@ static uint16_t mode_popcorn_core(bool useaudio) { struct virtualStrip { static void runStrip(uint16_t stripNr, Spark* popcorn, bool useaudio, um_data_t *um_data) { // WLEDMM added useaudio and um_data - float gravity = -0.0001 - (SEGMENT.speed/200000.0); // m/s/s + float gravity = -0.0001f - (SEGMENT.speed/200000.0f); // m/s/s gravity *= SEGLEN; uint8_t numPopcorn = SEGMENT.intensity*maxNumPopcorn/255; @@ -3267,7 +3273,7 @@ static uint16_t mode_popcorn_core(bool useaudio) { }; for (int stripNr=0; stripNr