Skip to content

Conversation

@DedeHai
Copy link
Collaborator

@DedeHai DedeHai commented May 9, 2025

VID_20250508_185054_1.mp4

Summary by CodeRabbit

  • New Features
    • Introduced a new 2D "Particle Galaxy" effect simulating spiraling particles with configurable color mapping, size, and motion blur.
    • Added starfield and spiral movement patterns with dynamic emitter motion and color transitions.
  • Enhancements
    • Increased the total number of available effects to 218.

DedeHai added 3 commits May 9, 2025 18:53
- parameters tuned to make it look good on most settings
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 9, 2025

Walkthrough

A new 2D particle effect called "Particle Galaxy" has been introduced, featuring spiraling particles with configurable parameters. The effect is implemented in the core source file, registered in the effect setup, and assigned a unique identifier in the header file. The total mode count is also updated to reflect the addition.

Changes

Files/Paths Change Summary
wled00/FX.cpp Added the mode_particlegalaxy function implementing a new 2D particle galaxy effect; registered the effect in the setup function with associated metadata.
wled00/FX.h Defined FX_MODE_PARTICLEGALAXY macro with value 217; incremented MODE_COUNT macro from 217 to 218.

Possibly related PRs

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

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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
Contributor

@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: 3

🧹 Nitpick comments (2)
wled00/FX.cpp (2)

8992-8996: custom1 / check3 interaction silently overrides particle size

When SEGMENT.check3 is true the code forcibly maps any custom1 value to either 0 or 1, effectively discarding sizes > 1.
Because UI sliders still allow 0-255 this can confuse users and feels like a bug.

Consider using a separate custom parameter for the “trace” toggle or honour the original size while still enabling motion-blur, e.g.:

-if (SEGMENT.check3)
-  particlesize = SEGMENT.custom1 ? 1 : 0;
+if (SEGMENT.check3 && particlesize <= 1)   // only coerce when really needed
+  particlesize = particlesize ? 1 : 0;

Please confirm if clamping to {0,1} is intentional UX.


9057-9057: Metadata string: placeholder fields are confusing

"PS Galaxy@!,!,Size,,Color,,Starfield,Trace;..." contains empty parameter slots (!,!, ,,) which show as unnamed sliders in the UI.

Consider either:

  1. Filling them with meaningful names (e.g. “Speed”, “Intensity”), or
  2. Removing trailing commas to hide them.

This improves UX consistency with other particle effects.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d9b086c and 5fe7663.

📒 Files selected for processing (2)
  • wled00/FX.cpp (2 hunks)
  • wled00/FX.h (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (19)
  • GitHub Check: wled_build / Build Environments (nodemcuv2_compat)
  • GitHub Check: wled_build / Build Environments (esp32_wrover)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_16MB_opi)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_8MB_opi)
  • GitHub Check: wled_build / Build Environments (esp32s3_4M_qspi)
  • GitHub Check: wled_build / Build Environments (lolin_s2_mini)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full_compat)
  • GitHub Check: wled_build / Build Environments (esp32_eth)
  • GitHub Check: wled_build / Build Environments (usermods)
  • GitHub Check: wled_build / Build Environments (esp32dev_V4)
  • GitHub Check: wled_build / Build Environments (esp32dev)
  • GitHub Check: wled_build / Build Environments (esp32c3dev)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full)
  • GitHub Check: wled_build / Build Environments (esp8266_2m_compat)
  • GitHub Check: wled_build / Build Environments (nodemcuv2_160)
  • GitHub Check: wled_build / Build Environments (esp8266_2m)
  • GitHub Check: wled_build / Build Environments (nodemcuv2)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full_160)
  • GitHub Check: wled_build / Build Environments (esp8266_2m_160)
🔇 Additional comments (3)
wled00/FX.h (2)

356-356: New effect identifier registration
The macro FX_MODE_PARTICLEGALAXY is correctly inserted with ID 217, following FX_MODE_PS1DSPRINGY (216). Ensure this ID is unique and doesn’t collide with any other mode IDs.

Please verify in FX.cpp’s setupEffectData() (or equivalent) that mode_particlegalaxy is registered using this identifier, e.g.:

addEffect(FX_MODE_PARTICLEGALAXY, mode_particlegalaxy, "Particle Galaxy");

357-357: Update MODE_COUNT to reflect new mode
The MODE_COUNT macro has been incremented from 217 to 218, which correctly accounts for the added effect. Confirm that any arrays, loops, or UI elements that rely on MODE_COUNT properly accommodate the new size.

wled00/FX.cpp (1)

8970-8983: Memory-leak / double-alloc defence

initParticleSystem2D allocates and stores the pointer in SEGENV.data, but PartSys is also a local pointer.
If the function fails midway (e.g. allocation succeeded but a subsequent call path returns mode_static()), the allocated object might be leaked.

Verify that initParticleSystem2D() internally frees on failure or add a clean-up path before returning.

@netmindz
Copy link
Member

netmindz commented May 9, 2025

Are any of the coderabbit suggestions valid/useful ?

@DedeHai
Copy link
Collaborator Author

DedeHai commented May 10, 2025

the last one is actually a good one.

Copy link
Contributor

@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

