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"
|
#include "main.h"
|
||||||
|
|
||||||
extern struct BackupMapLayout gBackupMapLayout;
|
extern struct BackupMapLayout gBackupMapLayout;
|
||||||
|
extern struct Coords16 gLightMetatiles[32];
|
||||||
|
|
||||||
u32 MapGridGetMetatileIdAt(int, int);
|
u32 MapGridGetMetatileIdAt(int, int);
|
||||||
u32 MapGridGetMetatileBehaviorAt(int, int);
|
u32 MapGridGetMetatileBehaviorAt(int, int);
|
||||||
|
|
|
@ -47,7 +47,6 @@ struct LinkPlayerObjectEvent
|
||||||
// Exported RAM declarations
|
// Exported RAM declarations
|
||||||
extern struct WarpData gLastUsedWarp;
|
extern struct WarpData gLastUsedWarp;
|
||||||
extern struct LinkPlayerObjectEvent gLinkPlayerObjectEvents[4];
|
extern struct LinkPlayerObjectEvent gLinkPlayerObjectEvents[4];
|
||||||
extern struct Coords16 gLightMetatiles[32];
|
|
||||||
|
|
||||||
extern u16 *gBGTilemapBuffers1;
|
extern u16 *gBGTilemapBuffers1;
|
||||||
extern u16 *gBGTilemapBuffers2;
|
extern u16 *gBGTilemapBuffers2;
|
||||||
|
|
|
@ -30,6 +30,7 @@ EWRAM_DATA struct MapHeader gMapHeader = {0};
|
||||||
EWRAM_DATA struct Camera gCamera = {0};
|
EWRAM_DATA struct Camera gCamera = {0};
|
||||||
EWRAM_DATA static struct ConnectionFlags gMapConnectionFlags = {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 static u32 sFiller = 0; // without this, the next file won't align properly
|
||||||
|
EWRAM_DATA struct Coords16 gLightMetatiles[32] = {0};
|
||||||
|
|
||||||
struct BackupMapLayout gBackupMapLayout;
|
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 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))
|
#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)
|
struct MapHeader const *const GetMapHeaderFromConnection(struct MapConnection *connection)
|
||||||
{
|
{
|
||||||
|
@ -73,6 +75,7 @@ void InitMap(void)
|
||||||
InitMapLayoutData(&gMapHeader);
|
InitMapLayoutData(&gMapHeader);
|
||||||
SetOccupiedSecretBaseEntranceMetatiles(gMapHeader.events);
|
SetOccupiedSecretBaseEntranceMetatiles(gMapHeader.events);
|
||||||
RunOnLoadMapScript();
|
RunOnLoadMapScript();
|
||||||
|
CacheLightMetatiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitMapFromSavedGame(void)
|
void InitMapFromSavedGame(void)
|
||||||
|
@ -82,6 +85,7 @@ void InitMapFromSavedGame(void)
|
||||||
SetOccupiedSecretBaseEntranceMetatiles(gMapHeader.events);
|
SetOccupiedSecretBaseEntranceMetatiles(gMapHeader.events);
|
||||||
LoadSavedMapView();
|
LoadSavedMapView();
|
||||||
RunOnLoadMapScript();
|
RunOnLoadMapScript();
|
||||||
|
CacheLightMetatiles();
|
||||||
UpdateTVScreensOnMap(gBackupMapLayout.width, gBackupMapLayout.height);
|
UpdateTVScreensOnMap(gBackupMapLayout.width, gBackupMapLayout.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,6 +382,23 @@ u32 MapGridGetMetatileBehaviorAt(int x, int y)
|
||||||
return GetBehaviorByMetatileId(metatile) & METATILE_BEHAVIOR_MASK;
|
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)
|
u8 MapGridGetMetatileLayerTypeAt(int x, int y)
|
||||||
{
|
{
|
||||||
u16 metatile = MapGridGetMetatileIdAt(x, 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 u16 sAmbientCrySpecies = 0;
|
||||||
EWRAM_DATA static bool8 sIsAmbientCryWaterMon = FALSE;
|
EWRAM_DATA static bool8 sIsAmbientCryWaterMon = FALSE;
|
||||||
EWRAM_DATA struct LinkPlayerObjectEvent gLinkPlayerObjectEvents[4] = {0};
|
EWRAM_DATA struct LinkPlayerObjectEvent gLinkPlayerObjectEvents[4] = {0};
|
||||||
EWRAM_DATA struct Coords16 gLightMetatiles[32] = {0};
|
|
||||||
|
|
||||||
|
|
||||||
// const rom data
|
// const rom data
|
||||||
|
@ -601,23 +600,6 @@ struct MapHeader const *const GetDestinationWarpMapHeader(void)
|
||||||
return Overworld_GetMapHeaderByGroupAndId(sWarpDestination.mapGroup, sWarpDestination.mapNum);
|
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)
|
static void LoadCurrentMapData(void)
|
||||||
{
|
{
|
||||||
sLastMapSectionId = gMapHeader.regionMapSectionId;
|
sLastMapSectionId = gMapHeader.regionMapSectionId;
|
||||||
|
@ -834,7 +816,6 @@ void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum)
|
||||||
Overworld_ClearSavedMusic();
|
Overworld_ClearSavedMusic();
|
||||||
RunOnTransitionMapScript();
|
RunOnTransitionMapScript();
|
||||||
InitMap();
|
InitMap();
|
||||||
CacheLightMetatiles();
|
|
||||||
CopySecondaryTilesetToVramUsingHeap(gMapHeader.mapLayout);
|
CopySecondaryTilesetToVramUsingHeap(gMapHeader.mapLayout);
|
||||||
LoadSecondaryTilesetPalette(gMapHeader.mapLayout);
|
LoadSecondaryTilesetPalette(gMapHeader.mapLayout);
|
||||||
|
|
||||||
|
@ -1823,7 +1804,6 @@ void CB2_ContinueSavedGame(void)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CacheLightMetatiles();
|
|
||||||
TryPutTodaysRivalTrainerOnAir();
|
TryPutTodaysRivalTrainerOnAir();
|
||||||
gFieldCallback = FieldCB_FadeTryShowMapPopup;
|
gFieldCallback = FieldCB_FadeTryShowMapPopup;
|
||||||
SetMainCallback1(CB1_Overworld);
|
SetMainCallback1(CB1_Overworld);
|
||||||
|
@ -1983,7 +1963,6 @@ static bool32 LoadMapInStepsLocal(u8 *state, bool32 a2)
|
||||||
(*state)++;
|
(*state)++;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
CacheLightMetatiles();
|
|
||||||
InitObjectEventsLocal();
|
InitObjectEventsLocal();
|
||||||
SetCameraToTrackPlayer();
|
SetCameraToTrackPlayer();
|
||||||
(*state)++;
|
(*state)++;
|
||||||
|
|
Loading…
Reference in a new issue