style: aplicar fixes de clang-tidy (todo excepto uppercase-literal-suffix)

Corregidos ~2570 issues automáticamente con clang-tidy --fix-errors
más ajustes manuales posteriores:

- modernize: designated-initializers, trailing-return-type, use-auto,
  avoid-c-arrays (→ std::array<>), use-ranges, use-emplace,
  deprecated-headers, use-equals-default, pass-by-value,
  return-braced-init-list, use-default-member-init
- readability: math-missing-parentheses, implicit-bool-conversion,
  braces-around-statements, isolate-declaration, use-std-min-max,
  identifier-naming, else-after-return, redundant-casting,
  convert-member-functions-to-static, make-member-function-const,
  static-accessed-through-instance
- performance: avoid-endl, unnecessary-value-param, type-promotion,
  inefficient-vector-operation
- dead code: XOR_KEY (orphan tras eliminar encryptData/decryptData),
  dead stores en engine.cpp y png_shape.cpp
- NOLINT justificado en 10 funciones con alta complejidad cognitiva
  (initialize, render, main, processEvents, update×3, performDemoAction,
  randomizeOnDemoStart, renderDebugHUD, AppLogo::update)

Compilación: gcc -Wall sin warnings. clang-tidy: 0 issues.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-21 10:52:07 +01:00
parent 4801f287df
commit c9bcce6f9b
71 changed files with 3469 additions and 2838 deletions

View File

