From 25a36d50643278ea5caff4e6d1523b590d00e65b Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 14 Apr 2026 19:08:45 +0200 Subject: [PATCH] arreglos en service menu per a emscripten --- CMakeLists.txt | 29 ++++++++++++++++++----------- Makefile | 15 +++++++++++++-- source/core/input/global_inputs.cpp | 5 +++++ source/core/system/director.cpp | 11 +++++++---- source/game/ui/service_menu.cpp | 15 +++++++++++++++ 5 files changed, 58 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6aec897..8090bdc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,17 +10,24 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # --- GENERACIÓN DE VERSIÓN AUTOMÁTICA --- -find_package(Git QUIET) -if(GIT_FOUND) - execute_process( - COMMAND ${GIT_EXECUTABLE} rev-parse --short=7 HEAD - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GIT_HASH - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_QUIET - ) -else() - set(GIT_HASH "unknown") +# Si GIT_HASH se ha pasado desde fuera (p.ej. desde el Makefile via -DGIT_HASH=xxx), +# lo usamos tal cual. Esto evita problemas con Docker/emscripten, donde git aborta por +# "dubious ownership" en el volumen montado. En builds locales sin -DGIT_HASH, se +# resuelve aquí ejecutando git directamente. +if(NOT DEFINED GIT_HASH OR GIT_HASH STREQUAL "") + find_package(Git QUIET) + if(GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --short=7 HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + endif() + if(NOT DEFINED GIT_HASH OR GIT_HASH STREQUAL "") + set(GIT_HASH "unknown") + endif() endif() # Configurar archivo de versión diff --git a/Makefile b/Makefile index a9e33a0..d4d76f7 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,17 @@ else VERSION := $(shell grep 'constexpr const char\* VERSION' source/utils/defines.hpp | sed -E 's/.*VERSION = "([^"]+)".*/\1/') endif +# Hash del commit actual, computado en el host. Se pasa a CMake via -DGIT_HASH +# para que el build en docker/emscripten no falle por "dubious ownership" de Git. +ifeq ($(OS),Windows_NT) + GIT_HASH := $(shell git rev-parse --short=7 HEAD 2>NUL) +else + GIT_HASH := $(shell git rev-parse --short=7 HEAD 2>/dev/null) +endif +ifeq ($(GIT_HASH),) + GIT_HASH := unknown +endif + # ============================================================================== # SHELL (Windows usa cmd.exe) # ============================================================================== @@ -411,12 +422,12 @@ raspi_release: # COMPILACIÓN PARA WEBASSEMBLY (requiere Docker) # ============================================================================== wasm: - @echo "Compilando para WebAssembly - Version: $(VERSION)" + @echo "Compilando para WebAssembly - Version: $(VERSION) ($(GIT_HASH))" docker run --rm \ -v $(DIR_ROOT):/src \ -w /src \ emscripten/emsdk:latest \ - bash -c "emcmake cmake -S . -B build/wasm -DCMAKE_BUILD_TYPE=Release && cmake --build build/wasm" + bash -c "emcmake cmake -S . -B build/wasm -DCMAKE_BUILD_TYPE=Release -DGIT_HASH=$(GIT_HASH) && cmake --build build/wasm" $(MKDIR) "$(DIST_DIR)/wasm" cp build/wasm/$(TARGET_NAME).html $(DIST_DIR)/wasm/ cp build/wasm/$(TARGET_NAME).js $(DIST_DIR)/wasm/ diff --git a/source/core/input/global_inputs.cpp b/source/core/input/global_inputs.cpp index 97857c3..090e395 100644 --- a/source/core/input/global_inputs.cpp +++ b/source/core/input/global_inputs.cpp @@ -21,6 +21,10 @@ namespace GlobalInputs { // Termina void quit() { +#ifdef __EMSCRIPTEN__ + // En la versión web no se permite salir: el navegador gestiona el cierre. + return; +#else const std::string CODE = "QUIT"; if (Notifier::get()->checkCode(CODE)) { // Si la notificación de salir está activa, cambia de sección @@ -30,6 +34,7 @@ namespace GlobalInputs { // Si la notificación de salir no está activa, muestra la notificación Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 01"), std::string()}, -1, CODE); } +#endif } // Reinicia diff --git a/source/core/system/director.cpp b/source/core/system/director.cpp index b71ea11..6738d48 100644 --- a/source/core/system/director.cpp +++ b/source/core/system/director.cpp @@ -120,11 +120,14 @@ void Director::init() { Options::loadCrtPiFromFile(); // Carga los presets CrtPi #ifdef __EMSCRIPTEN__ - // En la versión web el navegador gestiona la ventana: forzamos zoom=1, - // fullscreen para ocupar el canvas, e integer scale para píxeles nítidos. - Options::window.zoom = 1; - Options::video.fullscreen = true; + // En la versión web el navegador gestiona la ventana: ventana (no + // fullscreen — el canvas ya marca el área), integer scale para píxeles nítidos. + Options::window.zoom = 3; + Options::video.fullscreen = false; Options::video.integer_scale = true; + // Precarga silenciosa: pantalla negra mientras el .data termina de descargarse. + Options::loading.show = false; + Options::loading.wait_for_input = false; #endif loadParams(); // Carga los parámetros del programa loadScoreFile(); // Carga el archivo de puntuaciones diff --git a/source/game/ui/service_menu.cpp b/source/game/ui/service_menu.cpp index fb8d7cd..3460b74 100644 --- a/source/game/ui/service_menu.cpp +++ b/source/game/ui/service_menu.cpp @@ -642,6 +642,21 @@ void ServiceMenu::setHiddenOptions() { } } +#ifdef __EMSCRIPTEN__ + // En la versión web no tiene sentido exponer: shaders (build sin shaders), + // permitir apagar el sistema (no aplica al navegador) ni salir del juego + // (lo gestiona el navegador). + for (const auto& caption : { + Lang::getText("[SERVICE_MENU] SHADER"), + Lang::getText("[SERVICE_MENU] ENABLE_SHUTDOWN"), + Lang::getText("[SERVICE_MENU] QUIT")}) { + auto* option = getOptionByCaption(caption); + if (option != nullptr) { + option->setHidden(true); + } + } +#endif + updateMenu(); // El menú debe refrescarse si algo se oculta }