diff --git a/source/cheevos.cpp b/source/cheevos.cpp index b9a4ac8..c258ef1 100644 --- a/source/cheevos.cpp +++ b/source/cheevos.cpp @@ -8,6 +8,27 @@ #include "options.h" #include // Para fstream +// [SINGLETON] +Cheevos *Cheevos::cheevos_ = nullptr; + +// [SINGLETON] Crearemos el objeto con esta función estática +void Cheevos::init(const std::string &file) +{ + Cheevos::cheevos_ = new Cheevos(file); +} + +// [SINGLETON] Destruiremos el objeto con esta función estática +void Cheevos::destroy() +{ + delete Cheevos::cheevos_; +} + +// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él +Cheevos *Cheevos::get() +{ + return Cheevos::cheevos_; +} + // Constructor Cheevos::Cheevos(const std::string &file) : file_(file) @@ -25,27 +46,27 @@ Cheevos::~Cheevos() // Inicializa los logros void Cheevos::init() { - cheevos_.clear(); - cheevos_.emplace_back(1, "SHINY THINGS", "Get 25% of the items", 2); - cheevos_.emplace_back(2, "HALF THE WORK", "Get 50% of the items", 2); - cheevos_.emplace_back(3, "GETTING THERE", "Get 75% of the items", 2); - cheevos_.emplace_back(4, "THE COLLECTOR", "Get 100% of the items", 2); - cheevos_.emplace_back(5, "WANDERING AROUND", "Visit 20 rooms", 2); - cheevos_.emplace_back(6, "I GOT LOST", "Visit 40 rooms", 2); - cheevos_.emplace_back(7, "I LIKE TO EXPLORE", "Visit all rooms", 2); - cheevos_.emplace_back(8, "FINISH THE GAME", "Complete the game", 2); - cheevos_.emplace_back(9, "I WAS SUCKED BY A HOLE", "Complete the game without entering the jail", 2); - cheevos_.emplace_back(10, "MY LITTLE PROJECTS", "Complete the game with all items", 2); - cheevos_.emplace_back(11, "I LIKE MY MULTICOLOURED FRIENDS", "Complete the game without dying", 2); - cheevos_.emplace_back(12, "SHIT PROJECTS DONE FAST", "Complete the game in under 30 minutes", 2); + cheevos_list_.clear(); + cheevos_list_.emplace_back(1, "SHINY THINGS", "Get 25% of the items", 2); + cheevos_list_.emplace_back(2, "HALF THE WORK", "Get 50% of the items", 2); + cheevos_list_.emplace_back(3, "GETTING THERE", "Get 75% of the items", 2); + cheevos_list_.emplace_back(4, "THE COLLECTOR", "Get 100% of the items", 2); + cheevos_list_.emplace_back(5, "WANDERING AROUND", "Visit 20 rooms", 2); + cheevos_list_.emplace_back(6, "I GOT LOST", "Visit 40 rooms", 2); + cheevos_list_.emplace_back(7, "I LIKE TO EXPLORE", "Visit all rooms", 2); + cheevos_list_.emplace_back(8, "FINISH THE GAME", "Complete the game", 2); + cheevos_list_.emplace_back(9, "I WAS SUCKED BY A HOLE", "Complete the game without entering the jail", 2); + cheevos_list_.emplace_back(10, "MY LITTLE PROJECTS", "Complete the game with all items", 2); + cheevos_list_.emplace_back(11, "I LIKE MY MULTICOLOURED FRIENDS", "Complete the game without dying", 2); + cheevos_list_.emplace_back(12, "SHIT PROJECTS DONE FAST", "Complete the game in under 30 minutes", 2); } // Busca un logro por id y devuelve el indice int Cheevos::find(int id) { - for (int i = 0; i < (int)cheevos_.size(); ++i) + for (int i = 0; i < (int)cheevos_list_.size(); ++i) { - if (cheevos_[i].id == id) + if (cheevos_list_[i].id == id) { return i; } @@ -60,15 +81,15 @@ void Cheevos::unlock(int id) const int index = find(id); // Si el índice es inválido, el logro no es válido, ya está completado o el sistema de logros no está habilitado, no hacemos nada - if (index == -1 || !cheevos_.at(index).valid || cheevos_.at(index).completed || !enabled_) + if (index == -1 || !cheevos_list_.at(index).valid || cheevos_list_.at(index).completed || !enabled_) { return; } // Marcar el logro como completado - cheevos_.at(index).completed = true; + cheevos_list_.at(index).completed = true; // Mostrar notificación en la pantalla - Notifier::get()->show("ACHIEVEMENT UNLOCKED!", cheevos_.at(index).caption, cheevos_.at(index).icon); + Notifier::get()->show("ACHIEVEMENT UNLOCKED!", cheevos_list_.at(index).caption, cheevos_list_.at(index).icon); // Guardar el estado de los logros saveToFile(); } @@ -81,7 +102,7 @@ void Cheevos::invalidate(int id) // Si el índice es válido, se invalida el logro if (index != -1) { - cheevos_.at(index).valid = false; + cheevos_list_.at(index).valid = false; } } @@ -109,7 +130,7 @@ void Cheevos::loadFromFile() } // Guarda la información - for (const auto &cheevo : cheevos_) + for (const auto &cheevo : cheevos_list_) { newFile.write(reinterpret_cast(&cheevo.completed), sizeof(bool)); } @@ -131,7 +152,7 @@ void Cheevos::loadFromFile() } // Carga los datos - for (auto &cheevo : cheevos_) + for (auto &cheevo : cheevos_list_) { file.read(reinterpret_cast(&cheevo.completed), sizeof(bool)); } @@ -146,9 +167,9 @@ void Cheevos::saveToFile() if (file != NULL) { // Guarda la información - for (int i = 0; i < (int)cheevos_.size(); ++i) + for (int i = 0; i < (int)cheevos_list_.size(); ++i) { - SDL_RWwrite(file, &cheevos_[i].completed, sizeof(bool), 1); + SDL_RWwrite(file, &cheevos_list_[i].completed, sizeof(bool), 1); } // Cierra el fichero @@ -167,7 +188,7 @@ void Cheevos::saveToFile() int Cheevos::unlocked() { int count = 0; - for (auto cheevo : cheevos_) + for (auto cheevo : cheevos_list_) { if (cheevo.completed) { diff --git a/source/cheevos.h b/source/cheevos.h index 5aef832..1ba05e6 100644 --- a/source/cheevos.h +++ b/source/cheevos.h @@ -25,10 +25,13 @@ struct Achievement class Cheevos { private: + // [SINGLETON] Objeto privado + static Cheevos *cheevos_; + // Variables - std::vector cheevos_; // Listado de logros - bool enabled_ = true; // Indica si los logros se pueden obtener - std::string file_; // Fichero donde leer/almacenar el estado de los logros + std::vector cheevos_list_; // Listado de logros + bool enabled_ = true; // Indica si los logros se pueden obtener + std::string file_; // Fichero donde leer/almacenar el estado de los logros // Inicializa los logros void init(); @@ -42,13 +45,22 @@ private: // Guarda el estado de los logros en un fichero void saveToFile(); -public: // Constructor Cheevos(const std::string &file); // Destructor ~Cheevos(); +public: + // [SINGLETON] Crearemos el objeto con esta función estática + static void init(const std::string &file); + + // [SINGLETON] Destruiremos el objeto con esta función estática + static void destroy(); + + // [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él + static Cheevos *get(); + // Desbloquea un logro void unlock(int id); @@ -59,11 +71,11 @@ public: void enable(bool value) { enabled_ = value; } // Lista los logros - std::vector list() { return cheevos_; } + std::vector list() { return cheevos_list_; } // Devuelve el número total de logros desbloqueados int unlocked(); // Devuelve el número total de logros - int count() { return cheevos_.size(); } + int count() { return cheevos_list_.size(); } }; diff --git a/source/credits.cpp b/source/credits.cpp index c939c1e..5757047 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -25,7 +25,6 @@ Credits::Credits() input_(Input::get()) { // Reserva memoria para los punteros - event_handler_ = new SDL_Event(); text_ = new Text(resource_->getOffset("smb2.txt"), resource_->getTexture("smb2.png"), renderer_); sprite_ = new AnimatedSprite(renderer_, resource_->getAnimation("shine.ani")); @@ -66,7 +65,6 @@ Credits::Credits() // Destructor Credits::~Credits() { - delete event_handler_; delete text_; delete sprite_; SDL_DestroyTexture(text_texture_); @@ -76,11 +74,11 @@ Credits::~Credits() // Comprueba el manejador de eventos void Credits::checkEvents() { - // Comprueba los eventos que hay en la cola - while (SDL_PollEvent(event_handler_) != 0) + SDL_Event event; + while (SDL_PollEvent(&event)) { // Evento de salida de la aplicación - if (event_handler_->type == SDL_QUIT) + if (event.type == SDL_QUIT) { options.section.name = SECTION_QUIT; break; diff --git a/source/credits.h b/source/credits.h index cd26b31..1c021aa 100644 --- a/source/credits.h +++ b/source/credits.h @@ -28,7 +28,6 @@ private: Resource *resource_; // Objeto con los recursos Asset *asset_; // Objeto con los ficheros de recursos Input *input_; // Objeto pata gestionar la entrada - SDL_Event *event_handler_; // Manejador de eventos Text *text_; // Objeto para escribir texto en pantalla SDL_Texture *text_texture_; // Textura para dibujar el texto SDL_Texture *cover_texture_; // Textura para cubrir el texto diff --git a/source/demo.cpp b/source/demo.cpp index 5bfe9f4..4622574 100644 --- a/source/demo.cpp +++ b/source/demo.cpp @@ -41,7 +41,6 @@ Demo::Demo() itemTracker = new ItemTracker(); scoreboard = new Scoreboard(&board); room = new Room(resource->getRoom(currentRoom), itemTracker, &board.items, false); - eventHandler = new SDL_Event(); text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer); // Inicializa el resto de variables @@ -66,18 +65,17 @@ Demo::~Demo() delete itemTracker; delete scoreboard; delete room; - delete eventHandler; delete text; } // Comprueba los eventos de la cola void Demo::checkEvents() { - // Comprueba los eventos que hay en la cola - while (SDL_PollEvent(eventHandler) != 0) + SDL_Event event; + while (SDL_PollEvent(&event)) { // Evento de salida de la aplicación - if (eventHandler->type == SDL_QUIT) + if (event.type == SDL_QUIT) { options.section.name = SECTION_QUIT; screen->setBorderColor(stringToColor(options.palette, "black")); @@ -89,7 +87,6 @@ void Demo::checkEvents() // Comprueba las entradas void Demo::checkInput() { - if (input->checkInput(input_exit, REPEAT_FALSE)) { options.section.name = SECTION_QUIT; diff --git a/source/demo.h b/source/demo.h index 7ecd8b0..5e54e5f 100644 --- a/source/demo.h +++ b/source/demo.h @@ -23,7 +23,6 @@ private: // Objetos y punteros Screen *screen; // Objeto encargado de manejar el renderizador SDL_Renderer *renderer; // El renderizador de la ventana - SDL_Event *eventHandler; // Manejador de eventos Room *room; // Objeto encargado de gestionar cada habitación del juego Resource *resource; // Objeto con los recursos Asset *asset; // Objeto con la ruta a todos los ficheros de recursos diff --git a/source/director.cpp b/source/director.cpp index e150f73..6819eea 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -18,26 +18,27 @@ #include // Para basic_ostream, operator<<, cout #include // Para basic_string, operator+, char_... #include // Para vector -#include -#include "asset.h" // Para Asset, assetType -#include "const.h" // Para SECTION_LOGO, SECTION_TITLE -#include "debug.h" // Para Debug -#include "credits.h" // Para Credits -#include "demo.h" // Para Demo -#include "ending.h" // Para Ending -#include "ending2.h" // Para Ending2 -#include "game.h" // Para Game -#include "game_over.h" // Para GameOver -#include "loading_screen.h" // Para LoadingScreen -#include "logo.h" // Para Logo -#include "title.h" // Para Title -#include "input.h" // Para Input, inputs_e -#include "jail_audio.h" // Para JA_GetMusicState, JA_DeleteMusic -#include "resource.h" // Para Resource -#include "screen.h" // Para Screen, FILTER_NEAREST, FILTER... -#include "utils.h" // Para options_t, section_t, op_notif... +#include // Para std::make_unique +#include "asset.h" // Para Asset, assetType +#include "const.h" // Para SECTION_LOGO, SECTION_TITLE +#include "debug.h" // Para Debug +#include "credits.h" // Para Credits +#include "demo.h" // Para Demo +#include "ending.h" // Para Ending +#include "ending2.h" // Para Ending2 +#include "game.h" // Para Game +#include "game_over.h" // Para GameOver +#include "loading_screen.h" // Para LoadingScreen +#include "logo.h" // Para Logo +#include "title.h" // Para Title +#include "input.h" // Para Input, inputs_e +#include "jail_audio.h" // Para JA_GetMusicState, JA_DeleteMusic +#include "resource.h" // Para Resource +#include "screen.h" // Para Screen, FILTER_NEAREST, FILTER... +#include "utils.h" // Para options_t, section_t, op_notif... #include "notifier.h" #include "options.h" +#include "cheevos.h" #ifndef _WIN32 #include @@ -52,7 +53,7 @@ Director::Director(int argc, const char *argv[]) initOptions(); // Comprueba los parametros del programa - checkProgramArguments(argc, argv); + executable_path_ = checkProgramArguments(argc, argv); // Crea el objeto que controla los ficheros de recursos Asset::init(executable_path_); @@ -60,11 +61,7 @@ Director::Director(int argc, const char *argv[]) // Crea la carpeta del sistema donde guardar datos createSystemFolder("jailgames"); -#ifndef DEBUG createSystemFolder("jailgames/jaildoctors_dilemma"); -#else - createSystemFolder("jailgames/jaildoctors_dilemma_debug"); -#endif // Si falta algún fichero no inicia el programa if (!setFileList()) @@ -90,12 +87,13 @@ Director::Director(int argc, const char *argv[]) initInput(); Debug::init(); title_music_ = JA_LoadMusic(Asset::get()->get("title.ogg").c_str()); + Cheevos::init(Asset::get()->get("cheevos.bin")); } Director::~Director() { // Guarda las opciones a un fichero - saveOptionsFromFile(Asset::get()->get("config.txt")); + saveOptionsToFile(Asset::get()->get("config.txt")); // Destruye los singletones Asset::destroy(); @@ -104,6 +102,7 @@ Director::~Director() Notifier::destroy(); Debug::destroy(); Resource::destroy(); + Cheevos::destroy(); JA_DeleteMusic(title_music_); @@ -115,12 +114,9 @@ Director::~Director() } // Comprueba los parametros del programa -void Director::checkProgramArguments(int argc, const char *argv[]) +std::string Director::checkProgramArguments(int argc, const char *argv[]) { - // Establece la ruta del programa - executable_path_ = argv[0]; - - // Comprueba el resto de parametros + // Comprueba los parametros for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "--console") == 0) @@ -148,6 +144,8 @@ void Director::checkProgramArguments(int argc, const char *argv[]) options.cheat.altSkin = true; } } + + return argv[0]; } // Crea la carpeta del sistema donde guardar datos @@ -902,7 +900,7 @@ bool Director::initSDL() else { // Crea un renderizador para la ventana. El vsync se activa en funcion de las opciones - Uint32 flags = 0; + Uint32 flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE; if (options.vSync) { flags = flags | SDL_RENDERER_PRESENTVSYNC; diff --git a/source/director.h b/source/director.h index da21cde..55aa335 100644 --- a/source/director.h +++ b/source/director.h @@ -25,7 +25,7 @@ private: std::string system_folder_; // Carpeta del sistema donde guardar datos // Comprueba los parametros del programa - void checkProgramArguments(int argc, const char *argv[]); + std::string checkProgramArguments(int argc, const char *argv[]); // Crea la carpeta del sistema donde guardar datos void createSystemFolder(const std::string &folder); diff --git a/source/ending.cpp b/source/ending.cpp index bc07509..dd6b34b 100644 --- a/source/ending.cpp +++ b/source/ending.cpp @@ -27,7 +27,6 @@ Ending::Ending() input(Input::get()) { // Reserva memoria para los punteros a objetos - eventHandler = new SDL_Event(); text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer); music = JA_LoadMusic(asset->get("ending1.ogg").c_str()); @@ -72,7 +71,6 @@ Ending::Ending() Ending::~Ending() { // Libera la memoria de los objetos - delete eventHandler; delete text; SDL_DestroyTexture(coverTexture); @@ -159,11 +157,11 @@ void Ending::render() // Comprueba el manejador de eventos void Ending::checkEvents() { - // Comprueba los eventos que hay en la cola - while (SDL_PollEvent(eventHandler) != 0) + SDL_Event event; + while (SDL_PollEvent(&event)) { // Evento de salida de la aplicación - if (eventHandler->type == SDL_QUIT) + if (event.type == SDL_QUIT) { options.section.name = SECTION_QUIT; break; diff --git a/source/ending.h b/source/ending.h index 99a9ded..10d34dc 100644 --- a/source/ending.h +++ b/source/ending.h @@ -55,7 +55,6 @@ private: Resource *resource; // Objeto con los recursos Asset *asset; // Objeto con los ficheros de recursos Input *input; // Objeto pata gestionar la entrada - SDL_Event *eventHandler; // Manejador de eventos Text *text; // Objeto para escribir texto en pantalla SDL_Texture *coverTexture; // Textura para cubrir el texto diff --git a/source/ending2.cpp b/source/ending2.cpp index 5ee7636..b773e09 100644 --- a/source/ending2.cpp +++ b/source/ending2.cpp @@ -24,7 +24,6 @@ Ending2::Ending2() input(Input::get()) { // Reserva memoria para los punteros a objetos - eventHandler = new SDL_Event(); text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer); music = JA_LoadMusic(asset->get("ending2.ogg").c_str()); @@ -73,7 +72,6 @@ Ending2::Ending2() Ending2::~Ending2() { // Libera la memoria de los objetos - delete eventHandler; delete text; JA_DeleteMusic(music); @@ -189,11 +187,11 @@ void Ending2::render() // Comprueba el manejador de eventos void Ending2::checkEvents() { - // Comprueba los eventos que hay en la cola - while (SDL_PollEvent(eventHandler) != 0) + SDL_Event event; + while (SDL_PollEvent(&event)) { // Evento de salida de la aplicación - if (eventHandler->type == SDL_QUIT) + if (event.type == SDL_QUIT) { options.section.name = SECTION_QUIT; break; diff --git a/source/ending2.h b/source/ending2.h index 70816a7..59f7529 100644 --- a/source/ending2.h +++ b/source/ending2.h @@ -26,7 +26,6 @@ private: Resource *resource; // Objeto con los recursos Asset *asset; // Objeto con los ficheros de recursos Input *input; // Objeto pata gestionar la entrada - SDL_Event *eventHandler; // Manejador de eventos Text *text; // Objeto para escribir texto en pantalla std::vector sprites; // Vector con todos los sprites a dibujar std::vector spriteTexts; // Vector con los sprites de texto de los sprites diff --git a/source/game.cpp b/source/game.cpp index e7ce002..38a7ffb 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -48,7 +48,7 @@ Game::Game() #endif // Crea los objetos - cheevos_ = new Cheevos(asset_->get("cheevos.bin")); + cheevos_ = Cheevos::get(); scoreboard_ = new Scoreboard(&board_); item_tracker_ = new ItemTracker(); room_tracker_ = new RoomTracker(); @@ -56,8 +56,7 @@ Game::Game() const std::string playerPNG = options.cheat.altSkin ? "player2.png" : "player.png"; const std::string playerANI = options.cheat.altSkin ? "player2.ani" : "player.ani"; const player_t player = {spawn_point_, playerPNG, playerANI, room_}; - this->player_ = new Player(player); - event_handler_ = new SDL_Event(); + player_ = new Player(player); text_ = new Text(resource_->getOffset("smb2.txt"), resource_->getTexture("smb2.png"), renderer_); music_ = JA_LoadMusic(asset_->get("game.ogg").c_str()); death_sound_ = JA_LoadSound(asset_->get("death.wav").c_str()); @@ -111,13 +110,11 @@ Game::Game() Game::~Game() { // Libera la memoria de los objetos - delete cheevos_; delete scoreboard_; delete item_tracker_; delete room_tracker_; delete room_; delete player_; - delete event_handler_; delete text_; delete stats_; @@ -130,25 +127,25 @@ Game::~Game() // Comprueba los eventos de la cola void Game::checkEvents() { - // Comprueba los eventos que hay en la cola - while (SDL_PollEvent(event_handler_) != 0) + SDL_Event event; + while (SDL_PollEvent(&event)) { // Evento de salida de la aplicación - if (event_handler_->type == SDL_QUIT) + if (event.type == SDL_QUIT) { options.section.name = SECTION_QUIT; screen_->setBorderColor(stringToColor(options.palette, "black")); break; } - if (event_handler_->type == SDL_RENDER_DEVICE_RESET || event_handler_->type == SDL_RENDER_TARGETS_RESET) + if (event.type == SDL_RENDER_DEVICE_RESET || event.type == SDL_RENDER_TARGETS_RESET) { reLoadTextures(); } - if (event_handler_->type == SDL_KEYDOWN && event_handler_->key.repeat == 0) + if (event.type == SDL_KEYDOWN && event.key.repeat == 0) { - switch (event_handler_->key.keysym.scancode) + switch (event.key.keysym.scancode) { #ifdef DEBUG case SDL_SCANCODE_G: diff --git a/source/game.h b/source/game.h index 84e5b67..f9df4ac 100644 --- a/source/game.h +++ b/source/game.h @@ -29,7 +29,6 @@ private: // Objetos y punteros Screen *screen_; // Objeto encargado de manejar el renderizador SDL_Renderer *renderer_; // El renderizador de la ventana - SDL_Event *event_handler_; // Manejador de eventos Room *room_; // Objeto encargado de gestionar cada habitación del juego Player *player_; // Objeto con el jugador ItemTracker *item_tracker_; // Lleva el control de los objetos recogidos diff --git a/source/game_over.cpp b/source/game_over.cpp index 88ee0ee..d69b2ac 100644 --- a/source/game_over.cpp +++ b/source/game_over.cpp @@ -22,7 +22,6 @@ GameOver::GameOver() input(Input::get()) { // Reserva memoria para los punteros a objetos - eventHandler = new SDL_Event(); text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer); playerSprite = new AnimatedSprite(renderer, resource->getAnimation("player_game_over.ani")); tvSprite = new AnimatedSprite(renderer, resource->getAnimation("tv.ani")); @@ -56,7 +55,6 @@ GameOver::GameOver() GameOver::~GameOver() { // Libera la memoria de los objetos - delete eventHandler; delete text; delete playerSprite; delete tvSprite; @@ -125,11 +123,11 @@ void GameOver::render() // Comprueba el manejador de eventos void GameOver::checkEvents() { - // Comprueba los eventos que hay en la cola - while (SDL_PollEvent(eventHandler) != 0) + SDL_Event event; + while (SDL_PollEvent(&event)) { // Evento de salida de la aplicación - if (eventHandler->type == SDL_QUIT) + if (event.type == SDL_QUIT) { options.section.name = SECTION_QUIT; options.section.subsection = 0; diff --git a/source/game_over.h b/source/game_over.h index 93f6d50..5052cf9 100644 --- a/source/game_over.h +++ b/source/game_over.h @@ -22,7 +22,6 @@ private: Resource *resource; // Objeto con los recursos Asset *asset; // Objeto con los ficheros de recursos Input *input; // Objeto pata gestionar la entrada - SDL_Event *eventHandler; // Manejador de eventos Text *text; // Objeto para escribir texto en pantalla AnimatedSprite *playerSprite; // Sprite con el jugador AnimatedSprite *tvSprite; // Sprite con el televisor diff --git a/source/jail_shader.cpp b/source/jail_shader.cpp index 44d75d3..e6e8f52 100644 --- a/source/jail_shader.cpp +++ b/source/jail_shader.cpp @@ -1,5 +1,3 @@ -#ifndef NO_SHADERS - #include "jail_shader.h" #include // para SDL_Point #include // para NULL, free, malloc, exit @@ -247,5 +245,4 @@ namespace shader SDL_RenderPresent(renderer); } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/source/loading_screen.cpp b/source/loading_screen.cpp index 8aef1f9..1bcb17f 100644 --- a/source/loading_screen.cpp +++ b/source/loading_screen.cpp @@ -21,7 +21,6 @@ LoadingScreen::LoadingScreen() input_(Input::get()) { // Reserva memoria para los punteros - eventHandler = new SDL_Event(); if (options.palette == p_zxspectrum) { mono_loading_screen_texture_ = resource_->getTexture("loading_screen_bn.png"); @@ -70,7 +69,6 @@ LoadingScreen::~LoadingScreen() { delete mono_loading_screen_sprite_; delete color_loading_screen_sprite_; - delete eventHandler; JA_DeleteMusic(loading_sound1_); JA_DeleteMusic(loading_sound2_); JA_DeleteMusic(loading_sound3_); @@ -79,11 +77,11 @@ LoadingScreen::~LoadingScreen() // Comprueba el manejador de eventos void LoadingScreen::checkEvents() { - // Comprueba los eventos que hay en la cola - while (SDL_PollEvent(eventHandler) != 0) + SDL_Event event; + while (SDL_PollEvent(&event)) { // Evento de salida de la aplicación - if (eventHandler->type == SDL_QUIT) + if (event.type == SDL_QUIT) { options.section.name = SECTION_QUIT; break; diff --git a/source/loading_screen.h b/source/loading_screen.h index 4f0d0d7..ea70149 100644 --- a/source/loading_screen.h +++ b/source/loading_screen.h @@ -25,7 +25,6 @@ private: Input *input_; // Objeto pata gestionar la entrada Texture *mono_loading_screen_texture_; // Textura con la pantalla de carga en blanco y negro Texture *color_loading_screen_texture_; // Textura con la pantalla de carga en color - SDL_Event *eventHandler; // Manejador de eventos Sprite *mono_loading_screen_sprite_; // Sprite para manejar la textura loadingScreenTexture1 Sprite *color_loading_screen_sprite_; // Sprite para manejar la textura loadingScreenTexture2 diff --git a/source/logo.cpp b/source/logo.cpp index 935d46d..7448151 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -22,7 +22,6 @@ Logo::Logo() input_(Input::get()) { // Reserva memoria para los punteros - event_handler_ = new SDL_Event(); jailgames_texture_ = resource_->getTexture("jailgames.png"); since_1998_texture_ = resource_->getTexture("since_1998.png"); since_1998_sprite_ = new Sprite((256 - since_1998_texture_->getWidth()) / 2, 83 + jailgames_texture_->getHeight() + 5, since_1998_texture_->getWidth(), since_1998_texture_->getHeight(), since_1998_texture_, renderer_); @@ -68,17 +67,16 @@ Logo::~Logo() } delete since_1998_sprite_; - delete event_handler_; } // Comprueba el manejador de eventos void Logo::checkEvents() { - // Comprueba los eventos que hay en la cola - while (SDL_PollEvent(event_handler_) != 0) + SDL_Event event; + while (SDL_PollEvent(&event)) { // Evento de salida de la aplicación - if (event_handler_->type == SDL_QUIT) + if (event.type == SDL_QUIT) { options.section.name = SECTION_QUIT; break; diff --git a/source/logo.h b/source/logo.h index 6c654e5..7c5b796 100644 --- a/source/logo.h +++ b/source/logo.h @@ -25,7 +25,6 @@ private: Input *input_; // Objeto pata gestionar la entrada Texture *jailgames_texture_; // Textura con los graficos "JAILGAMES" Texture *since_1998_texture_; // Textura con los graficos "Since 1998" - SDL_Event *event_handler_; // Manejador de eventos std::vector jailgames_sprite_; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES Sprite *since_1998_sprite_; // Sprite para manejar la textura2 diff --git a/source/options.cpp b/source/options.cpp index 74c5ab1..ef55f54 100644 --- a/source/options.cpp +++ b/source/options.cpp @@ -115,14 +115,14 @@ bool loadOptionsFromFile(const std::string &file_path) // El fichero no existe else { // Crea el fichero con los valores por defecto - saveOptionsFromFile(file_path); + saveOptionsToFile(file_path); } // Si la versión de fichero no coincide, crea un fichero nuevo con los valores por defecto if (configVersion != options.configVersion) { initOptions(); - saveOptionsFromFile(file_path); + saveOptionsToFile(file_path); } // Normaliza los valores @@ -142,7 +142,7 @@ bool loadOptionsFromFile(const std::string &file_path) return success; } -bool saveOptionsFromFile(const std::string &file_path) +bool saveOptionsToFile(const std::string &file_path) { bool success = true; diff --git a/source/options.h b/source/options.h index 8af46cb..4e6e31a 100644 --- a/source/options.h +++ b/source/options.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include // Para SDL_Rect, SDL_Point #include // Para Uint8, Uint32 @@ -98,4 +98,4 @@ void initOptions(); bool loadOptionsFromFile(const std::string &file_path); // Guarda las opciones a un fichero -bool saveOptionsFromFile(const std::string &file_path); \ No newline at end of file +bool saveOptionsToFile(const std::string &file_path); \ No newline at end of file diff --git a/source/title.cpp b/source/title.cpp index 82c1c08..6cdd202 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -25,8 +25,6 @@ Title::Title() input_(Input::get()) { // Reserva memoria para los punteros - event_handler_ = new SDL_Event(); - cheevos_ = std::make_unique(Asset::get()->get("cheevos.bin")); if (options.palette == p_zxspectrum) { texture_ = resource_->getTexture("title_logo.png"); @@ -75,7 +73,6 @@ Title::Title() // Destructor Title::~Title() { - delete event_handler_; delete sprite_; delete cheevos_sprite_; delete cheevos_texture_; @@ -104,22 +101,22 @@ void Title::initMarquee() // Comprueba el manejador de eventos void Title::checkEvents() { - // Comprueba los eventos que hay en la cola - while (SDL_PollEvent(event_handler_) != 0) + SDL_Event event; + while (SDL_PollEvent(&event)) { // Evento de salida de la aplicación - if (event_handler_->type == SDL_QUIT) + if (event.type == SDL_QUIT) { options.section.name = SECTION_QUIT; break; } // Solo se comprueban estas teclas si no está activo el menu de logros - if (event_handler_->type == SDL_KEYDOWN) + if (event.type == SDL_KEYDOWN) { if (!show_cheevos_) { - switch (event_handler_->key.keysym.scancode) + switch (event.key.keysym.scancode) { case SDL_SCANCODE_1: options.section.name = SECTION_GAME; @@ -446,7 +443,7 @@ void Title::fillTexture() void Title::createCheevosTexture() { // Crea la textura con el listado de logros - const auto cheevosList = cheevos_->list(); + const auto cheevosList = Cheevos::get()->list(); const int cheevosTextureWidth = 200; const int cheevosTextureViewHeight = 110; const int cheevosTexturePosY = 73; @@ -465,7 +462,7 @@ void Title::createCheevosTexture() // Escribe la lista de logros en la textura const std::string cheevosOwner = "LOCAL ACHIEVEMENTS"; - const std::string cheevosListCaption = cheevosOwner + " (" + std::to_string(cheevos_->unlocked()) + " / " + std::to_string(cheevos_->count()) + ")"; + const std::string cheevosListCaption = cheevosOwner + " (" + std::to_string(Cheevos::get()->unlocked()) + " / " + std::to_string(Cheevos::get()->count()) + ")"; int pos = 2; info_text_->writeDX(TXT_CENTER | TXT_COLOR, cheevos_texture_->getWidth() / 2, pos, cheevosListCaption, 1, stringToColor(options.palette, "bright_green")); pos += info_text_->getCharacterSize(); diff --git a/source/title.h b/source/title.h index cbb394a..b44269e 100644 --- a/source/title.h +++ b/source/title.h @@ -41,7 +41,6 @@ private: SDL_Renderer *renderer_; // El renderizador de la ventana Resource *resource_; // Objeto con los recursos Input *input_; // Objeto pata gestionar la entrada - SDL_Event *event_handler_; // Manejador de eventos Texture *texture_; // Textura con los graficos Sprite *sprite_; // Sprite para manejar la textura SDL_Texture *bg_texture_; // Textura para dibujar el fondo de la pantalla @@ -49,7 +48,6 @@ private: Text *info_text_; // Objeto para escribir texto en pantalla Texture *cheevos_texture_; // Textura con la lista de logros Sprite *cheevos_sprite_; // Sprite para manejar la textura con la lista de logros - std::unique_ptr cheevos_; // Objeto encargado de gestionar los logros del juego // Variables int counter_ = 0; // Contador