From 88cfd9e2673e462bd1f0bee058c20443ccadda3b Mon Sep 17 00:00:00 2001 From: Ariel A <24759293+aarant@users.noreply.github.com> Date: Thu, 11 Jul 2024 00:01:45 -0400 Subject: [PATCH] fix: Removed `LoadSpriteSheetByTemplate` offset's dependence on EWRAM memory layout --- gflib/sprite.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gflib/sprite.c b/gflib/sprite.c index 31e320d77d28..48d561cdf849 100644 --- a/gflib/sprite.c +++ b/gflib/sprite.c @@ -1496,7 +1496,7 @@ void SetOamMatrixRotationScaling(u8 matrixNum, s16 xScale, s16 yScale, u16 rotat CopyOamMatrix(matrixNum, &matrix); } -u16 LoadSpriteSheet(const struct SpriteSheet *sheet) +static u16 LoadSpriteSheetWithOffset(const struct SpriteSheet *sheet, u32 offset) { s16 tileStart = AllocSpriteTiles(sheet->size / TILE_SIZE_4BPP); @@ -1507,11 +1507,16 @@ u16 LoadSpriteSheet(const struct SpriteSheet *sheet) else { AllocSpriteTileRange(sheet->tag, (u16)tileStart, sheet->size / TILE_SIZE_4BPP); - CpuSmartCopy16(sheet->data, (u8 *)OBJ_VRAM0 + TILE_SIZE_4BPP * tileStart, sheet->size); + CpuSmartCopy16(sheet->data, (u8 *)OBJ_VRAM0 + TILE_SIZE_4BPP * tileStart + offset, sheet->size - offset); return (u16)tileStart; } } +u16 LoadSpriteSheet(const struct SpriteSheet *sheet) +{ + return LoadSpriteSheetWithOffset(sheet, 0); +} + // Like LoadSpriteSheet, but checks if already loaded, and uses template image frames u16 LoadSpriteSheetByTemplate(const struct SpriteTemplate *template, u32 frame, s32 offset) { u16 tileStart; @@ -1521,10 +1526,10 @@ u16 LoadSpriteSheetByTemplate(const struct SpriteTemplate *template, u32 frame, return TAG_NONE; if ((tileStart = GetSpriteTileStartByTag(template->tileTag)) != TAG_NONE) // return if already loaded return tileStart; - sheet.data = template->images[frame].data - offset; + sheet.data = template->images[frame].data; sheet.size = template->images[frame].size; sheet.tag = template->tileTag; - return LoadSpriteSheet(&sheet); + return LoadSpriteSheetWithOffset(&sheet, offset); } void LoadSpriteSheets(const struct SpriteSheet *sheets)