@@ -1,6 +1,7 @@
#include "help_overlay.hpp"
#include <algorithm> // for std::min
#include <array> // for std::array
#include "defines.hpp"
#include "text/textrenderer.hpp"
@@ -21,69 +22,69 @@ HelpOverlay::HelpOverlay()
column2_width_(0),
column3_width_(0),
cached_texture_(nullptr),
last_category_color_({0, 0, 0, 255}),
last_content_color_({0, 0, 0, 255}),
last_bg_color_({0, 0, 0, 255}),
last_category_color_({.r = 0, .g = 0, .b = 0, .a = 255}),
last_content_color_({.r = 0, .g = 0, .b = 0, .a = 255}),
last_bg_color_({.r = 0, .g = 0, .b = 0, .a = 255}),
texture_needs_rebuild_(true) {
// Llenar lista de controles (organizados por categoría, equilibrado en 3 columnas)
key_bindings_ = {
// COLUMNA 1: SIMULACIÓN
{"SIMULACIÓN", ""},
{"1-8", "Escenarios (10 a 50.000 pelotas)"},
{"F", "Cambia entre figura y física"},
{"B", "Cambia entre boids y física"},
{"ESPACIO", "Impulso contra la gravedad"},
{"G", "Activar / Desactivar gravedad"},
{"CURSORES", "Dirección de la gravedad"},
{"", ""}, // Separador
{.key = "SIMULACIÓN", .description = ""},
{.key = "1-8", .description = "Escenarios (10 a 50.000 pelotas)"},
{.key = "F", .description = "Cambia entre figura y física"},
{.key = "B", .description = "Cambia entre boids y física"},
{.key = "ESPACIO", .description = "Impulso contra la gravedad"},
{.key = "G", .description = "Activar / Desactivar gravedad"},
{.key = "CURSORES", .description = "Dirección de la gravedad"},
{.key = "", .description = ""}, // Separador
// COLUMNA 1: FIGURAS 3D
{"FIGURAS 3D", ""},
{"Q/W/E/R", "Esfera / Lissajous / Hélice / Toroide"},
{"T/Y/U/I", "Cubo / Cilindro / Icosaedro / Átomo"},
{"Num+/-", "Escalar figura"},
{"Num*", "Reset escala"},
{"Num/", "Activar / Desactivar profundidad"},
{"[new_col]", ""}, // CAMBIO DE COLUMNA -> COLUMNA 2
{.key = "FIGURAS 3D", .description = ""},
{.key = "Q/W/E/R", .description = "Esfera / Lissajous / Hélice / Toroide"},
{.key = "T/Y/U/I", .description = "Cubo / Cilindro / Icosaedro / Átomo"},
{.key = "Num+/-", .description = "Escalar figura"},
{.key = "Num*", .description = "Reset escala"},
{.key = "Num/", .description = "Activar / Desactivar profundidad"},
{.key = "[new_col]", .description = ""}, // CAMBIO DE COLUMNA -> COLUMNA 2
// COLUMNA 2: MODOS
{"MODOS", ""},
{"D", "Activar / Desactivar modo demo"},
{"L", "Activar / Desactivar modo demo lite"},
{"K", "Activar / Desactivar modo logo"},
{"", ""}, // Separador
{.key = "MODOS", .description = ""},
{.key = "D", .description = "Activar / Desactivar modo demo"},
{.key = "L", .description = "Activar / Desactivar modo demo lite"},
{.key = "K", .description = "Activar / Desactivar modo logo"},
{.key = "", .description = ""}, // Separador
// COLUMNA 2: VISUAL
{"VISUAL", ""},
{"C", "Tema siguiente"},
{"Shift+C", "Tema anterior"},
{"NumEnter", "Página de temas"},
{"Shift+D", "Pausar tema dinámico"},
{"N", "Cambiar tamaño de pelota"},
{"X", "Ciclar presets PostFX"},
{"[new_col]", ""}, // CAMBIO DE COLUMNA -> COLUMNA 3
{.key = "VISUAL", .description = ""},
{.key = "C", .description = "Tema siguiente"},
{.key = "Shift+C", .description = "Tema anterior"},
{.key = "NumEnter", .description = "Página de temas"},
{.key = "Shift+D", .description = "Pausar tema dinámico"},
{.key = "N", .description = "Cambiar tamaño de pelota"},
{.key = "X", .description = "Ciclar presets PostFX"},
{.key = "[new_col]", .description = ""}, // CAMBIO DE COLUMNA -> COLUMNA 3
// COLUMNA 3: PANTALLA
{"PANTALLA", ""},
{"F1", "Disminuye ventana"},
{"F2", "Aumenta ventana"},
{"F3", "Pantalla completa"},
{"F4", "Pantalla completa real"},
{"F5", "Activar / Desactivar PostFX"},
{"F6", "Cambia el escalado de pantalla"},
{"V", "Activar / Desactivar V-Sync"},
{"", ""}, // Separador
{.key = "PANTALLA", .description = ""},
{.key = "F1", .description = "Disminuye ventana"},
{.key = "F2", .description = "Aumenta ventana"},
{.key = "F3", .description = "Pantalla completa"},
{.key = "F4", .description = "Pantalla completa real"},
{.key = "F5", .description = "Activar / Desactivar PostFX"},
{.key = "F6", .description = "Cambia el escalado de pantalla"},
{.key = "V", .description = "Activar / Desactivar V-Sync"},
{.key = "", .description = ""}, // Separador
// COLUMNA 3: DEBUG/AYUDA
{"DEBUG / AYUDA", ""},
{"F12", "Activar / Desactivar info debug"},
{"H", "Esta ayuda"},
{"ESC", "Salir"}};
{.key = "DEBUG / AYUDA", .description = ""},
{.key = "F12", .description = "Activar / Desactivar info debug"},
{.key = "H", .description = "Esta ayuda"},
{.key = "ESC", .description = "Salir"}};
}
HelpOverlay::~HelpOverlay() {
// Destruir textura cacheada si existe
if (cached_texture_) {
if (cached_texture_ != nullptr) {
SDL_DestroyTexture(cached_texture_);
cached_texture_ = nullptr;
}
@@ -117,7 +118,9 @@ void HelpOverlay::updatePhysicalWindowSize(int physical_width, int physical_heig
}
void HelpOverlay::reinitializeFontSize(int new_font_size) {
if (!text_renderer_) return;
if (text_renderer_ == nullptr) {
return;
}
// Reinicializar text renderer con nuevo tamaño
text_renderer_->reinitialize(new_font_size);
@@ -136,7 +139,7 @@ void HelpOverlay::updateAll(int font_size, int physical_width, int physical_heig
physical_height_ = physical_height;
// Reinicializar text renderer con nuevo tamaño (si cambió)
if (text_renderer_) {
if (text_renderer_ != nullptr) {
text_renderer_->reinitialize(font_size);
}
@@ -148,7 +151,7 @@ void HelpOverlay::updateAll(int font_size, int physical_width, int physical_heig
}
void HelpOverlay::calculateTextDimensions(int& max_width, int& total_height) {
if (!text_renderer_) {
if (text_renderer_ == nullptr) {
max_width = 0;
total_height = 0;
return;
@@ -210,7 +213,7 @@ void HelpOverlay::calculateTextDimensions(int& max_width, int& total_height) {
max_width = max_col1_width + max_col2_width + max_col3_width + padding * 2 + col_gap * 2;
// Calcular altura real simulando exactamente lo que hace el render
int col_heights[3] = {0, 0, 0};
std::array<int, 3> col_heights = {0, 0, 0};
current_column = 0;
for (const auto& binding : key_bindings_) {
@@ -220,11 +223,11 @@ void HelpOverlay::calculateTextDimensions(int& max_width, int& total_height) {
}
if (binding.key[0] == '\0') {
col_heights[current_column] += line_height; // separador vacío
col_heights[current_column] += line_height; // separador vacío
} else if (binding.description[0] == '\0') {
col_heights[current_column] += line_height; // encabezado
col_heights[current_column] += line_height; // encabezado
} else {
col_heights[current_column] += line_height; // línea normal
col_heights[current_column] += line_height; // línea normal
}
}
@@ -240,7 +243,8 @@ void HelpOverlay::calculateTextDimensions(int& max_width, int& total_height) {
void HelpOverlay::calculateBoxDimensions() {
// Calcular dimensiones necesarias según el texto
int text_width, text_height;
int text_width;
int text_height;
calculateTextDimensions(text_width, text_height);
// Aplicar límites máximos: 95% ancho, 90% altura
@@ -253,26 +257,27 @@ void HelpOverlay::calculateBoxDimensions() {
// Centrar en pantalla
box_x_ = (physical_width_ - box_width_) / 2;
box_y_ = (physical_height_ - box_height_) / 2;
}
void HelpOverlay::rebuildCachedTexture() {
if (!renderer_ || !theme_mgr_ || !text_renderer_) return;
if ((renderer_ == nullptr) || (theme_mgr_ == nullptr) || (text_renderer_ == nullptr)) {
return;
}
// Destruir textura anterior si existe
if (cached_texture_) {
if (cached_texture_ != nullptr) {
SDL_DestroyTexture(cached_texture_);
cached_texture_ = nullptr;
}
// Crear nueva textura del tamaño del overlay
cached_texture_ = SDL_CreateTexture(renderer_,
SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_TARGET,
box_width_,
box_height_);
SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_TARGET,
box_width_,
box_height_);
if (!cached_texture_) {
if (cached_texture_ == nullptr) {
SDL_Log("Error al crear textura cacheada: %s", SDL_GetError());
return;
}
@@ -294,42 +299,46 @@ void HelpOverlay::rebuildCachedTexture() {
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
// Obtener colores actuales del tema
int notif_bg_r, notif_bg_g, notif_bg_b;
int notif_bg_r;
int notif_bg_g;
int notif_bg_b;
theme_mgr_->getCurrentNotificationBackgroundColor(notif_bg_r, notif_bg_g, notif_bg_b);
// Renderizar fondo del overlay a la textura
float alpha = 0.85f;
SDL_Vertex bg_vertices[4];
std::array<SDL_Vertex, 4> bg_vertices{};
float r = notif_bg_r / 255.0f;
float g = notif_bg_g / 255.0f;
float b = notif_bg_b / 255.0f;
// Vértices del fondo (posición relativa 0,0 porque estamos renderizando a textura)
bg_vertices[0].position = {0, 0};
bg_vertices[0].tex_coord = {0.0f, 0.0f};
bg_vertices[0].color = {r, g, b, alpha};
bg_vertices[0].position = {.x = 0, .y = 0};
bg_vertices[0].tex_coord = {.x = 0.0f, .y = 0.0f};
bg_vertices[0].color = {.r = r, .g = g, .b = b, .a = alpha};
bg_vertices[1].position = {static_cast<float>(box_width_), 0};
bg_vertices[1].tex_coord = {1.0f, 0.0f};
bg_vertices[1].color = {r, g, b, alpha};
bg_vertices[1].position = {.x = static_cast<float>(box_width_), .y = 0};
bg_vertices[1].tex_coord = {.x = 1.0f, .y = 0.0f};
bg_vertices[1].color = {.r = r, .g = g, .b = b, .a = alpha};
bg_vertices[2].position = {static_cast<float>(box_width_), static_cast<float>(box_height_)};
bg_vertices[2].tex_coord = {1.0f, 1.0f};
bg_vertices[2].color = {r, g, b, alpha};
bg_vertices[2].position = {.x = static_cast<float>(box_width_), .y = static_cast<float>(box_height_)};
bg_vertices[2].tex_coord = {.x = 1.0f, .y = 1.0f};
bg_vertices[2].color = {.r = r, .g = g, .b = b, .a = alpha};
bg_vertices[3].position = {0, static_cast<float>(box_height_)};
bg_vertices[3].tex_coord = {0.0f, 1.0f};
bg_vertices[3].color = {r, g, b, alpha};
bg_vertices[3].position = {.x = 0, .y = static_cast<float>(box_height_)};
bg_vertices[3].tex_coord = {.x = 0.0f, .y = 1.0f};
bg_vertices[3].color = {.r = r, .g = g, .b = b, .a = alpha};
int bg_indices[6] = {0, 1, 2, 2, 3, 0};
SDL_RenderGeometry(renderer_, nullptr, bg_vertices, 4, bg_indices, 6);
std::array<int, 6> bg_indices = {0, 1, 2, 2, 3, 0};
SDL_RenderGeometry(renderer_, nullptr, bg_vertices.data(), 4, bg_indices.data(), 6);
// Renderizar texto del overlay (ajustando coordenadas para que sean relativas a 0,0)
// Necesito renderizar el texto igual que en renderHelpText() pero con coordenadas ajustadas
// Obtener colores para el texto
int text_r, text_g, text_b;
int text_r;
int text_g;
int text_b;
theme_mgr_->getCurrentThemeTextColor(text_r, text_g, text_b);
SDL_Color category_color = {static_cast<Uint8>(text_r), static_cast<Uint8>(text_g), static_cast<Uint8>(text_b), 255};
@@ -339,7 +348,7 @@ void HelpOverlay::rebuildCachedTexture() {
// Guardar colores actuales para comparación futura
last_category_color_ = category_color;
last_content_color_ = content_color;
last_bg_color_ = {static_cast<Uint8>(notif_bg_r), static_cast<Uint8>(notif_bg_g), static_cast<Uint8>(notif_bg_b), 255};
last_bg_color_ = {.r = static_cast<Uint8>(notif_bg_r), .g = static_cast<Uint8>(notif_bg_g), .b = static_cast<Uint8>(notif_bg_b), .a = 255};
// Configuración de espaciado
int line_height = text_renderer_->getTextHeight();
@@ -347,13 +356,13 @@ void HelpOverlay::rebuildCachedTexture() {
int col_gap = padding * 2;
// Posición X de inicio de cada columna
int col_start[3];
std::array<int, 3> col_start{};
col_start[0] = padding;
col_start[1] = padding + column1_width_ + col_gap;
col_start[2] = padding + column1_width_ + col_gap + column2_width_ + col_gap;
// Ancho de cada columna (para centrado interno)
int col_width[3] = {column1_width_, column2_width_, column3_width_};
std::array<int, 3> col_width = {column1_width_, column2_width_, column3_width_};
int glyph_height = text_renderer_->getGlyphHeight();
int current_y = padding;
@@ -387,7 +396,7 @@ void HelpOverlay::rebuildCachedTexture() {
} else {
// Encabezado de sección — centrado en la columna
int w = text_renderer_->getTextWidthPhysical(binding.key);
text_renderer_->printAbsolute(cx + (cw - w) / 2, current_y, binding.key, category_color);
text_renderer_->printAbsolute(cx + ((cw - w) / 2), current_y, binding.key, category_color);
current_y += line_height;
}
continue;
@@ -397,7 +406,7 @@ void HelpOverlay::rebuildCachedTexture() {
int key_width = text_renderer_->getTextWidthPhysical(binding.key);
int desc_width = text_renderer_->getTextWidthPhysical(binding.description);
int total_width = key_width + 10 + desc_width;
int line_x = cx + (cw - total_width) / 2;
int line_x = cx + ((cw - total_width) / 2);
text_renderer_->printAbsolute(line_x, current_y, binding.key, category_color);
text_renderer_->printAbsolute(line_x + key_width + 10, current_y, binding.description, content_color);
@@ -413,13 +422,19 @@ void HelpOverlay::rebuildCachedTexture() {
}
void HelpOverlay::render(SDL_Renderer* renderer) {
if (!visible_) return;
if (!visible_) {
return;
}
// Obtener colores actuales del tema
int notif_bg_r, notif_bg_g, notif_bg_b;
int notif_bg_r;
int notif_bg_g;
int notif_bg_b;
theme_mgr_->getCurrentNotificationBackgroundColor(notif_bg_r, notif_bg_g, notif_bg_b);
int text_r, text_g, text_b;
int text_r;
int text_g;
int text_b;
theme_mgr_->getCurrentThemeTextColor(text_r, text_g, text_b);
Color ball_color = theme_mgr_->getInterpolatedColor(0);
@@ -433,22 +448,24 @@ void HelpOverlay::render(SDL_Renderer* renderer) {
constexpr int COLOR_CHANGE_THRESHOLD = 5;
bool colors_changed =
(abs(current_bg.r - last_bg_color_.r) > COLOR_CHANGE_THRESHOLD ||
abs(current_bg.g - last_bg_color_.g) > COLOR_CHANGE_THRESHOLD ||
abs(current_bg.b - last_bg_color_.b) > COLOR_CHANGE_THRESHOLD ||
abs(current_category.r - last_category_color_.r) > COLOR_CHANGE_THRESHOLD ||
abs(current_category.g - last_category_color_.g) > COLOR_CHANGE_THRESHOLD ||
abs(current_category.b - last_category_color_.b) > COLOR_CHANGE_THRESHOLD ||
abs(current_content.r - last_content_color_.r) > COLOR_CHANGE_THRESHOLD ||
abs(current_content.g - last_content_color_.g) > COLOR_CHANGE_THRESHOLD ||
abs(current_content.b - last_content_color_.b) > COLOR_CHANGE_THRESHOLD);
abs(current_bg.g - last_bg_color_.g) > COLOR_CHANGE_THRESHOLD ||
abs(current_bg.b - last_bg_color_.b) > COLOR_CHANGE_THRESHOLD ||
abs(current_category.r - last_category_color_.r) > COLOR_CHANGE_THRESHOLD ||
abs(current_category.g - last_category_color_.g) > COLOR_CHANGE_THRESHOLD ||
abs(current_category.b - last_category_color_.b) > COLOR_CHANGE_THRESHOLD ||
abs(current_content.r - last_content_color_.r) > COLOR_CHANGE_THRESHOLD ||
abs(current_content.g - last_content_color_.g) > COLOR_CHANGE_THRESHOLD ||
abs(current_content.b - last_content_color_.b) > COLOR_CHANGE_THRESHOLD);
// Regenerar textura si es necesario (colores cambiaron O flag de rebuild activo)
if (texture_needs_rebuild_ || colors_changed || !cached_texture_) {
if (texture_needs_rebuild_ || colors_changed || (cached_texture_ == nullptr)) {
rebuildCachedTexture();
}
// Si no hay textura cacheada (error), salir
if (!cached_texture_) return;
if (cached_texture_ == nullptr) {
return;
}
// CRÍTICO: Habilitar alpha blending para que la transparencia funcione
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
@@ -460,8 +477,8 @@ void HelpOverlay::render(SDL_Renderer* renderer) {
// Calcular posición centrada dentro del VIEWPORT, no de la pantalla física
// viewport.w y viewport.h son las dimensiones del área visible
// viewport.x y viewport.y son el offset de las barras negras
int centered_x = viewport.x + (viewport.w - box_width_) / 2;
int centered_y = viewport.y + (viewport.h - box_height_) / 2;
int centered_x = viewport.x + ((viewport.w - box_width_) / 2);
int centered_y = viewport.y + ((viewport.h - box_height_) / 2);
// Renderizar la textura cacheada centrada en el viewport
SDL_FRect dest_rect;