Porównaj commity

...

11 Commity

Autor SHA1 Wiadomość Data
Damian Schneider 9fa410fe15
Merge a692563100 into bd1c06a7a7 2024-04-10 23:04:18 +02:00
Damian Schneider a692563100 merge commit of dev branch, reworked the whole system into a class
- put particle system in a class, went through the whole code, rewrote many of the functions
- added local rendering buffer (renders to buffer in heap)
- added fast and accurate color-add function
- converted all FX to the class and improved all of them with parameter tuning and new features
- fixed animation transitions with proper pointer setting in each FX call
- fixed collisions
- changed max number of particles and sprays based on some ram calculations
- countless bugfixes
- still a lot of debug stuff in the code, badly needs a cleanup
2024-04-04 18:24:23 +02:00
Damian Schneider 848d3d0263 updated PS Fireworks with many changes and fine-tuning of parameters
-removed spiral explosions
-added more versatility to circular explosions
-removed user selectable amount of rockets
-tuned explosion size of circular explosions to match random explosions (more or less, may need improvement)
-changed order of sliders in volcano animation
2024-03-25 19:10:08 +01:00
Damian Schneider add7051172 bugfix 2024-03-25 19:08:01 +01:00
Damian Schneider 65648140e2 Big update: lots of little fixes and big speed boost on fire animation
-fixed fire burning more on the left side
-fixed crash in particle attractor
-added many improvements for ESP8266
-improved particle rendering efficiency
-efficiency improvements in general
-changed the way fire is rendered, now more than 2x faster
-re-tuned fire to new rendering, also seperately tuned it for ESP8266
-changed all random8() to random16() as it runs faster on ESPs
-some reformating
-some renaming of effect stuff
-fine tuning on falling particle effect
-improvements to collision handling (faster and better)
-added a (temporary) function for speed tests, will be removed again
2024-03-25 19:08:01 +01:00
Damian Schneider e06a95f847 slight speed improvements in fire, like 1-2FPS 2024-03-21 22:42:45 +01:00
Damian Schneider 6c757573a9 Particle FX Rename, default parameter tuning, bugfix
-Now shorter names, 'PS' in front to filter the list
-Tuned default parameters to make them look better by default
-Bugfix in particle system (removed duplicate application of velocity)
-reduced PS fire RAM usage (less particles, less base flames, no noticeable difference)
-some variable renaming
2024-03-21 15:55:40 +01:00
Damian Schneider eebabb2cce added particle graphical equalizer (GEQ) 2024-03-20 19:51:29 +01:00
Damian Schneider 6d70b6ab02 Cleanup & Bugfixes plus major improvements for ESP8266
-added particle reductions for ESP8266 for all FX
-Removed collisions from Particle Perlin Noise FX, slows things down and does not contribute to a better effect experience
-lots of optimizations for ESP8266, all FX now work (at least on 160MHz but still slow)
-Some bugfixes
-removed unused variables to make compiler happy
2024-03-19 20:17:13 +01:00
Damian Schneider 7abbac5815 FX update
- changed firework exhaust to low saturation
- updated rotating particle spray animation
2024-03-17 21:59:42 +01:00
Damian Schneider da726c56e6 Squashed commit of FXparticleSystem 2024-03-13 20:57:15 +01:00
4 zmienionych plików z 2931 dodań i 3 usunięć

Plik diff jest za duży Load Diff

Wyświetl plik

