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:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <numbers>
|
||||
|
||||
namespace Defaults {
|
||||
// Configuración de ventana
|
||||
@@ -232,7 +233,7 @@ constexpr float VELOCITAT_ROT_MAX = 1.5F; // rad/s (~86°/s)
|
||||
|
||||
// Matemáticas
|
||||
namespace Math {
|
||||
constexpr float PI = 3.14159265359F;
|
||||
constexpr float PI = std::numbers::pi_v<float>;
|
||||
} // namespace Math
|
||||
|
||||
// Colores (oscilación para efecto CRT)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
namespace Graphics {
|
||||
|
||||
Shape::Shape(const std::string& filepath)
|
||||
: centre_({0.0F, 0.0F}),
|
||||
: centre_({.x = 0.0F, .y = 0.0F}),
|
||||
escala_defecte_(1.0F),
|
||||
nom_("unnamed") {
|
||||
carregar(filepath);
|
||||
@@ -106,7 +106,7 @@ bool Shape::starts_with(const std::string& str,
|
||||
if (str.length() < prefix.length()) {
|
||||
return false;
|
||||
}
|
||||
return str.compare(0, prefix.length(), prefix) == 0;
|
||||
return str.starts_with(prefix);
|
||||
}
|
||||
|
||||
// Helper: extract value after ':'
|
||||
@@ -128,7 +128,7 @@ void Shape::parse_center(const std::string& value) {
|
||||
centre_.y = std::stof(trim(val.substr(comma + 1)));
|
||||
} catch (...) {
|
||||
std::cerr << "[Shape] Warning: centre invàlid, usant (0,0)" << std::endl;
|
||||
centre_ = {0.0F, 0.0F};
|
||||
centre_ = {.x = 0.0F, .y = 0.0F};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,16 +36,16 @@ class Shape {
|
||||
bool parsejar_fitxer(const std::string& contingut);
|
||||
|
||||
// Getters
|
||||
const std::vector<ShapePrimitive>& get_primitives() const {
|
||||
[[nodiscard]] const std::vector<ShapePrimitive>& get_primitives() const {
|
||||
return primitives_;
|
||||
}
|
||||
const Punt& get_centre() const { return centre_; }
|
||||
float get_escala_defecte() const { return escala_defecte_; }
|
||||
bool es_valida() const { return !primitives_.empty(); }
|
||||
[[nodiscard]] const Punt& get_centre() const { return centre_; }
|
||||
[[nodiscard]] float get_escala_defecte() const { return escala_defecte_; }
|
||||
[[nodiscard]] bool es_valida() const { return !primitives_.empty(); }
|
||||
|
||||
// Info de depuració
|
||||
std::string get_nom() const { return nom_; }
|
||||
size_t get_num_primitives() const { return primitives_.size(); }
|
||||
[[nodiscard]] std::string get_nom() const { return nom_; }
|
||||
[[nodiscard]] size_t get_num_primitives() const { return primitives_.size(); }
|
||||
|
||||
private:
|
||||
std::vector<ShapePrimitive> primitives_;
|
||||
@@ -54,11 +54,11 @@ class Shape {
|
||||
std::string nom_; // Nom de la forma (per depuració)
|
||||
|
||||
// Helpers privats per parsejar
|
||||
std::string trim(const std::string& str) const;
|
||||
bool starts_with(const std::string& str, const std::string& prefix) const;
|
||||
std::string extract_value(const std::string& line) const;
|
||||
[[nodiscard]] std::string trim(const std::string& str) const;
|
||||
[[nodiscard]] bool starts_with(const std::string& str, const std::string& prefix) const;
|
||||
[[nodiscard]] std::string extract_value(const std::string& line) const;
|
||||
void parse_center(const std::string& value);
|
||||
std::vector<Punt> parse_points(const std::string& str) const;
|
||||
[[nodiscard]] std::vector<Punt> parse_points(const std::string& str) const;
|
||||
};
|
||||
|
||||
} // namespace Graphics
|
||||
|
||||
@@ -24,7 +24,7 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
|
||||
// Normalize path: "ship.shp" → "shapes/ship.shp"
|
||||
// "logo/letra_j.shp" → "shapes/logo/letra_j.shp"
|
||||
std::string normalized = filename;
|
||||
if (normalized.find("shapes/") != 0) {
|
||||
if (!normalized.starts_with("shapes/")) {
|
||||
// Doesn't start with "shapes/", so add it
|
||||
normalized = "shapes/" + normalized;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ std::string ShapeLoader::resolve_path(const std::string& filename) {
|
||||
}
|
||||
|
||||
// Si ja conté el prefix base_path, usar-lo directament
|
||||
if (filename.find(base_path_) == 0) {
|
||||
if (filename.starts_with(base_path_)) {
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,13 +57,13 @@ class Starfield {
|
||||
void inicialitzar_estrella(Estrella& estrella) const;
|
||||
|
||||
// Verificar si una estrella està fora de l'àrea
|
||||
bool fora_area(const Estrella& estrella) const;
|
||||
[[nodiscard]] bool fora_area(const Estrella& estrella) const;
|
||||
|
||||
// Calcular escala dinàmica segons distància del centre
|
||||
float calcular_escala(const Estrella& estrella) const;
|
||||
[[nodiscard]] float calcular_escala(const Estrella& estrella) const;
|
||||
|
||||
// Calcular brightness dinàmica segons distància del centre
|
||||
float calcular_brightness(const Estrella& estrella) const;
|
||||
[[nodiscard]] float calcular_brightness(const Estrella& estrella) const;
|
||||
|
||||
// Dades
|
||||
std::vector<Estrella> estrelles_;
|
||||
|
||||
@@ -201,7 +201,7 @@ void VectorText::render(const std::string& text, const Punt& posicio, float esca
|
||||
|
||||
// Iterar sobre cada byte del string (con detecció UTF-8)
|
||||
for (size_t i = 0; i < text.length(); i++) {
|
||||
unsigned char c = static_cast<unsigned char>(text[i]);
|
||||
auto c = static_cast<unsigned char>(text[i]);
|
||||
|
||||
// Detectar copyright UTF-8 (0xC2 0xA9)
|
||||
if (c == 0xC2 && i + 1 < text.length() &&
|
||||
@@ -222,7 +222,7 @@ void VectorText::render(const std::string& text, const Punt& posicio, float esca
|
||||
// Renderizar carácter
|
||||
// Ajustar X e Y para que posicio represente esquina superior izquierda
|
||||
// (render_shape espera el centro, así que sumamos la mitad de ancho y altura)
|
||||
Punt char_pos = {current_x + (char_width_scaled / 2.0F), posicio.y + (char_height_scaled / 2.0F)};
|
||||
Punt char_pos = {.x = current_x + (char_width_scaled / 2.0F), .y = posicio.y + (char_height_scaled / 2.0F)};
|
||||
Rendering::render_shape(renderer_, it->second, char_pos, 0.0F, escala, true, 1.0F, brightness);
|
||||
|
||||
// Avanzar posición
|
||||
@@ -244,8 +244,8 @@ void VectorText::render_centered(const std::string& text, const Punt& centre_pun
|
||||
// Calcular posició de l'esquina superior esquerra
|
||||
// restant la meitat de les dimensions del punt central
|
||||
Punt posicio_esquerra = {
|
||||
centre_punt.x - (text_width / 2.0F),
|
||||
centre_punt.y - (text_height / 2.0F)};
|
||||
.x = centre_punt.x - (text_width / 2.0F),
|
||||
.y = centre_punt.y - (text_height / 2.0F)};
|
||||
|
||||
// Delegar al mètode render() existent
|
||||
render(text, posicio_esquerra, escala, spacing, brightness);
|
||||
@@ -262,7 +262,7 @@ float VectorText::get_text_width(const std::string& text, float escala, float sp
|
||||
// Contar caracteres visuals (no bytes) - manejar UTF-8
|
||||
size_t visual_chars = 0;
|
||||
for (size_t i = 0; i < text.length(); i++) {
|
||||
unsigned char c = static_cast<unsigned char>(text[i]);
|
||||
auto c = static_cast<unsigned char>(text[i]);
|
||||
|
||||
// Detectar copyright UTF-8 (0xC2 0xA9) - igual que render()
|
||||
if (c == 0xC2 && i + 1 < text.length() &&
|
||||
|
||||
@@ -36,20 +36,20 @@ class VectorText {
|
||||
void render_centered(const std::string& text, const Punt& centre_punt, float escala = 1.0F, float spacing = 2.0F, float brightness = 1.0F);
|
||||
|
||||
// Calcular ancho total de un string (útil para centrado)
|
||||
float get_text_width(const std::string& text, float escala = 1.0F, float spacing = 2.0F) const;
|
||||
[[nodiscard]] float get_text_width(const std::string& text, float escala = 1.0F, float spacing = 2.0F) const;
|
||||
|
||||
// Calcular altura del texto (útil para centrado vertical)
|
||||
float get_text_height(float escala = 1.0F) const;
|
||||
[[nodiscard]] float get_text_height(float escala = 1.0F) const;
|
||||
|
||||
// Verificar si un carácter está soportado
|
||||
bool is_supported(char c) const;
|
||||
[[nodiscard]] bool is_supported(char c) const;
|
||||
|
||||
private:
|
||||
SDL_Renderer* renderer_;
|
||||
std::unordered_map<char, std::shared_ptr<Shape>> chars_;
|
||||
|
||||
void load_charset();
|
||||
std::string get_shape_filename(char c) const;
|
||||
[[nodiscard]] std::string get_shape_filename(char c) const;
|
||||
};
|
||||
|
||||
} // namespace Graphics
|
||||
|
||||
@@ -115,12 +115,12 @@ class Input {
|
||||
// --- Gestión de gamepads ---
|
||||
[[nodiscard]] auto gameControllerFound() const -> bool;
|
||||
[[nodiscard]] auto getNumGamepads() const -> int;
|
||||
auto getGamepad(SDL_JoystickID id) const -> std::shared_ptr<Gamepad>;
|
||||
auto getGamepadByName(const std::string& name) const -> std::shared_ptr<Input::Gamepad>;
|
||||
auto getGamepads() const -> const Gamepads& { return gamepads_; }
|
||||
[[nodiscard]] auto getGamepad(SDL_JoystickID id) const -> std::shared_ptr<Gamepad>;
|
||||
[[nodiscard]] auto getGamepadByName(const std::string& name) const -> std::shared_ptr<Input::Gamepad>;
|
||||
[[nodiscard]] auto getGamepads() const -> const Gamepads& { return gamepads_; }
|
||||
auto findAvailableGamepadByName(const std::string& gamepad_name) -> std::shared_ptr<Gamepad>;
|
||||
static auto getControllerName(const std::shared_ptr<Gamepad>& gamepad) -> std::string;
|
||||
auto getControllerNames() const -> std::vector<std::string>;
|
||||
[[nodiscard]] auto getControllerNames() const -> std::vector<std::string>;
|
||||
[[nodiscard]] static auto getControllerBinding(const std::shared_ptr<Gamepad>& gamepad, Action action) -> SDL_GamepadButton;
|
||||
void printConnectedGamepads() const;
|
||||
|
||||
|
||||
@@ -12,14 +12,14 @@ namespace Rendering {
|
||||
ColorOscillator::ColorOscillator()
|
||||
: accumulated_time_(0.0F) {
|
||||
// Inicialitzar amb el color mínim
|
||||
current_line_color_ = {Defaults::Color::LINE_MIN_R,
|
||||
Defaults::Color::LINE_MIN_G,
|
||||
Defaults::Color::LINE_MIN_B,
|
||||
255};
|
||||
current_background_color_ = {Defaults::Color::BACKGROUND_MIN_R,
|
||||
Defaults::Color::BACKGROUND_MIN_G,
|
||||
Defaults::Color::BACKGROUND_MIN_B,
|
||||
255};
|
||||
current_line_color_ = {.r = Defaults::Color::LINE_MIN_R,
|
||||
.g = Defaults::Color::LINE_MIN_G,
|
||||
.b = Defaults::Color::LINE_MIN_B,
|
||||
.a = 255};
|
||||
current_background_color_ = {.r = Defaults::Color::BACKGROUND_MIN_R,
|
||||
.g = Defaults::Color::BACKGROUND_MIN_G,
|
||||
.b = Defaults::Color::BACKGROUND_MIN_B,
|
||||
.a = 255};
|
||||
}
|
||||
|
||||
void ColorOscillator::update(float delta_time) {
|
||||
|
||||
@@ -12,8 +12,8 @@ class ColorOscillator {
|
||||
|
||||
void update(float delta_time);
|
||||
|
||||
SDL_Color getCurrentLineColor() const { return current_line_color_; }
|
||||
SDL_Color getCurrentBackgroundColor() const {
|
||||
[[nodiscard]] SDL_Color getCurrentLineColor() const { return current_line_color_; }
|
||||
[[nodiscard]] SDL_Color getCurrentBackgroundColor() const {
|
||||
return current_background_color_;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class SDLManager {
|
||||
|
||||
// Getters
|
||||
SDL_Renderer* obte_renderer() { return renderer_; }
|
||||
float getScaleFactor() const { return zoom_factor_; }
|
||||
[[nodiscard]] float getScaleFactor() const { return zoom_factor_; }
|
||||
|
||||
// [NUEVO] Actualitzar títol de la finestra
|
||||
void setWindowTitle(const std::string& title);
|
||||
|
||||
@@ -38,7 +38,7 @@ static Punt apply_3d_rotation(float x, float y, const Rotation3D& rot) {
|
||||
constexpr float perspective_factor = 500.0F;
|
||||
float scale_factor = perspective_factor / (perspective_factor + z2);
|
||||
|
||||
return {x3 * scale_factor, y3 * scale_factor};
|
||||
return {.x = x3 * scale_factor, .y = y3 * scale_factor};
|
||||
}
|
||||
|
||||
// Helper: transformar un punt amb rotació, escala i trasllació
|
||||
@@ -69,7 +69,7 @@ static Punt transform_point(const Punt& point, const Punt& shape_centre, const P
|
||||
float rotated_y = (scaled_x * sin_a) + (scaled_y * cos_a);
|
||||
|
||||
// 5. Aplicar trasllació a posició mundial
|
||||
return {rotated_x + posicio.x, rotated_y + posicio.y};
|
||||
return {.x = rotated_x + posicio.x, .y = rotated_y + posicio.y};
|
||||
}
|
||||
|
||||
void render_shape(SDL_Renderer* renderer,
|
||||
|
||||
@@ -27,7 +27,7 @@ struct Rotation3D {
|
||||
yaw(y),
|
||||
roll(r) {}
|
||||
|
||||
bool has_rotation() const {
|
||||
[[nodiscard]] bool has_rotation() const {
|
||||
return pitch != 0.0F || yaw != 0.0F || roll != 0.0F;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
|
||||
#include "resource_loader.hpp"
|
||||
|
||||
namespace Resource {
|
||||
namespace Helper {
|
||||
namespace Resource::Helper {
|
||||
|
||||
// Inicialitzar el sistema de recursos
|
||||
bool initializeResourceSystem(const std::string& pack_file, bool fallback) {
|
||||
@@ -79,5 +78,4 @@ bool isPackLoaded() {
|
||||
return Loader::get().isPackLoaded();
|
||||
}
|
||||
|
||||
} // namespace Helper
|
||||
} // namespace Resource
|
||||
} // namespace Resource::Helper
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Resource {
|
||||
namespace Helper {
|
||||
namespace Resource::Helper {
|
||||
|
||||
// Inicialització del sistema
|
||||
bool initializeResourceSystem(const std::string& pack_file, bool fallback);
|
||||
@@ -24,5 +23,4 @@ std::string normalizePath(const std::string& path);
|
||||
// Estat
|
||||
bool isPackLoaded();
|
||||
|
||||
} // namespace Helper
|
||||
} // namespace Resource
|
||||
} // namespace Resource::Helper
|
||||
|
||||
@@ -27,20 +27,20 @@ class Loader {
|
||||
|
||||
// Validació
|
||||
bool validatePack();
|
||||
bool isPackLoaded() const;
|
||||
[[nodiscard]] bool isPackLoaded() const;
|
||||
|
||||
// Estat
|
||||
void setBasePath(const std::string& path);
|
||||
std::string getBasePath() const;
|
||||
|
||||
private:
|
||||
Loader() = default;
|
||||
~Loader() = default;
|
||||
[[nodiscard]] std::string getBasePath() const;
|
||||
|
||||
// No es pot copiar ni moure
|
||||
Loader(const Loader&) = delete;
|
||||
Loader& operator=(const Loader&) = delete;
|
||||
|
||||
private:
|
||||
Loader() = default;
|
||||
~Loader() = default;
|
||||
|
||||
// Dades
|
||||
std::unique_ptr<Pack> pack_;
|
||||
bool fallback_enabled_ = false;
|
||||
|
||||
@@ -41,11 +41,11 @@ class Pack {
|
||||
|
||||
// Accés a recursos
|
||||
std::vector<uint8_t> getResource(const std::string& filename);
|
||||
bool hasResource(const std::string& filename) const;
|
||||
std::vector<std::string> getResourceList() const;
|
||||
[[nodiscard]] bool hasResource(const std::string& filename) const;
|
||||
[[nodiscard]] std::vector<std::string> getResourceList() const;
|
||||
|
||||
// Validació
|
||||
bool validatePack() const;
|
||||
[[nodiscard]] bool validatePack() const;
|
||||
|
||||
private:
|
||||
// Constants
|
||||
@@ -59,7 +59,7 @@ class Pack {
|
||||
|
||||
// Funcions auxiliars
|
||||
std::vector<uint8_t> readFile(const std::string& filepath);
|
||||
uint32_t calculateChecksum(const std::vector<uint8_t>& data) const;
|
||||
[[nodiscard]] uint32_t calculateChecksum(const std::vector<uint8_t>& data) const;
|
||||
void encryptData(std::vector<uint8_t>& data, const std::string& key);
|
||||
void decryptData(std::vector<uint8_t>& data, const std::string& key);
|
||||
};
|
||||
|
||||
@@ -27,9 +27,7 @@ class ContextEscenes {
|
||||
};
|
||||
|
||||
// Constructor inicial amb escena LOGO i sense opcions
|
||||
ContextEscenes()
|
||||
: escena_desti_(Escena::LOGO),
|
||||
opcio_(Opcio::NONE) {}
|
||||
ContextEscenes() = default;
|
||||
|
||||
// Canviar escena amb opció específica
|
||||
void canviar_escena(Escena nova_escena, Opcio opcio = Opcio::NONE) {
|
||||
@@ -71,8 +69,8 @@ class ContextEscenes {
|
||||
}
|
||||
|
||||
private:
|
||||
Escena escena_desti_; // Escena a la qual transicionar
|
||||
Opcio opcio_; // Opció específica per l'escena
|
||||
Escena escena_desti_{Escena::LOGO}; // Escena a la qual transicionar
|
||||
Opcio opcio_{Opcio::NONE}; // Opció específica per l'escena
|
||||
GameConfig::ConfigPartida config_partida_; // Configuració de partida (jugadors actius, mode)
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user