From a0c1c8342fbc91068cd2f81eaf74cdb63a02de72 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 20 May 2026 18:18:12 +0200 Subject: [PATCH] refactor: esborrar aliases morts de game/constants.hpp (#24) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Esborrats: - Constants::MARGIN_LEFT/RIGHT/TOP/BOTTOM (zero callers; tots els call-sites llegeixen Defaults::Zones::PLAYAREA directament). - Constants::VELOCITAT i VELOCITAT_MAX (zero callers; eren els últims lectors de Defaults::Physics::ENEMY_SPEED/BULLET_SPEED). Es mantenen MAX_ORNIS, MAX_BALES (sí usats a game_scene.hpp) i PI, més els helpers de zona. Habilita el hallazgo #25 (eliminar Defaults::Physics::ENEMY_SPEED / BULLET_SPEED / VELOCITY_SCALE) — ja sense lectors. Hallazgo #24 de CODE_REVIEW.md. Co-Authored-By: Claude Opus 4.7 (1M context) --- source/game/constants.hpp | 79 ++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 46 deletions(-) diff --git a/source/game/constants.hpp b/source/game/constants.hpp index 1a52e44..0e7fda0 100644 --- a/source/game/constants.hpp +++ b/source/game/constants.hpp @@ -2,58 +2,45 @@ #include "core/defaults.hpp" -// Aliases para backward compatibility con codi existent -// Permet usar Constants::MARGIN_LEFT en lloc de Defaults::Game::MARGIN_LEFT +// Aliases utilitzats per simplificar lectures freqüents de Defaults:: namespace Constants { -// Márgenes de l'àrea de juego (derivats de Defaults::Zones::GAME) -constexpr int MARGIN_LEFT = static_cast(Defaults::Zones::PLAYAREA.x); -constexpr int MARGIN_RIGHT = - static_cast(Defaults::Zones::PLAYAREA.x + Defaults::Zones::PLAYAREA.w); -constexpr int MARGIN_TOP = static_cast(Defaults::Zones::PLAYAREA.y); -constexpr int MARGIN_BOTTOM = - static_cast(Defaults::Zones::PLAYAREA.y + Defaults::Zones::PLAYAREA.h); + // Límits de objectes + constexpr int MAX_ORNIS = Defaults::Entities::MAX_ORNIS; + constexpr int MAX_BALES = Defaults::Entities::MAX_BALES; -// Límits de objectes -constexpr int MAX_ORNIS = Defaults::Entities::MAX_ORNIS; -constexpr int MAX_BALES = Defaults::Entities::MAX_BALES; + // Matemàtiques + constexpr float PI = Defaults::Math::PI; -// Velocitats (valors legacy del codi Pascal) -constexpr int VELOCITAT = static_cast(Defaults::Physics::ENEMY_SPEED); -constexpr int VELOCITAT_MAX = static_cast(Defaults::Physics::BULLET_SPEED); + // Helpers per comprovar límits de zona + inline auto isInPlayArea(float x, float y) -> bool { + const SDL_FPoint POINT = {x, y}; + return SDL_PointInRectFloat(&POINT, &Defaults::Zones::PLAYAREA); + } -// Matemàtiques -constexpr float PI = Defaults::Math::PI; + inline void getPlayAreaBounds(float& min_x, float& max_x, float& min_y, float& max_y) { + const auto& zona = Defaults::Zones::PLAYAREA; + min_x = zona.x; + max_x = zona.x + zona.w; + min_y = zona.y; + max_y = zona.y + zona.h; + } -// Helpers per comprovar límits de zona -inline auto isInPlayArea(float x, float y) -> bool { - const SDL_FPoint POINT = {x, y}; - return SDL_PointInRectFloat(&POINT, &Defaults::Zones::PLAYAREA); -} + // Obtenir límits segurs (compensant radi de l'entidad) + inline void getSafePlayAreaBounds(float radi, float& min_x, float& max_x, float& min_y, float& max_y) { + const auto& zona = Defaults::Zones::PLAYAREA; + constexpr float MARGE_SEGURETAT = 10.0F; // Safety margin -inline void getPlayAreaBounds(float& min_x, float& max_x, float& min_y, float& max_y) { - const auto& zona = Defaults::Zones::PLAYAREA; - min_x = zona.x; - max_x = zona.x + zona.w; - min_y = zona.y; - max_y = zona.y + zona.h; -} + min_x = zona.x + radi + MARGE_SEGURETAT; + max_x = zona.x + zona.w - radi - MARGE_SEGURETAT; + min_y = zona.y + radi + MARGE_SEGURETAT; + max_y = zona.y + zona.h - radi - MARGE_SEGURETAT; + } -// Obtenir límits segurs (compensant radi de l'entidad) -inline void getSafePlayAreaBounds(float radi, float& min_x, float& max_x, float& min_y, float& max_y) { - const auto& zona = Defaults::Zones::PLAYAREA; - constexpr float MARGE_SEGURETAT = 10.0F; // Safety margin - - min_x = zona.x + radi + MARGE_SEGURETAT; - max_x = zona.x + zona.w - radi - MARGE_SEGURETAT; - min_y = zona.y + radi + MARGE_SEGURETAT; - max_y = zona.y + zona.h - radi - MARGE_SEGURETAT; -} - -// Obtenir centro de l'àrea de juego -inline void getPlayAreaCenter(float& centre_x, float& centre_y) { - const auto& zona = Defaults::Zones::PLAYAREA; - centre_x = zona.x + (zona.w / 2.0F); - centre_y = zona.y + (zona.h / 2.0F); -} + // Obtenir centro de l'àrea de juego + inline void getPlayAreaCenter(float& centre_x, float& centre_y) { + const auto& zona = Defaults::Zones::PLAYAREA; + centre_x = zona.x + (zona.w / 2.0F); + centre_y = zona.y + (zona.h / 2.0F); + } } // namespace Constants