From 531ac94bc0112da0aef1d063bfa142f345f7ad0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Sun, 30 Oct 2022 22:23:24 +0100 Subject: [PATCH] Cambiando printf a std::cout --- source/common/input.cpp | 6 +++--- source/common/screen.cpp | 4 ++-- source/credits.cpp | 7 ++++--- source/director.cpp | 17 +++++++++-------- source/game.cpp | 13 ++++--------- source/main.cpp | 6 +++--- source/room.cpp | 1 - 7 files changed, 25 insertions(+), 29 deletions(-) diff --git a/source/common/input.cpp b/source/common/input.cpp index 0be4cd6..dd5a683 100644 --- a/source/common/input.cpp +++ b/source/common/input.cpp @@ -183,7 +183,7 @@ bool Input::discoverGameController() if (SDL_GameControllerAddMappingsFromFile(dbPath.c_str()) < 0) { - printf("Error, could not load %s file: %s\n", dbPath.c_str(), SDL_GetError()); + std::cout << "Error, could not load " << dbPath.c_str() << " file: " << SDL_GetError() << std::endl; } const int nJoysticks = SDL_NumJoysticks(); @@ -198,8 +198,8 @@ bool Input::discoverGameController() } } - printf("\nChecking for game controllers...\n"); - printf("%i joysticks found, %i are gamepads\n", nJoysticks, numGamepads); + std::cout << "\nChecking for game controllers...\n"; + std::cout << nJoysticks << " joysticks found, " << numGamepads << " are gamepads\n"; if (numGamepads > 0) { diff --git a/source/common/screen.cpp b/source/common/screen.cpp index 424600e..1d26692 100644 --- a/source/common/screen.cpp +++ b/source/common/screen.cpp @@ -1,6 +1,6 @@ #include "screen.h" #include -#include +#include // Constructor Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, int gameInternalResX, int gameInternalResY) @@ -23,7 +23,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, i gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight); if (gameCanvas == nullptr) { - printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError()); + std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl; } // Establece el modo de video diff --git a/source/credits.cpp b/source/credits.cpp index 588d83a..56f39d6 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -1,4 +1,5 @@ #include "credits.h" +#include // Constructor Credits::Credits(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options) @@ -32,7 +33,7 @@ Credits::Credits(SDL_Renderer *renderer, Screen *screen, Resource *resource, Ass textTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); if (textTexture == nullptr) { - printf("Error: textTexture could not be created!\nSDL Error: %s\n", SDL_GetError()); + std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl; } SDL_SetTextureBlendMode(textTexture, SDL_BLENDMODE_BLEND); @@ -40,7 +41,7 @@ Credits::Credits(SDL_Renderer *renderer, Screen *screen, Resource *resource, Ass coverTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); if (coverTexture == nullptr) { - printf("Error: coverTexture could not be created!\nSDL Error: %s\n", SDL_GetError()); + std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl; } SDL_SetTextureBlendMode(coverTexture, SDL_BLENDMODE_BLEND); @@ -271,7 +272,7 @@ void Credits::render() screen->clean(); if (counter < 1150) - { + { // Dibuja la textura con el texto en pantalla SDL_RenderCopy(renderer, textTexture, nullptr, nullptr); diff --git a/source/director.cpp b/source/director.cpp index b121dc9..c3ea41c 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -85,7 +85,7 @@ bool Director::loadConfig() if (file.good()) { // Procesa el fichero linea a linea - printf("Reading file config.txt\n"); + std::cout << "Reading file config.txt\n"; while (std::getline(file, line)) { // Comprueba que la linea no sea un comentario @@ -96,14 +96,15 @@ bool Director::loadConfig() // Procesa las dos subcadenas if (!setOptions(options, line.substr(0, pos), line.substr(pos + 1, line.length()))) { - printf("Warning: file %s\n, unknown parameter \"%s\"\n", "config.txt", line.substr(0, pos).c_str()); + std::cout << "Warning: file config.txt\n"; + std::cout << "unknown parameter " << line.substr(0, pos).c_str() << std::endl; success = false; } } } // Cierra el fichero - printf("Closing file config.txt\n\n"); + std::cout << "Closing file config.txt\n\n"; file.close(); } @@ -634,7 +635,7 @@ bool Director::initSDL() // Inicializa SDL if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO) < 0) { - printf("SDL could not initialize!\nSDL Error: %s\n", SDL_GetError()); + std::cout << "SDL could not initialize!\nSDL Error: " << SDL_GetError() << std::endl; success = false; } else @@ -645,14 +646,14 @@ bool Director::initSDL() // Establece el filtro de la textura a nearest if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(options->filter).c_str())) { - printf("Warning: Nearest texture filtering not enabled!\n"); + std::cout << "Warning: Nearest texture filtering not enabled!\n"; } // Crea la ventana window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, options->screenWidth, options->screenHeight, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI); if (window == nullptr) { - printf("Window could not be created!\nSDL Error: %s\n", SDL_GetError()); + std::cout << "Window could not be created!\nSDL Error: " << SDL_GetError() << std::endl; success = false; } else @@ -665,7 +666,7 @@ bool Director::initSDL() if (renderer == nullptr) { - printf("Renderer could not be created!\nSDL Error: %s\n", SDL_GetError()); + std::cout << "Renderer could not be created!\nSDL Error: " << SDL_GetError() << std::endl; success = false; } else @@ -682,7 +683,7 @@ bool Director::initSDL() } } - printf("\n"); + std::cout << std::endl; return success; } diff --git a/source/game.cpp b/source/game.cpp index d26b9be..6a6df88 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -88,7 +88,7 @@ void Game::checkEventHandler() screen->setBorderColor(stringToColor(options->palette, "black")); break; } - + if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0)) { switch (eventHandler->key.keysym.scancode) @@ -410,15 +410,10 @@ void Game::reLoadTextures() // Cambia la paleta void Game::switchPalette() { + std::cout << "** PALETTE SWITCH REQUESTED" << std::endl; + // Modifica la variable - if (options->palette == p_zxspectrum) - { - options->palette = p_zxarne; - } - else - { - options->palette = p_zxspectrum; - } + options->palette = (options->palette == p_zxspectrum) ? p_zxarne : p_zxspectrum; room->reLoadPalette(); player->reLoadPalette(); diff --git a/source/main.cpp b/source/main.cpp index af5c927..b5329b1 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -6,11 +6,11 @@ Empezado en Castalla el 01/07/2022. */ #include "director.h" -#include +#include int main(int argc, char *args[]) { - printf("Starting the game...\n\n"); + std::cout << "Starting the game...\n\n"; // Crea el objeto Director Director *director = new Director(args[0]); @@ -22,7 +22,7 @@ int main(int argc, char *args[]) delete director; director = nullptr; - printf("\nShutting down the game...\n"); + std::cout << "\nShutting down the game...\n"; return 0; } diff --git a/source/room.cpp b/source/room.cpp index 909785c..77b050f 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -450,7 +450,6 @@ Room::Room(room_t *room, SDL_Renderer *renderer, Screen *screen, Asset *asset, o Room::~Room() { // Reclama la memoria utilizada por los objetos - // delete texture; JA_DeleteSound(itemSound); SDL_DestroyTexture(mapTexture);