src/field/field_world_map.c
The world map: its perspective view, its tiles, and drawing its metatiles into a BG map. More…
#include "battle/battle_camera.h"#include "field/world_map.h"#include "window/window.h"#include "graphics/palette_buffers.h"
Included by field.c.
Macros
| Name | Description | |
|---|---|---|
#define | WORLD_MAP_BG_PALETTE ((Sint16 *)BG_PLTT) | |
#define | WORLD_MAP_TILE (coordinate) ((coordinate) >> 25) | A world map tile is 512 pixels square: WORLD_MAP_TILE gives the tile a 16.16 coordinate lies in, as FIELD_METATILE a map grid metatile. |
#define | WORLD_MAP_TILES_ACROSS 32 | |
#define | WORLD_MAP_LAYER_TILES 1024 | |
#define | WORLD_MAP_TILE_INDEX (x, y) | The tile id grid's entry (WORLD_MAP_VIEW.tileIds) for the tile at column x and row y, wrapping. |
#define | WORLD_MAP_WIDE_TILES 128 | WORLD_MAP_VIEW.wideTiles, MAP_STATE's wideTiles on the world map: its tileset animations copy 64-byte tiles of 256 colours, into char block 2. |
#define | WORLD_MAP_REGION_GROUP 10 | The world map's encounter regions come in groups of ten; three of the groups are drawn with a graphics set of their own, the rest with the default one. |
#define | STILL_IMAGE_TILES_ACROSS 32 | The still image on BG1 (fdWorldMapStartStillImage): 32 by 20 of the map screen's tiles, from its fifth row on. |
#define | STILL_IMAGE_TILE_ROWS 20 | |
#define | STILL_IMAGE_FIRST_TILE | |
#define | STILL_IMAGE_WINDOW_TOP 200 | While the still image shows, the perspective's window lies below the screen, so no line is drawn in perspective. |
#define | STILL_IMAGE_WINDOW_BOTTOM 255 | |
#define | WORLD_MAP_SET_TILE (view, x, y, tile) | Has view's tile id grid show world map tile number tile at column x and row y from now on. |
Enumerations
| Name | Description | |
|---|---|---|
enum | WORLD_MAP_GRAPHICS { WORLD_MAP_GRAPHICS_DEFAULT, WORLD_MAP_GRAPHICS_SNOWFIELD, WO … } | The world map's four graphics sets, the rows of WorldMapGraphicsResources. |
enum | WORLD_MAP_REGION_KIND { WORLD_MAP_REGIONS_TROPICAL, WORLD_MAP_REGIONS_BLIZZARD, WORL … } | |
enum | WORLD_MAP_GRAPHICS_RESOURCE { WORLD_MAP_SET_PALETTE, WORLD_MAP_SET_ANIMATION, WORLD_MAP_SE … } | A world map graphics set, a row of WorldMapGraphicsResources: its palette, tileset animation script, metatile tiles attributes and six tile sets. |
Functions
| Name | Description | |
|---|---|---|
static inline Sint32 | fdWorldMapGetRegionGroupGraphics (Sint32 group) | The graphics set a group of world map regions is drawn with. |
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 | fdWorldMapSetWindowMetatileTile (Sint32 x, Sint32 y, Sint32 metatileX, Sint32 metatileY) | Puts world map tile (x / 16, y / 16) at metatile (metatileX / 16, metatileY / 16) of the tile id grid, and draws it at once when it is next to the view. metatileX and metatileY count 32-pixel world map blocks, so a grid metatile is a 512-pixel tile; it is next to the view when metatileX / 8 and metatileY / 8, in 256-pixel steps, are within one step of the followed point's. |
void | fdWorldMapSetWindowMetatileTileAndDraw (Sint32 x, Sint32 y, Sint32 metatileX, Sint32 metatileY) | fdWorldMapSetWindowMetatileTile without its view test: puts world map tile (x / 16, y / 16) at metatile (metatileX / 16, metatileY / 16) of the tile grid and draws it in both layers. |
void | fdWorldMapLoadGraphics (Sint32 x, Sint32 z) | Loads the world map's palette and tiles for the area at (x, z): the set its region picks, its tint, and the plain BG maps the world map draws over. |
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 tiles to a tile map: its top two, then its bottom two on the row below. |
void | fdWorldMapDrawMetatileRow (Uint32 tileRow) | Draws the metatiles of the world map's tile row tileRow into its tile maps: the lower layer's 32 metatiles, then the upper layer's. |
void | fdWorldMapDrawMetatileColumn (Uint32 tileColumn) | Draws the metatiles of the world map's tile column tileColumn into its tile maps: 64 metatiles down, the lower layer's 32 and then the upper layer's, which follow them in the tile maps and in the metatiles. |
void | fdWorldMapUpdateView (void) | Each tick: follows the followed point with the screen shake, draws the rows and columns that came into view, and recomputes the projection and the ground plane for the current pitch and yaw; while the still image shows, only BG1 shakes. |
void | fdWorldMapUpdateCurrentTileBlock (void) | Loads and draws the 2x2 world map tiles around the player in both layers. |
Description
The world map: its perspective view, its tiles, and drawing its metatiles
into a BG map. 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 9 of file field_world_map.c.
WORLD_MAP_TILE
#define WORLD_MAP_TILE(coordinate) ((coordinate) >> 25)
A world map tile is 512 pixels square: WORLD_MAP_TILE gives the tile a 16.16
coordinate lies in, as FIELD_METATILE a map grid metatile. The world map is
32 by 32 tiles, wrapping, and each layer's tile numbers follow the 1024
before it.
Referenced by fdWorldMapPreloadCurrentTileBlock() and fdWorldMapUpdateCurrentTileBlock().
Definition at line 15 of file field_world_map.c.
WORLD_MAP_TILES_ACROSS
#define WORLD_MAP_TILES_ACROSS 32
Referenced by fdWorldMapInitPerspective().
Definition at line 16 of file field_world_map.c.
WORLD_MAP_LAYER_TILES
#define WORLD_MAP_LAYER_TILES 1024
Referenced by fdWorldMapPreloadCurrentTileBlock(), fdWorldMapSetWindowMetatileTile(), fdWorldMapSetWindowMetatileTileAndDraw() and fdWorldMapUpdateCurrentTileBlock().
Definition at line 17 of file field_world_map.c.
WORLD_MAP_TILE_INDEX
#define WORLD_MAP_TILE_INDEX(x, y)
The tile id grid's entry (WORLD_MAP_VIEW.tileIds) for the tile at column x
and row y, wrapping.
Referenced by fdWorldMapPreloadCurrentTileBlock() and fdWorldMapUpdateCurrentTileBlock().
Definition at line 20 of file field_world_map.c.
WORLD_MAP_WIDE_TILES
#define WORLD_MAP_WIDE_TILES 128
WORLD_MAP_VIEW.wideTiles, MAP_STATE's wideTiles on the world map: its tileset
animations copy 64-byte tiles of 256 colours, into char block 2.
Referenced by fdWorldMapInitPerspective().
Definition at line 26 of file field_world_map.c.
WORLD_MAP_REGION_GROUP
#define WORLD_MAP_REGION_GROUP 10
The world map's encounter regions come in groups of ten; three of the groups are drawn with a graphics set of their own, the rest with the default one.
Referenced by fdWorldMapLoadGraphics() and fdWorldMapPreloadCurrentTileBlock().
Definition at line 42 of file field_world_map.c.
STILL_IMAGE_TILES_ACROSS
#define STILL_IMAGE_TILES_ACROSS 32
The still image on BG1 (fdWorldMapStartStillImage): 32 by 20 of the map
screen's tiles, from its fifth row on.
Referenced by fdWorldMapLoadGraphics() and fdWorldMapPresentStillImage().
Definition at line 80 of file field_world_map.c.
STILL_IMAGE_TILE_ROWS
#define STILL_IMAGE_TILE_ROWS 20
Referenced by fdWorldMapLoadGraphics() and fdWorldMapPresentStillImage().
Definition at line 81 of file field_world_map.c.
STILL_IMAGE_FIRST_TILE
#define STILL_IMAGE_FIRST_TILE
Referenced by fdWorldMapLoadGraphics() and fdWorldMapPresentStillImage().
Definition at line 82 of file field_world_map.c.
STILL_IMAGE_WINDOW_TOP
#define STILL_IMAGE_WINDOW_TOP 200
While the still image shows, the perspective's window lies below the screen, so no line is drawn in perspective.
Referenced by fdWorldMapApplyAffinePage() and fdWorldMapStartStillImage().
Definition at line 86 of file field_world_map.c.
STILL_IMAGE_WINDOW_BOTTOM
#define STILL_IMAGE_WINDOW_BOTTOM 255
Referenced by fdWorldMapStartStillImage().
Definition at line 87 of file field_world_map.c.
WORLD_MAP_SET_TILE
#define WORLD_MAP_SET_TILE(view, x, y, tile)
Has view's tile id grid show world map tile number tile at column x and row y from now on.
Referenced by fdWorldMapSetWindowMetatileTile() and fdWorldMapSetWindowMetatileTileAndDraw().
Definition at line 234 of file field_world_map.c.
Enumerations in detail
WORLD_MAP_GRAPHICS
enum WORLD_MAP_GRAPHICS
The world map's four graphics sets, the rows of WorldMapGraphicsResources.
| Enumerator | Value | Description |
|---|---|---|
WORLD_MAP_GRAPHICS_DEFAULT | the green lands, deserts and mountains | |
WORLD_MAP_GRAPHICS_SNOWFIELD | Snow and ice: Kalt Island, the Northern Reaches, Tundaria. | |
WORLD_MAP_GRAPHICS_TROPICAL | Palm-covered islands in the seas at the world's edges, the Apojii Islands among them. | |
WORLD_MAP_GRAPHICS_BLIZZARD | Prox and Mars Lighthouse, snow falling. |
Definition at line 29 of file field_world_map.c.
WORLD_MAP_REGION_KIND
enum WORLD_MAP_REGION_KIND
| Enumerator | Value | Description |
|---|---|---|
WORLD_MAP_REGIONS_TROPICAL | 2 | |
WORLD_MAP_REGIONS_BLIZZARD | 3 | |
WORLD_MAP_REGIONS_SNOWFIELD | 4 |
Definition at line 44 of file field_world_map.c.
WORLD_MAP_GRAPHICS_RESOURCE
enum WORLD_MAP_GRAPHICS_RESOURCE
A world map graphics set, a row of WorldMapGraphicsResources: its palette,
tileset animation script, metatile tiles attributes and six tile sets.
| Enumerator | Value | Description |
|---|---|---|
WORLD_MAP_SET_PALETTE | ||
WORLD_MAP_SET_ANIMATION | ||
WORLD_MAP_SET_METATILE_ATTRIBUTES | ||
WORLD_MAP_SET_TILES_1 | ||
WORLD_MAP_SET_TILES_2 | ||
WORLD_MAP_SET_TILES_3 | ||
WORLD_MAP_SET_TILES_4 | ||
WORLD_MAP_SET_TILES_5 | ||
WORLD_MAP_SET_TILES_6 |
Definition at line 65 of file field_world_map.c.
Functions in detail
fdWorldMapGetRegionGroupGraphics
static inline Sint32 fdWorldMapGetRegionGroupGraphics(Sint32 group)
The graphics set a group of world map regions is drawn with.
References Sint32.
Referenced by fdWorldMapLoadGraphics() and fdWorldMapPreloadCurrentTileBlock().
Definition at line 52 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, fdWorldMapApplyAffinePage(), fdWorldMapBuildScanlineTable(), fdWorldMapUpdateAffineLinesCode, fdWorldMapUpdateAffineLinesCodeSize, fdWorldMapUpdateView(), MapGridMetatileBuffer, MapScene, 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 93 of file field_world_map.c.
fdWorldMapSetWindowMetatileTile
void fdWorldMapSetWindowMetatileTile(Sint32 x, Sint32 y, Sint32 metatileX, Sint32 metatileY)
Puts world map tile (x / 16, y / 16) at metatile (metatileX / 16, metatileY / 16) of the tile id grid, and draws it at once when it is next to the view. metatileX and metatileY count 32-pixel world map blocks, so a grid metatile is a 512-pixel tile; it is next to the view when metatileX / 8 and metatileY / 8, in 256-pixel steps, are within one step of the followed point's.
References fdWorldMapWriteLayerMetatileTile() and Sint32.
Referenced by fdSetWorldMapWindowMetatileTile().
Definition at line 242 of file field_world_map.c.
fdWorldMapSetWindowMetatileTileAndDraw
void fdWorldMapSetWindowMetatileTileAndDraw(Sint32 x, Sint32 y, Sint32 metatileX, Sint32 metatileY)
fdWorldMapSetWindowMetatileTile without its view test: puts world map tile (x
/ 16, y / 16) at metatile (metatileX / 16, metatileY / 16) of the tile grid
and draws it in both layers.
References fdWorldMapWriteLayerMetatileTile() and Sint32.
Referenced by scFieldWorldMapSetWindowMetatileTileAndDraw().
Definition at line 285 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 set its region picks, its tint, and the plain BG maps the world map draws over.
References fdPaletteFadeLoadPaletteStub(), fdTilesetAnimationStartAll(), fdWorldMapGetRegionGroupGraphics(), fdWorldMapUpdateRegionTint(), MapGridAnimationTiles, Sint32, syDecompressByteLZ(), syDecompressTaggedLZ(), syDMAXCopy(), syHeapAllocate(), syHeapRelease(), syResourceGetTableEntry(), WorldMapGraphicsResources and WorldMapStateWork.
Definition at line 327 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 445 of file field_world_map.c.
fdWorldMapCopyMetatileTiles
static __inline__ void fdWorldMapCopyMetatileTiles(Uint8 *metatileBytes, Uint8 *screenTile)
Copies one world map metatile's tiles to a tile map: its top two, then its bottom two on the row below.
Referenced by fdWorldMapDrawMetatileColumn() and fdWorldMapDrawMetatileRow().
Definition at line 511 of file field_world_map.c.
fdWorldMapDrawMetatileRow
void fdWorldMapDrawMetatileRow(Uint32 tileRow)
Draws the metatiles of the world map's tile row tileRow into its tile maps: the lower layer's 32 metatiles, then the upper layer's.
References fdWorldMapCopyMetatileTiles() and Sint32.
Referenced by fdWorldMapUpdateView().
Definition at line 524 of file field_world_map.c.
fdWorldMapDrawMetatileColumn
void fdWorldMapDrawMetatileColumn(Uint32 tileColumn)
Draws the metatiles of the world map's tile column tileColumn into its tile maps: 64 metatiles down, the lower layer's 32 and then the upper layer's, which follow them in the tile maps and in the metatiles.
References fdWorldMapCopyMetatileTiles() and Sint32.
Referenced by fdWorldMapUpdateView().
Definition at line 563 of file field_world_map.c.
fdWorldMapUpdateView
void fdWorldMapUpdateView(void)
Each tick: follows the followed point with the screen shake, draws the rows and columns that came into view, and recomputes the projection and the ground plane for the current pitch and yaw; while the still image shows, only BG1 shakes.
References BgScrollWork, fdWorldMapBuildScanlineTable(), fdWorldMapDrawMetatileColumn(), fdWorldMapDrawMetatileRow(), fdWorldMapPreloadCurrentTileBlock(), ProjectionWork, ScanlineAngle, ScanlinePitch, Sint32, syCalcPoint(), syCos(), syDivFX(), syInitMatrix(), syLookAtLoad(), syMatrixTranslateVector(), syRandom(), syRotX(), syRotY(), sySetScreenDist(), sySin() and TickCount.
Referenced by fdWorldMapInitPerspective().
Definition at line 588 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(), scStaffCreditShowBeacon() and scWorldMapDriftNorthOfContinent().
Definition at line 699 of file field_world_map.c.