Author Topic: Explanation of the Layer System  (Read 6455 times)

Offline CryZe

  • Deku Scrub
  • Posts: 9
Explanation of the Layer System
« on: October 07, 2014, 03:34:40 AM »
I'm not sure how interested people are in this, but I think this is somewhat interesting knowledge about the game.

Wind Waker uses Stages and Rooms to display its content. Only one Stage is loaded at a time and either 1 or 2 rooms associated with this stage are loaded. Both the Stage and the Rooms provide information about the current environment: Lighting, Actors to be loaded, Collision, Paths, Exits, Spawns, Spawn Events, Events, Zones, ...
Both Actors and Zones can be grouped into something the game calls a Layer. Whenever a room is to be loaded, the game then loads all zones and actors that are located in the default group and also decides on one specific layer to load as well. These layers usually are named in hexadecimal ranging from 0x0 to 0xB. From what I've noticed the "normal" layers are ranging from 0x0 to 0x7, while cutscene layers are ranging from 0x8 to 0xA. Some rooms also have a "beta layer" with the name 0xB containing beta content.

These layers are especially important as they reflect the progress in the game. Forsaken Fortress 3 for example is the exact same room as Forsaken Fortress 2, but is just using a different layer with different actors and zones. So how does the game decide on which layer to load?

Well, there's multiple ways this can happen. Whenever you warp to a Stage, the warp can specify to always put you on a specific layer. Normal loading zones can't do that though. So it's usually special zones that are causing this. There's also two ways the event system can warp you with a so called layer override. Major cutscenes are usually not done with the normal event system and are done with a storyboard instead. So the event system has a way to start these major cutscenes and it can specify where you'll end up after the cutscene which can involve a layer override. Cutscenes that are separated between multiple stages, like the Master Sword Cutscene, usually use the layer overrides together with specific spawns to load the correct actors and the correct spawns (which have events attached to them), to load the next cutscene.
Normal events can also use these layer overrides. A normal event can involve an actor called "DIRECTOR" who can decide on when and where to warp and these warps can include layer overrides as well.

But how does the game usually decide on which layers to load, when it does not involve layer overriding? The game obviously does not do a layer override for stuff like Forsaken Fortress 2 or 3, so how does this work? Well, we looked into the room files and couldn't find anything, so we decided to disassemble the game to find out how it decides on those and we found out that those are actually "hardcoded" into the game's layer determination function. So we disassembled the whole function and this is how it works (this is not simplified, this is 1:1 how it works): http://pastebin.com/sa5TRG16

As you can see, the layers apparently work in pairs. Every even layer is a day layer, while every odd layer is a night layer.

There's also four glitches in the game that we can abuse to load specific layers.
  • Layer 0: After you got KoRL, he will warp you next to him with a Layer Override of 0, so you will have an empty Forsaken Fortress (neither FF2 nor FF3), Intro Windfall and Intro Outset. This can also be caused by being on Layer 1 and playing the Song of Passing.
  • Layer 1: The Flight Platform Minigame always puts you on Layer 1 after ending it, so you will have Forsaken Fortress 2, Windfall at Night before getting Endless Night and a fully empty Outset. This can also be caused by being on Layer 0 and playing the Song of Passing.
  • Layer 2: The Flight Platform Minigame always puts you on Layer 2 during the minigame, so if you escape that, you will have Forsaken Fortress 3 (It's actually a copy of Forsaken Fortress 3), Pirates at Windfall (It's a day version of the Endless Night Pirates at Windfall) and Pirates at Outset. This can also be caused by being on Layer 3 and playing the Song of Passing.
  • Layer 3: This can be caused by being on Layer 2 and playing the Song of Passing. You will have Forsaken Fortress 3, Pirates at Windfall and an empty Outset.
  • Layer 8: If you skip the Gossip Stone, going into the Pirate Ship and exiting it will warp you back to Forsaken Fortress 1. If you complete that again, the KoRL cutscene won't play anymore and you stay on the cutscene layer 8. Windfall will have a seagull that's stuck in the air, Outset will be the version of Outset during the "Pirates arriving at Outset cutscene" and everything else will be pretty empty. This can also be caused by being on Layer 9 and playing the Song of Passing.
  • Layer 9: This can be caused by being on Layer 8 and playing the Song of Passing. You will have an empty Forsaken Fortress, an empty Windfall and Outset will be the version of Outset during the "Aryll getting captured by Helmaroc cutscene" and thus Aryll, Tetra and a Pirate will be on top of Outset.
« Last Edit: November 02, 2014, 07:50:07 AM by CryZe »

Offline mzxrules

  • Mega Guay
  • Posts: 923
  • Wrong warp expert
Re: Explanation of the Layer System
« Reply #1 on: October 11, 2014, 12:56:04 AM »
Sounds fairly similar to the Zelda 64 engine, if you change the word stage to scene, and layer to scene setup.

Quote
These layers usually are named in hexadecimal ranging from 0x0 to 0xB. From what I've noticed the "normal" layers are ranging from 0x0 to 0x7, while cutscene layers are ranging from 0x8 to 0xA. Some rooms also have a "beta layer" with the name 0xB containing beta content.

When you say named, do you mean there's actually a string value of "0xB" somewhere?
Quote from:  Leigh Rogers
Braid
This is art because the music is classical music, and the graphics are done with a pen. The story is something about a woman. I could not understand much of this to be honest, which makes it even more likely to be an art.

Offline CryZe

  • Deku Scrub
  • Posts: 9
Re: Explanation of the Layer System
« Reply #2 on: October 17, 2014, 03:54:32 PM »
Interesting, but yeah, the room and stage files name their groups of data and group names that are based on layers are called ACT0, ACT1, ..., ACTa, ACTb for example. The game has a constant string array that gets indexed based on the layer to access the group names.
« Last Edit: October 17, 2014, 04:03:41 PM by CryZe »