From ee82117f19ae4bc3bba6f050900ad70e50a91b1b Mon Sep 17 00:00:00 2001 From: David Vereb Date: Mon, 3 Apr 2023 20:58:50 -0400 Subject: [PATCH] Got rid of a lot of extra PD_ stuff. --- Pieces.cpp | 29 ++--------------------------- Pieces.h | 8 ++------ main.cpp | 30 +++++++++++++++++++----------- 3 files changed, 23 insertions(+), 44 deletions(-) diff --git a/Pieces.cpp b/Pieces.cpp index 74516ee..f596cef 100644 --- a/Pieces.cpp +++ b/Pieces.cpp @@ -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(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(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) diff --git a/Pieces.h b/Pieces.h index 98e3dbc..794365b 100644 --- a/Pieces.h +++ b/Pieces.h @@ -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 diff --git a/main.cpp b/main.cpp index 55ac3e6..7c9aef4 100644 --- a/main.cpp +++ b/main.cpp @@ -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(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(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(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();