don't click here

Sonic Background Scrolling Screensaver

Discussion in 'Engineering & Reverse Engineering' started by MainMemory, May 16, 2015.

  1. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,733
    330
    63
    SonLVL
    One day, I was thinking about SonLVL and wondering if I could use it to recreate the backgrounds from Sonic levels, complete with scrolling and animations. As it turns out, I could. So I decided to make a screensaver out of it, because it seemed like the best thing to do, I guess. And then, since I had the SMPS music player for Sonic & Knuckles Collection set up so it could be used by other programs, I decided to throw that in too.

    When first running the screensaver, you will have to configure it by right clicking and choosing the "Configure" option (or using the /c argument on the command line). You can choose whether or not to play music, the volume of the music (in percent, 0 to 1000, default 100), the number of frames per second (1 to 60, default 30), the speed to scroll at (-64 to 64, default 8), which levels to show and what order to show them in, and the amount of time to display each level for (hours:minutes:seconds:centiseconds, default 5 minutes).

    It is important to not install the screensaver by copying it into the system32 folder as is common practice, instead you should right click the file and select "Install".

    When running the screensaver, there are a few keyboard commands that will perform actions other than closing the screensaver: W toggles water when applicable, M toggles music, N jumps to the next level, up/down shift the camera up or down, and left/right increase or decrease the scroll speed.

    Here is the main part: Download
    .NET 3.5 is required, and MSVC 2010 redist if you want music. The screensaver will run on Linux, but without music.

    And the levels available so far are:

    The source code is on Sonic Retro's GitHub if you want to see how it works or contribute to development. Tech Members have access by default, anyone else may contact me for access.

    Before you all start requesting levels, keep in mind that I have to port all these by hand. I'm mostly familiar with Sonic 2, Sonic 1 I can barely understand the disassembly, Sonic CD has no disassembly (also music), Sonic 3 & Knuckles not only is poorly documented in the scrolling area, but it also has a lot of fancy tricks used to create the illusion of more layers, I could try to make them into actual layers, but I'd need some way to get full images for all the different "layers" (a similar thing applies to HTZ). Some levels have lots of animated tiles and I'm not sure how to handle that yet, I've got some ideas, I might have to try Metropolis Zone and see what works best. Levels from other games or different things entirely are possible, but I'm not likely to do it myself.

    If you look at the source code for each level, you can see that S2HPZ is closely emulating the original 68000 instructions, while LZ and EHZ are more high level but still producing identical results.

    About the framerate, I chose 30fps as the default because that's what works on my computer with minimal stuttering, and a graphics card isn't much help here, all the rendering is done in software, using a combination of my own 8bpp bitmap code from SonLVL and GDI+. If anyone has ideas for optimization, that would help a lot, possibly with SonLVL too.

     
    Last edited: Jun 3, 2023
  2. JansenM

    JansenM

    Member
    123
    20
    18
    Devon, UK
    Generations mods
    Brill! Functionality's top notch and it's really easy to get running.

    [​IMG]

    Only seems to work on two outside of Eyefinity, but that may be something to do with my DVI output. Other screen savers have no issue spanning across all three though, so it may be something to look into.

    Might I suggest tweaks to the Labyrinth/Scrap Brain backrounds' behaviour? I'm not sure if it's more faithful to the games as is, but the difference in speed due to the background being on a closer plane than the others is very jarring - Emerald Hill's pretty peaceful and Hidden Palace's depth works very well, but then you just have a wall zooming past a lot more excitedly than the other two. It's not fatal, but the inconsistency can be distracting.
     
  3. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,733
    330
    63
    SonLVL
    Apparently WinForms has an issue with setting negative coordinates in the form's constructor. I moved some code around and fixed the issue.

    I also cut LZ's scrolling speed in half, hopefully it should be okay now. The original game actually reduces it even more, but then it hardly moves at all.
     
  4. MarkeyJester

    MarkeyJester

    Original, No substitute Resident Jester
    2,188
    398
    63
    Japan
    Oh my! This is simply divine! + - (there, you happy now?).  

    Very impressive, I finally have a screen saver worth having... The source code availability is also a plus side, I think I might just add Starry Night Zone to it!
     
  5. Overlord

    Overlord

    Now playable in Smash Bros Ultimate Moderator
    19,214
    956
    93
    Long-term happiness
    Awesome stuff, have installed it and I think I'll be using it, even though there's noticible frame drops. That's more my PC being poor than anything.

    If nothing else, you now have confirmation it works properly from someone who has a dual monitor setup of both a portrait and a landscape monitor =P
     
  6. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,733
    330
    63
    SonLVL
    I've added a new Generic.dll file to the main download package, which can be used to make backgrounds without any programming.
    Just make a setup.ini file like the other levels have with "file=../Generic.dll" and "type=Generic.Generic", then you can either provide SonLVL-like level data settings, or a paletted bitmap file as an "image" setting.
    Then you can provide scroll speeds for each line in the image with "hscroll#" lines (above the [Level] group if you're using that) where # is the line starting at 0, and the value is a floating-point number that the camera's position is multiplied by (ie hscroll0=0.5 means line 0 scrolls at 1/2 the camera speed). If you don't have settings for all the lines, they will wrap around to the beginning of the list (so if you only have hscroll0, every line will scroll at the same speed).

    Here's an example:
    Code (Text):
    1. file=../Generic.dll
    2. type=Generic.Generic
    3. name=Generic Level
    4. music=S3Continue
    5. hscroll0=2
    6. hscroll1=0.5
    7. hscroll2=-1
    8. hscroll3=0
    9. version=S2
    10. [Level]
    11. tiles=art.bin
    12. blocks=blocks.bin
    13. chunks=chunks.bin
    14. layout=layout.bin
    15. palette=SonicAndTails.bin:0:0:16|palette.bin:0:16:48
    16.  
     
  7. Tets

    Tets

    one rude dude Oldbie
    903
    70
    28
    Neat! I haven't been this enthused by a screensaver since the Earthbound battle background screensaver was released years ago. All I could ask for is an option to scale up the graphics, but it's pretty slick as is.
     
  8. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,733
    330
    63
    SonLVL
    What kind of scaling? Nearest-neighbor? HQ#X? xBRZ? Something else? I can only do so much processing on the image in the time each frame lasts.
     
  9. Infiniti

    Infiniti

    ↑ & ↓ & ↻ Member
    476
    0
    0
    UK
    Oh I can think of another...
    This really is amazing! I'd be keen to see Sky Chase or Death Egg converted. For now, I'll keep it on the Labyrinth.
     
  10. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,733
    330
    63
    SonLVL
    Sky Chase is problematic, in that it was clearly designed for a 224 pixel tall screen. In order to make backgrounds work as a screensaver, they have to be able to tile horizontally, and either tile or extend with a solid color vertically. Also, which Death Egg? The only one I can see working well is S2's.
     
  11. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,733
    330
    63
    SonLVL
    I've added Death Egg Zone (Sonic 2), and updated the screensaver to fix a freeze when pressing the N key with only one level loaded.

    Edit: I've modified the Generic DLL so that any line numbers missing from the hscroll list will copy from the line that was defined last, so hscroll0=5 and hscroll20=4 will set lines 0-19 at speed 5 and line 20 at speed 4.

    Edit2: Mushroom Hill Zone, first S3K level, first multi-layered level, first level not ported from a disassembly.
     
  12. Tets

    Tets

    one rude dude Oldbie
    903
    70
    28
    Nothing quite that expensive, more like simple upscaling by integer factors. Say I wanted to just double the size of each pixel, or triple it, and so forth.

    On a different note, the MHZ background looks awesome at 1080p. Certainly no need to upscale that.
     
  13. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,733
    330
    63
    SonLVL
    I tried adding scaling to EHZ, and even at just 2x scale, the framerate dropped massively. I would have to come up with a much faster scaling method than the one SonLVL has currently and the one GDI+ gives me.

    Edit: Casino Night Zone
     
  14. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,733
    330
    63
    SonLVL
    Mushroom Hill Zone has been updated to add a fourth "All Seasons" mode, which cycles through the three color palettes with a configurable delay and fade length in frames. If you want to go back to the "Early Fall" palette after the "Late Fall" palette, you can just add a copy of the palette2 line as palette4.
     
  15. Tets

    Tets

    one rude dude Oldbie
    903
    70
    28
    Fair enough. I was afraid that might be the case, but I can't really complain in the end.
     
  16. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,733
    330
    63
    SonLVL
    I updated MHZ to fix a bug with negative scroll values, and I updated the main download with some functions MHZ needs to run.
     
  17. LordOfSquad

    LordOfSquad

    bobs over baghdad Member
    5,183
    229
    43
    Winnipeg, MB
    making cool music no one gives a shit about
    This is great, I've been looking for a new screensaver and this fits the bill handily. Works great on my multi-monitor setup as well. Thanks much!
     
  18. Pexs

    Pexs

    Otherwise known as Spex Member
    This is super cool.

    All of the Sonic 2 levels only work on one of my screens though. I have a monitor hooked up to my laptop, and the scrolling only shows on the monitor. The laptop gets a solid colored background, blue for EHZ, black for CNZ.

    All in all though, still way past cool. Nice work.
     
  19. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,733
    330
    63
    SonLVL
    EHZ and CNZ really only work if all the screens' bottoms are aligned. I don't know why DEZ or HPZ wouldn't work though.
     
  20. Hitaxas

    Hitaxas

    Retro 80's themed Twitch streamer ( on hiatus) Member
    What about custom SMPS? I've looked inside Songs.ini and the file paths it points to don't exist anywhere for some reason, which I find odd...