From 88fa3f296f5495f3937d3fe6b78a2cbe64ff0f51 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 14 May 2026 19:39:56 +0200 Subject: [PATCH] neteja cppcheck/tidy i elimina sistema de paletes mort --- source/core/audio/jail_audio.hpp | 6 +- source/game/defaults.hpp | 1 - source/game/options.cpp | 6 - source/game/options.hpp | 3 +- source/utils/utils.cpp | 193 ++++--------------------------- source/utils/utils.h | 37 +++--- 6 files changed, 41 insertions(+), 205 deletions(-) diff --git a/source/core/audio/jail_audio.hpp b/source/core/audio/jail_audio.hpp index 63308e0..e497c26 100644 --- a/source/core/audio/jail_audio.hpp +++ b/source/core/audio/jail_audio.hpp @@ -265,13 +265,13 @@ inline JA_Music_t* JA_LoadMusic(const Uint8* buffer, Uint32 length) { auto* music = new JA_Music_t(); music->ogg_data.assign(buffer, buffer + length); - int error = 0; + int err = 0; music->vorbis = stb_vorbis_open_memory(music->ogg_data.data(), static_cast(length), - &error, + &err, nullptr); if (!music->vorbis) { - std::cout << "JA_LoadMusic: stb_vorbis_open_memory failed (error " << error << ")" << '\n'; + std::cout << "JA_LoadMusic: stb_vorbis_open_memory failed (error " << err << ")" << '\n'; delete music; return nullptr; } diff --git a/source/game/defaults.hpp b/source/game/defaults.hpp index 211b391..9328956 100644 --- a/source/game/defaults.hpp +++ b/source/game/defaults.hpp @@ -52,7 +52,6 @@ namespace Defaults::Loading { namespace Defaults::Settings { constexpr int DIFFICULTY = DIFFICULTY_NORMAL; constexpr int LANGUAGE = ba_BA; - constexpr palette_e PALETTE = p_zxspectrum; } // namespace Defaults::Settings // Tamaño de bloque diff --git a/source/game/options.cpp b/source/game/options.cpp index 1ca4bbf..cd199cf 100644 --- a/source/game/options.cpp +++ b/source/game/options.cpp @@ -153,11 +153,6 @@ namespace Options { if (settings.language < 0 || settings.language > MAX_LANGUAGES) { settings.language = en_UK; } - if (st.contains("palette")) { - try { - settings.palette = static_cast(st["palette"].get_value()); - } catch (...) {} - } parseIntField(st, "player_selected", settings.player_selected); } @@ -330,7 +325,6 @@ namespace Options { file << "settings:\n"; file << " difficulty: " << settings.difficulty << "\n"; file << " language: " << settings.language << "\n"; - file << " palette: " << static_cast(settings.palette) << "\n"; file << " player_selected: " << settings.player_selected << "\n\n"; // INPUT diff --git a/source/game/options.hpp b/source/game/options.hpp index 13ee73d..8674d79 100644 --- a/source/game/options.hpp +++ b/source/game/options.hpp @@ -7,7 +7,7 @@ #include "core/rendering/shader_backend.hpp" // for Rendering::ShaderType #include "game/defaults.hpp" -#include "utils/utils.h" // for input_t, palette_e +#include "utils/utils.h" // for input_t // ============================================================================= // Opciones del programa, alineades amb coffee_crisis_arcade_edition. @@ -82,7 +82,6 @@ namespace Options { int config_version = CURRENT_CONFIG_VERSION; int difficulty = Defaults::Settings::DIFFICULTY; int language = Defaults::Settings::LANGUAGE; - palette_e palette = Defaults::Settings::PALETTE; bool console = false; int player_selected = 0; std::string config_file; diff --git a/source/utils/utils.cpp b/source/utils/utils.cpp index 7b2f8ff..b5aeb7f 100644 --- a/source/utils/utils.cpp +++ b/source/utils/utils.cpp @@ -6,32 +6,27 @@ #include // for abs // Calcula el cuadrado de la distancia entre dos puntos -double distanceSquared(int x1, int y1, int x2, int y2) { +auto distanceSquared(int x1, int y1, int x2, int y2) -> double { const int deltaX = x2 - x1; const int deltaY = y2 - y1; - return deltaX * deltaX + deltaY * deltaY; + return (deltaX * deltaX) + (deltaY * deltaY); } // Detector de colisiones entre dos circulos -bool checkCollision(const circle_t &a, const circle_t &b) { +auto checkCollision(const circle_t &a, const circle_t &b) -> bool { // Calcula el radio total al cuadrado int totalRadiusSquared = a.r + b.r; totalRadiusSquared = totalRadiusSquared * totalRadiusSquared; - // Si la distancia entre el centro de los circulos es inferior a la suma de sus radios - if (distanceSquared(a.x, a.y, b.x, b.y) < (totalRadiusSquared)) { - // Los circulos han colisionado - return true; - } - - // En caso contrario - return false; + // Han colisionat si la distancia entre centres és inferior a la suma de radis + return distanceSquared(a.x, a.y, b.x, b.y) < totalRadiusSquared; } // Detector de colisiones entre un circulo y un rectangulo -bool checkCollision(const circle_t &a, const SDL_Rect &b) { +auto checkCollision(const circle_t &a, const SDL_Rect &b) -> bool { // Closest point on collision box - int cX, cY; + int cX; + int cY; // Find closest x offset if (a.x < b.x) { @@ -62,7 +57,7 @@ bool checkCollision(const circle_t &a, const SDL_Rect &b) { } // Detector de colisiones entre dos rectangulos -bool checkCollision(const SDL_Rect &a, const SDL_Rect &b) { +auto checkCollision(const SDL_Rect &a, const SDL_Rect &b) -> bool { // Calcula las caras del rectangulo a const int leftA = a.x; const int rightA = a.x + a.w; @@ -97,7 +92,7 @@ bool checkCollision(const SDL_Rect &a, const SDL_Rect &b) { } // Detector de colisiones entre un punto y un rectangulo -bool checkCollision(const SDL_Point &p, const SDL_Rect &r) { +auto checkCollision(const SDL_Point &p, const SDL_Rect &r) -> bool { // Comprueba si el punto está a la izquierda del rectangulo if (p.x < r.x) { return false; @@ -123,7 +118,7 @@ bool checkCollision(const SDL_Point &p, const SDL_Rect &r) { } // Detector de colisiones entre una linea horizontal y un rectangulo -bool checkCollision(const h_line_t &l, const SDL_Rect &r) { +auto checkCollision(const h_line_t &l, const SDL_Rect &r) -> bool { // Comprueba si la linea esta por encima del rectangulo if (l.y < r.y) { return false; @@ -149,7 +144,7 @@ bool checkCollision(const h_line_t &l, const SDL_Rect &r) { } // Detector de colisiones entre una linea vertical y un rectangulo -bool checkCollision(const v_line_t &l, const SDL_Rect &r) { +auto checkCollision(const v_line_t &l, const SDL_Rect &r) -> bool { // Comprueba si la linea esta por la izquierda del rectangulo if (l.x < r.x) { return false; @@ -175,7 +170,7 @@ bool checkCollision(const v_line_t &l, const SDL_Rect &r) { } // Detector de colisiones entre una linea horizontal y un punto -bool checkCollision(const h_line_t &l, const SDL_Point &p) { +auto checkCollision(const h_line_t &l, const SDL_Point &p) -> bool { // Comprueba si el punto esta sobre la linea if (p.y > l.y) { return false; @@ -201,7 +196,7 @@ bool checkCollision(const h_line_t &l, const SDL_Point &p) { } // Detector de colisiones entre dos lineas -SDL_Point checkCollision(const line_t &l1, const line_t &l2) { +auto checkCollision(const line_t &l1, const line_t &l2) -> SDL_Point { const float x1 = l1.x1; const float y1 = l1.y1; const float x2 = l1.x2; @@ -222,13 +217,13 @@ SDL_Point checkCollision(const line_t &l1, const line_t &l2) { const float x = x1 + (uA * (x2 - x1)); const float y = y1 + (uA * (y2 - y1)); - return {(int)round(x), (int)round(y)}; + return {(int)std::round(x), (int)std::round(y)}; } return {-1, -1}; } // Detector de colisiones entre dos lineas -SDL_Point checkCollision(const d_line_t &l1, const v_line_t &l2) { +auto checkCollision(const d_line_t &l1, const v_line_t &l2) -> SDL_Point { const float x1 = l1.x1; const float y1 = l1.y1; const float x2 = l1.x2; @@ -291,7 +286,7 @@ void normalizeLine(d_line_t &l) { } // Detector de colisiones entre un punto y una linea diagonal -bool checkCollision(const SDL_Point &p, const d_line_t &l) { +auto checkCollision(const SDL_Point &p, const d_line_t &l) -> bool { // Comprueba si el punto está en alineado con la linea if (abs(p.x - l.x1) != abs(p.y - l.y1)) { return false; @@ -330,165 +325,23 @@ bool checkCollision(const SDL_Point &p, const d_line_t &l) { return false;*/ } -// Devuelve un color_t a partir de un string -color_t stringToColor(palette_e pal, const std::string &str) { - if (pal == p_zxspectrum) { - if (str == "black") { - return {0x00, 0x00, 0x00}; - } - - else if (str == "bright_black") { - return {0x00, 0x00, 0x00}; - } - - else if (str == "blue") { - return {0x00, 0x00, 0xd8}; - } - - else if (str == "bright_blue") { - return {0x00, 0x00, 0xFF}; - } - - else if (str == "red") { - return {0xd8, 0x00, 0x00}; - } - - else if (str == "bright_red") { - return {0xFF, 0x00, 0x00}; - } - - else if (str == "magenta") { - return {0xd8, 0x00, 0xd8}; - } - - else if (str == "bright_magenta") { - return {0xFF, 0x00, 0xFF}; - } - - else if (str == "green") { - return {0x00, 0xd8, 0x00}; - } - - else if (str == "bright_green") { - return {0x00, 0xFF, 0x00}; - } - - else if (str == "cyan") { - return {0x00, 0xd8, 0xd8}; - } - - else if (str == "bright_cyan") { - return {0x00, 0xFF, 0xFF}; - } - - else if (str == "yellow") { - return {0xd8, 0xd8, 0x00}; - } - - else if (str == "bright_yellow") { - return {0xFF, 0xFF, 0x00}; - } - - else if (str == "white") { - return {0xd8, 0xd8, 0xd8}; - } - - else if (str == "bright_white") { - return {0xFF, 0xFF, 0xFF}; - } - } - - else if (pal == p_zxarne) { // zxarne - if (str == "black") { - return {0x00, 0x00, 0x00}; - } - - else if (str == "bright_black") { - return {0x3C, 0x35, 0x1F}; - } - - else if (str == "blue") { - return {0x31, 0x33, 0x90}; - } - - else if (str == "bright_blue") { - return {0x15, 0x59, 0xDB}; - } - - else if (str == "red") { - return {0xA7, 0x32, 0x11}; - } - - else if (str == "bright_red") { - return {0xD8, 0x55, 0x25}; - } - - else if (str == "magenta") { - return {0xA1, 0x55, 0x89}; - } - - else if (str == "bright_magenta") { - return {0xCD, 0x7A, 0x50}; - } - - else if (str == "green") { - return {0x62, 0x9A, 0x31}; - } - - else if (str == "bright_green") { - return {0x9C, 0xD3, 0x3C}; - } - - else if (str == "cyan") { - return {0x28, 0xA4, 0xCB}; - } - - else if (str == "bright_cyan") { - return {0x65, 0xDC, 0xD6}; - } - - else if (str == "yellow") { - return {0xE8, 0xBC, 0x50}; - } - - else if (str == "bright_yellow") { - return {0xF1, 0xE7, 0x82}; - } - - else if (str == "white") { - return {0xBF, 0xBF, 0xBD}; - } - - else if (str == "bright_white") { - return {0xF2, 0xF1, 0xED}; - } - } - - return {0x00, 0x00, 0x00}; -} - // Convierte una cadena en un valor booleano -bool stringToBool(const std::string &str) { - if (str == "true") { - return true; - } else { - return false; - } +auto stringToBool(const std::string &str) -> bool { + return str == "true"; } // Convierte un valor booleano en una cadena -std::string boolToString(bool value) { +auto boolToString(bool value) -> std::string { if (value) { return "true"; - } else { - return "false"; } + return "false"; } // Convierte una cadena a minusculas -std::string toLower(const std::string &str) { +auto toLower(const std::string &str) -> std::string { std::string result; result.reserve(str.size()); - std::transform(str.begin(), str.end(), std::back_inserter(result), [](unsigned char c) { return static_cast(std::tolower(c)); }); + std::ranges::transform(str, std::back_inserter(result), [](unsigned char c) { return static_cast(std::tolower(c)); }); return result; } \ No newline at end of file diff --git a/source/utils/utils.h b/source/utils/utils.h index 38ceac9..fd4b56e 100644 --- a/source/utils/utils.h +++ b/source/utils/utils.h @@ -53,12 +53,6 @@ struct color_t { b(blue) {} }; -// Tipos de paleta -enum palette_e { - p_zxspectrum, - p_zxarne -}; - // Estructura para saber la seccion y subseccion del programa struct section_t { Uint8 name; @@ -83,49 +77,46 @@ struct input_t { }; // Calcula el cuadrado de la distancia entre dos puntos -double distanceSquared(int x1, int y1, int x2, int y2); +auto distanceSquared(int x1, int y1, int x2, int y2) -> double; // Detector de colisiones entre dos circulos -bool checkCollision(const circle_t &a, const circle_t &b); +auto checkCollision(const circle_t &a, const circle_t &b) -> bool; // Detector de colisiones entre un circulo y un rectangulo -bool checkCollision(const circle_t &a, const SDL_Rect &b); +auto checkCollision(const circle_t &a, const SDL_Rect &b) -> bool; // Detector de colisiones entre un dos rectangulos -bool checkCollision(const SDL_Rect &a, const SDL_Rect &b); +auto checkCollision(const SDL_Rect &a, const SDL_Rect &b) -> bool; // Detector de colisiones entre un punto y un rectangulo -bool checkCollision(const SDL_Point &p, const SDL_Rect &r); +auto checkCollision(const SDL_Point &p, const SDL_Rect &r) -> bool; // Detector de colisiones entre una linea horizontal y un rectangulo -bool checkCollision(const h_line_t &l, const SDL_Rect &r); +auto checkCollision(const h_line_t &l, const SDL_Rect &r) -> bool; // Detector de colisiones entre una linea vertical y un rectangulo -bool checkCollision(const v_line_t &l, const SDL_Rect &r); +auto checkCollision(const v_line_t &l, const SDL_Rect &r) -> bool; // Detector de colisiones entre una linea horizontal y un punto -bool checkCollision(const h_line_t &l, const SDL_Point &p); +auto checkCollision(const h_line_t &l, const SDL_Point &p) -> bool; // Detector de colisiones entre dos lineas -SDL_Point checkCollision(const line_t &l1, const line_t &l2); +auto checkCollision(const line_t &l1, const line_t &l2) -> SDL_Point; // Detector de colisiones entre dos lineas -SDL_Point checkCollision(const d_line_t &l1, const v_line_t &l2); +auto checkCollision(const d_line_t &l1, const v_line_t &l2) -> SDL_Point; // Detector de colisiones entre un punto y una linea diagonal -bool checkCollision(const SDL_Point &p, const d_line_t &l); +auto checkCollision(const SDL_Point &p, const d_line_t &l) -> bool; // Normaliza una linea diagonal void normalizeLine(d_line_t &l); -// Devuelve un color_t a partir de un string -color_t stringToColor(palette_e pal, const std::string &str); - // Convierte una cadena en un valor booleano -bool stringToBool(const std::string &str); +auto stringToBool(const std::string &str) -> bool; // Convierte un valor booleano en una cadena -std::string boolToString(bool value); +auto boolToString(bool value) -> std::string; // Convierte una cadena a minusculas -std::string toLower(const std::string &str); +auto toLower(const std::string &str) -> std::string;