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:
@@ -20,10 +20,12 @@ bool linea(SDL_Renderer* renderer, int x1, int y1, int x2, int y2, bool dibuixar
|
||||
|
||||
// Helper function: retorna el signe d'un nombre
|
||||
auto sign = [](int x) -> int {
|
||||
if (x < 0)
|
||||
if (x < 0) {
|
||||
return -1;
|
||||
if (x > 0)
|
||||
}
|
||||
if (x > 0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
@@ -40,7 +42,7 @@ bool linea(SDL_Renderer* renderer, int x1, int y1, int x2, int y2, bool dibuixar
|
||||
bool colisio = false;
|
||||
|
||||
// Dibuixar amb SDL3 (més eficient que Bresenham píxel a píxel)
|
||||
if (dibuixar && renderer) {
|
||||
if (dibuixar && (renderer != nullptr)) {
|
||||
// Transformar coordenades lògiques (640x480) a físiques (resolució real)
|
||||
float scale = g_current_scale_factor;
|
||||
int px1 = transform_x(x1, scale);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class SDLManager {
|
||||
void setWindowTitle(const std::string& title);
|
||||
|
||||
// [NUEVO] Actualitzar context de renderitzat (factor d'escala global)
|
||||
void updateRenderingContext();
|
||||
void updateRenderingContext() const;
|
||||
|
||||
private:
|
||||
SDL_Window* finestra_;
|
||||
|
||||
@@ -48,7 +48,7 @@ static Punt transform_point(const Punt& point, const Punt& shape_centre, const P
|
||||
float centered_y = point.y - shape_centre.y;
|
||||
|
||||
// 2. Aplicar rotació 3D (si es proporciona)
|
||||
if (rotation_3d && rotation_3d->has_rotation()) {
|
||||
if ((rotation_3d != nullptr) && rotation_3d->has_rotation()) {
|
||||
Punt rotated_3d = apply_3d_rotation(centered_x, centered_y, *rotation_3d);
|
||||
centered_x = rotated_3d.x;
|
||||
centered_y = rotated_3d.y;
|
||||
|
||||
Reference in New Issue
Block a user