commit 3b6da311ff80f5be10f9307c20d3faad6fc1bb7f
Author: jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Mon Jan 17 19:51:08 2022 -0700
Commit: jtothebell <j.to.the.bell@gmail.com>
CommitDate: Mon Jan 17 19:51:08 2022 -0700
Quick band aid for flipped sspr calls
This really needs a better fix, but I want to come back to sprite
blitting soon to clean up and optimize anyway, so adding a test for
this broken case that should catch it when I come back
---
source/graphics.cpp | 5 +++--
test/graphicstests.cpp | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/source/graphics.cpp b/source/graphics.cpp
index 61a6496..369ed78 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -247,8 +247,9 @@ void Graphics::copyStretchSpriteToScreen(
if (scr_w == 0 || scr_h == 0)
return;
- if (spr_h == scr_h && spr_w == scr_w) {
- // use faster non stretch blitter if sprite is not stretched
+ if (spr_h == scr_h && spr_w == scr_w && !flip_x) {
+ // use faster non stretch blitter if sprite is not stretched
+ //(or flipped horizontally - but skipping for that is just a hacky fix)
copySpriteToScreen(spritebuffer, scr_x, scr_y, spr_x, spr_y, scr_w, scr_h, flip_x, flip_y);
return;
}
diff --git a/test/graphicstests.cpp b/test/graphicstests.cpp
index 3a05061..a1dfea5 100644
--- a/test/graphicstests.cpp
+++ b/test/graphicstests.cpp
@@ -987,6 +987,42 @@ TEST_CASE("graphics class behaves as expected") {
checkPoints(graphics, expectedPoints);
}
+ SUBCASE("sspr(...) draws from odd numbered sprite sheet location flipped horizontally") {
+ //bug discovered in high stakes
+ graphics->cls();
+
+ for(uint8_t i = 0; i < 16; i++) {
+ for(uint8_t j = 0; j < 16; j++) {
+ graphics->sset(i, j, i);
+ }
+ }
+
+ graphics->sspr(1, 1, 4, 4, 0, 15, 4, 4, true, false);
+
+ //check sprite in columns
+ std::vector<coloredPoint> expectedPoints = {
+ {0, 14, 0},
+ {0, 15, 4},
+ {0, 16, 4},
+ {0, 17, 4},
+ {0, 18, 4},
+ {1, 15, 3},
+ {1, 16, 3},
+ {1, 17, 3},
+ {1, 18, 3},
+ {2, 15, 2},
+ {2, 16, 2},
+ {2, 17, 2},
+ {2, 18, 2},
+ {3, 15, 1},
+ {3, 16, 1},
+ {3, 17, 1},
+ {3, 18, 1},
+ {4, 15, 0},
+ };
+
+ checkPoints(graphics, expectedPoints);
+ }
SUBCASE("sspr(...) draws non-square to screen at location") {
graphics->cls();