Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize graphx clipping logic #513

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

calc84maniac
Copy link
Contributor

@calc84maniac calc84maniac commented Nov 7, 2024

Reworks sprite clipping to use range-based (unsigned) comparisons instead of signed comparisons, and also moves shared pointer calculation logic into the clipping routine. Additionally, logic is added to gfx_SetClipRegion to apply SMC to all clipping routines. This saves 178 215 bytes overall, and I measured the following changes in cycle counts for gfx_Sprite (up until the gfx_Wait for drawn sprites, or through the return for culled sprites):

fully onscreen: 1177 -> 716 644

clipped top: 1450 -> 860 772
clipped left: 1488 -> 864 780
clipped right: 1254 -> 756 684
clipped bottom: 1202 -> 744 672

clipped top left: 1761 -> 1008 908
clipped top right: 1527 -> 900 812
clipped bottom left: 1513 -> 892 808
clipped bottom right: 1279 -> 784 712

clipped left+right: 1565 -> 863 779
clipped top+bottom: 1475 -> 859 767
clipped top+left+right+bottom: 1863 -> 1006 902

culled top: 471 -> 370 334
culled left: 803 -> 540 468
culled right: 776 -> 540 468
culled bottom: 474 -> 370 334

I'll probably take a look at gfx_RLETSprite later and add it to this PR if I can improve it.

@calc84maniac
Copy link
Contributor Author

While updating all clipped routines to use SMC, I found and fixed two bugs in flood fill clipping, the first being that X clipping on the left was always treated as 0, and the second being that X clipping on the right was off by one (treating the upper bound as inclusive instead of exclusive).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant