diff --git a/data/config/demo1.bin b/data/config/demo1.bin index d886e4a..d17b069 100644 Binary files a/data/config/demo1.bin and b/data/config/demo1.bin differ diff --git a/source/const.h b/source/const.h index 5d9c0f0..f16010a 100644 --- a/source/const.h +++ b/source/const.h @@ -6,8 +6,6 @@ #ifndef CONST_H #define CONST_H -#define RECORDING - // Tamaño de bloque #define BLOCK 8 #define HALF_BLOCK BLOCK / 2 diff --git a/source/game.cpp b/source/game.cpp index 1f5464b..025665e 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -34,23 +34,13 @@ Game::Game(int playerID, int currentStage, SDL_Renderer *renderer, Screen *scree // Inicializa los vectores con los datos para la demo if (demo) { - std::vector tmp; - this->demo.dataFile.clear(); - this->demo.dataFile.push_back(tmp); - this->demo.dataFile.push_back(tmp); - // Aleatoriza la asignación del fichero const int index1 = rand() % 2; const int index2 = (index1 + 1) % 2; - loadDemoFile(asset->get("demo1.bin"), &this->demo.dataFile.at(index1)); - loadDemoFile(asset->get("demo2.bin"), &this->demo.dataFile.at(index2)); + loadDemoFile(asset->get("demo1.bin"), &this->demo.dataFile[index1]); + loadDemoFile(asset->get("demo2.bin"), &this->demo.dataFile[index2]); } -#ifdef RECORDING - // Prepara el vector para recoger los datos - //this->demo.dataFile[0].clear(); -#endif - // Establece la máxima puntuación desde fichero o desde las puntuaciones online setHiScore(); @@ -277,7 +267,7 @@ void Game::init(int playerID) } // Activa o no al otro jugador - // if (rand() % 3 == 0) + if (rand() % 3 == 0) { const int otherPlayer = playerID == 1 ? 2 : 1; players[otherPlayer - 1]->enable(true); @@ -628,7 +618,7 @@ bool Game::loadScoreFile() } // Carga el fichero de datos para la demo -bool Game::loadDemoFile(std::string f, std::vector *dataFile) +bool Game::loadDemoFile(std::string f, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA]) { // Indicador de éxito en la carga bool success = true; @@ -655,7 +645,6 @@ bool Game::loadDemoFile(std::string f, std::vector *dataFile) } // Inicializas los datos y los guarda en el fichero - dataFile->clear(); for (int i = 0; i < TOTAL_DEMO_DATA; ++i) { demoKeys_t tmp; @@ -665,7 +654,7 @@ bool Game::loadDemoFile(std::string f, std::vector *dataFile) tmp.fire = 0; tmp.fireLeft = 0; tmp.fireRight = 0; - dataFile->push_back(tmp); + (*dataFile)[i] = tmp; SDL_RWwrite(file, &tmp, sizeof(demoKeys_t), 1); } @@ -690,15 +679,12 @@ bool Game::loadDemoFile(std::string f, std::vector *dataFile) std::cout << "Reading file " << filename.c_str() << std::endl; } - // Inicializa el destino - dataFile->clear(); - // Lee todos los datos del fichero y los deja en el destino for (int i = 0; i < TOTAL_DEMO_DATA; ++i) { demoKeys_t tmp; SDL_RWread(file, &tmp, sizeof(demoKeys_t), 1); - dataFile->push_back(tmp); + (*dataFile)[i] = tmp; } // Cierra el fichero @@ -749,31 +735,31 @@ bool Game::saveDemoFile() const std::string p = asset->get("demo1.bin"); const std::string filename = p.substr(p.find_last_of("\\/") + 1); - SDL_RWops *file = SDL_RWFromFile(p.c_str(), "w+b"); - if (file != nullptr) + SDL_RWops *file = SDL_RWFromFile(p.c_str(), "w+b"); + if (file != nullptr) + { + // Guardamos los datos + for (int i = 0; i < TOTAL_DEMO_DATA; ++i) { - // Guardamos los datos - for (int i = 0; i < TOTAL_DEMO_DATA; ++i) - { - SDL_RWwrite(file, &demo.dataFile[0][i], sizeof(demoKeys_t), 1); - } - - if (options->console) - { - std::cout << "Writing file " << filename.c_str() << std::endl; - } - - // Cerramos el fichero - SDL_RWclose(file); + SDL_RWwrite(file, &demo.dataFile[0][i], sizeof(demoKeys_t), 1); } - else + + if (options->console) { - if (options->console) - { - std::cout << "Error: Unable to save " << filename.c_str() << " file! " << SDL_GetError() << std::endl; - } + std::cout << "Writing file " << filename.c_str() << std::endl; } - + + // Cerramos el fichero + SDL_RWclose(file); + } + else + { + if (options->console) + { + std::cout << "Error: Unable to save " << filename.c_str() << " file! " << SDL_GetError() << std::endl; + } + } + return success; } #endif @@ -2793,9 +2779,9 @@ void Game::checkInput() // Modo Demo activo if (demo.enabled) { + int i = 0; for (auto player : players) { - int i = 0; if (player->isAlive() && player->isEnabled()) { // Comprueba direcciones diff --git a/source/game.h b/source/game.h index 0066374..8d7bf4f 100644 --- a/source/game.h +++ b/source/game.h @@ -232,7 +232,7 @@ private: bool loadScoreFile(); // Carga el fichero de datos para la demo - bool loadDemoFile(std::string fileName, std::vector *dataFile); + bool loadDemoFile(std::string fileName, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA]); // Guarda el fichero de puntos bool saveScoreFile();