petits [[nodiscard]] pour le fun
All checks were successful
Linux arm64 / Build (push) Successful in 12m30s

This commit is contained in:
2025-06-19 22:31:41 +02:00
parent 34d781fcfe
commit 8342bf3969
6 changed files with 38 additions and 23 deletions

View File

@@ -35,25 +35,35 @@ void benchmarking(int min_size, int max_size) {
Generator gen;
PiecesFiles pf;
auto t1 = high_resolution_clock::now();
auto t2 = high_resolution_clock::now();
duration<double, std::milli> ms_double;
bool ok;
for (int i = min_size; i <= max_size; i++) {
std::cout << "| " << i;
auto t1 = high_resolution_clock::now();
t1 = high_resolution_clock::now();
std::vector<Polyomino> polyominoes = gen.generatePolyominoes(i);
auto t2 = high_resolution_clock::now();
duration<double, std::milli> ms_double = t2 - t1;
t2 = high_resolution_clock::now();
ms_double = t2 - t1;
std::cout << " | " << polyominoes.size();
std::flush(std::cout);
std::cout << " | " << (int) ms_double.count() / 1000 << "s " << std::fmod(ms_double.count(), 1000) << "ms ";
std::flush(std::cout);
t1 = high_resolution_clock::now();
pf.savePieces(i, polyominoes);
ok = pf.savePieces(i, polyominoes);
t2 = high_resolution_clock::now();
ms_double = t2 - t1;
std::cout << " | " << (int) ms_double.count() / 1000 << "s " << std::fmod(ms_double.count(), 1000) << "ms ";
std::flush(std::cout);
if (!ok) {
std::cerr << "\nERROR: Could not save pieces to file." << std::endl;
return;
}
polyominoes.clear();
polyominoes.shrink_to_fit();
@@ -63,12 +73,17 @@ void benchmarking(int min_size, int max_size) {
std::vector<int> otherPieces;
t1 = high_resolution_clock::now();
pf.loadPieces(i, pieces, convexPieces, holelessPieces, otherPieces);
ok = pf.loadPieces(i, pieces, convexPieces, holelessPieces, otherPieces);
t2 = high_resolution_clock::now();
ms_double = t2 - t1;
std::cout << " | " << (int) ms_double.count() / 1000 << "s " << std::fmod(ms_double.count(), 1000) << "ms ";
std::flush(std::cout);
if (!ok) {
std::cerr << "\nERROR: Could not load pieces from file." << std::endl;
return;
}
pieces.clear();
pieces.shrink_to_fit();
convexPieces.clear();

View File

@@ -4,7 +4,7 @@
#include "Player.h"
#include "Game.h"
static const int FRAMES_PER_SECOND = 60; // the number of frames per second, all the values in the app were choosen with this number in mind
static const int FRAMES_PER_SECOND = 60; // the number of frames per second, all the values in the app were choosen with this number in mind
/**

View File

@@ -27,13 +27,12 @@ PiecesList::PiecesList() {
this->pushBackEmptyVectors();
}
bool PiecesList::loadPieces(int size) {
if (size < 1) return false;
if (size <= this->highestLoadedSize) return true;
bool PiecesList::loadPieces(int max_size) {
if (max_size < 1) return false;
if (max_size <= this->highestLoadedSize) return true;
PiecesFiles piecesFiles;
for (int i = this->highestLoadedSize + 1; i <= size; i++) {
for (int 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;
}

View File

@@ -30,10 +30,10 @@ class PiecesList {
PiecesList();
/**
* Makes the list load all pieces of the specified size
* @return If it sucessfully loaded the pieces
* Makes the list load all pieces up to the specified size
* @return If all pieces up to the specified size are correctly loaded
*/
bool loadPieces(int size);
[[nodiscard]] bool loadPieces(int max_size);
/**
* Selects the specified piece

View File

@@ -18,21 +18,21 @@ class PiecesFiles {
/**
* Generate a file containing all the pieces of the specified size
* @return If the file could be created
* @return If the pieces are saved correctly
*/
bool savePieces(int polyominoSize) const;
[[nodiscard]] bool savePieces(int polyominoSize) const;
/**
* Generate a file containing all the pieces of the specified size, assuming they have been correctly generated
* @return If the file could be created
* @return If the piece are saved correctly
*/
bool savePieces(int polyominoSize, std::vector<Polyomino>& polyominoes) const;
[[nodiscard]] bool savePieces(int polyominoSize, std::vector<Polyomino>& polyominoes) const;
/**
* Replace the content of the vectors by the pieces of the specified size, if the file wasn't found the vectors stays untouched
* @return If the file was found
* Replace the content of the vectors by the pieces of the specified size, if the pieces can't be loaded correctly the vectors stays untouched
* @return If the pieces could be loaded correctly
*/
bool loadPieces(int polyominoSize, std::vector<Piece>& pieces, std::vector<int>& convexPieces, std::vector<int>& holelessPieces, std::vector<int>& otherPieces) const;
[[nodiscard]] bool loadPieces(int polyominoSize, std::vector<Piece>& pieces, std::vector<int>& convexPieces, std::vector<int>& holelessPieces, std::vector<int>& otherPieces) const;
/**
* Puts the path to the piece file of the specified size in order, if the data folder wasn't found the string stays untouched