Lint: clang-tidy --fix mecánico (trailing return, default member init, auto, enum size)
Pase automático de clang-tidy --fix sobre el conjunto de checks que son puro transform de sintaxis y no rompen API. Invocado con --format-style=none para que clang-tidy NO arrastre clang-format sobre las líneas tocadas (evita la regla NamespaceIndentation: All del .clang-format reformateando solo trozos del archivo). Checks aplicados: - modernize-use-trailing-return-type (193 hits): 'int foo()' → 'auto foo() -> int'. Estilo coherente con la convención del proyecto. - modernize-use-default-member-init (36 hits): inicialización de miembros pasa de la lista del constructor a la declaración. Reduce duplicación cuando hay varios constructores con los mismos defaults. - modernize-use-auto (6 hits): tipos largos sustituidos por auto donde el tipo es evidente del contexto (new T, dynamic_cast, etc). - modernize-use-starts-ends-with (2 hits): s.rfind(x) == 0 → s.starts_with(x), aprovechando C++20. - performance-enum-size (10 hits): enums pequeños declaran tipo subyacente (uint8_t / similar) para reducir tamaño y precisar layout. NO aplicado en este pase (riesgo de cambios semánticos o de API): - readability-identifier-naming (renames pueden romper callsites parciales) - readability-convert-member-functions-to-static (cambia firma) - readability-use-anyofallof (reescribe loops, side effects) - readability-function-cognitive-complexity (requiere refactor manual) - bugs reales (bugprone-*, clang-diagnostic-*) → uno a uno Cambios manuales asociados: - SDLManager::clear() ahora devuelve bool: propaga el resultado de beginFrame al caller para que Director::runFrameLoop salte draw+present cuando la swapchain no esté disponible (ventana minimizada). Antes la función ignoraba el [[nodiscard]] del beginFrame y los vértices se acumulaban en el batch sin nadie que los consumiera. - vector_text.cpp: borrada la línea suelta "// Test pre-commit hook" que quedó como cruft. clang-tidy crashea en LLVM 19.1 con performance-noexcept-move-constructor (recursión infinita en ExceptionSpecAnalyzer al procesar std::set); check deshabilitado en .clang-tidy con comentario explicativo. Build limpio, smoke test OK. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -12,12 +12,12 @@ namespace Graphics {
|
||||
|
||||
Shape::Shape(const std::string& filepath)
|
||||
: center_({.x = 0.0F, .y = 0.0F}),
|
||||
escala_defecte_(1.0F),
|
||||
|
||||
nom_("unnamed") {
|
||||
load(filepath);
|
||||
}
|
||||
|
||||
bool Shape::load(const std::string& filepath) {
|
||||
auto Shape::load(const std::string& filepath) -> bool {
|
||||
// Llegir file
|
||||
std::ifstream file(filepath);
|
||||
if (!file.is_open()) {
|
||||
@@ -35,7 +35,7 @@ bool Shape::load(const std::string& filepath) {
|
||||
return parseFile(contingut);
|
||||
}
|
||||
|
||||
bool Shape::parseFile(const std::string& contingut) {
|
||||
auto Shape::parseFile(const std::string& contingut) -> bool {
|
||||
std::istringstream iss(contingut);
|
||||
std::string line;
|
||||
|
||||
@@ -89,7 +89,7 @@ bool Shape::parseFile(const std::string& contingut) {
|
||||
}
|
||||
|
||||
// Helper: trim whitespace
|
||||
std::string Shape::trim(const std::string& str) const {
|
||||
auto Shape::trim(const std::string& str) const -> std::string {
|
||||
const char* whitespace = " \t\n\r";
|
||||
size_t start = str.find_first_not_of(whitespace);
|
||||
if (start == std::string::npos) {
|
||||
@@ -101,8 +101,8 @@ std::string Shape::trim(const std::string& str) const {
|
||||
}
|
||||
|
||||
// Helper: starts_with
|
||||
bool Shape::starts_with(const std::string& str,
|
||||
const std::string& prefix) const {
|
||||
auto Shape::starts_with(const std::string& str,
|
||||
const std::string& prefix) const -> bool {
|
||||
if (str.length() < prefix.length()) {
|
||||
return false;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ bool Shape::starts_with(const std::string& str,
|
||||
}
|
||||
|
||||
// Helper: extract value after ':'
|
||||
std::string Shape::extract_value(const std::string& line) const {
|
||||
auto Shape::extract_value(const std::string& line) const -> std::string {
|
||||
size_t colon = line.find(':');
|
||||
if (colon == std::string::npos) {
|
||||
return "";
|
||||
@@ -134,7 +134,7 @@ void Shape::parse_center(const std::string& value) {
|
||||
}
|
||||
|
||||
// Helper: parse points "x1,y1 x2,y2 x3,y3"
|
||||
std::vector<Vec2> Shape::parse_points(const std::string& str) const {
|
||||
auto Shape::parse_points(const std::string& str) const -> std::vector<Vec2> {
|
||||
std::vector<Vec2> points;
|
||||
std::istringstream iss(trim(str));
|
||||
std::string pair;
|
||||
|
||||
@@ -30,18 +30,18 @@ class Shape {
|
||||
explicit Shape(const std::string& filepath);
|
||||
|
||||
// Carregar shape desde file .shp
|
||||
bool load(const std::string& filepath);
|
||||
auto load(const std::string& filepath) -> bool;
|
||||
|
||||
// Parsejar shape desde buffer de memòria (per al sistema de recursos)
|
||||
bool parseFile(const std::string& contingut);
|
||||
auto parseFile(const std::string& contingut) -> bool;
|
||||
|
||||
// Getters
|
||||
[[nodiscard]] const std::vector<ShapePrimitive>& get_primitives() const {
|
||||
[[nodiscard]] auto get_primitives() const -> const std::vector<ShapePrimitive>& {
|
||||
return primitives_;
|
||||
}
|
||||
[[nodiscard]] const Vec2& getCenter() const { return center_; }
|
||||
[[nodiscard]] float get_escala_defecte() const { return escala_defecte_; }
|
||||
[[nodiscard]] bool isValid() const { return !primitives_.empty(); }
|
||||
[[nodiscard]] auto getCenter() const -> const Vec2& { return center_; }
|
||||
[[nodiscard]] auto get_escala_defecte() const -> float { return escala_defecte_; }
|
||||
[[nodiscard]] auto isValid() const -> bool { return !primitives_.empty(); }
|
||||
|
||||
// Info de depuració
|
||||
[[nodiscard]] auto getName() const -> const std::string& { return nom_; }
|
||||
@@ -55,11 +55,11 @@ class Shape {
|
||||
std::string nom_; // Nom de la shape (per depuració)
|
||||
|
||||
// Helpers privats per parsejar
|
||||
[[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;
|
||||
[[nodiscard]] auto trim(const std::string& str) const -> std::string;
|
||||
[[nodiscard]] auto starts_with(const std::string& str, const std::string& prefix) const -> bool;
|
||||
[[nodiscard]] auto extract_value(const std::string& line) const -> std::string;
|
||||
void parse_center(const std::string& value);
|
||||
[[nodiscard]] std::vector<Vec2> parse_points(const std::string& str) const;
|
||||
[[nodiscard]] auto parse_points(const std::string& str) const -> std::vector<Vec2>;
|
||||
};
|
||||
|
||||
} // namespace Graphics
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Graphics {
|
||||
std::unordered_map<std::string, std::shared_ptr<Shape>> ShapeLoader::cache_;
|
||||
std::string ShapeLoader::base_path_ = "data/shapes/";
|
||||
|
||||
std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
|
||||
auto ShapeLoader::load(const std::string& filename) -> std::shared_ptr<Shape> {
|
||||
// Check cache first
|
||||
auto it = cache_.find(filename);
|
||||
if (it != cache_.end()) {
|
||||
@@ -66,9 +66,9 @@ void ShapeLoader::clear_cache() {
|
||||
cache_.clear();
|
||||
}
|
||||
|
||||
size_t ShapeLoader::get_cache_size() { return cache_.size(); }
|
||||
auto ShapeLoader::get_cache_size() -> size_t { return cache_.size(); }
|
||||
|
||||
std::string ShapeLoader::resolve_path(const std::string& filename) {
|
||||
auto ShapeLoader::resolve_path(const std::string& filename) -> std::string {
|
||||
// Si es un path absolut (comença con '/'), usar-lo directament
|
||||
if (!filename.empty() && filename[0] == '/') {
|
||||
return filename;
|
||||
|
||||
@@ -20,20 +20,20 @@ class ShapeLoader {
|
||||
// Carregar shape desde file (con caché)
|
||||
// Retorna punter compartit (nullptr si error)
|
||||
// Exemple: load("ship.shp") → busca a "data/shapes/ship.shp"
|
||||
static std::shared_ptr<Shape> load(const std::string& filename);
|
||||
static auto load(const std::string& filename) -> std::shared_ptr<Shape>;
|
||||
|
||||
// Netejar caché (útil per debug/recàrrega)
|
||||
static void clear_cache();
|
||||
|
||||
// Estadístiques (debug)
|
||||
static size_t get_cache_size();
|
||||
static auto get_cache_size() -> size_t;
|
||||
|
||||
private:
|
||||
static std::unordered_map<std::string, std::shared_ptr<Shape>> cache_;
|
||||
static std::string base_path_; // "data/shapes/"
|
||||
|
||||
// Helpers privats
|
||||
static std::string resolve_path(const std::string& filename);
|
||||
static auto resolve_path(const std::string& filename) -> std::string;
|
||||
};
|
||||
|
||||
} // namespace Graphics
|
||||
|
||||
@@ -81,7 +81,7 @@ void Starfield::inicialitzar_estrella(Estrella& estrella) const {
|
||||
}
|
||||
|
||||
// Verificar si una estrella está fuera de l'àrea
|
||||
bool Starfield::fora_area(const Estrella& estrella) const {
|
||||
auto Starfield::fora_area(const Estrella& estrella) const -> bool {
|
||||
return (estrella.position.x < area_.x ||
|
||||
estrella.position.x > area_.x + area_.w ||
|
||||
estrella.position.y < area_.y ||
|
||||
@@ -89,7 +89,7 @@ bool Starfield::fora_area(const Estrella& estrella) const {
|
||||
}
|
||||
|
||||
// Calcular scale dinàmica segons distancia del centro
|
||||
float Starfield::calcular_escala(const Estrella& estrella) const {
|
||||
auto Starfield::calcular_escala(const Estrella& estrella) const -> float {
|
||||
const CapaConfig& capa = capes_[estrella.capa];
|
||||
|
||||
// Interpolació lineal basada en distancia del centro
|
||||
@@ -99,7 +99,7 @@ float Starfield::calcular_escala(const Estrella& estrella) const {
|
||||
}
|
||||
|
||||
// Calcular brightness dinàmica segons distancia del centro
|
||||
float Starfield::calcular_brightness(const Estrella& estrella) const {
|
||||
auto Starfield::calcular_brightness(const Estrella& estrella) const -> float {
|
||||
// Interpolació lineal: estrelles properes (vora) més brillants
|
||||
// distancia_centre: 0.0 (centro, llunyanes) → 1.0 (vora, properes)
|
||||
float brightness_base = Defaults::Brightness::STARFIELD_MIN +
|
||||
|
||||
@@ -59,13 +59,13 @@ class Starfield {
|
||||
void inicialitzar_estrella(Estrella& estrella) const;
|
||||
|
||||
// Verificar si una estrella está fuera de l'àrea
|
||||
[[nodiscard]] bool fora_area(const Estrella& estrella) const;
|
||||
[[nodiscard]] auto fora_area(const Estrella& estrella) const -> bool;
|
||||
|
||||
// Calcular scale dinàmica segons distancia del centro
|
||||
[[nodiscard]] float calcular_escala(const Estrella& estrella) const;
|
||||
[[nodiscard]] auto calcular_escala(const Estrella& estrella) const -> float;
|
||||
|
||||
// Calcular brightness dinàmica segons distancia del centro
|
||||
[[nodiscard]] float calcular_brightness(const Estrella& estrella) const;
|
||||
[[nodiscard]] auto calcular_brightness(const Estrella& estrella) const -> float;
|
||||
|
||||
// Dades
|
||||
std::vector<Estrella> estrelles_;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// vector_text.cpp - Implementació del sistema de text vectorial
|
||||
// © 2026 JailDesigner
|
||||
// Test pre-commit hook
|
||||
|
||||
#include "core/graphics/vector_text.hpp"
|
||||
|
||||
@@ -80,7 +79,7 @@ void VectorText::load_charset() {
|
||||
<< '\n';
|
||||
}
|
||||
|
||||
std::string VectorText::get_shape_filename(char c) const {
|
||||
auto VectorText::get_shape_filename(char c) const -> std::string {
|
||||
// Mapeo carácter → nombre de archivo (con prefix "font/")
|
||||
switch (c) {
|
||||
case '0':
|
||||
@@ -177,7 +176,7 @@ std::string VectorText::get_shape_filename(char c) const {
|
||||
}
|
||||
}
|
||||
|
||||
bool VectorText::is_supported(char c) const {
|
||||
auto VectorText::is_supported(char c) const -> bool {
|
||||
return chars_.contains(c);
|
||||
}
|
||||
|
||||
@@ -251,7 +250,7 @@ void VectorText::renderCentered(const std::string& text, const Vec2& centre_punt
|
||||
render(text, posicio_esquerra, scale, spacing, brightness);
|
||||
}
|
||||
|
||||
float VectorText::get_text_width(const std::string& text, float scale, float spacing) const {
|
||||
auto VectorText::get_text_width(const std::string& text, float scale, float spacing) const -> float {
|
||||
if (text.empty()) {
|
||||
return 0.0F;
|
||||
}
|
||||
@@ -278,7 +277,7 @@ float VectorText::get_text_width(const std::string& text, float scale, float spa
|
||||
return (visual_chars * char_width_scaled) + ((visual_chars - 1) * spacing_scaled);
|
||||
}
|
||||
|
||||
float VectorText::get_text_height(float scale) const {
|
||||
auto VectorText::get_text_height(float scale) const -> float {
|
||||
return char_height * scale;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,20 +38,20 @@ class VectorText {
|
||||
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]] float get_text_width(const std::string& text, float scale = 1.0F, float spacing = 2.0F) const;
|
||||
[[nodiscard]] auto get_text_width(const std::string& text, float scale = 1.0F, float spacing = 2.0F) const -> float;
|
||||
|
||||
// Calcular altura del texto (útil para centrado vertical)
|
||||
[[nodiscard]] float get_text_height(float scale = 1.0F) const;
|
||||
[[nodiscard]] auto get_text_height(float scale = 1.0F) const -> float;
|
||||
|
||||
// Verificar si un carácter está soportado
|
||||
[[nodiscard]] bool is_supported(char c) const;
|
||||
[[nodiscard]] auto is_supported(char c) const -> bool;
|
||||
|
||||
private:
|
||||
Rendering::Renderer* renderer_;
|
||||
std::unordered_map<char, std::shared_ptr<Shape>> chars_;
|
||||
|
||||
void load_charset();
|
||||
[[nodiscard]] std::string get_shape_filename(char c) const;
|
||||
[[nodiscard]] auto get_shape_filename(char c) const -> std::string;
|
||||
};
|
||||
|
||||
} // namespace Graphics
|
||||
|
||||
Reference in New Issue
Block a user