mirror of https://github.com/pret/pokeemerald.git
Name overworld tilemaps for their bg, add layer type constants
This commit is contained in:
parent
69759b2d12
commit
f127e64a3c
|
@ -1,6 +1,6 @@
|
|||
gBGTilemapBuffers1
|
||||
gBGTilemapBuffers2
|
||||
gBGTilemapBuffers3
|
||||
gOverworldTilemapBuffer_Bg2
|
||||
gOverworldTilemapBuffer_Bg1
|
||||
gOverworldTilemapBuffer_Bg3
|
||||
gHeldKeyCodeToSend
|
||||
gFieldCallback
|
||||
gFieldCallback2
|
||||
|
|
|
@ -9,6 +9,12 @@
|
|||
#define METATILE_COLLISION_SHIFT 10
|
||||
#define METATILE_ELEVATION_MASK 0xF000
|
||||
|
||||
enum {
|
||||
METATILE_LAYER_TYPE_NORMAL, // Metatile uses middle and top bg layers
|
||||
METATILE_LAYER_TYPE_COVERED, // Metatile uses bottom and middle bg layers
|
||||
METATILE_LAYER_TYPE_SPLIT, // Metatile uses bottom and top bg layers
|
||||
};
|
||||
|
||||
#define METATILE_ID(tileset, name) (METATILE_##tileset##_##name)
|
||||
|
||||
// Rows of metatiles do not actually have a strict width.
|
||||
|
|
|
@ -40,20 +40,18 @@ struct LinkPlayerObjectEvent
|
|||
u8 movementMode;
|
||||
};
|
||||
|
||||
// Exported RAM declarations
|
||||
extern struct WarpData gLastUsedWarp;
|
||||
extern struct LinkPlayerObjectEvent gLinkPlayerObjectEvents[4];
|
||||
|
||||
extern u16 *gBGTilemapBuffers1;
|
||||
extern u16 *gBGTilemapBuffers2;
|
||||
extern u16 *gBGTilemapBuffers3;
|
||||
extern u16 *gOverworldTilemapBuffer_Bg2;
|
||||
extern u16 *gOverworldTilemapBuffer_Bg1;
|
||||
extern u16 *gOverworldTilemapBuffer_Bg3;
|
||||
extern u16 gHeldKeyCodeToSend;
|
||||
extern void (*gFieldCallback)(void);
|
||||
extern bool8 (*gFieldCallback2)(void);
|
||||
extern u8 gLocalLinkPlayerId;
|
||||
extern u8 gFieldLinkPlayerCount;
|
||||
|
||||
// Exported ROM declarations
|
||||
extern const struct UCoords32 gDirectionToVectors[];
|
||||
|
||||
void DoWhiteOut(void);
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
EWRAM_DATA bool8 gUnusedBikeCameraAheadPanback = FALSE;
|
||||
|
||||
// Static type declarations
|
||||
struct FieldCameraOffset
|
||||
{
|
||||
u8 xPixelOffset;
|
||||
|
@ -24,18 +23,16 @@ struct FieldCameraOffset
|
|||
bool8 copyBGToVRAM;
|
||||
};
|
||||
|
||||
// static functions
|
||||
static void RedrawMapSliceNorth(struct FieldCameraOffset *cameraOffset, const struct MapLayout *mapLayout);
|
||||
static void RedrawMapSliceSouth(struct FieldCameraOffset *cameraOffset, const struct MapLayout *mapLayout);
|
||||
static void RedrawMapSliceEast(struct FieldCameraOffset *cameraOffset, const struct MapLayout *mapLayout);
|
||||
static void RedrawMapSliceWest(struct FieldCameraOffset *cameraOffset, const struct MapLayout *mapLayout);
|
||||
static s32 MapPosToBgTilemapOffset(struct FieldCameraOffset *a, s32 x, s32 y);
|
||||
static void DrawWholeMapViewInternal(int x, int y, const struct MapLayout *mapLayout);
|
||||
static void DrawMetatileAt(const struct MapLayout *mapLayout, u16, int, int);
|
||||
static void DrawMetatile(s32 a, u16 *b, u16 c);
|
||||
static void RedrawMapSliceNorth(struct FieldCameraOffset *, const struct MapLayout *);
|
||||
static void RedrawMapSliceSouth(struct FieldCameraOffset *, const struct MapLayout *);
|
||||
static void RedrawMapSliceEast(struct FieldCameraOffset *, const struct MapLayout *);
|
||||
static void RedrawMapSliceWest(struct FieldCameraOffset *, const struct MapLayout *);
|
||||
static s32 MapPosToBgTilemapOffset(struct FieldCameraOffset *, s32, s32);
|
||||
static void DrawWholeMapViewInternal(int, int, const struct MapLayout *);
|
||||
static void DrawMetatileAt(const struct MapLayout *, u16, int, int);
|
||||
static void DrawMetatile(s32, u16 *, u16);
|
||||
static void CameraPanningCB_PanAhead(void);
|
||||
|
||||
// IWRAM bss vars
|
||||
static struct FieldCameraOffset sFieldCameraOffset;
|
||||
static s16 sHorizontalCameraPan;
|
||||
static s16 sVerticalCameraPan;
|
||||
|
@ -46,7 +43,6 @@ struct CameraObject gFieldCamera;
|
|||
u16 gTotalCameraPixelOffsetY;
|
||||
u16 gTotalCameraPixelOffsetX;
|
||||
|
||||
// text
|
||||
static void ResetCameraOffset(struct FieldCameraOffset *cameraOffset)
|
||||
{
|
||||
cameraOffset->xTileOffset = 0;
|
||||
|
@ -222,7 +218,7 @@ void DrawDoorMetatileAt(int x, int y, u16 *arr)
|
|||
|
||||
if (offset >= 0)
|
||||
{
|
||||
DrawMetatile(1, arr, offset);
|
||||
DrawMetatile(METATILE_LAYER_TYPE_COVERED, arr, offset);
|
||||
sFieldCameraOffset.copyBGToVRAM = TRUE;
|
||||
}
|
||||
}
|
||||
|
@ -244,66 +240,66 @@ static void DrawMetatileAt(const struct MapLayout *mapLayout, u16 offset, int x,
|
|||
DrawMetatile(MapGridGetMetatileLayerTypeAt(x, y), metatiles + metatileId * 8, offset);
|
||||
}
|
||||
|
||||
static void DrawMetatile(s32 metatileLayerType, u16 *metatiles, u16 offset)
|
||||
static void DrawMetatile(s32 metatileLayerType, u16 *tiles, u16 offset)
|
||||
{
|
||||
switch (metatileLayerType)
|
||||
{
|
||||
case 2: // LAYER_TYPE_
|
||||
case METATILE_LAYER_TYPE_SPLIT:
|
||||
// Draw metatile's bottom layer to the bottom background layer.
|
||||
gBGTilemapBuffers3[offset] = metatiles[0];
|
||||
gBGTilemapBuffers3[offset + 1] = metatiles[1];
|
||||
gBGTilemapBuffers3[offset + 0x20] = metatiles[2];
|
||||
gBGTilemapBuffers3[offset + 0x21] = metatiles[3];
|
||||
gOverworldTilemapBuffer_Bg3[offset] = tiles[0];
|
||||
gOverworldTilemapBuffer_Bg3[offset + 1] = tiles[1];
|
||||
gOverworldTilemapBuffer_Bg3[offset + 0x20] = tiles[2];
|
||||
gOverworldTilemapBuffer_Bg3[offset + 0x21] = tiles[3];
|
||||
|
||||
// Draw transparent tiles to the middle background layer.
|
||||
gBGTilemapBuffers1[offset] = 0;
|
||||
gBGTilemapBuffers1[offset + 1] = 0;
|
||||
gBGTilemapBuffers1[offset + 0x20] = 0;
|
||||
gBGTilemapBuffers1[offset + 0x21] = 0;
|
||||
gOverworldTilemapBuffer_Bg2[offset] = 0;
|
||||
gOverworldTilemapBuffer_Bg2[offset + 1] = 0;
|
||||
gOverworldTilemapBuffer_Bg2[offset + 0x20] = 0;
|
||||
gOverworldTilemapBuffer_Bg2[offset + 0x21] = 0;
|
||||
|
||||
// Draw metatile's top layer to the top background layer.
|
||||
gBGTilemapBuffers2[offset] = metatiles[4];
|
||||
gBGTilemapBuffers2[offset + 1] = metatiles[5];
|
||||
gBGTilemapBuffers2[offset + 0x20] = metatiles[6];
|
||||
gBGTilemapBuffers2[offset + 0x21] = metatiles[7];
|
||||
gOverworldTilemapBuffer_Bg1[offset] = tiles[4];
|
||||
gOverworldTilemapBuffer_Bg1[offset + 1] = tiles[5];
|
||||
gOverworldTilemapBuffer_Bg1[offset + 0x20] = tiles[6];
|
||||
gOverworldTilemapBuffer_Bg1[offset + 0x21] = tiles[7];
|
||||
break;
|
||||
case 1: // LAYER_TYPE_COVERED_BY_OBJECTS
|
||||
case METATILE_LAYER_TYPE_COVERED:
|
||||
// Draw metatile's bottom layer to the bottom background layer.
|
||||
gBGTilemapBuffers3[offset] = metatiles[0];
|
||||
gBGTilemapBuffers3[offset + 1] = metatiles[1];
|
||||
gBGTilemapBuffers3[offset + 0x20] = metatiles[2];
|
||||
gBGTilemapBuffers3[offset + 0x21] = metatiles[3];
|
||||
gOverworldTilemapBuffer_Bg3[offset] = tiles[0];
|
||||
gOverworldTilemapBuffer_Bg3[offset + 1] = tiles[1];
|
||||
gOverworldTilemapBuffer_Bg3[offset + 0x20] = tiles[2];
|
||||
gOverworldTilemapBuffer_Bg3[offset + 0x21] = tiles[3];
|
||||
|
||||
// Draw metatile's top layer to the middle background layer.
|
||||
gBGTilemapBuffers1[offset] = metatiles[4];
|
||||
gBGTilemapBuffers1[offset + 1] = metatiles[5];
|
||||
gBGTilemapBuffers1[offset + 0x20] = metatiles[6];
|
||||
gBGTilemapBuffers1[offset + 0x21] = metatiles[7];
|
||||
gOverworldTilemapBuffer_Bg2[offset] = tiles[4];
|
||||
gOverworldTilemapBuffer_Bg2[offset + 1] = tiles[5];
|
||||
gOverworldTilemapBuffer_Bg2[offset + 0x20] = tiles[6];
|
||||
gOverworldTilemapBuffer_Bg2[offset + 0x21] = tiles[7];
|
||||
|
||||
// Draw transparent tiles to the top background layer.
|
||||
gBGTilemapBuffers2[offset] = 0;
|
||||
gBGTilemapBuffers2[offset + 1] = 0;
|
||||
gBGTilemapBuffers2[offset + 0x20] = 0;
|
||||
gBGTilemapBuffers2[offset + 0x21] = 0;
|
||||
gOverworldTilemapBuffer_Bg1[offset] = 0;
|
||||
gOverworldTilemapBuffer_Bg1[offset + 1] = 0;
|
||||
gOverworldTilemapBuffer_Bg1[offset + 0x20] = 0;
|
||||
gOverworldTilemapBuffer_Bg1[offset + 0x21] = 0;
|
||||
break;
|
||||
case 0: // LAYER_TYPE_NORMAL
|
||||
case METATILE_LAYER_TYPE_NORMAL:
|
||||
// Draw garbage to the bottom background layer.
|
||||
gBGTilemapBuffers3[offset] = 0x3014;
|
||||
gBGTilemapBuffers3[offset + 1] = 0x3014;
|
||||
gBGTilemapBuffers3[offset + 0x20] = 0x3014;
|
||||
gBGTilemapBuffers3[offset + 0x21] = 0x3014;
|
||||
gOverworldTilemapBuffer_Bg3[offset] = 0x3014;
|
||||
gOverworldTilemapBuffer_Bg3[offset + 1] = 0x3014;
|
||||
gOverworldTilemapBuffer_Bg3[offset + 0x20] = 0x3014;
|
||||
gOverworldTilemapBuffer_Bg3[offset + 0x21] = 0x3014;
|
||||
|
||||
// Draw metatile's bottom layer to the middle background layer.
|
||||
gBGTilemapBuffers1[offset] = metatiles[0];
|
||||
gBGTilemapBuffers1[offset + 1] = metatiles[1];
|
||||
gBGTilemapBuffers1[offset + 0x20] = metatiles[2];
|
||||
gBGTilemapBuffers1[offset + 0x21] = metatiles[3];
|
||||
gOverworldTilemapBuffer_Bg2[offset] = tiles[0];
|
||||
gOverworldTilemapBuffer_Bg2[offset + 1] = tiles[1];
|
||||
gOverworldTilemapBuffer_Bg2[offset + 0x20] = tiles[2];
|
||||
gOverworldTilemapBuffer_Bg2[offset + 0x21] = tiles[3];
|
||||
|
||||
// Draw metatile's top layer to the top background layer, which covers object event sprites.
|
||||
gBGTilemapBuffers2[offset] = metatiles[4];
|
||||
gBGTilemapBuffers2[offset + 1] = metatiles[5];
|
||||
gBGTilemapBuffers2[offset + 0x20] = metatiles[6];
|
||||
gBGTilemapBuffers2[offset + 0x21] = metatiles[7];
|
||||
gOverworldTilemapBuffer_Bg1[offset] = tiles[4];
|
||||
gOverworldTilemapBuffer_Bg1[offset + 1] = tiles[5];
|
||||
gOverworldTilemapBuffer_Bg1[offset + 0x20] = tiles[6];
|
||||
gOverworldTilemapBuffer_Bg1[offset + 0x21] = tiles[7];
|
||||
break;
|
||||
}
|
||||
ScheduleBgCopyTilemapToVram(1);
|
||||
|
|
|
@ -183,9 +183,9 @@ static u16 (*sPlayerKeyInterceptCallback)(u32);
|
|||
static bool8 sReceivingFromLink;
|
||||
static u8 sRfuKeepAliveTimer;
|
||||
|
||||
u16 *gBGTilemapBuffers1;
|
||||
u16 *gBGTilemapBuffers2;
|
||||
u16 *gBGTilemapBuffers3;
|
||||
u16 *gOverworldTilemapBuffer_Bg2;
|
||||
u16 *gOverworldTilemapBuffer_Bg1;
|
||||
u16 *gOverworldTilemapBuffer_Bg3;
|
||||
u16 gHeldKeyCodeToSend;
|
||||
void (*gFieldCallback)(void);
|
||||
bool8 (*gFieldCallback2)(void);
|
||||
|
@ -1394,12 +1394,12 @@ static void InitOverworldBgs(void)
|
|||
SetBgAttribute(1, BG_ATTR_MOSAIC, 1);
|
||||
SetBgAttribute(2, BG_ATTR_MOSAIC, 1);
|
||||
SetBgAttribute(3, BG_ATTR_MOSAIC, 1);
|
||||
gBGTilemapBuffers2 = AllocZeroed(BG_SCREEN_SIZE);
|
||||
gBGTilemapBuffers1 = AllocZeroed(BG_SCREEN_SIZE);
|
||||
gBGTilemapBuffers3 = AllocZeroed(BG_SCREEN_SIZE);
|
||||
SetBgTilemapBuffer(1, gBGTilemapBuffers2);
|
||||
SetBgTilemapBuffer(2, gBGTilemapBuffers1);
|
||||
SetBgTilemapBuffer(3, gBGTilemapBuffers3);
|
||||
gOverworldTilemapBuffer_Bg1 = AllocZeroed(BG_SCREEN_SIZE);
|
||||
gOverworldTilemapBuffer_Bg2 = AllocZeroed(BG_SCREEN_SIZE);
|
||||
gOverworldTilemapBuffer_Bg3 = AllocZeroed(BG_SCREEN_SIZE);
|
||||
SetBgTilemapBuffer(1, gOverworldTilemapBuffer_Bg1);
|
||||
SetBgTilemapBuffer(2, gOverworldTilemapBuffer_Bg2);
|
||||
SetBgTilemapBuffer(3, gOverworldTilemapBuffer_Bg3);
|
||||
InitStandardTextBoxWindows();
|
||||
}
|
||||
|
||||
|
@ -1407,12 +1407,9 @@ void CleanupOverworldWindowsAndTilemaps(void)
|
|||
{
|
||||
ClearMirageTowerPulseBlendEffect();
|
||||
FreeAllOverworldWindowBuffers();
|
||||
if (gBGTilemapBuffers3)
|
||||
FREE_AND_SET_NULL(gBGTilemapBuffers3);
|
||||
if (gBGTilemapBuffers1)
|
||||
FREE_AND_SET_NULL(gBGTilemapBuffers1);
|
||||
if (gBGTilemapBuffers2)
|
||||
FREE_AND_SET_NULL(gBGTilemapBuffers2);
|
||||
TRY_FREE_AND_SET_NULL(gOverworldTilemapBuffer_Bg3);
|
||||
TRY_FREE_AND_SET_NULL(gOverworldTilemapBuffer_Bg2);
|
||||
TRY_FREE_AND_SET_NULL(gOverworldTilemapBuffer_Bg1);
|
||||
}
|
||||
|
||||
static void ResetSafariZoneFlag_(void)
|
||||
|
|
Loading…
Reference in New Issue