From 5401328b6e69182cdbf879c4dd81d66e8bdc6d00 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Mon, 15 Jul 2024 14:05:19 +0200 Subject: [PATCH] loop optimizations * made cols/rows integer, to avoid that "cols-x" wraps around * pre-compute some expressions that don't depend on loop counters --> wins us 1-4 fps on my 72x72 test setup --- wled00/FX.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 5b367e84..8d523ffc 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -8408,8 +8408,8 @@ uint16_t mode_GEQLASER(void) { SEGMENT.fill(BLACK); const int NUM_BANDS = map(SEGMENT.custom3, 0, 31, 1, 16); // custom3 is 0..31 - const uint16_t cols = SEGMENT.virtualWidth(); - const uint16_t rows = SEGMENT.virtualHeight(); + const int cols = SEGMENT.virtualWidth(); + const int rows = SEGMENT.virtualHeight(); uint32_t ledColorTemp; uint_fast8_t split = map(*projector,0,SEGMENT.virtualWidth(),0,(NUM_BANDS - 1)); @@ -8421,9 +8421,8 @@ uint16_t mode_GEQLASER(void) { uint8_t *fftResult = (uint8_t*)um_data->u_data[2]; uint8_t heights[NUM_GEQ_CHANNELS] = { 0 }; - for (int i=0; i 1) { ledColorTemp = color_fade(ledColor,32,true); + int pPos = linex+(cols/NUM_BANDS)-1; for (int y = (i= linex+(cols/NUM_BANDS)-1)) { // draw if above horizon AND not directly under projector (special case later) + if (heights[i] < rows-horizon && (*projector <=linex || *projector >= pPos)) { // draw if above horizon AND not directly under projector (special case later) - for (uint_fast8_t x=linex; x<=linex+(cols/NUM_BANDS)-1;x++) { + for (uint_fast8_t x=linex; x<=pPos;x++) { SEGMENT.drawLine(x,rows-heights[i]-2,*projector,horizon,ledColorTemp,false,distance); // top perspective } @@ -8465,6 +8465,7 @@ uint16_t mode_GEQLASER(void) { uint32_t ledColor = SEGMENT.color_from_palette(colorIndex, false, PALETTE_SOLID_WRAP, 0); int linex = i*(cols/NUM_BANDS); + int pPos = linex+(cols/NUM_BANDS)-1; if (heights[i] > 1) { @@ -8476,9 +8477,9 @@ uint16_t mode_GEQLASER(void) { ledColorTemp = color_fade(ledColor,128,true); - if (heights[i] < rows-horizon && (*projector <=linex || *projector >= linex+(cols/NUM_BANDS)-1)) { // draw if above horizon AND not directly under projector (special case later) + if (heights[i] < rows-horizon && (*projector <=linex || *projector >= pPos)) { // draw if above horizon AND not directly under projector (special case later) - for (uint_fast8_t x=linex; x<=linex+(cols/NUM_BANDS)-1;x++) { + for (uint_fast8_t x=linex; x<=pPos;x++) { SEGMENT.drawLine(x,rows-heights[i]-2,*projector,horizon,ledColorTemp,false,distance); // top perspective } @@ -8494,14 +8495,16 @@ uint16_t mode_GEQLASER(void) { uint32_t ledColor = SEGMENT.color_from_palette(colorIndex, false, PALETTE_SOLID_WRAP, 0); int linex = i*(cols/NUM_BANDS); + int pPos = linex+(cols/NUM_BANDS)-1; + int pPos1 = linex+(cols/NUM_BANDS); - if (*projector >=linex && *projector <= linex+(cols/NUM_BANDS)-1) { // special case when top perspective is directly under the projector + if (*projector >=linex && *projector <= pPos) { // special case when top perspective is directly under the projector if (heights[i] > 1 && heights[i] < rows-horizon) { ledColorTemp = color_fade(ledColor,128,true); - for (uint_fast8_t x=linex; x<=linex+(cols/NUM_BANDS)-1;x++) { + for (uint_fast8_t x=linex; x<=pPos;x++) { SEGMENT.drawLine(x,rows-heights[i]-2,*projector,horizon,ledColorTemp,false,distance); // top perspective } @@ -8513,7 +8516,7 @@ uint16_t mode_GEQLASER(void) { ledColorTemp = color_fade(ledColor,SEGMENT.intensity,true); - for (uint_fast8_t x=linex; x