style: aplicar todos los checks readability-* (225 fixes)

Cambios aplicados:
- readability-braces-around-statements (añadir llaves en ifs/fors)
- readability-implicit-bool-conversion (puntero → bool explícito)
- readability-container-size-empty (.empty() en lugar de .size()==0)
- readability-container-contains (.contains() C++20)
- readability-make-member-function-const (métodos const)
- readability-else-after-return (5 casos adicionales)
- Añadido #include <cmath> en defaults.hpp

Checks excluidos (justificados):
- identifier-naming: Cascada de 300+ cambios
- identifier-length: Nombres cortos son OK en este proyecto
- magic-numbers: Demasiados falsos positivos
- convert-member-functions-to-static: Rompe encapsulación
- use-anyofallof: C++20 ranges no universal
- function-cognitive-complexity: Complejidad aceptable
- clang-analyzer-security.insecureAPI.rand: rand() suficiente para juegos
This commit is contained in:
2025-12-18 19:51:43 +01:00
parent 2088ccdcc6
commit fdfb84170f
28 changed files with 258 additions and 167 deletions
+21 -16
View File
@@ -47,7 +47,7 @@ SDLManager::SDLManager()
SDL_WINDOW_RESIZABLE // Permetre resize manual també
);
if (!finestra_) {
if (finestra_ == nullptr) {
std::cerr << "Error creant finestra: " << SDL_GetError() << std::endl;
SDL_Quit();
return;
@@ -59,7 +59,7 @@ SDLManager::SDLManager()
// Crear renderer amb acceleració
renderer_ = SDL_CreateRenderer(finestra_, nullptr);
if (!renderer_) {
if (renderer_ == nullptr) {
std::cerr << "Error creant renderer: " << SDL_GetError() << std::endl;
SDL_DestroyWindow(finestra_);
SDL_Quit();
@@ -114,7 +114,7 @@ SDLManager::SDLManager(int width, int height, bool fullscreen)
// Crear finestra
finestra_ = SDL_CreateWindow(window_title.c_str(), current_width_, current_height_, flags);
if (!finestra_) {
if (finestra_ == nullptr) {
std::cerr << "Error creant finestra: " << SDL_GetError() << std::endl;
SDL_Quit();
return;
@@ -128,7 +128,7 @@ SDLManager::SDLManager(int width, int height, bool fullscreen)
// Crear renderer amb acceleració
renderer_ = SDL_CreateRenderer(finestra_, nullptr);
if (!renderer_) {
if (renderer_ == nullptr) {
std::cerr << "Error creant renderer: " << SDL_GetError() << std::endl;
SDL_DestroyWindow(finestra_);
SDL_Quit();
@@ -157,12 +157,12 @@ SDLManager::SDLManager(int width, int height, bool fullscreen)
}
SDLManager::~SDLManager() {
if (renderer_) {
if (renderer_ != nullptr) {
SDL_DestroyRenderer(renderer_);
renderer_ = nullptr;
}
if (finestra_) {
if (finestra_ != nullptr) {
SDL_DestroyWindow(finestra_);
finestra_ = nullptr;
}
@@ -175,7 +175,7 @@ void SDLManager::calculateMaxWindowSize() {
SDL_DisplayID display = SDL_GetPrimaryDisplay();
const SDL_DisplayMode* mode = SDL_GetCurrentDisplayMode(display);
if (mode) {
if (mode != nullptr) {
// Deixar marge de 100px per a decoracions de l'OS
max_width_ = mode->w - 100;
max_height_ = mode->h - 100;
@@ -282,14 +282,15 @@ void SDLManager::updateViewport() {
<< std::endl;
}
void SDLManager::updateRenderingContext() {
void SDLManager::updateRenderingContext() const {
// Actualitzar el factor d'escala global per a totes les funcions de renderitzat
Rendering::g_current_scale_factor = zoom_factor_;
}
void SDLManager::increaseWindowSize() {
if (is_fullscreen_)
if (is_fullscreen_) {
return;
}
float new_zoom = zoom_factor_ + Defaults::Window::ZOOM_INCREMENT;
applyZoom(new_zoom);
@@ -298,8 +299,9 @@ void SDLManager::increaseWindowSize() {
}
void SDLManager::decreaseWindowSize() {
if (is_fullscreen_)
if (is_fullscreen_) {
return;
}
float new_zoom = zoom_factor_ - Defaults::Window::ZOOM_INCREMENT;
applyZoom(new_zoom);
@@ -309,7 +311,8 @@ void SDLManager::decreaseWindowSize() {
void SDLManager::applyWindowSize(int new_width, int new_height) {
// Obtenir posició actual ABANS del resize
int old_x, old_y;
int old_x;
int old_y;
SDL_GetWindowPosition(finestra_, &old_x, &old_y);
int old_width = current_width_;
@@ -396,8 +399,9 @@ bool SDLManager::handleWindowEvent(const SDL_Event& event) {
}
void SDLManager::neteja(uint8_t r, uint8_t g, uint8_t b) {
if (!renderer_)
if (renderer_ == nullptr) {
return;
}
// [MODIFICAT] Usar color oscil·lat del fons en lloc dels paràmetres
(void)r;
@@ -409,8 +413,9 @@ void SDLManager::neteja(uint8_t r, uint8_t g, uint8_t b) {
}
void SDLManager::presenta() {
if (!renderer_)
if (renderer_ == nullptr) {
return;
}
SDL_RenderPresent(renderer_);
}
@@ -444,7 +449,7 @@ void SDLManager::updateFPS(float delta_time) {
fps_display_,
vsync_state);
if (finestra_) {
if (finestra_ != nullptr) {
SDL_SetWindowTitle(finestra_, title.c_str());
}
}
@@ -452,7 +457,7 @@ void SDLManager::updateFPS(float delta_time) {
// [NUEVO] Actualitzar títol de la finestra
void SDLManager::setWindowTitle(const std::string& title) {
if (finestra_) {
if (finestra_ != nullptr) {
SDL_SetWindowTitle(finestra_, title.c_str());
}
}
@@ -463,7 +468,7 @@ void SDLManager::toggleVSync() {
Options::rendering.vsync = (Options::rendering.vsync == 1) ? 0 : 1;
// Aplicar a SDL
if (renderer_) {
if (renderer_ != nullptr) {
SDL_SetRenderVSync(renderer_, Options::rendering.vsync);
}