Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to particle system #4630

Open
wants to merge 264 commits into
base: main
Choose a base branch
from
Open

Conversation

DedeHai
Copy link
Collaborator

@DedeHai DedeHai commented Apr 6, 2025

  • code prettyfied
  • varios minor fixes and speed tweaks
  • improved collision detection and handling (look-ahead)
  • improvements in PS Hourglass
  • added "playful" mode to PS Chase (random variation of speed, size, spacing and colors)

New PS Effects:

  • Sonic Boom: AR effect with firework like explosions with different mapping options (static position, alternating positions, random)
  • PS Springy: particles chained with springs with many parameters, optionally supports AR. Not all combination of settings look good on all setups: parameter ranges are such that it can be made to look good on 10LEDs or 1000 LEDs

edit:
not sure why this PR shows so many commits, maybe I should have rebased the branch before cherry-picking? It's actually only 8 commits. Is it better to start a new PR or just squash-merge this one?

Summary by CodeRabbit

  • New Features
    • Introduced two new visual effect modes, expanding the creative display options.
  • Refactor
    • Enhanced particle dynamics, including adjustments to speed and saturation for improved visual effects.
    • Updated collision detection logic for more accurate interactions between particles.

at the expense of more ram usage, animations now have more options for color control (already used in fireworks now)
improved efficiency for stackup (pushback), added code to correctly determine direction if particles meed (probably overkill but now its there)
untested, need to verify it works
…ables 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.
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)
particle pile-up did not work correctly, now fixed
touch is implemented differently on S2 and S3, these changes make touch buttons work on S2 and S3
now better fits the default threshold value of 32
-removed wrap_update function, now integrated into move_update
-added more 'out of bounds' checking in fire functions, may speed it up a little
-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
removed / added comments
…, 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
if a PS FX is partially overlapping, it will render in overlay mode
- 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)
- improved Balance and Hourglass FX
- bugfix in 1D collisions
- minor improvements / fixes
added velcity lookahead, improved calculation speed for 1D collisions (only about 1% FPS increase but still an improvement)
Copy link

coderabbitai bot commented Apr 6, 2025

Walkthrough

This pull request updates the particle effects system. In the primary effects file, the fireworks mode now uses hardware-based randomization for velocity and saturation, and two new modes—sonic boom and springy—are introduced. The corresponding header file updates the effect mode definitions and the overall mode count. In the particle system implementation, function signatures have been refined by changing parameter types (e.g., from uint32_t to uint8_t) to better suit color and brightness handling. Minor adjustments for readability, optimization of mathematical operations, and revised collision handling are also applied.

Changes

File(s) Change Summary
wled00/FX.cpp
wled00/FX.h
In FX.cpp, updated mode_particleFireworks1D() to use hw_random16 for velocity and saturation; added new effect modes: mode_particle1DsonicBoom() and mode_particleSpringy(). In FX.h, replaced the old mode constant with definitions for FX_MODE_PS1DSONICBOOM (215) and FX_MODE_PS1DSPRINGY (216) and updated MODE_COUNT to 217.
wled00/FXparticleSystem.cpp
wled00/FXparticleSystem.h
Updated function signatures: changed parameter types from uint32_t to uint8_t for color scaling and brightness in functions like fast_color_add, fast_color_scale, and renderParticle. Modified collision handling parameters (e.g., dx_abs type) and replaced division with bit shifting for particle size calculations. Added minor formatting improvements for readability.

Possibly related PRs

  • intermediate fix for PS transition speedup #4562: The changes in this PR are related to the modifications in the renderParticle method signatures in the FXparticleSystem.cpp and FXparticleSystem.h files.
  • Adding Particle System with many new FX #4506: This PR addresses modifications in the FX.h file, specifically the addition of new effect modes that include FX_MODE_PS1DSONICBOOM and FX_MODE_PS1DSPRINGY, which are directly connected to the new particle effects introduced.

Suggested reviewers

  • netmindz
  • softhack007

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.31.1)
wled00/FX.cpp

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e2fde1 and d0042b6.

