don't click here

Labyrinth Zone and vertical scrolling

Discussion in 'General Sonic Discussion' started by Black Squirrel, Mar 11, 2016.

  1. Black Squirrel

    Black Squirrel

    no reverse gear Wiki Sysop
    8,585
    2,481
    93
    Northumberland, UK
    steamboat wiki
    Because I know you looked at my post in the Supreme Topic of Other Knowledge:

    [​IMG]

    The fun prototype of Sonic 1. With a higher resolution screenshot, we can see that the old background isn't so much "different" as it is entirely unfinished. There's a straight line cut-off. This explains why we have screenshots with seemingly no background - they're not two different builds, they're just highlighting the fact the background doesn't scroll vertically.

    Quite the oddity, because frankly the prototype background looks better than the final.
    [​IMG]
    It's more interesting, and seems to suggest multiple layers of parallax scrolling were intended. Otherwise it would look like garbage.


    But get this, on levels which can wrap vertically, there is only ever one background layer. You see it in Labyrinth Zone, and you see it in Scrap Brain Zone act 2 (and 3). For whatever reason, a fancier, pseudo 3D background effect couldn't be done. Maybe it was a design choice, but the final Labyrinth Zone background is hardly thrilling. A stumbling block for a young Yuji Naka?


    And question: did they give it another go?
    [​IMG]

    Hidden Palace Zone opts for a similar background design to the above prototype, and yet its layout suggests it was meant to have a vertical wrap-around. People have suggested it was the inclusion of water that ruined their dreams... but Labyrinth Zone Act 3 has water. Was it the parallax scrolling that killed it?

    Incidentally Metropolis Zone, the only Sonic 2 stage to have vertical wrap-around, also only uses one background layer. It doesn't appear they solved this issue until Sonic 3.
     
  2. Flygon

    Flygon

    Member
    If I may ask, what happens when ROM hackers attempt to implement more complex parallax scrolling backgrounds into the first two Sonic games?

    I recall fiddling around with this with a few friends a few years ago with Emerald Hill Zone, but I completely forgot the process. And the ROM was so bad that it actually caused an emulator to BSoD a PC. Still, it does have infinite vertical looping in Emerald Hill (which I think had parallax scrolling)... if you can find an emulator that doesn't crash booting it.
     
  3. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,742
    338
    63
    SonLVL
    I would point you towards Knuckles' Emerald Hunt, which features a vertical wrapping section in Hidden Palace Zone. However, in order to achieve that, the section in question had to disable the water, and the scrolling code for HPZ's background had to be modified by Flamewing.

    It should have been possible for them to have vertical wrapping in levels with complex scrolling backgrounds in S1 and S2. I suppose it's possible that nobody figured out a solution until S3, it might have been easier to just simplify the BG in LZ and HPZ could have gotten scrapped before any vertical wrapping was implemented.
     
  4. Tiberious

    Tiberious

    Yeah, I'm furry. Got a problem? Oldbie
    778
    15
    18
    Keep in mind also that it's only the beginning part of Labyrinth Zone Act 3 that wraps vertically, and there isn't any water in that section. Once you go through the section of wall that opens after you hit the switch, water is enabled, and the wrapping is disabled (the level chunk also changes back to close off the way back). In fact, you'll hear the 'object moving' sound when you reach that point.

    I'm not sure if you can use debug mode to go back, or what happens if you do, but it'll probably act really weird if it loops, unless they had the foresight to deactivate the water level again.
     
  5. Chibisteven

    Chibisteven

    Member
    1,364
    39
    28
    US
    You can use debug mode to go back and the water level stays the same. The vertical wrapping reactivates though.

    Hitting the same switch that opens the wall a second time causes the wall to stay open permanently.
     
  6. nineko

    nineko

    I am the Holy Cat Tech Member
    6,308
    486
    63
    italy
    Excuse me, but the climbing section during the boss fight in LZ3 features both Y-wrapping and rising water.
     
  7. LOst

    LOst

    Tech Member
    4,891
    8
    18
    I have been studying the wrapping system of Sonic for an extended time. The whole concept of wrapping is interesting, and both Sonic (last seen in Sonic 3 & Knuckles) and Mario (last seen fully achieved in New Super Mario DS, broken in Wii) failed to get around it without using hacks.

    For Sonic 1, the wrapping point is very buggy and causes deaths even in normal gameplay, especially LZ3 before the boss, but also if Sonic finds a way to walk up/jump in the beginning because there is no water slide. Scrap Brain 2 tries to use the wrapping only during teleport transport areas to extend the size of the level.

    Even late pre-release Sonic 1 must have been buggy (both collision and tile drawing) as shown in the Larry Cedar commercial:
    https://www.youtube.com/watch?feature=player_detailpage&v=jR98zOj0yiw#t=5

    And Sonic & Knuckles doesn't really solve wrapping. You already know about the camera wrapping around when looking down and jumping at the earliest frame. But here is also the background redraw bug from Sandopolis 2:
    https://www.youtube.com/watch?v=iYKefSi4148&feature=player_detailpage#t=1489

    EDIT:

    And the collision of several hitboxes don't work during wrapping as shown here:
    https://www.youtube.com/watch?feature=player_detailpage&v=8yIfuAqyJUQ#t=2272

    Sonic did get something right with wrapping though, and that is the collision code for solids. That means it would have worked to use that code for all collision tests, however the player is reset to be inside the map's dimension each frame causing the solid's collision to fail as well, similar to how Mario fails wrapping (Mario actually has to test collisions multiple times for one axis each frame for wors case scenario, which is almost always since collisions rarely happen, where Sonic only needed one test for one axis). Solution is: All objects must preserve their signs to make it work. The difference between two unsigned numbers is still the distance between them (wrapping is done unsigned, so the test value must be >= 0), but masking the number to stay within the map's coordinates (such as and.w #$7FFF,d0) will not keep the distance between them.


    I really like hearing more about wrapping and how it is implemented.
     
  8. Fred

    Fred

    Taking a break Oldbie
    1,563
    117
    43
    Portugal
    Sonic 3 Unlocked
    Uh, excuse me, but that isn't a "background redraw bug", it's a consequence of skipping key points in the rising sand sequence with the camera wrapping glitch you yourself mentioned, meaning the dynamic resize counter is still stuck in an low number and doesn't fix itself until you pass through a specific Y coordinate. It doesn't happen in normal play.
     
  9. LOst

    LOst

    Tech Member
    4,891
    8
    18
    Oh, cool. I never managed to activate this myself.

    Also wanted to thank you for your good Youtube videos!
     
  10. I don't know how wrapping is implemented in Sonic games, but if it was my engine, I'd simply allow coordinates to go past the physical map, but use bit masks when reading from the map in order to get "mirrors" of the actual map, much like happens with memory mirroring in a multitude of hardware architectures.

    Objects would also need to have their coordinates slightly manipulated when they were spawned, so that they could be placed into the correct mirrored sections of the level.

    Wrapping from 32767 to 32768 or from 65535 to 0 shouldn't need any special handling, as long as the sign bit (N flag) is used to compare coordinates (for collisions and such), instead of the carry flag. Any comparison between numbers that are less than 32768 units apart should result in a valid sign bit, and since only objects close to the camera are active at any given time, there's no way any 2 active objects will be that far apart.
     
  11. nineko

    nineko

    I am the Holy Cat Tech Member
    6,308
    486
    63
    italy
  12. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,742
    338
    63
    SonLVL
    Actually, in Sonic 1 and 2, objects are loaded in vertical strips, and all the objects within the strip are active, so it would be possible for that to occur, if not for the fact that Sonic levels are generally limited to $800 (2048) pixels in height, which makes wrapping a bit more involved than the scenario you present.
     
  13. Indeed, the solution I described was originally meant for an engine that limits the number of active objects vertically, so that when the camera reached the seam, objects at the opposite edge wouldn't be active anymore and could be activated in the mirrored section of the level.

    But even if all objects in a vertical strip are active at the same time, each object could simply track the camera, and once it got closer to where the object would be than to where it currently is, it would "teleport" to the new location. In other words, if the distance between the the object and the camera is larger than half the height of the level, it should move the full height of the level towards the camera.

    EDIT: As for spawning objects in this scenario, the naive approach would be to move new objects a full level's height at a time towards the camera until their relative distance was less than half the level's height, but that sounds slow, so there's probably a better way. One idea I just had exploits the fact that the new objects would be mapped to at most 2 mirrored sections of the level, meaning that some objects would go on the top mirror and some would go on the bottom mirror. To make the decision, all you'd have to do is calculate where the split point was, based on the position of the camera. In this case, the split point would be half the level's height above the camera, with the top bits filtered out so this split point is a coordinate within the physical level. Objects below the split point would go on the top mirror, while objects above the split point go on the bottom mirror. Hope that makes sense, I'm not very good at explaining my ideas. ;)

    EDIT: Better yet: The camera is always between 2 mirrored sections of the level, so you can have 2 variables containing the high bits of these 2 sections, and assume new objects are in the top section (combine the high bits with the coordinates that come from the object placement table), and then check its distance to the camera to see if this assumption was correct, or if the object should be moved to the other section.
     
  14. Mastered Realm

    Mastered Realm

    Member
    3,830
    556
    93
    -
    You got my attention. Maybe the vertical-wrapping on hidden pallace was going to be a boss battle of some kind with a cutscene to the water section on the right afterwards. I mean, look at Marble Garden Zone boss. It's entirely possible!
     
  15. DigitalDuck

    DigitalDuck

    Arriving four years late. Member
    5,349
    437
    63
    Lincs, UK
    TurBoa, S1RL
    I don't think you understand. The boss isn't necessary to have vertical wrapping and rising water; it works just fine if you remove the boss entirely.

    I'm guessing the reason the level doesn't loop vertically throughout the main bulk of it is just to keep things a lot simpler without tons of triggers to sort out the logic of the water level.
     
  16. redhotsonic

    redhotsonic

    Also known as RHS Tech Member
    1,587
    10
    18
    United Kingdom
    YouTuber
    Am I right in remembering that Esrael's S2 Delta also had vertical wrapping in HPZ and disabled the water at this bit? He even made a list that takes you up there. Can't remember if the background still scrolls or not.