Skip to content

Commit

Permalink
bugfix in wrap function and firwork FX
Browse files Browse the repository at this point in the history
  • Loading branch information
DedeHai committed Apr 24, 2024
1 parent 2e7fbc0 commit e43f3bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions wled00/FXparticleSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit e43f3bd

Please sign in to comment.