Corregido el orden de ejecución update-checkEvents-render en todas las secciones del juego para evitar que el juego tarde en actualizarse cuando hay muchos eventos
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -11,4 +11,4 @@ thumbs.db
|
||||
*.app
|
||||
*config.bin
|
||||
*score.bin
|
||||
coffee_crisis_debug*
|
||||
coffee_crisis*
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ private:
|
||||
void render();
|
||||
|
||||
// Comprueba los eventos
|
||||
void checkEventHandler();
|
||||
void checkEvents();
|
||||
|
||||
// Comprueba las entradas
|
||||
void checkInput();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ private:
|
||||
bool loadMedia();
|
||||
|
||||
// Comprueba los eventos
|
||||
void checkEventHandler();
|
||||
void checkEvents();
|
||||
|
||||
// Comprueba las entradas
|
||||
void checkInput();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ private:
|
||||
void checkLogoEnd();
|
||||
|
||||
// Comprueba los eventos
|
||||
void checkEventHandler();
|
||||
void checkEvents();
|
||||
|
||||
// Comprueba las entradas
|
||||
void checkInput();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ private:
|
||||
void render();
|
||||
|
||||
// Comprueba los eventos
|
||||
void checkEventHandler();
|
||||
void checkEvents();
|
||||
|
||||
// Comprueba las entradas
|
||||
void checkInput();
|
||||
|
||||
Reference in New Issue
Block a user