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:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
|
||||
namespace Defaults {
|
||||
@@ -441,13 +442,13 @@ constexpr float CENTER_Y = Game::HEIGHT / 2.0F; // 240.0f
|
||||
// Nota: std::cos/sin no són constexpr en C++20, però funcionen en runtime
|
||||
// Les funcions inline són optimitzades pel compilador (zero overhead)
|
||||
inline float P1_TARGET_X() {
|
||||
return CENTER_X + CLOCK_RADIUS * std::cos(CLOCK_8_ANGLE);
|
||||
return CENTER_X + (CLOCK_RADIUS * std::cos(CLOCK_8_ANGLE));
|
||||
}
|
||||
inline float P1_TARGET_Y() {
|
||||
return CENTER_Y + ((Game::HEIGHT / 2.0F) * TARGET_Y_RATIO);
|
||||
}
|
||||
inline float P2_TARGET_X() {
|
||||
return CENTER_X + CLOCK_RADIUS * std::cos(CLOCK_4_ANGLE);
|
||||
return CENTER_X + (CLOCK_RADIUS * std::cos(CLOCK_4_ANGLE));
|
||||
}
|
||||
inline float P2_TARGET_Y() {
|
||||
return CENTER_Y + ((Game::HEIGHT / 2.0F) * TARGET_Y_RATIO);
|
||||
|
||||
@@ -44,8 +44,9 @@ bool Shape::parsejar_fitxer(const std::string& contingut) {
|
||||
line = trim(line);
|
||||
|
||||
// Skip comments and blanks
|
||||
if (line.empty() || line[0] == '#')
|
||||
if (line.empty() || line[0] == '#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Parse command
|
||||
if (starts_with(line, "name:")) {
|
||||
@@ -91,8 +92,9 @@ bool Shape::parsejar_fitxer(const std::string& contingut) {
|
||||
std::string Shape::trim(const std::string& str) const {
|
||||
const char* whitespace = " \t\n\r";
|
||||
size_t start = str.find_first_not_of(whitespace);
|
||||
if (start == std::string::npos)
|
||||
if (start == std::string::npos) {
|
||||
return "";
|
||||
}
|
||||
|
||||
size_t end = str.find_last_not_of(whitespace);
|
||||
return str.substr(start, end - start + 1);
|
||||
@@ -101,16 +103,18 @@ 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 {
|
||||
if (str.length() < prefix.length())
|
||||
if (str.length() < prefix.length()) {
|
||||
return false;
|
||||
}
|
||||
return str.compare(0, prefix.length(), prefix) == 0;
|
||||
}
|
||||
|
||||
// Helper: extract value after ':'
|
||||
std::string Shape::extract_value(const std::string& line) const {
|
||||
size_t colon = line.find(':');
|
||||
if (colon == std::string::npos)
|
||||
if (colon == std::string::npos) {
|
||||
return "";
|
||||
}
|
||||
return line.substr(colon + 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ Starfield::Starfield(SDL_Renderer* renderer,
|
||||
}
|
||||
|
||||
// Inicialitzar una estrella (nova o regenerada)
|
||||
void Starfield::inicialitzar_estrella(Estrella& estrella) {
|
||||
void Starfield::inicialitzar_estrella(Estrella& estrella) const {
|
||||
// Angle aleatori des del punt de fuga cap a fora
|
||||
estrella.angle = (static_cast<float>(rand()) / RAND_MAX) * 2.0F * Defaults::Math::PI;
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ class Starfield {
|
||||
};
|
||||
|
||||
// Inicialitzar una estrella (nova o regenerada)
|
||||
void inicialitzar_estrella(Estrella& estrella);
|
||||
void inicialitzar_estrella(Estrella& estrella) const;
|
||||
|
||||
// Verificar si una estrella està fora de l'àrea
|
||||
bool fora_area(const Estrella& estrella) const;
|
||||
|
||||
@@ -178,11 +178,11 @@ std::string VectorText::get_shape_filename(char c) const {
|
||||
}
|
||||
|
||||
bool VectorText::is_supported(char c) const {
|
||||
return chars_.find(c) != chars_.end();
|
||||
return chars_.contains(c);
|
||||
}
|
||||
|
||||
void VectorText::render(const std::string& text, const Punt& posicio, float escala, float spacing, float brightness) {
|
||||
if (!renderer_) {
|
||||
if (renderer_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -506,7 +506,7 @@ void Input::applyPlayer1BindingsFromOptions() {
|
||||
std::shared_ptr<Gamepad> gamepad = nullptr;
|
||||
if (Options::player1.gamepad_name.empty()) {
|
||||
// Fallback: usar primer gamepad disponible
|
||||
gamepad = (gamepads_.size() > 0) ? gamepads_[0] : nullptr;
|
||||
gamepad = (!gamepads_.empty()) ? gamepads_[0] : nullptr;
|
||||
} else {
|
||||
// Buscar por nombre
|
||||
gamepad = findAvailableGamepadByName(Options::player1.gamepad_name);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -197,7 +197,7 @@ bool Pack::loadPack(const std::string& pack_file) {
|
||||
file.read(reinterpret_cast<char*>(&name_len), sizeof(name_len));
|
||||
|
||||
std::string filename(name_len, '\0');
|
||||
file.read(&filename[0], name_len);
|
||||
file.read(filename.data(), name_len);
|
||||
|
||||
// Offset, mida, checksum
|
||||
ResourceEntry entry;
|
||||
@@ -258,7 +258,7 @@ std::vector<uint8_t> Pack::getResource(const std::string& filename) {
|
||||
|
||||
// Comprovar si existeix un recurs
|
||||
bool Pack::hasResource(const std::string& filename) const {
|
||||
return resources_.find(filename) != resources_.end();
|
||||
return resources_.contains(filename);
|
||||
}
|
||||
|
||||
// Obtenir llista de tots els recursos
|
||||
|
||||
@@ -42,8 +42,12 @@ struct ConfigPartida {
|
||||
// Retorna l'ID de l'únic jugador actiu (0 o 1)
|
||||
// Només vàlid si es_un_jugador() retorna true
|
||||
[[nodiscard]] uint8_t id_unic_jugador() const {
|
||||
if (jugador1_actiu && !jugador2_actiu) return 0;
|
||||
if (!jugador1_actiu && jugador2_actiu) return 1;
|
||||
if (jugador1_actiu && !jugador2_actiu) {
|
||||
return 0;
|
||||
}
|
||||
if (!jugador1_actiu && jugador2_actiu) {
|
||||
return 1;
|
||||
}
|
||||
return 0; // Fallback (cal comprovar es_un_jugador() primer)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ static std::string executable_directory_;
|
||||
|
||||
// Inicialitzar el sistema de rutes amb argv[0]
|
||||
void initializePathSystem(const char* argv0) {
|
||||
if (!argv0) {
|
||||
if (argv0 == nullptr) {
|
||||
std::cerr << "[PathUtils] ADVERTÈNCIA: argv[0] és nullptr\n";
|
||||
executable_path_ = "";
|
||||
executable_directory_ = ".";
|
||||
@@ -65,10 +65,8 @@ std::string getResourceBasePath() {
|
||||
// Bundle de macOS: recursos a ../Resources des de MacOS/
|
||||
std::cout << "[PathUtils] Detectat bundle de macOS\n";
|
||||
return exe_dir + "/../Resources";
|
||||
} else {
|
||||
// Executable normal: recursos al mateix directori
|
||||
return exe_dir;
|
||||
}
|
||||
} // Executable normal: recursos al mateix directori
|
||||
return exe_dir;
|
||||
}
|
||||
|
||||
// Normalitzar ruta (convertir barres, etc.)
|
||||
|
||||
Reference in New Issue
Block a user