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,30 +1,31 @@
#include "ball.hpp"
#include <stdlib.h> // for rand
#include <cmath> // for fabs
#include <algorithm>
#include <cmath> // for fabs
#include <cstdlib> // for rand
#include <utility>
#include "defines.hpp" // for Color, SCREEN_HEIGHT, GRAVITY_FORCE
class Texture;
// Función auxiliar para generar pérdida aleatoria en rebotes
float generateBounceVariation() {
auto generateBounceVariation() -> float {
// Genera un valor entre 0 y BOUNCE_RANDOM_LOSS_PERCENT (solo pérdida adicional)
float loss = (rand() % 1000) / 1000.0f * BOUNCE_RANDOM_LOSS_PERCENT;
return 1.0f - loss; // Retorna multiplicador (ej: 0.90 - 1.00 para 10% max pérdida)
}
// Función auxiliar para generar pérdida lateral aleatoria
float generateLateralLoss() {
auto generateLateralLoss() -> float {
// Genera un valor entre 0 y LATERAL_LOSS_PERCENT
float loss = (rand() % 1000) / 1000.0f * LATERAL_LOSS_PERCENT;
return 1.0f - loss; // Retorna multiplicador (ej: 0.98 - 1.0 para 0-2% pérdida)
}
// Constructor
Ball::Ball(float x, float y, float vx, float vy, Color color, std::shared_ptr<Texture> texture, int screen_width, int screen_height, int ball_size, GravityDirection gravity_dir, float mass_factor)
Ball::Ball(float x, float y, float vx, float vy, Color color, const std::shared_ptr<Texture>& texture, int screen_width, int screen_height, int ball_size, GravityDirection gravity_dir, float mass_factor)
: sprite_(std::make_unique<Sprite>(texture)),
pos_({x, y, static_cast<float>(ball_size), static_cast<float>(ball_size)}) {
pos_({.x = x, .y = y, .w = static_cast<float>(ball_size), .h = static_cast<float>(ball_size)}) {
// Convertir velocidades de píxeles/frame a píxeles/segundo (multiplicar por 60)
vx_ = vx * 60.0f;
vy_ = vy * 60.0f;
@@ -36,7 +37,7 @@ Ball::Ball(float x, float y, float vx, float vy, Color color, std::shared_ptr<Te
gravity_force_ = GRAVITY_FORCE * 60.0f * 60.0f;
gravity_mass_factor_ = mass_factor; // Factor de masa individual para esta pelota
gravity_direction_ = gravity_dir;
screen_width_ = screen_width; // Dimensiones del terreno de juego
screen_width_ = screen_width; // Dimensiones del terreno de juego
screen_height_ = screen_height;
on_surface_ = false;
// Coeficiente base IGUAL para todas las pelotas (solo variación por rebote individual)
@@ -54,11 +55,11 @@ Ball::Ball(float x, float y, float vx, float vy, Color color, std::shared_ptr<Te
}
// Actualiza la lógica de la clase
void Ball::update(float deltaTime) {
void Ball::update(float delta_time) { // NOLINT(readability-function-cognitive-complexity)
// Aplica la gravedad según la dirección (píxeles/segundo²)
if (!on_surface_) {
// Aplicar gravedad multiplicada por factor de masa individual
float effective_gravity = gravity_force_ * gravity_mass_factor_ * deltaTime;
float effective_gravity = gravity_force_ * gravity_mass_factor_ * delta_time;
switch (gravity_direction_) {
case GravityDirection::DOWN:
vy_ += effective_gravity;
@@ -77,26 +78,26 @@ void Ball::update(float deltaTime) {
// Actualiza la posición en función de la velocidad (píxeles/segundo)
if (!on_surface_) {
pos_.x += vx_ * deltaTime;
pos_.y += vy_ * deltaTime;
pos_.x += vx_ * delta_time;
pos_.y += vy_ * delta_time;
} else {
// Si está en superficie, mantener posición según dirección de gravedad
switch (gravity_direction_) {
case GravityDirection::DOWN:
pos_.y = screen_height_ - pos_.h;
pos_.x += vx_ * deltaTime; // Seguir moviéndose en X
pos_.x += vx_ * delta_time; // Seguir moviéndose en X
break;
case GravityDirection::UP:
pos_.y = 0;
pos_.x += vx_ * deltaTime; // Seguir moviéndose en X
pos_.x += vx_ * delta_time; // Seguir moviéndose en X
break;
case GravityDirection::LEFT:
pos_.x = 0;
pos_.y += vy_ * deltaTime; // Seguir moviéndose en Y
pos_.y += vy_ * delta_time; // Seguir moviéndose en Y
break;
case GravityDirection::RIGHT:
pos_.x = screen_width_ - pos_.w;
pos_.y += vy_ * deltaTime; // Seguir moviéndose en Y
pos_.y += vy_ * delta_time; // Seguir moviéndose en Y
break;
}
}
@@ -176,7 +177,7 @@ void Ball::update(float deltaTime) {
// Aplica rozamiento al estar en superficie
if (on_surface_) {
// Convertir rozamiento de frame-based a time-based
float friction_factor = pow(0.97f, 60.0f * deltaTime);
float friction_factor = std::pow(0.97f, 60.0f * delta_time);
switch (gravity_direction_) {
case GravityDirection::DOWN:
@@ -246,7 +247,7 @@ void Ball::setGravityDirection(GravityDirection direction) {
// Aplica un pequeño empuje lateral aleatorio
void Ball::applyRandomLateralPush() {
// Generar velocidad lateral aleatoria (nunca 0)
float lateral_speed = GRAVITY_CHANGE_LATERAL_MIN + (rand() % 1000) / 1000.0f * (GRAVITY_CHANGE_LATERAL_MAX - GRAVITY_CHANGE_LATERAL_MIN);
float lateral_speed = GRAVITY_CHANGE_LATERAL_MIN + ((rand() % 1000) / 1000.0f * (GRAVITY_CHANGE_LATERAL_MAX - GRAVITY_CHANGE_LATERAL_MIN));
// Signo aleatorio (+ o -)
int sign = ((rand() % 2) * 2) - 1;
@@ -304,18 +305,18 @@ void Ball::enableShapeAttraction(bool enable) {
}
// Obtener distancia actual al punto objetivo (para calcular convergencia)
float Ball::getDistanceToTarget() const {
auto Ball::getDistanceToTarget() const -> float {
// Siempre calcular distancia (útil para convergencia en LOGO mode)
float dx = target_x_ - pos_.x;
float dy = target_y_ - pos_.y;
return sqrtf(dx * dx + dy * dy);
return sqrtf((dx * dx) + (dy * dy));
}
// Aplicar fuerza de resorte hacia punto objetivo en figuras 3D
void Ball::applyShapeForce(float target_x, float target_y, float sphere_radius, float deltaTime,
float spring_k_base, float damping_base_base, float damping_near_base,
float near_threshold_base, float max_force_base) {
if (!shape_attraction_active_) return;
void Ball::applyShapeForce(float target_x, float target_y, float sphere_radius, float delta_time, float spring_k_base, float damping_base_base, float damping_near_base, float near_threshold_base, float max_force_base) {
if (!shape_attraction_active_) {
return;
}
// Calcular factor de escala basado en el radio (radio base = 80px)
// Si radius=80 → scale=1.0, si radius=160 → scale=2.0, si radius=360 → scale=4.5
@@ -334,7 +335,7 @@ void Ball::applyShapeForce(float target_x, float target_y, float sphere_radius,
float diff_y = target_y - pos_.y;
// Calcular distancia al punto objetivo
float distance = sqrtf(diff_x * diff_x + diff_y * diff_y);
float distance = sqrtf((diff_x * diff_x) + (diff_y * diff_y));
// Fuerza de resorte (Ley de Hooke: F = -k * x)
float spring_force_x = spring_k * diff_x;
@@ -354,7 +355,7 @@ void Ball::applyShapeForce(float target_x, float target_y, float sphere_radius,
float total_force_y = spring_force_y - damping_force_y;
// Limitar magnitud de fuerza (evitar explosiones numéricas)
float force_magnitude = sqrtf(total_force_x * total_force_x + total_force_y * total_force_y);
float force_magnitude = sqrtf((total_force_x * total_force_x) + (total_force_y * total_force_y));
if (force_magnitude > max_force) {
float scale_limit = max_force / force_magnitude;
total_force_x *= scale_limit;
@@ -363,18 +364,22 @@ void Ball::applyShapeForce(float target_x, float target_y, float sphere_radius,
// Aplicar aceleración (F = ma, asumiendo m = 1 para simplificar)
// a = F/m, pero m=1, así que a = F
vx_ += total_force_x * deltaTime;
vy_ += total_force_y * deltaTime;
vx_ += total_force_x * delta_time;
vy_ += total_force_y * delta_time;
// Actualizar posición con física normal (velocidad integrada)
pos_.x += vx_ * deltaTime;
pos_.y += vy_ * deltaTime;
pos_.x += vx_ * delta_time;
pos_.y += vy_ * delta_time;
// Mantener pelotas dentro de los límites de pantalla
if (pos_.x < 0) pos_.x = 0;
if (pos_.x + pos_.w > screen_width_) pos_.x = screen_width_ - pos_.w;
if (pos_.y < 0) pos_.y = 0;
if (pos_.y + pos_.h > screen_height_) pos_.y = screen_height_ - pos_.h;
pos_.x = std::max<float>(pos_.x, 0);
if (pos_.x + pos_.w > screen_width_) {
pos_.x = screen_width_ - pos_.w;
}
pos_.y = std::max<float>(pos_.y, 0);
if (pos_.y + pos_.h > screen_height_) {
pos_.y = screen_height_ - pos_.h;
}
// Actualizar sprite para renderizado
sprite_->setPos({pos_.x, pos_.y});
@@ -393,5 +398,5 @@ void Ball::updateSize(int new_size) {
void Ball::setTexture(std::shared_ptr<Texture> texture) {
// Actualizar textura del sprite
sprite_->setTexture(texture);
sprite_->setTexture(std::move(texture));
}