fix: resolve OBJ sprite-vs-sprite priority by OAM index - #71
Open
eduardovra wants to merge 2 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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. Eachdraw_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
TestSpriteVsSpritePrioritycovering 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 onmain, unrelated to sprites.