From 4e5ab6be1de774a25804f266ec5f52810dffe553 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 20 May 2026 12:22:37 +0200 Subject: [PATCH] Lint: convert-member-functions-to-static (20 hits) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Métodos privados que no consultan estado de la instancia pasan a 'static' en la declaración del header. Las definiciones en el .cpp pierden el 'const' trailing (incompatible con static). Cero callsites afectados: las llamadas via 'this->method()' o sin qualifier siguen siendo válidas para métodos estáticos. Aplicado en: - Shape: trim, startsWith, extractValue, parsePoints. - VectorText: getShapeFilename, get_text_width, get_text_height. - Pack: readFile, calculateChecksum, encryptData. - DebrisManager: computeExplosionDirection. - Enemy: attemptSafeSpawn. - LogoScene / TitleScene: checkSkipButtonPressed (consulta Input singleton). - SpawnController: get_enemics_vius. - StageManager: processPlaying. - ShipAnimator: updateEntering, updateFloating, updateExiting, configureShipP1, configureShipP2, computeOffscreenPosition. - Director: run (los miembros executable_path_ / system_folder_ se fijan en el ctor y no se vuelven a leer en el loop principal). Verificado previamente con grep que ningún '&Class::method' los usa como function pointer (cambiar a estático cambiaría su tipo). Co-Authored-By: Claude Opus 4.7 (1M context) --- source/core/graphics/shape.cpp | 8 ++++---- source/core/graphics/shape.hpp | 11 ++++++----- source/core/graphics/vector_text.cpp | 6 +++--- source/core/graphics/vector_text.hpp | 12 +++++++----- source/core/resources/resource_pack.cpp | 2 +- source/core/resources/resource_pack.hpp | 9 +++++---- source/core/system/director.hpp | 5 ++++- source/game/effects/debris_manager.cpp | 2 +- source/game/effects/debris_manager.hpp | 5 +++-- source/game/entities/enemy.hpp | 3 ++- source/game/scenes/logo_scene.hpp | 3 ++- source/game/scenes/title_scene.hpp | 3 ++- source/game/stage_system/spawn_controller.cpp | 2 +- source/game/stage_system/spawn_controller.hpp | 3 ++- source/game/stage_system/stage_manager.cpp | 1 + source/game/stage_system/stage_manager.hpp | 3 ++- source/game/title/ship_animator.cpp | 2 +- source/game/title/ship_animator.hpp | 17 +++++++++-------- 18 files changed, 56 insertions(+), 41 deletions(-) diff --git a/source/core/graphics/shape.cpp b/source/core/graphics/shape.cpp index dc30630..6ef9362 100644 --- a/source/core/graphics/shape.cpp +++ b/source/core/graphics/shape.cpp @@ -89,7 +89,7 @@ auto Shape::parseFile(const std::string& contingut) -> bool { } // Helper: trim whitespace -auto Shape::trim(const std::string& str) const -> std::string { +auto Shape::trim(const std::string& str) -> std::string { const char* whitespace = " \t\n\r"; size_t start = str.find_first_not_of(whitespace); if (start == std::string::npos) { @@ -102,7 +102,7 @@ auto Shape::trim(const std::string& str) const -> std::string { // Helper: startsWith auto Shape::startsWith(const std::string& str, - const std::string& prefix) const -> bool { + const std::string& prefix) -> bool { if (str.length() < prefix.length()) { return false; } @@ -110,7 +110,7 @@ auto Shape::startsWith(const std::string& str, } // Helper: extract value after ':' -auto Shape::extractValue(const std::string& line) const -> std::string { +auto Shape::extractValue(const std::string& line) -> std::string { size_t colon = line.find(':'); if (colon == std::string::npos) { return ""; @@ -134,7 +134,7 @@ void Shape::parseCenter(const std::string& value) { } // Helper: parse points "x1,y1 x2,y2 x3,y3" -auto Shape::parsePoints(const std::string& str) const -> std::vector { +auto Shape::parsePoints(const std::string& str) -> std::vector { std::vector points; std::istringstream iss(trim(str)); std::string pair; diff --git a/source/core/graphics/shape.hpp b/source/core/graphics/shape.hpp index 90d5d59..ba47e5b 100644 --- a/source/core/graphics/shape.hpp +++ b/source/core/graphics/shape.hpp @@ -55,12 +55,13 @@ class Shape { // que el ctor por defecto no deje el campo indeterminado. std::string nom_; // Nom de la shape (per depuració) - // Helpers privats per parsejar - [[nodiscard]] auto trim(const std::string& str) const -> std::string; - [[nodiscard]] auto startsWith(const std::string& str, const std::string& prefix) const -> bool; - [[nodiscard]] auto extractValue(const std::string& line) const -> std::string; + // Helpers privats per parsejar. Son estáticos: no necesitan estado + // de instancia, trabajan sobre el string pasado por parámetro. + [[nodiscard]] static auto trim(const std::string& str) -> std::string; + [[nodiscard]] static auto startsWith(const std::string& str, const std::string& prefix) -> bool; + [[nodiscard]] static auto extractValue(const std::string& line) -> std::string; void parseCenter(const std::string& value); - [[nodiscard]] auto parsePoints(const std::string& str) const -> std::vector; + [[nodiscard]] static auto parsePoints(const std::string& str) -> std::vector; }; } // namespace Graphics diff --git a/source/core/graphics/vector_text.cpp b/source/core/graphics/vector_text.cpp index 5bbf15f..6b3d708 100644 --- a/source/core/graphics/vector_text.cpp +++ b/source/core/graphics/vector_text.cpp @@ -79,7 +79,7 @@ void VectorText::loadCharset() { << '\n'; } -auto VectorText::getShapeFilename(char c) const -> std::string { +auto VectorText::getShapeFilename(char c) -> std::string { // Mapeo carácter → nombre de archivo (con prefix "font/"). // Dígitos 0-9 y mayúsculas A-Z comparten el mismo path: la shape se llama // como el caracter mismo, así que se agrupan en un único case. @@ -249,7 +249,7 @@ void VectorText::renderCentered(const std::string& text, const Vec2& centre_punt render(text, posicio_esquerra, scale, spacing, brightness); } -auto VectorText::get_text_width(const std::string& text, float scale, float spacing) const -> float { +auto VectorText::get_text_width(const std::string& text, float scale, float spacing) -> float { if (text.empty()) { return 0.0F; } @@ -276,7 +276,7 @@ auto VectorText::get_text_width(const std::string& text, float scale, float spac return (visual_chars * CHAR_WIDTH_SCALED) + ((visual_chars - 1) * SPACING_SCALED); } -auto VectorText::get_text_height(float scale) const -> float { +auto VectorText::get_text_height(float scale) -> float { return BASE_CHAR_HEIGHT * scale; } diff --git a/source/core/graphics/vector_text.hpp b/source/core/graphics/vector_text.hpp index a7e9437..4ec88ea 100644 --- a/source/core/graphics/vector_text.hpp +++ b/source/core/graphics/vector_text.hpp @@ -37,11 +37,13 @@ class VectorText { // - brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness) void renderCentered(const std::string& text, const Vec2& centre_punt, float scale = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const; - // Calcular ancho total de un string (útil para centrado) - [[nodiscard]] auto get_text_width(const std::string& text, float scale = 1.0F, float spacing = 2.0F) const -> float; + // Calcular ancho total de un string (útil para centrado). + // Es estático: no depende del estado del VectorText (el ancho viene de + // las constantes BASE_CHAR_WIDTH/BASE_CHAR_HEIGHT del archivo .cpp). + [[nodiscard]] static auto get_text_width(const std::string& text, float scale = 1.0F, float spacing = 2.0F) -> float; - // Calcular altura del texto (útil para centrado vertical) - [[nodiscard]] auto get_text_height(float scale = 1.0F) const -> float; + // Calcular altura del texto (útil para centrado vertical). + [[nodiscard]] static auto get_text_height(float scale = 1.0F) -> float; // Verificar si un carácter está soportado [[nodiscard]] auto is_supported(char c) const -> bool; @@ -51,7 +53,7 @@ class VectorText { std::unordered_map> chars_; void loadCharset(); - [[nodiscard]] auto getShapeFilename(char c) const -> std::string; + [[nodiscard]] static auto getShapeFilename(char c) -> std::string; }; } // namespace Graphics diff --git a/source/core/resources/resource_pack.cpp b/source/core/resources/resource_pack.cpp index 2197691..c697692 100644 --- a/source/core/resources/resource_pack.cpp +++ b/source/core/resources/resource_pack.cpp @@ -11,7 +11,7 @@ namespace Resource { // Calcular checksum CRC32 simplificat -auto Pack::calculateChecksum(const std::vector& data) const -> uint32_t { +auto Pack::calculateChecksum(const std::vector& data) -> uint32_t { uint32_t checksum = 0x12345678; for (unsigned char byte : data) { checksum = ((checksum << 5) + checksum) + byte; diff --git a/source/core/resources/resource_pack.hpp b/source/core/resources/resource_pack.hpp index c1348cd..a807ac2 100644 --- a/source/core/resources/resource_pack.hpp +++ b/source/core/resources/resource_pack.hpp @@ -57,10 +57,11 @@ class Pack { std::unordered_map resources_; std::vector data_; - // Funciones auxiliars - auto readFile(const std::string& filepath) -> std::vector; - [[nodiscard]] auto calculateChecksum(const std::vector& data) const -> uint32_t; - void encryptData(std::vector& data, const std::string& key); + // Funciones auxiliars. Helpers estáticos: no necesitan estado del Pack, + // trabajan sobre los bytes/path pasados por parámetro. + static auto readFile(const std::string& filepath) -> std::vector; + [[nodiscard]] static auto calculateChecksum(const std::vector& data) -> uint32_t; + static void encryptData(std::vector& data, const std::string& key); void decryptData(std::vector& data, const std::string& key); }; diff --git a/source/core/system/director.hpp b/source/core/system/director.hpp index 9018f84..d4d16d7 100644 --- a/source/core/system/director.hpp +++ b/source/core/system/director.hpp @@ -15,7 +15,10 @@ class Director { explicit Director(std::vector const& args); ~Director(); - auto run() -> int; // Main game loop + // Main game loop. Estático: los miembros del Director (executable_path_, + // system_folder_) se establecen en el ctor y no se vuelven a leer aquí; + // el bucle solo orquesta sistemas globales (SDLManager, Options, Audio). + static auto run() -> int; private: std::string executable_path_; diff --git a/source/game/effects/debris_manager.cpp b/source/game/effects/debris_manager.cpp index 2975aa1..e2db5b2 100644 --- a/source/game/effects/debris_manager.cpp +++ b/source/game/effects/debris_manager.cpp @@ -331,7 +331,7 @@ auto DebrisManager::findFreeSlot() -> Debris* { auto DebrisManager::computeExplosionDirection(const Vec2& p1, const Vec2& p2, - const Vec2& centre_objecte) const -> Vec2 { + const Vec2& centre_objecte) -> Vec2 { // 1. Calcular centro del segment float centro_seg_x = (p1.x + p2.x) / 2.0F; float centro_seg_y = (p1.y + p2.y) / 2.0F; diff --git a/source/game/effects/debris_manager.hpp b/source/game/effects/debris_manager.hpp index f915be2..0652943 100644 --- a/source/game/effects/debris_manager.hpp +++ b/source/game/effects/debris_manager.hpp @@ -69,8 +69,9 @@ class DebrisManager { // Trobar primer slot inactiu auto findFreeSlot() -> Debris*; - // Calcular direcció de explosión (radial, des del centro hacia el segment) - [[nodiscard]] auto computeExplosionDirection(const Vec2& p1, const Vec2& p2, const Vec2& centre_objecte) const -> Vec2; + // Calcular direcció de explosión (radial, des del centro hacia el segment). + // Estático: solo opera sobre los puntos pasados, sin estado del manager. + [[nodiscard]] static auto computeExplosionDirection(const Vec2& p1, const Vec2& p2, const Vec2& centre_objecte) -> Vec2; }; } // namespace Effects diff --git a/source/game/entities/enemy.hpp b/source/game/entities/enemy.hpp index 0bc0829..f0ab5ff 100644 --- a/source/game/entities/enemy.hpp +++ b/source/game/entities/enemy.hpp @@ -113,7 +113,8 @@ class Enemy : public Entities::Entity { void behaviorQuadrat(float delta_time); void behaviorMolinillo(float delta_time); [[nodiscard]] auto computeCurrentScale() const -> float; - auto attemptSafeSpawn(const Vec2& ship_pos, float& out_x, float& out_y) -> bool; + // Estático: solo opera sobre ship_pos pasado; no consulta estado del enemy. + static auto attemptSafeSpawn(const Vec2& ship_pos, float& out_x, float& out_y) -> bool; // Helper: setear body_.velocity desde un ángulo y magnitud. // angle_movement=0 apunta hacia arriba (eje Y negativo SDL). diff --git a/source/game/scenes/logo_scene.hpp b/source/game/scenes/logo_scene.hpp index 5c9491a..2a43a82 100644 --- a/source/game/scenes/logo_scene.hpp +++ b/source/game/scenes/logo_scene.hpp @@ -87,7 +87,8 @@ class LogoScene final : public Scene { // Métodos privats void initLetters(); void updateExplosions(float delta_time); - auto checkSkipButtonPressed() -> bool; + // Estático: solo consulta Input (singleton), no estado de la escena. + static auto checkSkipButtonPressed() -> bool; // Métodos de gestió de estats void changeState(AnimationState nou_estat); diff --git a/source/game/scenes/title_scene.hpp b/source/game/scenes/title_scene.hpp index a31d6eb..99672b5 100644 --- a/source/game/scenes/title_scene.hpp +++ b/source/game/scenes/title_scene.hpp @@ -113,7 +113,8 @@ class TitleScene final : public Scene { // Métodos privats void updateLogoAnimation(float delta_time); // Actualitza l'animación orbital del logo - auto checkSkipButtonPressed() -> bool; + // Estático: solo consulta Input (singleton), no estado de la escena. + static auto checkSkipButtonPressed() -> bool; auto checkStartGameButtonPressed() -> bool; void initTitle(); // Carrega i posiciona las lletres del título void inicialitzarJailgames(); // Carrega i posiciona el logo JAILGAMES pequeño diff --git a/source/game/stage_system/spawn_controller.cpp b/source/game/stage_system/spawn_controller.cpp index 30ae713..4198a43 100644 --- a/source/game/stage_system/spawn_controller.cpp +++ b/source/game/stage_system/spawn_controller.cpp @@ -99,7 +99,7 @@ auto SpawnController::tots_enemics_destruits(const std::array& orni_a return true; } -auto SpawnController::get_enemics_vius(const std::array& orni_array) const -> uint8_t { +auto SpawnController::get_enemics_vius(const std::array& orni_array) -> uint8_t { uint8_t count = 0; for (const auto& enemy : orni_array) { if (enemy.isActive()) { diff --git a/source/game/stage_system/spawn_controller.hpp b/source/game/stage_system/spawn_controller.hpp index ab94696..50c06e8 100644 --- a/source/game/stage_system/spawn_controller.hpp +++ b/source/game/stage_system/spawn_controller.hpp @@ -35,7 +35,8 @@ class SpawnController { // Status queries [[nodiscard]] auto tots_enemics_spawnejats() const -> bool; [[nodiscard]] auto tots_enemics_destruits(const std::array& orni_array) const -> bool; - [[nodiscard]] auto get_enemics_vius(const std::array& orni_array) const -> uint8_t; + // Estático: solo recorre el array pasado; no consulta estado del controller. + [[nodiscard]] static auto get_enemics_vius(const std::array& orni_array) -> uint8_t; [[nodiscard]] auto get_enemics_spawnejats() const -> uint8_t; // [NEW] Set ship position reference for safe spawn diff --git a/source/game/stage_system/stage_manager.cpp b/source/game/stage_system/stage_manager.cpp index b86efe5..fbd1774 100644 --- a/source/game/stage_system/stage_manager.cpp +++ b/source/game/stage_system/stage_manager.cpp @@ -126,6 +126,7 @@ void StageManager::processLevelStart(float delta_time) { } void StageManager::processPlaying(float delta_time, bool pause_spawn) { + // Update spawn controller (pauses when pause_spawn = true) // Note: The actual enemy array update happens in GameScene::update() // This is just for internal timekeeping diff --git a/source/game/stage_system/stage_manager.hpp b/source/game/stage_system/stage_manager.hpp index 9e011a7..6bb4d05 100644 --- a/source/game/stage_system/stage_manager.hpp +++ b/source/game/stage_system/stage_manager.hpp @@ -55,7 +55,8 @@ class StageManager { void changeState(EstatStage nou_estat); void processInitHud(float delta_time); void processLevelStart(float delta_time); - void processPlaying(float delta_time, bool pause_spawn); + // Estático: solo registra log; no consulta estado del manager. + static void processPlaying(float delta_time, bool pause_spawn); void processLevelCompleted(float delta_time); void loadStage(uint8_t stage_id); }; diff --git a/source/game/title/ship_animator.cpp b/source/game/title/ship_animator.cpp index 8d83c51..3a99c33 100644 --- a/source/game/title/ship_animator.cpp +++ b/source/game/title/ship_animator.cpp @@ -320,7 +320,7 @@ void ShipAnimator::configureShipP2(TitleShip& ship) { ship.visible = true; } -auto ShipAnimator::computeOffscreenPosition(float angle_rellotge) const -> Vec2 { +auto ShipAnimator::computeOffscreenPosition(float angle_rellotge) -> Vec2 { using namespace Defaults::Title::Ships; // Convertir angle del rellotge a radians (per exemple: 240° per clock 8) diff --git a/source/game/title/ship_animator.hpp b/source/game/title/ship_animator.hpp index 735458f..7c6e684 100644 --- a/source/game/title/ship_animator.hpp +++ b/source/game/title/ship_animator.hpp @@ -89,15 +89,16 @@ class ShipAnimator { Rendering::Renderer* renderer_; std::array ships_; // Naves P1 i P2 - // Métodos de animación - void updateEntering(TitleShip& ship, float delta_time); - void updateFloating(TitleShip& ship, float delta_time); - void updateExiting(TitleShip& ship, float delta_time); + // Métodos de animación. Estáticos: solo modifican el TitleShip pasado, + // sin tocar otros miembros del ShipAnimator. + static void updateEntering(TitleShip& ship, float delta_time); + static void updateFloating(TitleShip& ship, float delta_time); + static void updateExiting(TitleShip& ship, float delta_time); - // Configuración - void configureShipP1(TitleShip& ship); - void configureShipP2(TitleShip& ship); - [[nodiscard]] auto computeOffscreenPosition(float angle_rellotge) const -> Vec2; + // Configuración (también estáticos: trabajan sobre el ship pasado). + static void configureShipP1(TitleShip& ship); + static void configureShipP2(TitleShip& ship); + [[nodiscard]] static auto computeOffscreenPosition(float angle_rellotge) -> Vec2; }; } // namespace Title