Modificado el bucle principal

This commit is contained in:
2022-08-08 20:12:51 +02:00
parent 1801c23957
commit 4439f8477a
4 changed files with 75 additions and 48 deletions

View File

@@ -147,7 +147,7 @@ bool Director::initSDL()
printf("%i joysticks were found.\n", SDL_NumJoysticks());
std::cout << SDL_JoystickNumButtons(gameController) << " buttons\n";
//Get controller haptic device
// Get controller haptic device
controllerHaptic = SDL_HapticOpenFromJoystick(gameController);
if (controllerHaptic == NULL)
{
@@ -157,7 +157,7 @@ bool Director::initSDL()
{
printf("Haptics detected\n");
//Get initialize rumble
// Get initialize rumble
if (SDL_HapticRumbleInit(controllerHaptic) < 0)
{
printf("Warning: Unable to initialize rumble!\nSDL Error: %s\n", SDL_GetError());
@@ -212,7 +212,7 @@ bool Director::initSDL()
void Director::initObjects()
{
eventHandler = new SDL_Event();
text.white = new Text("",nullptr,nullptr);
text.white = new Text("", nullptr, nullptr);
}
// Borra los objetos del programa
@@ -347,18 +347,6 @@ bool Director::initResourceList()
return checkResourceList();
}
// Carga un archivo de imagen en una textura
bool Director::loadTextureFromFile(LTexture *texture, std::string path, SDL_Renderer *renderer)
{
bool success = true;
if (!texture->loadFromFile(path, renderer))
{
printf("Failed to load %s texture!\n", path.c_str());
success = false;
}
return success;
}
// Carga los recursos necesarios
bool Director::loadMedia(Uint8 section)
{
@@ -681,4 +669,38 @@ void Director::renderGame()
// Muestra el backbuffer en pantalla
SDL_RenderPresent(renderer);
}
// Bucle principal
void Director::run()
{
bool quit = false;
// Comprueba si existen todos los ficheros de recursos
if (!initResourceList())
{
quit = true;
}
// Arranca SDL y crea la ventana
if ((!quit) && (!initSDL()))
{
quit = true;
}
// Inicializa las variables del juego
if (!quit)
{
initGame();
}
// Bucle del juego
if (!quit)
{
while (isRunning())
{
runGame();
}
}
quitGame();
}