Skip to content

Commit

Permalink
Fixed reported number of tiles (removing duplicated tilesets) by SPR_…
Browse files Browse the repository at this point in the history
…loadAllFrames(..)
  • Loading branch information
Stephane-D committed Nov 22, 2024
1 parent 6f2b7cd commit d430517
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Binary file modified lib/libmd.a
Binary file not shown.
8 changes: 5 additions & 3 deletions src/sprite_eng.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ u16 spriteVramSize;

#ifdef SPR_PROFIL


#define PROFIL_ALLOCATE_SPRITE 0
#define PROFIL_RELEASE_SPRITE 1
#define PROFIL_ADD_SPRITE 2
Expand Down Expand Up @@ -622,9 +623,6 @@ u16** NO_INLINE SPR_loadAllFrames(const SpriteDefinition* sprDef, u16 index, u16
anim++;
}

// store total num tile if needed
if (totalNumTile) *totalNumTile = numTileTot;

// allocate result table indexes[numAnim][numFrame]
u16** indexes = MEM_alloc((numAnimation * sizeof(u16*)) + (numFrameTot * sizeof(u16)));
// used to detect duplicate
Expand All @@ -634,6 +632,7 @@ u16** NO_INLINE SPR_loadAllFrames(const SpriteDefinition* sprDef, u16 index, u16
// not enough memory
if ((tilesets == NULL) || (tilesetIndexes == NULL) || (indexes == NULL))
{
if (totalNumTile) *totalNumTile = 0;
if (tilesets) MEM_free(tilesets);
if (tilesetIndexes) MEM_free(tilesetIndexes);
if (indexes) MEM_free(indexes);
Expand Down Expand Up @@ -683,6 +682,9 @@ u16** NO_INLINE SPR_loadAllFrames(const SpriteDefinition* sprDef, u16 index, u16
anim++;
}

// store total num tile (discarding duplicated tilesets)
if (totalNumTile) *totalNumTile = (tileInd - index);

MEM_free(tilesets);
MEM_free(tilesetIndexes);
MEM_pack();
Expand Down
7 changes: 4 additions & 3 deletions src/sprite_eng_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,9 +626,6 @@ u16** NO_INLINE SPR_loadAllFrames(const SpriteDefinition* sprDef, u16 index, u16
anim++;
}

// store total num tile if needed
if (totalNumTile) *totalNumTile = numTileTot;

// allocate result table indexes[numAnim][numFrame]
u16** indexes = MEM_alloc((numAnimation * sizeof(u16*)) + (numFrameTot * sizeof(u16)));
// used to detect duplicate
Expand All @@ -638,6 +635,7 @@ u16** NO_INLINE SPR_loadAllFrames(const SpriteDefinition* sprDef, u16 index, u16
// not enough memory
if ((tilesets == NULL) || (tilesetIndexes == NULL) || (indexes == NULL))
{
if (totalNumTile) *totalNumTile = 0;
if (tilesets) MEM_free(tilesets);
if (tilesetIndexes) MEM_free(tilesetIndexes);
if (indexes) MEM_free(indexes);
Expand Down Expand Up @@ -687,6 +685,9 @@ u16** NO_INLINE SPR_loadAllFrames(const SpriteDefinition* sprDef, u16 index, u16
anim++;
}

// store total num tile (discarding duplicated tilesets)
if (totalNumTile) *totalNumTile = (tileInd - index);

MEM_free(tilesets);
MEM_free(tilesetIndexes);
MEM_pack();
Expand Down

0 comments on commit d430517

Please sign in to comment.