@ -313,8 +313,20 @@
#define FX_MODE_WAVESINS 184
#define FX_MODE_ROCKTAVES 185
#define FX_MODE_2DAKEMI 186
#define MODE_COUNT 187
#define FX_MODE_PARTICLEVOLCANO 187
#define FX_MODE_PARTICLEFIRE 188
#define FX_MODE_PARTICLEFIREWORKS 189
#define FX_MODE_PARTICLEVORTEX 190
#define FX_MODE_PARTICLEPERLIN 191
#define FX_MODE_PARTICLEPIT 192
#define FX_MODE_PARTICLEBOX 193
#define FX_MODE_PARTICLEATTRACTOR 194
#define FX_MODE_PARTICLEIMPACT 195
#define FX_MODE_PARTICLEWATERFALL 196
#define FX_MODE_PARTICLESPRAY 197
#define FX_MODE_PARTICLESGEQ 198
#define FX_MODE_PARTICLECENTERGEQ 199
#define MODE_COUNT 200
typedef enum mapping1D2D {
M12_Pixels = 0,

Plik diff jest za duży Load Diff

Wyświetl plik

@ -0,0 +1,174 @@
/*
FXparticleSystem.cpp
Particle system with functions for particle generation, particle movement and particle rendering to RGB matrix.
by DedeHai (Damian Schneider) 2013-2024
LICENSE
The MIT License (MIT)
Copyright (c) 2024 Damian Schneider
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <stdint.h>
#include "FastLED.h"
//memory allocation
#define ESP8266_MAXPARTICLES 148 // enough for one 16x16 segment with transitions
#define ESP8266_MAXSOURCES 16
#define ESP32S2_MAXPARTICLES 768 // enough for four 16x16 segments
#define ESP32S2_MAXSOURCES 48
#define ESP32_MAXPARTICLES 1024 // enough for four 16x16 segments TODO: not enough for one 64x64 panel...
#define ESP32_MAXSOURCES 64
//particle dimensions (subpixel division)
#define PS_P_RADIUS 64 //subpixel size, each pixel is divided by this for particle movement, if this value is changed, also change the shift defines (next two lines)
#define PS_P_HALFRADIUS 32
#define PS_P_RADIUS_SHIFT 6 // shift for RADIUS
#define PS_P_SURFACE 12 // shift: 2^PS_P_SURFACE = (PS_P_RADIUS)^2
#define PS_P_HARDRADIUS 80 //hard surface radius of a particle, used for collision detection proximity
#define PS_P_MINSURFACEHARDNESS 128 //minimum hardness used in collision impulse calculation, below this hardness, particles become sticky
#define PS_P_MAXSPEED 200 //maximum speed a particle can have
//struct for a single particle
typedef struct {
int16_t x; //x position in particle system
int16_t y; //y position in particle system
int8_t vx; //horizontal velocity
int8_t vy; //vertical velocity
uint8_t hue; // color hue
uint8_t sat; // color saturation
//two byte bit field:
uint16_t ttl : 12; // time to live, 12 bit or 4095 max (which is 50s at 80FPS)
bool outofbounds : 1; //out of bounds flag, set to true if particle is outside of display area
bool collide : 1; //if set, particle takes part in collisions
bool flag3 : 1; // unused flags...
bool flag4 : 1;
} PSparticle;
//struct for a particle source
typedef struct {
uint16_t minLife; //minimum ttl of emittet particles
uint16_t maxLife; //maximum ttl of emitted particles
PSparticle source; //use a particle as the emitter source (speed, position, color)
uint8_t var; //variation of emitted speed
int8_t vx; //emitting speed
int8_t vy; //emitting speed
} PSsource;
// struct for PS settings
typedef struct
{
// add a one byte bit field:
bool wrapX : 1;
bool wrapY : 1;
bool bounceX : 1;
bool bounceY : 1;
bool killoutofbounds : 1; // if set, out of bound particles are killed immediately
bool useGravity : 1; //set to 1 if gravity is used, disables bounceY at the top
bool useCollisions : 1;
bool colorByAge : 1; // if set, particle hue is set by ttl value in render function
} PSsettings;
class ParticleSystem
{
public:
ParticleSystem(uint16_t width, uint16_t height, uint16_t numberofparticles, uint16_t numberofsources); // constructor
// note: memory is allcated in the FX function, no deconstructor needed
void update(void); //update the particles according to set options and render to the matrix
void updateFire(uint32_t intensity); // update function for fire
// particle emitters
void flameEmit(PSsource &emitter);
void sprayEmit(PSsource &emitter);
void angleEmit(PSsource& emitter, uint16_t angle, uint32_t speed);
void updateSystem(void); // call at the beginning of every FX, updates pointers and dimensions
// move functions
void particleMoveUpdate(PSparticle &part, PSsettings &options);
//particle physics
void applyGravity(PSparticle *part, uint32_t numarticles, uint8_t force, uint8_t *counter);
void applyGravity(PSparticle *part, uint32_t numarticles, uint8_t *counter); //use global gforce
void applyGravity(PSparticle *part); //use global system settings
void applyForce(PSparticle *part, uint32_t numparticles, int8_t xforce, int8_t yforce, uint8_t *counter);
void applyForce(PSparticle *part, uint32_t numparticles, int8_t xforce, int8_t yforce);
void applyAngleForce(PSparticle *part, uint32_t numparticles, uint8_t force, uint16_t angle, uint8_t *counter);
void applyAngleForce(PSparticle *part, uint32_t numparticles, uint8_t force, uint16_t angle);
void applyFriction(PSparticle *part, uint8_t coefficient); // apply friction to specific particle
void applyFriction(uint8_t coefficient); // apply friction to all used particles
void attract(PSparticle *particle, PSparticle *attractor, uint8_t *counter, uint8_t strength, bool swallow);
//set options
void setUsedParticles(uint16_t num);
void setCollisionHardness(uint8_t hardness); //hardness for particle collisions (255 means full hard)
void setWallHardness(uint8_t hardness); //hardness for bouncing on the wall if bounceXY is set
void setMatrixSize(uint16_t x, uint16_t y);
void setWrapX(bool enable);
void setWrapY(bool enable);
void setBounceX(bool enable);
void setBounceY(bool enable);
void setKillOutOfBounds(bool enable); //if enabled, particles outside of matrix instantly die
void setColorByAge(bool enable);
void enableGravity(bool enable, uint8_t force = 8);
void enableParticleCollisions(bool enable, uint8_t hardness = 255);
PSparticle *particles; // pointer to particle array
PSsource *sources; // pointer to sources
uint8_t* PSdataEnd; //points to first available byte after the PSmemory, is set in setPointers(). use this to set pointer to FX custom data
uint16_t maxX, maxY; //particle system size i.e. width-1 / height-1 in subpixels
uint32_t maxXpixel, maxYpixel; // last physical pixel that can be drawn to (FX can read this to read segment size if required)
uint8_t numSources; //number of sources
uint16_t numParticles; // number of particles available in this system
uint16_t usedParticles; // number of particles used in animation (can be smaller then numParticles)
PSsettings particlesettings; // settings used when updating particles (can also used by FX to move sources), do not edit properties directly, use functions above
private:
//rendering functions
void ParticleSys_render(bool firemode = false, uint32_t fireintensity = 128);
void renderParticle(PSparticle *particle, uint32_t brightess, int32_t *pixelvalues, int32_t (*pixelpositions)[2]);
//paricle physics applied by system if flags are set
void handleCollisions();
void collideParticles(PSparticle *particle1, PSparticle *particle2);
void fireParticleupdate();
//utility functions
void updatePSpointers(); // update the data pointers to current segment data space
int32_t wraparound(int32_t w, int32_t maxvalue);
int32_t calcForce_dV(int8_t force, uint8_t *counter);
CRGB **allocate2Dbuffer(uint32_t cols, uint32_t rows);
// note: variables that are accessed often are 32bit for speed
uint32_t emitIndex; // index to count through particles to emit so searching for dead pixels is faster
int32_t collisionHardness;
int32_t wallHardness;
uint8_t gforcecounter; //counter for global gravity
uint8_t gforce; //gravity strength, default is 8
uint8_t collisioncounter; //counter to handle collisions
};
//initialization functions (not part of class)
bool initParticleSystem(ParticleSystem *&PartSys, uint16_t additionalbytes = 0);
uint32_t calculateNumberOfParticles();
uint32_t calculateNumberOfSources();
bool allocateParticleSystemMemory(uint16_t numparticles, uint16_t numsources, uint16_t additionalbytes);
//color add function
CRGB fast_color_add(CRGB c1, CRGB c2, uint32_t scale); // fast and accurate color adding with scaling (scales c2 before adding)