Refactor GameBoard Rendering Architecture#171
Conversation
- Implemented explicit rendering passes for Background, Decals, World, and Foreground layers as per AGENTS.md. - Replaced the high-allocation `DrawableEntity` logic with a zero-allocation pooled `WorldItem` system. - Optimized depth sorting in the World layer using a singleton `WorldItemComparator` on pooled entities. - Consolidated ground-level decals and overhead effects into their respective layers. - Updated `fixes.md` with REF-014 to document the architectural improvement. Co-authored-by: candour <4670475+candour@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
📝 WalkthroughWalkthroughGameBoard.kt's rendering pipeline was refactored from deferred DrawableEntity + sorted drawables to explicit layered direct rendering: background, decals, pooled/sorted world entities, and foreground. Projectile interpolation, selection/range indicators, and upgrade badges moved into direct foreground drawing. A changelog entry (REF-014) was added. ChangesGameBoard Rendering Architecture Refactor
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Build Successful! 🚀Note: This link will be removed when the PR is closed. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
app/src/main/java/com/messark/hawker/ui/components/GameBoard.kt (2)
141-146: ⚡ Quick winSorting is missing the
zOrdertiebreaker betweenrandq.The comparator sorts by
rthen directly byq, but coding guidelines specify sorting byr, thenzOrder, thenqfor correct isometric depth. WithoutzOrder, entities of different types at the same row (e.g., a stall and enemy at similarr) may render in incorrect depth order.Consider adding a
zOrderfield toWorldItemand updating the comparator:Suggested approach
private class WorldItem { var q: Float = 0f var r: Float = 0f + var zOrder: Int = 0 var type: WorldItemType = WorldItemType.PILLAR // ... } private object WorldItemComparator : Comparator<WorldItem> { override fun compare(a: WorldItem, b: WorldItem): Int { val rComp = a.r.compareTo(b.r) - return if (rComp != 0) rComp else a.q.compareTo(b.q) + if (rComp != 0) return rComp + val zComp = a.zOrder.compareTo(b.zOrder) + return if (zComp != 0) zComp else a.q.compareTo(b.q) } }Then assign appropriate
zOrdervalues when populating items (e.g., PILLAR=0, STALL=1, ENEMY=2).As per coding guidelines: "Sort World layer entities (zOrder group 2) strictly by axial r (row) coordinate, then by zOrder, then by q (column) for correct isometric depth".
333-344: 💤 Low valueSilent pool exhaustion may cause entities to disappear without warning.
If
poolIdxreaches 512, additional world entities are silently dropped and won't render. While 512 is likely sufficient for typical gameplay, edge cases (large maps, many enemies) could trigger this.Consider adding a debug assertion or log to surface this during development:
Suggested addition
enemies.forEach { enemy -> if (poolIdx < worldItemPool.size) { val item = worldItemPool[poolIdx++] item.set(enemy.position.q, enemy.position.r, WorldItemType.ENEMY, null, null, enemy, ctx.toScreenPrecise(enemy.position.q, enemy.position.r)) activeWorldItems.add(item) + } else { + // Log.w("GameBoard", "WorldItem pool exhausted, dropping entity") } }Also applies to: 348-352
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7ccc8319-dbad-4284-9408-b8bf10df0501
📒 Files selected for processing (2)
app/src/main/java/com/messark/hawker/ui/components/GameBoard.ktfixes.md
|
Sorting is missing the zOrder tiebreaker between r and q. The comparator sorts by r then directly by q, but coding guidelines specify sorting by r, then zOrder, then q for correct isometric depth. Without zOrder, entities of different types at the same row (e.g., a stall and enemy at similar r) may render in incorrect depth order. |
|
If poolIdx reaches 512, additional world entities are silently dropped and won't render. While 512 is likely sufficient for typical gameplay, edge cases (large maps, many enemies) could trigger this. Consider adding a debug assertion or log to surface this during development: |
Good catch. I've updated the |
- Updated `WorldItem` to track `zOrder`. - Modified `WorldItemComparator` to sort by `r`, then `zOrder`, then `q`. - Updated `fixes.md` to reflect the refined sorting logic. Co-authored-by: candour <4670475+candour@users.noreply.github.com>
Build Successful! 🚀Note: This link will be removed when the PR is closed. |
|
Silent pool exhaustion may cause entities to disappear without warning. If poolIdx reaches 512, additional world entities are silently dropped and won't render. While 512 is likely sufficient for typical gameplay, edge cases (large maps, many enemies) could trigger this. |
Good point. I've added a Log.w warning that triggers once per frame if the pool is exhausted. This should make it obvious during development if we need to increase the pool size, while maintaining the zero-allocation performance goals. |
- Added `android.util.Log.w` warning when the pre-allocated entity pool is exhausted. - Ensured `poolIdx` continues to increment to correctly trigger the warning only once per frame. Co-authored-by: candour <4670475+candour@users.noreply.github.com>
Build Successful! 🚀Note: This link will be removed when the PR is closed. |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b45f31ad-2af4-4044-add9-5aae91ef2c9d
📒 Files selected for processing (2)
app/src/main/java/com/messark/hawker/ui/components/GameBoard.ktfixes.md
✅ Files skipped from review due to trivial changes (1)
- fixes.md
This PR refactors the core rendering loop in
GameBoard.ktto significantly improve performance and maintainability.Key changes include:
DrawableEntityobjects and captured lambdas in theonDrawloop. Instead, a pre-allocated pool ofWorldItemobjects is used to collect and sort world entities.Comparator, reducing the complexity and overhead of sorting all drawables together.AGENTS.md.These changes reduce garbage collection pressure on the UI thread and ensure correct isometric depth rendering across all entity types.
PR created automatically by Jules for task 4478512731080798057 started by @candour
Summary by CodeRabbit