Skip to content

Commit e43f3bd

Browse files
committed
bugfix in wrap function and firwork FX
1 parent 2e7fbc0 commit e43f3bd

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

wled00/FX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8063,7 +8063,7 @@ uint16_t mode_particlefireworks(void)
80638063

80648064
if (SEGMENT.call == 0) // initialization
80658065
{
8066-
if (!initParticleSystem(PartSys, NUMBEROFSOURCES)) // init, no additional data needed
8066+
if (!initParticleSystem(PartSys, NUMBEROFSOURCES, true)) // init with advanced particle properties
80678067
return mode_static(); // allocation failed; //allocation failed
80688068
PartSys->setKillOutOfBounds(true); //out of bounds particles dont return (except on top, taken care of by gravity setting)
80698069
PartSys->setWallHardness(100); //ground bounce is fixed

wled00/FXparticleSystem.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,18 +1207,20 @@ void ParticleSystem::collideParticles(PSparticle *particle1, PSparticle *particl
12071207

12081208
}
12091209

1210-
//fast calculation of particle wraparound (modulo version takes 37 instructions, this only takes 28, other variants are slower on ESP8266)
1210+
//calculation of particle wraparound
12111211
//function assumes that out of bounds is checked before calling it
12121212
int32_t ParticleSystem::wraparound(int32_t p, int32_t maxvalue)
12131213
{
1214+
/*
1215+
//variant without modulo (but is unsafe, far out particles will not get wrapped!) TODO: !!! remove this variant
12141216
if (p < 0)
1215-
{
12161217
p += maxvalue + 1;
1217-
}
12181218
else //if (p > maxvalue)
1219-
{
12201219
p -= maxvalue + 1;
1221-
}
1220+
return p;*/
1221+
p = p % (maxvalue + 1);
1222+
if (p < 0)
1223+
p = maxvalue - p;
12221224
return p;
12231225
}
12241226

0 commit comments

Comments
 (0)