From 4a4485c6f843198f88ca2bf23b58de44c16d1794 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 18 Apr 2026 18:16:41 +0200 Subject: [PATCH] bugfixes --- data/locale/ca.yaml | 1 + source/core/audio/audio.cpp | 18 ++++++++---------- source/core/jail/jfile.cpp | 25 ++++++++++++++++--------- source/core/rendering/menu.cpp | 2 ++ source/game/defaults.hpp | 1 + source/game/options.cpp | 3 +++ source/game/options.hpp | 1 + source/main.cpp | 2 +- source/scenes/boot_loader_scene.cpp | 3 +++ 9 files changed, 36 insertions(+), 20 deletions(-) diff --git a/data/locale/ca.yaml b/data/locale/ca.yaml index d515ed2..d5290c3 100644 --- a/data/locale/ca.yaml +++ b/data/locale/ca.yaml @@ -21,6 +21,7 @@ menu: exit_game: "Eixir del joc" use_new_logo: "Logo nou" show_title_credits: "Crèdits del port" + show_preload: "Barra de precàrrega" zoom: "Zoom" screen: "Pantalla" shader: "Shader" diff --git a/source/core/audio/audio.cpp b/source/core/audio/audio.cpp index d25dd0e..1e9d0f4 100644 --- a/source/core/audio/audio.cpp +++ b/source/core/audio/audio.cpp @@ -169,20 +169,18 @@ auto Audio::getRealMusicState() -> MusicState { // Establece el volumen de los sonidos (float 0.0..1.0) void Audio::setSoundVolume(float sound_volume, Group group) const { - if (sound_enabled_) { - sound_volume = std::clamp(sound_volume, MIN_VOLUME, MAX_VOLUME); - const float CONVERTED_VOLUME = sound_volume * Options::audio.volume; - JA_SetSoundVolume(CONVERTED_VOLUME, static_cast(group)); - } + 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; + JA_SetSoundVolume(CONVERTED_VOLUME, static_cast(group)); } // Establece el volumen de la música (float 0.0..1.0) void Audio::setMusicVolume(float music_volume) const { - if (music_enabled_) { - music_volume = std::clamp(music_volume, MIN_VOLUME, MAX_VOLUME); - const float CONVERTED_VOLUME = music_volume * Options::audio.volume; - JA_SetMusicVolume(CONVERTED_VOLUME); - } + 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; + JA_SetMusicVolume(CONVERTED_VOLUME); } // Aplica la configuración diff --git a/source/core/jail/jfile.cpp b/source/core/jail/jfile.cpp index 499fd87..e325d84 100644 --- a/source/core/jail/jfile.cpp +++ b/source/core/jail/jfile.cpp @@ -70,19 +70,26 @@ void file_setconfigfolder(const char* foldername) { if (!homedir) homedir = "/tmp"; config_folder = std::string(homedir) + "/Library/Application Support/" + foldername; #elif __linux__ - // Nota emscripten: `__linux__` també està definit, però `getpwuid` no - // troba cap /etc/passwd al MEMFS i retorna nullptr. Amb els fallbacks - // HOME → /tmp evitem crashejar al primer arranque dins del navegador. - // La config no persistirà entre recàrregues de la pàgina (MEMFS és - // volàtil); caldria IDBFS si volguéssem persistència a web. + // Nota emscripten: `__linux__` també està definit, però `getpwuid` pot + // retornar nullptr (sense /etc/passwd al MEMFS) o un passwd amb pw_dir + // buit. Amb els fallbacks HOME → /tmp evitem crashejar al primer + // arranque dins del navegador. La config no persistirà entre recàrregues + // (MEMFS és volàtil); caldria IDBFS si volguéssem persistència a web. struct passwd* pw = getpwuid(getuid()); - const char* homedir = (pw && pw->pw_dir) ? pw->pw_dir : nullptr; - if (!homedir) homedir = getenv("HOME"); - if (!homedir) homedir = "/tmp"; + const char* homedir = (pw && pw->pw_dir && pw->pw_dir[0]) ? pw->pw_dir : nullptr; + if (!homedir || !homedir[0]) homedir = getenv("HOME"); + if (!homedir || !homedir[0]) homedir = "/tmp"; config_folder = std::string(homedir) + "/.config/" + foldername; #endif - std::filesystem::create_directories(config_folder); + if (config_folder.empty()) { + config_folder = "/tmp/jailgames_config"; + } + std::error_code ec; + std::filesystem::create_directories(config_folder, ec); + // A emscripten/MEMFS create_directories pot fallar (p.ex. parent + // read-only o libc++ amb path empty-check estricte). La config és + // volàtil al navegador de totes formes: ignorem l'error i continuem. } const char* file_getconfigfolder() { diff --git a/source/core/rendering/menu.cpp b/source/core/rendering/menu.cpp index 6b7aea3..29b8131 100644 --- a/source/core/rendering/menu.cpp +++ b/source/core/rendering/menu.cpp @@ -271,6 +271,8 @@ namespace Menu { p.items.push_back({Locale::get("menu.items.show_title_credits"), ItemKind::Toggle, [] { return yesNo(Options::game.show_title_credits); }, [](int) { Options::game.show_title_credits = !Options::game.show_title_credits; }, nullptr}); + p.items.push_back({Locale::get("menu.items.show_preload"), ItemKind::Toggle, [] { return yesNo(Options::game.show_preload); }, [](int) { Options::game.show_preload = !Options::game.show_preload; }, nullptr}); + return p; } diff --git a/source/game/defaults.hpp b/source/game/defaults.hpp index 17334d1..523e0c1 100644 --- a/source/game/defaults.hpp +++ b/source/game/defaults.hpp @@ -46,4 +46,5 @@ namespace Defaults::Game { constexpr int DINERS_INICIAL = 0; constexpr bool USE_NEW_LOGO = true; constexpr bool SHOW_TITLE_CREDITS = true; + constexpr bool SHOW_PRELOAD = false; } // namespace Defaults::Game diff --git a/source/game/options.cpp b/source/game/options.cpp index f558d8b..1bdeb86 100644 --- a/source/game/options.cpp +++ b/source/game/options.cpp @@ -219,6 +219,8 @@ namespace Options { game.use_new_logo = node["use_new_logo"].get_value(); if (node.contains("show_title_credits")) game.show_title_credits = node["show_title_credits"].get_value(); + if (node.contains("show_preload")) + game.show_preload = node["show_preload"].get_value(); } // Carrega les opcions des del fitxer configurat @@ -368,6 +370,7 @@ namespace Options { file << "game:\n"; file << " use_new_logo: " << (game.use_new_logo ? "true" : "false") << "\n"; file << " show_title_credits: " << (game.show_title_credits ? "true" : "false") << "\n"; + file << " show_preload: " << (game.show_preload ? "true" : "false") << "\n"; file << "\n"; // CONTROLS — només moviment del jugador. Les tecles d'UI viuen a diff --git a/source/game/options.hpp b/source/game/options.hpp index 55e241e..efa541a 100644 --- a/source/game/options.hpp +++ b/source/game/options.hpp @@ -90,6 +90,7 @@ namespace Options { int diners_inicial{Defaults::Game::DINERS_INICIAL}; bool use_new_logo{Defaults::Game::USE_NEW_LOGO}; bool show_title_credits{Defaults::Game::SHOW_TITLE_CREDITS}; + bool show_preload{Defaults::Game::SHOW_PRELOAD}; }; // Preset PostFX diff --git a/source/main.cpp b/source/main.cpp index 3ba31fb..c700d4d 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -74,7 +74,7 @@ SDL_AppResult SDL_AppInit(void** /*appstate*/, int /*argc*/, char* /*argv*/[]) { #ifdef __EMSCRIPTEN__ // MEMFS no persistix entre recàrregues: força valors sensats per a web. Options::window.fullscreen = false; - Options::window.zoom = 1; + Options::window.zoom = 3; Options::video.aspect_ratio_4_3 = true; Options::video.scaling_mode = Options::ScalingMode::INTEGER; Options::video.texture_filter = Options::TextureFilter::LINEAR; diff --git a/source/scenes/boot_loader_scene.cpp b/source/scenes/boot_loader_scene.cpp index 6ba9795..392f15c 100644 --- a/source/scenes/boot_loader_scene.cpp +++ b/source/scenes/boot_loader_scene.cpp @@ -2,6 +2,7 @@ #include "core/jail/jdraw8.hpp" #include "core/resources/resource_cache.hpp" +#include "game/options.hpp" namespace scenes { @@ -37,6 +38,8 @@ namespace scenes { void BootLoaderScene::render() const { JD8_ClearScreen(BG_COLOR); + if (!Options::game.show_preload) return; + const float pct = Resource::Cache::get()->getProgress(); const int filled = static_cast(static_cast(BAR_W) * pct);