[nostalgia/core/userland] Fix sprite location wrapping

This commit is contained in:
Gary Talent 2023-02-01 21:01:20 -06:00
parent 4bcef4bd35
commit 1cc3549d00

View File

@ -480,11 +480,11 @@ void setSprite(Context *ctx,
{4, 8}, // 2, 3
};
const auto dim = dimensions[(spriteShape << 2) | spriteSize];
const auto uX = static_cast<unsigned>(x) % 255;
const auto uY = static_cast<unsigned>(y) % 127;
const auto uX = static_cast<int>(x) % 255;
const auto uY = static_cast<int>(y + 8) % 255 - 8;
auto &id = *ctx->rendererData<renderer::GlImplData>();
auto i = 0u;
const auto set = [&](unsigned xIt, unsigned yIt) {
const auto set = [&](int xIt, int yIt) {
const auto fX = static_cast<float>(uX + xIt * 8) / 8;
const auto fY = static_cast<float>(uY + yIt * 8) / 8;
const auto cidx = idx + i;
@ -495,15 +495,15 @@ void setSprite(Context *ctx,
++i;
};
if (!flipX) {
for (auto yIt = 0u; yIt < dim.y; ++yIt) {
for (auto yIt = 0; yIt < static_cast<int>(dim.y); ++yIt) {
for (auto xIt = 0u; xIt < dim.x; ++xIt) {
set(xIt, yIt);
set(static_cast<int>(xIt), static_cast<int>(yIt));
}
}
} else {
for (auto yIt = 0u; yIt < dim.y; ++yIt) {
for (auto xIt = dim.x - 1; xIt < ~0u; --xIt) {
set(xIt, yIt);
set(static_cast<int>(xIt), static_cast<int>(yIt));
}
}
}