Layered maps: loading, drawing and scrolling, and copying cells. More...
Go to the source code of this file.
Data Structures | |
| struct | LayeredSceneEntry |
| A row of gMap_LayeredScenes: a layered map's resources, counted from ResourceId_Map001: its header, palette, three tile sheets and layer data. More... | |
| struct | LayeredSceneLayer |
| One background layer's setup in a layered map's header: its origin, its parallax and drift, and where it wraps. More... | |
| struct | LayeredSceneHeader |
| A layered map's header: the camera's bounds, the layers' priorities, tile bases and setup, and the offsets of its packed tiles, collision, tilemap, tile animation, blend script and marker list. More... | |
| struct | MapTilePos |
| The top left of a layer's visible area, in cells. More... | |
| struct | MapCopyCommand |
| One step of a map edit sequence: the rectangle of cells to copy from and the wait after it. More... | |
Macros | |
| #define | MAP_CELLS ((u32 *)gMapCellBuffer) |
| #define | MAP_CELL_TILE_MASK 0x00000fff |
| the block (metatile) number | |
| #define | MAP_CELL_ATTRIBUTE_MASK 0xfffff000 |
| the cell's attributes | |
Typedefs | |
| typedef void(*) | TilemapConvertFn(void *dst, const void *src, const void *saved) |
| typedef char | MapCopyCommandSize[(sizeof(struct MapCopyCommand)==10) ? 1 :-1] |
Functions | |
| void | Runtime_RemapBytesByTable (u8 *bytes, s32 byteCount) |
| Remaps byteCount bytes in place through gRuntime_ByteRemapTable. | |
| void | Tilemap_DecodeStagedBuffer (s32 size) |
| Unpacks the staged block data into gMapBlocks. | |
| UNUSED void | Tilemap_NumberPlaceholderBlocks (void) |
| Gives each map cell whose block number is 0xfff (a placeholder) a number of its own, counting up from 0 in map order. | |
| void | Tilemap_ConvertBuffer (void) |
| Converts the map's cells in place with Tile_ConvertMap, run from RAM, from a saved copy of the staged buffer. | |
| static __inline__ void | Map_CopyMetatileHalfColumn (u32 *cell, u8 *screenMap, u32 screenRowOffset, u32 screenColumnOffset, u32 tileHalf) |
| Copies one tile column of a block (metatile) into a BG map: its top and bottom tile entries, choosing the left or right half with tileHalf. | |
| static __inline__ void | Map_CopyMetatileToScreen (u32 *cell, u8 *screenMap, u32 screenRowOffset, u32 screenColumnOffset) |
| Copies a whole block (metatile) into a BG map: its top two tile entries and its bottom two, a map row (64 bytes) below. | |
| s32 | Map_LoadLayeredScene (s32 index) |
| Loads layered scene index from gMap_LayeredScenes: its blocks, collision, cells, tile animations, blend script and marker list; sets up the three background layers' origins, parallax and wrap from the scene header; loads the palette and tile graphics unless FLAG_KEEP_LAYER_GRAPHICS says they are loaded; and starts the layer scrolling. | |
| void | Map_CenterOnFollowedPoint (void) |
| Centres the camera on the point the map follows (origin: x, height, z), or on (0, 0) when there is none, and scrolls the layers there. | |
| void | Map_RenderMetatileRow (u32 layer, s32 tileX, s32 tileY) |
| Draws a row of 16 blocks (32 tiles) of a layer's cells into its BG map (screen block 5 + layer), starting at tile (tileX, tileY); the BG map wraps every 32 tiles. | |
| void | Map_RenderMetatileColumn (u32 layer, s32 tileX, s32 tileY) |
| Draws a column of 11 blocks of a layer's cells, one tile wide, into its BG map, starting at tile (tileX, tileY). | |
| void | Map_UpdateLayerScroll (void) |
| Each frame on a layered map: centres the view on the point the map follows (origin), clamped to the map's bounds and shaken by any decaying screen shake; then scrolls each of the three layers by its parallax scale and automatic scroll (wrapping at its period), draws the block column or row that scrolls into view, and sets its BG scroll. | |
| void | Map_SetCameraCenter (s32 x, s32 y) |
| Centres the view on (x, y) in 16.16 pixels, clamped to the map's bounds, and redraws every enabled layer's BG map around it. | |
| void | Map_CopyMetatileIndicesRect (s32 srcX, s32 srcY, u32 dstX, u32 dstY, u32 width, u32 height) |
| Copies the block numbers of a rectangle of cells from (srcX, srcY) to (dstX, dstY), width by height cells, keeping each destination's attributes, and redraws the copied cells that are on screen. | |
| void | Map_PlayMetatileCopySequence (u16 *sequence, s32 destinationX, u32 destinationY) |
| Plays a map edit sequence (struct MapCopyCommand records, ended by a source of 0xffff): copies each record's rectangle of block numbers to (destinationX, destinationY) and waits its delay in frames. | |
| void | Map_CopyMetatileCellsRect (s32 srcX, s32 srcY, s32 width, s32 height, s32 dstX, s32 dstY) |
| Copies a rectangle of cells (16x16 pixels each) as they are, from (srcX, srcY) to (dstX, dstY), width by height cells. | |
| void | Map_CopyCellAttributeRect (s32 srcX, s32 srcY, s32 width, s32 height, s32 dstX, s32 dstY) |
| Copies only the attributes of a rectangle of cells, from (srcX, srcY) to (dstX, dstY), width by height cells, keeping each destination cell's block number. | |
| void | Map_CopyCellIndexRect (s32 srcX, s32 srcY, s32 width, s32 height, s32 dstX, s32 dstY) |
| Copies only the block numbers of a rectangle of cells, from (srcX, srcY) to (dstX, dstY), width by height cells, keeping each destination cell's attributes; cells in a visible area update the BG maps too. | |
| void | Map_SetShownLayers (u32 layerFlags) |
| Sets which of BG1-BG3 the map shows (bits 9-11 of its display flags, as in REG_DISPCNT) from layerFlags, keeping its other flags. | |
Variables | |
| struct LayeredSceneEntry | gMap_LayeredScenes [] |
Layered maps: loading, drawing and scrolling, and copying cells.
Part of field.c, the field object, compiled only through it.
Definition in file map_layers.c.
| #define MAP_CELLS ((u32 *)gMapCellBuffer) |
Definition at line 794 of file map_layers.c.
Referenced by Map_CopyCellAttributeRect(), MercuryLighthouse_HopAcrossPool(), and ObjectTable_ResetForObject().
| #define MAP_CELL_TILE_MASK 0x00000fff |
the block (metatile) number
Definition at line 795 of file map_layers.c.
Referenced by Map_CopyCellAttributeRect(), and Map_CopyCellIndexRect().
| #define MAP_CELL_ATTRIBUTE_MASK 0xfffff000 |
the cell's attributes
Definition at line 796 of file map_layers.c.
Referenced by Map_CopyCellAttributeRect(), and Map_CopyCellIndexRect().
| typedef void(*) TilemapConvertFn(void *dst, const void *src, const void *saved) |
Definition at line 80 of file map_layers.c.
| typedef char MapCopyCommandSize[(sizeof(struct MapCopyCommand)==10) ? 1 :-1] |
Definition at line 738 of file map_layers.c.
Remaps byteCount bytes in place through gRuntime_ByteRemapTable.
Called through Runtime_RemapBytesByTableFar by RenderResource_LoadFrame, which remaps the colours of a command icon's first 768 bytes.
Definition at line 10 of file map_layers.c.
Referenced by Runtime_RemapBytesByTable().
| void Tilemap_DecodeStagedBuffer | ( | s32 | size | ) |
Unpacks the staged block data into gMapBlocks.
Byte 1 of the staged buffer (Ram_MapCellBuffer) is the method, and the 16-bit data follows from byte 2. size counts the method byte too (an even size means no data). Methods: 0: copy as it is 1: all the high bytes, then all the low bytes; each value is XORed with the one before 2: each value is XORed with the one before
Called by Map_LoadLayeredScene with the size Resource_DecodeType01 returns; the packed stream is decoded to Ram_MapCellBuffer + 1 so that its method byte lands at byte 1 and the halfwords at byte 2 are aligned.
Definition at line 39 of file map_layers.c.
Referenced by Map_LoadLayeredScene(), and Tilemap_DecodeStagedBuffer().
| UNUSED void Tilemap_NumberPlaceholderBlocks | ( | void | ) |
Gives each map cell whose block number is 0xfff (a placeholder) a number of its own, counting up from 0 in map order.
Definition at line 84 of file map_layers.c.
Referenced by Tilemap_NumberPlaceholderBlocks().
| void Tilemap_ConvertBuffer | ( | void | ) |
Converts the map's cells in place with Tile_ConvertMap, run from RAM, from a saved copy of the staged buffer.
Called by Map_LoadLayeredScene once the cell planes are decoded. Copies the first 32 KB of Ram_MapCellBuffer to a block from the alternate pool and loads the routine into RAM; frees both when done.
Definition at line 110 of file map_layers.c.
Referenced by Map_LoadLayeredScene(), and Tilemap_ConvertBuffer().
|
static |
Copies one tile column of a block (metatile) into a BG map: its top and bottom tile entries, choosing the left or right half with tileHalf.
Definition at line 126 of file map_layers.c.
Referenced by Map_CopyMetatileHalfColumn(), and Map_RenderMetatileColumn().
|
static |
Copies a whole block (metatile) into a BG map: its top two tile entries and its bottom two, a map row (64 bytes) below.
Definition at line 146 of file map_layers.c.
Referenced by Map_CopyMetatileToScreen(), and Map_SetCameraCenter().
Loads layered scene index from gMap_LayeredScenes: its blocks, collision, cells, tile animations, blend script and marker list; sets up the three background layers' origins, parallax and wrap from the scene header; loads the palette and tile graphics unless FLAG_KEEP_LAYER_GRAPHICS says they are loaded; and starts the layer scrolling.
Returns 2.
Called through Map_LoadLayeredSceneFar when a scene with a layered map starts (index is gGameState.map). Allocates and clears the map work in HEAP_SLOT_MAP; writes the BG palette (keeping the backdrop colour), char blocks 1 to 3, gMapLayerData, BG1CNT to BG3CNT, REG_MOSAIC, REG_BLDCNT and REG_DISPCNT; and registers Map_UpdateLayerScroll with the scheduler.
Definition at line 211 of file map_layers.c.
Referenced by Map_LoadLayeredScene().
| void Map_CenterOnFollowedPoint | ( | void | ) |
Centres the camera on the point the map follows (origin: x, height, z), or on (0, 0) when there is none, and scrolls the layers there.
Called through Map_CenterOnFollowedPointFar when a layered scene starts, by the camera event commands after they move the camera, and by about 35 scene scripts through Engine_MapRedraw.
Definition at line 387 of file map_layers.c.
Referenced by Map_CenterOnFollowedPoint().
Draws a row of 16 blocks (32 tiles) of a layer's cells into its BG map (screen block 5 + layer), starting at tile (tileX, tileY); the BG map wraps every 32 tiles.
Called by Map_UpdateLayerScroll when a layer scrolls onto a new row of blocks.
Definition at line 411 of file map_layers.c.
Referenced by Map_RenderMetatileRow(), and Map_UpdateLayerScroll().
Draws a column of 11 blocks of a layer's cells, one tile wide, into its BG map, starting at tile (tileX, tileY).
Called by Map_UpdateLayerScroll when a layer scrolls onto a new column of tiles; tileX's low bit picks the block's left or right half.
Definition at line 443 of file map_layers.c.
Referenced by Map_RenderMetatileColumn(), and Map_UpdateLayerScroll().
| void Map_UpdateLayerScroll | ( | void | ) |
Each frame on a layered map: centres the view on the point the map follows (origin), clamped to the map's bounds and shaken by any decaying screen shake; then scrolls each of the three layers by its parallax scale and automatic scroll (wrapping at its period), draws the block column or row that scrolls into view, and sets its BG scroll.
Registered with the scheduler by Map_LoadLayeredScene (priority 0xc85), and called by Map_CenterOnFollowedPoint. Sets work->viewX and viewY, decays work->shakeX and shakeY, advances each drifting layer's phase, and writes each layer's position and gBgScroll entry.
Definition at line 474 of file map_layers.c.
Referenced by Map_CenterOnFollowedPoint(), Map_LoadLayeredScene(), and Map_UpdateLayerScroll().
Centres the view on (x, y) in 16.16 pixels, clamped to the map's bounds, and redraws every enabled layer's BG map around it.
Called by Map_CenterOnFollowedPoint. Sets work->viewX and viewY, and advances each drifting layer's phase by one frame.
Definition at line 572 of file map_layers.c.
Referenced by Map_CenterOnFollowedPoint(), and Map_SetCameraCenter().
Copies the block numbers of a rectangle of cells from (srcX, srcY) to (dstX, dstY), width by height cells, keeping each destination's attributes, and redraws the copied cells that are on screen.
It does what Map_CopyCellIndexRect does, with the destination before the size.
Called by Map_PlayMetatileCopySequence, and by about 40 scene scripts through Map_CopyMetatileIndicesRectFar (Engine_MapCopyCellsTo).
Definition at line 644 of file map_layers.c.
Referenced by Map_CopyMetatileIndicesRect(), and Map_PlayMetatileCopySequence().
Plays a map edit sequence (struct MapCopyCommand records, ended by a source of 0xffff): copies each record's rectangle of block numbers to (destinationX, destinationY) and waits its delay in frames.
Doors and other changing scenery are drawn this way.
Called by about 30 scene scripts through Map_PlayMetatileCopySequenceFar (Engine_MapAnimateCells); it returns only when the sequence ends, so it blocks the script that calls it.
Definition at line 748 of file map_layers.c.
Referenced by Map_PlayMetatileCopySequence().
Copies a rectangle of cells (16x16 pixels each) as they are, from (srcX, srcY) to (dstX, dstY), width by height cells.
Where a copied cell lies in a layer's visible area (16x12 cells), its block's 2x2 tiles go to that layer's BG map in VRAM too. Called by about 15 scene scripts through Map_CopyMetatileCellsRectFar (Engine_MapCopyCells).
Definition at line 803 of file map_layers.c.
Referenced by Map_CopyMetatileCellsRect().
Copies only the attributes of a rectangle of cells, from (srcX, srcY) to (dstX, dstY), width by height cells, keeping each destination cell's block number.
Nothing is redrawn: the attributes (flags, collision code and shape) do not show. Called by about 65 scene scripts through Map_CopyCellAttributeRectFar (Engine_MapCopyCellAttributes).
Definition at line 923 of file map_layers.c.
Referenced by Map_CopyCellAttributeRect().
Copies only the block numbers of a rectangle of cells, from (srcX, srcY) to (dstX, dstY), width by height cells, keeping each destination cell's attributes; cells in a visible area update the BG maps too.
Called by seven scene scripts through Map_CopyCellIndexRectFar (Engine_MapCopyCellsLayered).
Definition at line 950 of file map_layers.c.
Referenced by Map_CopyCellIndexRect().
| void Map_SetShownLayers | ( | u32 | layerFlags | ) |
Sets which of BG1-BG3 the map shows (bits 9-11 of its display flags, as in REG_DISPCNT) from layerFlags, keeping its other flags.
Called by Lunpa Fortress's scene through Map_SetShownLayersFar (Engine_MapSetWorkFlagBits9To11).
Definition at line 1050 of file map_layers.c.
Referenced by Map_SetShownLayers().
|
extern |
Referenced by Map_LoadLayeredScene().