♻️ Duplicate comments (1)
wled00/FX.cpp (1)

9006-9018: 🛠️ Refactor suggestion

Optimize by moving invariant calculations outside the particle loop

The calculation of centerx/centery and the mode-specific settings are invariant for each frame but are recalculated for every particle. Moving these outside the particle loop would improve performance, especially on resource-constrained devices like ESP8266.

+  // move alive particles in a spiral motion (or almost straight in fast starfield mode)
+  int32_t centerx = PartSys->maxX >> 1; // center of matrix in subpixel coordinates
+  int32_t centery = PartSys->maxY >> 1;
+  if (SEGMENT.check2) { // starfield mode
+    PartSys->setKillOutOfBounds(true);
+    PartSys->sources[0].var = 7; // emiting variation
+    PartSys->sources[0].source.x =  centerx; // set emitter to center
+    PartSys->sources[0].source.y =  centery;
+  }
+  else {
+    PartSys->setKillOutOfBounds(false);
+    PartSys->sources[0].var = 1; // emiting variation
+  }
+
   for (uint32_t i = 0; i < PartSys->usedParticles; i++) { //check all particles
     if (PartSys->particles[i].ttl == 0) continue; //skip dead particles
     // (dx/dy): vector pointing from particle to center
-    int32_t centerx = PartSys->maxX >> 1; // center of matrix in subpixel coordinates
-    int32_t centery = PartSys->maxY >> 1;
-    if (SEGMENT.check2) { // starfield mode
-      PartSys->setKillOutOfBounds(true);
-      PartSys->sources[0].var = 7; // emiting variation
-      PartSys->sources[0].source.x =  centerx; // set emitter to center
-      PartSys->sources[0].source.y =  centery;
-    }
-    else {
-      PartSys->setKillOutOfBounds(false);
-      PartSys->sources[0].var = 1; // emiting variation
-    }
🧹 Nitpick comments (2)
wled00/FX.cpp (2)

9039-9041: Use consistent type definitions for spiral calculations

You're using int for spiral velocity calculations, while the rest of the code uses int32_t. For consistency and to prevent potential issues with large values (especially from the << 9 shift), use int32_t throughout.

-      int vxc = (dx << 9) / (distance - 19); // subtract value from distance to make the pull-in force a bit stronger (helps on faster speeds)
-      int vyc = (dy << 9) / (distance - 19);
+      int32_t vxc = (dx << 9) / (distance - 19); // subtract value from distance to make the pull-in force a bit stronger (helps on faster speeds)
+      int32_t vyc = (dy << 9) / (distance - 19);

9052-9055: Define behavior for intermediate custom3 values

The color mapping logic only explicitly handles custom3 values of 0 and 31, leaving the behavior for values between 1-30 undefined. Consider adding handling for intermediate values or clarifying the current behavior in a comment.

     if(SEGMENT.custom3 == 31) // color by age but mapped to 1024 as particles have a long life, since age is random, this gives more or less random colors
       PartSys->particles[i].hue = PartSys->particles[i].ttl >> 2;
     else if(SEGMENT.custom3 == 0) // color by distance
       PartSys->particles[i].hue = map(distance, 20, (PartSys->maxX + PartSys->maxY) >> 2, 0, 180); // color by distance to center
+    else // for intermediate values 1-30, inherit hue from source with small variations
+      PartSys->particles[i].hue = PartSys->sources[0].source.hue + (hw_random8() & 0x0F) - 7; // +/- 7 variation
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5fe7663 and 608aff1.

📒 Files selected for processing (1)
  • wled00/FX.cpp (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
wled00/FX.cpp (2)

undefined

<retrieved_learning>
Learnt from: DedeHai
PR: #4682
File: wled00/FX.cpp:8997-9005
Timestamp: 2025-05-09T18:43:15.327Z
Learning: In the WLED codebase, SEGMENT.custom3 is always constrained to the range 0-31 and will not exceed this range.
</retrieved_learning>

<retrieved_learning>
Learnt from: DedeHai
PR: #4682
File: wled00/FX.cpp:9016-9039
Timestamp: 2025-05-09T18:48:21.248Z
Learning: WLED does not support matrices large enough (≥1024 px) for 32-bit overflow in dxdx + dydy to be a practical concern in particle system effects.
</retrieved_learning>

⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_8MB_opi)
  • GitHub Check: wled_build / Build Environments (usermods)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_16MB_opi)
  • GitHub Check: wled_build / Build Environments (esp32_wrover)
  • GitHub Check: wled_build / Build Environments (esp32_eth)
  • GitHub Check: wled_build / Build Environments (lolin_s2_mini)
  • GitHub Check: wled_build / Build Environments (esp32s3_4M_qspi)
  • GitHub Check: wled_build / Build Environments (esp32dev_V4)
  • GitHub Check: wled_build / Build Environments (esp32dev)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full_compat)
  • GitHub Check: wled_build / Build Environments (esp8266_2m)
🔇 Additional comments (1)
wled00/FX.cpp (1)

10762-10762: LGTM! Effect registration looks good.

The new effect is properly registered in the effect setup function.

@DedeHai
Copy link
Collaborator Author

DedeHai commented May 10, 2025

ok, fixed it. ready to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants