mirror of
https://github.com/wled/WLED.git
synced 2025-07-19 08:46:34 +00:00
Adding Particle System with many new FX (#4506)
* cleanup * added collision handling back in update from another commit that got lost * reformat * added latest version of functions this somehow also got lost from an earlier commit * Update platformio.ini * updated particle box and firework effects particle box now is more random in random mode (still a work in progress) firework is now more configurable by sliders * added preliminary functions and FX * added particle attractor, added two new FX but still buggy particle attractor animation does not work, somthing wrong with pointer allocation, it worked with static variables * bugfixes, attracot now works still unknown, why more than 256 particles are needed in memory allocation to not make it crash, but it works for now * added angle emitter, added fireworks effect using it * Added saturation to be set for each particle individually at the expense of more ram usage, animations now have more options for color control (already used in fireworks now) * bugfixes in impact animation * added option to use fast color add, may improve performance a little also fixed a bug in fire animation * collision detection is now a function plus some improvements & fixes * improved collision efficiency improved efficiency for stackup (pushback), added code to correctly determine direction if particles meed (probably overkill but now its there) * added fix for piling oscillations untested, need to verify it works * Improved collision handling (faster, less oscillations), changed variables to 32bit for faster calculation 32bit variables are faster on ESP32, so use them whenever a variable is used a lot, it saves one instruction per access. * removed option for fastcolor add it made very little difference in performance, but for ESP8266 it may matter so it is set permanently there. graphically the difference is also very small (sometimes a particle gets brighter or less saturated) * Fixed some bugs in particle system, runs much smoother now also tweaked some of the FX * Bugfix in particle push, now piling is working again particle pile-up did not work correctly, now fixed * changed particle pile demo into waterfall plus some tweaks * lots of bugfixes * updated particle attractor animation parameters and added more user options to perlin noise * removed TODOs * added particle WrapUpdate function, added spray FX, some bugfixes * fixed touch buttons for ESP32 S2 and S3 touch is implemented differently on S2 and S3, these changes make touch buttons work on S2 and S3 * some tuning for touch buttons on S2/S3 now better fits the default threshold value of 32 * updated rotating particle spray with more user options * chaned rotating spray default parameters * add todo * Revert "some tuning for touch buttons on S2/S3" This reverts commit d21ad8e7d1651a96f879d43ef1146a72a6ed8271. * Revert "fixed touch buttons for ESP32 S2 and S3" This reverts commit 09041551862361cd8c7444ca25403f5f96a9077b. * removed comments, added comments * cleanup -removed wrap_update function, now integrated into move_update -added more 'out of bounds' checking in fire functions, may speed it up a little * cleanup session -removed particle box 'rocking boat' (buggy) and replaced with random sloshing. -removed comments -changed some variables into 32bit for speed boost on ESP32 -added link to KB at the top of FX.cpp * cleanup removed / added comments * added particle GEQ effect (untested) * Particle GEQ fixes, it now actually works * GEQ FX parameter tuning * added rotating GEQ, work in progress -animation works but sliders are too sensitive. need to adjust the ranges * FX update - changed firework exhaust to low saturation - updated rotating particle spray animation * 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 * 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 * slight speed improvements in fire, like 1-2FPS * 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 * bugfix * 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 * put particle system in a class. work in progress. another huge update to the particle system. went through the whole code, rewrote many of the functions. many improvements over the previous code. fixed many bugs (and even an ancient one in rendering function). spent many hours optimizing the code for speed and usability. still a work in progress, debugging is ongoing. more updates to come. * many (many!) bugfixes, added fire FX back in (and improved it a lot) added local renderbuffer for huge speed boost -lots of bugfixes in Particle system -added local rendering buffer (renders to buffer in heap) -added fast and accurate color-add function -bugfixes in render function -added improved 'sticky' particles in collision (unfinished business) -added ballpit animation back -lots of tweaks to fire FX and fire rendering functions, looks even better now (still unfinished) -added palette render option to fire still many debug print outputs around, needs cleanup at one point * More Bugfixes, more converted FX * more bugfixes, some animation tuning, added volcano back in - fixed animation transitions with proper pointer setting in each FX call - added color by age setting to particle system - maybe fixed collision having a tendency to go to the left - fixed bugs in fireworks FX - added fire spread width as a slider - changed max number of particles and sprays based on some ram calculations - some other random fixes * updated fire, added some functions to PS, ported attractor FX - added turbulance to fire (after hours of fine-tuning) it now looks even more awesome - added attractor animation back in and improved it with more functionality - fixed the attractor function in the PS - renamed FX: 'candy' is now called 'vortex' - added new force function to apply a force immediately (and handle the timing in the FX) - added update function to PS for size update to handle dynamic segment size change - made waterfall width dynamic on segment width - removed some debug stuff - added #defines for maximum number of particles/sprays - updated fire parameter to make it look better on ESP8266 - some little bugfixes * another huge update, many improvements, fine-tune collision, fire and some other FX -removed classic fire render as palette now looks much better -tweaked fire parameters to more awesome -added (optional) turbulence to fire using perlin-noise -ported spray FX to use PS-class -now definitely fixed asymmetrical collision issue: do not use bitshifts on negative numbers! -changed piling behaviour of particles, full rework. looks way more natural now and works much better -changed bouncing behavour: they now bounce at full diameter, making them stay fully in frame when laying on the floor -replaced all relevant bitshifts with divisions for higher accuracy throughout the PS -added new modes to particle box FX -changed a lot of FX parameters (finetuning) -changed all config strings to proper settings (matrix only) -fixed newly introduced bugs -added speedup/slowdown to vortex FX (aka candy, aka rotating sprays) -some renaming -fixed bugs… lots of bugs -merged rendering functions, removed obsolete stuff * Fixed Speed limit limiting speed was incorrect, leading to overflows. fixed this. also fixed bugs in GEQ, removed some debug stuff, added FPS limit to fire (just en experiment) * work in progress, added motion blur and line attracto (non working) * work in progress, added test function to increase particle size, also added wobbling test * added more tests, non compiling at the moment * in the middle of fixing FX to use new PS functions * debugging going on * bugfix in wrap function and firwork FX * added local render blurring, boosting FPS, work in progress - changed fast-add function to use pointers - added fast-scaling function - added simple (but fast) 2D blurring function test shows that local blurring of full frame is almost double the speed (40FPS now is 80FPS). lots of comments still there * Bugfixes, improvements and added wall roughness setting - fixed bug in PS fuzzy noise which made it asymmetric for some reason, seems to work better now - added particle size option to attractor but had to remove speed setting (now fixed emit speed) - some parameter tuning of FX - improvements to code size in render function - added smear option to blurring (not tested much, may be buggy without smear) - speed improvement to caldForce_dv, added zero checking. * removed zero inits - removed zero initialisations in FX, segment.data is set to zero by alloc function * added individual size particle rendering plus some fixes - advanced particles can now be rendered to individual sizes. It is computationally intensive but it works well for up to 15 very large particles and more smaller ones - added collision handling for individual sizes (walls and collisions) - fixed bugs in particlebox - fixed fire not transitioning properly (flickering) when frame skip is active - removed 'wraparound' function as it can easily be done by casting to an unsigned and then modulo - fixed ballpit particles wandering left and right very fast if wrapX is set * Fixed some nasty memory bugs, fixed some FX parameters - fixed memory alignment bug in PS pointer assignment by making sure only multiples of 4 are allowed for particles and sources - added saturation back to particle struct, as it was aligned to 10 bytes anyway. - fixed a bug where a null pointer could be accessed - fixed rendering out of frame particles if buffer allocation failed - improvements on ESP8266 * Replaced Ghost Rider FX with PS version - new FX is kept close to original animation but added more user settings * added walls to ghostride, fixed some bugs * added 'perpetual' flag to particles * Fixed another memory / pointer bug, but there is still one left... -also some minor fixes * Found and fixed crashes, it was wrongly assigned pointers * Added advanced particle size control and new Blob FX - advanced size control allows for growing, shrinking, wobbling - render function updated to support asymmetric rendering - various code improvements and bugfixes - some FX parameter tuning - bugfix: removed sli() sei() calls in render function that caused random flickering on S3/C3 (may add that back in but only for ESP8266 to reduce fragmentation) - removed some debug / test stuff * code cleanup, removed some unused stuff * bugfix, sprayEmit() would not return and get stuck - forgot default return value... * remove esp_random() as it is not supported on ESP8266 * small bugfix for ESP32, cleanup / reformatting * added WLED_DISABLE_PARTICLESYSTEM option, fixed volcano movement use '-D WLED_DISABLE_PARTICLESYSTEM' to disable compiling * a line got lost in the last commit * - added WLED_DISABLE_PARTICLESYSTEM option & cleanup & bugfixes - cleanup / reformatting - fixed volcano movement - small bugfix for ESP32 (random() does not work, using random16() ) * Added PS source option to emit more than one particle, addes AR to Blobs and Spray * added center GEQ back in, changed AR behaviour of spray a little center GEQ is a mix between the PS equalizer and vortex, tuned for AR. some more tuning may be needed, it can probably be extended and improved a little. * Bugfix and minor improvements - fixed bug in center GEQ - added '2D washing machine' mode for particle box - improved color-change rate in ghostrider - added AR to attractor (experimental, may remove again) * hacked in a 1D port of the 2D PS, untested code * fixed first bugs in 1D system, added test FX * fixed bug in wrapping (also was wrong for 2D system) * fixed collisions, added bouncing ball replacement (work in progress) * replaced more FX, some tweaks to 1D PS - changed virtual particle size from 64 to 32, making them able to move faster - added 'rolling balls' option to bouncing balls (i.e. no gravity plus some tweaks) - added dancing shadows with PS (work in progress) - temporarily removed native FX: bouncing balls, rolling balls, popcorn, dancing shadows -and of course some bugfixes * updated dancing shadows to more closely mimic original * added drip FX, added #ifdefs, removed some common functions #ifdefs to individually disable 1D and 2D system. * fixed compile issue, removed replaced FX (again) * added Fireworks1D replacement (unfinished) also fixed a bug in `applyForce()` using uninitialized variable. * added sparkler and hourglass (both work in progress) tried fixing 1D collisions * many improvements in 1D collisions (fine tuned), hour glass FX is almost done spent A LOT of time in fine-tuning collisions for best stacking without collipsing, ringing, oscillations or particle flips. still not perfect but probably as good as it can be with the limited time-resolution * many bugfixes in PS and FX * minor FX adjustments * Improved 1D collisions, added 2 new 1D FX (work in progress) * bugfixes * added 'color by position' as a PS setting -made settings struct for 1D and 2D version to be different -added setting 'color by position' as that is used by multiple FX now * added large size rendering to 1D PS, work in progress * bugfix (forgot to free memory) also: made random size a permanent option in 1D fireworks as it looks kind of cool * Added PS based Chase, fixed some bugs * minor update * two new FX: Starburst and 1D GEQ * Added more advanced (and proper) size handling in collisions, work in progress - copied and adapted some stuff from 2D system (out of bounds size rendering, dynamic collision detection distance, dynamic wall bounce distance) * fixed some parameters in 1D FX * added #ifndef to disable FX replaced by PS - define DISABLE_1D_PS_REPLACEMENTS or DISABLE_2D_PS_REPLACEMENTS * bugfixes * default parameter change * explicit cast to fix compile error * Bugfixes * added color-waves to PS chase, some parameter tuning plus bugfixes * FX update and bugfixes - fixed wall collisions on larger particle sizes - update to bouncing balls: - added size setting - added proper updating on parameter change - bugfixes added support for 'colorwaves' and 'pride' to PS Chase to save on code size. currently broken... * minor update to rolling balls, fixed stuff in Chase, pride option still not working * update on 'pride' now working again but needs finetuning * SEGMENT -> SEGENV on data, aux0, aux1, step also removed debug outputs * added pride and colorwaves to 1D replacement list * removed unused variables * added variable to set number of particles if not all are required (saves ram) also fixed a nasty render bug * added preliminary 1D fire function, unfinished * added fractal FX test, fixed bugs in emit function * tweaked 1D fire a little, still work in progress * minor tuning on 1D fire to avoid 'oscillation' at start * improved 1D particle fire, much more natural now. * updated 2D fire, fixed init bug - source init was wrong making fire init weirdly - changed parameters on 2D fire making it look better and improving flame height for larger setups * fixed 'nervours' fire * slight improvements and some cleanup * removed douplicate code for fire emit (tradeoff for some speed), removed unfinished fractal FX - with the duplicate code removed, the fire particle emits are a bit slower but it saves on code. it is not really noticeable, its slower by about 1FPS * Re-license from MIT to EUPL * Started cleanup, speed improvement to rendering, renamed class - 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 * Optimization and bugfixes - added out of bounds checking function - fixed rendering at boundaries - various small changes and cleanup - bugfixes with comparing ints of different signeness - fixed bounce radius * Cleanup, bugfixes, speed improvements, refactoring - lots of code refactoring / reformating - fixed bug in fire particle update and improved speed a bit - refactoring of pixel rendering - removed 2D buffers, replaced with 1D buffer for faster access - bugfix in blur2D - many small improvements to 2D system * Refactoring and cleanup of 1D PS, removed debug printouts - code reformating for consistency and readability - replaced "'?" operator with min / max (produces the same code, more readable) - minor changes for speed (random16 used, can later be replaced with hardware random function) - renamed PS Equalizer to PS 2D GEQ * Cleanup and some refactoring of particle FX - moved 2D / length check to PS initi - code reformating - removed some comments * missed a spot * minor tweaks to fast_color_add() * Work in progress: update to fireworks, needs more testing & finetuning also bugs fixed and some minor cleanup * Work in Progress: added particle memory manager for transitions - uses only one, persistant buffer to render all present particle systems - Buffer for particles is shared for one segment (may allow interacitng systems in the future) - updated some of the FX to handle the new transfer, 1D FX still not done - updated parameters for particle impact FX * work in progress: lots of changes & fixes, transitions now work correctly in 2D - still fragile code with lots of cleanup to do * added transitions for big-size rendering - transitions now work with FX that use global large size rendering. this is done by handling the buffer correctly. to avoid creating a second buffer, it is transferred back and forth to the segment. this is a bit slow but a compromise solution. - multiple segment handling is still untested * speed improvement to fast_color_add, added preliminary buffer transfer function * merge fixes * bugfix in setCurrentPalette, corrected order of 2D memory allocation, increased max particles/sources - fixed timing for vortex * fixed particle buffer handover, added 2D blur option, increased particle limits, various fixes - fixed bug in memory watchdog, now works and also works when freezing segments - fixed PS Box to work again with particle handover - added smear blurring to waterfall - added smear blurring to vortex, fixed color distribution, removed random color distribution option - replaced all random() calls with hw_random() - transitions now work but only if FX transitions are enabled and not when chaning segment size * implemented correct 1D<->2D buffer handover+bugfixes work in progress * added smear to fuzzy noise, some cleanup * added blurring option to PS 2D fireworks, work in progress in finding that nasty bug that crashes all * BUGFIX: finally found and squased the memory bug, no more random crashes also: removed debug outputs and minor cleanup * minor cleanup and fixed a bug 1D system had a lot of crashes, some out of bounds memory issue. fixed it but I have no idea which change did that, maybe the order in 1D initialization * BUGFIX: out of bounds checking was wrong, leading to crashes * better handling of used particles in transitions for FX that do not use all particles, transitions were constantly shifting the pointer, resulting in newly generated particles and weird particle flickering, this is not fixed by keeping the pointer constant once the number of used particles is reached. * improved particle transition for low-count FX, updated 1D FX now most 1D FX work again, still needs some fine-tuning * Rework on Fireworks 1D, some minor fixes - fireworks 1D now matches as closely as possible to the old FX still not identical but as good as it gets. * bugfix in PS Chase, increased brightness of 1D fireworks * replaced sin16/cos16 with new versions * bugfixes * fixed hourglass init, rearranged PS FX init * speed optimization - moved out of bounds calculation to proper spot - removed repeated allocation attempts if initial buffer alloc fails * Added Sonic Stream FX, some cleanup, bugfix in emitter * changed TTL to brightness calculation, added collision binning - brightness is now doubled as some FX were really dim due to low TTL - added binning in x-direction giving a huge speed advantage on larger matrix sizes * collision binning bugfix, made particles less sticky, update to waterfall - updated waterfall intensity and blurring * WIP: fixed 1D system for over 1000 pixels, added collision binning for 1D - making x coordinate 32bit allows for larger strips but uses a lot of ram due to struct memory alignment (12bytes instead of 8 bytes), this needs some more work to properly fix. - adding collision binning significantly speeds things up, about a factor of 2 on most FX using collision - there are still some bugs in FX or 1D memory handling (or both) on large setups * moved particle flags to seperate array to save on RAM, refactoring - moving the flags optimizes ram alignment, saving memory for each particle - changed lots of parameters to `const` - moved fire intensity to a variable instead of passing it to every render() call - changed passing pointers to passing reference where possible - saves a total of 340 bytes of flash * removed todos after some checks, minor improvements * inverted y axis in 2D render, 1D collision improvements, cleanup and fixes - inverting the y-axis in the buffer instead of in buffer transfer fixes the FX flipping when transitiononing 1D<->2D - improved particle binning for collisions - added hard-pushing also when not using gravity so piles close to an edge dont collapse - some improvments to "balance" FX - renaming and cleanup * FX fixes and minor tweaks * increased min rockets * fixed #ifdefs * another fix * revert unnecessary changes to base code * merge fix * minor tweak * tweaked sparkler FX, some cleanup * Fix in volcano FX, changed blurring of volcano and waterfall * added ifdefs * minor tweaks, increased 1D minsurfacehardness * improved sparkler FX, made overlay possible (1D not yet), cleanup * cleanup, now using new hsv2rgb/rgb2hsv, add overlay rendering to 1D - new hsv2rgb is a tiny bit faster - removed redundant code (using transferBuffer instead) - tweked parameters in vortex, removed unneeded slider defaults * fix for non or partially overlapping segments - can not use overlay rendering if no segment clears the buffer, it will all add up to white eventually - now additive transfer i.e. overlay mode is only activated if the segment is fully overlapping an underlying segment * change got lost... * increased sparkler intensity, some cleanup * replaced #ifdefs, removed 1D replacements that have 2D version, removed notes * cleanup, improvements to PS bouncing ball, replaced multicomet - bouncing balls is now named pinball and has settings/parameters updated to be a replacement for multicomet * cleanup, improvements, bugfixes - large size rendering now works without framebuffer - background adding is now done on buffer (if avilable) instead of segment - fixed overflow bug in 2D large particle rendering (it worked only for powers of 2 size) * potential bugfix, compiler warning fix * removed colorwaves and pride option from chase (not worthy replacements) * updated #defines, removed PS from 1M and 2M builds * Adding Particle System and PS FX Adding all 187 commits from particle system dev branch * reverted some accidental changes * reverted some accidental changes * merge fixes * changed replacement: multicomet instead of comet (lighthouse) * changed replacement: multicomet instead of comet (lighthouse) * disable 2D PS for ESP8266, some cleanup, improved pinball FX parameters, bugfixes * Improved collision binning for large particles, improved pinball FX * improved speed handling in pinball FX - rolling * disable 2D PS for ESP8266, some cleanup, improved pinball FX parameters, bugfixes * improved hourglass: millis instead of frame timing, better stacking. and cleanup. * revert whitespaces * simplified 1D collisions, improved binning for larger particles - ran a lot of experiments with collisions in 1D, the new much simpler approach seems to be a good compromise with regards to stacking and normal collisions. * Improved collision binning for large particles, improved pinball FX * improved speed handling in pinball FX - rolling * improved hourglass: millis instead of frame timing, better stacking. and cleanup. * revert whitespaces * prohibit use of 1D and 2D system simultaneously on ESP8266 * prohibit use of 1D and 2D system simultaneously on ESP8266 * update to handle blending styles * fixed bugs, improved new transition handling * updated 1D system to work with new transitions, replaced NULL with nullptr * merge fixes * added single pixel particle rendering for 2D system, adjusted FX to work with it * improved collisions in 1D and 2D, some bugfixes in radius calculation, minor tweaks - collisions are now also velocity based in 1D, there was a bug that prevented that from working well (wrong collision distance calculation) - improvement and bugfix in 2D collision distance calculation - added distance based pushing in 2D (instead of only using the dotproduct) the combination of improved distance calculation and proper pushing make collisions a lot better in all tested FX * minor fix * fixed overlay detection, checking for partial overlay if a PS FX is partially overlapping, it will render in overlay mode * better blur range in PS Firworks * minor code consolidation * updated 1D collisions (yet again), improved 2D collision speed - slight improvement to 2D collision code efficiency - added faster "division" to C3/ESP8266 by using a right shift trick (biasing towards 0 also for negative numbers by applying proper rounding) * minor tweak in PS balance
This commit is contained in:
parent
756e27fb52
commit
46a3e3d353
@ -367,6 +367,7 @@ platform_packages = ${common.platform_packages}
|
|||||||
board_build.ldscript = ${common.ldscript_4m1m}
|
board_build.ldscript = ${common.ldscript_4m1m}
|
||||||
build_unflags = ${common.build_unflags}
|
build_unflags = ${common.build_unflags}
|
||||||
build_flags = ${common.build_flags} ${esp8266.build_flags} -D WLED_RELEASE_NAME=\"ESP8266\" #-DWLED_DISABLE_2D
|
build_flags = ${common.build_flags} ${esp8266.build_flags} -D WLED_RELEASE_NAME=\"ESP8266\" #-DWLED_DISABLE_2D
|
||||||
|
-D WLED_DISABLE_PARTICLESYSTEM2D
|
||||||
lib_deps = ${esp8266.lib_deps}
|
lib_deps = ${esp8266.lib_deps}
|
||||||
monitor_filters = esp8266_exception_decoder
|
monitor_filters = esp8266_exception_decoder
|
||||||
|
|
||||||
@ -376,6 +377,7 @@ extends = env:nodemcuv2
|
|||||||
platform = ${esp8266.platform_compat}
|
platform = ${esp8266.platform_compat}
|
||||||
platform_packages = ${esp8266.platform_packages_compat}
|
platform_packages = ${esp8266.platform_packages_compat}
|
||||||
build_flags = ${common.build_flags} ${esp8266.build_flags_compat} -D WLED_RELEASE_NAME=\"ESP8266_compat\" #-DWLED_DISABLE_2D
|
build_flags = ${common.build_flags} ${esp8266.build_flags_compat} -D WLED_RELEASE_NAME=\"ESP8266_compat\" #-DWLED_DISABLE_2D
|
||||||
|
-D WLED_DISABLE_PARTICLESYSTEM2D
|
||||||
;; lib_deps = ${esp8266.lib_deps_compat} ;; experimental - use older NeoPixelBus 2.7.9
|
;; lib_deps = ${esp8266.lib_deps_compat} ;; experimental - use older NeoPixelBus 2.7.9
|
||||||
|
|
||||||
[env:nodemcuv2_160]
|
[env:nodemcuv2_160]
|
||||||
@ -383,6 +385,7 @@ extends = env:nodemcuv2
|
|||||||
board_build.f_cpu = 160000000L
|
board_build.f_cpu = 160000000L
|
||||||
build_flags = ${common.build_flags} ${esp8266.build_flags} -D WLED_RELEASE_NAME=\"ESP8266_160\" #-DWLED_DISABLE_2D
|
build_flags = ${common.build_flags} ${esp8266.build_flags} -D WLED_RELEASE_NAME=\"ESP8266_160\" #-DWLED_DISABLE_2D
|
||||||
-D USERMOD_AUDIOREACTIVE
|
-D USERMOD_AUDIOREACTIVE
|
||||||
|
-D WLED_DISABLE_PARTICLESYSTEM2D
|
||||||
|
|
||||||
[env:esp8266_2m]
|
[env:esp8266_2m]
|
||||||
board = esp_wroom_02
|
board = esp_wroom_02
|
||||||
@ -391,6 +394,8 @@ platform_packages = ${common.platform_packages}
|
|||||||
board_build.ldscript = ${common.ldscript_2m512k}
|
board_build.ldscript = ${common.ldscript_2m512k}
|
||||||
build_unflags = ${common.build_unflags}
|
build_unflags = ${common.build_unflags}
|
||||||
build_flags = ${common.build_flags} ${esp8266.build_flags} -D WLED_RELEASE_NAME=\"ESP02\"
|
build_flags = ${common.build_flags} ${esp8266.build_flags} -D WLED_RELEASE_NAME=\"ESP02\"
|
||||||
|
-D WLED_DISABLE_PARTICLESYSTEM2D
|
||||||
|
-D WLED_DISABLE_PARTICLESYSTEM1D
|
||||||
lib_deps = ${esp8266.lib_deps}
|
lib_deps = ${esp8266.lib_deps}
|
||||||
|
|
||||||
[env:esp8266_2m_compat]
|
[env:esp8266_2m_compat]
|
||||||
@ -399,12 +404,16 @@ extends = env:esp8266_2m
|
|||||||
platform = ${esp8266.platform_compat}
|
platform = ${esp8266.platform_compat}
|
||||||
platform_packages = ${esp8266.platform_packages_compat}
|
platform_packages = ${esp8266.platform_packages_compat}
|
||||||
build_flags = ${common.build_flags} ${esp8266.build_flags_compat} -D WLED_RELEASE_NAME=\"ESP02_compat\" #-DWLED_DISABLE_2D
|
build_flags = ${common.build_flags} ${esp8266.build_flags_compat} -D WLED_RELEASE_NAME=\"ESP02_compat\" #-DWLED_DISABLE_2D
|
||||||
|
-D WLED_DISABLE_PARTICLESYSTEM1D
|
||||||
|
-D WLED_DISABLE_PARTICLESYSTEM2D
|
||||||
|
|
||||||
[env:esp8266_2m_160]
|
[env:esp8266_2m_160]
|
||||||
extends = env:esp8266_2m
|
extends = env:esp8266_2m
|
||||||
board_build.f_cpu = 160000000L
|
board_build.f_cpu = 160000000L
|
||||||
build_flags = ${common.build_flags} ${esp8266.build_flags} -D WLED_RELEASE_NAME=\"ESP02_160\"
|
build_flags = ${common.build_flags} ${esp8266.build_flags} -D WLED_RELEASE_NAME=\"ESP02_160\"
|
||||||
-D USERMOD_AUDIOREACTIVE
|
-D USERMOD_AUDIOREACTIVE
|
||||||
|
-D WLED_DISABLE_PARTICLESYSTEM1D
|
||||||
|
-D WLED_DISABLE_PARTICLESYSTEM2D
|
||||||
|
|
||||||
[env:esp01_1m_full]
|
[env:esp01_1m_full]
|
||||||
board = esp01_1m
|
board = esp01_1m
|
||||||
@ -414,6 +423,8 @@ board_build.ldscript = ${common.ldscript_1m128k}
|
|||||||
build_unflags = ${common.build_unflags}
|
build_unflags = ${common.build_unflags}
|
||||||
build_flags = ${common.build_flags} ${esp8266.build_flags} -D WLED_RELEASE_NAME=\"ESP01\" -D WLED_DISABLE_OTA
|
build_flags = ${common.build_flags} ${esp8266.build_flags} -D WLED_RELEASE_NAME=\"ESP01\" -D WLED_DISABLE_OTA
|
||||||
; -D WLED_USE_REAL_MATH ;; may fix wrong sunset/sunrise times, at the cost of 7064 bytes FLASH and 975 bytes RAM
|
; -D WLED_USE_REAL_MATH ;; may fix wrong sunset/sunrise times, at the cost of 7064 bytes FLASH and 975 bytes RAM
|
||||||
|
-D WLED_DISABLE_PARTICLESYSTEM1D
|
||||||
|
-D WLED_DISABLE_PARTICLESYSTEM2D
|
||||||
lib_deps = ${esp8266.lib_deps}
|
lib_deps = ${esp8266.lib_deps}
|
||||||
|
|
||||||
[env:esp01_1m_full_compat]
|
[env:esp01_1m_full_compat]
|
||||||
@ -422,6 +433,8 @@ extends = env:esp01_1m_full
|
|||||||
platform = ${esp8266.platform_compat}
|
platform = ${esp8266.platform_compat}
|
||||||
platform_packages = ${esp8266.platform_packages_compat}
|
platform_packages = ${esp8266.platform_packages_compat}
|
||||||
build_flags = ${common.build_flags} ${esp8266.build_flags_compat} -D WLED_RELEASE_NAME=\"ESP01_compat\" -D WLED_DISABLE_OTA #-DWLED_DISABLE_2D
|
build_flags = ${common.build_flags} ${esp8266.build_flags_compat} -D WLED_RELEASE_NAME=\"ESP01_compat\" -D WLED_DISABLE_OTA #-DWLED_DISABLE_2D
|
||||||
|
-D WLED_DISABLE_PARTICLESYSTEM1D
|
||||||
|
-D WLED_DISABLE_PARTICLESYSTEM2D
|
||||||
|
|
||||||
[env:esp01_1m_full_160]
|
[env:esp01_1m_full_160]
|
||||||
extends = env:esp01_1m_full
|
extends = env:esp01_1m_full
|
||||||
@ -429,6 +442,8 @@ board_build.f_cpu = 160000000L
|
|||||||
build_flags = ${common.build_flags} ${esp8266.build_flags} -D WLED_RELEASE_NAME=\"ESP01_160\" -D WLED_DISABLE_OTA
|
build_flags = ${common.build_flags} ${esp8266.build_flags} -D WLED_RELEASE_NAME=\"ESP01_160\" -D WLED_DISABLE_OTA
|
||||||
-D USERMOD_AUDIOREACTIVE
|
-D USERMOD_AUDIOREACTIVE
|
||||||
; -D WLED_USE_REAL_MATH ;; may fix wrong sunset/sunrise times, at the cost of 7064 bytes FLASH and 975 bytes RAM
|
; -D WLED_USE_REAL_MATH ;; may fix wrong sunset/sunrise times, at the cost of 7064 bytes FLASH and 975 bytes RAM
|
||||||
|
-D WLED_DISABLE_PARTICLESYSTEM1D
|
||||||
|
-D WLED_DISABLE_PARTICLESYSTEM2D
|
||||||
|
|
||||||
[env:esp32dev]
|
[env:esp32dev]
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
|
2646
wled00/FX.cpp
2646
wled00/FX.cpp
File diff suppressed because it is too large
Load Diff
36
wled00/FX.h
36
wled00/FX.h
@ -323,8 +323,35 @@ extern byte realtimeMode; // used in getMappedPixelIndex()
|
|||||||
#define FX_MODE_WAVESINS 184
|
#define FX_MODE_WAVESINS 184
|
||||||
#define FX_MODE_ROCKTAVES 185
|
#define FX_MODE_ROCKTAVES 185
|
||||||
#define FX_MODE_2DAKEMI 186
|
#define FX_MODE_2DAKEMI 186
|
||||||
|
#define FX_MODE_PARTICLEVOLCANO 187
|
||||||
#define MODE_COUNT 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 FX_MODE_PARTICLEGHOSTRIDER 200
|
||||||
|
#define FX_MODE_PARTICLEBLOBS 201
|
||||||
|
#define FX_MODE_PSDRIP 202
|
||||||
|
#define FX_MODE_PSPINBALL 203
|
||||||
|
#define FX_MODE_PSDANCINGSHADOWS 204
|
||||||
|
#define FX_MODE_PSFIREWORKS1D 205
|
||||||
|
#define FX_MODE_PSSPARKLER 206
|
||||||
|
#define FX_MODE_PSHOURGLASS 207
|
||||||
|
#define FX_MODE_PS1DSPRAY 208
|
||||||
|
#define FX_MODE_PSBALANCE 209
|
||||||
|
#define FX_MODE_PSCHASE 210
|
||||||
|
#define FX_MODE_PSSTARBURST 211
|
||||||
|
#define FX_MODE_PS1DGEQ 212
|
||||||
|
#define FX_MODE_PSFIRE1D 213
|
||||||
|
#define FX_MODE_PS1DSONICSTREAM 214
|
||||||
|
#define MODE_COUNT 215
|
||||||
|
|
||||||
|
|
||||||
#define BLEND_STYLE_FADE 0x00 // universal
|
#define BLEND_STYLE_FADE 0x00 // universal
|
||||||
@ -481,6 +508,7 @@ typedef struct Segment {
|
|||||||
uint8_t _prevPaletteBlends; // number of previous palette blends (there are max 255 blends possible)
|
uint8_t _prevPaletteBlends; // number of previous palette blends (there are max 255 blends possible)
|
||||||
unsigned long _start; // must accommodate millis()
|
unsigned long _start; // must accommodate millis()
|
||||||
uint16_t _dur;
|
uint16_t _dur;
|
||||||
|
// -> here is one byte of padding
|
||||||
Transition(uint16_t dur=750)
|
Transition(uint16_t dur=750)
|
||||||
: _palT(CRGBPalette16(CRGB::Black))
|
: _palT(CRGBPalette16(CRGB::Black))
|
||||||
, _prevPaletteBlends(0)
|
, _prevPaletteBlends(0)
|
||||||
@ -579,6 +607,7 @@ typedef struct Segment {
|
|||||||
inline static void addUsedSegmentData(int len) { Segment::_usedSegmentData += len; }
|
inline static void addUsedSegmentData(int len) { Segment::_usedSegmentData += len; }
|
||||||
#ifndef WLED_DISABLE_MODE_BLEND
|
#ifndef WLED_DISABLE_MODE_BLEND
|
||||||
inline static void modeBlend(bool blend) { _modeBlend = blend; }
|
inline static void modeBlend(bool blend) { _modeBlend = blend; }
|
||||||
|
inline static bool getmodeBlend(void) { return _modeBlend; }
|
||||||
#endif
|
#endif
|
||||||
inline static unsigned vLength() { return Segment::_vLength; }
|
inline static unsigned vLength() { return Segment::_vLength; }
|
||||||
inline static unsigned vWidth() { return Segment::_vWidth; }
|
inline static unsigned vWidth() { return Segment::_vWidth; }
|
||||||
@ -627,6 +656,7 @@ typedef struct Segment {
|
|||||||
uint8_t currentMode() const; // currently active effect/mode (while in transition)
|
uint8_t currentMode() const; // currently active effect/mode (while in transition)
|
||||||
[[gnu::hot]] uint32_t currentColor(uint8_t slot) const; // currently active segment color (blended while in transition)
|
[[gnu::hot]] uint32_t currentColor(uint8_t slot) const; // currently active segment color (blended while in transition)
|
||||||
CRGBPalette16 &loadPalette(CRGBPalette16 &tgt, uint8_t pal);
|
CRGBPalette16 &loadPalette(CRGBPalette16 &tgt, uint8_t pal);
|
||||||
|
void loadOldPalette(); // loads old FX palette into _currentPalette
|
||||||
|
|
||||||
// 1D strip
|
// 1D strip
|
||||||
[[gnu::hot]] uint16_t virtualLength() const;
|
[[gnu::hot]] uint16_t virtualLength() const;
|
||||||
@ -1009,4 +1039,4 @@ class WS2812FX { // 96 bytes
|
|||||||
extern const char JSON_mode_names[];
|
extern const char JSON_mode_names[];
|
||||||
extern const char JSON_palette_names[];
|
extern const char JSON_palette_names[];
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -11,6 +11,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
#include "FX.h"
|
#include "FX.h"
|
||||||
|
#include "FXparticleSystem.h" // TODO: better define the required function (mem service) in FX.h?
|
||||||
#include "palettes.h"
|
#include "palettes.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -470,6 +471,12 @@ void Segment::beginDraw() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// loads palette of the old FX during transitions (used by particle system)
|
||||||
|
void Segment::loadOldPalette(void) {
|
||||||
|
if(isInTransition())
|
||||||
|
loadPalette(_currentPalette, _t->_palTid);
|
||||||
|
}
|
||||||
|
|
||||||
// relies on WS2812FX::service() to call it for each frame
|
// relies on WS2812FX::service() to call it for each frame
|
||||||
void Segment::handleRandomPalette() {
|
void Segment::handleRandomPalette() {
|
||||||
// is it time to generate a new palette?
|
// is it time to generate a new palette?
|
||||||
@ -1592,6 +1599,9 @@ void WS2812FX::service() {
|
|||||||
_segment_index++;
|
_segment_index++;
|
||||||
}
|
}
|
||||||
Segment::setClippingRect(0, 0); // disable clipping for overlays
|
Segment::setClippingRect(0, 0); // disable clipping for overlays
|
||||||
|
#if !(defined(WLED_DISABLE_PARTICLESYSTEM2D) && defined(WLED_DISABLE_PARTICLESYSTEM1D))
|
||||||
|
servicePSmem(); // handle segment particle system memory
|
||||||
|
#endif
|
||||||
_isServicing = false;
|
_isServicing = false;
|
||||||
_triggered = false;
|
_triggered = false;
|
||||||
|
|
||||||
@ -2036,4 +2046,4 @@ const char JSON_palette_names[] PROGMEM = R"=====([
|
|||||||
"Aurora","Atlantica","C9 2","C9 New","Temperature","Aurora 2","Retro Clown","Candy","Toxy Reaf","Fairy Reaf",
|
"Aurora","Atlantica","C9 2","C9 New","Temperature","Aurora 2","Retro Clown","Candy","Toxy Reaf","Fairy Reaf",
|
||||||
"Semi Blue","Pink Candy","Red Reaf","Aqua Flash","Yelblu Hot","Lite Light","Red Flash","Blink Red","Red Shift","Red Tide",
|
"Semi Blue","Pink Candy","Red Reaf","Aqua Flash","Yelblu Hot","Lite Light","Red Flash","Blink Red","Red Shift","Red Tide",
|
||||||
"Candy2","Traffic Light"
|
"Candy2","Traffic Light"
|
||||||
])=====";
|
])=====";
|
2425
wled00/FXparticleSystem.cpp
Normal file
2425
wled00/FXparticleSystem.cpp
Normal file
File diff suppressed because it is too large
Load Diff
416
wled00/FXparticleSystem.h
Normal file
416
wled00/FXparticleSystem.h
Normal file
@ -0,0 +1,416 @@
|
|||||||
|
/*
|
||||||
|
FXparticleSystem.cpp
|
||||||
|
|
||||||
|
Particle system with functions for particle generation, particle movement and particle rendering to RGB matrix.
|
||||||
|
by DedeHai (Damian Schneider) 2013-2024
|
||||||
|
|
||||||
|
Copyright (c) 2024 Damian Schneider
|
||||||
|
Licensed under the EUPL v. 1.2 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef WLED_DISABLE_2D
|
||||||
|
#define WLED_DISABLE_PARTICLESYSTEM2D
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !(defined(WLED_DISABLE_PARTICLESYSTEM2D) && defined(WLED_DISABLE_PARTICLESYSTEM1D)) // not both disabled
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "wled.h"
|
||||||
|
|
||||||
|
#define PS_P_MAXSPEED 120 // maximum speed a particle can have (vx/vy is int8)
|
||||||
|
#define MAX_MEMIDLE 10 // max idle time (in frames) before memory is deallocated (if deallocated during an effect, it will crash!)
|
||||||
|
|
||||||
|
//#define WLED_DEBUG_PS // note: enabling debug uses ~3k of flash
|
||||||
|
|
||||||
|
#ifdef WLED_DEBUG_PS
|
||||||
|
#define PSPRINT(x) Serial.print(x)
|
||||||
|
#define PSPRINTLN(x) Serial.println(x)
|
||||||
|
#else
|
||||||
|
#define PSPRINT(x)
|
||||||
|
#define PSPRINTLN(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// memory and transition manager
|
||||||
|
struct partMem {
|
||||||
|
void* particleMemPointer; // pointer to particle memory
|
||||||
|
uint32_t buffersize; // buffer size in bytes
|
||||||
|
uint8_t particleType; // type of particles currently in memory: 0 = none, particle struct size otherwise (required for 1D<->2D transitions)
|
||||||
|
uint8_t id; // ID of segment this memory belongs to
|
||||||
|
uint8_t watchdog; // counter to handle deallocation
|
||||||
|
uint8_t inTransition; // to track PS to PS FX transitions (is set to new FX ID during transitions), not set if not both FX are PS FX
|
||||||
|
uint8_t currentFX; // current FX ID, is set when transition is complete, used to detect back and forth transitions
|
||||||
|
bool finalTransfer; // used to update buffer in rendering function after transition has ended
|
||||||
|
bool transferParticles; // if set, particles in buffer are transferred to new FX
|
||||||
|
};
|
||||||
|
|
||||||
|
void* particleMemoryManager(const uint32_t requestedParticles, size_t structSize, uint32_t &availableToPS, uint32_t numParticlesUsed, const uint8_t effectID); // update particle memory pointer, handles memory transitions
|
||||||
|
void particleHandover(void *buffer, size_t structSize, int32_t numParticles);
|
||||||
|
void updateUsedParticles(const uint32_t allocated, const uint32_t available, const uint8_t percentage, uint32_t &used);
|
||||||
|
bool segmentIsOverlay(void); // check if segment is fully overlapping with at least one underlying segment
|
||||||
|
partMem* getPartMem(void); // returns pointer to memory struct for current segment or nullptr
|
||||||
|
void updateRenderingBuffer(uint32_t requiredpixels, bool isFramebuffer, bool initialize); // allocate CRGB rendering buffer, update size if needed
|
||||||
|
void transferBuffer(uint32_t width, uint32_t height, bool useAdditiveTransfer = false); // transfer the buffer to the segment (supports 1D and 2D)
|
||||||
|
void servicePSmem(); // increments watchdog, frees memory if idle too long
|
||||||
|
|
||||||
|
// limit speed of particles (used in 1D and 2D)
|
||||||
|
static inline int32_t limitSpeed(const int32_t speed) {
|
||||||
|
return speed > PS_P_MAXSPEED ? PS_P_MAXSPEED : (speed < -PS_P_MAXSPEED ? -PS_P_MAXSPEED : speed); // note: this is slightly faster than using min/max at the cost of 50bytes of flash
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WLED_DISABLE_PARTICLESYSTEM2D
|
||||||
|
// memory allocation
|
||||||
|
#define ESP8266_MAXPARTICLES 300 // enough up to 20x20 pixels
|
||||||
|
#define ESP8266_MAXSOURCES 24
|
||||||
|
#define ESP32S2_MAXPARTICLES 1024 // enough up to 32x32 pixels
|
||||||
|
#define ESP32S2_MAXSOURCES 64
|
||||||
|
#define ESP32_MAXPARTICLES 2048 // enough up to 64x32 pixels
|
||||||
|
#define ESP32_MAXSOURCES 128
|
||||||
|
|
||||||
|
// particle dimensions (subpixel division)
|
||||||
|
#define PS_P_RADIUS 64 // subpixel size, each pixel is divided by this for particle movement (must be a power of 2)
|
||||||
|
#define PS_P_HALFRADIUS (PS_P_RADIUS >> 1)
|
||||||
|
#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_MINHARDRADIUS 64 // minimum hard surface radius for collisions
|
||||||
|
#define PS_P_MINSURFACEHARDNESS 128 // minimum hardness used in collision impulse calculation, below this hardness, particles become sticky
|
||||||
|
|
||||||
|
// struct for PS settings (shared for 1D and 2D class)
|
||||||
|
typedef union {
|
||||||
|
struct{ // one byte bit field for 2D settings
|
||||||
|
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
|
||||||
|
};
|
||||||
|
byte asByte; // access as a byte, order is: LSB is first entry in the list above
|
||||||
|
} PSsettings2D;
|
||||||
|
|
||||||
|
//struct for a single particle
|
||||||
|
typedef struct { // 10 bytes
|
||||||
|
int16_t x; // x position in particle system
|
||||||
|
int16_t y; // y position in particle system
|
||||||
|
uint16_t ttl; // time to live in frames
|
||||||
|
int8_t vx; // horizontal velocity
|
||||||
|
int8_t vy; // vertical velocity
|
||||||
|
uint8_t hue; // color hue
|
||||||
|
uint8_t sat; // particle color saturation
|
||||||
|
} PSparticle;
|
||||||
|
|
||||||
|
//struct for particle flags note: this is separate from the particle struct to save memory (ram alignment)
|
||||||
|
typedef union {
|
||||||
|
struct { // 1 byte
|
||||||
|
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 perpetual : 1; // if set, particle does not age (TTL is not decremented in move function, it still dies from killoutofbounds)
|
||||||
|
bool custom1 : 1; // unused custom flags, can be used by FX to track particle states
|
||||||
|
bool custom2 : 1;
|
||||||
|
bool custom3 : 1;
|
||||||
|
bool custom4 : 1;
|
||||||
|
bool custom5 : 1;
|
||||||
|
};
|
||||||
|
byte asByte; // access as a byte, order is: LSB is first entry in the list above
|
||||||
|
} PSparticleFlags;
|
||||||
|
|
||||||
|
// struct for additional particle settings (option)
|
||||||
|
typedef struct { // 2 bytes
|
||||||
|
uint8_t size; // particle size, 255 means 10 pixels in diameter
|
||||||
|
uint8_t forcecounter; // counter for applying forces to individual particles
|
||||||
|
} PSadvancedParticle;
|
||||||
|
|
||||||
|
// struct for advanced particle size control (option)
|
||||||
|
typedef struct { // 8 bytes
|
||||||
|
uint8_t asymmetry; // asymmetrical size (0=symmetrical, 255 fully asymmetric)
|
||||||
|
uint8_t asymdir; // direction of asymmetry, 64 is x, 192 is y (0 and 128 is symmetrical)
|
||||||
|
uint8_t maxsize; // target size for growing
|
||||||
|
uint8_t minsize; // target size for shrinking
|
||||||
|
uint8_t sizecounter : 4; // counters used for size contol (grow/shrink/wobble)
|
||||||
|
uint8_t wobblecounter : 4;
|
||||||
|
uint8_t growspeed : 4;
|
||||||
|
uint8_t shrinkspeed : 4;
|
||||||
|
uint8_t wobblespeed : 4;
|
||||||
|
bool grow : 1; // flags
|
||||||
|
bool shrink : 1;
|
||||||
|
bool pulsate : 1; // grows & shrinks & grows & ...
|
||||||
|
bool wobble : 1; // alternate x and y size
|
||||||
|
} PSsizeControl;
|
||||||
|
|
||||||
|
|
||||||
|
//struct for a particle source (20 bytes)
|
||||||
|
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)
|
||||||
|
PSparticleFlags sourceFlags; // flags for the source particle
|
||||||
|
int8_t var; // variation of emitted speed (adds random(+/- var) to speed)
|
||||||
|
int8_t vx; // emitting speed
|
||||||
|
int8_t vy;
|
||||||
|
uint8_t size; // particle size (advanced property)
|
||||||
|
} PSsource;
|
||||||
|
|
||||||
|
// class uses approximately 60 bytes
|
||||||
|
class ParticleSystem2D {
|
||||||
|
public:
|
||||||
|
ParticleSystem2D(const uint32_t width, const uint32_t height, const uint32_t numberofparticles, const uint32_t numberofsources, const bool isadvanced = false, const bool sizecontrol = false); // 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(const uint8_t intensity, const bool renderonly); // update function for fire, if renderonly is set, particles are not updated (required to fix transitions with frameskips)
|
||||||
|
void updateSystem(void); // call at the beginning of every FX, updates pointers and dimensions
|
||||||
|
void particleMoveUpdate(PSparticle &part, PSparticleFlags &partFlags, PSsettings2D *options = NULL, PSadvancedParticle *advancedproperties = NULL); // move function
|
||||||
|
// particle emitters
|
||||||
|
int32_t sprayEmit(const PSsource &emitter);
|
||||||
|
void flameEmit(const PSsource &emitter);
|
||||||
|
int32_t angleEmit(PSsource& emitter, const uint16_t angle, const int32_t speed);
|
||||||
|
//particle physics
|
||||||
|
void applyGravity(PSparticle &part); // applies gravity to single particle (use this for sources)
|
||||||
|
[[gnu::hot]] void applyForce(PSparticle &part, const int8_t xforce, const int8_t yforce, uint8_t &counter);
|
||||||
|
[[gnu::hot]] void applyForce(const uint32_t particleindex, const int8_t xforce, const int8_t yforce); // use this for advanced property particles
|
||||||
|
void applyForce(const int8_t xforce, const int8_t yforce); // apply a force to all particles
|
||||||
|
void applyAngleForce(PSparticle &part, const int8_t force, const uint16_t angle, uint8_t &counter);
|
||||||
|
void applyAngleForce(const uint32_t particleindex, const int8_t force, const uint16_t angle); // use this for advanced property particles
|
||||||
|
void applyAngleForce(const int8_t force, const uint16_t angle); // apply angular force to all particles
|
||||||
|
void applyFriction(PSparticle &part, const int32_t coefficient); // apply friction to specific particle
|
||||||
|
void applyFriction(const int32_t coefficient); // apply friction to all used particles
|
||||||
|
void pointAttractor(const uint32_t particleindex, PSparticle &attractor, const uint8_t strength, const bool swallow);
|
||||||
|
// set options note: inlining the set function uses more flash so dont optimize
|
||||||
|
void setUsedParticles(const uint8_t percentage); // set the percentage of particles used in the system, 255=100%
|
||||||
|
inline uint32_t getAvailableParticles(void) { return availableParticles; } // available particles in the buffer, use this to check if buffer changed during FX init
|
||||||
|
void setCollisionHardness(const uint8_t hardness); // hardness for particle collisions (255 means full hard)
|
||||||
|
void setWallHardness(const uint8_t hardness); // hardness for bouncing on the wall if bounceXY is set
|
||||||
|
void setWallRoughness(const uint8_t roughness); // wall roughness randomizes wall collisions
|
||||||
|
void setMatrixSize(const uint32_t x, const uint32_t y);
|
||||||
|
void setWrapX(const bool enable);
|
||||||
|
void setWrapY(const bool enable);
|
||||||
|
void setBounceX(const bool enable);
|
||||||
|
void setBounceY(const bool enable);
|
||||||
|
void setKillOutOfBounds(const bool enable); // if enabled, particles outside of matrix instantly die
|
||||||
|
void setSaturation(const uint8_t sat); // set global color saturation
|
||||||
|
void setColorByAge(const bool enable);
|
||||||
|
void setMotionBlur(const uint8_t bluramount); // note: motion blur can only be used if 'particlesize' is set to zero
|
||||||
|
void setSmearBlur(const uint8_t bluramount); // enable 2D smeared blurring of full frame
|
||||||
|
void setParticleSize(const uint8_t size);
|
||||||
|
void setGravity(const int8_t force = 8);
|
||||||
|
void enableParticleCollisions(const bool enable, const uint8_t hardness = 255);
|
||||||
|
|
||||||
|
PSparticle *particles; // pointer to particle array
|
||||||
|
PSparticleFlags *particleFlags; // pointer to particle flags array
|
||||||
|
PSsource *sources; // pointer to sources
|
||||||
|
PSadvancedParticle *advPartProps; // pointer to advanced particle properties (can be NULL)
|
||||||
|
PSsizeControl *advPartSize; // pointer to advanced particle size control (can be NULL)
|
||||||
|
uint8_t* PSdataEnd; // points to first available byte after the PSmemory, is set in setPointers(). use this for FX custom data
|
||||||
|
int32_t maxX, maxY; // particle system size i.e. width-1 / height-1 in subpixels, Note: all "max" variables must be signed to compare to coordinates (which are signed)
|
||||||
|
int32_t maxXpixel, maxYpixel; // last physical pixel that can be drawn to (FX can read this to read segment size if required), equal to width-1 / height-1
|
||||||
|
uint32_t numSources; // number of sources
|
||||||
|
uint32_t usedParticles; // number of particles used in animation, is relative to 'numParticles'
|
||||||
|
//note: some variables are 32bit for speed and code size at the cost of ram
|
||||||
|
|
||||||
|
private:
|
||||||
|
//rendering functions
|
||||||
|
void ParticleSys_render();
|
||||||
|
[[gnu::hot]] void renderParticle(const uint32_t particleindex, const uint32_t brightness, const CRGB& color, const bool wrapX, const bool wrapY);
|
||||||
|
//paricle physics applied by system if flags are set
|
||||||
|
void applyGravity(); // applies gravity to all particles
|
||||||
|
void handleCollisions();
|
||||||
|
[[gnu::hot]] void collideParticles(PSparticle &particle1, PSparticle &particle2, const int32_t dx, const int32_t dy, const int32_t collDistSq);
|
||||||
|
void fireParticleupdate();
|
||||||
|
//utility functions
|
||||||
|
void updatePSpointers(const bool isadvanced, const bool sizecontrol); // update the data pointers to current segment data space
|
||||||
|
bool updateSize(PSadvancedParticle *advprops, PSsizeControl *advsize); // advanced size control
|
||||||
|
void getParticleXYsize(PSadvancedParticle *advprops, PSsizeControl *advsize, uint32_t &xsize, uint32_t &ysize);
|
||||||
|
[[gnu::hot]] void bounce(int8_t &incomingspeed, int8_t ¶llelspeed, int32_t &position, const uint32_t maxposition); // bounce on a wall
|
||||||
|
// note: variables that are accessed often are 32bit for speed
|
||||||
|
PSsettings2D particlesettings; // settings used when updating particles (can also used by FX to move sources), do not edit properties directly, use functions above
|
||||||
|
uint32_t numParticles; // total number of particles allocated by this system note: during transitions, less are available, use availableParticles
|
||||||
|
uint32_t availableParticles; // number of particles available for use (can be more or less than numParticles, assigned by memory manager)
|
||||||
|
uint32_t emitIndex; // index to count through particles to emit so searching for dead pixels is faster
|
||||||
|
int32_t collisionHardness;
|
||||||
|
uint32_t wallHardness;
|
||||||
|
uint32_t wallRoughness; // randomizes wall collisions
|
||||||
|
uint32_t particleHardRadius; // hard surface radius of a particle, used for collision detection (32bit for speed)
|
||||||
|
uint16_t collisionStartIdx; // particle array start index for collision detection
|
||||||
|
uint8_t fireIntesity = 0; // fire intensity, used for fire mode (flash use optimization, better than passing an argument to render function)
|
||||||
|
uint8_t fractionOfParticlesUsed; // percentage of particles used in the system (255=100%), used during transition updates
|
||||||
|
uint8_t forcecounter; // counter for globally applied forces
|
||||||
|
uint8_t gforcecounter; // counter for global gravity
|
||||||
|
int8_t gforce; // gravity strength, default is 8 (negative is allowed, positive is downwards)
|
||||||
|
// global particle properties for basic particles
|
||||||
|
uint8_t particlesize; // global particle size, 0 = 1 pixel, 1 = 2 pixels, 255 = 10 pixels (note: this is also added to individual sized particles)
|
||||||
|
uint8_t motionBlur; // motion blur, values > 100 gives smoother animations. Note: motion blurring does not work if particlesize is > 0
|
||||||
|
uint8_t smearBlur; // 2D smeared blurring of full frame
|
||||||
|
uint8_t effectID; // ID of the effect that is using this particle system, used for transitions
|
||||||
|
};
|
||||||
|
|
||||||
|
void blur2D(CRGB *colorbuffer, const uint32_t xsize, uint32_t ysize, const uint32_t xblur, const uint32_t yblur, const uint32_t xstart = 0, uint32_t ystart = 0, const bool isparticle = false);
|
||||||
|
// initialization functions (not part of class)
|
||||||
|
bool initParticleSystem2D(ParticleSystem2D *&PartSys, const uint32_t requestedsources, const uint32_t additionalbytes = 0, const bool advanced = false, const bool sizecontrol = false);
|
||||||
|
uint32_t calculateNumberOfParticles2D(const uint32_t pixels, const bool advanced, const bool sizecontrol);
|
||||||
|
uint32_t calculateNumberOfSources2D(const uint32_t pixels, const uint32_t requestedsources);
|
||||||
|
bool allocateParticleSystemMemory2D(const uint32_t numparticles, const uint32_t numsources, const bool advanced, const bool sizecontrol, const uint32_t additionalbytes);
|
||||||
|
#endif // WLED_DISABLE_PARTICLESYSTEM2D
|
||||||
|
|
||||||
|
////////////////////////
|
||||||
|
// 1D Particle System //
|
||||||
|
////////////////////////
|
||||||
|
#ifndef WLED_DISABLE_PARTICLESYSTEM1D
|
||||||
|
// memory allocation
|
||||||
|
#define ESP8266_MAXPARTICLES_1D 450
|
||||||
|
#define ESP8266_MAXSOURCES_1D 16
|
||||||
|
#define ESP32S2_MAXPARTICLES_1D 1300
|
||||||
|
#define ESP32S2_MAXSOURCES_1D 32
|
||||||
|
#define ESP32_MAXPARTICLES_1D 2600
|
||||||
|
#define ESP32_MAXSOURCES_1D 64
|
||||||
|
|
||||||
|
// particle dimensions (subpixel division)
|
||||||
|
#define PS_P_RADIUS_1D 32 // 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_1D (PS_P_RADIUS_1D >> 1)
|
||||||
|
#define PS_P_RADIUS_SHIFT_1D 5 // 1 << PS_P_RADIUS_SHIFT = PS_P_RADIUS
|
||||||
|
#define PS_P_SURFACE_1D 5 // shift: 2^PS_P_SURFACE = PS_P_RADIUS_1D
|
||||||
|
#define PS_P_MINHARDRADIUS_1D 32 // minimum hard surface radius note: do not change or hourglass effect will be broken
|
||||||
|
#define PS_P_MINSURFACEHARDNESS_1D 120 // minimum hardness used in collision impulse calculation
|
||||||
|
|
||||||
|
// struct for PS settings (shared for 1D and 2D class)
|
||||||
|
typedef union {
|
||||||
|
struct{
|
||||||
|
// one byte bit field for 1D settings
|
||||||
|
bool wrap : 1;
|
||||||
|
bool bounce : 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
|
||||||
|
bool colorByPosition : 1; // if set, particle hue is set by its position in the strip segment
|
||||||
|
bool unused : 1;
|
||||||
|
};
|
||||||
|
byte asByte; // access as a byte, order is: LSB is first entry in the list above
|
||||||
|
} PSsettings1D;
|
||||||
|
|
||||||
|
//struct for a single particle (8 bytes)
|
||||||
|
typedef struct {
|
||||||
|
int32_t x; // x position in particle system
|
||||||
|
uint16_t ttl; // time to live in frames
|
||||||
|
int8_t vx; // horizontal velocity
|
||||||
|
uint8_t hue; // color hue
|
||||||
|
} PSparticle1D;
|
||||||
|
|
||||||
|
//struct for particle flags
|
||||||
|
typedef union {
|
||||||
|
struct { // 1 byte
|
||||||
|
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 perpetual : 1; // if set, particle does not age (TTL is not decremented in move function, it still dies from killoutofbounds)
|
||||||
|
bool reversegrav : 1; // if set, gravity is reversed on this particle
|
||||||
|
bool forcedirection : 1; // direction the force was applied, 1 is positive x-direction (used for collision stacking, similar to reversegrav) TODO: not used anymore, can be removed
|
||||||
|
bool fixed : 1; // if set, particle does not move (and collisions make other particles revert direction),
|
||||||
|
bool custom1 : 1; // unused custom flags, can be used by FX to track particle states
|
||||||
|
bool custom2 : 1;
|
||||||
|
};
|
||||||
|
byte asByte; // access as a byte, order is: LSB is first entry in the list above
|
||||||
|
} PSparticleFlags1D;
|
||||||
|
|
||||||
|
// struct for additional particle settings (optional)
|
||||||
|
typedef struct {
|
||||||
|
uint8_t sat; //color saturation
|
||||||
|
uint8_t size; // particle size, 255 means 10 pixels in diameter
|
||||||
|
uint8_t forcecounter;
|
||||||
|
} PSadvancedParticle1D;
|
||||||
|
|
||||||
|
//struct for a particle source (20 bytes)
|
||||||
|
typedef struct {
|
||||||
|
uint16_t minLife; // minimum ttl of emittet particles
|
||||||
|
uint16_t maxLife; // maximum ttl of emitted particles
|
||||||
|
PSparticle1D source; // use a particle as the emitter source (speed, position, color)
|
||||||
|
PSparticleFlags1D sourceFlags; // flags for the source particle
|
||||||
|
int8_t var; // variation of emitted speed (adds random(+/- var) to speed)
|
||||||
|
int8_t v; // emitting speed
|
||||||
|
uint8_t sat; // color saturation (advanced property)
|
||||||
|
uint8_t size; // particle size (advanced property)
|
||||||
|
// note: there is 3 bytes of padding added here
|
||||||
|
} PSsource1D;
|
||||||
|
|
||||||
|
class ParticleSystem1D
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ParticleSystem1D(const uint32_t length, const uint32_t numberofparticles, const uint32_t numberofsources, const bool isadvanced = false); // 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 updateSystem(void); // call at the beginning of every FX, updates pointers and dimensions
|
||||||
|
// particle emitters
|
||||||
|
int32_t sprayEmit(const PSsource1D &emitter);
|
||||||
|
void particleMoveUpdate(PSparticle1D &part, PSparticleFlags1D &partFlags, PSsettings1D *options = NULL, PSadvancedParticle1D *advancedproperties = NULL); // move function
|
||||||
|
//particle physics
|
||||||
|
[[gnu::hot]] void applyForce(PSparticle1D &part, const int8_t xforce, uint8_t &counter); //apply a force to a single particle
|
||||||
|
void applyForce(const int8_t xforce); // apply a force to all particles
|
||||||
|
void applyGravity(PSparticle1D &part, PSparticleFlags1D &partFlags); // applies gravity to single particle (use this for sources)
|
||||||
|
void applyFriction(const int32_t coefficient); // apply friction to all used particles
|
||||||
|
// set options
|
||||||
|
void setUsedParticles(const uint8_t percentage); // set the percentage of particles used in the system, 255=100%
|
||||||
|
inline uint32_t getAvailableParticles(void) { return availableParticles; } // available particles in the buffer, use this to check if buffer changed during FX init
|
||||||
|
void setWallHardness(const uint8_t hardness); // hardness for bouncing on the wall if bounceXY is set
|
||||||
|
void setSize(const uint32_t x); //set particle system size (= strip length)
|
||||||
|
void setWrap(const bool enable);
|
||||||
|
void setBounce(const bool enable);
|
||||||
|
void setKillOutOfBounds(const bool enable); // if enabled, particles outside of matrix instantly die
|
||||||
|
// void setSaturation(uint8_t sat); // set global color saturation
|
||||||
|
void setColorByAge(const bool enable);
|
||||||
|
void setColorByPosition(const bool enable);
|
||||||
|
void setMotionBlur(const uint8_t bluramount); // note: motion blur can only be used if 'particlesize' is set to zero
|
||||||
|
void setSmearBlur(const uint8_t bluramount); // enable 1D smeared blurring of full frame
|
||||||
|
void setParticleSize(const uint8_t size); //size 0 = 1 pixel, size 1 = 2 pixels, is overruled by advanced particle size
|
||||||
|
void setGravity(int8_t force = 8);
|
||||||
|
void enableParticleCollisions(bool enable, const uint8_t hardness = 255);
|
||||||
|
|
||||||
|
PSparticle1D *particles; // pointer to particle array
|
||||||
|
PSparticleFlags1D *particleFlags; // pointer to particle flags array
|
||||||
|
PSsource1D *sources; // pointer to sources
|
||||||
|
PSadvancedParticle1D *advPartProps; // pointer to advanced particle properties (can be NULL)
|
||||||
|
//PSsizeControl *advPartSize; // pointer to advanced particle size control (can be NULL)
|
||||||
|
uint8_t* PSdataEnd; // points to first available byte after the PSmemory, is set in setPointers(). use this for FX custom data
|
||||||
|
int32_t maxX; // particle system size i.e. width-1, Note: all "max" variables must be signed to compare to coordinates (which are signed)
|
||||||
|
int32_t maxXpixel; // last physical pixel that can be drawn to (FX can read this to read segment size if required), equal to width-1
|
||||||
|
uint32_t numSources; // number of sources
|
||||||
|
uint32_t usedParticles; // number of particles used in animation, is relative to 'numParticles'
|
||||||
|
|
||||||
|
private:
|
||||||
|
//rendering functions
|
||||||
|
void ParticleSys_render(void);
|
||||||
|
void renderParticle(const uint32_t particleindex, const uint32_t brightness, const CRGB &color, const bool wrap);
|
||||||
|
|
||||||
|
//paricle physics applied by system if flags are set
|
||||||
|
void applyGravity(); // applies gravity to all particles
|
||||||
|
void handleCollisions();
|
||||||
|
[[gnu::hot]] void collideParticles(PSparticle1D &particle1, const PSparticleFlags1D &particle1flags, PSparticle1D &particle2, const PSparticleFlags1D &particle2flags, int32_t dx, int32_t relativeVx, const int32_t collisiondistance);
|
||||||
|
|
||||||
|
//utility functions
|
||||||
|
void updatePSpointers(const bool isadvanced); // update the data pointers to current segment data space
|
||||||
|
//void updateSize(PSadvancedParticle *advprops, PSsizeControl *advsize); // advanced size control
|
||||||
|
[[gnu::hot]] void bounce(int8_t &incomingspeed, int8_t ¶llelspeed, int32_t &position, const uint32_t maxposition); // bounce on a wall
|
||||||
|
// note: variables that are accessed often are 32bit for speed
|
||||||
|
PSsettings1D particlesettings; // settings used when updating particles
|
||||||
|
uint32_t numParticles; // total number of particles allocated by this system note: never use more than this, even if more are available (only this many advanced particles are allocated)
|
||||||
|
uint32_t availableParticles; // number of particles available for use (can be more or less than numParticles, assigned by memory manager)
|
||||||
|
uint8_t fractionOfParticlesUsed; // percentage of particles used in the system (255=100%), used during transition updates
|
||||||
|
uint32_t emitIndex; // index to count through particles to emit so searching for dead pixels is faster
|
||||||
|
int32_t collisionHardness;
|
||||||
|
uint32_t particleHardRadius; // hard surface radius of a particle, used for collision detection
|
||||||
|
uint32_t wallHardness;
|
||||||
|
uint8_t gforcecounter; // counter for global gravity
|
||||||
|
int8_t gforce; // gravity strength, default is 8 (negative is allowed, positive is downwards)
|
||||||
|
uint8_t forcecounter; // counter for globally applied forces
|
||||||
|
uint16_t collisionStartIdx; // particle array start index for collision detection
|
||||||
|
//global particle properties for basic particles
|
||||||
|
uint8_t particlesize; // global particle size, 0 = 1 pixel, 1 = 2 pixels
|
||||||
|
uint8_t motionBlur; // enable motion blur, values > 100 gives smoother animations
|
||||||
|
uint8_t smearBlur; // smeared blurring of full frame
|
||||||
|
uint8_t effectID; // ID of the effect that is using this particle system, used for transitions
|
||||||
|
};
|
||||||
|
|
||||||
|
bool initParticleSystem1D(ParticleSystem1D *&PartSys, const uint32_t requestedsources, const uint8_t fractionofparticles = 255, const uint32_t additionalbytes = 0, const bool advanced = false);
|
||||||
|
uint32_t calculateNumberOfParticles1D(const uint32_t fraction, const bool isadvanced);
|
||||||
|
uint32_t calculateNumberOfSources1D(const uint32_t requestedsources);
|
||||||
|
bool allocateParticleSystemMemory1D(const uint32_t numparticles, const uint32_t numsources, const bool isadvanced, const uint32_t additionalbytes);
|
||||||
|
void blur1D(CRGB *colorbuffer, uint32_t size, uint32_t blur, uint32_t start);
|
||||||
|
#endif // WLED_DISABLE_PARTICLESYSTEM1D
|
@ -1210,4 +1210,4 @@ void serializeConfigSec() {
|
|||||||
if (f) serializeJson(root, f);
|
if (f) serializeJson(root, f);
|
||||||
f.close();
|
f.close();
|
||||||
releaseJSONBufferLock();
|
releaseJSONBufferLock();
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user