fix: tidy statics, instance, stretch43, fill/find_if ranges, NOLINT externs
This commit is contained in:
@@ -176,16 +176,16 @@ auto Audio::getRealMusicState() -> MusicState {
|
||||
// Establece el volumen de los sonidos (float 0.0..1.0)
|
||||
void Audio::setSoundVolume(float sound_volume, Group group) const {
|
||||
sound_volume = std::clamp(sound_volume, MIN_VOLUME, MAX_VOLUME);
|
||||
const bool active = enabled_ && sound_enabled_;
|
||||
const float CONVERTED_VOLUME = active ? sound_volume * Options::audio.volume : 0.0F;
|
||||
const bool ACTIVE = enabled_ && sound_enabled_;
|
||||
const float CONVERTED_VOLUME = ACTIVE ? sound_volume * Options::audio.volume : 0.0F;
|
||||
Ja::setSoundVolume(CONVERTED_VOLUME, static_cast<int>(group));
|
||||
}
|
||||
|
||||
// Establece el volumen de la música (float 0.0..1.0)
|
||||
void Audio::setMusicVolume(float music_volume) const {
|
||||
music_volume = std::clamp(music_volume, MIN_VOLUME, MAX_VOLUME);
|
||||
const bool active = enabled_ && music_enabled_;
|
||||
const float CONVERTED_VOLUME = active ? music_volume * Options::audio.volume : 0.0F;
|
||||
const bool ACTIVE = enabled_ && music_enabled_;
|
||||
const float CONVERTED_VOLUME = ACTIVE ? music_volume * Options::audio.volume : 0.0F;
|
||||
Ja::setMusicVolume(CONVERTED_VOLUME);
|
||||
}
|
||||
|
||||
|
||||
@@ -259,7 +259,7 @@ namespace Ja {
|
||||
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'; }
|
||||
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() {
|
||||
@@ -663,7 +663,7 @@ namespace Ja {
|
||||
const float V = SDL_clamp(volume, 0.0F, 1.0F);
|
||||
|
||||
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) {
|
||||
sound_volume[group] = V;
|
||||
} else {
|
||||
|
||||
@@ -11,13 +11,13 @@
|
||||
namespace KeyConfig {
|
||||
|
||||
namespace {
|
||||
std::vector<KeyEntry> entries_;
|
||||
std::unordered_map<std::string, size_t> index_;
|
||||
std::string overrides_path_;
|
||||
std::vector<KeyEntry> key_entries;
|
||||
std::unordered_map<std::string, size_t> index_table;
|
||||
std::string overrides_path;
|
||||
|
||||
auto findIndex(const std::string& id) -> size_t {
|
||||
auto it = index_.find(id);
|
||||
if (it == index_.end()) {
|
||||
auto it = index_table.find(id);
|
||||
if (it == index_table.end()) {
|
||||
return SIZE_MAX;
|
||||
}
|
||||
return it->second;
|
||||
@@ -52,10 +52,10 @@ namespace KeyConfig {
|
||||
entry.scancode = sc;
|
||||
entry.default_scancode = sc;
|
||||
|
||||
index_[entry.id] = entries_.size();
|
||||
entries_.push_back(std::move(entry));
|
||||
index_table[entry.id] = key_entries.size();
|
||||
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';
|
||||
} catch (const fkyaml::exception& e) {
|
||||
std::cerr << "KeyConfig: error parsejant YAML: " << e.what() << '\n';
|
||||
@@ -93,8 +93,8 @@ namespace KeyConfig {
|
||||
<< "' per '" << id << "'\n";
|
||||
continue;
|
||||
}
|
||||
entries_[idx].scancode = sc;
|
||||
entries_[idx].code = code;
|
||||
key_entries[idx].scancode = sc;
|
||||
key_entries[idx].code = code;
|
||||
applied++;
|
||||
}
|
||||
if (applied > 0) {
|
||||
@@ -109,20 +109,20 @@ namespace KeyConfig {
|
||||
|
||||
void init(const std::string& defaults_resource_path,
|
||||
const std::string& user_overrides_disk_path) {
|
||||
entries_.clear();
|
||||
index_.clear();
|
||||
overrides_path_ = user_overrides_disk_path;
|
||||
key_entries.clear();
|
||||
index_table.clear();
|
||||
overrides_path = user_overrides_disk_path;
|
||||
|
||||
loadDefaults(defaults_resource_path);
|
||||
if (!overrides_path_.empty()) {
|
||||
applyOverrides(overrides_path_);
|
||||
if (!overrides_path.empty()) {
|
||||
applyOverrides(overrides_path);
|
||||
}
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
entries_.clear();
|
||||
index_.clear();
|
||||
overrides_path_.clear();
|
||||
key_entries.clear();
|
||||
index_table.clear();
|
||||
overrides_path.clear();
|
||||
}
|
||||
|
||||
auto scancode(const std::string& id) -> SDL_Scancode {
|
||||
@@ -130,7 +130,7 @@ namespace KeyConfig {
|
||||
if (idx == SIZE_MAX) {
|
||||
return SDL_SCANCODE_UNKNOWN;
|
||||
}
|
||||
return entries_[idx].scancode;
|
||||
return key_entries[idx].scancode;
|
||||
}
|
||||
|
||||
auto scancodePtr(const std::string& id) -> SDL_Scancode* {
|
||||
@@ -138,7 +138,7 @@ namespace KeyConfig {
|
||||
if (idx == SIZE_MAX) {
|
||||
return nullptr;
|
||||
}
|
||||
return &entries_[idx].scancode;
|
||||
return &key_entries[idx].scancode;
|
||||
}
|
||||
|
||||
void setScancode(const std::string& id, SDL_Scancode sc) {
|
||||
@@ -146,38 +146,38 @@ namespace KeyConfig {
|
||||
if (idx == SIZE_MAX) {
|
||||
return;
|
||||
}
|
||||
entries_[idx].scancode = sc;
|
||||
key_entries[idx].scancode = 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 {
|
||||
if (sc == SDL_SCANCODE_UNKNOWN) {
|
||||
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>& {
|
||||
return entries_;
|
||||
return key_entries;
|
||||
}
|
||||
|
||||
auto saveOverrides() -> bool {
|
||||
if (overrides_path_.empty()) {
|
||||
if (overrides_path.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Recull només les entrades remapeades.
|
||||
std::vector<const KeyEntry*> changed;
|
||||
for (const auto& e : entries_) {
|
||||
for (const auto& e : key_entries) {
|
||||
if (e.scancode != e.default_scancode) {
|
||||
changed.push_back(&e);
|
||||
}
|
||||
}
|
||||
|
||||
std::ofstream file(overrides_path_);
|
||||
std::ofstream file(overrides_path);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ auto Jf::getConfigValue(const char* key) -> const char* {
|
||||
if (config.empty()) {
|
||||
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()) {
|
||||
thread_local std::string value_cache_;
|
||||
value_cache_ = IT->value;
|
||||
@@ -125,7 +125,7 @@ void Jf::setConfigValue(const char* key, const char* value) {
|
||||
if (config.empty()) {
|
||||
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()) {
|
||||
IT->value = value;
|
||||
saveConfigValues();
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
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
|
||||
static void traverse(const fkyaml::node& node, const std::string& prefix) {
|
||||
@@ -25,7 +25,7 @@ namespace Locale {
|
||||
}
|
||||
} else if (node.is_scalar()) {
|
||||
try {
|
||||
strings_[prefix] = node.get_value<std::string>();
|
||||
strings_table[prefix] = node.get_value<std::string>();
|
||||
} catch (...) {
|
||||
// @INTENTIONAL: si el valor no és string vàlid, l'ignorem i continuem.
|
||||
}
|
||||
@@ -42,9 +42,9 @@ namespace Locale {
|
||||
|
||||
try {
|
||||
auto yaml = fkyaml::node::deserialize(content);
|
||||
strings_.clear();
|
||||
strings_table.clear();
|
||||
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;
|
||||
} catch (const fkyaml::exception& e) {
|
||||
std::cerr << "Locale: error parsing " << filename << ": " << e.what() << '\n';
|
||||
@@ -53,8 +53,8 @@ namespace Locale {
|
||||
}
|
||||
|
||||
auto get(const char* key) -> const char* {
|
||||
auto it = strings_.find(key);
|
||||
if (it != strings_.end()) {
|
||||
auto it = strings_table.find(key);
|
||||
if (it != strings_table.end()) {
|
||||
return it->second.c_str();
|
||||
}
|
||||
return key; // fallback: retorna la clau mateixa
|
||||
|
||||
@@ -56,18 +56,18 @@ namespace {
|
||||
} // namespace
|
||||
#endif // __EMSCRIPTEN__
|
||||
|
||||
std::unique_ptr<Screen> Screen::instance_;
|
||||
std::unique_ptr<Screen> Screen::instance;
|
||||
|
||||
void Screen::init() {
|
||||
instance_ = std::unique_ptr<Screen>(new Screen());
|
||||
instance = std::unique_ptr<Screen>(new Screen());
|
||||
}
|
||||
|
||||
void Screen::destroy() {
|
||||
instance_.reset();
|
||||
instance.reset();
|
||||
}
|
||||
|
||||
auto Screen::get() -> Screen* {
|
||||
return instance_.get();
|
||||
return instance.get();
|
||||
}
|
||||
|
||||
Screen::Screen() {
|
||||
@@ -178,7 +178,7 @@ void Screen::initShaders() {
|
||||
shader_backend_->setScalingMode(Options::video.scaling_mode);
|
||||
shader_backend_->setVSync(Options::video.vsync);
|
||||
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);
|
||||
|
||||
if (Options::video.supersampling) {
|
||||
@@ -346,7 +346,7 @@ auto Screen::toggleSupersampling() -> bool {
|
||||
void Screen::toggleAspectRatio() {
|
||||
Options::video.aspect_ratio_4_3 = !Options::video.aspect_ratio_4_3;
|
||||
if (shader_backend_) {
|
||||
shader_backend_->setStretch4_3(Options::video.aspect_ratio_4_3);
|
||||
shader_backend_->setStretch43(Options::video.aspect_ratio_4_3);
|
||||
} else {
|
||||
applyFallbackPresentation();
|
||||
}
|
||||
@@ -560,7 +560,7 @@ auto Screen::getActiveShaderName() const -> const char* {
|
||||
}
|
||||
|
||||
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_);
|
||||
|
||||
// Segment 0: FPS + driver (sempre visible)
|
||||
@@ -578,7 +578,7 @@ void Screen::updateRenderInfo() {
|
||||
// Segment 3: hora (només si show_time)
|
||||
char time_buf[32] = {0};
|
||||
if (Options::render_info.show_time) {
|
||||
Uint32 elapsed = SDL_GetTicks() - start_ticks;
|
||||
Uint32 elapsed = SDL_GetTicks() - START_TICKS;
|
||||
int minutes = elapsed / 60000;
|
||||
int seconds = (elapsed / 1000) % 60;
|
||||
int centis = (elapsed / 10) % 100;
|
||||
|
||||
@@ -71,7 +71,7 @@ class Screen {
|
||||
void applyFallbackPresentation(); // Logical presentation + scale mode per al path SDL_Renderer
|
||||
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_Renderer* renderer_{nullptr};
|
||||
|
||||
@@ -1286,7 +1286,7 @@ namespace Rendering {
|
||||
}
|
||||
}
|
||||
|
||||
void SDL3GPUShader::setStretch4_3(bool enabled) {
|
||||
void SDL3GPUShader::setStretch43(bool enabled) {
|
||||
stretch_4_3_ = enabled;
|
||||
if (!is_initialized_ || device_ == nullptr) {
|
||||
return;
|
||||
|
||||
@@ -118,8 +118,8 @@ namespace Rendering {
|
||||
[[nodiscard]] auto getActiveShader() const -> ShaderType override { return active_shader_; }
|
||||
|
||||
// Estirament vertical 4:3 (fusionat amb l'upscale pass)
|
||||
void setStretch4_3(bool enabled) override;
|
||||
[[nodiscard]] auto isStretch4_3() const -> bool override { return stretch_4_3_; }
|
||||
void setStretch43(bool enabled) override;
|
||||
[[nodiscard]] auto isStretch43() const -> bool override { return stretch_4_3_; }
|
||||
|
||||
// Filtre de textura global (sempre aplicat, independent de 4:3)
|
||||
void setTextureFilter(Options::TextureFilter filter) override {
|
||||
|
||||
@@ -171,8 +171,8 @@ namespace Rendering {
|
||||
* @brief Activa/desactiva estirament vertical 4:3 (200→240 línies efectives).
|
||||
* Només afecta el viewport, no les textures ni els shaders.
|
||||
*/
|
||||
virtual void setStretch4_3(bool /*enabled*/) {}
|
||||
[[nodiscard]] virtual auto isStretch4_3() const -> bool { return false; }
|
||||
virtual void setStretch43(bool /*enabled*/) {}
|
||||
[[nodiscard]] virtual auto isStretch43() const -> bool { return false; }
|
||||
|
||||
/**
|
||||
* @brief Filtre de textura global per a l'upscale final (sempre aplicat).
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
// Forward declarations de gif.h (inclòs des de jdraw8.cpp, no es pot incloure dos vegades)
|
||||
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*;
|
||||
|
||||
Text::Text(const char* fnt_file, const char* gif_file) {
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
// 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,
|
||||
// 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 LoadPalette(unsigned char* data) -> unsigned char*;
|
||||
// NOLINTEND(readability-identifier-naming)
|
||||
|
||||
namespace Resource {
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
namespace ResourceHelper {
|
||||
|
||||
namespace {
|
||||
ResourcePack pack_;
|
||||
bool pack_loaded_ = false;
|
||||
bool fallback_enabled_ = true;
|
||||
ResourcePack pack_obj;
|
||||
bool pack_loaded = false;
|
||||
bool fallback_enabled = true;
|
||||
|
||||
auto readFromDisk(const std::string& relative_path) -> std::vector<uint8_t> {
|
||||
const std::string FULL = std::string(Jf::getResourceFolder()) + relative_path;
|
||||
@@ -32,11 +32,11 @@ namespace ResourceHelper {
|
||||
} // namespace
|
||||
|
||||
auto initializeResourceSystem(const std::string& pack_file, bool enable_fallback) -> bool {
|
||||
fallback_enabled_ = enable_fallback;
|
||||
pack_loaded_ = pack_.loadPack(pack_file);
|
||||
fallback_enabled = enable_fallback;
|
||||
pack_loaded = pack_obj.loadPack(pack_file);
|
||||
|
||||
if (pack_loaded_) {
|
||||
std::cout << "ResourceHelper: pack loaded (" << pack_.getResourceCount()
|
||||
if (pack_loaded) {
|
||||
std::cout << "ResourceHelper: pack loaded (" << pack_obj.getResourceCount()
|
||||
<< " entries) from " << pack_file << '\n';
|
||||
} else if (enable_fallback) {
|
||||
std::cout << "ResourceHelper: no pack at " << pack_file
|
||||
@@ -50,22 +50,22 @@ namespace ResourceHelper {
|
||||
}
|
||||
|
||||
void shutdownResourceSystem() {
|
||||
pack_.clear();
|
||||
pack_loaded_ = false;
|
||||
pack_obj.clear();
|
||||
pack_loaded = false;
|
||||
}
|
||||
|
||||
auto loadFile(const std::string& relative_path) -> std::vector<uint8_t> {
|
||||
if (pack_loaded_ && pack_.hasResource(relative_path)) {
|
||||
return pack_.getResource(relative_path);
|
||||
if (pack_loaded && pack_obj.hasResource(relative_path)) {
|
||||
return pack_obj.getResource(relative_path);
|
||||
}
|
||||
if (fallback_enabled_) {
|
||||
if (fallback_enabled) {
|
||||
return readFromDisk(relative_path);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
auto hasPack() -> bool {
|
||||
return pack_loaded_;
|
||||
return pack_loaded;
|
||||
}
|
||||
|
||||
} // namespace ResourceHelper
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "game/scenes/secreta_scene.hpp"
|
||||
#include "game/scenes/slides_scene.hpp"
|
||||
|
||||
std::unique_ptr<Director> Director::instance_;
|
||||
std::unique_ptr<Director> Director::instance;
|
||||
|
||||
Director::~Director() = default;
|
||||
|
||||
@@ -76,7 +76,7 @@ auto Director::createNextScene() const -> std::unique_ptr<Scenes::Scene> {
|
||||
}
|
||||
|
||||
void Director::init() {
|
||||
instance_ = std::unique_ptr<Director>(new Director());
|
||||
instance = std::unique_ptr<Director>(new Director());
|
||||
Gamepad::init();
|
||||
|
||||
// Registre d'escenes. Cada entrada = un state_key (`num_piramide`)
|
||||
@@ -113,11 +113,11 @@ void Director::init() {
|
||||
|
||||
void Director::destroy() {
|
||||
Gamepad::destroy();
|
||||
instance_.reset();
|
||||
instance.reset();
|
||||
}
|
||||
|
||||
auto Director::get() -> Director* {
|
||||
return instance_.get();
|
||||
return instance.get();
|
||||
}
|
||||
|
||||
void Director::togglePause() {
|
||||
|
||||
@@ -57,7 +57,7 @@ class Director {
|
||||
private:
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user