manuals tidy tier 3a: rondes, ternaris, anyofallof, padding, etc.

This commit is contained in:
2026-05-14 19:24:02 +02:00
parent 0b82be193f
commit a48fe51f73
13 changed files with 54 additions and 32 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
// Implementación de stb_vorbis (debe estar ANTES de incluir jail_audio.hpp). // Implementación de stb_vorbis (debe estar ANTES de incluir jail_audio.hpp).
// clang-format off // clang-format off
#undef STB_VORBIS_HEADER_ONLY #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 // 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. // perquè xocarien amb noms de paràmetres de plantilla en altres headers.
#undef L #undef L
+2 -1
View File
@@ -1,5 +1,6 @@
#pragma once #pragma once
#include <cmath> // Para std::lround
#include <cstdint> // Para int8_t, uint8_t #include <cstdint> // Para int8_t, uint8_t
#include <memory> // Para std::unique_ptr #include <memory> // Para std::unique_ptr
#include <string> // Para string #include <string> // Para string
@@ -62,7 +63,7 @@ class Audio {
// --- Helpers de conversió per a la capa de presentació --- // --- Helpers de conversió per a la capa de presentació ---
// UI (menús, notificacions) manega enters 0..100; internament viu float 0..1. // UI (menús, notificacions) manega enters 0..100; internament viu float 0..1.
static constexpr auto toPercent(float volume) -> int { static constexpr auto toPercent(float volume) -> int {
return static_cast<int>((volume * 100.0F) + 0.5F); return static_cast<int>(std::lround(volume * 100.0F));
} }
static constexpr auto fromPercent(int percent) -> float { static constexpr auto fromPercent(int percent) -> float {
return static_cast<float>(percent) / 100.0F; return static_cast<float>(percent) / 100.0F;
+6 -2
View File
@@ -12,7 +12,7 @@
#include <vector> // Para std::vector #include <vector> // Para std::vector
#define STB_VORBIS_HEADER_ONLY #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*`. // Deleter stateless per a buffers reservats amb `SDL_malloc` / `SDL_LoadWAV*`.
// Compatible amb `std::unique_ptr<Uint8[], SDLFreeDeleter>` — zero size // Compatible amb `std::unique_ptr<Uint8[], SDLFreeDeleter>` — zero size
@@ -57,10 +57,10 @@ struct JA_Sound_t {
struct JA_Channel_t { struct JA_Channel_t {
JA_Sound_t* sound{nullptr}; JA_Sound_t* sound{nullptr};
SDL_AudioStream* stream{nullptr};
int pos{0}; int pos{0};
int times{0}; int times{0};
int group{0}; int group{0};
SDL_AudioStream* stream{nullptr};
JA_Channel_state state{JA_CHANNEL_FREE}; 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); fseek(f, 0, SEEK_END);
long fsize = ftell(f); long fsize = ftell(f);
fseek(f, 0, SEEK_SET); fseek(f, 0, SEEK_SET);
if (fsize <= 0) {
fclose(f);
return nullptr;
}
auto* buffer = static_cast<Uint8*>(malloc(fsize + 1)); auto* buffer = static_cast<Uint8*>(malloc(fsize + 1));
if (buffer == nullptr) { if (buffer == nullptr) {
fclose(f); fclose(f);
+2 -6
View File
@@ -1,5 +1,6 @@
#include "core/input/key_config.hpp" #include "core/input/key_config.hpp"
#include <algorithm>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <utility> #include <utility>
@@ -154,12 +155,7 @@ namespace KeyConfig {
if (sc == SDL_SCANCODE_UNKNOWN) { if (sc == SDL_SCANCODE_UNKNOWN) {
return false; return false;
} }
for (const auto& e : entries_) { return std::ranges::any_of(entries_, [sc](const auto& e) { return e.scancode == sc; });
if (e.scancode == sc) {
return true;
}
}
return false;
} }
auto entries() -> const std::vector<KeyEntry>& { auto entries() -> const std::vector<KeyEntry>& {
+3 -1
View File
@@ -12,7 +12,9 @@
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-but-set-variable" #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#endif #endif
// NOLINTBEGIN(clang-analyzer-unix.Malloc): codi extern de tercers, no l'auditem.
#include "external/gif.h" #include "external/gif.h"
// NOLINTEND(clang-analyzer-unix.Malloc)
#if defined(__clang__) #if defined(__clang__)
#pragma clang diagnostic pop #pragma clang diagnostic pop
#elif defined(__GNUC__) #elif defined(__GNUC__)
@@ -26,7 +28,7 @@ Uint32* pixel_data = nullptr;
void JD8_Init() { void JD8_Init() {
screen = new Uint8[64000]{}; screen = new Uint8[64000]{};
main_palette = new Color[256]{}; main_palette = new Color[256]{};
pixel_data = new Uint32[320 * 200]{}; pixel_data = new Uint32[std::size_t{320} * 200]{};
} }
void JD8_Quit() { void JD8_Quit() {
+1 -6
View File
@@ -106,12 +106,7 @@ auto JI_KeyPressed(int key) -> bool {
if (static_cast<int>(keystates[key]) != 0) { if (static_cast<int>(keystates[key]) != 0) {
return true; return true;
} }
for (auto& virtual_keystate : virtual_keystates) { return std::ranges::any_of(virtual_keystates, [key](const auto& vk) { return vk[key] != 0; });
if (virtual_keystate[key] != 0) {
return true;
}
}
return false;
} }
auto JI_CheatActivated(const char* cheat_code) -> bool { auto JI_CheatActivated(const char* cheat_code) -> bool {
+5 -1
View File
@@ -16,7 +16,11 @@ namespace Locale {
if (node.is_mapping()) { if (node.is_mapping()) {
for (auto it = node.begin(); it != node.end(); ++it) { for (auto it = node.begin(); it != node.end(); ++it) {
auto key = it.key().get_value<std::string>(); auto key = it.key().get_value<std::string>();
std::string full = prefix.empty() ? key : prefix + "." + key; std::string full = prefix;
if (!full.empty()) {
full += ".";
}
full += key;
traverse(it.value(), full); traverse(it.value(), full);
} }
} else if (node.is_scalar()) { } else if (node.is_scalar()) {
+15 -3
View File
@@ -223,7 +223,7 @@ namespace Menu {
// Converteix volum 0..1 a percentatge i ho formata com "50%" // Converteix volum 0..1 a percentatge i ho formata com "50%"
static auto volPct(float v) -> std::string { static auto volPct(float v) -> std::string {
int pct = static_cast<int>((v * 100.0F) + 0.5F); int pct = static_cast<int>(std::lround(v * 100.0F));
pct = std::max(pct, 0); pct = std::max(pct, 0);
pct = std::min(pct, 100); pct = std::min(pct, 100);
char buf[8]; 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); 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) { } else if (item.kind == ItemKind::KeyBind) {
bool this_capturing = (capturing_ == item.scancode); 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)) { if ((text == nullptr) || (*text == 0)) {
text = Locale::get("menu.values.unknown"); text = Locale::get("menu.values.unknown");
} }
int tw = font_->width(text); 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); 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) { } else if (item.getValue) {
std::string value = item.getValue(); std::string value = item.getValue();
+2 -2
View File
@@ -14,13 +14,13 @@ namespace Overlay {
void render(Uint32* pixel_data); void render(Uint32* pixel_data);
// Posició + animació d'una notificació // 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_LEFT_SLIDE, // Cantó superior esquerra, slide horizontal des de fora
TOP_CENTER_DROP, // Centrat horitzontal, baixa des de sobre TOP_CENTER_DROP, // Centrat horitzontal, baixa des de sobre
}; };
// Estil de la notificació: caixa de fons, ombra o contorn del text // 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 BOX, // Rectangle de fons amb accent_color
SHADOW, // Sense fons, text amb ombra (offset +1,+1) en 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 OUTLINE, // Sense fons, text amb contorn 4-direccional en accent_color
@@ -767,7 +767,7 @@ namespace Rendering {
} }
// Copia directa — el upscale lo hace la GPU en el primer render pass // Copia directa — el upscale lo hace la GPU en el primer render pass
std::memcpy(mapped, pixels, static_cast<size_t>(width * height * 4)); std::memcpy(mapped, pixels, static_cast<size_t>(width) * static_cast<size_t>(height) * 4);
SDL_UnmapGPUTransferBuffer(device_, upload_buffer_); SDL_UnmapGPUTransferBuffer(device_, upload_buffer_);
} }
+8 -4
View File
@@ -34,10 +34,14 @@ void ModuleGame::onEnter() {
// Audio::playMusic ja és idempotent: si la pista actual coincideix amb la // Audio::playMusic ja és idempotent: si la pista actual coincideix amb la
// demanada, no fa res. Per això podem cridar-lo cada onEnter sense // demanada, no fa res. Per això podem cridar-lo cada onEnter sense
// desencadenar restarts indesitjats. // desencadenar restarts indesitjats.
const char* music_name = info::ctx.num_piramide == 3 ? "piramide_3.ogg" const char* music_name = "piramide_1_4_5.ogg";
: info::ctx.num_piramide == 2 ? "piramide_2.ogg" if (info::ctx.num_piramide == 3) {
: info::ctx.num_piramide == 6 ? "secreta.ogg" music_name = "piramide_3.ogg";
: "piramide_1_4_5.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); Audio::get()->playMusic(music_name);
// Arranca el fade-in tick-based. El `PaletteFade` avança un pas (de // Arranca el fade-in tick-based. El `PaletteFade` avança un pas (de
+2 -1
View File
@@ -346,7 +346,7 @@ namespace Options {
file << " shader_enabled: " << (video.shader_enabled ? "true" : "false") << "\n"; file << " shader_enabled: " << (video.shader_enabled ? "true" : "false") << "\n";
file << " supersampling: " << (video.supersampling ? "true" : "false") << "\n"; file << " supersampling: " << (video.supersampling ? "true" : "false") << "\n";
{ {
const char* m = "integer"; const char* m = nullptr;
switch (video.scaling_mode) { switch (video.scaling_mode) {
case ScalingMode::DISABLED: case ScalingMode::DISABLED:
m = "disabled"; m = "disabled";
@@ -361,6 +361,7 @@ namespace Options {
m = "overscan"; m = "overscan";
break; break;
case ScalingMode::INTEGER: case ScalingMode::INTEGER:
default:
m = "integer"; m = "integer";
break; break;
} }
+6 -3
View File
@@ -117,9 +117,12 @@ namespace scenes {
case Phase::Slide2Enter: case Phase::Slide2Enter:
case Phase::Slide3Enter: { case Phase::Slide3Enter: {
phase_acc_ms_ += delta_ms; phase_acc_ms_ += delta_ms;
const int slide_idx = (phase_ == Phase::Slide1Enter ? 0 int slide_idx = 2;
: phase_ == Phase::Slide2Enter ? 1 if (phase_ == Phase::Slide1Enter) {
: 2); slide_idx = 0;
} else if (phase_ == Phase::Slide2Enter) {
slide_idx = 1;
}
const float t = std::min(1.0F, static_cast<float>(phase_acc_ms_) / static_cast<float>(SCROLL_MS)); const float t = std::min(1.0F, static_cast<float>(phase_acc_ms_) / static_cast<float>(SCROLL_MS));
const float eased = Easing::outCubic(t); const float eased = Easing::outCubic(t);
const int pos_x = Easing::lerpInt(SLIDE_START_X[slide_idx], 0, eased); const int pos_x = Easing::lerpInt(SLIDE_START_X[slide_idx], 0, eased);