From c80212adb96b88921305fb3d85d0aaccc3b757b8 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 20 May 2026 11:50:58 +0200 Subject: [PATCH] Lint: rename de locales (constants + const-ref vars) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tanda de identifier-naming de variables y constantes locales a funciones o archivos. Ninguno cross-file (los símbolos públicos quedan para una pasada manual con VS Code). - audio_adapter.cpp: path → PATH (const local en 3 funciones). - vector_text.cpp: symbols → SYMBOLS, char_width_scaled → CHAR_WIDTH_SCALED, char_height_scaled → CHAR_HEIGHT_SCALED, spacing_scaled → SPACING_SCALED (const locales en render/renderCentered/get_text_width). - physics_world.cpp: acceleration → ACCELERATION (const local en update). - constants.hpp::dins_zona_joc: point → POINT. - game_scene.cpp: - stepGameOver: game_over_text → GAME_OVER_TEXT. - dibuixar_marcador: scale/spacing → SCALE/SPACING (const), y la ref local 'scoreboard' (const SDL_FRect&) → 'scoreboard_zone' para no colisionar con Defaults::Zones::SCOREBOARD (las refs no son "constant" según el .clang-tidy y deben ser lower_case). - dibuixar_missatge_stage: max_width → MAX_WIDTH (const local). - dibuixar_continue: continue_text/counter_str/continues_text → UPPER_CASE. - title_scene.cpp::draw (sección MAIN): spacing → SPACING, main_text → MAIN_TEXT, escala_main → MAIN_SCALE. - shape_renderer.cpp: const Vec2& SHAPE_CENTRE → shape_centre (es ref, no constant). - collision_system.cpp: const Vec2& POS_ENEMIC → enemy_pos (ref + traducción). - init_hud_animator.cpp: refs ZONA → zone (en 2 funciones), SCOREBOARD → scoreboard_zone (sin colisionar con Defaults::Zones::SCOREBOARD). Co-Authored-By: Claude Opus 4.7 (1M context) --- source/core/audio/audio_adapter.cpp | 20 ++++++------- source/core/graphics/vector_text.cpp | 24 ++++++++-------- source/core/physics/physics_world.cpp | 4 +-- source/core/rendering/shape_renderer.cpp | 10 +++---- source/game/constants.hpp | 4 +-- source/game/scenes/game_scene.cpp | 34 +++++++++++------------ source/game/scenes/title_scene.cpp | 10 +++---- source/game/systems/collision_system.cpp | 6 ++-- source/game/systems/init_hud_animator.cpp | 20 ++++++------- 9 files changed, 66 insertions(+), 66 deletions(-) diff --git a/source/core/audio/audio_adapter.cpp b/source/core/audio/audio_adapter.cpp index 2fb2765..5bec949 100644 --- a/source/core/audio/audio_adapter.cpp +++ b/source/core/audio/audio_adapter.cpp @@ -54,21 +54,21 @@ auto getMusic(const std::string& name) -> Ja::Music* { return it->second.get(); } - const std::string path = normalizeMusicPath(name); - auto bytes = Resource::Helper::loadFile(path); + const std::string PATH = normalizeMusicPath(name); + auto bytes = Resource::Helper::loadFile(PATH); if (bytes.empty()) { - std::cerr << "[AudioResource] no se ha podido cargar música: " << path << "\n"; + std::cerr << "[AudioResource] no se ha podido cargar música: " << PATH << "\n"; return nullptr; } Ja::Music* raw = Ja::loadMusic(bytes.data(), static_cast(bytes.size()), name.c_str()); if (raw == nullptr) { - std::cerr << "[AudioResource] decodificación de música falló: " << path << "\n"; + std::cerr << "[AudioResource] decodificación de música falló: " << PATH << "\n"; return nullptr; } cache.emplace(name, std::unique_ptr(raw)); - std::cout << "[AudioResource] música cargada: " << path << "\n"; + std::cout << "[AudioResource] música cargada: " << PATH << "\n"; return raw; } @@ -78,21 +78,21 @@ auto getSound(const std::string& name) -> Ja::Sound* { return it->second.get(); } - const std::string path = normalizeSoundPath(name); - auto bytes = Resource::Helper::loadFile(path); + const std::string PATH = normalizeSoundPath(name); + auto bytes = Resource::Helper::loadFile(PATH); if (bytes.empty()) { - std::cerr << "[AudioResource] no se ha podido cargar sonido: " << path << "\n"; + std::cerr << "[AudioResource] no se ha podido cargar sonido: " << PATH << "\n"; return nullptr; } Ja::Sound* raw = Ja::loadSound(bytes.data(), static_cast(bytes.size())); if (raw == nullptr) { - std::cerr << "[AudioResource] decodificación de sonido falló: " << path << "\n"; + std::cerr << "[AudioResource] decodificación de sonido falló: " << PATH << "\n"; return nullptr; } cache.emplace(name, std::unique_ptr(raw)); - std::cout << "[AudioResource] sonido cargado: " << path << "\n"; + std::cout << "[AudioResource] sonido cargado: " << PATH << "\n"; return raw; } diff --git a/source/core/graphics/vector_text.cpp b/source/core/graphics/vector_text.cpp index f2ce020..46bf1bd 100644 --- a/source/core/graphics/vector_text.cpp +++ b/source/core/graphics/vector_text.cpp @@ -47,8 +47,8 @@ void VectorText::load_charset() { } // Cargar símbolos - const std::string symbols[] = {".", ",", "-", ":", "!", "?"}; - for (const auto& sym : symbols) { + const std::string SYMBOLS[] = {".", ",", "-", ":", "!", "?"}; + for (const auto& sym : SYMBOLS) { char c = sym[0]; std::string filename = get_shape_filename(c); auto shape = ShapeLoader::load(filename); @@ -185,13 +185,13 @@ void VectorText::render(const std::string& text, const Vec2& position, float sca } // Ancho de un carácter base (20 px a scale 1.0) - const float char_width_scaled = BASE_CHAR_WIDTH * scale; + const float CHAR_WIDTH_SCALED = BASE_CHAR_WIDTH * scale; // Spacing escalado - const float spacing_scaled = spacing * scale; + const float SPACING_SCALED = spacing * scale; // Altura de un carácter escalado (necesario para ajustar Y) - const float char_height_scaled = BASE_CHAR_HEIGHT * scale; + const float CHAR_HEIGHT_SCALED = BASE_CHAR_HEIGHT * scale; // Posición X del borde izquierdo del carácter actual // (se ajustará +BASE_CHAR_WIDTH/2 para obtener el centro al renderizar) @@ -210,7 +210,7 @@ void VectorText::render(const std::string& text, const Vec2& position, float sca // Manejar espacios (avanzar sin dibujar) if (c == ' ') { - current_x += char_width_scaled + spacing_scaled; + current_x += CHAR_WIDTH_SCALED + SPACING_SCALED; continue; } @@ -220,16 +220,16 @@ void VectorText::render(const std::string& text, const Vec2& position, float sca // Renderizar carácter // Ajustar X e Y para que position represente esquina superior izquierda // (render_shape espera el centro, así que sumamos la mitad de ancho y altura) - Vec2 char_pos = {.x = current_x + (char_width_scaled / 2.0F), .y = position.y + (char_height_scaled / 2.0F)}; + Vec2 char_pos = {.x = current_x + (CHAR_WIDTH_SCALED / 2.0F), .y = position.y + (CHAR_HEIGHT_SCALED / 2.0F)}; Rendering::render_shape(renderer_, it->second, char_pos, 0.0F, scale, 1.0F, brightness); // Avanzar posición - current_x += char_width_scaled + spacing_scaled; + current_x += CHAR_WIDTH_SCALED + SPACING_SCALED; } else { // Carácter no soportado: saltar (o renderizar '?' en el futuro) std::cerr << "[VectorText] Warning: caràcter no suportat '" << c << "'" << '\n'; - current_x += char_width_scaled + spacing_scaled; + current_x += CHAR_WIDTH_SCALED + SPACING_SCALED; } } } @@ -254,8 +254,8 @@ auto VectorText::get_text_width(const std::string& text, float scale, float spac return 0.0F; } - const float char_width_scaled = BASE_CHAR_WIDTH * scale; - const float spacing_scaled = spacing * scale; + const float CHAR_WIDTH_SCALED = BASE_CHAR_WIDTH * scale; + const float SPACING_SCALED = spacing * scale; // Contar caracteres visuals (no bytes) - manejar UTF-8 size_t visual_chars = 0; @@ -273,7 +273,7 @@ auto VectorText::get_text_width(const std::string& text, float scale, float spac } // Ancho total = todos los caracteres VISUALES + spacing entre ellos - return (visual_chars * char_width_scaled) + ((visual_chars - 1) * spacing_scaled); + return (visual_chars * CHAR_WIDTH_SCALED) + ((visual_chars - 1) * SPACING_SCALED); } auto VectorText::get_text_height(float scale) const -> float { diff --git a/source/core/physics/physics_world.cpp b/source/core/physics/physics_world.cpp index 822203d..fd7793c 100644 --- a/source/core/physics/physics_world.cpp +++ b/source/core/physics/physics_world.cpp @@ -42,8 +42,8 @@ void PhysicsWorld::integrate(float dt) { } // Aplicar fuerzas acumuladas → aceleración - const Vec2 acceleration = body->force_accumulator * body->inverse_mass; - body->velocity += acceleration * dt; + const Vec2 ACCELERATION = body->force_accumulator * body->inverse_mass; + body->velocity += ACCELERATION * dt; // Damping exponencial: equivalente a v *= exp(-damping * dt) // Aproximación lineal cuando damping*dt es pequeño. diff --git a/source/core/rendering/shape_renderer.cpp b/source/core/rendering/shape_renderer.cpp index f39e9a2..b0be7f2 100644 --- a/source/core/rendering/shape_renderer.cpp +++ b/source/core/rendering/shape_renderer.cpp @@ -88,20 +88,20 @@ void render_shape(Rendering::Renderer* renderer, return; } - const Vec2& SHAPE_CENTRE = shape->getCenter(); + const Vec2& shape_centre = shape->getCenter(); for (const auto& primitive : shape->get_primitives()) { if (primitive.type == Graphics::PrimitiveType::POLYLINE) { // POLYLINE: conectar puntos consecutivos. for (size_t i = 0; i < primitive.points.size() - 1; i++) { - const Vec2 P1 = transformPoint(primitive.points[i], SHAPE_CENTRE, position, angle, scale, rotation_3d); - const Vec2 P2 = transformPoint(primitive.points[i + 1], SHAPE_CENTRE, position, angle, scale, rotation_3d); + const Vec2 P1 = transformPoint(primitive.points[i], shape_centre, position, angle, scale, rotation_3d); + const Vec2 P2 = transformPoint(primitive.points[i + 1], shape_centre, position, angle, scale, rotation_3d); linea(renderer, static_cast(P1.x), static_cast(P1.y), static_cast(P2.x), static_cast(P2.y), brightness, 0.0F, color); } } else if (primitive.points.size() >= 2) { // LINE - const Vec2 P1 = transformPoint(primitive.points[0], SHAPE_CENTRE, position, angle, scale, rotation_3d); - const Vec2 P2 = transformPoint(primitive.points[1], SHAPE_CENTRE, position, angle, scale, rotation_3d); + const Vec2 P1 = transformPoint(primitive.points[0], shape_centre, position, angle, scale, rotation_3d); + const Vec2 P2 = transformPoint(primitive.points[1], shape_centre, position, angle, scale, rotation_3d); linea(renderer, static_cast(P1.x), static_cast(P1.y), static_cast(P2.x), static_cast(P2.y), brightness, 0.0F, color); } diff --git a/source/game/constants.hpp b/source/game/constants.hpp index 5771c80..8201d44 100644 --- a/source/game/constants.hpp +++ b/source/game/constants.hpp @@ -27,8 +27,8 @@ constexpr float PI = Defaults::Math::PI; // Helpers per comprovar límits de zona inline auto dins_zona_joc(float x, float y) -> bool { - const SDL_FPoint point = {x, y}; - return SDL_PointInRectFloat(&point, &Defaults::Zones::PLAYAREA); + const SDL_FPoint POINT = {x, y}; + return SDL_PointInRectFloat(&POINT, &Defaults::Zones::PLAYAREA); } inline void obtenir_limits_zona(float& min_x, float& max_x, float& min_y, float& max_y) { diff --git a/source/game/scenes/game_scene.cpp b/source/game/scenes/game_scene.cpp index 03bc026..f2f56a1 100644 --- a/source/game/scenes/game_scene.cpp +++ b/source/game/scenes/game_scene.cpp @@ -527,7 +527,7 @@ void GameScene::draw() { floating_score_manager_.draw(); // Draw centered "GAME OVER" text - const std::string game_over_text = "GAME OVER"; + const std::string GAME_OVER_TEXT = "GAME OVER"; constexpr float SCALE = Defaults::Game::GameOverScreen::TEXT_SCALE; constexpr float SPACING = Defaults::Game::GameOverScreen::TEXT_SPACING; @@ -536,7 +536,7 @@ void GameScene::draw() { float centre_x = play_area.x + (play_area.w / 2.0F); float centre_y = play_area.y + (play_area.h / 2.0F); - text_.renderCentered(game_over_text, {.x = centre_x, .y = centre_y}, SCALE, SPACING); + text_.renderCentered(GAME_OVER_TEXT, {.x = centre_x, .y = centre_y}, SCALE, SPACING); dibuixar_marcador(); return; @@ -736,16 +736,16 @@ void GameScene::dibuixar_marcador() { std::string text = buildScoreboard(); // Parámetros de renderització - const float scale = 0.85F; - const float spacing = 0.0F; + const float SCALE = 0.85F; + const float SPACING = 0.0F; // Calcular centro de la zona del marcador - const SDL_FRect& scoreboard = Defaults::Zones::SCOREBOARD; - float centre_x = scoreboard.w / 2.0F; - float centre_y = scoreboard.y + (scoreboard.h / 2.0F); + const SDL_FRect& scoreboard_zone = Defaults::Zones::SCOREBOARD; + float centre_x = scoreboard_zone.w / 2.0F; + float centre_y = scoreboard_zone.y + (scoreboard_zone.h / 2.0F); // Renderizar centrat - text_.renderCentered(text, {.x = centre_x, .y = centre_y}, scale, spacing); + text_.renderCentered(text, {.x = centre_x, .y = centre_y}, SCALE, SPACING); } auto GameScene::buildScoreboard() const -> std::string { @@ -794,7 +794,7 @@ void GameScene::dibuixar_missatge_stage(const std::string& message) { constexpr float SPACING = 2.0F; const SDL_FRect& play_area = Defaults::Zones::PLAYAREA; - const float max_width = play_area.w * Defaults::Game::STAGE_MESSAGE_MAX_WIDTH_RATIO; + const float MAX_WIDTH = play_area.w * Defaults::Game::STAGE_MESSAGE_MAX_WIDTH_RATIO; // ========== TYPEWRITER EFFECT (PARAMETRIZED) ========== // Get state-specific timing configuration @@ -837,9 +837,9 @@ void GameScene::dibuixar_missatge_stage(const std::string& message) { float text_width_at_base = text_.get_text_width(message, BASE_SCALE, SPACING); // Auto-scale if text exceeds max width - float scale = (text_width_at_base <= max_width) + float scale = (text_width_at_base <= MAX_WIDTH) ? BASE_SCALE - : max_width / text_width_at_base; + : MAX_WIDTH / text_width_at_base; // Recalculate dimensions with final scale (using FULL message for centering) float full_text_width = text_.get_text_width(message, scale, SPACING); @@ -913,33 +913,33 @@ void GameScene::dibuixar_continue() { constexpr float SPACING = 4.0F; // "CONTINUE" text (using constants) - const std::string continue_text = "CONTINUE"; + const std::string CONTINUE_TEXT = "CONTINUE"; float escala_continue = Defaults::Game::ContinueScreen::CONTINUE_TEXT_SCALE; float y_ratio_continue = Defaults::Game::ContinueScreen::CONTINUE_TEXT_Y_RATIO; float centre_x = play_area.x + (play_area.w / 2.0F); float centre_y_continue = play_area.y + (play_area.h * y_ratio_continue); - text_.renderCentered(continue_text, {.x = centre_x, .y = centre_y_continue}, escala_continue, SPACING); + text_.renderCentered(CONTINUE_TEXT, {.x = centre_x, .y = centre_y_continue}, escala_continue, SPACING); // Countdown number (using constants) - const std::string counter_str = std::to_string(continue_counter_); + const std::string COUNTER_STR = std::to_string(continue_counter_); float escala_counter = Defaults::Game::ContinueScreen::COUNTER_TEXT_SCALE; float y_ratio_counter = Defaults::Game::ContinueScreen::COUNTER_TEXT_Y_RATIO; float centre_y_counter = play_area.y + (play_area.h * y_ratio_counter); - text_.renderCentered(counter_str, {.x = centre_x, .y = centre_y_counter}, escala_counter, SPACING); + text_.renderCentered(COUNTER_STR, {.x = centre_x, .y = centre_y_counter}, escala_counter, SPACING); // "CONTINUES LEFT" (conditional + using constants) if (!Defaults::Game::INFINITE_CONTINUES) { - const std::string continues_text = "CONTINUES LEFT: " + std::to_string(Defaults::Game::MAX_CONTINUES - continues_used_); + const std::string CONTINUES_TEXT = "CONTINUES LEFT: " + std::to_string(Defaults::Game::MAX_CONTINUES - continues_used_); float escala_info = Defaults::Game::ContinueScreen::INFO_TEXT_SCALE; float y_ratio_info = Defaults::Game::ContinueScreen::INFO_TEXT_Y_RATIO; float centre_y_info = play_area.y + (play_area.h * y_ratio_info); - text_.renderCentered(continues_text, {.x = centre_x, .y = centre_y_info}, escala_info, SPACING); + text_.renderCentered(CONTINUES_TEXT, {.x = centre_x, .y = centre_y_info}, escala_info, SPACING); } } diff --git a/source/game/scenes/title_scene.cpp b/source/game/scenes/title_scene.cpp index dcaf9c5..7d96f70 100644 --- a/source/game/scenes/title_scene.cpp +++ b/source/game/scenes/title_scene.cpp @@ -676,7 +676,7 @@ void TitleScene::draw() { // En state MAIN: siempre visible // En state TRANSITION: parpellejant (blink con sinusoide) - const float spacing = Defaults::Title::Layout::TEXT_SPACING; + const float SPACING = Defaults::Title::Layout::TEXT_SPACING; bool mostrar_text = true; if (estat_actual_ == TitleState::PLAYER_JOIN_PHASE) { @@ -686,16 +686,16 @@ void TitleScene::draw() { } if (mostrar_text) { - const std::string main_text = "PRESS START TO PLAY"; - const float escala_main = Defaults::Title::Layout::PRESS_START_SCALE; + const std::string MAIN_TEXT = "PRESS START TO PLAY"; + const float MAIN_SCALE = Defaults::Title::Layout::PRESS_START_SCALE; float centre_x = Defaults::Game::WIDTH / 2.0F; float centre_y = Defaults::Game::HEIGHT * Defaults::Title::Layout::PRESS_START_POS; - text_.renderCentered(main_text, {.x = centre_x, .y = centre_y}, escala_main, spacing); + text_.renderCentered(MAIN_TEXT, {.x = centre_x, .y = centre_y}, MAIN_SCALE, SPACING); } - dibuixarPeuTitol(spacing); + dibuixarPeuTitol(SPACING); } } diff --git a/source/game/systems/collision_system.cpp b/source/game/systems/collision_system.cpp index fa1d4d7..97ea628 100644 --- a/source/game/systems/collision_system.cpp +++ b/source/game/systems/collision_system.cpp @@ -21,7 +21,7 @@ void detectBulletEnemy(Context& ctx) { } // *** COLISIÓN bullet → enemy *** - const Vec2& POS_ENEMIC = enemy.getCenter(); + const Vec2& enemy_pos = enemy.getCenter(); // 1. Puntos según tipo int points = 0; @@ -39,7 +39,7 @@ void detectBulletEnemy(Context& ctx) { uint8_t owner_id = bullet.getOwnerId(); ctx.score_per_player[owner_id] += points; - ctx.floating_score_manager.crear(points, POS_ENEMIC); + ctx.floating_score_manager.crear(points, enemy_pos); // 2. Destruir enemy + crear explosión (debris hereda color del enemy) SDL_Color enemy_color{}; @@ -52,7 +52,7 @@ void detectBulletEnemy(Context& ctx) { Vec2 vel_enemic = enemy.getVelocityVector(); ctx.debris_manager.explode( enemy.getShape(), - POS_ENEMIC, + enemy_pos, 0.0F, // angle (la rotación es interna del enemy) 1.0F, // escala VELOCITAT_EXPLOSIO, diff --git a/source/game/systems/init_hud_animator.cpp b/source/game/systems/init_hud_animator.cpp index 64ba432..9943d44 100644 --- a/source/game/systems/init_hud_animator.cpp +++ b/source/game/systems/init_hud_animator.cpp @@ -31,21 +31,21 @@ auto computeRangeProgress(float global_progress, auto computeShipPosition(float progress, const Vec2& final_position) -> Vec2 { const float EASED = Easing::ease_out_quad(progress); - const SDL_FRect& ZONA = Defaults::Zones::PLAYAREA; + const SDL_FRect& zone = Defaults::Zones::PLAYAREA; // Y inicial: 50 px bajo la zona de juego. - const float Y_INI = ZONA.y + ZONA.h + 50.0F; + const float Y_INI = zone.y + zone.h + 50.0F; const float Y_ANIM = Y_INI + ((final_position.y - Y_INI) * EASED); return Vec2{.x = final_position.x, .y = Y_ANIM}; } void drawBordersAnimated(Rendering::Renderer* renderer, float progress) { - const SDL_FRect& ZONA = Defaults::Zones::PLAYAREA; + const SDL_FRect& zone = Defaults::Zones::PLAYAREA; const float EASED = Easing::ease_out_quad(progress); - const int X1 = static_cast(ZONA.x); - const int Y1 = static_cast(ZONA.y); - const int X2 = static_cast(ZONA.x + ZONA.w); - const int Y2 = static_cast(ZONA.y + ZONA.h); + const int X1 = static_cast(zone.x); + const int Y1 = static_cast(zone.y); + const int X2 = static_cast(zone.x + zone.w); + const int Y2 = static_cast(zone.y + zone.h); const int CX = (X1 + X2) / 2; constexpr float PHASE_1_END = 0.33F; @@ -85,9 +85,9 @@ void drawScoreboardAnimated(const Graphics::VectorText& text, constexpr float SCALE = 0.85F; constexpr float SPACING = 0.0F; - const SDL_FRect& SCOREBOARD = Defaults::Zones::SCOREBOARD; - const float CENTRE_X = SCOREBOARD.w / 2.0F; - const float Y_FINAL = SCOREBOARD.y + (SCOREBOARD.h / 2.0F); + const SDL_FRect& scoreboard_zone = Defaults::Zones::SCOREBOARD; + const float CENTRE_X = scoreboard_zone.w / 2.0F; + const float Y_FINAL = scoreboard_zone.y + (scoreboard_zone.h / 2.0F); // Posición inicial: fuera de la pantalla por debajo. const auto Y_INI = static_cast(Defaults::Game::HEIGHT); const float Y_ANIM = Y_INI + ((Y_FINAL - Y_INI) * EASED);