Skip to content

Commit

Permalink
added WLED_DISABLE_PARTICLESYSTEM option, fixed volcano movement
Browse files Browse the repository at this point in the history
use '-D WLED_DISABLE_PARTICLESYSTEM' to disable compiling
  • Loading branch information
DedeHai committed May 7, 2024
1 parent 1e6e84e commit 935c476
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
17 changes: 12 additions & 5 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7892,6 +7892,8 @@ uint16_t mode_2Dwavingcell() {
}
static const char _data_FX_MODE_2DWAVINGCELL[] PROGMEM = "Waving Cell@!,,Amplitude 1,Amplitude 2,Amplitude 3;;!;2";

#ifndef WLED_DISABLE_PARTICLESYSTEM

/*
* Particle System Vortex
* Particles sprayed from center with a rotating spray
Expand Down Expand Up @@ -8222,9 +8224,12 @@ uint16_t mode_particlevolcano(void)
if (SEGLEN == 1)
return mode_static();
ParticleSystem *PartSys = NULL;
PSsettings 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
uint32_t i = 0;


if (SEGMENT.call == 0) // initialization
{
if (!initParticleSystem(PartSys, NUMBEROFSOURCES)) // init, no additional data needed
Expand Down Expand Up @@ -8274,12 +8279,12 @@ uint16_t mode_particlevolcano(void)
PartSys->sources[i].source.y = PS_P_RADIUS + 5; // reset to just above the lower edge that is allowed for bouncing particles, if zero, particles already 'bounce' at start and loose speed.
PartSys->sources[i].source.vy = 0; //reset speed (so no extra particlesettin is required to keep the source 'afloat')
PartSys->sources[i].source.hue++; // = random16(); //change hue of spray source (note: random does not look good)
PartSys->sources[i].source.vx = PartSys->sources[i].source.vx > 0 ? SEGMENT.custom1 >> 4 : -(SEGMENT.custom1 >> 4); // set moving speed but keep the direction given by PS
PartSys->sources[i].source.vx = PartSys->sources[i].source.vx > 0 ? SEGMENT.custom1 >> 2 : -(SEGMENT.custom1 >> 2); // set moving speed but keep the direction given by PS
PartSys->sources[i].vy = SEGMENT.speed >> 2; // emitting speed
PartSys->sources[i].vx = 0;
PartSys->sources[i].var = SEGMENT.custom3 >> 1; // emiting variation = nozzle size (custom 3 goes from 0-31)
PartSys->sprayEmit(PartSys->sources[i]);
PartSys->particleMoveUpdate(PartSys->sources[i].source); //move the source (also applies gravity, which is corrected for above, that is a hack but easier than creating more particlesettings)
PartSys->particleMoveUpdate(PartSys->sources[i].source, &volcanosettings); //move the source
}
}

Expand Down Expand Up @@ -9367,8 +9372,6 @@ uint16_t mode_particleghostrider(void)
SEGMENT.aux0 += (int32_t)SEGMENT.step; // step is angle increment
uint16_t emitangle = SEGMENT.aux0 + 32767; // +180°
int32_t speed = map(SEGMENT.speed, 0, 255, 12, 64);
int8_t newvx = ((int32_t)cos16(SEGMENT.aux0) * speed) / (int32_t)32767;
int8_t newvy = ((int32_t)sin16(SEGMENT.aux0) * speed) / (int32_t)32767;
PartSys->sources[0].source.vx = ((int32_t)cos16(SEGMENT.aux0) * speed) / (int32_t)32767;
PartSys->sources[0].source.vy = ((int32_t)sin16(SEGMENT.aux0) * speed) / (int32_t)32767;
PartSys->sources[0].source.ttl = 500; // source never dies (note: setting 'perpetual' is not needed if replenished each frame)
Expand Down Expand Up @@ -9596,6 +9599,9 @@ uint16_t mode_particlecenterGEQ(void)
}
static const char _data_FX_MODE_PARTICLECCIRCULARGEQ[] PROGMEM = "PS Center GEQ@Speed,Color Change,Particle Speed,Spray Count,Nozzle Size,Random Color, Direction;;!;012;pal=56,sx=0,ix=222,c1=190,c2=200,c3=0,o1=0,o2=0";
*/

