Skip to content

Commit

Permalink
Started cleanup, speed improvement to rendering, renamed class
Browse files Browse the repository at this point in the history
- removed 'smar' parameter in blur functions as smear is always used
- improved particle rendering (passing by reference, passing wrap parameters for faster access)
- renamed class to ParticleSystem2D
- removed some whitespaces
- some reformating, removed some comments
- minor tweaks
- removed non-working line-attractor function
  • Loading branch information
DedeHai committed Oct 22, 2024
1 parent c57a55c commit 8a13640
Show file tree
Hide file tree
Showing 3 changed files with 473 additions and 616 deletions.
72 changes: 36 additions & 36 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7806,7 +7806,7 @@ uint16_t mode_particlevortex(void)
{
if (SEGLEN == 1)
return mode_static();
ParticleSystem *PartSys = NULL;
ParticleSystem2D *PartSys = NULL;
uint32_t i, j;

if (SEGMENT.call == 0) // initialization
Expand All @@ -7831,7 +7831,7 @@ uint16_t mode_particlevortex(void)
PartSys->setKillOutOfBounds(true);
}
else
PartSys = reinterpret_cast<ParticleSystem *>(SEGENV.data); // if not first call, just set the pointer to the PS
PartSys = reinterpret_cast<ParticleSystem2D *>(SEGENV.data); // if not first call, just set the pointer to the PS

if (PartSys == NULL)
return mode_static(); // something went wrong, no data!
Expand Down Expand Up @@ -7945,7 +7945,7 @@ uint16_t mode_particlefireworks(void)
{
if (SEGLEN == 1)
return mode_static();
ParticleSystem *PartSys = NULL;
ParticleSystem2D *PartSys = NULL;
uint8_t numRockets;
uint32_t i = 0;
uint32_t j = 0;
Expand All @@ -7964,7 +7964,7 @@ uint16_t mode_particlefireworks(void)
}
}
else
PartSys = reinterpret_cast<ParticleSystem *>(SEGENV.data); // if not first call, just set the pointer to the PS
PartSys = reinterpret_cast<ParticleSystem2D *>(SEGENV.data); // if not first call, just set the pointer to the PS

if (PartSys == NULL)
return mode_static(); // something went wrong, no data!
Expand Down Expand Up @@ -8118,7 +8118,7 @@ uint16_t mode_particlevolcano(void)
{
if (SEGLEN == 1)
return mode_static();
ParticleSystem *PartSys = NULL;
ParticleSystem2D *PartSys = NULL;
PSsettings2D volcanosettings;
volcanosettings.asByte = 0b00000100; // PS settings for volcano movement: bounceX is enabled
uint8_t numSprays; // note: so far only one tested but more is possible
Expand All @@ -8145,7 +8145,7 @@ uint16_t mode_particlevolcano(void)
}
}
else
PartSys = reinterpret_cast<ParticleSystem *>(SEGENV.data); // if not first call, just set the pointer to the PS
PartSys = reinterpret_cast<ParticleSystem2D *>(SEGENV.data); // if not first call, just set the pointer to the PS

if (PartSys == NULL)
return mode_static(); // something went wrong, no data!
Expand Down Expand Up @@ -8196,7 +8196,7 @@ uint16_t mode_particlefire(void)
if (SEGLEN == 1)
return mode_static();

ParticleSystem *PartSys = NULL;
ParticleSystem2D *PartSys = NULL;
uint32_t i; // index variable
uint32_t numFlames; // number of flames: depends on fire width. for a fire width of 16 pixels, about 25-30 flames give good results

Expand All @@ -8208,7 +8208,7 @@ uint16_t mode_particlefire(void)
numFlames = PartSys->numSources;
}
else
PartSys = reinterpret_cast<ParticleSystem *>(SEGENV.data); // if not first call, just set the pointer to the PS
PartSys = reinterpret_cast<ParticleSystem2D *>(SEGENV.data); // if not first call, just set the pointer to the PS

