2 Commits

Author SHA1 Message Date
1a95765877 variable max polyo size 2025-03-31 14:12:36 +02:00
6bff555cbc fix les gros polyos 2025-03-31 11:25:23 +02:00
10 changed files with 111 additions and 33 deletions

View File

@@ -48,4 +48,7 @@ The settings file has the following format:
- The last selected height of the board, stored with 1 byte
- The uniformity mode (0 for default distribution, 1 for uniformous distribution, 2 for custom distribution), stored with 1 byte
- For each size, store the custom proportion (from 0 to 10) (15x1 byte total)
- Every selected pieces, using 1 byte for the type of selection (once again converted from an Enum) and 1 byte for the actual value
- Every selected pieces
- For every groupe of piece (ALL, CONVEX, HOLELESS, OTHER), use 1 byte for the type (once again converted from an Enum) and 1 byte for the size
- For every single piece, use 1 byte for (the size + encoding that it is a single piece),
and 3 bytes to store the number of the piece (allows number up to 16M, size 15 has 6M pieces).

View File

@@ -12,7 +12,7 @@ GameDistributionAppMenu::GameDistributionAppMenu(std::shared_ptr<MenuStack> menu
AppMenu(menuStack, settings, renderWindow),
playerCursor({1}) {
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
for (int i = 1; i <= this->settings->getMaximumPiecesSize(); i++) {
this->playerCursor.addRow(i, 1);
}
}
@@ -65,7 +65,7 @@ void GameDistributionAppMenu::drawFrame() const {
const DistributionMode distributionMode = this->settings->getMenu().readPiecesList().getDistributionMode();
const std::vector<int>& distributions = this->settings->getDistributions();
int firstElem = std::clamp(((int) this->playerCursor.getPosition().y) - 1, 0, MAXIMUM_PIECES_SIZE - 3);
int firstElem = std::clamp(((int) this->playerCursor.getPosition().y) - 1, 0, this->settings->getMaximumPiecesSize() - 3);
if (firstElem == 0) {
this->placeText(text, this->playerCursor, "< DISTRIBUTION MODE: " + getPiecesDistributionName(distributionMode) + " >", 5.f, 15.f, sf::Vector2u{0, 0});
}

View File

@@ -13,7 +13,7 @@ GamePiecesAppMenu::GamePiecesAppMenu(std::shared_ptr<MenuStack> menuStack, std::
AppMenu(menuStack, settings, renderWindow),
playerCursor({1, (unsigned int) this->settings->getSelectedPieces().size() + 1u}) {
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
for (int i = 1; i <= this->settings->getMaximumPiecesSize(); i++) {
this->playerCursor.addRow(i + 1, this->settings->getMenu().readPiecesList().getNumberOfPieces(i) + 4);
}
}
@@ -53,11 +53,7 @@ void GamePiecesAppMenu::computeFrame() {
}
}
else {
if (this->settings->getSelectedPieces().size() == 0) {
this->settings->selectPieces(ALL_PIECES, 4);
}
this->settings->confirmSelectedPieces();
this->menuStack->pop();
}
}
@@ -82,7 +78,7 @@ void GamePiecesAppMenu::drawFrame() const {
this->drawSelectedPiecesRow(15.f);
bool drawFromFirstElem = (this->playerCursor.getPosition().y == 1);
int firstElem = std::clamp(((int) this->playerCursor.getPosition().y) - 2, 1, MAXIMUM_PIECES_SIZE - 2);
int firstElem = std::clamp(((int) this->playerCursor.getPosition().y) - 2, 1, this->settings->getMaximumPiecesSize() - 2);
this->drawRow(firstElem, 25.f, drawFromFirstElem);
this->drawRow(firstElem + 1, 35.f, drawFromFirstElem);
this->drawRow(firstElem + 2, 45.f, drawFromFirstElem);

View File

@@ -11,8 +11,8 @@
static const double TIME_BETWEEN_FRAMES = (1000.f / FRAMES_PER_SECOND);
GraphApp::GraphApp() {
this->settings = std::make_shared<Settings>();
GraphApp::GraphApp(int maximumPiecesSize) {
this->settings = std::make_shared<Settings>(maximumPiecesSize);
this->menuStack = std::make_shared<MenuStack>();
this->renderWindow = std::make_shared<sf::RenderWindow>();
}

View File

@@ -15,7 +15,7 @@ class GraphApp {
std::shared_ptr<sf::RenderWindow> renderWindow;
public:
GraphApp();
GraphApp(int maximumPiecesSize);
void run();
};

View File

@@ -14,8 +14,9 @@ static const int START_TIMER_MAX = 4;
static const int DISTRIBUTION_MAX = 10;
Settings::Settings() {
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
Settings::Settings(int maximumPiecesSize) {
this->maximumPiecesSize = maximumPiecesSize;
for (int i = 1; i <= this->maximumPiecesSize; i++) {
this->menu.getPiecesList().loadPieces(i);
}
@@ -81,13 +82,31 @@ void Settings::loadSettingsFromFile() {
// selected pieces
char pieceType;
char pieceValue;
char pieceSize;
char lowByte;
char midByte;
char highByte;
this->selectedPieces.clear();
while (settingsFile.get(pieceType)) {
if (settingsFile.eof()) break;
settingsFile.get(pieceValue);
this->selectedPieces.push_back({PiecesType(pieceType), pieceValue});
if (getSizeOfPieces(PiecesType(pieceType)) == 0) {
settingsFile.get(pieceSize);
if (!(pieceSize > this->maximumPiecesSize)) {
this->selectedPieces.emplace_back(PiecesType(pieceType), pieceSize);
}
}
else {
if (!(getSizeOfPieces(PiecesType(pieceType)) > this->maximumPiecesSize)) {
settingsFile.get(lowByte);
settingsFile.get(midByte);
settingsFile.get(highByte);
int pieceNumber = ((unsigned char) lowByte) + ((unsigned char) midByte << 8) + ((unsigned char) highByte << 16);
this->selectedPieces.emplace_back(PiecesType(pieceType), pieceNumber);
}
}
}
this->confirmSelectedPieces();
}
@@ -147,8 +166,18 @@ void Settings::saveSettingsToFile() const {
for (const auto& [type, value] : this->selectedPieces) {
byte = type;
settingsFile.write(&byte, 1);
byte = value;
settingsFile.write(&byte, 1);
if (getSizeOfPieces(type) == 0) {
byte = value;
settingsFile.write(&byte, 1);
}
else {
int number = value;
for (int i = 0; i < 3; i++) {
byte = (number % 256);
settingsFile.write(&byte, 1);
number = (number >> 8);
}
}
}
}
@@ -230,6 +259,10 @@ void Settings::unselectPieces(int index) {
void Settings::confirmSelectedPieces() {
this->menu.getPiecesList().unselectAll();
if (this->getSelectedPieces().size() == 0) {
this->selectedPieces.push_back(DEFAULT_SELECTION);
}
for (const auto& [type, value] : this->selectedPieces) {
int size = getSizeOfPieces(type);
@@ -242,15 +275,13 @@ void Settings::confirmSelectedPieces() {
}
}
else {
if (size > MAXIMUM_PIECES_SIZE) return;
this->menu.getPiecesList().selectPiece(size, value);
}
}
}
bool Settings::increaseDistribution(int size) {
if (size < 1 || size > MAXIMUM_PIECES_SIZE) return false;
if (size < 1 || size > this->maximumPiecesSize) return false;
if (this->distributions.at(size) < DISTRIBUTION_MAX) {
this->distributions.at(size)++;
@@ -260,7 +291,7 @@ bool Settings::increaseDistribution(int size) {
}
bool Settings::decreaseDistribution(int size) {
if (size < 1 || size > MAXIMUM_PIECES_SIZE) return false;
if (size < 1 || size > this->maximumPiecesSize) return false;
if (this->distributions.at(size) > 0) {
this->distributions.at(size)--;
@@ -283,6 +314,10 @@ Keybinds& Settings::getKeybinds() {
return this->keybinds.at(this->chosenKeybinds);
}
int Settings::getMaximumPiecesSize() const {
return this->maximumPiecesSize;
}
int Settings::getKeybindsLayout() const {
return this->chosenKeybinds;
}

View File

@@ -1,6 +1,7 @@
#pragma once
#include "../Core/Menu.h"
#include "StartUpMenu.h"
#include "Keybinds.h"
#include "PiecesType.h"
@@ -10,17 +11,11 @@
static const int MAXIMUM_BOARD_WIDTH = 40;
static const int MAXIMUM_BOARD_HEIGHT = 40;
//#define __JMINOS_RELEASE__
#ifdef __JMINOS_RELEASE__
static const int MAXIMUM_PIECES_SIZE = 15;
#else
static const int MAXIMUM_PIECES_SIZE = 10;
#endif
class Settings {
private:
Menu menu;
int maximumPiecesSize;
std::vector<Keybinds> keybinds;
int chosenKeybinds;
int windowSizeMode;
@@ -30,7 +25,7 @@ class Settings {
std::vector<int> distributions;
public:
Settings();
Settings(int maximumPiecesSize);
void loadSettingsFromFile();
@@ -70,6 +65,8 @@ class Settings {
Keybinds& getKeybinds();
int getMaximumPiecesSize() const;
int getKeybindsLayout() const;
Gamemode getGamemode() const;

View File

@@ -0,0 +1,15 @@
#include "StartUpMenu.h"
#include "PlayerCursor.h"
StartUpMenu::StartUpMenu() :
playerCursor({LOADED_PIECES_SIZE}) {
this->playerCursor.goToPosition({MINIMUM_PIECES_SIZE, 0});
}
int StartUpMenu::getMaximumPiecesSize() {
return LOADED_PIECES_SIZE;
//TODO
}

View File

@@ -0,0 +1,28 @@
#pragma once
#include "PiecesType.h"
#include "PlayerCursor.h"
static const int MINIMUM_PIECES_SIZE = 4;
static const int MAXIMUM_PIECES_SIZE = 15;
//#define __JMINOS_RELEASE__
#ifdef __JMINOS_RELEASE__
static const int LOADED_PIECES_SIZE = 15;
#else
static const int LOADED_PIECES_SIZE = 10;
#endif
static const std::pair<PiecesType, int> DEFAULT_SELECTION = {ALL_PIECES, MINIMUM_PIECES_SIZE};
class StartUpMenu {
private:
PlayerCursor playerCursor;
public:
StartUpMenu();
int getMaximumPiecesSize();
};

View File

@@ -1,3 +1,4 @@
#include "StartUpMenu.h"
#include "GraphApp.h"
#include "../Pieces/PiecesFiles.h"
@@ -13,7 +14,7 @@ int main() {
std::srand(std::time(NULL));
PiecesFiles pf;
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
for (int i = 1; i <= LOADED_PIECES_SIZE; i++) {
if (!std::filesystem::exists("data/pieces/" + std::to_string(i) + "minos.bin")) {
std::cout << "pieces files for size " << i << " not found, generating..." << std::endl;
pf.savePieces(i);
@@ -30,7 +31,10 @@ int main() {
}
}
GraphApp UI;
StartUpMenu startUp;
int maximumPiecesSize = startUp.getMaximumPiecesSize();
GraphApp UI(maximumPiecesSize);
UI.run();
return 0;