Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add defines for tile, metatile, and palette count #333

Merged
merged 3 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/fieldmap.h
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/field_camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
22 changes: 11 additions & 11 deletions src/fieldmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}

Expand Down