style: aplicar checks modernize-* (215 fixes)

Cambios aplicados:
- [[nodiscard]] añadido a funciones que retornan valores
- .starts_with() en lugar de .find() == 0
- Inicializadores designados {.x=0, .y=0}
- auto en castings obvios
- = default para constructores triviales
- Funciones deleted movidas a public
- std::numbers::pi_v<float> (C++20)

Checks excluidos:
- use-trailing-return-type: Estilo controversial
- avoid-c-arrays: Arrays C aceptables en ciertos contextos
This commit is contained in:
2025-12-18 20:16:46 +01:00
parent fdfb84170f
commit 7f6af6dd00
42 changed files with 178 additions and 178 deletions

View File

@@ -555,7 +555,7 @@ void EscenaJoc::dibuixar() {
float centre_x = play_area.x + (play_area.w / 2.0F);
float centre_y = play_area.y + (play_area.h / 2.0F);
text_.render_centered(game_over_text, {centre_x, centre_y}, escala, spacing);
text_.render_centered(game_over_text, {.x = centre_x, .y = centre_y}, escala, spacing);
dibuixar_marcador();
return;
@@ -710,7 +710,7 @@ void EscenaJoc::tocado(uint8_t player_id) {
float ship_angle = naus_[player_id].get_angle();
Punt vel_nau = naus_[player_id].get_velocitat_vector();
// Reduir a 80% la velocitat heretada per la nau (més realista)
Punt vel_nau_80 = {vel_nau.x * 0.8F, vel_nau.y * 0.8F};
Punt vel_nau_80 = {.x = vel_nau.x * 0.8F, .y = vel_nau.y * 0.8F};
debris_manager_.explotar(
naus_[player_id].get_forma(), // Ship shape (3 lines)
@@ -763,7 +763,7 @@ void EscenaJoc::dibuixar_marcador() {
float centre_y = scoreboard.y + (scoreboard.h / 2.0F);
// Renderitzar centrat
text_.render_centered(text, {centre_x, centre_y}, escala, spacing);
text_.render_centered(text, {.x = centre_x, .y = centre_y}, escala, spacing);
}
void EscenaJoc::dibuixar_marges_animat(float progress) const {
@@ -844,13 +844,13 @@ void EscenaJoc::dibuixar_marcador_animat(float progress) {
float centre_y_final = scoreboard.y + (scoreboard.h / 2.0F);
// Posició Y inicial (offscreen, sota de la pantalla)
float centre_y_inicial = static_cast<float>(Defaults::Game::HEIGHT);
auto centre_y_inicial = static_cast<float>(Defaults::Game::HEIGHT);
// Interpolació amb easing
float centre_y_animada = centre_y_inicial + ((centre_y_final - centre_y_inicial) * eased_progress);
// Renderitzar centrat en posició animada
text_.render_centered(text, {centre_x, centre_y_animada}, escala, spacing);
text_.render_centered(text, {.x = centre_x, .y = centre_y_animada}, escala, spacing);
}
Punt EscenaJoc::calcular_posicio_nau_init_hud(float progress, uint8_t player_id) const {
@@ -874,7 +874,7 @@ Punt EscenaJoc::calcular_posicio_nau_init_hud(float progress, uint8_t player_id)
// Y interpola amb easing
float y_animada = y_inicial + ((y_final - y_inicial) * eased_progress);
return {x_final, y_animada};
return {.x = x_final, .y = y_animada};
}
float EscenaJoc::calcular_progress_rango(float global_progress, float ratio_init, float ratio_end) const {
@@ -1061,8 +1061,8 @@ void EscenaJoc::detectar_col·lisio_naus_enemics() {
const Punt& pos_enemic = enemic.get_centre();
// Calculate squared distance (avoid sqrt)
float dx = static_cast<float>(pos_nau.x - pos_enemic.x);
float dy = static_cast<float>(pos_nau.y - pos_enemic.y);
auto dx = static_cast<float>(pos_nau.x - pos_enemic.x);
auto dy = static_cast<float>(pos_nau.y - pos_enemic.y);
float distancia_quadrada = (dx * dx) + (dy * dy);
// Check collision
@@ -1220,7 +1220,7 @@ void EscenaJoc::dibuixar_missatge_stage(const std::string& missatge) {
float y = play_area.y + (play_area.h * Defaults::Game::STAGE_MESSAGE_Y_RATIO) - (text_height / 2.0F);
// Render only the partial message (typewriter effect)
Punt pos = {x, y};
Punt pos = {.x = x, .y = y};
text_.render(partial_message, pos, escala, spacing);
}
@@ -1243,8 +1243,8 @@ Punt EscenaJoc::obtenir_punt_spawn(uint8_t player_id) const {
}
return {
zona.x + (zona.w * x_ratio),
zona.y + (zona.h * Defaults::Game::SPAWN_Y_RATIO)};
.x = zona.x + (zona.w * x_ratio),
.y = zona.y + (zona.h * Defaults::Game::SPAWN_Y_RATIO)};
}
void EscenaJoc::disparar_bala(uint8_t player_id) {
@@ -1266,7 +1266,7 @@ void EscenaJoc::disparar_bala(uint8_t player_id) {
float sin_a = std::sin(ship_angle);
float tip_x = (LOCAL_TIP_X * cos_a) - (LOCAL_TIP_Y * sin_a) + ship_centre.x;
float tip_y = (LOCAL_TIP_X * sin_a) + (LOCAL_TIP_Y * cos_a) + ship_centre.y;
Punt posicio_dispar = {tip_x, tip_y};
Punt posicio_dispar = {.x = tip_x, .y = tip_y};
// Buscar primera bala inactiva en el pool del jugador
int start_idx = player_id * 3; // P1=[0,1,2], P2=[3,4,5]
@@ -1400,7 +1400,7 @@ void EscenaJoc::dibuixar_continue() {
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_.render_centered(continue_text, {centre_x, centre_y_continue}, escala_continue, spacing);
text_.render_centered(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_);
@@ -1409,7 +1409,7 @@ void EscenaJoc::dibuixar_continue() {
float centre_y_counter = play_area.y + (play_area.h * y_ratio_counter);
text_.render_centered(counter_str, {centre_x, centre_y_counter}, escala_counter, spacing);
text_.render_centered(counter_str, {.x = centre_x, .y = centre_y_counter}, escala_counter, spacing);
// "CONTINUES LEFT" (conditional + using constants)
if (!Defaults::Game::INFINITE_CONTINUES) {
@@ -1419,7 +1419,7 @@ void EscenaJoc::dibuixar_continue() {
float centre_y_info = play_area.y + (play_area.h * y_ratio_info);
text_.render_centered(continues_text, {centre_x, centre_y_info}, escala_info, spacing);
text_.render_centered(continues_text, {.x = centre_x, .y = centre_y_info}, escala_info, spacing);
}
}

View File

@@ -87,7 +87,7 @@ class EscenaJoc {
void dibuixar_marges() const; // Dibuixar vores de la zona de joc
void dibuixar_marcador(); // Dibuixar marcador de puntuació
void disparar_bala(uint8_t player_id); // Shoot bullet from player
Punt obtenir_punt_spawn(uint8_t player_id) const; // Get spawn position for player
[[nodiscard]] Punt obtenir_punt_spawn(uint8_t player_id) const; // Get spawn position for player
// [NEW] Continue & Join system
void unir_jugador(uint8_t player_id); // Join inactive player mid-game
@@ -102,13 +102,13 @@ class EscenaJoc {
// [NEW] Funcions d'animació per INIT_HUD
void dibuixar_marges_animat(float progress) const; // Rectangle amb creixement uniforme
void dibuixar_marcador_animat(float progress); // Marcador que puja des de baix
Punt calcular_posicio_nau_init_hud(float progress, uint8_t player_id) const; // Posició animada de la nau
[[nodiscard]] Punt calcular_posicio_nau_init_hud(float progress, uint8_t player_id) const; // Posició animada de la nau
// [NEW] Función helper del sistema de animación INIT_HUD
float calcular_progress_rango(float global_progress, float ratio_init, float ratio_end) const;
[[nodiscard]] float calcular_progress_rango(float global_progress, float ratio_init, float ratio_end) const;
// [NEW] Funció helper del marcador
std::string construir_marcador() const;
[[nodiscard]] std::string construir_marcador() const;
};
#endif // ESCENA_JOC_HPP

View File

@@ -167,7 +167,7 @@ void EscenaLogo::inicialitzar_lletres() {
float offset_centre = (forma->get_centre().x - min_x) * ESCALA_FINAL;
lletres_.push_back({forma,
{0.0F, 0.0F}, // Posició es calcularà després
{.x = 0.0F, .y = 0.0F}, // Posició es calcularà després
ancho,
offset_centre});
@@ -243,13 +243,13 @@ void EscenaLogo::actualitzar_explosions(float delta_time) {
const auto& lletra = lletres_[index_actual];
debris_manager_->explotar(
lletra.forma, // Forma a explotar
lletra.posicio, // Posició
0.0F, // Angle (sense rotació)
ESCALA_FINAL, // Escala (lletres a escala final)
VELOCITAT_EXPLOSIO, // Velocitat base
1.0F, // Brightness màxim (per defecte)
{0.0F, 0.0F} // Sense velocitat (per defecte)
lletra.forma, // Forma a explotar
lletra.posicio, // Posició
0.0F, // Angle (sense rotació)
ESCALA_FINAL, // Escala (lletres a escala final)
VELOCITAT_EXPLOSIO, // Velocitat base
1.0F, // Brightness màxim (per defecte)
{.x = 0.0F, .y = 0.0F} // Sense velocitat (per defecte)
);
std::cout << "[EscenaLogo] Explota lletra " << lletra_explosio_index_ << "\n";
@@ -347,7 +347,7 @@ void EscenaLogo::dibuixar() {
? std::min(temps_estat_actual_ / DURACIO_ZOOM, 1.0F)
: 1.0F; // POST: mantenir al 100%
const Punt ORIGEN_ZOOM = {ORIGEN_ZOOM_X, ORIGEN_ZOOM_Y};
const Punt ORIGEN_ZOOM = {.x = ORIGEN_ZOOM_X, .y = ORIGEN_ZOOM_Y};
for (size_t i = 0; i < lletres_.size(); i++) {
const auto& lletra = lletres_[i];

View File

@@ -87,5 +87,5 @@ class EscenaLogo {
// Mètodes de gestió d'estats
void canviar_estat(EstatAnimacio nou_estat);
bool totes_lletres_completes() const;
[[nodiscard]] bool totes_lletres_completes() const;
};

View File

@@ -7,6 +7,7 @@
#include <cfloat>
#include <cmath>
#include <iostream>
#include <numbers>
#include <string>
#include "core/audio/audio.hpp"
@@ -51,8 +52,8 @@ EscenaTitol::EscenaTitol(SDLManager& sdl, ContextEscenes& context)
// Crear starfield de fons
Punt centre_pantalla{
Defaults::Game::WIDTH / 2.0F,
Defaults::Game::HEIGHT / 2.0F};
.x = Defaults::Game::WIDTH / 2.0F,
.y = Defaults::Game::HEIGHT / 2.0F};
SDL_FRect area_completa{
0,
@@ -146,7 +147,7 @@ void EscenaTitol::inicialitzar_titol() {
float altura = altura_sin_escalar * Defaults::Title::Layout::LOGO_SCALE;
float offset_centre = (forma->get_centre().x - min_x) * Defaults::Title::Layout::LOGO_SCALE;
lletres_orni_.push_back({forma, {0.0F, 0.0F}, ancho, altura, offset_centre});
lletres_orni_.push_back({forma, {.x = 0.0F, .y = 0.0F}, ancho, altura, offset_centre});
ancho_total_orni += ancho;
}
@@ -220,7 +221,7 @@ void EscenaTitol::inicialitzar_titol() {
float altura = altura_sin_escalar * Defaults::Title::Layout::LOGO_SCALE;
float offset_centre = (forma->get_centre().x - min_x) * Defaults::Title::Layout::LOGO_SCALE;
lletres_attack_.push_back({forma, {0.0F, 0.0F}, ancho, altura, offset_centre});
lletres_attack_.push_back({forma, {.x = 0.0F, .y = 0.0F}, ancho, altura, offset_centre});
ancho_total_attack += ancho;
}
@@ -653,7 +654,7 @@ void EscenaTitol::dibuixar() {
bool mostrar_text = true;
if (estat_actual_ == EstatTitol::PLAYER_JOIN_PHASE) {
// Parpelleig: sin oscil·la entre -1 i 1, volem ON quan > 0
float fase = temps_acumulat_ * BLINK_FREQUENCY * 2.0F * 3.14159F; // 2π × freq × temps
float fase = temps_acumulat_ * BLINK_FREQUENCY * 2.0F * std::numbers::pi_v<float>; // 2π × freq × temps
mostrar_text = (std::sin(fase) > 0.0F);
}
@@ -664,7 +665,7 @@ void EscenaTitol::dibuixar() {
float centre_x = Defaults::Game::WIDTH / 2.0F;
float centre_y = Defaults::Game::HEIGHT * Defaults::Title::Layout::PRESS_START_POS;
text_.render_centered(main_text, {centre_x, centre_y}, escala_main, spacing);
text_.render_centered(main_text, {.x = centre_x, .y = centre_y}, escala_main, spacing);
}
// === Copyright a la part inferior (centrat horitzontalment, dues línies) ===
@@ -695,8 +696,8 @@ void EscenaTitol::dibuixar() {
// Renderitzar línees centrades
float centre_x = Defaults::Game::WIDTH / 2.0F;
text_.render_centered(copyright_original, {centre_x, y_line1}, escala_copy, spacing);
text_.render_centered(copyright_port, {centre_x, y_line2}, escala_copy, spacing);
text_.render_centered(copyright_original, {.x = centre_x, .y = y_line1}, escala_copy, spacing);
text_.render_centered(copyright_port, {.x = centre_x, .y = y_line2}, escala_copy, spacing);
}
}