fix some compiler warnings
All checks were successful
Linux arm64 / Build (push) Successful in 2m27s

This commit is contained in:
2025-07-20 23:02:45 +02:00
parent ecc035c972
commit 4095103843
11 changed files with 67 additions and 67 deletions

View File

@@ -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<unsigned>(position.x) >= this->width || position.y < 0) return;
// resize the grid if needed
if (position.y >= this->grid.size()) {
if (static_cast<unsigned>(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<Block> 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;

View File

@@ -13,8 +13,8 @@ class Board {
private:
std::vector<std::vector<Block>> grid; // the grid, (0,0) is downleft
std::vector<Block> 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:
/**

View File

@@ -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<int, int>(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++) {

View File

@@ -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<std::vector<Piece>> loadedPieces; // every loaded pieces by size
std::vector<std::vector<int>> convexPieces; // the list of convex loaded pieces by size
std::vector<std::vector<int>> 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

View File

@@ -26,7 +26,7 @@ std::vector<Polyomino>&& Generator::generatePolyominoes(int polyominoSize) {
return std::move(this->validPolyominoes);
}
void Generator::generate(int polyominoSize, int lastAddedPositionNumber, int nextAvaibleNumber, std::map<Position, int> candidatePositions) {
void Generator::generate(unsigned polyominoSize, int lastAddedPositionNumber, int nextAvaibleNumber, std::map<Position, int> 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<Position, int>() : candidatePositions);

View File

@@ -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<Position, int> candidatePositions);
void generate(unsigned polyominoSize, int lastAddedPositionNumber, int nextAvaibleNumber, std::map<Position, int> candidatePositions);
/**
* Checks wheter a candidate position can be added to the current tested shape

View File

@@ -100,8 +100,6 @@ bool PiecesFiles::loadPieces(int polyominoSize, std::vector<Piece>& 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;

View File

@@ -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];
}

View File

@@ -10,30 +10,6 @@ static const unsigned char data_fonts_pressstart_prstartk_ttf[] = {
#include <data/fonts/pressstart/prstartk.ttf.h>
};
static const unsigned char data_images_keybinds_Rotate180_png[] = {
#include <data/images/keybinds/Rotate180.png.h>
};
static const unsigned char data_images_keybinds_Rotate0_png[] = {
#include <data/images/keybinds/Rotate0.png.h>
};
static const unsigned char data_images_keybinds_RotateCCW_png[] = {
#include <data/images/keybinds/RotateCCW.png.h>
};
static const unsigned char data_images_keybinds_Retry_png[] = {
#include <data/images/keybinds/Retry.png.h>
};
static const unsigned char data_images_keybinds_RotateCW_png[] = {
#include <data/images/keybinds/RotateCW.png.h>
};
static const unsigned char data_images_keybinds_Moveright_png[] = {
#include <data/images/keybinds/Moveright.png.h>
};
static const unsigned char data_images_keybinds_Harddrop_png[] = {
#include <data/images/keybinds/Harddrop.png.h>
};
@@ -42,14 +18,38 @@ static const unsigned char data_images_keybinds_Moveleft_png[] = {
#include <data/images/keybinds/Moveleft.png.h>
};
static const unsigned char data_images_keybinds_Hold_png[] = {
#include <data/images/keybinds/Hold.png.h>
static const unsigned char data_images_keybinds_RotateCW_png[] = {
#include <data/images/keybinds/RotateCW.png.h>
};
static const unsigned char data_images_keybinds_RotateCCW_png[] = {
#include <data/images/keybinds/RotateCCW.png.h>
};
static const unsigned char data_images_keybinds_Softdrop_png[] = {
#include <data/images/keybinds/Softdrop.png.h>
};
static const unsigned char data_images_keybinds_Moveright_png[] = {
#include <data/images/keybinds/Moveright.png.h>
};
static const unsigned char data_images_keybinds_Rotate180_png[] = {
#include <data/images/keybinds/Rotate180.png.h>
};
static const unsigned char data_images_keybinds_Hold_png[] = {
#include <data/images/keybinds/Hold.png.h>
};
static const unsigned char data_images_keybinds_Rotate0_png[] = {
#include <data/images/keybinds/Rotate0.png.h>
};
static const unsigned char data_images_keybinds_Retry_png[] = {
#include <data/images/keybinds/Retry.png.h>
};
static const unsigned char data_images_keybinds_Pause_png[] = {
#include <data/images/keybinds/Pause.png.h>
};
@@ -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<std::string, AssetName> 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},
};

View File

@@ -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,
};

View File

@@ -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")