Lint: inicializadores + retornos const-ref + warnings preexistentes
Primera tanda mecánica sobre el lint pendiente. Arregla la causa raíz, no
silencia diagnósticos. Detalle por categoría:
- Uninit members (cppcheck warnings) → inicializadores en declaración:
Bullet (esta_, owner_id_, grace_timer_), Enemy (drotacio_, rotacio_,
esta_, type_, tracking_timer_, ship_position_, tracking_strength_,
direction_change_timer_, timer_invulnerabilitat_), Ship (is_hit_,
invulnerable_timer_), Shape (escala_defecte_) y TitleShip (todos los
miembros del struct, que viven dentro de un std::array<,2>).
- returnByReference (cppcheck performance) → return const T&:
Shape::getName, ResourceLoader::getBasePath. De paso, Shape::get_nom
se renombra a getName y get_num_primitives a getNumPrimitives para
cumplir la convención camelBack del proyecto (lint del .clang-tidy).
- useInitializationList (cppcheck performance) →
Starfield::shape_estrella_ pasa a la lista de inicialización (reordenada
según la declaración para no disparar -Wreorder-ctor).
- noExplicitConstructor (cppcheck style) → explicit en ctores de 1 arg:
Bullet(Renderer*), Enemy(Renderer*), Ship(Renderer*,...) y VectorText(Renderer*).
- variableScope (cppcheck style) → en vector_text.cpp se elimina la
variable 'c' intermedia y se usa el literal '\\xA9' directamente en el
único punto donde se necesita.
- constParameterReference (cppcheck style) → drawScoreboardAnimated pasa
el VectorText por const ref (la API render/renderCentered es const).
- Warnings preexistentes del compilador (resueltos de paso):
- stage_config.hpp: stage_id <= 255 sobre uint8_t era siempre true; se
elimina la comparación redundante y se explica con comentario.
- director.cpp: 'struct stat st = {.st_dev = 0};' disparaba
-Wmissing-field-initializers; pasa a 'struct stat st{};' (zero-init
completo, robusto a las variantes específicas del SO).
- game_scene.cpp: stepDeathSequence devolvía un bool [[nodiscard]] que
el caller ignoraba; el valor era puramente interno. Cambiada la
firma a void.
- cppcheck: añadido --suppress=useStlAlgorithm. Las 26 sugerencias
'Consider using std::any_of/find_if/count_if' son cosméticas y no
aportan claridad sobre las raw loops actuales.
- .clang-tidy de source/core/audio/ eliminado: deshabilitaba todos los
checks en ese subdirectorio por dependencia de jail_audio.hpp, pero
impedía ejecutar 'make tidy' (clang-tidy aborta con "no checks
enabled" al primer archivo del directorio). El proyecto pasa a usar
el mismo patrón de CCAE: solo source/external/ y source/legacy/
quedan fuera del lint.
- lint-reports/ añadido a .gitignore. Carpeta donde 'make tidy' y
'make cppcheck' vuelcan su salida completa para inspección posterior.
Build limpio, cero warnings activos.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+2
-1
@@ -104,4 +104,5 @@ ehthumbs_vista.db
|
||||
*.swo
|
||||
|
||||
.cache/
|
||||
.claude/
|
||||
.claude/lint-reports/
|
||||
lint-reports/
|
||||
|
||||
@@ -259,6 +259,7 @@ if(CPPCHECK_EXE)
|
||||
--suppress=*:*source/external/*
|
||||
--suppress=*:*source/legacy/*
|
||||
--suppress=normalCheckLevelMaxBranches
|
||||
--suppress=useStlAlgorithm
|
||||
-D_DEBUG
|
||||
-DLINUX_BUILD
|
||||
--quiet
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
# Deshabilitar clang-tidy para este directorio (código externo: jail_audio.hpp)
|
||||
# Los demás archivos de este directorio (audio.cpp, audio_cache.cpp) también se benefician
|
||||
# de no ser modificados porque dependen íntimamente de la API de jail_audio.hpp
|
||||
|
||||
Checks: '-*'
|
||||
@@ -44,13 +44,14 @@ class Shape {
|
||||
[[nodiscard]] bool isValid() const { return !primitives_.empty(); }
|
||||
|
||||
// Info de depuració
|
||||
[[nodiscard]] std::string get_nom() const { return nom_; }
|
||||
[[nodiscard]] size_t get_num_primitives() const { return primitives_.size(); }
|
||||
[[nodiscard]] auto getName() const -> const std::string& { return nom_; }
|
||||
[[nodiscard]] auto getNumPrimitives() const -> size_t { return primitives_.size(); }
|
||||
|
||||
private:
|
||||
std::vector<ShapePrimitive> primitives_;
|
||||
Vec2 center_; // Centro/origin de la shape
|
||||
float escala_defecte_; // Escala per defecte (normalment 1.0)
|
||||
float escala_defecte_{1.0F}; // Escala per defecte (normalment 1.0). Inicializada para
|
||||
// que el ctor por defecto no deje el campo indeterminado.
|
||||
std::string nom_; // Nom de la shape (per depuració)
|
||||
|
||||
// Helpers privats per parsejar
|
||||
|
||||
@@ -53,8 +53,8 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
|
||||
}
|
||||
|
||||
// Cache and return
|
||||
std::cout << "[ShapeLoader] Carregat: " << normalized << " (" << shape->get_nom()
|
||||
<< ", " << shape->get_num_primitives() << " primitives)" << '\n';
|
||||
std::cout << "[ShapeLoader] Carregat: " << normalized << " (" << shape->getName()
|
||||
<< ", " << shape->getNumPrimitives() << " primitives)" << '\n';
|
||||
|
||||
cache_[filename] = shape;
|
||||
return shape;
|
||||
|
||||
@@ -18,13 +18,11 @@ Starfield::Starfield(Rendering::Renderer* renderer,
|
||||
const Vec2& punt_fuga,
|
||||
const SDL_FRect& area,
|
||||
int densitat)
|
||||
: renderer_(renderer),
|
||||
: shape_estrella_(ShapeLoader::load("star.shp")),
|
||||
renderer_(renderer),
|
||||
punt_fuga_(punt_fuga),
|
||||
area_(area),
|
||||
densitat_(densitat) {
|
||||
// Carregar shape de estrella con ShapeLoader
|
||||
shape_estrella_ = ShapeLoader::load("star.shp");
|
||||
|
||||
if (!shape_estrella_ || !shape_estrella_->isValid()) {
|
||||
std::cerr << "ERROR: No s'ha pogut load star.shp" << '\n';
|
||||
return;
|
||||
|
||||
@@ -62,17 +62,16 @@ void VectorText::load_charset() {
|
||||
}
|
||||
}
|
||||
|
||||
// Cargar símbolo de copyright (©) - UTF-8 U+00A9
|
||||
// Usem el segon byte (0xA9) como a key interna
|
||||
// Cargar símbolo de copyright (©) - UTF-8 U+00A9.
|
||||
// Usamos el segundo byte (0xA9, 169 decimal) como key interna del map.
|
||||
{
|
||||
char c = '\xA9'; // 169 decimal
|
||||
std::string filename = "font/char_copyright.shp";
|
||||
auto shape = ShapeLoader::load(filename);
|
||||
const std::string FILENAME = "font/char_copyright.shp";
|
||||
auto shape = ShapeLoader::load(FILENAME);
|
||||
|
||||
if (shape && shape->isValid()) {
|
||||
chars_[c] = shape;
|
||||
chars_['\xA9'] = shape;
|
||||
} else {
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut load " << filename
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut load " << FILENAME
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Graphics {
|
||||
|
||||
class VectorText {
|
||||
public:
|
||||
VectorText(Rendering::Renderer* renderer);
|
||||
explicit VectorText(Rendering::Renderer* renderer);
|
||||
|
||||
// Renderizar string completo
|
||||
// - text: cadena a renderizar (soporta: A-Z, a-z, 0-9, '.', ',', '-', ':',
|
||||
|
||||
@@ -105,7 +105,7 @@ void Loader::setBasePath(const std::string& path) {
|
||||
}
|
||||
|
||||
// Obtenir la ruta base
|
||||
std::string Loader::getBasePath() const {
|
||||
auto Loader::getBasePath() const -> const std::string& {
|
||||
return base_path_;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class Loader {
|
||||
|
||||
// Estat
|
||||
void setBasePath(const std::string& path);
|
||||
[[nodiscard]] std::string getBasePath() const;
|
||||
[[nodiscard]] auto getBasePath() const -> const std::string&;
|
||||
|
||||
// No es pot copiar ni moure
|
||||
Loader(const Loader&) = delete;
|
||||
|
||||
@@ -175,8 +175,10 @@ void Director::createSystemFolder(const std::string& folder) {
|
||||
}
|
||||
#endif
|
||||
|
||||
// Comprovar si la carpeta existeix
|
||||
struct stat st = {.st_dev = 0};
|
||||
// Comprovar si la carpeta existeix. Zero-init de toda la struct stat
|
||||
// para evitar -Wmissing-field-initializers (struct con muchos campos
|
||||
// específicos del SO que no queremos enumerar manualmente).
|
||||
struct stat st{};
|
||||
if (stat(system_folder_.c_str(), &st) == -1) {
|
||||
errno = 0;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ class Bullet : public Entities::Entity {
|
||||
public:
|
||||
Bullet()
|
||||
: Entity(nullptr) {}
|
||||
Bullet(Rendering::Renderer* renderer);
|
||||
explicit Bullet(Rendering::Renderer* renderer);
|
||||
|
||||
void init() override;
|
||||
void disparar(const Vec2& position, float angle, uint8_t owner_id);
|
||||
@@ -40,8 +40,10 @@ class Bullet : public Entities::Entity {
|
||||
void desactivar();
|
||||
|
||||
private:
|
||||
// Miembros específicos de Bullet (heredados: renderer_, shape_, center_, angle_, brightness_, body_)
|
||||
bool esta_;
|
||||
uint8_t owner_id_; // 0=P1, 1=P2
|
||||
float grace_timer_; // Grace period timer (0.0 = vulnerable)
|
||||
// Miembros específicos de Bullet (heredados: renderer_, shape_, center_, angle_, brightness_, body_).
|
||||
// Inicializados en la declaración para que tanto el ctor por defecto como el que toma renderer
|
||||
// dejen el objeto en estado coherente (proyectil inactivo, sin owner, sin grace timer).
|
||||
bool esta_{false};
|
||||
uint8_t owner_id_{0}; // 0=P1, 1=P2
|
||||
float grace_timer_{0.0F}; // Grace period timer (0.0 = vulnerable)
|
||||
};
|
||||
|
||||
@@ -37,7 +37,7 @@ class Enemy : public Entities::Entity {
|
||||
public:
|
||||
Enemy()
|
||||
: Entity(nullptr) {}
|
||||
Enemy(Rendering::Renderer* renderer);
|
||||
explicit Enemy(Rendering::Renderer* renderer);
|
||||
|
||||
void init() override { init(EnemyType::PENTAGON, nullptr); }
|
||||
void init(EnemyType type, const Vec2* ship_pos = nullptr);
|
||||
@@ -86,22 +86,24 @@ class Enemy : public Entities::Entity {
|
||||
[[nodiscard]] auto getInvulnerabilityTime() const -> float { return timer_invulnerabilitat_; }
|
||||
|
||||
private:
|
||||
// Miembros específicos (heredados: renderer_, shape_, center_, angle_, brightness_, body_)
|
||||
float drotacio_; // Velocidad angular visual (rad/s) — solo decoración, separada de body_.angular_velocity
|
||||
float rotacio_; // Rotación visual acumulada (no afecta movimiento)
|
||||
bool esta_;
|
||||
// Miembros específicos (heredados: renderer_, shape_, center_, angle_, brightness_, body_).
|
||||
// Inicializados en la declaración: el ctor por defecto deja al enemy en estado "inactivo
|
||||
// como pentágono", coherente con lo que harán init() o el ctor con renderer al activarlo.
|
||||
float drotacio_{0.0F}; // Velocidad angular visual (rad/s) — solo decoración, separada de body_.angular_velocity
|
||||
float rotacio_{0.0F}; // Rotación visual acumulada (no afecta movimiento)
|
||||
bool esta_{false};
|
||||
|
||||
EnemyType type_;
|
||||
EnemyType type_{EnemyType::PENTAGON};
|
||||
EnemyAnimation animacio_;
|
||||
|
||||
// Comportamiento type-specific
|
||||
float tracking_timer_; // Quadrat: tiempo desde último update de dirección
|
||||
const Vec2* ship_position_; // Puntero a posición de la nave (para tracking)
|
||||
float tracking_strength_; // Quadrat: intensidad de tracking (0.0-1.5), default 0.5
|
||||
float direction_change_timer_; // Pentagon: tiempo para próximo cambio de dirección
|
||||
float tracking_timer_{0.0F}; // Quadrat: tiempo desde último update de dirección
|
||||
const Vec2* ship_position_{nullptr}; // Puntero a posición de la nave (para tracking)
|
||||
float tracking_strength_{0.0F}; // Quadrat: intensidad de tracking (0.0-1.5), default 0.5
|
||||
float direction_change_timer_{0.0F}; // Pentagon: tiempo para próximo cambio de dirección
|
||||
|
||||
// Invulnerabilidad post-spawn
|
||||
float timer_invulnerabilitat_;
|
||||
float timer_invulnerabilitat_{0.0F};
|
||||
|
||||
// Métodos privados
|
||||
void updateAnimation(float delta_time);
|
||||
|
||||
@@ -14,7 +14,7 @@ class Ship : public Entities::Entity {
|
||||
public:
|
||||
Ship()
|
||||
: Entity(nullptr) {}
|
||||
Ship(Rendering::Renderer* renderer, const char* shape_file = "ship.shp");
|
||||
explicit Ship(Rendering::Renderer* renderer, const char* shape_file = "ship.shp");
|
||||
|
||||
void init() override { init(nullptr, false); }
|
||||
void init(const Vec2* spawn_point, bool activar_invulnerabilitat = false);
|
||||
@@ -56,7 +56,9 @@ class Ship : public Entities::Entity {
|
||||
}
|
||||
|
||||
private:
|
||||
// Miembros específicos de Ship (heredados: renderer_, shape_, center_, angle_, brightness_, body_)
|
||||
bool is_hit_;
|
||||
float invulnerable_timer_; // 0.0f = vulnerable, >0.0f = invulnerable
|
||||
// Miembros específicos de Ship (heredados: renderer_, shape_, center_, angle_, brightness_, body_).
|
||||
// Inicializados en la declaración: el ctor por defecto deja la nave "viva y sin invulnerabilidad",
|
||||
// que es el estado coherente al que llevan tanto init() como el ctor con renderer.
|
||||
bool is_hit_{false};
|
||||
float invulnerable_timer_{0.0F}; // 0.0f = vulnerable, >0.0f = invulnerable
|
||||
};
|
||||
|
||||
@@ -310,7 +310,7 @@ auto GameScene::stepGameOver(float delta_time) -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto GameScene::stepDeathSequence(float delta_time) -> bool {
|
||||
void GameScene::stepDeathSequence(float delta_time) {
|
||||
bool algun_mort = false;
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
if (hit_timer_per_player_[i] <= 0.0F || hit_timer_per_player_[i] >= 999.0F) {
|
||||
@@ -355,7 +355,9 @@ auto GameScene::stepDeathSequence(float delta_time) -> bool {
|
||||
debris_manager_.update(delta_time);
|
||||
floating_score_manager_.update(delta_time);
|
||||
}
|
||||
return algun_mort;
|
||||
// El bool 'algun_mort' es puramente interno: no aporta nada al caller
|
||||
// (la stage state machine sigue corriendo aunque haya jugadores muriendo),
|
||||
// así que la función no devuelve nada.
|
||||
}
|
||||
|
||||
void GameScene::stepStageStateMachine(float delta_time) {
|
||||
|
||||
@@ -109,10 +109,10 @@ class GameScene final : public Scene {
|
||||
// Devuelven true si el frame debe salir tras esta sección.
|
||||
[[nodiscard]] auto stepContinueScreen(float delta_time) -> bool;
|
||||
[[nodiscard]] auto stepGameOver(float delta_time) -> bool;
|
||||
// Avanza el death timer / respawn / transition a CONTINUE. Devuelve
|
||||
// true si algun jugador está en secuencia de muerte (para que el
|
||||
// caller actualice efectos sin gameplay).
|
||||
[[nodiscard]] auto stepDeathSequence(float delta_time) -> bool;
|
||||
// Avanza el death timer / respawn / transición a CONTINUE. Si algún
|
||||
// jugador está en secuencia de muerte, también actualiza efectos
|
||||
// (enemigos, balas, debris) que siguen vivos en el escenario.
|
||||
void stepDeathSequence(float delta_time);
|
||||
void stepStageStateMachine(float delta_time);
|
||||
void runStageInitHud(float delta_time);
|
||||
void runStageLevelStart(float delta_time);
|
||||
|
||||
@@ -56,7 +56,9 @@ struct StageConfig {
|
||||
|
||||
// Validació
|
||||
[[nodiscard]] bool es_valid() const {
|
||||
return stage_id >= 1 && stage_id <= 255 &&
|
||||
// stage_id es uint8_t: el rango superior (<=255) está garantizado por
|
||||
// el tipo; basta con confirmar que no es 0 (sentinela "sin asignar").
|
||||
return stage_id >= 1 &&
|
||||
total_enemies > 0 && total_enemies <= 15 &&
|
||||
distribucio.pentagon + distribucio.cuadrado + distribucio.molinillo == 100;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ void drawBordersAnimated(Rendering::Renderer* renderer, float progress) {
|
||||
}
|
||||
}
|
||||
|
||||
void drawScoreboardAnimated(Graphics::VectorText& text,
|
||||
void drawScoreboardAnimated(const Graphics::VectorText& text,
|
||||
const std::string& scoreboard_text,
|
||||
float progress) {
|
||||
const float EASED = Easing::ease_out_quad(progress);
|
||||
|
||||
@@ -42,7 +42,7 @@ void drawBordersAnimated(Rendering::Renderer* renderer, float progress);
|
||||
|
||||
// Dibuja el scoreboard centrado, subiendo desde fuera de la pantalla
|
||||
// hasta su posición final con easing.
|
||||
void drawScoreboardAnimated(Graphics::VectorText& text,
|
||||
void drawScoreboardAnimated(const Graphics::VectorText& text,
|
||||
const std::string& scoreboard_text,
|
||||
float progress);
|
||||
|
||||
|
||||
@@ -22,42 +22,45 @@ enum class ShipState {
|
||||
EXITING // Volant hacia el point de fuga
|
||||
};
|
||||
|
||||
// Dades de una ship individual al título
|
||||
// Dades de una ship individual al título.
|
||||
// Todos los miembros tienen inicializador por defecto: ShipAnimator::ships_
|
||||
// es un std::array<TitleShip, 2> y sin estos defaults los campos primitivos
|
||||
// quedarían indeterminados al instanciar el animador.
|
||||
struct TitleShip {
|
||||
// Identificació
|
||||
int player_id; // 1 o 2
|
||||
int player_id{0}; // 1 o 2
|
||||
|
||||
// Estat
|
||||
ShipState state;
|
||||
float state_time; // Temps acumulat en l'state actual
|
||||
ShipState state{ShipState::ENTERING};
|
||||
float state_time{0.0F}; // Temps acumulat en l'state actual
|
||||
|
||||
// Posicions
|
||||
Vec2 initial_position; // Posición de start (fuera de pantalla per ENTERING)
|
||||
Vec2 target_position; // Posición objetivo (rellotge 8 o 4)
|
||||
Vec2 current_position; // Posición interpolada actual
|
||||
Vec2 initial_position{}; // Posición de start (fuera de pantalla per ENTERING)
|
||||
Vec2 target_position{}; // Posición objetivo (rellotge 8 o 4)
|
||||
Vec2 current_position{}; // Posición interpolada actual
|
||||
|
||||
// Escales (simulació eix Z)
|
||||
float initial_scale; // Escala de start (més grande = més a prop)
|
||||
float target_scale; // Escala objetivo (mida flotació)
|
||||
float current_scale; // Escala interpolada actual
|
||||
float initial_scale{1.0F}; // Escala de start (més grande = més a prop)
|
||||
float target_scale{1.0F}; // Escala objetivo (mida flotació)
|
||||
float current_scale{1.0F}; // Escala interpolada actual
|
||||
|
||||
// Flotació
|
||||
float oscillation_phase; // Acumulador de fase per movement sinusoïdal
|
||||
float oscillation_phase{0.0F}; // Acumulador de fase per movement sinusoïdal
|
||||
|
||||
// Parámetros de entrada
|
||||
float entry_delay; // Delay antes de entrar (0.0 per P1, 0.5 per P2)
|
||||
float entry_delay{0.0F}; // Delay antes de entrar (0.0 per P1, 0.5 per P2)
|
||||
|
||||
// Parámetros de oscil·lació per ship
|
||||
float amplitude_x;
|
||||
float amplitude_y;
|
||||
float frequency_x;
|
||||
float frequency_y;
|
||||
float amplitude_x{0.0F};
|
||||
float amplitude_y{0.0F};
|
||||
float frequency_x{0.0F};
|
||||
float frequency_y{0.0F};
|
||||
|
||||
// Forma
|
||||
std::shared_ptr<Graphics::Shape> shape;
|
||||
|
||||
// Visibilitat
|
||||
bool visible;
|
||||
bool visible{false};
|
||||
};
|
||||
|
||||
// Gestor de animación de naves para l'escena de título
|
||||
|
||||
Reference in New Issue
Block a user