From 40951038438a01e5201ae1d0ba306e225428de6f Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Sun, 20 Jul 2025 23:02:45 +0200 Subject: [PATCH] fix some compiler warnings --- src/Core/Board.cpp | 8 ++-- src/Core/Board.h | 4 +- src/Core/PiecesList.cpp | 8 ++-- src/Core/PiecesList.h | 8 ++-- src/Pieces/Generator.cpp | 4 +- src/Pieces/Generator.h | 2 +- src/Pieces/PiecesFiles.cpp | 2 - src/Pieces/Polyomino.cpp | 2 +- src/Utils/AssetManager.cpp | 80 +++++++++++++++++++------------------- src/Utils/AssetManager.h | 14 +++---- xmake.lua | 2 + 11 files changed, 67 insertions(+), 67 deletions(-) diff --git a/src/Core/Board.cpp b/src/Core/Board.cpp index 7006d51..848736d 100644 --- a/src/Core/Board.cpp +++ b/src/Core/Board.cpp @@ -20,10 +20,10 @@ Board::Board(int width, int height) : } void Board::changeBlock(const Position& position, Block block) { - if (position.x < 0 || position.x >= this->width || position.y < 0) return; + if (position.x < 0 || static_cast(position.x) >= this->width || position.y < 0) return; // resize the grid if needed - if (position.y >= this->grid.size()) { + if (static_cast(position.y) >= this->grid.size()) { for (int j = this->grid.size(); j <= position.y; j++) { this->grid.push_back(this->emptyRow); } @@ -34,7 +34,7 @@ void Board::changeBlock(const Position& position, Block block) { void Board::insertRow(int height, int holePosition, Block blockType) { std::vector insertedRow; - for (int i = 0; i < this->width; i++) { + for (unsigned i = 0; i < this->width; i++) { if (i == holePosition) { insertedRow.push_back(NOTHING); } @@ -51,7 +51,7 @@ int Board::clearRows() { int clearedLines = 0; for (int j = this->grid.size() - 1; j >= 0; j--) { bool lineIsFull = true; - int i = 0; + unsigned i = 0; while (lineIsFull && (i < width)) { if (this->grid.at(j).at(i) == NOTHING) { lineIsFull = false; diff --git a/src/Core/Board.h b/src/Core/Board.h index fcd48fa..cc5f107 100644 --- a/src/Core/Board.h +++ b/src/Core/Board.h @@ -13,8 +13,8 @@ class Board { private: std::vector> grid; // the grid, (0,0) is downleft std::vector emptyRow; // an empty row of blocks - int width; // the width of the grid - int height; // the base height of the grid, which can extend indefinitely + unsigned width; // the width of the grid + unsigned height; // the base height of the grid, which can extend indefinitely public: /** diff --git a/src/Core/PiecesList.cpp b/src/Core/PiecesList.cpp index a6bd0d3..614fd11 100644 --- a/src/Core/PiecesList.cpp +++ b/src/Core/PiecesList.cpp @@ -27,12 +27,12 @@ PiecesList::PiecesList() { this->pushBackEmptyVectors(); } -bool PiecesList::loadPieces(int max_size) { +bool PiecesList::loadPieces(unsigned max_size) { if (max_size < 1) return false; if (max_size <= this->highestLoadedSize) return true; PiecesFiles piecesFiles; - for (int i = this->highestLoadedSize + 1; i <= max_size; i++) { + for (unsigned i = this->highestLoadedSize + 1; i <= max_size; i++) { if (!piecesFiles.loadPieces(i, this->loadedPieces.at(i), this->convexPieces.at(i), this->holelessPieces.at(i), this->otherPieces.at(i))) { return false; } @@ -45,14 +45,14 @@ bool PiecesList::loadPieces(int max_size) { return true; } -bool PiecesList::selectPiece(int size, int number) { +bool PiecesList::selectPiece(unsigned size, unsigned number) { if (size < 1 || size > this->highestLoadedSize || number >= this->loadedPieces.at(size).size()) return false; this->selectedPieces.push_back(std::pair(size, number)); return true; } -bool PiecesList::selectAllPieces(int size) { +bool PiecesList::selectAllPieces(unsigned size) { if (size < 1 || size > this->highestLoadedSize) return false; for (int i = 0; i < this->loadedPieces.at(size).size(); i++) { diff --git a/src/Core/PiecesList.h b/src/Core/PiecesList.h index 8c4991f..2150d0c 100644 --- a/src/Core/PiecesList.h +++ b/src/Core/PiecesList.h @@ -13,7 +13,7 @@ */ class PiecesList { private: - int highestLoadedSize; // the highest size of pieces currently loaded + unsigned highestLoadedSize; // the highest size of pieces currently loaded std::vector> loadedPieces; // every loaded pieces by size std::vector> convexPieces; // the list of convex loaded pieces by size std::vector> holelessPieces; // the list of holeless loaded pieces by size @@ -33,19 +33,19 @@ class PiecesList { * Makes the list load all pieces up to the specified size * @return If all pieces up to the specified size are correctly loaded */ - [[nodiscard]] bool loadPieces(int max_size); + [[nodiscard]] bool loadPieces(unsigned max_size); /** * Selects the specified piece * @return If the piece could be selected */ - bool selectPiece(int size, int number); + bool selectPiece(unsigned size, unsigned number); /** * Selects all pieces of the specified size * @return If the pieces could be selected */ - bool selectAllPieces(int size); + bool selectAllPieces(unsigned size); /** * Selects all convex pieces of the specified size diff --git a/src/Pieces/Generator.cpp b/src/Pieces/Generator.cpp index 4b6e45c..dd12183 100644 --- a/src/Pieces/Generator.cpp +++ b/src/Pieces/Generator.cpp @@ -26,7 +26,7 @@ std::vector&& Generator::generatePolyominoes(int polyominoSize) { return std::move(this->validPolyominoes); } -void Generator::generate(int polyominoSize, int lastAddedPositionNumber, int nextAvaibleNumber, std::map candidatePositions) { +void Generator::generate(unsigned polyominoSize, int lastAddedPositionNumber, int nextAvaibleNumber, std::map candidatePositions) { // recursion stop if (polyominoSize == this->currentTestedShape.size()) { Polyomino candidate(std::move(this->currentTestedShape)); @@ -58,7 +58,7 @@ void Generator::generate(int polyominoSize, int lastAddedPositionNumber, int nex } // try adding a square only to positions with a higher number than the last one - for (const auto [key, val] : candidatePositions) { + for (const auto& [key, val] : candidatePositions) { if (val > lastAddedPositionNumber) { this->currentTestedShape.insert(key); this->generate(polyominoSize, val, nextAvaibleNumber, (polyominoSize == this->currentTestedShape.size()) ? std::map() : candidatePositions); diff --git a/src/Pieces/Generator.h b/src/Pieces/Generator.h index 3cdaeac..339c5f3 100644 --- a/src/Pieces/Generator.h +++ b/src/Pieces/Generator.h @@ -31,7 +31,7 @@ class Generator { /** * Generates all one-sided polyominoes of the specified size using the current tested shape */ - void generate(int polyominoSize, int lastAddedPositionNumber, int nextAvaibleNumber, std::map candidatePositions); + void generate(unsigned polyominoSize, int lastAddedPositionNumber, int nextAvaibleNumber, std::map candidatePositions); /** * Checks wheter a candidate position can be added to the current tested shape diff --git a/src/Pieces/PiecesFiles.cpp b/src/Pieces/PiecesFiles.cpp index 15e7036..6357eab 100644 --- a/src/Pieces/PiecesFiles.cpp +++ b/src/Pieces/PiecesFiles.cpp @@ -100,8 +100,6 @@ bool PiecesFiles::loadPieces(int polyominoSize, std::vector& pieces, std: constexpr char convexMask = 0b1000'0000; constexpr char holeMask = 0b0100'0000; constexpr char lengthMask = 0b0011'1111; - constexpr char xMask = 0b1111'0000; - constexpr char yMask = 0b0000'1111; std::uint8_t infoByte; std::uint8_t positionByte; diff --git a/src/Pieces/Polyomino.cpp b/src/Pieces/Polyomino.cpp index f0e634a..c771d2f 100644 --- a/src/Pieces/Polyomino.cpp +++ b/src/Pieces/Polyomino.cpp @@ -296,7 +296,7 @@ int Polyomino::getPolyominoSize() const { bool Polyomino::operator<(const Polyomino& other) const { if (this->length != other.length) return this->length < other.length; - for (int i = 0; i < this->positions.size(); i++) { + for (std::size_t i = 0; i < this->positions.size(); i++) { if (this->positions[i] != other.positions[i]) { return this->positions[i] < other.positions[i]; } diff --git a/src/Utils/AssetManager.cpp b/src/Utils/AssetManager.cpp index 75b2c5d..2656747 100644 --- a/src/Utils/AssetManager.cpp +++ b/src/Utils/AssetManager.cpp @@ -10,30 +10,6 @@ static const unsigned char data_fonts_pressstart_prstartk_ttf[] = { #include }; -static const unsigned char data_images_keybinds_Rotate180_png[] = { - #include -}; - -static const unsigned char data_images_keybinds_Rotate0_png[] = { - #include -}; - -static const unsigned char data_images_keybinds_RotateCCW_png[] = { - #include -}; - -static const unsigned char data_images_keybinds_Retry_png[] = { - #include -}; - -static const unsigned char data_images_keybinds_RotateCW_png[] = { - #include -}; - -static const unsigned char data_images_keybinds_Moveright_png[] = { - #include -}; - static const unsigned char data_images_keybinds_Harddrop_png[] = { #include }; @@ -42,14 +18,38 @@ static const unsigned char data_images_keybinds_Moveleft_png[] = { #include }; -static const unsigned char data_images_keybinds_Hold_png[] = { - #include +static const unsigned char data_images_keybinds_RotateCW_png[] = { + #include +}; + +static const unsigned char data_images_keybinds_RotateCCW_png[] = { + #include }; static const unsigned char data_images_keybinds_Softdrop_png[] = { #include }; +static const unsigned char data_images_keybinds_Moveright_png[] = { + #include +}; + +static const unsigned char data_images_keybinds_Rotate180_png[] = { + #include +}; + +static const unsigned char data_images_keybinds_Hold_png[] = { + #include +}; + +static const unsigned char data_images_keybinds_Rotate0_png[] = { + #include +}; + +static const unsigned char data_images_keybinds_Retry_png[] = { + #include +}; + static const unsigned char data_images_keybinds_Pause_png[] = { #include }; @@ -57,16 +57,16 @@ static const unsigned char data_images_keybinds_Pause_png[] = { static const Asset assets[] = { {data_fonts_pressstart_prstart_ttf, sizeof(data_fonts_pressstart_prstart_ttf)}, {data_fonts_pressstart_prstartk_ttf, sizeof(data_fonts_pressstart_prstartk_ttf)}, - {data_images_keybinds_Rotate180_png, sizeof(data_images_keybinds_Rotate180_png)}, - {data_images_keybinds_Rotate0_png, sizeof(data_images_keybinds_Rotate0_png)}, - {data_images_keybinds_RotateCCW_png, sizeof(data_images_keybinds_RotateCCW_png)}, - {data_images_keybinds_Retry_png, sizeof(data_images_keybinds_Retry_png)}, - {data_images_keybinds_RotateCW_png, sizeof(data_images_keybinds_RotateCW_png)}, - {data_images_keybinds_Moveright_png, sizeof(data_images_keybinds_Moveright_png)}, {data_images_keybinds_Harddrop_png, sizeof(data_images_keybinds_Harddrop_png)}, {data_images_keybinds_Moveleft_png, sizeof(data_images_keybinds_Moveleft_png)}, - {data_images_keybinds_Hold_png, sizeof(data_images_keybinds_Hold_png)}, + {data_images_keybinds_RotateCW_png, sizeof(data_images_keybinds_RotateCW_png)}, + {data_images_keybinds_RotateCCW_png, sizeof(data_images_keybinds_RotateCCW_png)}, {data_images_keybinds_Softdrop_png, sizeof(data_images_keybinds_Softdrop_png)}, + {data_images_keybinds_Moveright_png, sizeof(data_images_keybinds_Moveright_png)}, + {data_images_keybinds_Rotate180_png, sizeof(data_images_keybinds_Rotate180_png)}, + {data_images_keybinds_Hold_png, sizeof(data_images_keybinds_Hold_png)}, + {data_images_keybinds_Rotate0_png, sizeof(data_images_keybinds_Rotate0_png)}, + {data_images_keybinds_Retry_png, sizeof(data_images_keybinds_Retry_png)}, {data_images_keybinds_Pause_png, sizeof(data_images_keybinds_Pause_png)}, }; @@ -74,16 +74,16 @@ static const Asset assets[] = { static const std::map assetMap = { {"data/fonts/pressstart/prstart.ttf", AssetName::data_fonts_pressstart_prstart_ttf}, {"data/fonts/pressstart/prstartk.ttf", AssetName::data_fonts_pressstart_prstartk_ttf}, - {"data/images/keybinds/Rotate180.png", AssetName::data_images_keybinds_Rotate180_png}, - {"data/images/keybinds/Rotate0.png", AssetName::data_images_keybinds_Rotate0_png}, - {"data/images/keybinds/RotateCCW.png", AssetName::data_images_keybinds_RotateCCW_png}, - {"data/images/keybinds/Retry.png", AssetName::data_images_keybinds_Retry_png}, - {"data/images/keybinds/RotateCW.png", AssetName::data_images_keybinds_RotateCW_png}, - {"data/images/keybinds/Moveright.png", AssetName::data_images_keybinds_Moveright_png}, {"data/images/keybinds/Harddrop.png", AssetName::data_images_keybinds_Harddrop_png}, {"data/images/keybinds/Moveleft.png", AssetName::data_images_keybinds_Moveleft_png}, - {"data/images/keybinds/Hold.png", AssetName::data_images_keybinds_Hold_png}, + {"data/images/keybinds/RotateCW.png", AssetName::data_images_keybinds_RotateCW_png}, + {"data/images/keybinds/RotateCCW.png", AssetName::data_images_keybinds_RotateCCW_png}, {"data/images/keybinds/Softdrop.png", AssetName::data_images_keybinds_Softdrop_png}, + {"data/images/keybinds/Moveright.png", AssetName::data_images_keybinds_Moveright_png}, + {"data/images/keybinds/Rotate180.png", AssetName::data_images_keybinds_Rotate180_png}, + {"data/images/keybinds/Hold.png", AssetName::data_images_keybinds_Hold_png}, + {"data/images/keybinds/Rotate0.png", AssetName::data_images_keybinds_Rotate0_png}, + {"data/images/keybinds/Retry.png", AssetName::data_images_keybinds_Retry_png}, {"data/images/keybinds/Pause.png", AssetName::data_images_keybinds_Pause_png}, }; diff --git a/src/Utils/AssetManager.h b/src/Utils/AssetManager.h index e4eacae..0404d69 100644 --- a/src/Utils/AssetManager.h +++ b/src/Utils/AssetManager.h @@ -11,16 +11,16 @@ struct Asset { enum class AssetName { data_fonts_pressstart_prstart_ttf, data_fonts_pressstart_prstartk_ttf, - data_images_keybinds_Rotate180_png, - data_images_keybinds_Rotate0_png, - data_images_keybinds_RotateCCW_png, - data_images_keybinds_Retry_png, - data_images_keybinds_RotateCW_png, - data_images_keybinds_Moveright_png, data_images_keybinds_Harddrop_png, data_images_keybinds_Moveleft_png, - data_images_keybinds_Hold_png, + data_images_keybinds_RotateCW_png, + data_images_keybinds_RotateCCW_png, data_images_keybinds_Softdrop_png, + data_images_keybinds_Moveright_png, + data_images_keybinds_Rotate180_png, + data_images_keybinds_Hold_png, + data_images_keybinds_Rotate0_png, + data_images_keybinds_Retry_png, data_images_keybinds_Pause_png, }; diff --git a/xmake.lua b/xmake.lua index d579661..9b0c35e 100644 --- a/xmake.lua +++ b/xmake.lua @@ -2,6 +2,8 @@ add_rules("mode.debug", "mode.release") includes("xmake/bin2c.lua") +set_warnings("all") + add_requires("sfml 3.0.0", "zlib") set_languages("c++20")