Skip to content

fix: resolve OBJ sprite-vs-sprite priority by OAM index - #71

Open
eduardovra wants to merge 2 commits into
mainfrom
fix/obj-sprite-priority-oam-index
Open

fix: resolve OBJ sprite-vs-sprite priority by OAM index#71
eduardovra wants to merge 2 commits into
mainfrom
fix/obj-sprite-priority-oam-index

Conversation

@eduardovra

Copy link
Copy Markdown
Owner

Problem

In Super Bomberman 5, the menu cursor (the bomberman head, OAM index 0, priority field 2) was drawn behind the character art (priority field 3).

On real SNES hardware, sprite-vs-sprite priority is decided purely by OAM index — the lowest-numbered object wins each pixel. The OAM priority field only chooses where that pixel sits relative to background layers, not relative to other sprites.

The renderer instead treated each OBJ priority level as a fully independent layer (draw all priority-0 sprites, then priority-1, …, each pass overwriting the last). So a high-index priority-3 sprite would overwrite a low-index priority-2 sprite — exactly the cursor bug.

Fix

Resolve the whole OBJ layer once per scanline by OAM index into per-line buffers (_obj_line_color / _obj_line_pri / _obj_line_layer), with the lowest-index sprite winning each pixel along with its priority bit. Each draw_objects(priority=N) pass then blits only the pixels whose owning sprite has that priority. The mode dispatcher's per-priority calls and BG interleaving are unchanged, so BG/OBJ layering is preserved. This also fixes same-priority sprite ordering (lowest index on top).

Tests

Added TestSpriteVsSpritePriority covering the cross-priority OAM-index rule (two overlapping sprites). All three new tests fail on the pre-fix code and pass with the fix.

Verified against the save state: the bomberman-head cursor now renders in front of the character, left of "NORMAL GAME". Full pysnes/ppu/ suite passes except two pre-existing Mesen-oracle BG failures (bg_4bpp, tile_flip) that also fail on main, unrelated to sprites.

Sprite-vs-sprite priority on the SNES is decided purely by OAM index —
the lowest-numbered object wins each pixel — while the OAM priority field
only selects where that pixel sits relative to BG layers. The renderer
instead treated each OBJ priority level as an independent layer, so a
high-index priority-3 sprite would overwrite a low-index priority-2
sprite. In Super Bomberman 5 this drew the menu cursor (bomberman head,
OAM index 0, priority 2) behind the character art (priority 3).

Resolve the whole OBJ layer once per scanline by OAM index into per-line
buffers (color/priority/layer), then have each draw_objects(priority=N)
pass blit only the pixels whose owning sprite has that priority. The mode
dispatcher's per-priority calls and BG interleaving are unchanged, so
BG/OBJ layering is preserved.

Add TestSpriteVsSpritePriority covering the cross-priority OAM-index rule.
- Remove draw_tiles, which has no callers after object drawing moved to
  _plot_obj (BG rendering lives in bg_renderer).
- Annotate cgram_cache and hoist the loop-invariant obj_cache lookup in
  _plot_obj.
- Rename draw_objects -> copy_obj_pixels_for_priority to reflect that it
  copies one priority's resolved OBJ pixels into the screen, and drop the
  now-redundant trailing priority comments at the dispatch sites.
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