From a48fe51f73f36b1eb1c53390c05a4ee715569041 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 14 May 2026 19:24:02 +0200 Subject: [PATCH] manuals tidy tier 3a: rondes, ternaris, anyofallof, padding, etc. --- source/core/audio/audio.cpp | 2 +- source/core/audio/audio.hpp | 3 ++- source/core/audio/jail_audio.hpp | 8 ++++++-- source/core/input/key_config.cpp | 8 ++------ source/core/jail/jdraw8.cpp | 4 +++- source/core/jail/jinput.cpp | 7 +------ source/core/locale/locale.cpp | 6 +++++- source/core/rendering/menu.cpp | 18 +++++++++++++++--- source/core/rendering/overlay.hpp | 4 ++-- .../core/rendering/sdl3gpu/sdl3gpu_shader.cpp | 2 +- source/game/modulegame.cpp | 12 ++++++++---- source/game/options.cpp | 3 ++- source/game/scenes/slides_scene.cpp | 9 ++++++--- 13 files changed, 54 insertions(+), 32 deletions(-) diff --git a/source/core/audio/audio.cpp b/source/core/audio/audio.cpp index 922b4ae..da5800b 100644 --- a/source/core/audio/audio.cpp +++ b/source/core/audio/audio.cpp @@ -8,7 +8,7 @@ // Implementación de stb_vorbis (debe estar ANTES de incluir jail_audio.hpp). // clang-format off #undef STB_VORBIS_HEADER_ONLY -#include "external/stb_vorbis.c" +#include "external/stb_vorbis.c" // NOLINT(bugprone-suspicious-include): stb header-only library // 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. #undef L diff --git a/source/core/audio/audio.hpp b/source/core/audio/audio.hpp index 7753904..ae795a1 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 std::unique_ptr #include // Para string @@ -62,7 +63,7 @@ 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); + 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 cb46012..e2e86e8 100644 --- a/source/core/audio/jail_audio.hpp +++ b/source/core/audio/jail_audio.hpp @@ -12,7 +12,7 @@ #include // Para std::vector #define STB_VORBIS_HEADER_ONLY -#include "external/stb_vorbis.c" // Para stb_vorbis_open_memory i streaming +#include "external/stb_vorbis.c" // NOLINT(bugprone-suspicious-include): stb header-only library // Deleter stateless per a buffers reservats amb `SDL_malloc` / `SDL_LoadWAV*`. // Compatible amb `std::unique_ptr` — zero size @@ -57,10 +57,10 @@ struct JA_Sound_t { struct JA_Channel_t { JA_Sound_t* sound{nullptr}; + SDL_AudioStream* stream{nullptr}; int pos{0}; int times{0}; int group{0}; - SDL_AudioStream* stream{nullptr}; JA_Channel_state state{JA_CHANNEL_FREE}; }; @@ -339,6 +339,10 @@ inline auto JA_LoadMusic(const char* filename) -> JA_Music_t* { fseek(f, 0, SEEK_END); long fsize = ftell(f); fseek(f, 0, SEEK_SET); + if (fsize <= 0) { + fclose(f); + return nullptr; + } auto* buffer = static_cast(malloc(fsize + 1)); if (buffer == nullptr) { fclose(f); diff --git a/source/core/input/key_config.cpp b/source/core/input/key_config.cpp index 0e8b66c..71997cf 100644 --- a/source/core/input/key_config.cpp +++ b/source/core/input/key_config.cpp @@ -1,5 +1,6 @@ #include "core/input/key_config.hpp" +#include #include #include #include @@ -154,12 +155,7 @@ namespace KeyConfig { if (sc == SDL_SCANCODE_UNKNOWN) { return false; } - for (const auto& e : entries_) { - if (e.scancode == sc) { - return true; - } - } - return false; + return std::ranges::any_of(entries_, [sc](const auto& e) { return e.scancode == sc; }); } auto entries() -> const std::vector& { diff --git a/source/core/jail/jdraw8.cpp b/source/core/jail/jdraw8.cpp index 45805ae..7316e9a 100644 --- a/source/core/jail/jdraw8.cpp +++ b/source/core/jail/jdraw8.cpp @@ -12,7 +12,9 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-but-set-variable" #endif +// NOLINTBEGIN(clang-analyzer-unix.Malloc): codi extern de tercers, no l'auditem. #include "external/gif.h" +// NOLINTEND(clang-analyzer-unix.Malloc) #if defined(__clang__) #pragma clang diagnostic pop #elif defined(__GNUC__) @@ -26,7 +28,7 @@ Uint32* pixel_data = nullptr; void JD8_Init() { screen = new Uint8[64000]{}; main_palette = new Color[256]{}; - pixel_data = new Uint32[320 * 200]{}; + pixel_data = new Uint32[std::size_t{320} * 200]{}; } void JD8_Quit() { diff --git a/source/core/jail/jinput.cpp b/source/core/jail/jinput.cpp index a30cc11..9f1329a 100644 --- a/source/core/jail/jinput.cpp +++ b/source/core/jail/jinput.cpp @@ -106,12 +106,7 @@ auto JI_KeyPressed(int key) -> bool { if (static_cast(keystates[key]) != 0) { return true; } - for (auto& virtual_keystate : virtual_keystates) { - if (virtual_keystate[key] != 0) { - return true; - } - } - return false; + return std::ranges::any_of(virtual_keystates, [key](const auto& vk) { return vk[key] != 0; }); } auto JI_CheatActivated(const char* cheat_code) -> bool { diff --git a/source/core/locale/locale.cpp b/source/core/locale/locale.cpp index 80a6bea..547d4a8 100644 --- a/source/core/locale/locale.cpp +++ b/source/core/locale/locale.cpp @@ -16,7 +16,11 @@ namespace Locale { if (node.is_mapping()) { for (auto it = node.begin(); it != node.end(); ++it) { auto key = it.key().get_value(); - std::string full = prefix.empty() ? key : prefix + "." + key; + std::string full = prefix; + if (!full.empty()) { + full += "."; + } + full += key; traverse(it.value(), full); } } else if (node.is_scalar()) { diff --git a/source/core/rendering/menu.cpp b/source/core/rendering/menu.cpp index a54fbf0..66f3122 100644 --- a/source/core/rendering/menu.cpp +++ b/source/core/rendering/menu.cpp @@ -223,7 +223,7 @@ namespace Menu { // Converteix volum 0..1 a percentatge i ho formata com "50%" static auto volPct(float v) -> std::string { - int pct = static_cast((v * 100.0F) + 0.5F); + int pct = static_cast(std::lround(v * 100.0F)); pct = std::max(pct, 0); pct = std::min(pct, 100); char buf[8]; @@ -605,12 +605,24 @@ namespace Menu { font_->drawClipped(pixel_data, box_x + BOX_W - ITEM_PAD_X - aw + x_offset, y, arrow, ac, clip_x_min, clip_x_max, clip_y_min, clip_y_max); } else if (item.kind == ItemKind::KeyBind) { bool this_capturing = (capturing_ == item.scancode); - const char* text = this_capturing ? Locale::get("menu.values.press_key") : ((item.scancode != nullptr) ? SDL_GetScancodeName(*item.scancode) : ""); + const char* text = nullptr; + if (this_capturing) { + text = Locale::get("menu.values.press_key"); + } else if (item.scancode != nullptr) { + text = SDL_GetScancodeName(*item.scancode); + } else { + text = ""; + } if ((text == nullptr) || (*text == 0)) { text = Locale::get("menu.values.unknown"); } int tw = font_->width(text); - Uint32 tc = this_capturing ? 0xFF00FFFF : (selected ? CURSOR_COLOR : VALUE_COLOR); + Uint32 tc = 0; + if (this_capturing) { + tc = 0xFF00FFFF; + } else { + tc = selected ? CURSOR_COLOR : VALUE_COLOR; + } font_->drawClipped(pixel_data, box_x + BOX_W - ITEM_PAD_X - tw + x_offset, y, text, tc, clip_x_min, clip_x_max, clip_y_min, clip_y_max); } else if (item.getValue) { std::string value = item.getValue(); diff --git a/source/core/rendering/overlay.hpp b/source/core/rendering/overlay.hpp index 9ec3cbb..6d5a4b5 100644 --- a/source/core/rendering/overlay.hpp +++ b/source/core/rendering/overlay.hpp @@ -14,13 +14,13 @@ namespace Overlay { void render(Uint32* pixel_data); // Posició + animació d'una notificació - enum class NotifPosition { + enum class NotifPosition : std::uint8_t { TOP_LEFT_SLIDE, // Cantó superior esquerra, slide horizontal des de fora TOP_CENTER_DROP, // Centrat horitzontal, baixa des de sobre }; // Estil de la notificació: caixa de fons, ombra o contorn del text - enum class NotifStyle { + enum class NotifStyle : std::uint8_t { BOX, // Rectangle de fons amb accent_color SHADOW, // Sense fons, text amb ombra (offset +1,+1) en accent_color OUTLINE, // Sense fons, text amb contorn 4-direccional en accent_color diff --git a/source/core/rendering/sdl3gpu/sdl3gpu_shader.cpp b/source/core/rendering/sdl3gpu/sdl3gpu_shader.cpp index fd3c10c..9516943 100644 --- a/source/core/rendering/sdl3gpu/sdl3gpu_shader.cpp +++ b/source/core/rendering/sdl3gpu/sdl3gpu_shader.cpp @@ -767,7 +767,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/game/modulegame.cpp b/source/game/modulegame.cpp index a71decc..9e60d35 100644 --- a/source/game/modulegame.cpp +++ b/source/game/modulegame.cpp @@ -34,10 +34,14 @@ void ModuleGame::onEnter() { // Audio::playMusic ja és idempotent: si la pista actual coincideix amb la // demanada, no fa res. Per això podem cridar-lo cada onEnter sense // desencadenar restarts indesitjats. - const char* music_name = info::ctx.num_piramide == 3 ? "piramide_3.ogg" - : info::ctx.num_piramide == 2 ? "piramide_2.ogg" - : info::ctx.num_piramide == 6 ? "secreta.ogg" - : "piramide_1_4_5.ogg"; + const char* music_name = "piramide_1_4_5.ogg"; + if (info::ctx.num_piramide == 3) { + music_name = "piramide_3.ogg"; + } else if (info::ctx.num_piramide == 2) { + music_name = "piramide_2.ogg"; + } else if (info::ctx.num_piramide == 6) { + music_name = "secreta.ogg"; + } Audio::get()->playMusic(music_name); // Arranca el fade-in tick-based. El `PaletteFade` avança un pas (de diff --git a/source/game/options.cpp b/source/game/options.cpp index 30cb82b..0bfa3b9 100644 --- a/source/game/options.cpp +++ b/source/game/options.cpp @@ -346,7 +346,7 @@ namespace Options { file << " shader_enabled: " << (video.shader_enabled ? "true" : "false") << "\n"; file << " supersampling: " << (video.supersampling ? "true" : "false") << "\n"; { - const char* m = "integer"; + const char* m = nullptr; switch (video.scaling_mode) { case ScalingMode::DISABLED: m = "disabled"; @@ -361,6 +361,7 @@ namespace Options { m = "overscan"; break; case ScalingMode::INTEGER: + default: m = "integer"; break; } diff --git a/source/game/scenes/slides_scene.cpp b/source/game/scenes/slides_scene.cpp index 5baffa9..e354ba9 100644 --- a/source/game/scenes/slides_scene.cpp +++ b/source/game/scenes/slides_scene.cpp @@ -117,9 +117,12 @@ namespace scenes { case Phase::Slide2Enter: case Phase::Slide3Enter: { phase_acc_ms_ += delta_ms; - const int slide_idx = (phase_ == Phase::Slide1Enter ? 0 - : phase_ == Phase::Slide2Enter ? 1 - : 2); + int slide_idx = 2; + if (phase_ == Phase::Slide1Enter) { + slide_idx = 0; + } else if (phase_ == Phase::Slide2Enter) { + slide_idx = 1; + } const float t = std::min(1.0F, static_cast(phase_acc_ms_) / static_cast(SCROLL_MS)); const float eased = Easing::outCubic(t); const int pos_x = Easing::lerpInt(SLIDE_START_X[slide_idx], 0, eased);