Merge pull request #14 from rodri042/replacing-dynamic-cast-with-boolean

Replacing dynamic_cast with boolean for performance reasons
This commit is contained in:
Wouter Groeneveld 2020-06-28 15:57:36 +02:00 committed by GitHub
commit 941aea1241
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 6 deletions

View File

@ -61,6 +61,7 @@ protected:
u8 animationDelay, numberOfFrames, beginFrame, currentFrame, previousFrame, animationCounter;
bool animating;
OBJ_ATTR oam;
bool isAffine;
void syncAnimation();
virtual void syncOam();

View File

@ -13,11 +13,11 @@ void AffineSprite::identity() {
}
AffineSprite::AffineSprite(const AffineSprite &other) : Sprite(other), affIndex(other.affIndex) {
isAffine = true;
}
AffineSprite::AffineSprite(const void *imgData, int imgSize, int xC, int yC, SpriteSize spriteSize) : Sprite(imgData, imgSize, xC, yC, spriteSize), affIndex(0) {
isAffine = true;
}
void AffineSprite::rotate(u16 alpha) {

View File

@ -17,7 +17,7 @@ Sprite::Sprite(const Sprite &other) : Sprite(nullptr, 0, other.x, other.y, other
}
Sprite::Sprite(const void *imageData, int imageSize, int x, int y, SpriteSize size)
: x(x), y(y), data(imageData), imageSize(imageSize), spriteSize(size), priority(0),
: x(x), y(y), data(imageData), imageSize(imageSize), spriteSize(size), priority(0), isAffine(false),
animationDelay(0), numberOfFrames(0), beginFrame(0), currentFrame(0), animationCounter(0) {
setAttributesBasedOnSize(size);
}

View File

@ -47,11 +47,10 @@ void SpriteManager::copyOverSpriteOAMToVRAM() {
oam_mem[i] = sprite->oam;
auto affine = dynamic_cast<AffineSprite*>(sprite);
if(affine) {
if(sprite->isAffine) {
// WHY warning: can't do this: obj_aff_mem[affineIndex] = *affineShadow;
// because that would override OAM also! only want to set non-overlapping affine attribs
auto affine = static_cast<AffineSprite*>(sprite);
affine->setTransformationMatrix(&obj_aff_mem[affineIndex]);
affine->setAffineIndex(affineIndex);
affineIndex++;