📒 Files selected for processing (1)
  • wled00/FX.cpp (14 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
wled00/FX.cpp (5)
wled00/fcn_declare.h (14)
  • hw_random16 (539-539)
  • hw_random16 (539-539)
  • hw_random16 (540-540)
  • hw_random16 (540-540)
  • hw_random16 (541-541)
  • hw_random16 (541-541)
  • sin16_t (574-574)
  • perlin8 (525-525)
  • perlin8 (526-526)
  • perlin8 (527-527)
  • hw_random (536-536)
  • hw_random (536-536)
  • hw_random (537-537)
  • hw_random (538-538)
wled00/FXparticleSystem.cpp (2)
  • initParticleSystem1D (1946-1959)
  • initParticleSystem1D (1946-1946)
wled00/FXparticleSystem.h (1)
  • initParticleSystem1D (413-413)
wled00/wled_math.cpp (2)
  • sin16_t (65-76)
  • sin16_t (65-65)
wled00/util.cpp (10)
  • perlin8 (785-787)
  • perlin8 (785-785)
  • perlin8 (789-791)
  • perlin8 (789-789)
  • perlin8 (793-795)
  • perlin8 (793-793)
  • hw_random (608-612)
  • hw_random (608-608)
  • hw_random (614-620)
  • hw_random (614-614)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: wled_build / Build Environments (esp32dev_V4)
  • GitHub Check: wled_build / Build Environments (lolin_s2_mini)
  • GitHub Check: wled_build / Build Environments (usermods)
  • GitHub Check: wled_build / Build Environments (esp32_wrover)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_8MB_opi)
  • GitHub Check: wled_build / Build Environments (esp32s3_4M_qspi)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_16MB_opi)
  • GitHub Check: wled_build / Build Environments (esp32_eth)
  • GitHub Check: wled_build / Build Environments (esp32c3dev)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full_compat)
  • GitHub Check: wled_build / Build Environments (esp32dev)
  • GitHub Check: wled_build / Build Environments (nodemcuv2_compat)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full_160)
  • GitHub Check: wled_build / Build Environments (esp8266_2m_160)
  • GitHub Check: wled_build / Build Environments (nodemcuv2_160)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full)
🔇 Additional comments (18)
wled00/FX.cpp (18)

7821-7821: Improved randomization for rocket speed 👍

The change from random16 to hw_random16 improves the quality of randomness for the rocket speed calculation. Hardware-based randomization typically provides better entropy and can be more efficient.


7891-7891: Enhanced particle color saturation control

The modified saturation calculation 100 + hw_random16(156) ensures a minimum saturation of 100 while using hardware randomization, resulting in more vibrant and consistent colors for the explosion particles.


9517-9517: Improved particle count calculation

The refined formula to calculate used particles provides more precise control over particle density based on intensity.


9520-9520: Enhanced collision physics with specific hardness

Setting collision hardness to 32 provides a good balance that was likely determined through experimentation across various settings.


9534-9539: Well-designed target position calculation using lambda

The lambda function elegantly handles position calculation based on gravity direction, improving code readability and maintainability.


9542-9546: Improved collision detection with look-ahead mechanism

The new collision detection logic with the closeToTarget check creates a more natural transition when particles approach their target positions, preventing abrupt movements.


9571-9576: Added particle reordering for collision consistency

This new code ensures particles maintain their proper order after collisions, which is essential for maintaining visual coherence in the hourglass effect.


9695-9695: Added configurable motion blur

Motion blur mapped to SEGMENT.custom2 enhances visual aesthetics by creating smoother transitions between particle positions.


9712-9721: Enhanced particle ordering with wrap-around handling

This improved reordering algorithm handles the special case where particles wrap around the edges of the display, maintaining visual consistency for all particle rendering modes.


9777-9780: Refined particle distribution and color gradient

The revised calculations for particle count and hue step provide better scaling based on segment settings, resulting in more visually appealing effects.


9782-9785: Added dynamic "playful mode" variations

The conditional spacing and size adjustments based on time create an organic, dynamic animation that varies particle appearance based on sine waves, resulting in a more engaging visual effect.

Also applies to: 9807-9809


9818-9842: Comprehensive implementation of "playful mode"

This sophisticated mode dynamically varies multiple parameters (hue, size, speed, density) over time, creating an organically evolving effect that responds to mathematical functions rather than fixed settings. The bidirectional controls using direction variables prevent parameters from exceeding useful bounds.


10087-10087: Improved threshold calculation for audio reactivity

The modified threshold calculation based on intensity provides better control over audio sensitivity, making the effect more responsive to various audio input levels.


10095-10095: Enhanced color control with saturation condition

Setting saturation based on the SEGMENT.custom1 value with a conditional to handle white color (saturation=0) provides better user control over the effect's color scheme.


10106-10108: Added frequency-based color modulation

The new mid-frequency modulation creates color variations based on audio spectrum analysis, resulting in more dynamic and responsive visuals that match music patterns.


10159-10242: Well-implemented new Sonic Boom effect

This new particle effect creates firework-like explosions triggered by audio beats. The implementation includes:

  • Proper initialization with memory checks
  • Customizable position options (fixed, alternating, or random)
  • Threshold-based audio reactivity with optional filtering
  • Color selection based on position or incremental changes
  • Dynamic particle emission based on audio volume

