Skip to content

Commit

Permalink
Actually implement tilemap wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Speak2Erase committed Jul 31, 2024
1 parent e44b826 commit 21a7c08
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
2 changes: 1 addition & 1 deletion binding/tilemap-binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
66 changes: 40 additions & 26 deletions src/display/tilemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 21a7c08

Please sign in to comment.