From 8f5d897048cf40d3e29943c204f4d7a57e056022 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 14 May 2026 23:55:44 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20resta=20tidy=20(60=20troballes=20?= =?UTF-8?q?=E2=80=94=20empty-catch,=20widening,=20branch-clone,=20etc.)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/core/audio/audio.cpp | 1 + source/core/audio/audio.hpp | 5 +- source/core/audio/jail_audio.hpp | 12 +- source/core/input/input.cpp | 3 +- source/core/input/input.hpp | 4 +- source/core/rendering/gif.cpp | 4 +- source/core/rendering/screen.cpp | 8 +- .../core/rendering/sdl3gpu/sdl3gpu_shader.cpp | 2 +- source/core/rendering/sprite/sprite.hpp | 6 +- source/core/rendering/surface.cpp | 14 +- source/core/rendering/text.cpp | 12 +- source/core/resources/resource_cache.cpp | 170 ++++++------------ source/core/resources/resource_cache.hpp | 13 +- source/core/system/global_events.cpp | 8 +- source/game/entities/player.cpp | 2 - source/game/options.cpp | 45 +++-- source/game/scenes/logo.cpp | 3 - source/game/ui/console.cpp | 19 +- source/game/ui/console_commands.cpp | 6 +- source/game/ui/notifier.cpp | 8 +- source/game/ui/notifier.hpp | 6 +- source/utils/delta_timer.cpp | 3 +- source/utils/delta_timer.hpp | 2 +- 23 files changed, 163 insertions(+), 193 deletions(-) diff --git a/source/core/audio/audio.cpp b/source/core/audio/audio.cpp index 6e39c0a..ad58c6a 100644 --- a/source/core/audio/audio.cpp +++ b/source/core/audio/audio.cpp @@ -8,6 +8,7 @@ // Implementación de stb_vorbis (debe estar ANTES de incluir jail_audio.hpp). // clang-format off #undef STB_VORBIS_HEADER_ONLY +// NOLINTNEXTLINE(bugprone-suspicious-include) — stb_vorbis és single-file: el TU principal inclou el .c per portar la implementació. #include "external/stb_vorbis.c" // stb_vorbis.c filtra les macros L, C i R (i PLAYBACK_*) al TU. Les netegem // perquè xocarien amb noms de paràmetres de plantilla en altres headers. diff --git a/source/core/audio/audio.hpp b/source/core/audio/audio.hpp index 783afad..be490d4 100644 --- a/source/core/audio/audio.hpp +++ b/source/core/audio/audio.hpp @@ -1,5 +1,6 @@ #pragma once +#include // Para std::lround #include // Para int8_t, uint8_t #include // Para string #include // Para move @@ -64,8 +65,8 @@ class Audio { // --- Helpers de conversió per a la capa de presentació --- // UI (menús, notificacions) manega enters 0..100; internament viu float 0..1. - static constexpr auto toPercent(float volume) -> int { - return static_cast(volume * 100.0F + 0.5F); + static auto toPercent(float volume) -> int { + return static_cast(std::lround(volume * 100.0F)); } static constexpr auto fromPercent(int percent) -> float { return static_cast(percent) / 100.0F; diff --git a/source/core/audio/jail_audio.hpp b/source/core/audio/jail_audio.hpp index 52c910a..b1e7625 100644 --- a/source/core/audio/jail_audio.hpp +++ b/source/core/audio/jail_audio.hpp @@ -57,12 +57,14 @@ namespace Ja { std::unique_ptr buffer; }; + // L'ordre (punters primer, ints després, enum de 8 bits al final) minimitza + // el padding a 64-bit (evita avisos de clang-analyzer-optin.performance.Padding). struct Channel { Sound* sound{nullptr}; + SDL_AudioStream* stream{nullptr}; int pos{0}; int times{0}; int group{0}; - SDL_AudioStream* stream{nullptr}; ChannelState state{ChannelState::FREE}; }; @@ -314,7 +316,11 @@ namespace Ja { std::fseek(f, 0, SEEK_END); const long FSIZE = std::ftell(f); std::fseek(f, 0, SEEK_SET); - auto* buffer = static_cast(std::malloc(FSIZE + 1)); + if (FSIZE <= 0) { + std::fclose(f); + return nullptr; + } + auto* buffer = static_cast(std::malloc(static_cast(FSIZE) + 1)); if (buffer == nullptr) { std::fclose(f); return nullptr; @@ -520,7 +526,7 @@ namespace Ja { inline auto loadSound(std::uint8_t* buffer, std::uint32_t size) -> Sound* { auto sound = std::make_unique(); Uint8* raw = nullptr; - if (!SDL_LoadWAV_IO(SDL_IOFromMem(buffer, size), 1, &sound->spec, &raw, &sound->length)) { + if (!SDL_LoadWAV_IO(SDL_IOFromMem(buffer, size), true, &sound->spec, &raw, &sound->length)) { std::cout << "Failed to load WAV from memory: " << SDL_GetError() << '\n'; return nullptr; } diff --git a/source/core/input/input.cpp b/source/core/input/input.cpp index 567f842..f6440c9 100644 --- a/source/core/input/input.cpp +++ b/source/core/input/input.cpp @@ -425,8 +425,9 @@ auto Input::handleEvent(const SDL_Event& event) -> std::string { // NOLINT(read return addGamepad(event.gdevice.which); case SDL_EVENT_GAMEPAD_REMOVED: return removeGamepad(event.gdevice.which); + default: + return {}; } - return {}; } auto Input::addGamepad(int device_index) -> std::string { // NOLINT(readability-convert-member-functions-to-static) diff --git a/source/core/input/input.hpp b/source/core/input/input.hpp index 152b906..3685016 100644 --- a/source/core/input/input.hpp +++ b/source/core/input/input.hpp @@ -55,8 +55,8 @@ class Input { // Evita nombres como "Retroid Controller (vendor: 1001) ..." en las notificaciones. static auto trimName(const char* raw) -> std::string { std::string s(raw != nullptr ? raw : ""); - const auto pos = s.find_first_of("(["); - if (pos != std::string::npos) { s.erase(pos); } + const auto POS = s.find_first_of("(["); + if (POS != std::string::npos) { s.erase(POS); } while (!s.empty() && s.back() == ' ') { s.pop_back(); } return s; } diff --git a/source/core/rendering/gif.cpp b/source/core/rendering/gif.cpp index 654090e..302138e 100644 --- a/source/core/rendering/gif.cpp +++ b/source/core/rendering/gif.cpp @@ -224,8 +224,8 @@ namespace GIF { if ((screen_descriptor.fields & 0x80) != 0) { int global_color_table_size = 1 << ((screen_descriptor.fields & 0x07) + 1); global_color_table.resize(global_color_table_size); - std::memcpy(global_color_table.data(), buffer, 3 * global_color_table_size); - buffer += 3 * global_color_table_size; + std::memcpy(global_color_table.data(), buffer, static_cast(3) * global_color_table_size); + buffer += static_cast(3) * global_color_table_size; } // Supongamos que 'buffer' es el puntero actual y TRAILER es 0x3B diff --git a/source/core/rendering/screen.cpp b/source/core/rendering/screen.cpp index 15063aa..c0e1e01 100644 --- a/source/core/rendering/screen.cpp +++ b/source/core/rendering/screen.cpp @@ -475,13 +475,13 @@ void Screen::textureToRenderer() { // Franjas superior e inferior (ancho completo) std::fill_n(border_pixel_buffer_.data(), OFF_Y * BORDER_W, border_argb_color_); - std::fill_n(&border_pixel_buffer_[(OFF_Y + GAME_H) * BORDER_W], + std::fill_n(&border_pixel_buffer_[static_cast(OFF_Y + GAME_H) * BORDER_W], (BORDER_H - OFF_Y - GAME_H) * BORDER_W, border_argb_color_); // Columnas laterales en las filas del área de juego for (int y = OFF_Y; y < OFF_Y + GAME_H; ++y) { - std::fill_n(&border_pixel_buffer_[y * BORDER_W], OFF_X, border_argb_color_); - std::fill_n(&border_pixel_buffer_[(y * BORDER_W) + OFF_X + GAME_W], + std::fill_n(&border_pixel_buffer_[static_cast(y) * BORDER_W], OFF_X, border_argb_color_); + std::fill_n(&border_pixel_buffer_[(static_cast(y) * BORDER_W) + OFF_X + GAME_W], BORDER_W - OFF_X - GAME_W, border_argb_color_); } @@ -494,7 +494,7 @@ void Screen::textureToRenderer() { // Overlay del juego sobre el centro del buffer (ambos paths) game_surface_->toARGBBuffer(game_pixel_buffer_.data()); for (int y = 0; y < GAME_H; ++y) { - const Uint32* src = &game_pixel_buffer_[y * GAME_W]; + const Uint32* src = &game_pixel_buffer_[static_cast(y) * GAME_W]; Uint32* dst = &border_pixel_buffer_[((OFF_Y + y) * BORDER_W) + OFF_X]; std::memcpy(dst, src, GAME_W * sizeof(Uint32)); } diff --git a/source/core/rendering/sdl3gpu/sdl3gpu_shader.cpp b/source/core/rendering/sdl3gpu/sdl3gpu_shader.cpp index cc43cc0..00ec21f 100644 --- a/source/core/rendering/sdl3gpu/sdl3gpu_shader.cpp +++ b/source/core/rendering/sdl3gpu/sdl3gpu_shader.cpp @@ -762,7 +762,7 @@ namespace Rendering { } // Copia directa — el upscale lo hace la GPU en el primer render pass - std::memcpy(mapped, pixels, static_cast(width * height * 4)); + std::memcpy(mapped, pixels, static_cast(width) * static_cast(height) * 4); SDL_UnmapGPUTransferBuffer(device_, upload_buffer_); } diff --git a/source/core/rendering/sprite/sprite.hpp b/source/core/rendering/sprite/sprite.hpp index ec5d153..ebcc56c 100644 --- a/source/core/rendering/sprite/sprite.hpp +++ b/source/core/rendering/sprite/sprite.hpp @@ -10,10 +10,10 @@ class Surface; // lines 5-5 class Sprite { public: // Constructores - Sprite(std::shared_ptr, float x, float y, float w, float h); - Sprite(std::shared_ptr, SDL_FRect rect); + Sprite(std::shared_ptr surface, float x, float y, float w, float h); + Sprite(std::shared_ptr surface, SDL_FRect rect); Sprite(); - explicit Sprite(std::shared_ptr); + explicit Sprite(std::shared_ptr surface); // Destructor virtual ~Sprite() = default; diff --git a/source/core/rendering/surface.cpp b/source/core/rendering/surface.cpp index a33263d..d18b3e5 100644 --- a/source/core/rendering/surface.cpp +++ b/source/core/rendering/surface.cpp @@ -180,7 +180,7 @@ void Surface::fillRect(const SDL_FRect* rect, Uint8 color) { // NOLINT(readabil const int SURF_WIDTH = surface_data_->width; const int ROW_WIDTH = static_cast(x_end) - static_cast(x_start); for (int y = static_cast(y_start); y < static_cast(y_end); ++y) { - std::memset(data_ptr + (y * SURF_WIDTH) + static_cast(x_start), color, ROW_WIDTH); + std::memset(data_ptr + (static_cast(y) * SURF_WIDTH) + static_cast(x_start), color, ROW_WIDTH); } } @@ -196,8 +196,8 @@ void Surface::drawRectBorder(const SDL_FRect* rect, Uint8 color) { // NOLINT(re Uint8* data_ptr = surface_data_->data.get(); const int SURF_WIDTH = surface_data_->width; const int ROW_WIDTH = static_cast(x_end) - static_cast(x_start); - std::memset(data_ptr + (static_cast(y_start) * SURF_WIDTH) + static_cast(x_start), color, ROW_WIDTH); - std::memset(data_ptr + ((static_cast(y_end) - 1) * SURF_WIDTH) + static_cast(x_start), color, ROW_WIDTH); + std::memset(data_ptr + (static_cast(y_start) * SURF_WIDTH) + static_cast(x_start), color, ROW_WIDTH); + std::memset(data_ptr + ((static_cast(y_end) - 1) * SURF_WIDTH) + static_cast(x_start), color, ROW_WIDTH); // Dibujar bordes verticales for (int y = y_start; y < y_end; ++y) { @@ -539,8 +539,8 @@ void Surface::copyToTexture(SDL_Renderer* renderer, SDL_Texture* texture) { // const int WIDTH = surface_data_->width; const int HEIGHT = surface_data_->height; for (int y = 0; y < HEIGHT; ++y) { - const Uint8* src_row = src + (y * WIDTH); - Uint32* dst_row = pixels + (y * row_stride); + const Uint8* src_row = src + (static_cast(y) * WIDTH); + Uint32* dst_row = pixels + (static_cast(y) * row_stride); for (int x = 0; x < WIDTH; ++x) { dst_row[x] = pal[src_row[x]]; } @@ -588,8 +588,8 @@ void Surface::copyToTexture(SDL_Renderer* renderer, SDL_Texture* texture, SDL_FR const int WIDTH = surface_data_->width; const int HEIGHT = surface_data_->height; for (int y = 0; y < HEIGHT; ++y) { - const Uint8* src_row = src + (y * WIDTH); - Uint32* dst_row = pixels + (y * row_stride); + const Uint8* src_row = src + (static_cast(y) * WIDTH); + Uint32* dst_row = pixels + (static_cast(y) * row_stride); for (int x = 0; x < WIDTH; ++x) { dst_row[x] = pal[src_row[x]]; } diff --git a/source/core/rendering/text.cpp b/source/core/rendering/text.cpp index 4a76380..36ef4d6 100644 --- a/source/core/rendering/text.cpp +++ b/source/core/rendering/text.cpp @@ -22,11 +22,11 @@ auto Text::nextCodepoint(const std::string& s, size_t& pos) -> uint32_t { // NO if (c < 0x80) { cp = c; extra = 0; - } else if (c < 0xC0) { - pos++; - return 0xFFFD; - } // byte de continuación suelto - else if (c < 0xE0) { + } else if (c < 0xE0) { + if (c < 0xC0) { + pos++; + return 0xFFFD; // byte de continuación suelto + } cp = c & 0x1F; extra = 1; } else if (c < 0xF0) { @@ -260,7 +260,7 @@ void Text::writeDX(Uint8 flags, int x, int y, const std::string& text, int kerni if (COLORED) { writeColored(x, y, text, text_color, kerning, lenght); } else { - writeColored(x, y, text, text_color, kerning, lenght); + write(x, y, text, kerning, lenght); } } diff --git a/source/core/resources/resource_cache.cpp b/source/core/resources/resource_cache.cpp index 42799f0..e836c97 100644 --- a/source/core/resources/resource_cache.cpp +++ b/source/core/resources/resource_cache.cpp @@ -87,148 +87,88 @@ namespace Resource { return stage_ == LoadStage::DONE; } + // Helper per a una etapa que itera una llista de recursos. + // Imprimeix la capçalera i neteja el vector al primer cop; després carrega + // un element per crida fins exhaurir la llista, moment en què passa a `next`. + void Cache::stepEachInList(List::Type type, const char* header, const std::function& clear_fn, LoadStage next, const std::function& load_fn) { + auto list = List::get()->getListByType(type); + if (stage_index_ == 0) { + std::cout << "\n>> " << header << '\n'; + clear_fn(); + } + if (stage_index_ >= list.size()) { + stage_ = next; + stage_index_ = 0; + return; + } + load_fn(stage_index_++); + } + // Carga assets hasta agotar el presupuesto de tiempo o completar todas las etapas. // Devuelve true cuando ya no queda nada por cargar. auto Cache::loadStep(int budget_ms) -> bool { if (stage_ == LoadStage::DONE) { return true; } - const Uint64 start_ns = SDL_GetTicksNS(); - const Uint64 budget_ns = static_cast(budget_ms) * 1'000'000ULL; - - auto listOf = [](List::Type t) { return List::get()->getListByType(t); }; + const Uint64 START_NS = SDL_GetTicksNS(); + const Uint64 BUDGET_NS = static_cast(budget_ms) * 1'000'000ULL; while (stage_ != LoadStage::DONE) { switch (stage_) { - case LoadStage::SOUNDS: { - auto list = listOf(List::Type::SOUND); - if (stage_index_ == 0) { - std::cout << "\n>> SOUND FILES" << '\n'; - sounds_.clear(); - } - if (stage_index_ >= list.size()) { - stage_ = LoadStage::MUSICS; - stage_index_ = 0; - break; - } - loadOneSound(stage_index_++); + case LoadStage::SOUNDS: + stepEachInList(List::Type::SOUND, "SOUND FILES", [this] { sounds_.clear(); }, LoadStage::MUSICS, [this](size_t i) { loadOneSound(i); }); break; - } - case LoadStage::MUSICS: { - auto list = listOf(List::Type::MUSIC); - if (stage_index_ == 0) { - std::cout << "\n>> MUSIC FILES" << '\n'; - musics_.clear(); - } - if (stage_index_ >= list.size()) { - stage_ = LoadStage::SURFACES; - stage_index_ = 0; - break; - } - loadOneMusic(stage_index_++); + case LoadStage::MUSICS: + stepEachInList(List::Type::MUSIC, "MUSIC FILES", [this] { musics_.clear(); }, LoadStage::SURFACES, [this](size_t i) { loadOneMusic(i); }); break; - } - case LoadStage::SURFACES: { - auto list = listOf(List::Type::BITMAP); - if (stage_index_ == 0) { - std::cout << "\n>> SURFACES" << '\n'; - surfaces_.clear(); - } - if (stage_index_ >= list.size()) { - stage_ = LoadStage::SURFACES_POST; - stage_index_ = 0; - break; - } - loadOneSurface(stage_index_++); + case LoadStage::SURFACES: + stepEachInList(List::Type::BITMAP, "SURFACES", [this] { surfaces_.clear(); }, LoadStage::SURFACES_POST, [this](size_t i) { loadOneSurface(i); }); break; - } - case LoadStage::SURFACES_POST: { + case LoadStage::SURFACES_POST: finalizeSurfaces(); stage_ = LoadStage::PALETTES; stage_index_ = 0; break; - } - case LoadStage::PALETTES: { - auto list = listOf(List::Type::PALETTE); - if (stage_index_ == 0) { - std::cout << "\n>> PALETTES" << '\n'; - palettes_.clear(); - } - if (stage_index_ >= list.size()) { - stage_ = LoadStage::TEXT_FILES; - stage_index_ = 0; - break; - } - loadOnePalette(stage_index_++); + case LoadStage::PALETTES: + stepEachInList(List::Type::PALETTE, "PALETTES", [this] { palettes_.clear(); }, LoadStage::TEXT_FILES, [this](size_t i) { loadOnePalette(i); }); break; - } - case LoadStage::TEXT_FILES: { - auto list = listOf(List::Type::FONT); - if (stage_index_ == 0) { - std::cout << "\n>> TEXT FILES" << '\n'; - text_files_.clear(); - } - if (stage_index_ >= list.size()) { - stage_ = LoadStage::ANIMATIONS; - stage_index_ = 0; - break; - } - loadOneTextFile(stage_index_++); + case LoadStage::TEXT_FILES: + stepEachInList(List::Type::FONT, "TEXT FILES", [this] { text_files_.clear(); }, LoadStage::ANIMATIONS, [this](size_t i) { loadOneTextFile(i); }); break; - } - case LoadStage::ANIMATIONS: { - auto list = listOf(List::Type::ANIMATION); - if (stage_index_ == 0) { - std::cout << "\n>> ANIMATIONS" << '\n'; - animations_.clear(); - } - if (stage_index_ >= list.size()) { - stage_ = LoadStage::ROOMS; - stage_index_ = 0; - break; - } - loadOneAnimation(stage_index_++); + case LoadStage::ANIMATIONS: + stepEachInList(List::Type::ANIMATION, "ANIMATIONS", [this] { animations_.clear(); }, LoadStage::ROOMS, [this](size_t i) { loadOneAnimation(i); }); break; - } - case LoadStage::ROOMS: { - auto list = listOf(List::Type::ROOM); - if (stage_index_ == 0) { - std::cout << "\n>> ROOMS" << '\n'; - rooms_.clear(); - } - if (stage_index_ >= list.size()) { - stage_ = LoadStage::TEXTS; - stage_index_ = 0; - break; - } - loadOneRoom(stage_index_++); + case LoadStage::ROOMS: + stepEachInList(List::Type::ROOM, "ROOMS", [this] { rooms_.clear(); }, LoadStage::TEXTS, [this](size_t i) { loadOneRoom(i); }); break; - } - case LoadStage::TEXTS: { - // createText itera sobre una lista fija de 5 fuentes - constexpr size_t TEXT_COUNT = 5; - if (stage_index_ == 0) { - std::cout << "\n>> CREATING TEXT_OBJECTS" << '\n'; - texts_.clear(); - } - if (stage_index_ >= TEXT_COUNT) { - stage_ = LoadStage::DONE; - stage_index_ = 0; - std::cout << "\n** RESOURCES LOADED" << '\n'; - break; - } - createOneText(stage_index_++); + case LoadStage::TEXTS: + stepTexts(); break; - } case LoadStage::DONE: break; } - if ((SDL_GetTicksNS() - start_ns) >= budget_ns) { break; } + if ((SDL_GetTicksNS() - START_NS) >= BUDGET_NS) { break; } } return stage_ == LoadStage::DONE; } + void Cache::stepTexts() { + // createText itera sobre una lista fija de 5 fuentes + constexpr size_t TEXT_COUNT = 5; + if (stage_index_ == 0) { + std::cout << "\n>> CREATING TEXT_OBJECTS" << '\n'; + texts_.clear(); + } + if (stage_index_ >= TEXT_COUNT) { + stage_ = LoadStage::DONE; + stage_index_ = 0; + std::cout << "\n** RESOURCES LOADED" << '\n'; + return; + } + createOneText(stage_index_++); + } + // Recarga todos los recursos (síncrono, solo para hot-reload de debug) void Cache::reload() { clear(); @@ -382,13 +322,13 @@ namespace Resource { }; auto getTextObjectInfos() -> const std::vector& { - static const std::vector info = { + static const std::vector INFO = { {.key = "aseprite", .texture_file = "aseprite.gif", .text_file = "aseprite.fnt"}, {.key = "gauntlet", .texture_file = "gauntlet.gif", .text_file = "gauntlet.fnt"}, {.key = "smb2", .texture_file = "smb2.gif", .text_file = "smb2.fnt"}, {.key = "subatomic", .texture_file = "subatomic.gif", .text_file = "subatomic.fnt"}, {.key = "8bithud", .texture_file = "8bithud.gif", .text_file = "8bithud.fnt"}}; - return info; + return INFO; } } // namespace diff --git a/source/core/resources/resource_cache.hpp b/source/core/resources/resource_cache.hpp index 4548e87..f9be4ed 100644 --- a/source/core/resources/resource_cache.hpp +++ b/source/core/resources/resource_cache.hpp @@ -1,11 +1,13 @@ #pragma once -#include // Para uint8_t -#include // Para shared_ptr -#include // Para string +#include // Para uint8_t +#include // Para std::function +#include // Para shared_ptr +#include // Para string #include #include // Para vector +#include "core/resources/resource_list.hpp" // Para List::Type #include "core/resources/resource_types.hpp" // Para structs de recursos namespace Resource { @@ -103,6 +105,11 @@ namespace Resource { // Helper para mensajes de error de carga static void logLoadError(const std::string& asset_type, const std::string& file_path, const std::exception& e); + // Helper d'iteració per a una etapa que recorre una llista de recursos. + // Crida `load_fn(i)` per a cada element i, en exhaurir-se, transiciona a `next`. + void stepEachInList(List::Type type, const char* header, const std::function& clear_fn, LoadStage next, const std::function& load_fn); + void stepTexts(); // Etapa especial: no usa List, itera sobre TEXT_COUNT fonts fixes. + // Constructor y destructor Cache(); ~Cache() = default; diff --git a/source/core/system/global_events.cpp b/source/core/system/global_events.cpp index 905ee7f..0cb3617 100644 --- a/source/core/system/global_events.cpp +++ b/source/core/system/global_events.cpp @@ -13,7 +13,7 @@ namespace GlobalEvents { namespace { // Flag per saber si en aquest frame s'ha rebut un button down del gamepad. // El consumeix GlobalInputs perquè un botó del comandament salti escenes. - bool gamepad_button_pressed_ = false; + bool gamepad_button_pressed = false; } // namespace // Comprueba los eventos que se pueden producir en cualquier sección del juego. @@ -56,7 +56,7 @@ namespace GlobalEvents { const bool RESERVE_BACK = IS_BACK; #endif if (!RESERVE_BACK && !IS_SHOULDER) { - gamepad_button_pressed_ = true; + gamepad_button_pressed = true; } } @@ -72,8 +72,8 @@ namespace GlobalEvents { } auto consumeGamepadButtonPressed() -> bool { - const bool RESULT = gamepad_button_pressed_; - gamepad_button_pressed_ = false; + const bool RESULT = gamepad_button_pressed; + gamepad_button_pressed = false; return RESULT; } } // namespace GlobalEvents \ No newline at end of file diff --git a/source/game/entities/player.cpp b/source/game/entities/player.cpp index 1efa930..6f11c4d 100644 --- a/source/game/entities/player.cpp +++ b/source/game/entities/player.cpp @@ -836,8 +836,6 @@ void Player::updateVelocity() { sprite_->setFlip(Flip::RIGHT); break; case Direction::NONE: - vx_ = 0.0F; - break; default: vx_ = 0.0F; break; diff --git a/source/game/options.cpp b/source/game/options.cpp index 67fd6d7..bcbdaaf 100644 --- a/source/game/options.cpp +++ b/source/game/options.cpp @@ -368,12 +368,14 @@ namespace Options { if (sh_node.contains("current_postfx_preset")) { try { video.shader.current_postfx_preset_name = sh_node["current_postfx_preset"].get_value(); - } catch (...) {} + } catch (...) { /* @INTENTIONAL: camp YAML malformat → conservem default */ + } } if (sh_node.contains("current_crtpi_preset")) { try { video.shader.current_crtpi_preset_name = sh_node["current_crtpi_preset"].get_value(); - } catch (...) {} + } catch (...) { /* @INTENTIONAL: camp YAML malformat → conservem default */ + } } } @@ -573,24 +575,28 @@ namespace Options { if (a.contains("enabled")) { try { audio.enabled = a["enabled"].get_value(); - } catch (...) {} + } catch (...) { /* @INTENTIONAL: camp YAML malformat → conservem default */ + } } if (a.contains("volume")) { try { audio.volume = std::clamp(a["volume"].get_value(), 0.0F, 1.0F); - } catch (...) {} + } catch (...) { /* @INTENTIONAL: camp YAML malformat → conservem default */ + } } if (a.contains("music")) { const auto& m = a["music"]; if (m.contains("enabled")) { try { audio.music.enabled = m["enabled"].get_value(); - } catch (...) {} + } catch (...) { /* @INTENTIONAL: camp YAML malformat → conservem default */ + } } if (m.contains("volume")) { try { audio.music.volume = std::clamp(m["volume"].get_value(), 0.0F, 1.0F); - } catch (...) {} + } catch (...) { /* @INTENTIONAL: camp YAML malformat → conservem default */ + } } } if (a.contains("sound")) { @@ -598,12 +604,14 @@ namespace Options { if (s.contains("enabled")) { try { audio.sound.enabled = s["enabled"].get_value(); - } catch (...) {} + } catch (...) { /* @INTENTIONAL: camp YAML malformat → conservem default */ + } } if (s.contains("volume")) { try { audio.sound.volume = std::clamp(s["volume"].get_value(), 0.0F, 1.0F); - } catch (...) {} + } catch (...) { /* @INTENTIONAL: camp YAML malformat → conservem default */ + } } } } @@ -891,7 +899,8 @@ namespace Options { if (node.contains(key)) { try { target = node[key].get_value(); - } catch (...) {} + } catch (...) { /* @INTENTIONAL: camp YAML malformat → conservem default */ + } } } @@ -1181,32 +1190,38 @@ namespace Options { if (p.contains("mask_type")) { try { preset.mask_type = p["mask_type"].get_value(); - } catch (...) {} + } catch (...) { /* @INTENTIONAL: camp YAML malformat → conservem default */ + } } if (p.contains("enable_scanlines")) { try { preset.enable_scanlines = p["enable_scanlines"].get_value(); - } catch (...) {} + } catch (...) { /* @INTENTIONAL: camp YAML malformat → conservem default */ + } } if (p.contains("enable_multisample")) { try { preset.enable_multisample = p["enable_multisample"].get_value(); - } catch (...) {} + } catch (...) { /* @INTENTIONAL: camp YAML malformat → conservem default */ + } } if (p.contains("enable_gamma")) { try { preset.enable_gamma = p["enable_gamma"].get_value(); - } catch (...) {} + } catch (...) { /* @INTENTIONAL: camp YAML malformat → conservem default */ + } } if (p.contains("enable_curvature")) { try { preset.enable_curvature = p["enable_curvature"].get_value(); - } catch (...) {} + } catch (...) { /* @INTENTIONAL: camp YAML malformat → conservem default */ + } } if (p.contains("enable_sharper")) { try { preset.enable_sharper = p["enable_sharper"].get_value(); - } catch (...) {} + } catch (...) { /* @INTENTIONAL: camp YAML malformat → conservem default */ + } } crtpi_presets.push_back(preset); } diff --git a/source/game/scenes/logo.cpp b/source/game/scenes/logo.cpp index 39dd017..8601d14 100644 --- a/source/game/scenes/logo.cpp +++ b/source/game/scenes/logo.cpp @@ -238,9 +238,6 @@ void Logo::endSection() { break; case SceneManager::Options::LOGO_TO_LOADING_SCREEN: - SceneManager::current = SceneManager::Scene::LOADING_SCREEN; - break; - default: SceneManager::current = SceneManager::Scene::LOADING_SCREEN; break; diff --git a/source/game/ui/console.cpp b/source/game/ui/console.cpp index 8483d99..63144db 100644 --- a/source/game/ui/console.cpp +++ b/source/game/ui/console.cpp @@ -66,9 +66,11 @@ auto Console::wrapText(const std::string& text) const -> std::vector> word) { - const std::string TEST = current_line.empty() ? word : (current_line + ' ' + word); - if (text_->length(TEST) <= MAX_PX) { - current_line = TEST; + std::string test = current_line; + if (!test.empty()) { test += ' '; } + test += word; + if (text_->length(test) <= MAX_PX) { + current_line = std::move(test); } else { if (!current_line.empty()) { result.push_back(current_line); } current_line = word; @@ -182,10 +184,10 @@ void Console::update(float delta_time) { // NOLINT(readability-function-cogniti // Efecto typewriter: revelar letras una a una (solo cuando ACTIVE) if (status_ == Status::ACTIVE) { - const int total_chars = std::accumulate(msg_lines_.begin(), msg_lines_.end(), 0, [](int acc, const auto& line) { return acc + static_cast(line.size()); }); - if (typewriter_chars_ < total_chars) { + const int TOTAL_CHARS = std::accumulate(msg_lines_.begin(), msg_lines_.end(), 0, [](int acc, const auto& line) { return acc + static_cast(line.size()); }); + if (typewriter_chars_ < TOTAL_CHARS) { typewriter_timer_ += delta_time; - while (typewriter_timer_ >= TYPEWRITER_CHAR_DELAY && typewriter_chars_ < total_chars) { + while (typewriter_timer_ >= TYPEWRITER_CHAR_DELAY && typewriter_chars_ < TOTAL_CHARS) { typewriter_timer_ -= TYPEWRITER_CHAR_DELAY; ++typewriter_chars_; } @@ -345,7 +347,10 @@ void Console::handleEvent(const SDL_Event& event) { // NOLINT(readability-funct const auto OPTS = registry_.getCompletions(BASE_CMD); for (const auto& arg : OPTS) { if (SUB_PREFIX.empty() || std::string_view{arg}.starts_with(SUB_PREFIX)) { - tab_matches_.emplace_back(BASE_CMD + " " + arg); + std::string match = BASE_CMD; + match += ' '; + match += arg; + tab_matches_.push_back(std::move(match)); } } } diff --git a/source/game/ui/console_commands.cpp b/source/game/ui/console_commands.cpp index f2dd8a6..e886238 100644 --- a/source/game/ui/console_commands.cpp +++ b/source/game/ui/console_commands.cpp @@ -259,7 +259,8 @@ static auto cmdZoom(const std::vector& args) -> std::string { if (N == Options::window.zoom) { return "Zoom already " + std::to_string(N); } Screen::get()->setWindowZoom(N); return "Zoom " + std::to_string(Options::window.zoom); - } catch (...) {} + } catch (...) { /* @INTENTIONAL: camp YAML malformat → conservem default */ + } return "usage: zoom [up|down|<1-" + std::to_string(Screen::getMaxZoom()) + ">]"; } @@ -912,7 +913,8 @@ static auto cmdPlayer(const std::vector& args) -> std::string { int color = -1; try { color = std::stoi(args[1]); - } catch (...) {} + } catch (...) { /* @INTENTIONAL: camp YAML malformat → conservem default */ + } if (color < 0 || color > 15) { return "usage: player color <0-15>|default"; } if (!GameControl::change_player_color) { return "Game not initialized"; } GameControl::change_player_color(color); diff --git a/source/game/ui/notifier.cpp b/source/game/ui/notifier.cpp index 6086dbf..32471ec 100644 --- a/source/game/ui/notifier.cpp +++ b/source/game/ui/notifier.cpp @@ -117,8 +117,6 @@ void Notifier::update(float delta_time) { } case Status::FINISHED: - break; - default: break; } @@ -172,7 +170,7 @@ void Notifier::show(std::vector texts, const Style& style, int icon const int ICON_SPACE = icon >= 0 ? ICON_SIZE + PADDING_IN_H : 0; const TextAlign TEXT_IS = ICON_SPACE > 0 ? TextAlign::LEFT : style.text_align; const float WIDTH = Options::game.width - (PADDING_OUT * 2); - const float HEIGHT = (TEXT_SIZE * texts.size()) + (PADDING_IN_V * 2); + const float HEIGHT = (TEXT_SIZE * static_cast(texts.size())) + (PADDING_IN_V * 2); const auto SHAPE = style.shape; // Posición horizontal @@ -287,7 +285,7 @@ void Notifier::clearNotifications() { } // Y absoluta de la base de la pila (justo debajo de Console, o 0 si no hay Console) -auto Notifier::getStackBaseY() const -> int { +auto Notifier::getStackBaseY() -> int { return Console::get() != nullptr ? Console::get()->getVisibleHeight() : 0; } @@ -297,7 +295,7 @@ auto Notifier::getVisibleHeight() const -> int { for (const auto& n : notifications_) { if (n.state == Status::FINISHED) { continue; } const int N_BOTTOM = static_cast(n.rect.y + n.rect.h); - if (N_BOTTOM > bottom) { bottom = N_BOTTOM; } + bottom = std::max(N_BOTTOM, bottom); } return bottom; } diff --git a/source/game/ui/notifier.hpp b/source/game/ui/notifier.hpp index a907fbd..af2236f 100644 --- a/source/game/ui/notifier.hpp +++ b/source/game/ui/notifier.hpp @@ -98,9 +98,9 @@ class Notifier { static Notifier* notifier; // Métodos privados - void clearFinishedNotifications(); // Elimina las notificaciones finalizadas - void clearNotifications(); // Finaliza y elimina todas las notificaciones activas - [[nodiscard]] auto getStackBaseY() const -> int; // Y absoluta de la base de la pila (leída de Console) + void clearFinishedNotifications(); // Elimina las notificaciones finalizadas + void clearNotifications(); // Finaliza y elimina todas las notificaciones activas + [[nodiscard]] static auto getStackBaseY() -> int; // Y absoluta de la base de la pila (leída de Console) // Constructor y destructor privados [SINGLETON] Notifier(const std::string& icon_file, const std::string& text); diff --git a/source/utils/delta_timer.cpp b/source/utils/delta_timer.cpp index 0e8d82e..620a51d 100644 --- a/source/utils/delta_timer.cpp +++ b/source/utils/delta_timer.cpp @@ -2,8 +2,7 @@ DeltaTimer::DeltaTimer() noexcept : last_counter_(SDL_GetPerformanceCounter()), - perf_freq_(static_cast(SDL_GetPerformanceFrequency())), - time_scale_(1.0F) { + perf_freq_(static_cast(SDL_GetPerformanceFrequency())) { } auto DeltaTimer::tick() noexcept -> float { diff --git a/source/utils/delta_timer.hpp b/source/utils/delta_timer.hpp index deb6f39..c5fa206 100644 --- a/source/utils/delta_timer.hpp +++ b/source/utils/delta_timer.hpp @@ -24,5 +24,5 @@ class DeltaTimer { private: Uint64 last_counter_; double perf_freq_; - float time_scale_; + float time_scale_{1.0F}; };