Got rid of a lot of extra PD_ stuff.

This commit is contained in:
David Vereb 2023-04-03 20:58:50 -04:00
parent 59bd17a0ec
commit ee82117f19
3 changed files with 23 additions and 44 deletions

View File

@ -418,35 +418,10 @@ unsigned PD_PieceWidth(const PieceData &data)
return rtn;
}
unsigned PD_PieceHeight(const Piece &piece, Rotation rotation)
void PD_DrawPiece(const PieceData &data, int y, int x, int color)
{
switch(rotation)
{
default:
case Rotation::ROTATION_NONE:
case Rotation::ROTATION_180:
return pieces.at(piece).size();
break;
case Rotation::ROTATION_90:
case Rotation::ROTATION_270:
return PD_PieceHeight(RotatePieceData(pieces.at(piece), Rotation::ROTATION_90));
break;
};
}
attrset(COLOR_PAIR(static_cast<int>(color) % 8));
unsigned PD_PieceWidth(const Piece &piece, Rotation rotation)
{
size_t rtn = 0;
for(auto row : pieces.at(piece))
rtn = std::max(rtn, row.size());
return rtn;
}
void PD_DrawPiece(const Piece &piece, int y, int x, Rotation rotation)
{
attrset(COLOR_PAIR(static_cast<int>(piece) % 8));
auto data = RotatePieceData(pieces.at(piece), rotation);
for(size_t row = 0; row < data.size(); ++row)
{
for(size_t col = 0; col < data[row].size(); ++col)

View File

@ -149,12 +149,8 @@ void DrawPiece(const Piece &piece, int y, int x,
PieceData RotatePieceData(const PieceData &data, Rotation rotation);
unsigned PD_PieceHeight(const PieceData &data);
unsigned PD_PieceHeight(const Piece &piece,
Rotation rotation = Rotation::ROTATION_NONE);
unsigned PD_PieceWidth(const PieceData &data);
unsigned PD_PieceWidth(const Piece &piece,
Rotation rotation = Rotation::ROTATION_NONE);
void PD_DrawPiece(const Piece &piece, int y, int x,
Rotation rotation = Rotation::ROTATION_NONE);
void PD_DrawPiece(const PieceData &data, int y, int x, int color = 0);
#endif

View File

@ -38,8 +38,8 @@ int main(int argc, char *argv[])
{
try {
Piece piece = 0b111 & std::atoi(argv[input]);
PD_DrawPiece(piece, y, 1);
y += PD_PieceHeight(piece) + 1;
PD_DrawPiece(pieces.at(piece), y, 1);
y += PD_PieceHeight(pieces.at(piece)) + 1;
} catch(const std::exception &e) {
mvaddstr(y, 1, "std::atoi error");
y += 2;
@ -104,8 +104,9 @@ void DemoPieces()
y = 2;
for(auto i = 0; i < 8; ++i)
{
Piece piece = static_cast<Piece>(i);
PD_DrawPiece(piece, y, x, rotation);
PieceData data = pieces.at(i);
data = RotatePieceData(data, rotation);
PD_DrawPiece(data, y, x, i);
mvaddstr(y-1, x, "Piece");
mvaddstr(y-1, x + 6, std::to_string(i + 1).c_str());
x += 12;
@ -116,18 +117,25 @@ void DemoPieces()
y = 10;
for(auto i = 0; i < 8; ++i)
{
Piece piece = static_cast<Piece>(i);
PD_DrawPiece(piece, y, x, rotation);
x += PD_PieceWidth(piece, rotation) * 2 + 2;
PieceData data = pieces.at(i);
data = RotatePieceData(data, rotation);
PD_DrawPiece(data, y, x, i);
x += PD_PieceWidth(data) * 2 + 2;
}
// Always same height apart, sharing first piece with same-width row:
x = 2;
y = 10 + PD_PieceHeight(0, rotation) + 1;
y = 10;
{
auto data = pieces.at(0);
data = RotatePieceData(data, rotation);
y += PD_PieceHeight(data) + 1;
}
for(auto i = 1; i < 8; ++i) // skip first
{
Piece piece = static_cast<Piece>(i);
PD_DrawPiece(piece, y, x, rotation);
y += PD_PieceHeight(piece, rotation) + 1;
PieceData data = pieces.at(i);
data = RotatePieceData(data, rotation);
PD_DrawPiece(data, y, x, i);
y += PD_PieceHeight(data) + 1;
}
getch();