optimalizing engine for OAM, remove needles pointer dereferences in every update
This commit is contained in:
parent
573f1623e2
commit
8f0c3d337f
|
@ -53,6 +53,7 @@ void Sprite::flipVertically(bool flip) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite::makeAnimated(int beginFrame, int numberOfFrames, int animationDelay) {
|
void Sprite::makeAnimated(int beginFrame, int numberOfFrames, int animationDelay) {
|
||||||
|
previousFrame = -1;
|
||||||
setBeginFrame(beginFrame);
|
setBeginFrame(beginFrame);
|
||||||
animateToFrame(beginFrame);
|
animateToFrame(beginFrame);
|
||||||
this->numberOfFrames = numberOfFrames;
|
this->numberOfFrames = numberOfFrames;
|
||||||
|
|
|
@ -182,12 +182,15 @@ const u32 kul_data [] = {
|
||||||
class SpriteWithStubOam : public Sprite {
|
class SpriteWithStubOam : public Sprite {
|
||||||
public:
|
public:
|
||||||
SpriteWithStubOam(SpriteSize size) : Sprite(nullptr, imageSize, x, y, size) {
|
SpriteWithStubOam(SpriteSize size) : Sprite(nullptr, imageSize, x, y, size) {
|
||||||
oam = std::unique_ptr<OBJ_ATTR>(new OBJ_ATTR());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OBJ_ATTR* buildOamForTesting(int tileIndex = 0) {
|
OBJ_ATTR getOam() {
|
||||||
|
return oam;
|
||||||
|
}
|
||||||
|
|
||||||
|
OBJ_ATTR buildOamForTesting(int tileIndex = 0) {
|
||||||
buildOam(tileIndex);
|
buildOam(tileIndex);
|
||||||
return oam.get();
|
return oam;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -205,17 +208,33 @@ protected:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(SpriteSuite, Sync_Animation_Updates_OAM_To_Next_Frame) {
|
TEST_F(SpriteSuite, Update_Syncs_Animation_In_OAM_To_Next_Frame) {
|
||||||
s = new SpriteWithStubOam(SIZE_16_32);
|
s = new SpriteWithStubOam(SIZE_16_32);
|
||||||
s->makeAnimated(0, 2, 0);
|
s->makeAnimated(0, 2, 0);
|
||||||
auto oam = s->buildOamForTesting(208); // should start at 224 (11100000) after a frame update
|
auto oam = s->buildOamForTesting(208); // should start at 224 (11100000) after a frame update
|
||||||
s->update();
|
s->update();
|
||||||
|
|
||||||
auto attr2 = std::bitset<16>(oam->attr2).to_string();
|
oam = s->getOam();
|
||||||
|
auto attr2 = std::bitset<16>(oam.attr2).to_string();
|
||||||
|
|
||||||
ASSERT_EQ(std::string("0000000011100000"), attr2);
|
ASSERT_EQ(std::string("0000000011100000"), attr2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(SpriteSuite, Update_Does_Not_Sync_Animation_In_OAM_If_No_Frames_Changed) {
|
||||||
|
s = new SpriteWithStubOam(SIZE_16_32);
|
||||||
|
s->makeAnimated(0, 2, 0);
|
||||||
|
auto oam = s->buildOamForTesting(208); // should start at 224 (11100000) after a frame update
|
||||||
|
s->update();
|
||||||
|
|
||||||
|
s->animateToFrame(2);
|
||||||
|
s->update();
|
||||||
|
|
||||||
|
oam = s->getOam();
|
||||||
|
auto attr2 = std::bitset<16>(oam.attr2).to_string();
|
||||||
|
|
||||||
|
ASSERT_EQ(std::string("0000000011010000"), attr2);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(SpriteSuite, Animated_Sprite_Copy_In_Constructor_Takes_Over_Animation_Properties) {
|
TEST_F(SpriteSuite, Animated_Sprite_Copy_In_Constructor_Takes_Over_Animation_Properties) {
|
||||||
s->makeAnimated(0, 2, 5);
|
s->makeAnimated(0, 2, 5);
|
||||||
|
|
||||||
|
@ -265,10 +284,10 @@ TEST_F(SpriteSuite, CollidesWith_B_Half_In_A_On_X_Axis_Collides) {
|
||||||
TEST_F(SpriteSuite, MovesToNegativeCoordsAreMaskedIntoOAM) {
|
TEST_F(SpriteSuite, MovesToNegativeCoordsAreMaskedIntoOAM) {
|
||||||
s->moveTo(-10, -15);
|
s->moveTo(-10, -15);
|
||||||
auto oam = s->buildOamForTesting();
|
auto oam = s->buildOamForTesting();
|
||||||
auto attr0 = std::bitset<16>(oam->attr0).to_string();
|
auto attr0 = std::bitset<16>(oam.attr0).to_string();
|
||||||
auto attr1 = std::bitset<16>(oam->attr1).to_string();
|
auto attr1 = std::bitset<16>(oam.attr1).to_string();
|
||||||
|
|
||||||
ASSERT_EQ(std::string("0000000011110001"), attr0);
|
ASSERT_EQ(std::string("0010000011110001"), attr0);
|
||||||
ASSERT_EQ(std::string("0000000111110110"), attr1);
|
ASSERT_EQ(std::string("0000000111110110"), attr1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue