Language…
12 users online: bblid, chester_fields, Children's Digest 1950-2009, Coockie1173, gui, HeitorPorfirio2006, Kezcade, Khastvrokg, Mr. MS, Saela, schema_tuna, SuperMarioDs64 - Guests: 111 - Bots: 196
Users: 57,121 (2,260 active)
Latest user: Notsammyr

Optimized Spotlight

SMW Patches → Optimized Spotlight

Submission Details

Name: Optimized Spotlight
Author: yoshifanatic
Added:
Tool: Asar
Requires Free Space: No
Bug Fix: Yes
Featured: No
Description: The spotlight sprite is one of the most demanding sprites in SMW, being so performance intensive that the devs had to update it every 4 frames just to minimize slowdown, even when the spotlight is off. In addition, for no real reason, this sprite uses $001472-$001486 as scratch RAM even though all of those could easily just be $00-$0F and/or sprite RAM tables. While the SA-1 patch helps a lot, it doesn't change the fact that the spotlight's code is trash.

This patch significantly improves the performance of the spotlight by not just optimizing the HDMA buffer loop, but also by only updating the even/odd scanlines on a given frame. The result is the spotlight now has ~40% of the performance impact it originally had (~95-99% when the spotlight is off), to the point where non-SA-1 ROMs can update it at 60FPS without costing an arm and a leg's worth of CPU time. The only tradeoff being a negligible difference in the spotlight window's appearance and the fact it takes an extra frame to fully turn on/off.

In addition, this patch includes a define that makes the spotlight use the on/off switch rather than the light switch sprite, since sprite C8 has no reason to exist and just wastes more processing time when its on screen.

Requires no freespace.

Note: The below .gifs were recorded on an otherwise clean SMW ROM with only BMF54123's CPU meter patch applied to it. No Lunar Magic hijacks, no SA-1, and no FastROM.
Tags: lorom sa-1
Comments: 6 (jump to comments)
Download 1.97 KiB | 105 downloads

Screenshots

View all

Comments (6)

yoshifanatic Author Link
Originally posted by MarioFanGamer
Moderated with:
  • Lunar Magic v3.31
  • SA-1 Pack v1.40
  • Asar 1.81
  • BSNES v115
The overuse of defines and their long names make it very hard to read your code!

Aside from that, as I commented for last C3, this is quite an improvement for what SMW is doing. Futhermore, the interlacing even has got a certain charm in the sense that whenever you activate and disable the spotlight, the light doesn't turn on instantly but with a small transition.

Note for users: The On/Off dependent spotlight is activate by default given that this is how the default switch state.


Thanks for moderating my patch!

About the amount of defines, this patch was originally code that was directly integrated into my MYSQ source code. As such, it's set up to be trivial to integrate directly into my SMW disassembly. As for the long names, I name my defines in a way that leaves as little ambiguity as possible as to their scope and purpose. It does create a lot of redundancy, but I'd rather have that than mixing up constant defines with RAM defines or having to decipher potentially dozens of alphabet soup define names if I come back to a project later. Plus, the define naming scheme I use helps in other ways, like making it easier for me to import code from any of the SNES games I've disassembled.

Also, fun fact, but before settling on the interlacing, I tried a few other ideas for trying to improve the spotlight performance. For example, cutting the vertical resolution in half by duplicating scanlines. But they ended up either not working very well or just made the spotlight look ugly. The nice thing about the solution I went with is that the optimized spotlight looks almost indistinguishable from the original unless you look closely at the edges. That transition from turning the light on/off is also a nice little side effect of the way I implemented this, as with the right video filter, those scanlines can be blended together to make it look like the light is dimming on those frames.
 MarioFanGamer Link
Moderated with:
  • Lunar Magic v3.31
  • SA-1 Pack v1.40
  • Asar 1.81
  • BSNES v115
The overuse of defines and their long names make it very hard to read your code!

Aside from that, as I commented for last C3, this is quite an improvement for what SMW is doing. Futhermore, the interlacing even has got a certain charm in the sense that whenever you activate and disable the spotlight, the light doesn't turn on instantly but with a small transition.

Note for users: The On/Off dependent spotlight is activate by default given that this is how the default switch state.
Final Theory Link
Excellent work!
HammerBrother Link
yoshifanatic
Originally posted by yoshifanatic
Originally posted by HammerBrother
Does this also frees up 1486 bytes of $001472-$001486?


It frees up the 20 bytes of RAM at $001472-$001486. Those RAM addresses have been mapped to either $00-$0F or various normal sprite RAM tables.


Uhh, just downloaded the files, and saw this description:
Quote
Code
$001472-$001486


I think you are off by 1, because:
Code
Line 1  : $1472
Line 2  : $1473
Line 3  : $1474
Line 4  : $1475
Line 5  : $1476
Line 6  : $1477
Line 7  : $1478
Line 8  : $1479
Line 9  : $147A
Line 10 : $147B
Line 11 : $147C
Line 12 : $147D
Line 13 : $147E
Line 14 : $147F
Line 15 : $1480
Line 16 : $1481
Line 17 : $1482
Line 18 : $1483
Line 19 : $1484
Line 20 : $1485
Line 21 : $1486


To count how many bytes when given a range of address, assuming the range is inclusive (includes the min and max address), it is NumberOfBytes = EndingAddress - StartingAddress + 1

(I use my own tool to find ranges and the number of bytes).
yoshifanatic Author Link
Originally posted by HammerBrother
Does this also frees up 1486 bytes of $001472-$001486?


It frees up the 20 bytes of RAM at $001472-$001486. Those RAM addresses have been mapped to either $00-$0F or various normal sprite RAM tables.
HammerBrother Link
Does this also frees up 1486 bytes of $001472-$001486?