The effect's parameters are well-designed to provide substantial customization while maintaining good defaults.


10249-10410: Comprehensive implementation of Springy particle effect

This sophisticated physics simulation of particles connected by springs includes:

  • Spring force calculations with proper constraints
  • Oscillation dampening to prevent perpetual motion
  • Multiple excitation modes (periodic, sinusoidal, random, audio-reactive)
  • Color mapping options (speed-based, gradient, or density-based)
  • Particle reordering to maintain visual coherence
  • Particle position limits to prevent excessive stretching

The physics implementation correctly handles spring forces, friction, and external stimuli while maintaining stability.


10681-10683: Successfully registered new particle effects

The new Sonic Boom and Springy effects are properly registered with the effects system, making them available for selection in the user interface.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
wled00/FX.cpp (1)

9776-9776: Minor typo in comment.

There's a typo in the comment "anable motion blur" instead of "enable motion blur".

-PartSys->setMotionBlur(7 + ((SEGMENT.custom3) << 3)); // anable motion blur
+PartSys->setMotionBlur(7 + ((SEGMENT.custom3) << 3)); // enable motion blur
wled00/FXparticleSystem.h (1)

346-346: Inconsistency in function formatting

The function signature changed but doesn't appear to have substantive changes to the parameters. This might be just a code formatting change for consistency.

wled00/FXparticleSystem.cpp (1)

914-917: Enhanced collision detection with velocity lookahead.

The collision detection has been significantly improved by including velocity components in proximity calculations. Instead of just comparing current positions, the code now predicts where particles will be in the next frame by adding velocity to position. This results in more accurate collision detection, especially for fast-moving particles that might otherwise pass through each other between frames.

Consider adding a comment explaining the lookahead approach to make the intention clear to future maintainers.

-        int32_t dx = (particles[idx_j].x + particles[idx_j].vx) - (particles[idx_i].x + particles[idx_i].vx); // distance with lookahead
+        // Calculate predicted position difference using lookahead (position + velocity) for more accurate collision detection
+        int32_t dx = (particles[idx_j].x + particles[idx_j].vx) - (particles[idx_i].x + particles[idx_i].vx); // distance with lookahead
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b0b3196 and eae42af.

📒 Files selected for processing (4)
  • wled00/FX.cpp (13 hunks)
  • wled00/FX.h (1 hunks)
  • wled00/FXparticleSystem.cpp (57 hunks)
  • wled00/FXparticleSystem.h (3 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
wled00/FX.cpp (4)
wled00/fcn_declare.h (15)
  • hw_random16 (539-539)
  • hw_random16 (539-539)
  • hw_random16 (540-540)
  • hw_random16 (540-540)
  • hw_random16 (541-541)
  • hw_random16 (541-541)
  • sin16_t (574-574)
  • sqrt32_bw (587-587)
  • perlin8 (525-525)
  • perlin8 (526-526)
  • perlin8 (527-527)
  • hw_random (536-536)
  • hw_random (536-536)
  • hw_random (537-537)
  • hw_random (538-538)
wled00/FXparticleSystem.h (1)
  • initParticleSystem1D (413-413)
wled00/wled_math.cpp (4)
  • sin16_t (65-76)
  • sin16_t (65-65)
  • sqrt32_bw (225-246)
  • sqrt32_bw (225-225)
wled00/util.cpp (10)
  • perlin8 (785-787)
  • perlin8 (785-785)
  • perlin8 (789-791)
  • perlin8 (789-789)
  • perlin8 (793-795)
  • perlin8 (793-793)
  • hw_random (608-612)
  • hw_random (608-608)
  • hw_random (614-620)
  • hw_random (614-614)
wled00/FXparticleSystem.cpp (1)
wled00/FXparticleSystem.h (17)
  • part (163-163)
  • part (169-169)
  • part (170-170)
  • part (173-173)
  • part (176-176)
  • part (344-344)
  • part (346-346)
  • part (348-348)
  • particleindex (171-171)
  • particleindex (174-174)
  • particleindex (178-178)
  • particleindex (214-214)
  • particleindex (381-381)
  • x (185-185)
  • x (354-354)
  • particle1 (218-218)
  • particle1 (386-386)
🪛 Cppcheck (2.10-2)
wled00/FX.cpp

[error] 10320-10320: Invalid abs() argument nr 1. A non-boolean value is required.

(invalidFunctionArgBool)

⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: wled_build / Build Environments (nodemcuv2_compat)
  • GitHub Check: wled_build / Build Environments (esp32s3_4M_qspi)
  • GitHub Check: wled_build / Build Environments (nodemcuv2_160)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full_160)
  • GitHub Check: wled_build / Build Environments (esp32dev)
  • GitHub Check: wled_build / Build Environments (esp32_wrover)
  • GitHub Check: wled_build / Build Environments (esp8266_2m_compat)
  • GitHub Check: wled_build / Build Environments (esp32dev_V4)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_16MB_opi)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_8MB_opi)
  • GitHub Check: wled_build / Build Environments (usermods)
  • GitHub Check: wled_build / Build Environments (lolin_s2_mini)
  • GitHub Check: wled_build / Build Environments (esp32c3dev)
  • GitHub Check: wled_build / Build Environments (esp8266_2m_160)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full_compat)
  • GitHub Check: wled_build / Build Environments (nodemcuv2)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full)
  • GitHub Check: wled_build / Build Environments (esp8266_2m)
