From 899ae7a59a2335917b3494b2b5c65dfa52faf4ce Mon Sep 17 00:00:00 2001 From: Diegoisawesome Date: Tue, 18 Sep 2018 10:03:24 -0500 Subject: [PATCH] Add defines for tile, metatile, and palette count --- include/fieldmap.h | 7 +++++++ src/field_camera.c | 6 +++--- src/fieldmap.c | 22 +++++++++++----------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/include/fieldmap.h b/include/fieldmap.h index 05ffb2edc..8287229ed 100644 --- a/include/fieldmap.h +++ b/include/fieldmap.h @@ -1,6 +1,13 @@ #ifndef GUARD_FIELDMAP_H #define GUARD_FIELDMAP_H +#define NUM_TILES_IN_PRIMARY 512 +#define NUM_TILES_TOTAL 1024 +#define NUM_METATILES_IN_PRIMARY 512 +#define NUM_METATILES_TOTAL 1024 +#define NUM_PALS_IN_PRIMARY 6 +#define NUM_PALS_TOTAL 13 + extern struct BackupMapLayout gUnknown_03005DC0; u32 MapGridGetMetatileIdAt(int, int); diff --git a/src/field_camera.c b/src/field_camera.c index 8629bec2b..e8900e06a 100644 --- a/src/field_camera.c +++ b/src/field_camera.c @@ -232,14 +232,14 @@ static void DrawMetatileAt(const struct MapLayout *mapLayout, u16 b, int c, int u16 metatileId = MapGridGetMetatileIdAt(c, d); u16 *metatiles; - if (metatileId > 1024) + if (metatileId > NUM_METATILES_TOTAL) metatileId = 0; - if (metatileId < 512) + if (metatileId < NUM_METATILES_IN_PRIMARY) metatiles = mapLayout->primaryTileset->metatiles; else { metatiles = mapLayout->secondaryTileset->metatiles; - metatileId -= 512; + metatileId -= NUM_METATILES_IN_PRIMARY; } DrawMetatile(MapGridGetMetatileLayerTypeAt(c, d), metatiles + metatileId * 8, b); } diff --git a/src/fieldmap.c b/src/fieldmap.c index 019db9d0d..96f5d2b85 100644 --- a/src/fieldmap.c +++ b/src/fieldmap.c @@ -482,15 +482,15 @@ void MapGridSetMetatileEntryAt(int x, int y, u16 metatile) u16 GetBehaviorByMetatileId(u16 metatile) { u16 *attributes; - if (metatile <= 0x1ff) + if (metatile < NUM_METATILES_IN_PRIMARY) { attributes = gMapHeader.mapLayout->primaryTileset->metatileAttributes; return attributes[metatile]; } - else if (metatile <= 0x3ff) + else if (metatile < NUM_METATILES_TOTAL) { attributes = gMapHeader.mapLayout->secondaryTileset->metatileAttributes; - return attributes[metatile - 0x200]; + return attributes[metatile - NUM_METATILES_IN_PRIMARY]; } else { @@ -979,7 +979,7 @@ void apply_map_tileset_palette(struct Tileset const *tileset, u16 destOffset, u1 } else if (tileset->isSecondary == TRUE) { - LoadPalette(((u16*)tileset->palettes) + 0x60, destOffset, size); + LoadPalette(((u16*)tileset->palettes) + (NUM_PALS_IN_PRIMARY * 16), destOffset, size); nullsub_3(destOffset, size >> 1); } else @@ -992,35 +992,35 @@ void apply_map_tileset_palette(struct Tileset const *tileset, u16 destOffset, u1 void copy_map_tileset1_to_vram(struct MapLayout const *mapLayout) { - copy_tileset_patterns_to_vram(mapLayout->primaryTileset, 0x200, 0); + copy_tileset_patterns_to_vram(mapLayout->primaryTileset, NUM_TILES_IN_PRIMARY, 0); } void copy_map_tileset2_to_vram(struct MapLayout const *mapLayout) { - copy_tileset_patterns_to_vram(mapLayout->secondaryTileset, 0x200, 0x200); + copy_tileset_patterns_to_vram(mapLayout->secondaryTileset, NUM_TILES_TOTAL - NUM_TILES_IN_PRIMARY, NUM_TILES_IN_PRIMARY); } void copy_map_tileset2_to_vram_2(struct MapLayout const *mapLayout) { - copy_tileset_patterns_to_vram2(mapLayout->secondaryTileset, 0x200, 0x200); + copy_tileset_patterns_to_vram2(mapLayout->secondaryTileset, NUM_TILES_TOTAL - NUM_TILES_IN_PRIMARY, NUM_TILES_IN_PRIMARY); } void apply_map_tileset1_palette(struct MapLayout const *mapLayout) { - apply_map_tileset_palette(mapLayout->primaryTileset, 0, 0xC0); + apply_map_tileset_palette(mapLayout->primaryTileset, 0, NUM_PALS_IN_PRIMARY * 16 * 2); } void apply_map_tileset2_palette(struct MapLayout const *mapLayout) { - apply_map_tileset_palette(mapLayout->secondaryTileset, 0x60, 0xE0); + apply_map_tileset_palette(mapLayout->secondaryTileset, NUM_PALS_IN_PRIMARY * 16, (NUM_PALS_TOTAL - NUM_PALS_IN_PRIMARY) * 16 * 2); } void copy_map_tileset1_tileset2_to_vram(struct MapLayout const *mapLayout) { if (mapLayout) { - copy_tileset_patterns_to_vram2(mapLayout->primaryTileset, 0x200, 0); - copy_tileset_patterns_to_vram2(mapLayout->secondaryTileset, 0x200, 0x200); + copy_tileset_patterns_to_vram2(mapLayout->primaryTileset, NUM_TILES_IN_PRIMARY, 0); + copy_tileset_patterns_to_vram2(mapLayout->secondaryTileset, NUM_TILES_TOTAL - NUM_TILES_IN_PRIMARY, NUM_TILES_IN_PRIMARY); } }