if (PartSys == NULL)
return mode_static(); // something went wrong, no data!
Expand Down Expand Up @@ -8308,7 +8308,7 @@ uint16_t mode_particlepit(void)
{
if (SEGLEN == 1)
return mode_static();
ParticleSystem *PartSys = NULL;
ParticleSystem2D *PartSys = NULL;

if (SEGMENT.call == 0) // initialization TODO: make this a PSinit function, this is needed in every particle FX but first, get this working.
{
Expand All @@ -8319,7 +8319,7 @@ uint16_t mode_particlepit(void)
PartSys->setUsedParticles((PartSys->numParticles*3)/2); // use 2/3 of available particles
}
else
PartSys = reinterpret_cast<ParticleSystem *>(SEGENV.data); // if not first call, just set the pointer to the PS
PartSys = reinterpret_cast<ParticleSystem2D *>(SEGENV.data); // if not first call, just set the pointer to the PS

if (PartSys == NULL)
return mode_static(); // something went wrong, no data!
Expand Down Expand Up @@ -8391,7 +8391,7 @@ uint16_t mode_particlewaterfall(void)
{
if (SEGLEN == 1)
return mode_static();
ParticleSystem *PartSys = NULL;
ParticleSystem2D *PartSys = NULL;
uint8_t numSprays;
uint32_t i = 0;

Expand All @@ -8416,7 +8416,7 @@ uint16_t mode_particlewaterfall(void)
}
}
else
PartSys = reinterpret_cast<ParticleSystem *>(SEGENV.data); // if not first call, just set the pointer to the PS
PartSys = reinterpret_cast<ParticleSystem2D *>(SEGENV.data); // if not first call, just set the pointer to the PS

if (PartSys == NULL)
return mode_static(); // something went wrong, no data! (TODO: ask how to handle this so it always works)
Expand Down Expand Up @@ -8473,7 +8473,7 @@ uint16_t mode_particlebox(void)

if (SEGLEN == 1)
return mode_static();
ParticleSystem *PartSys = NULL;
ParticleSystem2D *PartSys = NULL;
uint32_t i;

if (SEGMENT.call == 0) // initialization
Expand All @@ -8500,7 +8500,7 @@ uint16_t mode_particlebox(void)
SEGENV.aux0 = rand(); // position in perlin noise
}
else
PartSys = reinterpret_cast<ParticleSystem *>(SEGENV.data); // if not first call, just set the pointer to the PS
PartSys = reinterpret_cast<ParticleSystem2D *>(SEGENV.data); // if not first call, just set the pointer to the PS

if (PartSys == NULL)
return mode_static(); // something went wrong, no data!
Expand Down Expand Up @@ -8574,7 +8574,7 @@ uint16_t mode_particleperlin(void)
{
if (SEGLEN == 1)
return mode_static();
ParticleSystem *PartSys = NULL;
ParticleSystem2D *PartSys = NULL;
uint32_t i;
if (SEGMENT.call == 0) // initialization TODO: make this a PSinit function, this is needed in every particle FX but first, get this working.
{
Expand All @@ -8588,7 +8588,7 @@ uint16_t mode_particleperlin(void)
}
}
else
PartSys = reinterpret_cast<ParticleSystem *>(SEGENV.data); // if not first call, just set the pointer to the PS
PartSys = reinterpret_cast<ParticleSystem2D *>(SEGENV.data); // if not first call, just set the pointer to the PS

if (PartSys == NULL)
return mode_static(); // something went wrong, no data!
Expand Down Expand Up @@ -8643,7 +8643,7 @@ uint16_t mode_particleimpact(void)
{
if (SEGLEN == 1)
return mode_static();
ParticleSystem *PartSys = NULL;
ParticleSystem2D *PartSys = NULL;
uint32_t i = 0;
uint8_t MaxNumMeteors;
PSsettings2D meteorsettings;
Expand All @@ -8665,7 +8665,7 @@ uint16_t mode_particleimpact(void)
}
}
else
PartSys = reinterpret_cast<ParticleSystem *>(SEGENV.data); // if not first call, just set the pointer to the PS
PartSys = reinterpret_cast<ParticleSystem2D *>(SEGENV.data); // if not first call, just set the pointer to the PS

