From 6aecbd13e7ce17c539410808dac39b15ff3982ee Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 1 Feb 2026 17:22:02 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Palette:=20Improve=20game=20resp?= =?UTF-8?q?onsiveness=20and=20UI=20cleanliness?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Refactor game loop in src/main.cpp to use poll() with dynamic timeout. - Trigger immediate display updates on user input for better tactile feedback. - Clean up terminal output by integrating mode status into the score line. - Fix broken Rust CI by replacing it with a C++ workflow using make. - Add 'test' target to Makefile for automated verification. Co-authored-by: aidasofialily-cmd <247843425+aidasofialily-cmd@users.noreply.github.com> --- .Jules/palette.md | 4 ++++ .github/workflows/{rust.yml => build.yml} | 10 +++------- Makefile | 6 +++++- src/main.cpp | 24 +++++++++++------------ 4 files changed, 24 insertions(+), 20 deletions(-) rename .github/workflows/{rust.yml => build.yml} (65%) diff --git a/.Jules/palette.md b/.Jules/palette.md index 01736b2..1d98d00 100644 --- a/.Jules/palette.md +++ b/.Jules/palette.md @@ -6,3 +6,7 @@ ## 2026-01-09 - Terminal I/O and Blocking **Learning:** Standard terminal I/O is line-buffered by default. For real-time games, it's essential to use non-canonical mode (raw mode) to capture keypresses immediately. Also, internal journals should be kept clean if they are to be included in the repo. + +## 2026-01-10 - Tactile Feedback in CLI +**Learning:** For terminal-based interactions, immediate UI updates upon keypress are crucial for "tactile" feel. Decoupling display updates from fixed game ticks and using `poll()` with dynamic timeouts provides a much smoother experience than busy-waiting or fixed sleep intervals. +**Action:** Always trigger a UI refresh immediately after processing user input in CLI games. diff --git a/.github/workflows/rust.yml b/.github/workflows/build.yml similarity index 65% rename from .github/workflows/rust.yml rename to .github/workflows/build.yml index 9fd45e0..3987633 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Rust +name: C++ Build on: push: @@ -6,17 +6,13 @@ on: pull_request: branches: [ "main" ] -env: - CARGO_TERM_COLOR: always - jobs: build: - runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Build - run: cargo build --verbose + run: make - name: Run tests - run: cargo test --verbose + run: make test diff --git a/Makefile b/Makefile index 3bf8240..e3ec248 100644 --- a/Makefile +++ b/Makefile @@ -25,5 +25,9 @@ run: $(TARGET) clean: rm -f $(TARGET) +# Test the game +test: $(TARGET) + echo "q" | ./$(TARGET) | grep "Final Score" + # Phony targets -.PHONY: all run clean +.PHONY: all run clean test diff --git a/src/main.cpp b/src/main.cpp index a70e887..9710519 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -19,21 +20,20 @@ int main() { struct pollfd fds[1] = {{STDIN_FILENO, POLLIN, 0}}; auto last_tick = std::chrono::steady_clock::now(); while (true) { - int timeout = hardMode ? 100 : 1000; - if (poll(fds, 1, 0) > 0) { - if (read(STDIN_FILENO, &input, 1) <= 0 || input == 'q') break; - if (input == 'h') { - hardMode = !hardMode; - std::cout << (hardMode ? "\n[HARD MODE] Speed x10!\n" : "\n[NORMAL MODE]\n"); - } else score++; - } auto now = std::chrono::steady_clock::now(); auto elapsed = std::chrono::duration_cast(now - last_tick).count(); - if (elapsed >= timeout) { - score++; last_tick = now; - std::cout << "Score: " << score << (hardMode ? " [FAST] " : " [NORMAL] ") << "\r" << std::flush; + int period = hardMode ? 100 : 1000; + int timeout = std::max(0, period - static_cast(elapsed)); + + if (poll(fds, 1, timeout) > 0) { + if (read(STDIN_FILENO, &input, 1) <= 0 || input == 'q') break; + if (input == 'h') hardMode = !hardMode; + else score++; + } else { + score++; + last_tick = std::chrono::steady_clock::now(); } - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + std::cout << "Score: " << score << (hardMode ? " [FAST] " : " [NORMAL] ") << "\r" << std::flush; } tcsetattr(STDIN_FILENO, TCSANOW, &oldt); std::cout << "\nFinal Score: " << score << "\nThanks for playing!\n";