decrease file size
All checks were successful
Linux arm64 / Build (push) Successful in 2m27s

This commit is contained in:
2025-07-20 21:39:10 +02:00
parent a3ef52c7a1
commit dd6da58642

View File

@@ -51,11 +51,11 @@ bool PiecesFiles::savePieces(int polyominoSize, std::vector<Polyomino>& polyomin
buffer << infoByte; buffer << infoByte;
const int bitsNeeded = polyomino.getLength() * polyomino.getLength(); const int bitsNeeded = polyomino.getLength() * polyomino.getLength();
const int longsNeeded = bitsNeeded / 64 + 1; const int bytesNeeded = bitsNeeded / 8 + 1;
// write the positions of the piece // write the positions of the piece
for (int i = 0; i < longsNeeded; i++) { for (int i = 0; i < bytesNeeded; i++) {
buffer << polyomino.getPositionsData()[i]; buffer << static_cast<std::uint8_t>(polyomino.getPositionsData()[i/4] >> ((i%4) * 8));
} }
} }
@@ -99,6 +99,7 @@ bool PiecesFiles::loadPieces(int polyominoSize, std::vector<Piece>& pieces, std:
constexpr char yMask = 0b0000'1111; constexpr char yMask = 0b0000'1111;
std::uint8_t infoByte; std::uint8_t infoByte;
std::uint8_t positionByte;
int i = 0; int i = 0;
while (!buffer.IsFinished()) { while (!buffer.IsFinished()) {
// if (piecesFile.eof()) break; // if (piecesFile.eof()) break;
@@ -110,19 +111,20 @@ bool PiecesFiles::loadPieces(int polyominoSize, std::vector<Piece>& pieces, std:
int length = (infoByte & lengthMask); int length = (infoByte & lengthMask);
const int bitsNeeded = length * length; const int bitsNeeded = length * length;
const int longsNeeded = bitsNeeded / 64 + 1; const int bytesNeeded = bitsNeeded / 8 + 1;
// read positions // read positions
Polyomino::PolyominoData polyominoData{}; Polyomino::PolyominoData polyominoData{};
for (int i = 0; i < longsNeeded; i++) {
buffer >> polyominoData[i]; for (int j = 0; j < bytesNeeded; j++) {
buffer >> positionByte;
polyominoData[j/4] |= static_cast<std::uint64_t>(positionByte) << ((j%4) * 8);
} }
// create piece pieces.emplace_back(Polyomino(std::move(polyominoData), length), pieceBlock);
Piece readPiece(Polyomino(std::move(polyominoData), length), pieceBlock);
nextPieceBlockType(pieceBlock); nextPieceBlockType(pieceBlock);
pieces.push_back(readPiece);
if (isConvex) { if (isConvex) {
convexPieces.push_back(i); convexPieces.push_back(i);
} }