diff --git a/.gitignore b/.gitignore index c49e316..cc6a67c 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,4 @@ thumbs.db *.app *config.bin *score.bin -coffee_crisis_debug* \ No newline at end of file +coffee_crisis* \ No newline at end of file diff --git a/source/common/utils.cpp b/source/common/utils.cpp index 9497d3c..6252753 100644 --- a/source/common/utils.cpp +++ b/source/common/utils.cpp @@ -581,7 +581,7 @@ std::string toLower(std::string str) { const char *original = str.c_str(); char *lower = (char *)malloc(str.size() + 1); - for (int i = 0; i < str.size(); ++i) + for (int i = 0; i < (int)str.size(); ++i) { char c = original[i]; lower[i] = (c >= 65 && c <= 90) ? c + 32 : c; diff --git a/source/director.cpp b/source/director.cpp index 27b075a..3f73e7d 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -184,14 +184,15 @@ bool Director::initSDL() else { // Crea un renderizador para la ventana. El vsync se activa en funcion de las opciones + // Crea un renderizador para la ventana. El vsync se activa en funcion de las opciones + //Uint32 flags = SDL_RENDERER_SOFTWARE; + //Uint32 flags = SDL_RENDERER_ACCELERATED; + Uint32 flags = 0; if (options->vSync) - { - renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); - } - else - { - renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); - } + { + flags = flags | SDL_RENDERER_PRESENTVSYNC; + } + renderer = SDL_CreateRenderer(window, -1, flags); if (renderer == nullptr) { diff --git a/source/game.cpp b/source/game.cpp index 588332e..c06a2b3 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -1739,7 +1739,7 @@ void Game::renderScoreBoard() { if (jscore::getNumUsers() > 0) { - const std::string txt = jscore::getUserName(0).substr(0,12) + " - " + updateScoreText((Uint32)jscore::getPoints(0)); + const std::string txt = jscore::getUserName(0).substr(0, 12) + " - " + updateScoreText((Uint32)jscore::getPoints(0)); textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset4, txt); } else @@ -2785,9 +2785,6 @@ void Game::updateEnemyDeployCounter() // Actualiza el juego void Game::update() { - // Comprueba los eventos que hay en cola - checkEventHandler(); - // Comprueba que la diferencia de ticks sea mayor a la velocidad del juego if (SDL_GetTicks() - ticks > ticksSpeed) { @@ -3377,6 +3374,9 @@ section_t Game::run() // Actualiza la lógica del juego update(); + // Comprueba los eventos que hay en cola + checkEvents(); + // Dibuja los objetos render(); } @@ -3388,9 +3388,6 @@ section_t Game::run() // Actualiza las variables del menu de pausa del juego void Game::updatePausedGame() { - // Comprueba los eventos que hay en la cola - checkEventHandler(); - // Calcula la lógica de los objetos if (SDL_GetTicks() - ticks > ticksSpeed) { @@ -3525,6 +3522,7 @@ void Game::runPausedGame() while ((section.subsection == GAME_SECTION_PAUSE) && (section.name == PROG_SECTION_GAME)) { updatePausedGame(); + checkEvents(); renderPausedGame(); } } @@ -3535,26 +3533,6 @@ void Game::updateGameOverScreen() // Variables static int postFade = 0; - // Comprueba los eventos que hay en la cola - while (SDL_PollEvent(eventHandler) != 0) - { - // Evento de salida de la aplicación - if (eventHandler->type == SDL_QUIT) - { - section.name = PROG_SECTION_QUIT; - break; - } - else if (eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) - { - if (gameCompleted) - { - postFade = 1; - fade->activateFade(); - JA_PlaySound(itemPickUpSound); - } - } - } - // Calcula la lógica de los objetos if (SDL_GetTicks() - ticks > ticksSpeed) { @@ -3615,6 +3593,26 @@ void Game::updateGameOverScreen() } } } + + // Comprueba los eventos que hay en la cola + while (SDL_PollEvent(eventHandler) != 0) + { + // Evento de salida de la aplicación + if (eventHandler->type == SDL_QUIT) + { + section.name = PROG_SECTION_QUIT; + break; + } + else if (eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) + { + if (gameCompleted) + { + postFade = 1; + fade->activateFade(); + JA_PlaySound(itemPickUpSound); + } + } + } } // Dibuja los elementos de la pantalla de game over @@ -3859,7 +3857,7 @@ bool Game::allPlayersAreDead() } // Comprueba los eventos que hay en cola -void Game::checkEventHandler() +void Game::checkEvents() { while (SDL_PollEvent(eventHandler) != 0) { diff --git a/source/game.h b/source/game.h index d0c30bd..8da70e1 100644 --- a/source/game.h +++ b/source/game.h @@ -245,7 +245,7 @@ private: void render(); // Comprueba los eventos que hay en cola - void checkEventHandler(); + void checkEvents(); // Inicializa las variables necesarias para la sección 'Game' void init(); diff --git a/source/instructions.cpp b/source/instructions.cpp index 4a8901c..80b0484 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -73,9 +73,6 @@ Instructions::~Instructions() // Actualiza las variables void Instructions::update() { - // Comprueba los eventos - checkEventHandler(); - // Comprueba las entradas checkInput(); @@ -209,7 +206,7 @@ void Instructions::render() } // Comprueba los eventos -void Instructions::checkEventHandler() +void Instructions::checkEvents() { // Comprueba los eventos que hay en la cola while (SDL_PollEvent(eventHandler) != 0) @@ -272,6 +269,7 @@ section_t Instructions::run(mode_e mode) while (section.name == SELF) { update(); + checkEvents(); render(); } diff --git a/source/instructions.h b/source/instructions.h index 2988f37..ae4b95a 100644 --- a/source/instructions.h +++ b/source/instructions.h @@ -51,7 +51,7 @@ private: void render(); // Comprueba los eventos - void checkEventHandler(); + void checkEvents(); // Comprueba las entradas void checkInput(); diff --git a/source/intro.cpp b/source/intro.cpp index c19c587..ddd51e3 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -173,7 +173,7 @@ bool Intro::loadMedia() } // Comprueba los eventos -void Intro::checkEventHandler() +void Intro::checkEvents() { // Comprueba los eventos que hay en la cola while (SDL_PollEvent(eventHandler) != 0) @@ -377,7 +377,6 @@ void Intro::updateScenes() // Actualiza las variables del objeto void Intro::update() { - checkEventHandler(); checkInput(); if (SDL_GetTicks() - ticks > ticksSpeed) @@ -436,6 +435,7 @@ section_t Intro::run() while (section.name == PROG_SECTION_INTRO) { update(); + checkEvents(); render(); } diff --git a/source/intro.h b/source/intro.h index eff3443..013e1bc 100644 --- a/source/intro.h +++ b/source/intro.h @@ -47,7 +47,7 @@ private: bool loadMedia(); // Comprueba los eventos - void checkEventHandler(); + void checkEvents(); // Comprueba las entradas void checkInput(); diff --git a/source/logo.cpp b/source/logo.cpp index c81c2dd..294f329 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -46,7 +46,7 @@ void Logo::checkLogoEnd() } // Comprueba los eventos -void Logo::checkEventHandler() +void Logo::checkEvents() { // Comprueba los eventos que hay en la cola while (SDL_PollEvent(eventHandler) != 0) @@ -106,7 +106,6 @@ void Logo::renderFade() // Actualiza las variables del objeto void Logo::update() { - checkEventHandler(); checkInput(); if (SDL_GetTicks() - ticks > ticksSpeed) @@ -152,6 +151,7 @@ section_t Logo::run() while (section.name == PROG_SECTION_LOGO) { update(); + checkEvents(); render(); } diff --git a/source/logo.h b/source/logo.h index 864e861..145736e 100644 --- a/source/logo.h +++ b/source/logo.h @@ -41,7 +41,7 @@ private: void checkLogoEnd(); // Comprueba los eventos - void checkEventHandler(); + void checkEvents(); // Comprueba las entradas void checkInput(); diff --git a/source/title.cpp b/source/title.cpp index 89cb315..0a4f4fc 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -215,9 +215,6 @@ void Title::init() // Actualiza las variables del objeto void Title::update() { - // Comprueba los eventos - checkEventHandler(); - // Comprueba las entradas checkInput(); @@ -670,7 +667,7 @@ void Title::render() } // Comprueba los eventos -void Title::checkEventHandler() +void Title::checkEvents() { // Comprueba los eventos que hay en la cola while (SDL_PollEvent(eventHandler) != 0) @@ -976,6 +973,7 @@ section_t Title::run() while (section.name == PROG_SECTION_TITLE) { update(); + checkEvents(); render(); } diff --git a/source/title.h b/source/title.h index fd92157..7e58a43 100644 --- a/source/title.h +++ b/source/title.h @@ -103,7 +103,7 @@ private: void render(); // Comprueba los eventos - void checkEventHandler(); + void checkEvents(); // Comprueba las entradas void checkInput();