Refactored light metatile caching.
This commit is contained in:
parent
68068981a4
commit
cd9276c569
4 changed files with 22 additions and 22 deletions
|
@ -12,6 +12,7 @@
|
|||
#include "main.h"
|
||||
|
||||
extern struct BackupMapLayout gBackupMapLayout;
|
||||
extern struct Coords16 gLightMetatiles[32];
|
||||
|
||||
u32 MapGridGetMetatileIdAt(int, int);
|
||||
u32 MapGridGetMetatileBehaviorAt(int, int);
|
||||
|
|
|
@ -47,7 +47,6 @@ struct LinkPlayerObjectEvent
|
|||
// Exported RAM declarations
|
||||
extern struct WarpData gLastUsedWarp;
|
||||
extern struct LinkPlayerObjectEvent gLinkPlayerObjectEvents[4];
|
||||
extern struct Coords16 gLightMetatiles[32];
|
||||
|
||||
extern u16 *gBGTilemapBuffers1;
|
||||
extern u16 *gBGTilemapBuffers2;
|
||||
|
|
|
@ -30,6 +30,7 @@ EWRAM_DATA struct MapHeader gMapHeader = {0};
|
|||
EWRAM_DATA struct Camera gCamera = {0};
|
||||
EWRAM_DATA static struct ConnectionFlags gMapConnectionFlags = {0};
|
||||
EWRAM_DATA static u32 sFiller = 0; // without this, the next file won't align properly
|
||||
EWRAM_DATA struct Coords16 gLightMetatiles[32] = {0};
|
||||
|
||||
struct BackupMapLayout gBackupMapLayout;
|
||||
|
||||
|
@ -62,6 +63,7 @@ static bool8 IsCoordInIncomingConnectingMap(int coord, int srcMax, int destMax,
|
|||
#define AreCoordsWithinMapGridBounds(x, y) (x >= 0 && x < gBackupMapLayout.width && y >= 0 && y < gBackupMapLayout.height)
|
||||
|
||||
#define MapGridGetTileAt(x, y) (AreCoordsWithinMapGridBounds(x, y) ? gBackupMapLayout.map[x + gBackupMapLayout.width * y] : MapGridGetBorderTileAt(x, y))
|
||||
static void CacheLightMetatiles(void);
|
||||
|
||||
struct MapHeader const *const GetMapHeaderFromConnection(struct MapConnection *connection)
|
||||
{
|
||||
|
@ -73,6 +75,7 @@ void InitMap(void)
|
|||
InitMapLayoutData(&gMapHeader);
|
||||
SetOccupiedSecretBaseEntranceMetatiles(gMapHeader.events);
|
||||
RunOnLoadMapScript();
|
||||
CacheLightMetatiles();
|
||||
}
|
||||
|
||||
void InitMapFromSavedGame(void)
|
||||
|
@ -82,6 +85,7 @@ void InitMapFromSavedGame(void)
|
|||
SetOccupiedSecretBaseEntranceMetatiles(gMapHeader.events);
|
||||
LoadSavedMapView();
|
||||
RunOnLoadMapScript();
|
||||
CacheLightMetatiles();
|
||||
UpdateTVScreensOnMap(gBackupMapLayout.width, gBackupMapLayout.height);
|
||||
}
|
||||
|
||||
|
@ -378,6 +382,23 @@ u32 MapGridGetMetatileBehaviorAt(int x, int y)
|
|||
return GetBehaviorByMetatileId(metatile) & METATILE_BEHAVIOR_MASK;
|
||||
}
|
||||
|
||||
// Caches light metatile coordinates
|
||||
static void CacheLightMetatiles(void) { // TODO: Better way to dynamically generate lights
|
||||
u8 i = 0;
|
||||
s16 x, y;
|
||||
for (x = 0; x < gBackupMapLayout.width; x++) {
|
||||
for (y = 0; y < gBackupMapLayout.height; y++) {
|
||||
if (MapGridGetMetatileBehaviorAt(x, y) == 0x04) {
|
||||
gLightMetatiles[i].x = x;
|
||||
gLightMetatiles[i].y = y;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
gLightMetatiles[i].x = -1;
|
||||
gLightMetatiles[i].y = -1;
|
||||
}
|
||||
|
||||
u8 MapGridGetMetatileLayerTypeAt(int x, int y)
|
||||
{
|
||||
u16 metatile = MapGridGetMetatileIdAt(x, y);
|
||||
|
|
|
@ -211,7 +211,6 @@ EWRAM_DATA static struct InitialPlayerAvatarState sInitialPlayerAvatarState = {0
|
|||
EWRAM_DATA static u16 sAmbientCrySpecies = 0;
|
||||
EWRAM_DATA static bool8 sIsAmbientCryWaterMon = FALSE;
|
||||
EWRAM_DATA struct LinkPlayerObjectEvent gLinkPlayerObjectEvents[4] = {0};
|
||||
EWRAM_DATA struct Coords16 gLightMetatiles[32] = {0};
|
||||
|
||||
|
||||
// const rom data
|
||||
|
@ -601,23 +600,6 @@ struct MapHeader const *const GetDestinationWarpMapHeader(void)
|
|||
return Overworld_GetMapHeaderByGroupAndId(sWarpDestination.mapGroup, sWarpDestination.mapNum);
|
||||
}
|
||||
|
||||
// Caches light metatile coordinates
|
||||
static void CacheLightMetatiles(void) { // TODO: Better way to dynamically generate lights
|
||||
u8 i = 0;
|
||||
s16 x, y;
|
||||
for (x = 0; x < gBackupMapLayout.width; x++) {
|
||||
for (y = 0; y < gBackupMapLayout.height; y++) {
|
||||
if (MapGridGetMetatileBehaviorAt(x, y) == 0x04) {
|
||||
gLightMetatiles[i].x = x;
|
||||
gLightMetatiles[i].y = y;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
gLightMetatiles[i].x = -1;
|
||||
gLightMetatiles[i].y = -1;
|
||||
}
|
||||
|
||||
static void LoadCurrentMapData(void)
|
||||
{
|
||||
sLastMapSectionId = gMapHeader.regionMapSectionId;
|
||||
|
@ -834,7 +816,6 @@ void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum)
|
|||
Overworld_ClearSavedMusic();
|
||||
RunOnTransitionMapScript();
|
||||
InitMap();
|
||||
CacheLightMetatiles();
|
||||
CopySecondaryTilesetToVramUsingHeap(gMapHeader.mapLayout);
|
||||
LoadSecondaryTilesetPalette(gMapHeader.mapLayout);
|
||||
|
||||
|
@ -1823,7 +1804,6 @@ void CB2_ContinueSavedGame(void)
|
|||
}
|
||||
else
|
||||
{
|
||||
CacheLightMetatiles();
|
||||
TryPutTodaysRivalTrainerOnAir();
|
||||
gFieldCallback = FieldCB_FadeTryShowMapPopup;
|
||||
SetMainCallback1(CB1_Overworld);
|
||||
|
@ -1983,7 +1963,6 @@ static bool32 LoadMapInStepsLocal(u8 *state, bool32 a2)
|
|||
(*state)++;
|
||||
break;
|
||||
case 3:
|
||||
CacheLightMetatiles();
|
||||
InitObjectEventsLocal();
|
||||
SetCameraToTrackPlayer();
|
||||
(*state)++;
|
||||
|
|
Loading…
Reference in a new issue