Investigating the S3&K MGZ2 earthquake

Discussion in 'Engineering & Reverse Engineering' started by Hayate, Dec 4, 2008.

Thread Status:
Not open for further replies.
  1. Hayate

    Hayate

    Tech Member
    This has puzzled me for a long time and it still does. While recently playing S3&K, I got to FBZ2 and saw the earthquake in that zone, when it occured to me to try using Gens' layer disabling functions. After disabling plane A I noticed that there was now a black bar where the floor should have been, and thought "hey, maybe it's just changing the position and base address of plane A on hblank?". This was possible for FBZ, but upon applying this thought to MGZ I am thoroughly confused. Here's some screenshots.

    [​IMG][​IMG]
    All layers enabled in a part of the earthquake sequence. In the right picture, only sprites are disabled, to prove that the game doesn't just cheat by putting land on sprites. The game was paused via Start rather than emulator pause, hence the emulator timer changing.

    [​IMG][​IMG]
    Plane A (left) and Plane B (right) disabled in the same area.

    Now, here's my thoughts at this time:

    1. Since they put part of the layer Sonic's on (I shall call this layer 0 from now on, and the other layer 1) on plane B, why didn't they put it /all/ on plane B? If I had programmed the effect I would have thought this would be the only way to do it.
    2. The only way this effect could be done in this way, that I can see, is that they used block vertical scrolling and changed the values on HBlank.

    However, 2 is wrong. Why? Because, after unpausing, letting the game run for a little longer and pausing again, we arrive at the next four screenshots (in the same order):

    [​IMG][​IMG]
    [​IMG][​IMG]

    Now, look at the screenshots above. As you can see, both layer 0 and 1 have remained on plane A, and the non-solid grass tiles are still on plane B. But notice that there are now tiles of both layers overlapping! You can see this in two places: the ceiling under the spikes, and the grass to the left of Sonic.

    While it is certainly possible for clever use of HBlanks and block vertical scrolling to allow these effects for rectangular areas such as in FBZ, this technique cannot possibly work for MGZ as any given 16x1 rectangle of the screen cannot possibly contain data from two 8x8 tiles on the same plane in the same frame. So, how is this possible? Right now I am thinking that the only way to do it would be to blit at least the overlapping tiles in software, but this seems like way too much programming effort not to mention the possible lag it may produce. As I mentioned before, I would have implemented the cutscene by placing layer 0 on plane A and layer 1 on plane B, which is exactly what Sky Sanctuary Zone does (with the clouds in the background on sprites).

    Anyone have any ideas about this?
     
  2. jman2050

    jman2050

    Teh Sonik Haker Tech Member
    633
    2
    16
    Correct answer: Gens layer disabling doesn't do what you think it does:

    Low plane disabled

    This makes sense, since the background and grassy parts are drawn behnd Sonic, while the terrain itself isn't. Using a newer emulator (Upthorn's Gens modification) confirms this. This part of the level works exactly the way you thought it did originally. The solid terrain further back is part of Plane B, the closer terrain is plane A
     
  3. Hayate

    Hayate

    Tech Member
    ....fuck

    Yeah, remind me to open Debugens and not Movie Gens next time I want to disable layers...

    Someone trash this <_<
     
  4. SMTP

    SMTP

    Tech Member
    What I understand though is, the background is on plane B too. Why is it that the background doesnt move too?
     
  5. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,719
    0
    0
    being an asshole =P
    I just checked and apparently it does.
     
  6. jman2050

    jman2050

    Teh Sonik Haker Tech Member
    633
    2
    16
  7. muteKi

    muteKi

    Fuck it Member
    7,617
    20
    18
    If you go far enough fast enough and get to the end of that section you'll see that part of the background moving up.
     
  8. Hayate

    Hayate

    Tech Member
    Actually I've just thought of another interesting thing - good job nobody trashed the topic like I asked =P

    Does the S3&K engine have some generic way of dealing with ground on both planes? HCZ, MGZ, FBZ, SZ and SSZ all do this kind of trick, SSZ throughout practically the entire zone. Perhaps the engine *always* checks for blocks marked as solid on plane B, and the level data and DSR effects merely control when we actually notice the effects of it.

    In fact, S2 might have this, even if it's restricted to being a DSR effect, as IIRC the HTZ moving lava is on plane B, and I /think/ someone once hacked that level to put non-lava in that area giving a MGZ-like segment.
     
  9. jman2050

    jman2050

    Teh Sonik Haker Tech Member
    633
    2
    16
    Yes, there is a flag in the level collision routine that does this. If set, it'll use the address of the background chunks in addition to the address of the foreground chunks when determining collision. The routine actually runs twice as a result.
     
  10. Upthorn

    Upthorn

    TAS Tech Member
    239
    0
    0
    Specifically, the flag is at $FFF664, and when set it checks sonic's collisions a second time, using the background chunks, and position offsets at $FFEE3E (X), and $FFEE40 (Y). When the flag is not set, however, it never checks sonic's collisions against the background.

    No. I looked into this several months ago, and the HTZ earthquake and moving terrain stuff is all done by objects in the SST. The lava, the non-lava, and everything are all objects with special routines for collision and display so that they can handle angles, position offsets, and being drawn on the background plane.
     
Thread Status:
Not open for further replies.