Keep track of allocated sprite count

This commit is contained in:
Pk11
2021-01-14 09:19:08 -06:00
parent 1ff3ba6534
commit c428fa704b
2 changed files with 16 additions and 5 deletions
+3 -1
View File
@@ -16,7 +16,7 @@ private:
bool _visibility; bool _visibility;
u16 *_gfx; u16 *_gfx;
static bool _assigned[2][128]; static u8 _assigned[2][128];
public: public:
/** /**
@@ -43,6 +43,8 @@ public:
*/ */
Sprite(bool top, SpriteSize size, SpriteColorFormat format, int x = 0, int y = 0, int priority = 0, int id = -1, int paletteAlpha = 15, int rotationIndex = -1, bool doubleSize = false, bool visible = true, bool vFlip = false, bool hFlip = false, bool mosaic = false); Sprite(bool top, SpriteSize size, SpriteColorFormat format, int x = 0, int y = 0, int priority = 0, int id = -1, int paletteAlpha = 15, int rotationIndex = -1, bool doubleSize = false, bool visible = true, bool vFlip = false, bool hFlip = false, bool mosaic = false);
Sprite(const Sprite &sprite);
~Sprite(void); ~Sprite(void);
u16* gfx(void) const { return _gfx; } u16* gfx(void) const { return _gfx; }
+13 -4
View File
@@ -28,7 +28,7 @@
#include "tonccpy.h" #include "tonccpy.h"
bool Sprite::_assigned[2][128] = {{false}, {false}}; u8 Sprite::_assigned[2][128] = {{false}, {false}};
Sprite::Sprite(bool top, SpriteSize size, SpriteColorFormat format, int x, int y, int priority, int id, Sprite::Sprite(bool top, SpriteSize size, SpriteColorFormat format, int x, int y, int priority, int id,
int paletteAlpha, int rotationIndex, bool doubleSize, bool visible, bool vFlip, bool hFlip, bool mosaic) int paletteAlpha, int rotationIndex, bool doubleSize, bool visible, bool vFlip, bool hFlip, bool mosaic)
@@ -44,7 +44,7 @@ Sprite::Sprite(bool top, SpriteSize size, SpriteColorFormat format, int x, int y
} }
} }
_assigned[top][_id] = true; _assigned[top][_id]++;
// Get the sprite width and height from the SpriteSize // Get the sprite width and height from the SpriteSize
if(((_size >> 12) & 3) == OBJSHAPE_SQUARE) { if(((_size >> 12) & 3) == OBJSHAPE_SQUARE) {
@@ -98,9 +98,18 @@ Sprite::Sprite(bool top, SpriteSize size, SpriteColorFormat format, int x, int y
vFlip, hFlip, mosaic); vFlip, hFlip, mosaic);
} }
Sprite::Sprite(const Sprite &sprite) : _top(sprite._top), _oam(sprite._oam), _size(sprite._size), _format(sprite._format), _x(sprite._x), _y(sprite._y), _priority(sprite._priority),
_id(sprite._id), _rotationIndex(sprite._rotationIndex), _paletteAlpha(sprite._paletteAlpha), _visibility(sprite._visibility) {
_assigned[_top][_id]++;
}
Sprite::~Sprite(void) { Sprite::~Sprite(void) {
oamFreeGfx(_oam, _gfx); _assigned[_top][_id]--;
_assigned[_top][_id] = false; if(!_assigned[_top][_id]) {
oamFreeGfx(_oam, _gfx);
oamClearSprite(_oam, _id);
oamUpdate(_oam);
}
} }
void Sprite::rotation(int rotation) { void Sprite::rotation(int rotation) {