Skip to content

Conversation

BobLoeffler68
Copy link

@BobLoeffler68 BobLoeffler68 commented Aug 31, 2025

This was already reviewed by dedahai and blazoncek in PR #4536, but that one had other code in it for another effect and we are not including that other effect in this PR. That other PR was a draft and has been closed.

The only PacMan code difference between that PR and this one is that I had to modify the colors of the characters and powerdots because of gamma correction fixes in the last few months. They made the character colors change enough where they didn't look good anymore. So colors are back to where they should be if Gamma Correction is enabled.

The other effect in the old PR is called Ants, but it will be done separately (either a normal effect or a usermod effect).

Summary by CodeRabbit

  • New Features
    • Added a Pac‑Man themed lighting mode with Pac‑Man, four ghosts, power‑dots, dot‑eating, chase/"blue ghost" behavior, and blinking cues near strip start.
    • Configurable speed, number of power dots, and dot style (white or compact).
    • Per‑segment support; appears as a new selectable effect alongside existing 1D/2D modes.

Copy link
Contributor

coderabbitai bot commented Aug 31, 2025

Walkthrough

Adds a Pac‑Man effect: defines FX_MODE_PACMAN (ID 151), implements static mode_pacman with a pacmancharacters_t state, adds _data_FX_MODE_PACMAN PROGMEM metadata, allocates per‑segment state for characters and power‑dots, renders Pac‑Man/ghosts/dots, and registers the effect (registration appears twice).

Changes

Cohort / File(s) Summary
Effect implementation & registration
wled00/FX.cpp
Adds pacmancharacters_t typedef, implements static uint16_t mode_pacman(void), adds _data_FX_MODE_PACMAN[] PROGMEM, uses SEGENV.allocateData for per‑segment character/dot state, renders Pac‑Man, ghosts, power‑dots and their interactions, and calls addEffect(FX_MODE_PACMAN, &mode_pacman, _data_FX_MODE_PACMAN) (inserted twice in patch).
Effect ID declaration
wled00/FX.h
Adds macro FX_MODE_PACMAN = 151; the prior FX_MODE_2DFIRE2012 at 151 is commented out.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • softhack007
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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: 1

🧹 Nitpick comments (4)
wled00/FX.h (1)

310-310: Nit: strengthen the inline comment to avoid SR-ID confusion.

The block header says “SR compatible IDs,” while this line is non-SR. Clarify in-line to discourage future renumbering.

Apply this tiny comment tweak:

-#define FX_MODE_PACMAN                 151 // gap fill - not SR
+#define FX_MODE_PACMAN                 151 // gap fill (non-SR). Do NOT renumber; SR-ID range must remain stable.
wled00/FX.cpp (3)

3291-3294: Power-dot rendering is safe, but keep positions guarded by contract

Current positions come from controlled math and remain within [0, SEGLEN-1]. If future changes alter placement logic, consider mirroring the same bounds check pattern used for characters to keep this robust.


3170-3177: Prefer explicit integer widths for positions

signed for pos/topPos works but is vague. Use int16_t (or int32_t if needed) to make intent and size explicit and minimize memory.

-typedef struct PacManChars {
-  signed    pos;
-  signed    topPos;
+typedef struct PacManChars {
+  int16_t   pos;
+  int16_t   topPos;

3338-3341: Decouple movement from PacMan’s direction (optional)

Ghost movement currently keys off character[PACMAN].direction. Using each ghost’s own direction improves clarity and future tweaks (e.g., different behaviors per ghost) with zero behavior change today.

-      character[i].pos += character[PACMAN].direction?1:-1;
+      character[i].pos += character[i].direction ? 1 : -1;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between da7f107 and a6111fb.

📒 Files selected for processing (2)
  • wled00/FX.cpp (2 hunks)
  • wled00/FX.h (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
wled00/{*.cpp,!(html_*)*.h}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use spaces (2 per level) for C++ source and header files

Files:

  • wled00/FX.h
  • wled00/FX.cpp
🧠 Learnings (3)
📓 Common learnings
Learnt from: DedeHai
PR: wled/WLED#4798
File: wled00/FX.cpp:7531-7533
Timestamp: 2025-08-26T11:51:21.817Z
Learning: In WLED PR #4798, DedeHai confirmed that certain gamma-related calls in FX.cpp/FX_fcn.cpp/particle systems are intentional for effect-level shaping (e.g., brightness curves, TV sim, Pride 2015 pre-mix), distinct from final output gamma. Do not flag or remove these in future reviews; add comments when feasible to clarify intent.
📚 Learning: 2025-06-15T09:59:52.720Z
Learnt from: netmindz
PR: wled/WLED#4728
File: wled00/FX.h:378-378
Timestamp: 2025-06-15T09:59:52.720Z
Learning: In WLED's FX.h, MODE_COUNT represents the highest FX_MODE_ ID + 1, not the total count of FX_MODE_ definitions. This is because some effects may have been removed but their IDs are not reused, creating gaps in the numbering sequence. MODE_COUNT is used for array bounds and range checking.

Applied to files:

  • wled00/FX.h
📚 Learning: 2025-08-26T11:51:21.817Z
Learnt from: DedeHai
PR: wled/WLED#4798
File: wled00/FX.cpp:7531-7533
Timestamp: 2025-08-26T11:51:21.817Z
Learning: In WLED PR #4798, DedeHai confirmed that certain gamma-related calls in FX.cpp/FX_fcn.cpp/particle systems are intentional for effect-level shaping (e.g., brightness curves, TV sim, Pride 2015 pre-mix), distinct from final output gamma. Do not flag or remove these in future reviews; add comments when feasible to clarify intent.

Applied to files:

  • wled00/FX.h
  • wled00/FX.cpp
🧬 Code graph analysis (1)
wled00/FX.cpp (1)
usermods/usermod_v2_animartrix/usermod_v2_animartrix.cpp (1)
  • SEGENV (64-76)
🔇 Additional comments (3)
wled00/FX.h (1)

310-310: Approved: FX_MODE_PACMAN addition verified
Unique define at 151, single addEffect registration in FX.cpp, and MODE_COUNT remains 218.

wled00/FX.cpp (2)

3312-3331: Reset logic depends solely on the end-of-strip power dot

The eaten-state reset after returning to LED 0 triggers only if character[5] (the end-of-segment dot) was eaten. If you intended “eat any power dot → chase → on return to start reset all,” this condition can leave dots eaten if the end dot was skipped. Verify intended game flow.

Would you like me to adjust the reset to trigger if any power dot was eaten during the chase window?


10980-10981: Registration confirmed for FX_MODE_PACMAN
FX_MODE_PACMAN is defined once (FX.h:310), its data is declared once (FX.cpp:3356), and it’s registered exactly once via addEffect (FX.cpp:10980).

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: 0

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

3249-3256: Guard the i-1 write when drawing spaced white dots

When Compact Dots is off, add a simple bound to avoid an i-1 underflow if this loop ever reaches 0 after future tweaks.

Apply:

-    for (int i = SEGLEN-1; i >= character[PACMAN].topPos+1; i--) {
+    for (int i = SEGLEN-1; i >= character[PACMAN].topPos+1; i--) {
       SEGMENT.setPixelColor(i, WHITEISH);
       if (!SEGMENT.check2) {
-        SEGMENT.setPixelColor(i-1, BLACK);
-        i--;
+        if (i > 0) {
+          SEGMENT.setPixelColor(i-1, BLACK);
+          i--;
+        }
       }
     }

3290-3294: Bounds-guard power-dot draws

Power-dot positions are computed, but a lightweight guard is safer against future changes and prevents accidental OOB writes.

Apply:

-  for (int i = 0; i < numPowerDots; i++) {
-    if (!character[i+5].eaten)
-      SEGMENT.setPixelColor(character[i+5].pos, character[i+5].color);
-  }
+  for (int i = 0; i < numPowerDots; i++) {
+    if (!character[i+5].eaten) {
+      if ((unsigned)character[i+5].pos < SEGLEN)
+        SEGMENT.setPixelColor(character[i+5].pos, character[i+5].color);
+    }
+  }
🧹 Nitpick comments (1)
wled00/FX.cpp (1)

3335-3352: Simplify in-range checks

The “>= 0” part is redundant after casting to unsigned; keeping only “< SEGLEN” is clearer.

Apply:

-    if ((unsigned)character[PACMAN].pos >= 0 && (unsigned)character[PACMAN].pos < SEGLEN)
+    if ((unsigned)character[PACMAN].pos < SEGLEN)
       SEGMENT.setPixelColor(character[PACMAN].pos, character[PACMAN].color);
@@
-      if ((unsigned)character[i].pos >= 0 && (unsigned)character[i].pos < SEGLEN)
+      if ((unsigned)character[i].pos < SEGLEN)
         SEGMENT.setPixelColor(character[i].pos, character[i].color);

Do the same in the “no update” branch just below.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a6111fb and d6e8623.

📒 Files selected for processing (2)
  • wled00/FX.cpp (2 hunks)
  • wled00/FX.h (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • wled00/FX.h
🧰 Additional context used
📓 Path-based instructions (1)
wled00/{*.cpp,!(html_*)*.h}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use spaces (2 per level) for C++ source and header files

Files:

  • wled00/FX.cpp
🧠 Learnings (3)
📓 Common learnings
Learnt from: BobLoeffler68
PR: wled/WLED#4891
File: wled00/FX.cpp:3333-3349
Timestamp: 2025-08-31T03:38:14.092Z
Learning: WLED PacMan effect (wled00/FX.cpp): Keep pacmancharacters_t position fields as signed int (not int16_t). Maintainer preference (blazoncek) prioritizes avoiding potential overhead/regressions over minor RAM savings. Avoid type shrinking here unless memory pressure is demonstrated.
Learnt from: DedeHai
PR: wled/WLED#4798
File: wled00/FX.cpp:7531-7533
Timestamp: 2025-08-26T11:51:21.817Z
Learning: In WLED PR #4798, DedeHai confirmed that certain gamma-related calls in FX.cpp/FX_fcn.cpp/particle systems are intentional for effect-level shaping (e.g., brightness curves, TV sim, Pride 2015 pre-mix), distinct from final output gamma. Do not flag or remove these in future reviews; add comments when feasible to clarify intent.
📚 Learning: 2025-08-31T03:38:14.092Z
Learnt from: BobLoeffler68
PR: wled/WLED#4891
File: wled00/FX.cpp:3333-3349
Timestamp: 2025-08-31T03:38:14.092Z
Learning: WLED PacMan effect (wled00/FX.cpp): Keep pacmancharacters_t position fields as signed int (not int16_t). Maintainer preference (blazoncek) prioritizes avoiding potential overhead/regressions over minor RAM savings. Avoid type shrinking here unless memory pressure is demonstrated.

Applied to files:

  • wled00/FX.cpp
📚 Learning: 2025-08-26T11:51:21.817Z
Learnt from: DedeHai
PR: wled/WLED#4798
File: wled00/FX.cpp:7531-7533
Timestamp: 2025-08-26T11:51:21.817Z
Learning: In WLED PR #4798, DedeHai confirmed that certain gamma-related calls in FX.cpp/FX_fcn.cpp/particle systems are intentional for effect-level shaping (e.g., brightness curves, TV sim, Pride 2015 pre-mix), distinct from final output gamma. Do not flag or remove these in future reviews; add comments when feasible to clarify intent.

Applied to files:

  • wled00/FX.cpp
🧬 Code graph analysis (1)
wled00/FX.cpp (1)
usermods/usermod_v2_animartrix/usermod_v2_animartrix.cpp (1)
  • SEGENV (64-76)
🔇 Additional comments (2)
wled00/FX.cpp (2)

3170-3177: Good call keeping pos/topPos as signed ints

Matches maintainer guidance and avoids needless overhead.


10984-10985: Registration looks correct (no duplicate)

Effect is registered once with proper metadata. Nothing else to do here.

@BobLoeffler68
Copy link
Author

Modified the latest batch of suggestions by CodeRabbit.

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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d6e8623 and fc72aa7.

📒 Files selected for processing (1)
  • wled00/FX.cpp (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
wled00/{*.cpp,!(html_*)*.h}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use spaces (2 per level) for C++ source and header files

Files:

  • wled00/FX.cpp
🧠 Learnings (3)
📓 Common learnings
Learnt from: DedeHai
PR: wled/WLED#4798
File: wled00/FX.cpp:7531-7533
Timestamp: 2025-08-26T11:51:21.817Z
Learning: In WLED PR #4798, DedeHai confirmed that certain gamma-related calls in FX.cpp/FX_fcn.cpp/particle systems are intentional for effect-level shaping (e.g., brightness curves, TV sim, Pride 2015 pre-mix), distinct from final output gamma. Do not flag or remove these in future reviews; add comments when feasible to clarify intent.
Learnt from: BobLoeffler68
PR: wled/WLED#4891
File: wled00/FX.cpp:3333-3349
Timestamp: 2025-08-31T03:38:14.092Z
Learning: WLED PacMan effect (wled00/FX.cpp): Keep pacmancharacters_t position fields as signed int (not int16_t). Maintainer preference (blazoncek) prioritizes avoiding potential overhead/regressions over minor RAM savings. Avoid type shrinking here unless memory pressure is demonstrated.
📚 Learning: 2025-08-31T03:38:14.092Z
Learnt from: BobLoeffler68
PR: wled/WLED#4891
File: wled00/FX.cpp:3333-3349
Timestamp: 2025-08-31T03:38:14.092Z
Learning: WLED PacMan effect (wled00/FX.cpp): Keep pacmancharacters_t position fields as signed int (not int16_t). Maintainer preference (blazoncek) prioritizes avoiding potential overhead/regressions over minor RAM savings. Avoid type shrinking here unless memory pressure is demonstrated.

Applied to files:

  • wled00/FX.cpp
📚 Learning: 2025-08-26T11:51:21.817Z
Learnt from: DedeHai
PR: wled/WLED#4798
File: wled00/FX.cpp:7531-7533
Timestamp: 2025-08-26T11:51:21.817Z
Learning: In WLED PR #4798, DedeHai confirmed that certain gamma-related calls in FX.cpp/FX_fcn.cpp/particle systems are intentional for effect-level shaping (e.g., brightness curves, TV sim, Pride 2015 pre-mix), distinct from final output gamma. Do not flag or remove these in future reviews; add comments when feasible to clarify intent.

Applied to files:

  • wled00/FX.cpp
🧬 Code graph analysis (1)
wled00/FX.cpp (1)
usermods/usermod_v2_animartrix/usermod_v2_animartrix.cpp (1)
  • SEGENV (64-76)
🔇 Additional comments (7)
wled00/FX.cpp (7)

3170-3177: Good call keeping positions as signed ints (per maintainer guidance).

Using signed ints for pos/topPos avoids unnecessary casts and overhead. Matches the preference noted by blazoncek.


3189-3192: Nice UX: reinit when power‑dot count changes.

Resetting on aux0 change keeps state consistent when the slider is moved.


3248-3257: Bounds-safe compact dots.

Guarding the i-1 write prevents underflow at index 0. Thanks for tightening this.


3292-3298: Power-dot draw uses in-bounds guard.

Casting pos to unsigned and checking < SEGLEN avoids OOB writes when dots are off-segment. Good.


3339-3357: Character draws now bounded.

The in-range checks around Pac‑Man and ghost positions prevent buffer corruption on transient -1/SEGLEN positions.


3364-3365: Effect metadata looks consistent.

Sliders/checks map correctly; default o1=1 (White dots enabled) matches the intended look post-gamma changes.


10888-10889: Pac-Man effect is only registered once. Search found a single addEffect(FX_MODE_PACMAN, …) call at FX.cpp:10988.

Copy link
Collaborator

@DedeHai DedeHai left a comment

Choose a reason for hiding this comment

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

Looks good in general, the formating needs some polishing, see review comments.
Test this with changed number of ghosts (hint: it wont work), also test if it looks ok to you on long strips of 1000+ LEDs, use peek preview if you do not have the hardware.

pacmancharacters_t *character = reinterpret_cast<pacmancharacters_t *>(SEGENV.data);

unsigned startBlinkingGhostsLED; // the first LED when the blue ghosts will start blinking
if (SEGLEN > 150)
Copy link
Collaborator

Choose a reason for hiding this comment

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

does this still look ok to you with 1000 or 2000 LEDs?

startBlinkingGhostsLED = SEGLEN/3; // for short strips, start blinking the ghosts when there is 1/3rd of the LEDs left

if (SEGENV.call == 0) {
for (int i = 0; i < 5; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

test with numghosts = 10

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