From 21a7c08e2a58cf8490267f80b3f2e188e57d3bfd Mon Sep 17 00:00:00 2001 From: Melody Madeline Lyons Date: Tue, 30 Jul 2024 23:40:44 -0700 Subject: [PATCH] Actually implement tilemap wrapping --- binding/tilemap-binding.cpp | 2 +- src/display/tilemap.cpp | 66 ++++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/binding/tilemap-binding.cpp b/binding/tilemap-binding.cpp index 1c719f5c6..428feb2e6 100644 --- a/binding/tilemap-binding.cpp +++ b/binding/tilemap-binding.cpp @@ -151,7 +151,7 @@ DEF_GFX_PROP_OBJ_VAL(Tilemap, Color, Color, "color") DEF_GFX_PROP_OBJ_VAL(Tilemap, Tone, Tone, "tone") DEF_GFX_PROP_B(Tilemap, Visible) -DEF_PROP_B(Tilemap, Wrapping) +DEF_GFX_PROP_B(Tilemap, Wrapping) DEF_GFX_PROP_I(Tilemap, OX) DEF_GFX_PROP_I(Tilemap, OY) diff --git a/src/display/tilemap.cpp b/src/display/tilemap.cpp index 985f26490..e17a8511a 100644 --- a/src/display/tilemap.cpp +++ b/src/display/tilemap.cpp @@ -744,8 +744,17 @@ struct TilemapPrivate void handleTile(int x, int y, int z) { - int tileInd = - tableGetWrapped(*mapData, x + viewpPos.x, y + viewpPos.y, z); + int ox = x + viewpPos.x; + int oy = y + viewpPos.y; + + bool in_bounds = ox >= 0 && oy >= 0 && ox < mapData->xSize() && oy < mapData->ySize(); + bool should_return = !(wrapping || in_bounds); + if (should_return) + return; + + int tileInd = tableGetWrapped(*mapData, ox, oy, z); + // int tileInd = + // tableGetWrapped(*mapData, x + viewpPos.x, y + viewpPos.y, z); /* Check for empty space */ if (tileInd < 48) @@ -806,30 +815,35 @@ struct TilemapPrivate { clearQuadArrays(); - int ox = viewpPos.x; - int oy = viewpPos.y; - int mapW = mapData->xSize(); - int mapH = mapData->ySize(); - - int minX = 0; - int minY = 0; - if (ox < 0) - minX = -ox; - if (oy < 0) - minY = -oy; - - // There could be off-by-one issues in these couple sections. - int maxX = viewpW; - int maxY = viewpH; - if (ox + maxX >= mapW) - maxX = mapW - ox - 1; - if (oy + maxY >= mapH) - maxY = mapH - oy - 1; - - if ((minX > maxX) || (minY > maxY)) - return; - for (int x = minX; x <= maxX; ++x) - for (int y = minY; y <= maxY; ++y) + // int ox = viewpPos.x; + // int oy = viewpPos.y; + // int mapW = mapData->xSize(); + // int mapH = mapData->ySize(); + + // int minX = 0; + // int minY = 0; + // if (ox < 0) + // minX = -ox; + // if (oy < 0) + // minY = -oy; + + // // There could be off-by-one issues in these couple sections. + // int maxX = viewpW; + // int maxY = viewpH; + // if (ox + maxX >= mapW) + // maxX = mapW - ox - 1; + // if (oy + maxY >= mapH) + // maxY = mapH - oy - 1; + + // if ((minX > maxX) || (minY > maxY)) + // return; + // for (int x = minX; x <= maxX; ++x) + // for (int y = minY; y <= maxY; ++y) + // for (int z = 0; z < mapData->zSize(); ++z) + // handleTile(x, y, z); + + for (int x = 0; x < viewpW; ++x) + for (int y = 0; y < viewpH; ++y) for (int z = 0; z < mapData->zSize(); ++z) handleTile(x, y, z); }