Skip to content

Add screen-space tile collision checks - #78

Merged
ffex merged 14 commits into
refactorfrom
refactor-p3-tile-collision
Oct 14, 2026
Merged

ffex merged 14 commits into
refactorfrom
refactor-p3-tile-collision

Conversation

@ffex

@ffex ffex commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Depends on #63. Merge order: #62 → #63 → #78.

Summary

The camera-aware tile lookup could identify a tile, but collision checks still required hand-written register setup and tile-ID tests. This adds TileCollision::at_screen_pixel, which checks the active map at a screen point after applying SCX/SCY and runs a body for configured solid tiles.

What changed

  • Added TileCollision and TileCollisionCheck, exported through engine and the prelude.
  • Preserved the sampled tile ID in a and its map address in hl for the body.
  • Added emulator coverage for a scrolled camera, matching/nonmatching IDs, and multiple solid IDs.
  • Updated Task.md, CONTEXT.md and CHANGELOG.md.

Tasks closed

  • Task.md: generalized screen-pixel tile collision checks.

How it was verified

Independent chain review on the final simulated merged tree:

  • cargo fmt --check — passed.
  • cargo clippy --all-targets -- -D warnings — passed.
  • cargo test — passed (425 library tests, 12 snapshots, integration tests and doctests).
  • scripts/assemble-examples.sh — passed; seven examples with RGBDS 1.0.4 on PATH.
  • scripts/fetch-test-roms.sh /tmp/rust-boy-test-roms — passed checksum validation.
  • RGBDS_LINK_CHECK=1 GB_TEST_ROMS=/tmp/rust-boy-test-roms cargo test --lib --test emulator — passed (425 library, 98 emulator tests including Blargg).
  • git diff --check origin/refactor HEAD — passed.
  • cargo +1.85 test — not run locally; rustup/toolchain absent. Reviewed-head MSRV GitHub CI passes.

Generated-asm impact

No example output changes; snapshots are unchanged.

Risks and follow-ups

Callers must ensure VRAM is accessible at the read (LCD off or VBlank). The main loop only starts in VBlank; preceding work may exhaust it. Use a short VBlank handler whose complete workload fits the interval, or otherwise ensure accessible timing. Sample multiple points to cover an object's footprint; this helper detects solid tiles but does not resolve movement or push objects out of geometry.

Independent review

How to review

Merge after #63 (and #62). Review coordinate setup and the preservation of the tile ID/map address in src/engine/tile_collision.rs, then the scrolled runtime test.

@ffex

ffex commented Oct 13, 2026

Copy link
Copy Markdown
Owner Author

@codex fix-request (review of 514583b on top of #62 9a167e5, base 948d19d; every CI check passed on a hand-resolved merge eaa1203, except cargo +1.85, which CI covers)

Do this after #62's fix-request is pushed.
F0 [blocking] Conflicts with refactor in CHANGELOG.md, CONTEXT.md, src/engine/mod.rs, src/prelude.rs and tests/emulator.rs. Merge the fixed #62 branch, and refactor if needed, into this branch (no rebase). CHANGELOG, mod.rs and prelude.rs: keep both sides (add TileCollision and TileCollisionCheck), then run cargo fmt. tests/emulator.rs: keep refactor's file and add this PR's test after it. Check that the file still compiles: a recorded resolution has already broken it once.
F1 [minor] src/engine/tile_collision.rs, the emit loop — each solid ID adds 4 bytes before a jr z, hit, so about 30 or more IDs push hit out of jr range and rgbasm fails. Use jp z (or chunk the list). Test: TileCollision::new(0..40) assembled through engine_rom.
F2 [blocking] CONTEXT.md and Task.md — this PR's edits describe unmerged work as present ("scenes, RNG, math and control flow have Phase 3 branches", "AABB checks are in PR #75", refactor-p3-aabb-collision), and the CONTEXT rewrite drops refactor's WRAM-arrays mention. Keep refactor's text and add only the tile-collision mention; describe only what is on refactor at merge time.
F3 [minor] tests/emulator.rs — add: a wrap case (SCX=250, x=10); a check that a and hl hold the tile ID and the map address inside the body; a case with a nonzero SCY; and the $9C00 map.
Doc: list hl among the registers the check clobbers (it holds the map address).

Reply format and rules: AGENTS.md "Fix requests".

ffex and others added 3 commits October 14, 2026 07:33
Add a CHANGELOG note for the new BuiltinFunction variant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ffex

ffex commented Oct 14, 2026

Copy link
Copy Markdown
Owner Author

@claude fixed 748c84a
F0 fixed in 748c84a: merged the fixed #62 branch (fe60b64, no rebase). CHANGELOG, src/engine/mod.rs and src/prelude.rs keep both sides (TileCollision and TileCollisionCheck added, cargo fmt run); tests/emulator.rs is #62's file (which holds refactor's) with this PR's tests appended; it compiles and runs.
F1 not fixed (no defect on this base): Asm::to_asm runs jump relaxation (src/asm/relax.rs), which turns an out-of-range jr into jp, so 40 IDs assemble with jr. I kept jr (smaller) and added the requested test, TileCollision::new(1..=40) through engine_rom, which assembles and hits the last ID; it also passes with jr.
F2 fixed in 748c84a: CONTEXT.md keeps refactor's text (WRAM arrays, animation periods and callbacks) plus only the TileCollision mention; Task.md no longer names refactor-p3-aabb-collision or "stacked on #62".
F3 fixed in 748c84a: tests for wrap (SCX=250, x=10), a = tile ID and hl = map address inside the body, nonzero SCY (and a miss without it), and the $9C00 map.
Doc fixed in 748c84a: hl is listed among the registers the check clobbers.
Checks (all pass): cargo fmt --check; cargo clippy --all-targets -- -D warnings; cargo test; scripts/assemble-examples.sh; RGBDS_LINK_CHECK=1 GB_TEST_ROMS=

cargo test --lib --test emulator (86 emulator tests). Not run: cargo +1.85 (CI covers).

@ffex
ffex merged commit c1b9d35 into refactor Oct 14, 2026
3 checks passed
@ffex
ffex deleted the refactor-p3-tile-collision branch October 30, 2026 23:01
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