🔇 Additional comments (30)
wled00/FX.cpp (17)

7821-7821: Good use of hardware randomization for velocity.

The change to use hw_random16 for rocket velocity provides better randomization than software-based methods. This should deliver more natural-looking firework behavior.


7891-7891: Nice enhancement to particle saturation range.

Using hw_random16(156) with a base of 100 ensures vibrant colors (saturation between 100-255) while maintaining randomness.


9517-9520: Good improvements to particle system configuration.

The updated intensity-based particle count calculation and collision detection with an experimentally-derived hardness value will improve the visual appeal and physics behavior.


9534-9539: Well-structured lambda function for target position calculation.

Using a lambda for calculating target positions improves code readability and maintenance by centralizing this logic.


9543-9546: Improved collision detection with look-ahead logic.

The new approach with a closeToTarget boolean improves readability and provides better control over when particles are considered "arrived" at their destinations.


9571-9576: Good addition of particle re-ordering after collisions.

This ensures particles maintain their intended visual arrangement even after physics interactions cause position changes.


9584-9584: Consistent use of the target position calculation.

Using the calcTargetPos lambda for setting initial positions ensures consistency with the rest of the code.


9712-9721: Particle re-ordering with wrap-around handling.

The additional check for wrap-around conditions is a good enhancement that prevents incorrect swapping of particles that are actually on opposite ends of the display.


9763-9763: Enhanced particle system initialization.

Setting advanced to true enables more sophisticated particle features that will improve the visual quality of the effect.


9777-9779: Improved particle count calculation.

The new logic for calculating the number of particles and hue steps based on intensity and other parameters will provide more consistent and visually pleasing results.


9799-9801: Great addition of dynamic color spread in "playful mode".

The sine-based modulation of hue step and particle size creates more dynamic and engaging visual patterns.

Also applies to: 9807-9809


9818-9842: Excellent implementation of "playful mode".

This new mode with its dynamic changes to hue, size, speed, and density creates a more engaging and varied visual experience. The combination of different timing mechanisms for each parameter provides complex but coherent motion.


10087-10087: Improved audio reactive behavior.

The updates to threshold calculation and saturation handling will provide better response to audio input and more consistent visuals.

Also applies to: 10095-10095


10106-10109: Nice addition of mid-frequency color modulation.

Using mid-frequency audio data with Perlin noise to modulate colors creates rich, responsive visual patterns that enhance the audio-reactive experience.


10159-10243: Great new "Sonic Boom" effect.

This effect creates explosion particles triggered by audio beats with multiple position modes (fixed, alternating, random) and color options. The implementation uses audio data effectively to create dynamic, music-responsive visuals.


10249-10411: Impressive "Springy" effect with realistic physics.

The new spring physics effect is well-implemented with:

  • Configurable spring constants and length
  • Advanced damping mechanisms to control oscillations
  • Multiple excitation methods (pulses, sine waves, random)
  • Smart handling of particle ordering and physics calculations
  • Various color mapping options based on particle physics properties

This effect adds significant value with its highly customizable parameters and realistic physics simulation.

🧰 Tools
🪛 Cppcheck (2.10-2)

[error] 10320-10320: Invalid abs() argument nr 1. A non-boolean value is required.

(invalidFunctionArgBool)


10681-10683: Good integration of new effects.

The new effects are properly registered with the system, making them available to users with appropriate metadata.

wled00/FX.h (1)

354-356: Added two new particle system effects

These changes introduce two new particle system effects ("PS1DSONICBOOM" and "PS1DSPRINGY") and update the MODE_COUNT accordingly. The new effects align with the PR objectives of adding "Sonic Boom" (an AR experience with firework-like explosions) and "PS Springy" (particles connected by springs).

