Lint: convert-member-functions-to-static (20 hits)
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) <noreply@anthropic.com>
This commit is contained in:
@@ -89,7 +89,7 @@ auto Shape::parseFile(const std::string& contingut) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper: trim whitespace
|
// 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";
|
const char* whitespace = " \t\n\r";
|
||||||
size_t start = str.find_first_not_of(whitespace);
|
size_t start = str.find_first_not_of(whitespace);
|
||||||
if (start == std::string::npos) {
|
if (start == std::string::npos) {
|
||||||
@@ -102,7 +102,7 @@ auto Shape::trim(const std::string& str) const -> std::string {
|
|||||||
|
|
||||||
// Helper: startsWith
|
// Helper: startsWith
|
||||||
auto Shape::startsWith(const std::string& str,
|
auto Shape::startsWith(const std::string& str,
|
||||||
const std::string& prefix) const -> bool {
|
const std::string& prefix) -> bool {
|
||||||
if (str.length() < prefix.length()) {
|
if (str.length() < prefix.length()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -110,7 +110,7 @@ auto Shape::startsWith(const std::string& str,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper: extract value after ':'
|
// 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(':');
|
size_t colon = line.find(':');
|
||||||
if (colon == std::string::npos) {
|
if (colon == std::string::npos) {
|
||||||
return "";
|
return "";
|
||||||
@@ -134,7 +134,7 @@ void Shape::parseCenter(const std::string& value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper: parse points "x1,y1 x2,y2 x3,y3"
|
// Helper: parse points "x1,y1 x2,y2 x3,y3"
|
||||||
auto Shape::parsePoints(const std::string& str) const -> std::vector<Vec2> {
|
auto Shape::parsePoints(const std::string& str) -> std::vector<Vec2> {
|
||||||
std::vector<Vec2> points;
|
std::vector<Vec2> points;
|
||||||
std::istringstream iss(trim(str));
|
std::istringstream iss(trim(str));
|
||||||
std::string pair;
|
std::string pair;
|
||||||
|
|||||||
@@ -55,12 +55,13 @@ class Shape {
|
|||||||
// que el ctor por defecto no deje el campo indeterminado.
|
// que el ctor por defecto no deje el campo indeterminado.
|
||||||
std::string nom_; // Nom de la shape (per depuració)
|
std::string nom_; // Nom de la shape (per depuració)
|
||||||
|
|
||||||
// Helpers privats per parsejar
|
// Helpers privats per parsejar. Son estáticos: no necesitan estado
|
||||||
[[nodiscard]] auto trim(const std::string& str) const -> std::string;
|
// de instancia, trabajan sobre el string pasado por parámetro.
|
||||||
[[nodiscard]] auto startsWith(const std::string& str, const std::string& prefix) const -> bool;
|
[[nodiscard]] static auto trim(const std::string& str) -> std::string;
|
||||||
[[nodiscard]] auto extractValue(const std::string& line) const -> 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);
|
void parseCenter(const std::string& value);
|
||||||
[[nodiscard]] auto parsePoints(const std::string& str) const -> std::vector<Vec2>;
|
[[nodiscard]] static auto parsePoints(const std::string& str) -> std::vector<Vec2>;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Graphics
|
} // namespace Graphics
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ void VectorText::loadCharset() {
|
|||||||
<< '\n';
|
<< '\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/").
|
// 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
|
// 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.
|
// 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);
|
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()) {
|
if (text.empty()) {
|
||||||
return 0.0F;
|
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);
|
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;
|
return BASE_CHAR_HEIGHT * scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,11 +37,13 @@ class VectorText {
|
|||||||
// - brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness)
|
// - 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;
|
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)
|
// 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;
|
// 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)
|
// Calcular altura del texto (útil para centrado vertical).
|
||||||
[[nodiscard]] auto get_text_height(float scale = 1.0F) const -> float;
|
[[nodiscard]] static auto get_text_height(float scale = 1.0F) -> float;
|
||||||
|
|
||||||
// Verificar si un carácter está soportado
|
// Verificar si un carácter está soportado
|
||||||
[[nodiscard]] auto is_supported(char c) const -> bool;
|
[[nodiscard]] auto is_supported(char c) const -> bool;
|
||||||
@@ -51,7 +53,7 @@ class VectorText {
|
|||||||
std::unordered_map<char, std::shared_ptr<Shape>> chars_;
|
std::unordered_map<char, std::shared_ptr<Shape>> chars_;
|
||||||
|
|
||||||
void loadCharset();
|
void loadCharset();
|
||||||
[[nodiscard]] auto getShapeFilename(char c) const -> std::string;
|
[[nodiscard]] static auto getShapeFilename(char c) -> std::string;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Graphics
|
} // namespace Graphics
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
namespace Resource {
|
namespace Resource {
|
||||||
|
|
||||||
// Calcular checksum CRC32 simplificat
|
// Calcular checksum CRC32 simplificat
|
||||||
auto Pack::calculateChecksum(const std::vector<uint8_t>& data) const -> uint32_t {
|
auto Pack::calculateChecksum(const std::vector<uint8_t>& data) -> uint32_t {
|
||||||
uint32_t checksum = 0x12345678;
|
uint32_t checksum = 0x12345678;
|
||||||
for (unsigned char byte : data) {
|
for (unsigned char byte : data) {
|
||||||
checksum = ((checksum << 5) + checksum) + byte;
|
checksum = ((checksum << 5) + checksum) + byte;
|
||||||
|
|||||||
@@ -57,10 +57,11 @@ class Pack {
|
|||||||
std::unordered_map<std::string, ResourceEntry> resources_;
|
std::unordered_map<std::string, ResourceEntry> resources_;
|
||||||
std::vector<uint8_t> data_;
|
std::vector<uint8_t> data_;
|
||||||
|
|
||||||
// Funciones auxiliars
|
// Funciones auxiliars. Helpers estáticos: no necesitan estado del Pack,
|
||||||
auto readFile(const std::string& filepath) -> std::vector<uint8_t>;
|
// trabajan sobre los bytes/path pasados por parámetro.
|
||||||
[[nodiscard]] auto calculateChecksum(const std::vector<uint8_t>& data) const -> uint32_t;
|
static auto readFile(const std::string& filepath) -> std::vector<uint8_t>;
|
||||||
void encryptData(std::vector<uint8_t>& data, const std::string& key);
|
[[nodiscard]] static auto calculateChecksum(const std::vector<uint8_t>& data) -> uint32_t;
|
||||||
|
static void encryptData(std::vector<uint8_t>& data, const std::string& key);
|
||||||
void decryptData(std::vector<uint8_t>& data, const std::string& key);
|
void decryptData(std::vector<uint8_t>& data, const std::string& key);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ class Director {
|
|||||||
explicit Director(std::vector<std::string> const& args);
|
explicit Director(std::vector<std::string> const& args);
|
||||||
~Director();
|
~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:
|
private:
|
||||||
std::string executable_path_;
|
std::string executable_path_;
|
||||||
|
|||||||
@@ -331,7 +331,7 @@ auto DebrisManager::findFreeSlot() -> Debris* {
|
|||||||
|
|
||||||
auto DebrisManager::computeExplosionDirection(const Vec2& p1,
|
auto DebrisManager::computeExplosionDirection(const Vec2& p1,
|
||||||
const Vec2& p2,
|
const Vec2& p2,
|
||||||
const Vec2& centre_objecte) const -> Vec2 {
|
const Vec2& centre_objecte) -> Vec2 {
|
||||||
// 1. Calcular centro del segment
|
// 1. Calcular centro del segment
|
||||||
float centro_seg_x = (p1.x + p2.x) / 2.0F;
|
float centro_seg_x = (p1.x + p2.x) / 2.0F;
|
||||||
float centro_seg_y = (p1.y + p2.y) / 2.0F;
|
float centro_seg_y = (p1.y + p2.y) / 2.0F;
|
||||||
|
|||||||
@@ -69,8 +69,9 @@ class DebrisManager {
|
|||||||
// Trobar primer slot inactiu
|
// Trobar primer slot inactiu
|
||||||
auto findFreeSlot() -> Debris*;
|
auto findFreeSlot() -> Debris*;
|
||||||
|
|
||||||
// Calcular direcció de explosión (radial, des del centro hacia el segment)
|
// 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;
|
// 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
|
} // namespace Effects
|
||||||
|
|||||||
@@ -113,7 +113,8 @@ class Enemy : public Entities::Entity {
|
|||||||
void behaviorQuadrat(float delta_time);
|
void behaviorQuadrat(float delta_time);
|
||||||
void behaviorMolinillo(float delta_time);
|
void behaviorMolinillo(float delta_time);
|
||||||
[[nodiscard]] auto computeCurrentScale() const -> float;
|
[[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.
|
// Helper: setear body_.velocity desde un ángulo y magnitud.
|
||||||
// angle_movement=0 apunta hacia arriba (eje Y negativo SDL).
|
// angle_movement=0 apunta hacia arriba (eje Y negativo SDL).
|
||||||
|
|||||||
@@ -87,7 +87,8 @@ class LogoScene final : public Scene {
|
|||||||
// Métodos privats
|
// Métodos privats
|
||||||
void initLetters();
|
void initLetters();
|
||||||
void updateExplosions(float delta_time);
|
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
|
// Métodos de gestió de estats
|
||||||
void changeState(AnimationState nou_estat);
|
void changeState(AnimationState nou_estat);
|
||||||
|
|||||||
@@ -113,7 +113,8 @@ class TitleScene final : public Scene {
|
|||||||
|
|
||||||
// Métodos privats
|
// Métodos privats
|
||||||
void updateLogoAnimation(float delta_time); // Actualitza l'animación orbital del logo
|
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;
|
auto checkStartGameButtonPressed() -> bool;
|
||||||
void initTitle(); // Carrega i posiciona las lletres del título
|
void initTitle(); // Carrega i posiciona las lletres del título
|
||||||
void inicialitzarJailgames(); // Carrega i posiciona el logo JAILGAMES pequeño
|
void inicialitzarJailgames(); // Carrega i posiciona el logo JAILGAMES pequeño
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ auto SpawnController::tots_enemics_destruits(const std::array<Enemy, 15>& orni_a
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto SpawnController::get_enemics_vius(const std::array<Enemy, 15>& orni_array) const -> uint8_t {
|
auto SpawnController::get_enemics_vius(const std::array<Enemy, 15>& orni_array) -> uint8_t {
|
||||||
uint8_t count = 0;
|
uint8_t count = 0;
|
||||||
for (const auto& enemy : orni_array) {
|
for (const auto& enemy : orni_array) {
|
||||||
if (enemy.isActive()) {
|
if (enemy.isActive()) {
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ class SpawnController {
|
|||||||
// Status queries
|
// Status queries
|
||||||
[[nodiscard]] auto tots_enemics_spawnejats() const -> bool;
|
[[nodiscard]] auto tots_enemics_spawnejats() const -> bool;
|
||||||
[[nodiscard]] auto tots_enemics_destruits(const std::array<Enemy, 15>& orni_array) const -> bool;
|
[[nodiscard]] auto tots_enemics_destruits(const std::array<Enemy, 15>& orni_array) const -> bool;
|
||||||
[[nodiscard]] auto get_enemics_vius(const std::array<Enemy, 15>& 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<Enemy, 15>& orni_array) -> uint8_t;
|
||||||
[[nodiscard]] auto get_enemics_spawnejats() const -> uint8_t;
|
[[nodiscard]] auto get_enemics_spawnejats() const -> uint8_t;
|
||||||
|
|
||||||
// [NEW] Set ship position reference for safe spawn
|
// [NEW] Set ship position reference for safe spawn
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ void StageManager::processLevelStart(float delta_time) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void StageManager::processPlaying(float delta_time, bool pause_spawn) {
|
void StageManager::processPlaying(float delta_time, bool pause_spawn) {
|
||||||
|
|
||||||
// Update spawn controller (pauses when pause_spawn = true)
|
// Update spawn controller (pauses when pause_spawn = true)
|
||||||
// Note: The actual enemy array update happens in GameScene::update()
|
// Note: The actual enemy array update happens in GameScene::update()
|
||||||
// This is just for internal timekeeping
|
// This is just for internal timekeeping
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ class StageManager {
|
|||||||
void changeState(EstatStage nou_estat);
|
void changeState(EstatStage nou_estat);
|
||||||
void processInitHud(float delta_time);
|
void processInitHud(float delta_time);
|
||||||
void processLevelStart(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 processLevelCompleted(float delta_time);
|
||||||
void loadStage(uint8_t stage_id);
|
void loadStage(uint8_t stage_id);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -320,7 +320,7 @@ void ShipAnimator::configureShipP2(TitleShip& ship) {
|
|||||||
ship.visible = true;
|
ship.visible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ShipAnimator::computeOffscreenPosition(float angle_rellotge) const -> Vec2 {
|
auto ShipAnimator::computeOffscreenPosition(float angle_rellotge) -> Vec2 {
|
||||||
using namespace Defaults::Title::Ships;
|
using namespace Defaults::Title::Ships;
|
||||||
|
|
||||||
// Convertir angle del rellotge a radians (per exemple: 240° per clock 8)
|
// Convertir angle del rellotge a radians (per exemple: 240° per clock 8)
|
||||||
|
|||||||
@@ -89,15 +89,16 @@ class ShipAnimator {
|
|||||||
Rendering::Renderer* renderer_;
|
Rendering::Renderer* renderer_;
|
||||||
std::array<TitleShip, 2> ships_; // Naves P1 i P2
|
std::array<TitleShip, 2> ships_; // Naves P1 i P2
|
||||||
|
|
||||||
// Métodos de animación
|
// Métodos de animación. Estáticos: solo modifican el TitleShip pasado,
|
||||||
void updateEntering(TitleShip& ship, float delta_time);
|
// sin tocar otros miembros del ShipAnimator.
|
||||||
void updateFloating(TitleShip& ship, float delta_time);
|
static void updateEntering(TitleShip& ship, float delta_time);
|
||||||
void updateExiting(TitleShip& ship, float delta_time);
|
static void updateFloating(TitleShip& ship, float delta_time);
|
||||||
|
static void updateExiting(TitleShip& ship, float delta_time);
|
||||||
|
|
||||||
// Configuración
|
// Configuración (también estáticos: trabajan sobre el ship pasado).
|
||||||
void configureShipP1(TitleShip& ship);
|
static void configureShipP1(TitleShip& ship);
|
||||||
void configureShipP2(TitleShip& ship);
|
static void configureShipP2(TitleShip& ship);
|
||||||
[[nodiscard]] auto computeOffscreenPosition(float angle_rellotge) const -> Vec2;
|
[[nodiscard]] static auto computeOffscreenPosition(float angle_rellotge) -> Vec2;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Title
|
} // namespace Title
|
||||||
|
|||||||
Reference in New Issue
Block a user