src/field/field_world_map.c
The world map: its perspective view, its tiles, and the still image of the view BG1 shows while a menu or script runs. More…
Included by field.c.
Structures
| Name | Description | |
|---|---|---|
struct | WORLD_MAP_METATILE | One 32-pixel metatile of the world map: its tile, its kind (WORLD_MAP_ENCOUNTER_REGION) and a flag. |
Macros
| Name | Description | |
|---|---|---|
#define | WORLD_MAP_BG_PALETTE ((Sint16 *)BG_PLTT) | |
#define | WORLD_MAP_METATILES ((WORLD_MAP_METATILE *)RamMetatileTiles) | |
#define | WORLD_MAP_TILE_METATILES 16 | A world map tile is 16 by 16 metatiles. |
#define | WORLD_MAP_TILES_ACROSS 16 | The world map is 16 by 16 tiles, 512 pixels each, wrapping; each layer's tile numbers follow the 320 before it. |
#define | WORLD_MAP_LAYER_TILES 320 | |
#define | WORLD_MAP_ALTERNATE_TILES | The tiles after the world's 256 in a layer: other versions of a few grid cells. |
#define | WORLD_MAP_FIXED_TO_TILE (v) ((v) >> 25) | 16.16 pixels to whole 512-pixel tiles. |
#define | WORLD_MAP_BUFFER_METATILES 32 | Each layer's metatile buffer holds the 2 by 2 tiles around the view: 32 metatiles a side, 4 bytes a metatile. |
#define | WORLD_MAP_METATILE_ROW_BYTES (WORLD_MAP_BUFFER_METATILES * 4) | |
#define | WORLD_MAP_LAYER_METATILE_BYTES | |
#define | WORLD_MAP_SCREEN_WIDTH 64 | An affine layer's BG map: 64 tiles a row, one byte each, two screen blocks in all. |
#define | WORLD_MAP_SCREEN_ROW_HALFWORDS (WORLD_MAP_SCREEN_WIDTH / 2) | A map row as the halfwords that write it two tiles at a time. |
#define | WORLD_MAP_LAYER_SCREEN_BYTES | |
#define | WORLD_MAP_WIDE_TILES 128 | MAP_GRID_SCROLL_STATE's wideTiles, which the world map shares: any nonzero value has the tileset animations copy 64-byte tiles. |
#define | WORLD_MAP_STILL_WINDOW_TOP 200 | The window rows fdWorldMapStartStillImage sets, below the screen: the tick update then picks mode 0 and BG1 shows the still image. |
#define | WORLD_MAP_STILL_WINDOW_BOTTOM 255 | |
#define | WORLD_MAP_STILL_TILES (DISPLAY_TILE_WIDTH * DISPLAY_TILE_HEIGHT) | |
#define | WORLD_MAP_USE_ALTERNATE_TILE (perspective, column, row) | Grid cell (column, row) shows its alternate tile. |
Typedefs
| Name | Description | |
|---|---|---|
typedef Sint32 (* | WORLD_MAP_PLANE_FN )(void *camera, Sint32 *position, void *lines, void *out); | fdWorldMapUpdateAffineLines, run from RAM: works out each screen line's BG2 and BG3 affine parameters for the camera into one of the two affine pages. |
Functions
| Name | Description | |
|---|---|---|
static __inline__ void | fdIOWrite16Inline (Sint32 value, volatile Uint16 *reg) | IO_WRITE16 as an inline function. |
Sint32 | fdWorldMapWriteLayerMetatileTile ( Sint32 layer, Sint32 x, Sint32 y, Sint32 tile, Sint32 update) | Loads world map tile tile into quarter (x & 1, y & 1) of a layer's metatile picture buffer, decompressing it from the area's graphics, and with update set also draws it into the layer's BG map. |
UNREAD_RESULT | fdWorldMapInitPerspective (void) | Sets up the world map's perspective view: BG2 and BG3 in affine mode, the camera state, the projection, the per-scanline ground plane function in RAM (fdWorldMapUpdateAffineLines) and its first tick, and the per-tick view and HBlank updates. |
void | fdWorldMapSetGridTile (Sint32 x, Sint32 y, Sint32 metatileX, Sint32 metatileY) | Changes one 512-pixel tile of the world map: the grid cell holding 32-pixel metatile (metatileX, metatileY) shows tile (y / 16) * 16 + x / 16 from now on (the broken bridge south of Vault is tile 264 in cell 11 by 3). |
void | fdWorldMapLoadGraphics (Sint32 x, Sint32 z) | Loads the world map's palette and tiles for the area at (x, z): the second set where the ground there is WORLD_MAP_ENCOUNTER_REGION_SNOWFIELD. |
void | fdWorldMapApplyAffinePage (void) | HBlank setup each VBlank 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 | fdWorldMapCopyMetatileTiles (Uint8 *metatileBytes, Uint8 *screenTile) | Copies one world map metatile's two tile entries (top and bottom) to a BG map. |
void | fdWorldMapDrawMetatileRow (Uint32 tileRow) | Draws row tileRow of the metatile buffer into both layers' BG maps, 32 metatiles in each: the row of the ground that scrolls into view. |
void | fdWorldMapDrawMetatileColumn (Uint32 tileColumn) | Draws column tileColumn of the metatile buffer into both layers' BG maps, 32 metatiles down in each (the second layer's map and metatiles follow the first's): the column of the ground that scrolls into view. |
void | fdWorldMapUpdateView (void) | Each tick 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 | fdWorldMapUpdateCurrentTileBlock (void) | Loads and draws the 2x2 world map tiles around the player in both layers. |
void | fdWorldMapPreloadCurrentTileBlock (void) | Loads the first of the 2x2 world map tiles around the player that is not shown yet (at most one a tick), without drawing it. |
void | fdWorldMapPresentStillImage (void) | VBlank: shows BG1 and copies the decoded picture's tiles into VRAM. |
void | fdWorldMapStartStillImage (void) | Freezes the world map's perspective view as a still image on BG1: saves BG1's tiles, draws the current affine frame into pixels and hands the window and VBlank to it. |
void | fdWorldMapEndStillImage (void) | VBlank at the end of the still image: puts BG1 back as the plain layer and copies the area's four tile sets back into char blocks 2 and 3. |
void | fdWorldMapLoadAreaGraphics (void) | Reloads the world map area's palette and tiles after the still image, puts the default metatiles back and returns to the perspective view. |
void | fdWorldMapLoadDefaultMetatilesAndUpdateBlock (void) | Puts the default world map metatiles back after the still image and returns to the perspective view, without reloading the area's palette or tiles. |
Description
The world map: its perspective view, its tiles, and the still image of the
view BG1 shows while a menu or script runs. Part of field.c.
Macros in detail
WORLD_MAP_BG_PALETTE
#define WORLD_MAP_BG_PALETTE ((Sint16 *)BG_PLTT)
Referenced by fdWorldMapLoadGraphics().
Definition at line 32 of file field_world_map.c.
WORLD_MAP_METATILES
#define WORLD_MAP_METATILES ((WORLD_MAP_METATILE *)RamMetatileTiles)
Referenced by fdWorldMapLoadGraphics().
Definition at line 34 of file field_world_map.c.
WORLD_MAP_TILE_METATILES
#define WORLD_MAP_TILE_METATILES 16
A world map tile is 16 by 16 metatiles.
Referenced by fdWorldMapWriteLayerMetatileTile().
Definition at line 37 of file field_world_map.c.
WORLD_MAP_TILES_ACROSS
#define WORLD_MAP_TILES_ACROSS 16
The world map is 16 by 16 tiles, 512 pixels each, wrapping; each layer's tile numbers follow the 320 before it.
Referenced by fdWorldMapInitPerspective(), fdWorldMapPreloadCurrentTileBlock(), fdWorldMapSetGridTile() and fdWorldMapUpdateCurrentTileBlock().
Definition at line 40 of file field_world_map.c.
WORLD_MAP_LAYER_TILES
#define WORLD_MAP_LAYER_TILES 320
Referenced by fdWorldMapPreloadCurrentTileBlock(), fdWorldMapSetGridTile() and fdWorldMapUpdateCurrentTileBlock().
Definition at line 41 of file field_world_map.c.
WORLD_MAP_ALTERNATE_TILES
#define WORLD_MAP_ALTERNATE_TILES
The tiles after the world's 256 in a layer: other versions of a few grid cells.
Definition at line 44 of file field_world_map.c.
WORLD_MAP_FIXED_TO_TILE
#define WORLD_MAP_FIXED_TO_TILE(v) ((v) >> 25)
16.16 pixels to whole 512-pixel tiles.
Referenced by fdWorldMapPreloadCurrentTileBlock() and fdWorldMapUpdateCurrentTileBlock().
Definition at line 47 of file field_world_map.c.
WORLD_MAP_BUFFER_METATILES
#define WORLD_MAP_BUFFER_METATILES 32
Each layer's metatile buffer holds the 2 by 2 tiles around the view: 32 metatiles a side, 4 bytes a metatile.
Referenced by fdWorldMapDrawMetatileColumn() and fdWorldMapDrawMetatileRow().
Definition at line 50 of file field_world_map.c.
WORLD_MAP_METATILE_ROW_BYTES
#define WORLD_MAP_METATILE_ROW_BYTES (WORLD_MAP_BUFFER_METATILES * 4)
Referenced by fdWorldMapDrawMetatileColumn(), fdWorldMapDrawMetatileRow() and fdWorldMapWriteLayerMetatileTile().
Definition at line 51 of file field_world_map.c.
WORLD_MAP_LAYER_METATILE_BYTES
#define WORLD_MAP_LAYER_METATILE_BYTES
Referenced by fdWorldMapDrawMetatileRow().
Definition at line 52 of file field_world_map.c.
WORLD_MAP_SCREEN_WIDTH
#define WORLD_MAP_SCREEN_WIDTH 64
An affine layer's BG map: 64 tiles a row, one byte each, two screen blocks in all.
Referenced by fdWorldMapCopyMetatileTiles() and fdWorldMapDrawMetatileColumn().
Definition at line 56 of file field_world_map.c.
WORLD_MAP_SCREEN_ROW_HALFWORDS
#define WORLD_MAP_SCREEN_ROW_HALFWORDS (WORLD_MAP_SCREEN_WIDTH / 2)
A map row as the halfwords that write it two tiles at a time.
Referenced by fdWorldMapWriteLayerMetatileTile().
Definition at line 58 of file field_world_map.c.
WORLD_MAP_LAYER_SCREEN_BYTES
#define WORLD_MAP_LAYER_SCREEN_BYTES
Referenced by fdWorldMapDrawMetatileRow().
Definition at line 59 of file field_world_map.c.
WORLD_MAP_WIDE_TILES
#define WORLD_MAP_WIDE_TILES 128
MAP_GRID_SCROLL_STATE's wideTiles, which the world map shares: any nonzero
value has the tileset animations copy 64-byte tiles.
Referenced by fdWorldMapInitPerspective().
Definition at line 63 of file field_world_map.c.
WORLD_MAP_STILL_WINDOW_TOP
#define WORLD_MAP_STILL_WINDOW_TOP 200
The window rows fdWorldMapStartStillImage sets, below the screen: the tick
update then picks mode 0 and BG1 shows the still image.
Referenced by fdWorldMapApplyAffinePage() and fdWorldMapStartStillImage().
Definition at line 67 of file field_world_map.c.
WORLD_MAP_STILL_WINDOW_BOTTOM
#define WORLD_MAP_STILL_WINDOW_BOTTOM 255
Referenced by fdWorldMapStartStillImage().
Definition at line 68 of file field_world_map.c.
WORLD_MAP_STILL_TILES
#define WORLD_MAP_STILL_TILES (DISPLAY_TILE_WIDTH * DISPLAY_TILE_HEIGHT)
Referenced by fdWorldMapPresentStillImage().
Definition at line 69 of file field_world_map.c.
WORLD_MAP_USE_ALTERNATE_TILE
#define WORLD_MAP_USE_ALTERNATE_TILE(perspective, column, row)
Grid cell (column, row) shows its alternate tile.
Referenced by fdWorldMapLoadGraphics().
Definition at line 72 of file field_world_map.c.
Typedefs in detail
WORLD_MAP_PLANE_FN
typedef Sint32 (*WORLD_MAP_PLANE_FN)(void *camera, Sint32 *position, void *lines, void *out);
fdWorldMapUpdateAffineLines, run from RAM: works out each screen line's BG2
and BG3 affine parameters for the camera into one of the two affine pages.
Referenced by fdWorldMapInitPerspective() and fdWorldMapUpdateView().
Definition at line 14 of file field_world_map.c.
Functions in detail
fdIOWrite16Inline
static __inline__ void fdIOWrite16Inline(Sint32 value, volatile Uint16 *reg)
IO_WRITE16 as an inline function.
References Sint32.
Referenced by fdWorldMapInitPerspective().
Definition at line 7 of file field_world_map.c.
fdWorldMapWriteLayerMetatileTile
Sint32 fdWorldMapWriteLayerMetatileTile( Sint32 layer, Sint32 x, Sint32 y, Sint32 tile, Sint32 update)
Loads world map tile tile into quarter (x & 1, y & 1) of a layer's metatile
picture buffer, decompressing it from the area's graphics, and with update
set also draws it into the layer's BG map.
References Sint32, syDecompressByteLZ(), syDMAXCopy(), syHeapSlotAllocate() and syHeapSlotRelease().
Referenced by fdWorldMapPreloadCurrentTileBlock(), fdWorldMapSetGridTile() and fdWorldMapUpdateCurrentTileBlock().
Definition at line 80 of file field_world_map.c.
fdWorldMapInitPerspective
UNREAD_RESULT fdWorldMapInitPerspective(void)
Sets up the world map's perspective view: BG2 and BG3 in affine mode, the
camera state, the projection, the per-scanline ground plane function in RAM
(fdWorldMapUpdateAffineLines) and its first tick, and the per-tick view and
HBlank updates.
References BgScrollWork, fdIOWrite16Inline(), fdTilesetAnimationStartAll(), fdWorldMapApplyAffinePage(), fdWorldMapBuildScanlineTable(), fdWorldMapUpdateAffineLines(), fdWorldMapUpdateAffineLinesCodeSize, fdWorldMapUpdateView(), HeapSlots, ProjectionWork, ScanlineAngle, ScanlinePitch, Sint32, syCalcPoint(), syCos(), syDecompressTaggedLZ(), syDivFX(), syHeapSlotAllocate(), syHeapSlotAllocateEWRAM(), syInitMatrix(), syLookAtLoad(), syMatrixTranslateVector(), syResourceGetTableEntry(), syRotX(), syRotY(), syScreenFadeFromBlack(), sySetEvent(), sySetScreenDist(), sySin() and TickCount.
Definition at line 157 of file field_world_map.c.
fdWorldMapSetGridTile
void fdWorldMapSetGridTile(Sint32 x, Sint32 y, Sint32 metatileX, Sint32 metatileY)
Changes one 512-pixel tile of the world map: the grid cell holding 32-pixel metatile (metatileX, metatileY) shows tile (y / 16) * 16 + x / 16 from now on (the broken bridge south of Vault is tile 264 in cell 11 by 3). The tile is drawn at once when the cell is within 256 pixels of the followed point; otherwise it is loaded as the view reaches it.
References fdWorldMapWriteLayerMetatileTile() and Sint32.
Referenced by fdSetWorldMapGridTile().
Definition at line 317 of file field_world_map.c.
fdWorldMapLoadGraphics
void fdWorldMapLoadGraphics(Sint32 x, Sint32 z)
Loads the world map's palette and tiles for the area at (x, z): the second
set where the ground there is WORLD_MAP_ENCOUNTER_REGION_SNOWFIELD.
References BgTileBuffer, fdWorldMapUpdateCurrentTileBlock(), MapGridAnimationTiles, Sint32, syDecompressByteLZ(), syDecompressTaggedLZ(), syDMAXCopy(), syHeapAllocate(), syHeapRelease(), syResourceGetTableEntry() and WorldMapGraphicsResources.
Definition at line 361 of file field_world_map.c.
fdWorldMapApplyAffinePage
void fdWorldMapApplyAffinePage(void)
HBlank setup each VBlank 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.
References Sint32, syDMAXCopy() and TickCount.
Referenced by fdWorldMapInitPerspective().
Definition at line 455 of file field_world_map.c.
fdWorldMapCopyMetatileTiles
static __inline__ void fdWorldMapCopyMetatileTiles(Uint8 *metatileBytes, Uint8 *screenTile)
Copies one world map metatile's two tile entries (top and bottom) to a BG map.
Referenced by fdWorldMapDrawMetatileColumn() and fdWorldMapDrawMetatileRow().
Definition at line 522 of file field_world_map.c.
fdWorldMapDrawMetatileRow
void fdWorldMapDrawMetatileRow(Uint32 tileRow)
Draws row tileRow of the metatile buffer into both layers' BG maps, 32
metatiles in each: the row of the ground that scrolls into view.
References fdWorldMapCopyMetatileTiles(), Sint32 and tileRow.
Referenced by fdWorldMapUpdateView().
Definition at line 535 of file field_world_map.c.
fdWorldMapDrawMetatileColumn
void fdWorldMapDrawMetatileColumn(Uint32 tileColumn)
Draws column tileColumn of the metatile buffer into both layers' BG maps, 32
metatiles down in each (the second layer's map and metatiles follow the
first's): the column of the ground that scrolls into view.
References fdWorldMapCopyMetatileTiles(), Sint32 and tileColumn.
Referenced by fdWorldMapUpdateView().
Definition at line 569 of file field_world_map.c.
fdWorldMapUpdateView
void fdWorldMapUpdateView(void)
Each tick 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.
References fdWorldMapBuildScanlineTable(), fdWorldMapDrawMetatileColumn(), fdWorldMapDrawMetatileRow(), fdWorldMapPreloadCurrentTileBlock(), HeapSlots, ProjectionWork, ScanlineAngle, ScanlinePitch, Sint32, syCalcPoint(), syCos(), syDivFX(), syInitMatrix(), syLookAtLoad(), syMatrixTranslateVector(), syMulFX(), syRandom(), syRotX(), syRotY(), sySetScreenDist(), sySin(), TickCount, tileColumn and tileRow.
Referenced by fdWorldMapInitPerspective().
Definition at line 590 of file field_world_map.c.
fdWorldMapUpdateCurrentTileBlock
void fdWorldMapUpdateCurrentTileBlock(void)
Loads and draws the 2x2 world map tiles around the player in both layers.
References fdWorldMapWriteLayerMetatileTile() and Sint32.
Referenced by fdWorldMapLoadAreaGraphics(), fdWorldMapLoadDefaultMetatilesAndUpdateBlock() and fdWorldMapLoadGraphics().
Definition at line 692 of file field_world_map.c.
fdWorldMapPreloadCurrentTileBlock
void fdWorldMapPreloadCurrentTileBlock(void)
Loads the first of the 2x2 world map tiles around the player that is not shown yet (at most one a tick), without drawing it.
References fdWorldMapWriteLayerMetatileTile() and Sint32.
Referenced by fdWorldMapUpdateView().
Definition at line 741 of file field_world_map.c.
fdWorldMapPresentStillImage
void fdWorldMapPresentStillImage(void)
VBlank: shows BG1 and copies the decoded picture's tiles into VRAM.
References MapGridMetatileBuffer and syDMAXCopy().
Referenced by fdWorldMapStartStillImage().
Definition at line 785 of file field_world_map.c.
fdWorldMapStartStillImage
void fdWorldMapStartStillImage(void)
Freezes the world map's perspective view as a still image on BG1: saves BG1's tiles, draws the current affine frame into pixels and hands the window and VBlank to it.
References DecodeBuffer, fdTileMapDrawRowsFromRam(), fdTilesetAnimationUpdate(), fdWorldMapPresentStillImage(), MapGridMetatileBuffer, syDMAXCopy(), sySuspendEvent(), sySynch(), TickCount and UserFunction().
Referenced by scWorldMapPlayLighthouseTransition().
Definition at line 798 of file field_world_map.c.
fdWorldMapEndStillImage
void fdWorldMapEndStillImage(void)
VBlank at the end of the still image: puts BG1 back as the plain layer and copies the area's four tile sets back into char blocks 2 and 3.
References BgTileBuffer and syDMAXCopy().
Referenced by fdWorldMapLoadAreaGraphics() and fdWorldMapLoadDefaultMetatilesAndUpdateBlock().
Definition at line 820 of file field_world_map.c.
fdWorldMapLoadAreaGraphics
void fdWorldMapLoadAreaGraphics(void)
Reloads the world map area's palette and tiles after the still image, puts the default metatiles back and returns to the perspective view.
References BgTileBuffer, fdTilesetAnimationUpdate(), fdWorldMapEndStillImage(), fdWorldMapUpdateCurrentTileBlock(), MapGridMetatileBuffer, syDecompressByteLZ(), syDecompressTaggedLZ(), syDMAXCopy(), syResourceGetTableEntry(), syResumeEvent(), sySynch() and UserFunction().
Referenced by scWorldMapPlayLighthouseTransition().
Definition at line 831 of file field_world_map.c.
fdWorldMapLoadDefaultMetatilesAndUpdateBlock
void fdWorldMapLoadDefaultMetatilesAndUpdateBlock(void)
Puts the default world map metatiles back after the still image and returns to the perspective view, without reloading the area's palette or tiles.
References fdTilesetAnimationUpdate(), fdWorldMapEndStillImage(), fdWorldMapUpdateCurrentTileBlock(), MapGridMetatileBuffer, syDecompressTaggedLZ(), syResourceGetTableEntry(), syResumeEvent(), sySynch() and UserFunction().
Referenced by scWorldMapShowEndingScript().
Definition at line 874 of file field_world_map.c.