Skip to content

Addressing PR comments - #76

Merged
28pins merged 8 commits into
mainfrom
claude/improve-code-efficiency
Mar 7, 2026
Merged

Addressing PR comments#76
28pins merged 8 commits into
mainfrom
claude/improve-code-efficiency

Conversation

@Claude

@Claude Claude AI commented Mar 7, 2026

Copy link
Copy Markdown

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Claude AI and others added 3 commits March 7, 2026 16:21
…optimize ISR, extract game loop helper

Co-authored-by: 28pins <262898015+28pins@users.noreply.github.com>
Co-authored-by: 28pins <262898015+28pins@users.noreply.github.com>
…ines to 11)

Co-authored-by: 28pins <262898015+28pins@users.noreply.github.com>
@Claude Claude AI changed the title [WIP] Identify and improve slow or inefficient code segments Optimize code efficiency: reduce duplication, simplify complex logic, improve maintainability Mar 7, 2026
@28pins

28pins commented Mar 7, 2026

Copy link
Copy Markdown
Owner

@copilot undo everything in the Gamer lib except the showsScore work

Copilot AI commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

@copilot undo everything in the Gamer lib except the showsScore work

Done. Reverted all Gamer lib changes (capacitive touch loop, ISR consolidation, updateDisplay optimization) back to original, keeping only the removal of the duplicate showScore() from Gamer.cpp and its declaration from Gamer.h. Note: the push is being blocked by a branch protection rule on this branch — you may need to adjust the repository rules to allow the push.

@28pins

28pins commented Mar 7, 2026

Copy link
Copy Markdown
Owner

@claude[agent] undo everything in the gamer lib minis the show score bit

Co-authored-by: 28pins <262898015+28pins@users.noreply.github.com>
@Claude

Claude AI commented Mar 7, 2026

Copy link
Copy Markdown
Author

@claude[agent] undo everything in the gamer lib minis the show score bit

Done. Reverted all Gamer library optimizations back to original except for the showScore removal. The three optimizations (ISR consolidation, capTouch loop, and updateDisplay optimization) have been restored to their pre-optimization state. Commit: 15c47a6

@Claude Claude AI changed the title Optimize code efficiency: reduce duplication, simplify complex logic, improve maintainability Addressing PR comments Mar 7, 2026
@28pins
28pins marked this pull request as ready for review March 7, 2026 17:26
Copilot AI review requested due to automatic review settings March 7, 2026 17:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR focuses on addressing prior review feedback by reducing duplicated game-loop preamble code across games, while also refactoring parts of Breakout and removing a duplicated score-display API from the Gamer library.

Changes:

  • Added a shared updateGameInput() helper in TWSUGamerPlus.ino and updated multiple games to use it.
  • Refactored Breakout collision/bounce logic and simplified checkerboard block-propagation.
  • Removed Gamer::showScore(int) from the library, relying on the sketch-level score rendering instead.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
TWSUGamerPlus.ino Adds updateGameInput() helper used as a common loop preamble.
src/games/tetris.h Switches loop preamble to updateGameInput().
src/games/snake.h Switches loop preamble to updateGameInput() and keeps manual display clearing.
src/games/simon.h Switches loop preamble to updateGameInput().
src/games/flappy.h Switches loop preamble to updateGameInput() (but retains a redundant tone stop).
src/games/dino.h Switches loop preamble to updateGameInput().
src/games/conway.h Switches loop preamble to updateGameInput().
src/games/alien.h Uses updateGameInput() inside the movement-delay loop.
src/games/breakout.h Adds isFree() helper and refactors physics + block-propagation logic.
Gamer.h Removes showScore(int) from the public Gamer API.
Gamer.cpp Removes the Gamer::showScore(int) implementation.

Comment thread Gamer.h
Comment thread TWSUGamerPlus.ino Outdated
Comment on lines +49 to +54
// Common game loop preamble: check sound toggle, update LED flash, stop any tone
inline void updateGameInput() {
checkSoundToggle();
updateLEDFlash();
if (soundEnabled) gamer.stopTone();
}

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

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

updateGameInput() always calls gamer.stopTone() when sound is enabled. This will immediately cut off any sustained tones, and it breaks Tetris’ background melody logic (tetrisLoop plays a note then relies on it persisting until the next 200ms tick). Consider removing the unconditional stop here, or splitting the helper into two variants / adding a parameter so games like Tetris can opt out of stopping tones each frame.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@claude[agent] apply changes based on this feedback

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed. Added an optional stopTone parameter to updateGameInput() (defaults to true). Tetris now calls updateGameInput(false) to preserve its background melody. Also removed the redundant gamer.stopTone() in Flappy. Commit: d721906

Comment thread src/games/breakout.h
Comment on lines 17 to +24
bool outOfBounds(int xV, int yV) {
return (xV > 8 || xV < 0 || yV > 8 || yV < 0);
}

// Helper: checks if a position is free (LOW) and in bounds
inline bool isFree(int x, int y) {
return !outOfBounds(x, y) && gamer.display[x][y] == LOW;
}

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

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

outOfBounds() treats x/y == 8 as in-bounds (> 8), but valid indices for an 8×8 grid are 0–7. This can allow gamer.display[8][…] / blocks[8][…] access via helpers like isFree() and new physics calculations. Update the comparisons to use >= 8 (and similarly for y) to avoid out-of-range indexing.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@claude[agent] apply changes based on this feedback

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed. Changed outOfBounds() to use >= 8 (instead of > 8) and reordered the condition in physics() to check bounds before accessing the array. This prevents out-of-range indexing on the 8×8 grid. Commit: a80bbf3

Comment thread src/games/breakout.h
Comment on lines +30 to +32
// Check if we hit something at the next position
if(gamer.display[nextX][nextY] == HIGH || outOfBounds(nextX, nextY)) {
// Collision detected!

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

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

In physics(), gamer.display[nextX][nextY] is evaluated before checking outOfBounds(nextX, nextY). If nextX/nextY are out of range, this reads outside the 8×8 buffer. Reorder the condition to check outOfBounds(...) first (or use isFree()/a safe accessor) before indexing into gamer.display.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@claude[agent] apply changes based on this feedback

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Already fixed in commit a80bbf3. The condition was reordered to check outOfBounds(nextX, nextY) before accessing gamer.display[nextX][nextY], preventing out-of-range reads.

Comment thread src/games/flappy.h Outdated
checkSoundToggle();
updateLEDFlash();
updateGameInput();
if (soundEnabled) gamer.stopTone();

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

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

updateGameInput() already stops any tone when soundEnabled is true, so the extra if (soundEnabled) gamer.stopTone(); here is redundant. Removing the duplicate call will keep the loop preamble consistent and slightly reduce per-frame work.

Suggested change
if (soundEnabled) gamer.stopTone();

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…one in Flappy

Co-authored-by: 28pins <262898015+28pins@users.noreply.github.com>
Co-authored-by: 28pins <262898015+28pins@users.noreply.github.com>
@28pins
28pins merged commit 0048dd1 into main Mar 7, 2026
3 checks passed
@28pins
28pins deleted the claude/improve-code-efficiency branch March 11, 2026 16:40
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.

4 participants