From 971b1cd042d6b29fbb865801f3984f011fd8188b Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Wed, 11 Dec 2024 14:16:46 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=93=20remove=20duplicated=20trail=20dr?= =?UTF-8?q?awing=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nametag/src/rain.cpp | 76 ++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/nametag/src/rain.cpp b/nametag/src/rain.cpp index 47a35d2..0531838 100644 --- a/nametag/src/rain.cpp +++ b/nametag/src/rain.cpp @@ -18,6 +18,7 @@ typedef struct { unsigned long last_moved; } Raindrop; +// TODO: Use a dynamic vector instead Raindrop raindrops[PANEL_WIDTH]; bool rain_initialized = false; uint16_t color_highlight; @@ -72,42 +73,49 @@ void draw_rain(MatrixPanel_I2S_DMA *matrix, Mode mode) { COLOR_DEFAULT_B * brightness ); - if (trail_y >= 0) { - int pixel_num = (trail_y * PANEL_WIDTH) + x; - if (overlay[pixel_num / 8] & (1 << (7 - (pixel_num % 8))) and mode != Stealth) { - if (mode == HighVis) { - matrix->drawPixel(x, trail_y, color_highlight); - } else { - matrix->drawPixel(x, trail_y, matrix->color565( - COLOR_HIGHLIGHT_R * brightness, - COLOR_HIGHLIGHT_G * brightness, - COLOR_HIGHLIGHT_B * brightness - )); - } - } else { - matrix->drawPixel(x, trail_y, fade_color); - } - } else if (raindrops[x].reached_bottom) { - int pixel_num = ((PANEL_HEIGHT + trail_y) * PANEL_WIDTH) + x; - if (raindrops[x].y >= 0) { - - if (overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) ) and mode != Stealth) { - if (mode == HighVis) { - matrix->drawPixel(x, PANEL_HEIGHT + trail_y, color_highlight); - } else { - matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565( - COLOR_HIGHLIGHT_R * brightness, - COLOR_HIGHLIGHT_G * brightness, - COLOR_HIGHLIGHT_B * brightness - )); - } - } else { - matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(0, fade_color, 0)); - } - } else { - break; + if (trail_y < 0) { + if (not raindrops[x].reached_bottom) { + continue; } + // we need to count from the bottom up + trail_y = PANEL_WIDTH + trail_y; } + + int pixel_num = (trail_y * PANEL_WIDTH) + x; + if (overlay[pixel_num / 8] & (1 << (7 - (pixel_num % 8))) and mode != Stealth) { + if (mode == HighVis) { + matrix->drawPixel(x, trail_y, color_highlight); + } else { + matrix->drawPixel(x, trail_y, matrix->color565( + COLOR_HIGHLIGHT_R * brightness, + COLOR_HIGHLIGHT_G * brightness, + COLOR_HIGHLIGHT_B * brightness + )); + } + } else { + matrix->drawPixel(x, trail_y, fade_color); + } + + //} else if (raindrops[x].reached_bottom) { + // int pixel_num = ((PANEL_HEIGHT + trail_y) * PANEL_WIDTH) + x; + // if (raindrops[x].y >= 0) { + // if (overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) ) and mode != Stealth) { + // if (mode == HighVis) { + // matrix->drawPixel(x, PANEL_HEIGHT + trail_y, color_highlight); + // } else { + // matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565( + // COLOR_HIGHLIGHT_R * brightness, + // COLOR_HIGHLIGHT_G * brightness, + // COLOR_HIGHLIGHT_B * brightness + // )); + // } + // } else { + // matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(0, fade_color, 0)); + // } + // } else { + // break; + // } + //} } } }