wled00/FXparticleSystem.h (3)

214-214: Optimized parameter type for brightness

Changed the brightness parameter from uint32_t to uint8_t. This is a good optimization since brightness values typically range from 0-255, making uint8_t sufficient. This reduces memory usage and aligns with the PR's performance optimization goals.


381-381: Optimized parameter type for brightness

Similar to the 2D version, the brightness parameter has been changed from uint32_t to uint8_t, which is an appropriate data type for brightness values (0-255). This optimization improves memory usage.


386-386: Improved collision detection parameters

Changed the collision parameters from using relative velocity (relativeVx) to using absolute distance (dx_abs). This modification likely improves the precision of collision detection and aligns with the PR objective of enhancing collision handling through a look-ahead mechanism.

wled00/FXparticleSystem.cpp (9)

21-22: Type correction for color scale parameters.

The parameter type changes from uint32_t to uint8_t for scale values in these functions is appropriate since color scaling factors typically range from 0-255. This improves type correctness and reduces memory usage while maintaining the same functionality.


390-398: Performance optimization using bit shifts instead of division.

The calculation of deviation and angle transformations now use bit shifts (>>) instead of division, which is more efficient on embedded hardware. The addition of 255 before shifting right by 8 bits (equivalent to dividing by 256) ensures proper rounding.


697-699: Type correction for brightness parameters.

Changing the type of brightness parameter from uint32_t to uint8_t is appropriate since brightness values are in the 0-255 range. Similarly, changing the pxlbrightness array type reduces memory usage. These changes make the code more type-correct and efficient.

Also applies to: 709-709


1771-1774: Improved 1D particle collision detection with lookahead.

Similar to the 2D system, the 1D particle collision detection now includes velocity in its calculations, which improves collision accuracy. The type change from int32_t dx_abs to uint32_t dx_abs is also appropriate since absolute values are always non-negative.


1783-1795: Optimized collision calculation for different architectures.

The collision calculation has been improved and optimized for different chip architectures. The code now uses bit shifts with proper rounding for ESP32C3 and ESP8266 platforms, while using division for other ESP32 platforms based on their performance characteristics.


2030-2030: Optimized maximum color value calculation.

The implementation for finding the maximum of three color values has been improved using chained comparisons, which according to the comment is faster than using std::max() or XOR operations. This small optimization can have a significant impact in a function called frequently during rendering.

Also applies to: 2043-2045


2098-2098: Memory management safety improvements.

Several safety checks have been added to prevent potential crashes:

  1. Null pointer check before freeing memory
  2. Improved minimum particle allocation logic
  3. Safety checks before particle transfers and buffer offset calculations

These changes enhance the robustness of the memory management system, reducing the risk of crashes due to invalid memory operations.

Also applies to: 2164-2166, 2189-2190, 2192-2195


2326-2330: Buffer handling robustness improvements.

The buffer allocation and deallocation logic has been enhanced with better checks:

  1. Improved conditional checks for buffer allocation
  2. Proper null checks before deallocating buffers
  3. Null check before transferring buffer data

These changes improve the reliability of the rendering system by preventing operations on invalid buffers.

Also applies to: 2364-2373, 2379-2379


2344-2347: Skipping frozen segments in memory management.

Adding a check to skip frozen segments when handling memory prevents unnecessary incrementing of the watchdog counter for inactive segments, which would otherwise lead to memory deallocation and potential crashes when the segment becomes active again.

@blazoncek
Copy link
Collaborator

You used your original particle branch which was squash-merged into main.
You will need to branch off of main, make changes/commits and make PR or squash again and make a PR from squashed commit.
It is also possible to do a squash merge from this PR.

@DedeHai
Copy link
Collaborator Author

DedeHai commented Apr 6, 2025

thanks for the clarification, makes sense as git does not know all old commits. I will do future updates branched from main then and use squash merge on this one.

@DedeHai
Copy link
Collaborator Author

DedeHai commented Apr 6, 2025

Assuming there are no objections to this PR:
@blazoncek the changes here diverge a bit from the draft PR for segment layering. I would update that PR with the latest PS version (i.e. this one but without the changes to FX.cpp) before I start working on it so there will be less conflicts when moving to 0.16 later on if that is ok with you.

@blazoncek
Copy link
Collaborator

FX.cpp is a beast I don't like very much.
In my own fork I have removed all audio effects from it and moved them into AR usermod.
I would suggest to do the same with PS effects. Move them to separate file.

@DedeHai
Copy link
Collaborator Author

DedeHai commented Apr 6, 2025

that is true and a good option to reduce FX.cpp. Some restructuring of files in general is something that may need to be discussed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants