Skip to Content
The Alchemy Project

src/field/field_view.c

Screen shake, the copied BG row drawer and the ground plane scanlines. More…

Included by field.c.

Macros

NameDescription
#defineMAPGRID_SHAKE_SETTLE_TICKS 300A wait for a shake to settle gives up after five seconds, and ends once both amplitudes are under 1/256 pixel (16.16).
#defineMAPGRID_SHAKE_SETTLE_MAX_AMPLITUDE (toFIXED(1) / 256 - 1)
#defineWORLD_MAP_TILE_MAP_BYTESOne of the world map's two tile maps of one-byte tiles, BG3's and then BG2's, as fdWorldMapStartStillImage copies them into DecodeBuffer.
#defineWORLD_MAP_BLOCK_BEACH (1 << 7)The bit of a world map block's top byte, its word's bit 31, that makes it a beach.

Typedefs

NameDescription
typedef const WORLD_MAP_AFFINE_PAIR *(*TILE_MAP_ROW_DRAWER )( const WORLD_MAP_AFFINE_PAIR *lines, Uint8 *pixels, const Uint8 *tiles, const Uint8 *map);The ARM function copied to RAM reads the BG2 affine row from each 32-byte pair and writes 240 by 160 pixels as 256-colour tiles; it returns the address past the last pair, where its row cursor stops.

Enumerations

NameDescription
enumTERRAIN_BEHAVIOR_ROWS { TERRAIN_ROWS_PLAIN, TERRAIN_ROWS_BEACH, TERRAIN_ROWS_SNOWFIE … }The sets of rows of WorldMapTerrainBehaviorTable, 16 collision values each, which differ in the battles their walkable ground and forest give.
enumanonymous enum { AIRS_ROCK_DESERT_REGION, SHAMAN_VILLAGE_SANDS_REGION, PROX_B … }The encounter regions (WORLD_MAP_METATILE.region) whose blocks take rows of their own.

Functions

NameDescription
Uint8fdWorldMapGetBattleEnvironment (WORLD_POS *pos, Sint32 *encounterRegion)Returns the world map's battle environment at position from WorldMapTerrainBehaviorTable, by its collision value and its block's rows, and stores the block's encounter region in encounterRegion.
voidfdMapGridSetScreenShake (FIXED shakeX, FIXED shakeY, FIXED shakeDecay)Changes the shake without restarting an axis whose argument is negative.
voidfdMapGridWaitForShakeToSettle (void)Waits until both shake amplitudes are below 1/256 pixel, with a 300-tick limit for a shake whose decay never settles.
voidfdTileMapDrawRowsFromRam (const WORLD_MAP_AFFINE_PAIR *lines, Uint8 *pixels)Draws the current affine page into the world map's still-image pixels.
voidfdWorldMapBuildScanlineTable (FIXED pitchSlope, Sint32 *pos, WORLD_MAP_SCANLINE *scanline)Rebuilds the ground plane's scanline terms when the world map pitch changes.

Description

Screen shake, the copied BG row drawer and the ground plane scanlines. Part of field.c.

Macros in detail

MAPGRID_SHAKE_SETTLE_TICKS

#define MAPGRID_SHAKE_SETTLE_TICKS 300

A wait for a shake to settle gives up after five seconds, and ends once both amplitudes are under 1/256 pixel (16.16).

Referenced by fdMapGridWaitForShakeToSettle().

Definition at line 6 of file field_view.c.

MAPGRID_SHAKE_SETTLE_MAX_AMPLITUDE

#define MAPGRID_SHAKE_SETTLE_MAX_AMPLITUDE (toFIXED(1) / 256 - 1)

Referenced by fdMapGridWaitForShakeToSettle().

Definition at line 7 of file field_view.c.

WORLD_MAP_TILE_MAP_BYTES

#define WORLD_MAP_TILE_MAP_BYTES

One of the world map's two tile maps of one-byte tiles, BG3's and then BG2's, as fdWorldMapStartStillImage copies them into DecodeBuffer.

Referenced by fdTileMapDrawRowsFromRam().

Definition at line 10 of file field_view.c.

WORLD_MAP_BLOCK_BEACH

#define WORLD_MAP_BLOCK_BEACH (1 << 7)

The bit of a world map block's top byte, its word's bit 31, that makes it a beach.

Referenced by fdWorldMapGetBattleEnvironment().

Definition at line 15 of file field_view.c.

Typedefs in detail

TILE_MAP_ROW_DRAWER

