Just realized the word 'Row' makes no sense whatsoever
This commit is contained in:
parent
a327d4c324
commit
41e1187063
|
@ -3,18 +3,18 @@
|
||||||
namespace TileAtlas
|
namespace TileAtlas
|
||||||
{
|
{
|
||||||
|
|
||||||
/* A Row represents a Rect
|
/* A Column represents a Rect
|
||||||
* with undefined width */
|
* with undefined width */
|
||||||
struct Row
|
struct Column
|
||||||
{
|
{
|
||||||
int x, y, h;
|
int x, y, h;
|
||||||
|
|
||||||
Row(int x, int y, int h)
|
Column(int x, int y, int h)
|
||||||
: x(x), y(y), h(h)
|
: x(x), y(y), h(h)
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef QList<Row> RowList;
|
typedef QList<Column> ColumnList;
|
||||||
|
|
||||||
/* Autotile area width */
|
/* Autotile area width */
|
||||||
static const int atAreaW = 96*4;
|
static const int atAreaW = 96*4;
|
||||||
|
@ -55,75 +55,75 @@ Vec2i minSize(int tilesetH, int maxAtlasSize)
|
||||||
return Vec2i(-1, -1);
|
return Vec2i(-1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RowList calcSrcRows(int tilesetH)
|
static ColumnList calcSrcCols(int tilesetH)
|
||||||
{
|
{
|
||||||
RowList rows;
|
ColumnList cols;
|
||||||
|
|
||||||
rows << Row(0, 0, tilesetH);
|
cols << Column(0, 0, tilesetH);
|
||||||
rows << Row(tsLaneW, 0, tilesetH);
|
cols << Column(tsLaneW, 0, tilesetH);
|
||||||
|
|
||||||
return rows;
|
return cols;
|
||||||
}
|
}
|
||||||
|
|
||||||
static RowList calcDstRows(int atlasW, int atlasH)
|
static ColumnList calcDstCols(int atlasW, int atlasH)
|
||||||
{
|
{
|
||||||
RowList rows;
|
ColumnList cols;
|
||||||
|
|
||||||
/* Rows below the autotile area */
|
/* Columns below the autotile area */
|
||||||
const int underAt = atlasH - atAreaH;
|
const int underAt = atlasH - atAreaH;
|
||||||
|
|
||||||
for (int i = 0; i < 3; ++i)
|
for (int i = 0; i < 3; ++i)
|
||||||
rows << Row(i*tsLaneW, atAreaH, underAt);
|
cols << Column(i*tsLaneW, atAreaH, underAt);
|
||||||
|
|
||||||
if (atlasW <= atAreaW)
|
if (atlasW <= atAreaW)
|
||||||
return rows;
|
return cols;
|
||||||
|
|
||||||
const int remRows = (atlasW - atAreaW) / tsLaneW;
|
const int remCols = (atlasW - atAreaW) / tsLaneW;
|
||||||
|
|
||||||
for (int i = 0; i < remRows; ++i)
|
for (int i = 0; i < remCols; ++i)
|
||||||
rows << Row(i*tsLaneW + atAreaW, 0, atlasH);
|
cols << Column(i*tsLaneW + atAreaW, 0, atlasH);
|
||||||
|
|
||||||
return rows;
|
return cols;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BlitList calcBlitsInt(RowList &srcRows, RowList &dstRows)
|
static BlitList calcBlitsInt(ColumnList &srcCols, ColumnList &dstCols)
|
||||||
{
|
{
|
||||||
BlitList blits;
|
BlitList blits;
|
||||||
|
|
||||||
while (!srcRows.empty())
|
while (!srcCols.empty())
|
||||||
{
|
{
|
||||||
Row srcRow = srcRows.takeFirst();
|
Column srcCol = srcCols.takeFirst();
|
||||||
Q_ASSERT(srcRow.h > 0);
|
Q_ASSERT(srcCol.h > 0);
|
||||||
|
|
||||||
while (!dstRows.empty() && srcRow.h > 0)
|
while (!dstCols.empty() && srcCol.h > 0)
|
||||||
{
|
{
|
||||||
Row dstRow = dstRows.takeFirst();
|
Column dstCol = dstCols.takeFirst();
|
||||||
|
|
||||||
if (srcRow.h > dstRow.h)
|
if (srcCol.h > dstCol.h)
|
||||||
{
|
{
|
||||||
/* srcRow doesn't fully fit into dstRow */
|
/* srcCol doesn't fully fit into dstCol */
|
||||||
blits << Blit(srcRow.x, srcRow.y,
|
blits << Blit(srcCol.x, srcCol.y,
|
||||||
dstRow.x, dstRow.y, dstRow.h);
|
dstCol.x, dstCol.y, dstCol.h);
|
||||||
|
|
||||||
srcRow.y += dstRow.h;
|
srcCol.y += dstCol.h;
|
||||||
srcRow.h -= dstRow.h;
|
srcCol.h -= dstCol.h;
|
||||||
}
|
}
|
||||||
else if (srcRow.h < dstRow.h)
|
else if (srcCol.h < dstCol.h)
|
||||||
{
|
{
|
||||||
/* srcRow fits into dstRow with space remaining */
|
/* srcCol fits into dstCol with space remaining */
|
||||||
blits << Blit(srcRow.x, srcRow.y,
|
blits << Blit(srcCol.x, srcCol.y,
|
||||||
dstRow.x, dstRow.y, srcRow.h);
|
dstCol.x, dstCol.y, srcCol.h);
|
||||||
|
|
||||||
dstRow.y += srcRow.h;
|
dstCol.y += srcCol.h;
|
||||||
dstRow.h -= srcRow.h;
|
dstCol.h -= srcCol.h;
|
||||||
dstRows.prepend(dstRow);
|
dstCols.prepend(dstCol);
|
||||||
srcRow.h = 0;
|
srcCol.h = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* srcRow fits perfectly into dstRow */
|
/* srcCol fits perfectly into dstCol */
|
||||||
blits << Blit(srcRow.x, srcRow.y,
|
blits << Blit(srcCol.x, srcCol.y,
|
||||||
dstRow.x, dstRow.y, dstRow.h);
|
dstCol.x, dstCol.y, dstCol.h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,10 +133,10 @@ static BlitList calcBlitsInt(RowList &srcRows, RowList &dstRows)
|
||||||
|
|
||||||
BlitList calcBlits(int tilesetH, const Vec2i &atlasSize)
|
BlitList calcBlits(int tilesetH, const Vec2i &atlasSize)
|
||||||
{
|
{
|
||||||
RowList srcRows = calcSrcRows(tilesetH);
|
ColumnList srcCols = calcSrcCols(tilesetH);
|
||||||
RowList dstRows = calcDstRows(atlasSize.x, atlasSize.y);
|
ColumnList dstCols = calcDstCols(atlasSize.x, atlasSize.y);
|
||||||
|
|
||||||
return calcBlitsInt(srcRows, dstRows);
|
return calcBlitsInt(srcCols, dstCols);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2i tileToAtlasCoor(int tileX, int tileY, int tilesetH, int atlasH)
|
Vec2i tileToAtlasCoor(int tileX, int tileY, int tilesetH, int atlasH)
|
||||||
|
|
Loading…
Reference in New Issue