Skip to content

Refactor Enemy Processing Pipeline#166

Merged
candour merged 2 commits into
mainfrom
refactor-enemy-pipeline-8137139885773267720
May 18, 2026
Merged

Refactor Enemy Processing Pipeline#166
candour merged 2 commits into
mainfrom
refactor-enemy-pipeline-8137139885773267720

Conversation

@candour
Copy link
Copy Markdown
Owner

@candour candour commented May 18, 2026

I have refactored the core enemy processing pipeline in MainViewModel.kt to improve both performance and code simplicity.

Key improvements include:

  • Unified Pipeline: Combined disparate logic for transients (held enemies, expired effects) and enemy movement into a single handleEnemyPipeline method, reducing redundant iterations over the enemy list.
  • Batch State Updates: Introduced an EngineUpdateBatch mechanism to collect health losses, gold changes, and hex modifications. These are now applied to the GameState in a single batch, significantly reducing the overhead of immutable state copying.
  • Optimized Grab/Hold Mechanics: Replaced an O(N_tiles) search for held enemies with an efficient lookup map based on heldEnemyId, improving engine performance during ticks with many active stalls.
  • Improved Consistency: Addressed edge cases where released enemies would wait a frame before moving, and ensured that stall-based puddle tracking remains accurate even on permanently wet tiles.

A record of this architectural refactor has been added to fixes.md under REF-012.


PR created automatically by Jules for task 8137139885773267720 started by @candour

Summary by CodeRabbit

  • Refactor
    • Improved game loop efficiency through consolidated enemy and board state processing.
    • Enhanced consistency of enemy movement, status effects, and buff interactions.

Review Change Stack

Consolidated updateTransientState and handleEnemyMovement into handleEnemyPipeline.
Introduced EngineUpdateBatch to collect and apply state updates in batches, reducing GameState copies.
Optimized "held enemy" tracking by using a lookup map instead of grid iterations.
Ensured released enemies can move in the same frame and restructured puddle detection for accurate stat tracking.
Updated fixes.md with REF-012.

Co-authored-by: candour <4670475+candour@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

Warning

Rate limit exceeded

@candour has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 49 minutes and 7 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1041f4bf-012e-49bc-9d7d-4a0860c2f926

📥 Commits

Reviewing files that changed from the base of the PR and between 1560232 and 62ce7a1.

📒 Files selected for processing (1)
  • fixes.md
📝 Walkthrough

Walkthrough

Consolidated MainViewModel.kt enemy-tick processing by introducing EngineUpdateBatch to batch health loss and hex mutations, refactoring updateGame to use a new unified handleEnemyPipeline instead of separate transient and movement helpers, and removing the old updateTransientState method. Updated fixes.md to document the refactor.

Changes

Enemy Processing Pipeline Consolidation

Layer / File(s) Summary
EngineUpdateBatch data structure
app/src/main/java/com/messark/hawker/MainViewModel.kt
New private EngineUpdateBatch container collects per-tick enemy processing results: total health loss and hex state updates map.
updateGame pipeline reorganization
app/src/main/java/com/messark/hawker/MainViewModel.kt
updateGame refactored to compute expired transients inline, call handleEnemyPipeline with EngineUpdateBatch, apply batched health loss and hex mutations back to GameState; old updateTransientState helper removed.
handleEnemyPipeline implementation
app/src/main/java/com/messark/hawker/MainViewModel.kt
New consolidated pipeline replaces prior multi-function approach; handles held/enqueued enemy release, special behavior state transitions, Tiger Mom buffing, puddle slow with stall tracking, path-based movement and health loss, Tiger Mom buff action application.
Refactor documentation
fixes.md
Added REF-012 entry documenting enemy processing pipeline consolidation, batch optimization, and held-enemy tracking improvements.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • candour/towerpower#164: Overlapping refactor of MainViewModel's per-tick enemy processing pipeline and batched hex/stall update logic.
  • candour/towerpower#153: Both modify updateGame enemy-tick processing with puddle slow and special wet-hex behavior via behavior-based EnemyDefinition API.
  • candour/towerpower#125: Both refactor enemy movement logic including puddle slows and Tiger Mom buff targeting; this PR consolidates those flows into handleEnemyPipeline.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Refactor Enemy Processing Pipeline' directly and accurately summarizes the main change: consolidation of enemy processing logic into a unified pipeline with optimized batching and held-enemy tracking.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor-enemy-pipeline-8137139885773267720

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

Build Successful! 🚀

Download APK

Note: This link will be removed when the PR is closed.

Copy link
Copy Markdown
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 info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 52517a9e-bcca-4ea0-882b-a824ac75e173

📥 Commits

Reviewing files that changed from the base of the PR and between bfe5c7f and 1560232.

📒 Files selected for processing (2)
  • app/src/main/java/com/messark/hawker/MainViewModel.kt
  • fixes.md

Comment thread fixes.md Outdated
@candour candour enabled auto-merge (squash) May 18, 2026 22:29
@candour
Copy link
Copy Markdown
Owner Author

candour commented May 18, 2026

Align REF-012 date/status with actual merge timeline.

Line 47 currently logs REF-012 as 2026-07-10 and Resolved, but this PR is still open (created on May 18, 2026). Please use the actual pr creation date.

@google-labs-jules
Copy link
Copy Markdown
Contributor

Align REF-012 date/status with actual merge timeline.

Line 47 currently logs REF-012 as 2026-07-10 and Resolved, but this PR is still open (created on May 18, 2026). Please use the actual pr creation date.

Acknowledged. I've updated the date for REF-012 to 2026-05-18 and changed the status to 'In Progress' to align with the PR timeline.

Co-authored-by: candour <4670475+candour@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown

Build Successful! 🚀

Download APK

Note: This link will be removed when the PR is closed.

@candour
Copy link
Copy Markdown
Owner Author

candour commented May 18, 2026

@coderabbitai resolve

@candour candour merged commit 6d96c81 into main May 18, 2026
3 checks passed
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

✅ Actions performed

Comments resolved and changes approved.

@candour candour deleted the refactor-enemy-pipeline-8137139885773267720 branch May 18, 2026 23:11
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.

1 participant