The world map: its perspective view, its tiles, and the still picture of the view BG1 shows while a menu or event runs. More...
Go to the source code of this file.
Data Structures | |
| struct | WorldMapCell |
| One 32-pixel cell of the world map: its tile, its kind (21 selects the second graphics set) and a flag. More... | |
Macros | |
| #define | WORLD_MAP_BG_PALETTE ((s16 *)BG_PLTT) |
| #define | WORLD_MAP_CELLS ((struct WorldMapCell *)Ram_MapBlocks) |
Typedefs | |
| typedef s32(*) | WorldMapPlaneFn(void *camera, s32 *position, void *lines, void *out) |
Functions | |
| static __inline__ void | Io_Set16 (s32 value, volatile u16 *reg) |
| Writes a halfword register (value first). | |
| static __inline__ void | Io_Put16 (volatile u16 *reg, s32 value) |
| Writes a halfword register (register first). | |
| s32 | Map_WriteLayerCellTile (s32 layer, s32 x, s32 y, s32 tile, s32 update) |
| Loads world map tile tile into quarter (x & 1, y & 1) of a layer's block buffer, decompressing it from the area's graphics, and with update set also draws it into the layer's BG map. | |
| s32 | Map_InitializePerspectiveScene (void) |
| Sets up the world map's perspective view: BG2 and BG3 in affine mode, the camera work, the projection, the per-scanline ground plane routine in RAM (Transform_UpdateVertices) and its first frame, and the per-frame view and HBlank updates. | |
| void | Map_SetWindowCellTile (s32 x, s32 y, s32 px, s32 py) |
| Puts world map tile (x / 16, y / 16) at cell (px / 16, py / 16) of the tile id grid, and draws it at once when it is next to the view. | |
| void | WorldMap_LoadGraphics (s32 x, s32 z) |
| Loads the world map's palette and tiles for the area at (x, z): the second set where the ground there is terrain kind 21. | |
| void | MapAnimation_ApplyAffineFrame (void) |
| HBlank setup each frame on the world map: copies the first scanline's BG2 and BG3 affine parameters, starts the HBlank DMA for the rest, and picks the BG mode from the window's top and bottom. | |
| static __inline__ void | WorldMap_CopyCellTiles (u8 *cellBytes, u8 *screenTile) |
| Copies one world map cell's two tile entries (top and bottom) to a BG map. | |
| void | Map_RenderPaletteMappedRow (u32 tileRow) |
| Draws world map tileRow into the BG map: 32 cells, then 32 more a screen block on. | |
| void | Map_RenderPaletteMappedColumn (u32 tileColumn) |
| Draws world map tileColumn into the BG map: 64 cells down. | |
| void | WorldMap_UpdateView (void) |
| Each frame on the world map: loads tiles as the view moves, shakes and follows the player, draws the BG row or column that scrolls into view, moves the camera, and builds the ground plane's scanline table. | |
| void | Map_UpdateCurrentTileBlock (void) |
| Loads and draws the 2x2 world map tiles around the player in both layers. | |
| void | Map_PreloadCurrentTileBlock (void) |
| Loads the first of the 2x2 world map tiles around the player that is not shown yet (at most one a frame), without drawing it. | |
| void | MapAnimation_PresentFrame (void) |
| VBlank: shows BG1 and copies the decoded frame's tiles into VRAM. | |
| void | WorldMap_BeginStillView (void) |
| Freezes the world map's perspective view as a still picture on BG1: saves BG1's tiles, draws the current affine frame into pixels and hands the window and VBlank to it. | |
| void | Map_ShowBg1FromBuffer (void) |
| VBlank: shows BG1 and copies the area's tiles back into VRAM. | |
| void | Map_LoadAreaGraphics (void) |
| Reloads the world map area's palette and tiles after the still view, puts the default cells back and returns to the perspective view. | |
| void | Map_LoadDefaultCellsAndUpdateBlock (void) |
| Puts the default world map cells back after the still view and returns to the perspective view, without reloading the area's palette or tiles. | |
The world map: its perspective view, its tiles, and the still picture of the view BG1 shows while a menu or event runs.
Part of field.c, the field object, compiled only through it.
Definition in file world_map.c.
Definition at line 25 of file world_map.c.
Referenced by WorldMap_LoadGraphics().
| #define WORLD_MAP_CELLS ((struct WorldMapCell *)Ram_MapBlocks) |
Definition at line 27 of file world_map.c.
Referenced by WorldMap_LoadGraphics().
Definition at line 14 of file world_map.c.
Writes a halfword register (value first).
Definition at line 9 of file world_map.c.
Referenced by Io_Set16(), and Map_InitializePerspectiveScene().
Writes a halfword register (register first).
Definition at line 12 of file world_map.c.
Referenced by Io_Put16(), and Map_InitializePerspectiveScene().
Loads world map tile tile into quarter (x & 1, y & 1) of a layer's block buffer, decompressing it from the area's graphics, and with update set also draws it into the layer's BG map.
Returns 0 when that quarter already shows the tile (and update is 0), else 1.
Called by Map_UpdateCurrentTileBlock and Map_SetWindowCellTile (update 1) and by Map_PreloadCurrentTileBlock (update 0). Sets the quarter's entry in perspective->quarterTiles, and borrows heap slot 14 for the decoded tile.
Definition at line 38 of file world_map.c.
Referenced by Map_PreloadCurrentTileBlock(), Map_SetWindowCellTile(), Map_UpdateCurrentTileBlock(), and Map_WriteLayerCellTile().
| s32 Map_InitializePerspectiveScene | ( | void | ) |
Sets up the world map's perspective view: BG2 and BG3 in affine mode, the camera work, the projection, the per-scanline ground plane routine in RAM (Transform_UpdateVertices) and its first frame, and the per-frame view and HBlank updates.
Called through Map_InitializePerspectiveSceneFar when the world map scene starts (run_scene.c). Allocates and clears the perspective work in HEAP_SLOT_MAP, the camera in HEAP_SLOT_CAMERA and the affine pages in heap slot 7; loads the default cells, block attributes and tile animations; writes the blend, BG and affine registers and REG_DISPCNT (mode 2); and registers WorldMap_UpdateView and MapAnimation_ApplyAffineFrame with the scheduler.
Definition at line 114 of file world_map.c.
Referenced by Map_InitializePerspectiveScene().
Puts world map tile (x / 16, y / 16) at cell (px / 16, py / 16) of the tile id grid, and draws it at once when it is next to the view.
Layer 1 takes the tile 0x140 (320) further on. Called by the world map scene (FieldMap_SetWindowCellTile, through Map_SetWindowCellTileFar). Sets perspective->tileIds.
Definition at line 271 of file world_map.c.
Referenced by FieldMap_SetWindowCellTile(), and Map_SetWindowCellTile().
Loads the world map's palette and tiles for the area at (x, z): the second set where the ground there is terrain kind 21.
Fills the BG maps, and for the second set swaps in its own tiles at ids 10-12 and 26-28.
Called through WorldMap_LoadGraphicsFar when the world map scene starts, with the party's position (run_scene.c). Sets perspective->resources, which Map_LoadAreaGraphics reloads from; writes BG palette colours 1 to 223 (keeping the backdrop), char blocks 2 and 3, gMapLayerData and screen blocks 5 and 6.
Definition at line 311 of file world_map.c.
Referenced by WorldMap_LoadGraphics().
| void MapAnimation_ApplyAffineFrame | ( | void | ) |
HBlank setup each frame on the world map: copies the first scanline's BG2 and BG3 affine parameters, starts the HBlank DMA for the rest, and picks the BG mode from the window's top and bottom.
Registered with the scheduler by Map_InitializePerspectiveScene (priority 0x480). Reads this frame's affine page (gFrameCount & 1), restarts DMA 0, sets shownTop and shownBottom, writes REG_DISPCNT's mode and clears windowPending.
Definition at line 386 of file world_map.c.
Referenced by Map_InitializePerspectiveScene(), and MapAnimation_ApplyAffineFrame().
Copies one world map cell's two tile entries (top and bottom) to a BG map.
Definition at line 444 of file world_map.c.
Referenced by Map_RenderPaletteMappedColumn(), Map_RenderPaletteMappedRow(), and WorldMap_CopyCellTiles().
| void Map_RenderPaletteMappedRow | ( | u32 | tileRow | ) |
Draws world map tileRow into the BG map: 32 cells, then 32 more a screen block on.
Called by WorldMap_UpdateView when the view crosses a row.
Definition at line 456 of file world_map.c.
Referenced by Map_RenderPaletteMappedRow(), and WorldMap_UpdateView().
| void Map_RenderPaletteMappedColumn | ( | u32 | tileColumn | ) |
Draws world map tileColumn into the BG map: 64 cells down.
Called by WorldMap_UpdateView when the view crosses a column.
Definition at line 484 of file world_map.c.
Referenced by Map_RenderPaletteMappedColumn(), and WorldMap_UpdateView().
| void WorldMap_UpdateView | ( | void | ) |
Each frame on the world map: loads tiles as the view moves, shakes and follows the player, draws the BG row or column that scrolls into view, moves the camera, and builds the ground plane's scanline table.
Registered with the scheduler by Map_InitializePerspectiveScene (priority 0xc85, as Map_UpdateLayerScroll is on layered maps). Sets viewX and viewY, decays the shake, moves the camera and its eye, and runs Transform_UpdateVertices from heap slot 46 into this frame's affine page.
Definition at line 508 of file world_map.c.
Referenced by Map_InitializePerspectiveScene(), and WorldMap_UpdateView().
| void Map_UpdateCurrentTileBlock | ( | void | ) |
Loads and draws the 2x2 world map tiles around the player in both layers.
Called through Map_UpdateCurrentTileBlockFar when the world map scene starts, by WorldMap_LoadGraphics for the second graphics set, and by Map_LoadAreaGraphics and Map_LoadDefaultCellsAndUpdateBlock after the still view.
Definition at line 607 of file world_map.c.
Referenced by Map_LoadAreaGraphics(), Map_LoadDefaultCellsAndUpdateBlock(), Map_UpdateCurrentTileBlock(), and WorldMap_LoadGraphics().
| void Map_PreloadCurrentTileBlock | ( | void | ) |
Loads the first of the 2x2 world map tiles around the player that is not shown yet (at most one a frame), without drawing it.
Called at the start of each WorldMap_UpdateView, so tiles come in one a frame as the player walks.
Definition at line 648 of file world_map.c.
Referenced by Map_PreloadCurrentTileBlock(), and WorldMap_UpdateView().
| void MapAnimation_PresentFrame | ( | void | ) |
VBlank: shows BG1 and copies the decoded frame's tiles into VRAM.
The frame is the still view WorldMap_BeginStillView draws: 0x2580 words, 240 by 160 pixels at a byte each, shown as 256-colour tiles on screen block 6. Set as gVBlankHook by WorldMap_BeginStillView.
Definition at line 684 of file world_map.c.
Referenced by MapAnimation_PresentFrame(), and WorldMap_BeginStillView().
| void WorldMap_BeginStillView | ( | void | ) |
Freezes the world map's perspective view as a still picture on BG1: saves BG1's tiles, draws the current affine frame into pixels and hands the window and VBlank to it.
Called through WorldMap_BeginStillViewFar by WorldMap_BeginEvent when a menu or event starts on the world map, and by the world map scene's lighthouse transition. Sets animationActive, suspends the tile animations (MapAnimation_Update), copies 8 KB of char block 1 to gDecodeBuffer, sets the window rows to 200 and 255 (BG mode 0) and sets gVBlankHook to MapAnimation_PresentFrame. Map_LoadAreaGraphics undoes it.
Definition at line 701 of file world_map.c.
Referenced by GameFlag_IsSet(), WorldMap_BeginStillView(), and WorldMap_PlayLighthouseTransition().
| void Map_ShowBg1FromBuffer | ( | void | ) |
VBlank: shows BG1 and copies the area's tiles back into VRAM.
Restores BG1CNT as Map_InitializePerspectiveScene set it, and the 32 KB of char blocks 2 and 3 the still view overwrote, from gBgTileBuffer. Set as gVBlankHook by Map_LoadAreaGraphics and Map_LoadDefaultCellsAndUpdateBlock.
Definition at line 722 of file world_map.c.
Referenced by Map_LoadAreaGraphics(), Map_LoadDefaultCellsAndUpdateBlock(), and Map_ShowBg1FromBuffer().
| void Map_LoadAreaGraphics | ( | void | ) |
Reloads the world map area's palette and tiles after the still view, puts the default cells back and returns to the perspective view.
Called through Map_LoadAreaGraphicsFar by WorldMap_EndEvent when a menu or event ends, by Map_ShowWorldMap, and by the world map scene's lighthouse transition. Decodes into gMapCellBuffer and gBgTileBuffer, sets gVBlankHook to Map_ShowBg1FromBuffer, sets the window rows back to 0 and 159, clears animationActive and resumes the tile animations. Waits two frames.
Definition at line 737 of file world_map.c.
Referenced by Map_LoadAreaGraphics(), and WorldMap_PlayLighthouseTransition().
| void Map_LoadDefaultCellsAndUpdateBlock | ( | void | ) |
Puts the default world map cells back after the still view and returns to the perspective view, without reloading the area's palette or tiles.
Called three times by the world map scene's events. Unlike Map_LoadAreaGraphics it leaves animationActive set. XXX: whether leaving animationActive set is intended; a scene that calls it and then opens a menu would show the effect.
Definition at line 780 of file world_map.c.
Referenced by Map_LoadDefaultCellsAndUpdateBlock(), and WorldMap_ShowEndingScene().