fix: tidy statics, instance, stretch43, fill/find_if ranges, NOLINT externs

This commit is contained in:
2026-05-16 15:17:38 +02:00
parent ae359f4a1e
commit b984e6041e
15 changed files with 77 additions and 74 deletions
+4 -4
View File
@@ -176,16 +176,16 @@ auto Audio::getRealMusicState() -> MusicState {
// Establece el volumen de los sonidos (float 0.0..1.0) // Establece el volumen de los sonidos (float 0.0..1.0)
void Audio::setSoundVolume(float sound_volume, Group group) const { void Audio::setSoundVolume(float sound_volume, Group group) const {
sound_volume = std::clamp(sound_volume, MIN_VOLUME, MAX_VOLUME); sound_volume = std::clamp(sound_volume, MIN_VOLUME, MAX_VOLUME);
const bool active = enabled_ && sound_enabled_; const bool ACTIVE = enabled_ && sound_enabled_;
const float CONVERTED_VOLUME = active ? sound_volume * Options::audio.volume : 0.0F; const float CONVERTED_VOLUME = ACTIVE ? sound_volume * Options::audio.volume : 0.0F;
Ja::setSoundVolume(CONVERTED_VOLUME, static_cast<int>(group)); Ja::setSoundVolume(CONVERTED_VOLUME, static_cast<int>(group));
} }
// Establece el volumen de la música (float 0.0..1.0) // Establece el volumen de la música (float 0.0..1.0)
void Audio::setMusicVolume(float music_volume) const { void Audio::setMusicVolume(float music_volume) const {
music_volume = std::clamp(music_volume, MIN_VOLUME, MAX_VOLUME); music_volume = std::clamp(music_volume, MIN_VOLUME, MAX_VOLUME);
const bool active = enabled_ && music_enabled_; const bool ACTIVE = enabled_ && music_enabled_;
const float CONVERTED_VOLUME = active ? music_volume * Options::audio.volume : 0.0F; const float CONVERTED_VOLUME = ACTIVE ? music_volume * Options::audio.volume : 0.0F;
Ja::setMusicVolume(CONVERTED_VOLUME); Ja::setMusicVolume(CONVERTED_VOLUME);
} }
+2 -2
View File
@@ -259,7 +259,7 @@ namespace Ja {
sdl_audio_device = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &audio_spec); sdl_audio_device = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &audio_spec);
if (sdl_audio_device == 0) { std::cout << "Failed to initialize SDL audio!" << '\n'; } if (sdl_audio_device == 0) { std::cout << "Failed to initialize SDL audio!" << '\n'; }
for (auto& ch : channels) { ch.state = ChannelState::FREE; } for (auto& ch : channels) { ch.state = ChannelState::FREE; }
std::fill(std::begin(sound_volume), std::end(sound_volume), 0.5F); std::ranges::fill(sound_volume, 0.5F);
} }
inline void quit() { inline void quit() {
@@ -663,7 +663,7 @@ namespace Ja {
const float V = SDL_clamp(volume, 0.0F, 1.0F); const float V = SDL_clamp(volume, 0.0F, 1.0F);
if (group == -1) { if (group == -1) {
std::fill(std::begin(sound_volume), std::end(sound_volume), V); std::ranges::fill(sound_volume, V);
} else if (group >= 0 && group < MAX_GROUPS) { } else if (group >= 0 && group < MAX_GROUPS) {
sound_volume[group] = V; sound_volume[group] = V;
} else { } else {
+28 -28
View File
@@ -11,13 +11,13 @@
namespace KeyConfig { namespace KeyConfig {
namespace { namespace {
std::vector<KeyEntry> entries_; std::vector<KeyEntry> key_entries;
std::unordered_map<std::string, size_t> index_; std::unordered_map<std::string, size_t> index_table;
std::string overrides_path_; std::string overrides_path;
auto findIndex(const std::string& id) -> size_t { auto findIndex(const std::string& id) -> size_t {
auto it = index_.find(id); auto it = index_table.find(id);
if (it == index_.end()) { if (it == index_table.end()) {
return SIZE_MAX; return SIZE_MAX;
} }
return it->second; return it->second;
@@ -52,10 +52,10 @@ namespace KeyConfig {
entry.scancode = sc; entry.scancode = sc;
entry.default_scancode = sc; entry.default_scancode = sc;
index_[entry.id] = entries_.size(); index_table[entry.id] = key_entries.size();
entries_.push_back(std::move(entry)); key_entries.push_back(std::move(entry));
} }
std::cout << "KeyConfig: " << entries_.size() << " tecles carregades de " std::cout << "KeyConfig: " << key_entries.size() << " tecles carregades de "
<< defaults_resource_path << '\n'; << defaults_resource_path << '\n';
} catch (const fkyaml::exception& e) { } catch (const fkyaml::exception& e) {
std::cerr << "KeyConfig: error parsejant YAML: " << e.what() << '\n'; std::cerr << "KeyConfig: error parsejant YAML: " << e.what() << '\n';
@@ -93,8 +93,8 @@ namespace KeyConfig {
<< "' per '" << id << "'\n"; << "' per '" << id << "'\n";
continue; continue;
} }
entries_[idx].scancode = sc; key_entries[idx].scancode = sc;
entries_[idx].code = code; key_entries[idx].code = code;
applied++; applied++;
} }
if (applied > 0) { if (applied > 0) {
@@ -109,20 +109,20 @@ namespace KeyConfig {
void init(const std::string& defaults_resource_path, void init(const std::string& defaults_resource_path,
const std::string& user_overrides_disk_path) { const std::string& user_overrides_disk_path) {
entries_.clear(); key_entries.clear();
index_.clear(); index_table.clear();
overrides_path_ = user_overrides_disk_path; overrides_path = user_overrides_disk_path;
loadDefaults(defaults_resource_path); loadDefaults(defaults_resource_path);
if (!overrides_path_.empty()) { if (!overrides_path.empty()) {
applyOverrides(overrides_path_); applyOverrides(overrides_path);
} }
} }
void destroy() { void destroy() {
entries_.clear(); key_entries.clear();
index_.clear(); index_table.clear();
overrides_path_.clear(); overrides_path.clear();
} }
auto scancode(const std::string& id) -> SDL_Scancode { auto scancode(const std::string& id) -> SDL_Scancode {
@@ -130,7 +130,7 @@ namespace KeyConfig {
if (idx == SIZE_MAX) { if (idx == SIZE_MAX) {
return SDL_SCANCODE_UNKNOWN; return SDL_SCANCODE_UNKNOWN;
} }
return entries_[idx].scancode; return key_entries[idx].scancode;
} }
auto scancodePtr(const std::string& id) -> SDL_Scancode* { auto scancodePtr(const std::string& id) -> SDL_Scancode* {
@@ -138,7 +138,7 @@ namespace KeyConfig {
if (idx == SIZE_MAX) { if (idx == SIZE_MAX) {
return nullptr; return nullptr;
} }
return &entries_[idx].scancode; return &key_entries[idx].scancode;
} }
void setScancode(const std::string& id, SDL_Scancode sc) { void setScancode(const std::string& id, SDL_Scancode sc) {
@@ -146,38 +146,38 @@ namespace KeyConfig {
if (idx == SIZE_MAX) { if (idx == SIZE_MAX) {
return; return;
} }
entries_[idx].scancode = sc; key_entries[idx].scancode = sc;
const char* name = SDL_GetScancodeName(sc); const char* name = SDL_GetScancodeName(sc);
entries_[idx].code = (name != nullptr) ? name : ""; key_entries[idx].code = (name != nullptr) ? name : "";
} }
auto isGuiKey(SDL_Scancode sc) -> bool { auto isGuiKey(SDL_Scancode sc) -> bool {
if (sc == SDL_SCANCODE_UNKNOWN) { if (sc == SDL_SCANCODE_UNKNOWN) {
return false; return false;
} }
return std::ranges::any_of(entries_, [sc](const auto& e) { return e.scancode == sc; }); return std::ranges::any_of(key_entries, [sc](const auto& e) { return e.scancode == sc; });
} }
auto entries() -> const std::vector<KeyEntry>& { auto entries() -> const std::vector<KeyEntry>& {
return entries_; return key_entries;
} }
auto saveOverrides() -> bool { auto saveOverrides() -> bool {
if (overrides_path_.empty()) { if (overrides_path.empty()) {
return false; return false;
} }
// Recull només les entrades remapeades. // Recull només les entrades remapeades.
std::vector<const KeyEntry*> changed; std::vector<const KeyEntry*> changed;
for (const auto& e : entries_) { for (const auto& e : key_entries) {
if (e.scancode != e.default_scancode) { if (e.scancode != e.default_scancode) {
changed.push_back(&e); changed.push_back(&e);
} }
} }
std::ofstream file(overrides_path_); std::ofstream file(overrides_path);
if (!file.is_open()) { if (!file.is_open()) {
std::cerr << "KeyConfig: no es pot escriure " << overrides_path_ << '\n'; std::cerr << "KeyConfig: no es pot escriure " << overrides_path << '\n';
return false; return false;
} }
+2 -2
View File
@@ -112,7 +112,7 @@ auto Jf::getConfigValue(const char* key) -> const char* {
if (config.empty()) { if (config.empty()) {
loadConfigValues(); loadConfigValues();
} }
const auto IT = std::find_if(config.begin(), config.end(), [key](const Keyvalue& pair) { return pair.key == key; }); const auto IT = std::ranges::find_if(config, [key](const Keyvalue& pair) { return pair.key == key; });
if (IT != config.end()) { if (IT != config.end()) {
thread_local std::string value_cache_; thread_local std::string value_cache_;
value_cache_ = IT->value; value_cache_ = IT->value;
@@ -125,7 +125,7 @@ void Jf::setConfigValue(const char* key, const char* value) {
if (config.empty()) { if (config.empty()) {
loadConfigValues(); loadConfigValues();
} }
const auto IT = std::find_if(config.begin(), config.end(), [key](const Keyvalue& pair) { return pair.key == key; }); const auto IT = std::ranges::find_if(config, [key](const Keyvalue& pair) { return pair.key == key; });
if (IT != config.end()) { if (IT != config.end()) {
IT->value = value; IT->value = value;
saveConfigValues(); saveConfigValues();
+6 -6
View File
@@ -9,7 +9,7 @@
namespace Locale { namespace Locale {
static std::unordered_map<std::string, std::string> strings_; static std::unordered_map<std::string, std::string> strings_table;
// Aplana un node YAML en claus amb notació punt // Aplana un node YAML en claus amb notació punt
static void traverse(const fkyaml::node& node, const std::string& prefix) { static void traverse(const fkyaml::node& node, const std::string& prefix) {
@@ -25,7 +25,7 @@ namespace Locale {
} }
} else if (node.is_scalar()) { } else if (node.is_scalar()) {
try { try {
strings_[prefix] = node.get_value<std::string>(); strings_table[prefix] = node.get_value<std::string>();
} catch (...) { } catch (...) {
// @INTENTIONAL: si el valor no és string vàlid, l'ignorem i continuem. // @INTENTIONAL: si el valor no és string vàlid, l'ignorem i continuem.
} }
@@ -42,9 +42,9 @@ namespace Locale {
try { try {
auto yaml = fkyaml::node::deserialize(content); auto yaml = fkyaml::node::deserialize(content);
strings_.clear(); strings_table.clear();
traverse(yaml, ""); traverse(yaml, "");
std::cout << "Locale loaded: " << strings_.size() << " string(s) from " << filename << '\n'; std::cout << "Locale loaded: " << strings_table.size() << " string(s) from " << filename << '\n';
return true; return true;
} catch (const fkyaml::exception& e) { } catch (const fkyaml::exception& e) {
std::cerr << "Locale: error parsing " << filename << ": " << e.what() << '\n'; std::cerr << "Locale: error parsing " << filename << ": " << e.what() << '\n';
@@ -53,8 +53,8 @@ namespace Locale {
} }
auto get(const char* key) -> const char* { auto get(const char* key) -> const char* {
auto it = strings_.find(key); auto it = strings_table.find(key);
if (it != strings_.end()) { if (it != strings_table.end()) {
return it->second.c_str(); return it->second.c_str();
} }
return key; // fallback: retorna la clau mateixa return key; // fallback: retorna la clau mateixa
+8 -8
View File
@@ -56,18 +56,18 @@ namespace {
} // namespace } // namespace
#endif // __EMSCRIPTEN__ #endif // __EMSCRIPTEN__
std::unique_ptr<Screen> Screen::instance_; std::unique_ptr<Screen> Screen::instance;
void Screen::init() { void Screen::init() {
instance_ = std::unique_ptr<Screen>(new Screen()); instance = std::unique_ptr<Screen>(new Screen());
} }
void Screen::destroy() { void Screen::destroy() {
instance_.reset(); instance.reset();
} }
auto Screen::get() -> Screen* { auto Screen::get() -> Screen* {
return instance_.get(); return instance.get();
} }
Screen::Screen() { Screen::Screen() {
@@ -178,7 +178,7 @@ void Screen::initShaders() {
shader_backend_->setScalingMode(Options::video.scaling_mode); shader_backend_->setScalingMode(Options::video.scaling_mode);
shader_backend_->setVSync(Options::video.vsync); shader_backend_->setVSync(Options::video.vsync);
shader_backend_->setTextureFilter(Options::video.texture_filter); shader_backend_->setTextureFilter(Options::video.texture_filter);
shader_backend_->setStretch4_3(Options::video.aspect_ratio_4_3); shader_backend_->setStretch43(Options::video.aspect_ratio_4_3);
shader_backend_->setDownscaleAlgo(Options::video.downscale_algo); shader_backend_->setDownscaleAlgo(Options::video.downscale_algo);
if (Options::video.supersampling) { if (Options::video.supersampling) {
@@ -346,7 +346,7 @@ auto Screen::toggleSupersampling() -> bool {
void Screen::toggleAspectRatio() { void Screen::toggleAspectRatio() {
Options::video.aspect_ratio_4_3 = !Options::video.aspect_ratio_4_3; Options::video.aspect_ratio_4_3 = !Options::video.aspect_ratio_4_3;
if (shader_backend_) { if (shader_backend_) {
shader_backend_->setStretch4_3(Options::video.aspect_ratio_4_3); shader_backend_->setStretch43(Options::video.aspect_ratio_4_3);
} else { } else {
applyFallbackPresentation(); applyFallbackPresentation();
} }
@@ -560,7 +560,7 @@ auto Screen::getActiveShaderName() const -> const char* {
} }
void Screen::updateRenderInfo() { void Screen::updateRenderInfo() {
static const Uint32 start_ticks = SDL_GetTicks(); static const Uint32 START_TICKS = SDL_GetTicks();
std::string driver = gpu_driver_.empty() ? "sdl" : toLower(gpu_driver_); std::string driver = gpu_driver_.empty() ? "sdl" : toLower(gpu_driver_);
// Segment 0: FPS + driver (sempre visible) // Segment 0: FPS + driver (sempre visible)
@@ -578,7 +578,7 @@ void Screen::updateRenderInfo() {
// Segment 3: hora (només si show_time) // Segment 3: hora (només si show_time)
char time_buf[32] = {0}; char time_buf[32] = {0};
if (Options::render_info.show_time) { if (Options::render_info.show_time) {
Uint32 elapsed = SDL_GetTicks() - start_ticks; Uint32 elapsed = SDL_GetTicks() - START_TICKS;
int minutes = elapsed / 60000; int minutes = elapsed / 60000;
int seconds = (elapsed / 1000) % 60; int seconds = (elapsed / 1000) % 60;
int centis = (elapsed / 10) % 100; int centis = (elapsed / 10) % 100;
+1 -1
View File
@@ -71,7 +71,7 @@ class Screen {
void applyFallbackPresentation(); // Logical presentation + scale mode per al path SDL_Renderer void applyFallbackPresentation(); // Logical presentation + scale mode per al path SDL_Renderer
void ensureFallbackInternalTexture(); // Recrea internal_texture_sdl_ si cal (fallback path) void ensureFallbackInternalTexture(); // Recrea internal_texture_sdl_ si cal (fallback path)
static std::unique_ptr<Screen> instance_; static std::unique_ptr<Screen> instance;
SDL_Window* window_{nullptr}; SDL_Window* window_{nullptr};
SDL_Renderer* renderer_{nullptr}; SDL_Renderer* renderer_{nullptr};
@@ -1286,7 +1286,7 @@ namespace Rendering {
} }
} }
void SDL3GPUShader::setStretch4_3(bool enabled) { void SDL3GPUShader::setStretch43(bool enabled) {
stretch_4_3_ = enabled; stretch_4_3_ = enabled;
if (!is_initialized_ || device_ == nullptr) { if (!is_initialized_ || device_ == nullptr) {
return; return;
@@ -118,8 +118,8 @@ namespace Rendering {
[[nodiscard]] auto getActiveShader() const -> ShaderType override { return active_shader_; } [[nodiscard]] auto getActiveShader() const -> ShaderType override { return active_shader_; }
// Estirament vertical 4:3 (fusionat amb l'upscale pass) // Estirament vertical 4:3 (fusionat amb l'upscale pass)
void setStretch4_3(bool enabled) override; void setStretch43(bool enabled) override;
[[nodiscard]] auto isStretch4_3() const -> bool override { return stretch_4_3_; } [[nodiscard]] auto isStretch43() const -> bool override { return stretch_4_3_; }
// Filtre de textura global (sempre aplicat, independent de 4:3) // Filtre de textura global (sempre aplicat, independent de 4:3)
void setTextureFilter(Options::TextureFilter filter) override { void setTextureFilter(Options::TextureFilter filter) override {
+2 -2
View File
@@ -171,8 +171,8 @@ namespace Rendering {
* @brief Activa/desactiva estirament vertical 4:3 (200→240 línies efectives). * @brief Activa/desactiva estirament vertical 4:3 (200→240 línies efectives).
* Només afecta el viewport, no les textures ni els shaders. * Només afecta el viewport, no les textures ni els shaders.
*/ */
virtual void setStretch4_3(bool /*enabled*/) {} virtual void setStretch43(bool /*enabled*/) {}
[[nodiscard]] virtual auto isStretch4_3() const -> bool { return false; } [[nodiscard]] virtual auto isStretch43() const -> bool { return false; }
/** /**
* @brief Filtre de textura global per a l'upscale final (sempre aplicat). * @brief Filtre de textura global per a l'upscale final (sempre aplicat).
+1
View File
@@ -12,6 +12,7 @@
// Forward declarations de gif.h (inclòs des de jdraw8.cpp, no es pot incloure dos vegades) // Forward declarations de gif.h (inclòs des de jdraw8.cpp, no es pot incloure dos vegades)
struct rgb; struct rgb;
// NOLINTNEXTLINE(readability-identifier-naming) — exportat per external/gif.h, no controlem el nom.
extern auto LoadGif(unsigned char* data, unsigned short* w, unsigned short* h) -> unsigned char*; extern auto LoadGif(unsigned char* data, unsigned short* w, unsigned short* h) -> unsigned char*;
Text::Text(const char* fnt_file, const char* gif_file) { Text::Text(const char* fnt_file, const char* gif_file) {
+2
View File
@@ -15,8 +15,10 @@
// ni inline, així que no podem tornar-lo a incloure aquí. Ens fiem de les // ni inline, així que no podem tornar-lo a incloure aquí. Ens fiem de les
// declaracions extern dels símbols que ens calen (linkatge C++ normal, // declaracions extern dels símbols que ens calen (linkatge C++ normal,
// igual que fa text.cpp). // igual que fa text.cpp).
// NOLINTBEGIN(readability-identifier-naming) — símbols externs de gif.h.
extern auto LoadGif(unsigned char* data, unsigned short* w, unsigned short* h) -> unsigned char*; extern auto LoadGif(unsigned char* data, unsigned short* w, unsigned short* h) -> unsigned char*;
extern auto LoadPalette(unsigned char* data) -> unsigned char*; extern auto LoadPalette(unsigned char* data) -> unsigned char*;
// NOLINTEND(readability-identifier-naming)
namespace Resource { namespace Resource {
+13 -13
View File
@@ -9,9 +9,9 @@
namespace ResourceHelper { namespace ResourceHelper {
namespace { namespace {
ResourcePack pack_; ResourcePack pack_obj;
bool pack_loaded_ = false; bool pack_loaded = false;
bool fallback_enabled_ = true; bool fallback_enabled = true;
auto readFromDisk(const std::string& relative_path) -> std::vector<uint8_t> { auto readFromDisk(const std::string& relative_path) -> std::vector<uint8_t> {
const std::string FULL = std::string(Jf::getResourceFolder()) + relative_path; const std::string FULL = std::string(Jf::getResourceFolder()) + relative_path;
@@ -32,11 +32,11 @@ namespace ResourceHelper {
} // namespace } // namespace
auto initializeResourceSystem(const std::string& pack_file, bool enable_fallback) -> bool { auto initializeResourceSystem(const std::string& pack_file, bool enable_fallback) -> bool {
fallback_enabled_ = enable_fallback; fallback_enabled = enable_fallback;
pack_loaded_ = pack_.loadPack(pack_file); pack_loaded = pack_obj.loadPack(pack_file);
if (pack_loaded_) { if (pack_loaded) {
std::cout << "ResourceHelper: pack loaded (" << pack_.getResourceCount() std::cout << "ResourceHelper: pack loaded (" << pack_obj.getResourceCount()
<< " entries) from " << pack_file << '\n'; << " entries) from " << pack_file << '\n';
} else if (enable_fallback) { } else if (enable_fallback) {
std::cout << "ResourceHelper: no pack at " << pack_file std::cout << "ResourceHelper: no pack at " << pack_file
@@ -50,22 +50,22 @@ namespace ResourceHelper {
} }
void shutdownResourceSystem() { void shutdownResourceSystem() {
pack_.clear(); pack_obj.clear();
pack_loaded_ = false; pack_loaded = false;
} }
auto loadFile(const std::string& relative_path) -> std::vector<uint8_t> { auto loadFile(const std::string& relative_path) -> std::vector<uint8_t> {
if (pack_loaded_ && pack_.hasResource(relative_path)) { if (pack_loaded && pack_obj.hasResource(relative_path)) {
return pack_.getResource(relative_path); return pack_obj.getResource(relative_path);
} }
if (fallback_enabled_) { if (fallback_enabled) {
return readFromDisk(relative_path); return readFromDisk(relative_path);
} }
return {}; return {};
} }
auto hasPack() -> bool { auto hasPack() -> bool {
return pack_loaded_; return pack_loaded;
} }
} // namespace ResourceHelper } // namespace ResourceHelper
+4 -4
View File
@@ -32,7 +32,7 @@
#include "game/scenes/secreta_scene.hpp" #include "game/scenes/secreta_scene.hpp"
#include "game/scenes/slides_scene.hpp" #include "game/scenes/slides_scene.hpp"
std::unique_ptr<Director> Director::instance_; std::unique_ptr<Director> Director::instance;
Director::~Director() = default; Director::~Director() = default;
@@ -76,7 +76,7 @@ auto Director::createNextScene() const -> std::unique_ptr<Scenes::Scene> {
} }
void Director::init() { void Director::init() {
instance_ = std::unique_ptr<Director>(new Director()); instance = std::unique_ptr<Director>(new Director());
Gamepad::init(); Gamepad::init();
// Registre d'escenes. Cada entrada = un state_key (`num_piramide`) // Registre d'escenes. Cada entrada = un state_key (`num_piramide`)
@@ -113,11 +113,11 @@ void Director::init() {
void Director::destroy() { void Director::destroy() {
Gamepad::destroy(); Gamepad::destroy();
instance_.reset(); instance.reset();
} }
auto Director::get() -> Director* { auto Director::get() -> Director* {
return instance_.get(); return instance.get();
} }
void Director::togglePause() { void Director::togglePause() {
+1 -1
View File
@@ -57,7 +57,7 @@ class Director {
private: private:
Director() = default; Director() = default;
static std::unique_ptr<Director> instance_; static std::unique_ptr<Director> instance;
void pollAllEvents(); // drenatge amb SDL_PollEvent, només per al bucle natiu void pollAllEvents(); // drenatge amb SDL_PollEvent, només per al bucle natiu