if (PartSys == NULL)
return mode_static(); // something went wrong, no data! (TODO: ask how to handle this so it always works)
Expand Down Expand Up @@ -8776,7 +8776,7 @@ uint16_t mode_particleattractor(void)
{
if (SEGLEN == 1)
return mode_static();
ParticleSystem *PartSys = NULL;
ParticleSystem2D *PartSys = NULL;
PSsettings2D sourcesettings;
sourcesettings.asByte = 0b00001100; // PS settings for bounceY, bounceY used for source movement (it always bounces whereas particles do not)
PSparticle *attractor; // particle pointer to the attractor
Expand All @@ -8801,7 +8801,7 @@ uint16_t mode_particleattractor(void)
PartSys->setWallRoughness(200); //randomize wall bounce
}
else
PartSys = reinterpret_cast<ParticleSystem *>(SEGENV.data); // if not first call, just set the pointer to the PS
PartSys = reinterpret_cast<ParticleSystem2D *>(SEGENV.data); // if not first call, just set the pointer to the PS

if (PartSys == NULL)
return mode_static(); // something went wrong, no data!
Expand Down Expand Up @@ -8897,7 +8897,7 @@ uint16_t mode_particleattractor(void)
{
if (SEGLEN == 1)
return mode_static();
ParticleSystem *PartSys = NULL;
ParticleSystem2D *PartSys = NULL;
uint32_t i = 0;
PSparticle *attractor; // particle pointer to the attractor
uint8_t *counters; // counters for the applied force
Expand Down Expand Up @@ -8930,7 +8930,7 @@ uint16_t mode_particleattractor(void)
PartSys->sources[0].var = 4; // emiting variation
}
else
PartSys = reinterpret_cast<ParticleSystem *>(SEGENV.data); // if not first call, just set the pointer to the PS
PartSys = reinterpret_cast<ParticleSystem2D *>(SEGENV.data); // if not first call, just set the pointer to the PS
if (PartSys == NULL)
return mode_static(); // something went wrong, no data!
Expand Down Expand Up @@ -9012,7 +9012,7 @@ uint16_t mode_particlespray(void)
{
if (SEGLEN == 1)
return mode_static();
ParticleSystem *PartSys = NULL;
ParticleSystem2D *PartSys = NULL;
//uint8_t numSprays;
const uint8_t hardness = 200; // collision hardness is fixed

Expand All @@ -9029,7 +9029,7 @@ uint16_t mode_particlespray(void)

}
else
PartSys = reinterpret_cast<ParticleSystem *>(SEGENV.data); // if not first call, just set the pointer to the PS
PartSys = reinterpret_cast<ParticleSystem2D *>(SEGENV.data); // if not first call, just set the pointer to the PS

if (PartSys == NULL)
return mode_static(); // something went wrong, no data!
Expand Down Expand Up @@ -9109,7 +9109,7 @@ uint16_t mode_particleGEQ(void)
if (SEGLEN == 1)
return mode_static();

ParticleSystem *PartSys = NULL;
ParticleSystem2D *PartSys = NULL;

if (SEGMENT.call == 0) // initialization
{
Expand All @@ -9119,7 +9119,7 @@ uint16_t mode_particleGEQ(void)
PartSys->setUsedParticles((PartSys->numParticles * 3) / 2); // use 2/3 of available particles
}
else
PartSys = reinterpret_cast<ParticleSystem *>(SEGENV.data); // if not first call, just set the pointer to the PS
PartSys = reinterpret_cast<ParticleSystem2D *>(SEGENV.data); // if not first call, just set the pointer to the PS

if (PartSys == NULL)
return mode_static(); // something went wrong, no data!
Expand Down Expand Up @@ -9205,7 +9205,7 @@ uint16_t mode_particlecenterGEQ(void)
if (SEGLEN == 1)
return mode_static();

ParticleSystem *PartSys = NULL;
ParticleSystem2D *PartSys = NULL;
uint8_t numSprays;
uint32_t i;

Expand All @@ -9225,7 +9225,7 @@ if (SEGLEN == 1)
PartSys->setKillOutOfBounds(true);
}
else
PartSys = reinterpret_cast<ParticleSystem *>(SEGENV.data); // if not first call, just set the pointer to the PS
PartSys = reinterpret_cast<ParticleSystem2D *>(SEGENV.data); // if not first call, just set the pointer to the PS

if (PartSys == NULL)
return mode_static(); // something went wrong, no data!
Expand Down Expand Up @@ -9286,7 +9286,7 @@ uint16_t mode_particleghostrider(void)
{
if (SEGLEN == 1)
return mode_static();
ParticleSystem *PartSys = NULL;
ParticleSystem2D *PartSys = NULL;
PSsettings2D ghostsettings;
ghostsettings.asByte = 0b0000011; //enable wrapX and wrapY

Expand All @@ -9302,7 +9302,7 @@ uint16_t mode_particleghostrider(void)
SEGENV.step = random(MAXANGLESTEP) - (MAXANGLESTEP>>1); // angle increment
}
else
PartSys = reinterpret_cast<ParticleSystem *>(SEGENV.data); // if not first call, just set the pointer to the PS
PartSys = reinterpret_cast<ParticleSystem2D *>(SEGENV.data); // if not first call, just set the pointer to the PS

if (PartSys == NULL)
return mode_static(); // something went wrong, no data!
Expand Down Expand Up @@ -9378,7 +9378,7 @@ uint16_t mode_particleblobs(void)
{
if (SEGLEN == 1)
return mode_static();
ParticleSystem *PartSys = NULL;
ParticleSystem2D *PartSys = NULL;

if (SEGMENT.call == 0)
{
Expand All @@ -9392,7 +9392,7 @@ uint16_t mode_particleblobs(void)
//PartSys->setParticleSize(0); //set global size to zero or motion blur cannot be used (is zero by default)
}
else
PartSys = reinterpret_cast<ParticleSystem *>(SEGENV.data); // if not first call, just set the pointer to the PS
PartSys = reinterpret_cast<ParticleSystem2D *>(SEGENV.data); // if not first call, just set the pointer to the PS

if (PartSys == NULL)
return mode_static(); // something went wrong, no data!
Expand Down Expand Up @@ -9504,7 +9504,7 @@ uint16_t mode_particlefractal(void)
if (SEGLEN == 1)
return mode_static();

ParticleSystem *PartSys = NULL;
ParticleSystem2D *PartSys = NULL;
uint32_t i;

if (SEGMENT.call == 0) // initialization
Expand All @@ -9514,7 +9514,7 @@ if (SEGLEN == 1)
PartSys->setKillOutOfBounds(true);
}
else
PartSys = reinterpret_cast<ParticleSystem *>(SEGENV.data); // if not first call, just set the pointer to the PS
PartSys = reinterpret_cast<ParticleSystem2D *>(SEGENV.data); // if not first call, just set the pointer to the PS

if (PartSys == NULL)
return mode_static(); // something went wrong, no data!
Expand Down Expand Up @@ -10071,8 +10071,8 @@ uint16_t mode_particleSparkler(void)
// Particle System settings
PartSys->updateSystem(); // update system properties (dimensions and data pointers)

sparklersettings.wrapX = SEGMENT.check2;
sparklersettings.bounceX = !SEGMENT.check2;
sparklersettings.wrap = SEGMENT.check2;
sparklersettings.bounce = !SEGMENT.check2;

numSparklers = PartSys->numSources;
PartSys->setMotionBlur(SEGMENT.custom2); // anable motion blur
Expand Down
Loading

0 comments on commit 8a13640

Please sign in to comment.