Acabat de renamar, encara que he descobert cosetes i tindré que fer altra pasaeta

Actualitzat stb_image.h a la última versió
This commit is contained in:
2024-10-12 22:25:43 +02:00
parent cce14dba4d
commit 33ea8d90ca
16 changed files with 528 additions and 431 deletions
+35 -35
View File
@@ -8,40 +8,40 @@
// Constructor
ManageHiScoreTable::ManageHiScoreTable(std::vector<HiScoreEntry> *table)
: table(table) {}
: table_(table) {}
// Resetea la tabla a los valores por defecto
void ManageHiScoreTable::clear()
{
// Limpia la tabla
table->clear();
table_->clear();
// Añade 10 entradas predefinidas
table->push_back({"Bry", 1000000});
table->push_back({"Usufondo", 500000});
table->push_back({"G.Lucas", 100000});
table->push_back({"P.Delgat", 50000});
table->push_back({"P.Arrabalera", 10000});
table->push_back({"Pelechano", 5000});
table->push_back({"Sahuquillo", 1000});
table->push_back({"Bacteriol", 500});
table->push_back({"Pepe", 200});
table->push_back({"Rosita", 100});
table_->push_back({"Bry", 1000000});
table_->push_back({"Usufondo", 500000});
table_->push_back({"G.Lucas", 100000});
table_->push_back({"P.Delgat", 50000});
table_->push_back({"P.Arrabalera", 10000});
table_->push_back({"Pelechano", 5000});
table_->push_back({"Sahuquillo", 1000});
table_->push_back({"Bacteriol", 500});
table_->push_back({"Pepe", 200});
table_->push_back({"Rosita", 100});
}
// Añade un elemento a la tabla
void ManageHiScoreTable::add(HiScoreEntry entry)
{
// Añade la entrada a la tabla
table->push_back(entry);
table_->push_back(entry);
// Ordena la tabla
sort();
// Deja solo las 10 primeras entradas
if ((int)table->size() > 10)
if (static_cast<int>(table_->size()) > 10)
{
table->resize(10);
table_->resize(10);
}
}
@@ -51,30 +51,30 @@ void ManageHiScoreTable::sort()
struct
{
bool operator()(HiScoreEntry a, HiScoreEntry b) const { return a.score > b.score; }
} customLess;
} custom_less;
std::sort(table->begin(), table->end(), customLess);
std::sort(table_->begin(), table_->end(), custom_less);
}
// Carga la tabla con los datos de un fichero
bool ManageHiScoreTable::loadFromFile(std::string filePath)
bool ManageHiScoreTable::loadFromFile(std::string file_path)
{
clear();
bool success = true;
const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1);
SDL_RWops *file = SDL_RWFromFile(filePath.c_str(), "r+b");
auto success = true;
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
auto file = SDL_RWFromFile(file_path.c_str(), "r+b");
if (file)
{
#ifdef DEBUG
#ifdef VERBOSE
std::cout << "Reading file: " << filename.c_str() << std::endl;
#endif
for (int i = 0; i < (int)table->size(); ++i)
for (int i = 0; i < (int)table_->size(); ++i)
{
int nameSize = 0;
if (SDL_RWread(file, &table->at(i).score, sizeof(int), 1) == 0)
if (SDL_RWread(file, &table_->at(i).score, sizeof(int), 1) == 0)
{
success = false;
break;
@@ -96,7 +96,7 @@ bool ManageHiScoreTable::loadFromFile(std::string filePath)
else
{
name[nameSize] = 0;
table->at(i).name = name;
table_->at(i).name = name;
free(name);
}
}
@@ -113,24 +113,24 @@ bool ManageHiScoreTable::loadFromFile(std::string filePath)
}
// Guarda la tabla en un fichero
bool ManageHiScoreTable::saveToFile(std::string filePath)
bool ManageHiScoreTable::saveToFile(std::string file_path)
{
bool success = true;
const std::string fileName = filePath.substr(filePath.find_last_of("\\/") + 1);
SDL_RWops *file = SDL_RWFromFile(filePath.c_str(), "w+b");
auto success = true;
const std::string fileName = file_path.substr(file_path.find_last_of("\\/") + 1);
auto file = SDL_RWFromFile(file_path.c_str(), "w+b");
if (file)
{
// Guarda los datos
for (int i = 0; i < (int)table->size(); ++i)
for (int i = 0; i < (int)table_->size(); ++i)
{
SDL_RWwrite(file, &table->at(i).score, sizeof(int), 1);
const int nameSize = (int)table->at(i).name.size();
SDL_RWwrite(file, &table_->at(i).score, sizeof(int), 1);
const int nameSize = (int)table_->at(i).name.size();
SDL_RWwrite(file, &nameSize, sizeof(int), 1);
SDL_RWwrite(file, table->at(i).name.c_str(), nameSize, 1);
SDL_RWwrite(file, table_->at(i).name.c_str(), nameSize, 1);
}
#ifdef DEBUG
#ifdef VERBOSE
std::cout << "Writing file: " << fileName.c_str() << std::endl;
#endif
// Cierra el fichero
@@ -138,7 +138,7 @@ bool ManageHiScoreTable::saveToFile(std::string filePath)
}
else
{
#ifdef DEBUG
#ifdef VERBOSE
std::cout << "Error: Unable to save " << fileName.c_str() << " file! " << SDL_GetError() << std::endl;
#endif
}