typedef const WORLD_MAP_AFFINE_PAIR *(*TILE_MAP_ROW_DRAWER)( const WORLD_MAP_AFFINE_PAIR *lines, Uint8 *pixels, const Uint8 *tiles, const Uint8 *map);

The ARM function copied to RAM reads the BG2 affine row from each 32-byte pair and writes 240 by 160 pixels as 256-colour tiles; it returns the address past the last pair, where its row cursor stops.

Referenced by fdTileMapDrawRowsFromRam().

Definition at line 122 of file field_view.c.

Enumerations in detail

TERRAIN_BEHAVIOR_ROWS

enum TERRAIN_BEHAVIOR_ROWS

The sets of rows of WorldMapTerrainBehaviorTable, 16 collision values each, which differ in the battles their walkable ground and forest give.

EnumeratorValueDescription
TERRAIN_ROWS_PLAIN0
TERRAIN_ROWS_BEACH16walkable ground fights on the beach
TERRAIN_ROWS_SNOWFIELD32
TERRAIN_ROWS_DESERT48walkable ground fights in the desert
TERRAIN_ROWS_BLIZZARD64

Definition at line 19 of file field_view.c.

anonymous enum

enum { AIRS_ROCK_DESERT_REGION, SHAMAN_VILLAGE_SANDS_REGION, PROX_BLIZZARD_REGION, SNOWFIELD_REGION_FIRST }

The encounter regions (WORLD_MAP_METATILE.region) whose blocks take rows of their own.

EnumeratorValueDescription
AIRS_ROCK_DESERT_REGION12the desert round Air's Rock
SHAMAN_VILLAGE_SANDS_REGION15the sandy shore north of Shaman Village
PROX_BLIZZARD_REGION36the snow round Prox
SNOWFIELD_REGION_FIRST41and every region after it

Definition at line 30 of file field_view.c.

Functions in detail

fdWorldMapGetBattleEnvironment

Uint8 fdWorldMapGetBattleEnvironment(WORLD_POS *pos, Sint32 *encounterRegion)

Returns the world map's battle environment at position from WorldMapTerrainBehaviorTable, by its collision value and its block's rows, and stores the block's encounter region in encounterRegion.

References fdWorldMapGetCollision(), MetatileTiles, Sint32 and WorldMapTerrainBehaviorTable.

Definition at line 41 of file field_view.c.

fdMapGridSetScreenShake

void fdMapGridSetScreenShake(FIXED shakeX, FIXED shakeY, FIXED shakeDecay)

Changes the shake without restarting an axis whose argument is negative. Amplitudes are 16.16 pixels and decay is a 16.16 multiplier per tick.

Referenced by fdMapGridSetShakeFX(), scInit() and scShrineOfTheSeaGodRiseOnWater().

Definition at line 76 of file field_view.c.

fdMapGridWaitForShakeToSettle

void fdMapGridWaitForShakeToSettle(void)

Waits until both shake amplitudes are below 1/256 pixel, with a 300-tick limit for a shake whose decay never settles.

References Sint32 and sySynch().

Referenced by scAirsRockInsideLandInHall(), scAirsRockInsideReadRevealTablet(), scDehkanPlateauLandFromFall(), scFieldMapGridWaitForShakeToSettle(), scKandoreanTempleLandFromAbove(), scMagmaRockKnockLeaderOffWall(), scSeaOfTimeOpen(), scShamanVillageBlowAwaySand(), scShrineOfTheSeaGodBreakCrossroadsBridge(), scShrineOfTheSeaGodLowerWater() and scTundariaTowerLandFromSlide().

Definition at line 99 of file field_view.c.

fdTileMapDrawRowsFromRam

void fdTileMapDrawRowsFromRam(const WORLD_MAP_AFFINE_PAIR *lines, Uint8 *pixels)

Draws the current affine page into the world map's still-image pixels. fdWorldMapStartStillImage supplies 160 pairs and a 240 by 160 byte output.

References DecodeBuffer, fdRenderDrawMapCode, fdRenderDrawMapCodeSize and syHeapRelease().

Referenced by fdWorldMapStartStillImage().

Definition at line 130 of file field_view.c.

fdWorldMapBuildScanlineTable

void fdWorldMapBuildScanlineTable(FIXED pitchSlope, Sint32 *pos, WORLD_MAP_SCANLINE *scanline)

Rebuilds the ground plane's scanline terms when the world map pitch changes.

References ProjectionWork, Sint32, syCalcPoint(), syDivFX() and sySquartIWRAM().

Referenced by fdWorldMapInitPerspective() and fdWorldMapUpdateView().

Definition at line 143 of file field_view.c.