don't click here

Sonic 2 Speedometer, Boost Meter, and Ring Finder

Discussion in 'Engineering & Reverse Engineering' started by Dr. D'nar, May 2, 2012.

  1. Dr. D'nar

    Dr. D'nar

    I wouldn't trust me if I were you Member
    Every so often, I like to show up and post something random. Today, I bring you a speedometer for Sonic 2. I wrote it as a Lua script for the Gens Recording fork (http://code.google.com/p/gens-rerecording/). For fun, I also threw in a boost meter for the spin dash and a ring finder. Most of the additional HUD elements this video shows are normally hidden unless you ask for them, but I turned that off for this demo video. You can find the Lua script at http://pastebin.com/8sDbWdxK. [New version for S2 and S3&K] The full documentation for the script is the source code's header. And the script is well-labeled and commented, so you should find it easy to find and delete the relevant parts of the code for any features you don't like, or move them around, or adjust them, &c.

    Here's a video of the script in action:
    [youtube]http://www.youtube.com/watch?v=SOJ-Moix6Fk&list=UUMrBexkDAu416p5oDHsSxXw&index=1&feature=plcp[/youtube]
     
  2. ICEknight

    ICEknight

    Researcher Researcher
    ...That's some amazing shit in there. :O


    I would have never ever expected anybody to put a ring radar in Sonic 2. Great work!
     
  3. redhotsonic

    redhotsonic

    Also known as RHS Tech Member
    1,587
    10
    18
    United Kingdom
    YouTuber
    Wow, that's very neat. The speedometre is the coolest there. Although, that ring finder is very handy for anyone looking for a perfect bonus. Good work!
     
  4. steveswede

    steveswede

    Member
    5,032
    1
    16
    Ask my hand
    Fighting against the Unitary State of Europe
    This is a very cool feature indeed.
     
  5. LocalH

    LocalH

    roxoring your soxors Tech Member
    Now figure out a way to do it without Lua *shot*

    Seriously, this is pretty cool. Lua is very powerful when it comes to integration with emulators, I've seen some equally impressive stuff for the NES (such as Xkeeper's drag-and-drop SMB1, among others).
     
  6. Dr. D'nar

    Dr. D'nar

    I wouldn't trust me if I were you Member
    Indeed. . . . I don't feel very motivated to implement this as an actual ROM hack, since I don't have a flash cart. I don't image it would be particularly difficult. If you include pre-rendered sprites for all the possible needle angles, you could entirely avoid doing the necessary trig in assembly. You would just do some division to find the right index into your table and copy the sprite to VRAM.

    New version with the code cleaned up a little, fixed typos, &c.

    On a tangentially-related note, I can't post this to the Wiki since my Wiki account is broken because my username has an apostrophe in it. It'd be nice if an admin could fix that.

    Notice that the ring-radar and speedometer are animated. While this may be useful to TASers, it's also supposed to be pretty. If only I had a better algorithm for drawing the meters. (They look really ugly if you try to use transparency.)
     
  7. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    The speedmeter and ring finder are look very nice. However, at least for TASing, I must say that my lua HUD is still unbeatable. You may want to look into it for other interesting timers to track; I know I will be copying your ideas about collision plane tracking and perfect bonus counter :v:.
     
  8. Knucklez

    Knucklez

    I love 2B 'n' ass. Member
    687
    21
    18
    The boost meter and ring finder aren't really necessary and if anything, they're eyesores IMO. The speedometer is a pretty neat feature though. It really adds to the whole speed thing about Sonic, so I'd love messing around with it to see the fastest I can make myself go.
     
  9. Ravenfreak

    Ravenfreak

    2 Edgy 4 U Tech Member
    3,091
    187
    43
    O'Fallon Mo
    Sonic 1 Game Gear Disassembly
    Wow this is pretty sweet. :) Do you have any plans on making this available for Sonic 1 and 3K? That'd be even cooler if you did. ^_^ And it'd be even more epic in a hack too. xP (But this is nice nonetheless of course.)
     
  10. Dr. D'nar

    Dr. D'nar

    I wouldn't trust me if I were you Member
    You, sir, have me truly outdone. At least, you do graphically. From what I've seen so far playing with, you don't show any S2 information I didn't have my script showing at one point. For example, I decided that the Tails AI timers and position indicator weren't particularly useful to me, since I don't actually make TAS videos. But I love the feature for disabling the original HUD.

    Since your script looks so much nicer, I'd love to see you absorb my features (just give me credit) as options in your script. Especially if you can make a better arc-drawing algorithm. (The best idea I've had is to render the graphic to a sort of back buffer so that pixels that are visited more than once don't actually result in multiple draws to that location.)

    That's why both automatically hide themselves. The video doesn't show the ring finder hiding in order to show off the tracking; in my script, you do Up+B to make it appear for two seconds.

    The script that flamewing posted below already does most everything I do, although without the analog meters. The ring finder cannot be ported as easily as the other features, since other Sonic games implement rings differently than Sonic 2 does. Nevertheless, I may give it a go in the next few weeks. It will require finding the current level's sprite table, parsing it, and cross-referencing the rings with the object respawn array.
     
  11. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    [quote name='Dr. D'nar' timestamp='1336034470' post='684002']You, sir, have me truly outdone. At least, you do graphically. From what I've seen so far playing with, you don't show any S2 information I didn't have my script showing at one point. For example, I decided that the Tails AI timers and position indicator weren't particularly useful to me, since I don't actually make TAS videos. But I love the feature for disabling the original HUD.[/quote]
    Most of the difference shows up on S3&K, now that I think about it.

    [quote name='Dr. D'nar' timestamp='1336034470' post='684002']The ring finder cannot be ported as easily as the other features, since other Sonic games implement rings differently than Sonic 2 does.[/quote]
    S1 rings are in-level objects; it is likely that doing a ring-finder for it will be quite annoying, at least for rings not yet loaded. S3&K rings are stored uncompressed in ROM, sorted from left to right, then top to bottom; there is a ring consumption table in RAM which marks rings as being taken.
     
  12. Hitaxas

    Hitaxas

    Retro 80's themed Twitch streamer ( on hiatus) Member
    Both lua scripts are awesome. Flamewings does not work with my hack, but I tried it out on stock s2, and it works well. D'nar, yours does work on my hack and even though the ring detector hides itself, it works despite the fact that I am using the s3k ring manager. :-)
     
  13. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    My script uses a whitelist-based approach to what hacks it supports because some elements are highly dependent on the game/hack in question: the specific RAM addresses and SST offsets depend on base game for example (and thankfully, most hacks keep RAM layout relatively unchanged from their base game), and the boss HUD and original HUD hiding portions hook ROM code execution at some points to do their thing. If the boss HUD/HUD hiding code is relatively unchanged in your hack, I can quickly add support for it on my script.

    I suppose I could add a limited functionality mode that asks for the base game type and disables the more involved functions.
     
  14. Hitaxas

    Hitaxas

    Retro 80's themed Twitch streamer ( on hiatus) Member
    For the most part, the ram and sst are the same, with the exception of 2 player mode and tails AI, which I removed in favor for some new features such as unlockable game play modes (different move sets based on different sonic games), the addition of extra characters, etc. The HUD code is untouched.

    I'll get you the games checksum when I can check it, don't remember it if the top if my head, and I am miles from my PC.
     
  15. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    More useful is a link to the hack: my script dumps the checksum to the console window so it is easier to add support for ROMs :v:
     
  16. Dr. D'nar

    Dr. D'nar

    I wouldn't trust me if I were you Member
    Update: I've completed Sonic 3 and Knuckles compatibility. http://pastebin.com/m5jrzGtD Next, of course, is Sonic 1 compatibility, but the information on S1 seems incomplete compared to S2 and S3&K.
     
  17. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    In S1, rings are objects -- object $25, to be precise -- and they are controlled by the object re-spawn table and the level object layout.
     
  18. Dr. D'nar

    Dr. D'nar

    I wouldn't trust me if I were you Member
    But how do they get their index into the respawn table?

    The Sonic 2 level started flag (F711) doesn't seem to work for Sonic 1.
     
  19. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    The entries in the object respawn table has to be computed by parsing the level's object data. Each entry in object data is 6 bytes long; bit 7 (the most significant bit) of the fifth byte (offset +4 from start of entry) indicates whether or not the object has an entry on object respawn. The first object with an object respawn entry has entry equal to 0; add 1 for each subsequent object. The actual object respawn entry for any given object is at $FFFFFC02 + object respawn entry; if bit 7 is set, the object has been destroyed/collected.