#endif //WLED_DISABLE_PARTICLESYSTEM

#endif // WLED_DISABLE_2D


Expand Down Expand Up @@ -9837,6 +9843,7 @@ void WS2812FX::setupEffectData() {

addEffect(FX_MODE_2DAKEMI, &mode_2DAkemi, _data_FX_MODE_2DAKEMI); // audio

#ifndef WLED_DISABLE_PARTICLESYSTEM
addEffect(FX_MODE_PARTICLEVORTEX, &mode_particlevortex, _data_FX_MODE_PARTICLEVORTEX);
addEffect(FX_MODE_PARTICLEFIREWORKS, &mode_particlefireworks, _data_FX_MODE_PARTICLEFIREWORKS);
addEffect(FX_MODE_PARTICLEVOLCANO, &mode_particlevolcano, _data_FX_MODE_PARTICLEVOLCANO);
Expand All @@ -9851,8 +9858,8 @@ void WS2812FX::setupEffectData() {
addEffect(FX_MODE_PARTICLESGEQ, &mode_particleGEQ, _data_FX_MODE_PARTICLEGEQ);
addEffect(FX_MODE_PARTICLEGHOSTRIDER, &mode_particleghostrider, _data_FX_MODE_PARTICLEGHOSTRIDER);
addEffect(FX_MODE_PARTICLEBLOBS, &mode_particleblobs, _data_FX_MODE_PARTICLEBLOBS);

// addEffect(FX_MODE_PARTICLECENTERGEQ, &mode_particlecenterGEQ, _data_FX_MODE_PARTICLECCIRCULARGEQ);
#endif // WLED_DISABLE_PARTICLESYSTEM

#endif // WLED_DISABLE_2D

Expand Down
7 changes: 5 additions & 2 deletions wled00/FXparticleSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
-add possiblity to emit more than one particle, just pass a source and the amount to emit or even add several sources and the amount, function decides if it should do it fair or not
-add an x/y struct, do particle rendering using that, much easier to read
*/
// sources need to be updatable by the FX, so functions are needed to apply it to a single particle that are public

#ifndef WLED_DISABLE_PARTICLESYSTEM

#include "FXparticleSystem.h"
#include "wled.h"
#include "FastLED.h"
Expand Down Expand Up @@ -1538,4 +1540,5 @@ void blur2D(CRGB **colorbuffer, uint32_t xsize, uint32_t ysize, uint32_t xblur,
}
fast_color_add(colorbuffer[x][ysize-1], carryover); // set last pixel
}
}
}}

5 changes: 4 additions & 1 deletion wled00/FXparticleSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
THE SOFTWARE.
*/

#ifndef WLED_DISABLE_PARTICLESYSTEM

#include <stdint.h>
#include "FastLED.h"
Expand Down Expand Up @@ -219,4 +220,6 @@ bool allocateParticleSystemMemory(uint16_t numparticles, uint16_t numsources, bo
// color functions
void fast_color_add(CRGB &c1, CRGB &c2, uint32_t scale = 255); // fast and accurate color adding with scaling (scales c2 before adding)
void fast_color_scale(CRGB &c, uint32_t scale); // fast scaling function using 32bit variable and pointer. note: keep 'scale' within 0-255
void blur2D(CRGB **colorbuffer, uint32_t xsize, uint32_t ysize, uint32_t xblur, uint32_t yblur, bool smear = true, uint32_t xstart = 0, uint32_t ystart = 0, bool isparticle = false);
void blur2D(CRGB **colorbuffer, uint32_t xsize, uint32_t ysize, uint32_t xblur, uint32_t yblur, bool smear = true, uint32_t xstart = 0, uint32_t ystart = 0, bool isparticle = false);

#endif // WLED_DISABLE_PARTICLESYSTEM

0 comments on commit 935c476

Please sign in to comment.