Skip to content

Instantly share code, notes, and snippets.

@benvillalobos
Last active January 21, 2025 04:38
Show Gist options
  • Save benvillalobos/df2c45cce3604d629098de6ec696ffc1 to your computer and use it in GitHub Desktop.
Save benvillalobos/df2c45cce3604d629098de6ec696ffc1 to your computer and use it in GitHub Desktop.
oot-docs
graph TD
    Scene[Scene]
    Scene --> Room[Room]
    Room --> Actors[Actors]
    Room --> Objects[Objects]
    Scene --> Cutscene[Cutscene]
    Actors --> Enemies[Enemies]
    Actors --> Plants[Plants]
Loading
sequenceDiagram
    participant Main as main.c
    participant Graph as graph.c
    participant ZLib as z_game_dlftbls.c

    Main ->> Graph: start thread: Graph_ThreadEntry
    Graph ->> ZLib: get GAMESTATE_SETUP overlay
    Note over ZLib: The overlay table is defined in gamestate_table.h

    ZLib ->> Graph: returns GameStateOverlay w/ Setup_Init/Destroy methods

    Graph ->> Graph: Overlay_LoadGameState(setupOverlay)
    Graph ->> Graph: GameState_Init(Setup_Init)

    loop Main Game Loop
        Graph ->> Graph: Graph_Update(SetupGameState)
    end
Loading

Question: How do we get into the opening cutscene?

How Ocarina of Time Enters the Opening Cinematic

  1. Main is (effectively) the entry point.
  2. Main starts the graphics thread
  3. From there, Graph_ThreadEntry starts.
  4. From the overlay table, we grab the GAMESTATE_SETUP overlay.
  5. GameState_Init is called, it calls the init function (Setup_Init) that was passed.
  6. Setup_Init initializes a save context, sets running to false, and sets the next gamestate to ConsoleLogo.
  7. The inner game loop does not run on the first iteration (Setup_Init set running to false).
  8. The next loaded overlay is ConsoleLogo.
  9. ConsoleLogo_Init sets ConsoleLogo_Main.
  10. The inner game loop, Graph_Update is called with the ConsoleLogo game state.
  11. Graph_Update calls the gamestate's main function, which is ConsoleLogo_Main.
  12. Once ConsoleLogo_Main is ready to exit, the next gamestate is set to TITLE_SETUP

Old

sequenceDiagram
    participant Main as main.c
    participant Graph as graph.c
    participant ZLib as z_game_dlftbls.c
    participant ZGame as game.c
    participant ZTitle as title_setup.c

    Main ->> Graph: start thread: Graph_ThreadEntry
    Graph ->> ZLib: get GAMESTATE_SETUP overlay
    Note over ZLib: The overlay table is defined in gamestate_table.h

    ZLib ->> Graph: GAMESTATE_SETUP overlay
    Graph ->> ZGame: GameState_Init(Setup_Init)
    Note over ZTitle: Setup_Init()'s job is to initialize a save<br/>and set next gamestate to ConsoleLogo.
    ZGame ->> ZTitle: Setup_Init()

    Note over Graph: This loop is skipped the first time due to<br/>Setup_Init setting state->running to false.<br/> The first time we enter this loop is in the ConsoleLogo state
    loop While running == true
        Graph ->> Graph: Graph_Update(ConsoleLogoState)
    end
Loading

  1. z_en_mag.c listens for cutscene flags 3 and 4, which begin fade in / fade out.
    1. These flags are fired by the intro cutscene
  2. If the player presses A, B, or Start while en_mag is displayed, it sets the gameMode to file select and starts a transition.
  3. In z_play.c, if the playState's transitionTrigger is not OFF, set transitionMode to setup., transitionType is also FADE_BLACK
  4. When the transition mode is SETUP, the SETUP case falls through to INSTANCE_INIT
    1. Note: The comment next to GAMEMODE_FILE_SELECT suggests that "instance type transitions" are specific to file select.
  5. At the end of the INSTANCE_INIT case, transitionMode is set to INSTANCE_RUNNING
  6. state.running is set to false when the transition completes, and the transitionTrigger is not TRIGGER_END
  7. When the gameMode is not FILE_SELECT, the next gamestate is set to file select.
@scriptorluminary
Copy link

I take you investigated The Legend of Zelda: Ocarina of Time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment