From e43f3bd5c612379c7004db005cd90e688f2036de Mon Sep 17 00:00:00 2001 From: Damian Schneider Date: Wed, 24 Apr 2024 17:33:02 +0200 Subject: [PATCH] bugfix in wrap function and firwork FX --- wled00/FX.cpp | 2 +- wled00/FXparticleSystem.cpp | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index a809d68085..f29b8ce825 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -8063,7 +8063,7 @@ uint16_t mode_particlefireworks(void) if (SEGMENT.call == 0) // initialization { - if (!initParticleSystem(PartSys, NUMBEROFSOURCES)) // init, no additional data needed + if (!initParticleSystem(PartSys, NUMBEROFSOURCES, true)) // init with advanced particle properties return mode_static(); // allocation failed; //allocation failed PartSys->setKillOutOfBounds(true); //out of bounds particles dont return (except on top, taken care of by gravity setting) PartSys->setWallHardness(100); //ground bounce is fixed diff --git a/wled00/FXparticleSystem.cpp b/wled00/FXparticleSystem.cpp index 087990a863..0277df3fa5 100644 --- a/wled00/FXparticleSystem.cpp +++ b/wled00/FXparticleSystem.cpp @@ -1207,18 +1207,20 @@ void ParticleSystem::collideParticles(PSparticle *particle1, PSparticle *particl } -//fast calculation of particle wraparound (modulo version takes 37 instructions, this only takes 28, other variants are slower on ESP8266) +//calculation of particle wraparound //function assumes that out of bounds is checked before calling it int32_t ParticleSystem::wraparound(int32_t p, int32_t maxvalue) { + /* + //variant without modulo (but is unsafe, far out particles will not get wrapped!) TODO: !!! remove this variant if (p < 0) - { p += maxvalue + 1; - } else //if (p > maxvalue) - { p -= maxvalue + 1; - } + return p;*/ + p = p % (maxvalue + 1); + if (p < 0) + p = maxvalue - p; return p; }