afegit suport Emscripten/WebAssembly al build system
- CMakeLists.txt: branca EMSCRIPTEN amb SDL3 via FetchContent, preload de data/ config/ i gamecontrollerdb.txt, WebGL2, EMSCRIPTEN_BUILD define i sortida .html. Exclou sdl3gpu_shader (no soportat a WebGL2) i el pack_tool en wasm. - Makefile: target wasm via Docker emscripten/emsdk, build a build/wasm i sortida a dist/wasm (.html .js .wasm .data). - director.cpp: createSystemFolder utilitza MEMFS en wasm (sense pwd.h/unistd.h), executable_path buit, dev-mode forçat (filesystem preload, no pack), windowed. - screen.cpp: initShaders és no-op en wasm (SDL3 GPU no suportat a WebGL2). - global_inputs.cpp: handleQuit és no-op en wasm (no es pot eixir del joc). - Director::handleEvent ignora SDL_EVENT_QUIT en wasm. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -40,7 +40,7 @@
|
||||
#include "game/editor/map_editor.hpp" // Para MapEditor
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#if !defined(_WIN32) && !defined(__EMSCRIPTEN__)
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
|
||||
@@ -48,12 +48,17 @@
|
||||
Director::Director() {
|
||||
std::cout << "Game start" << '\n';
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
// En Emscripten els assets estan al root del filesystem virtual (/data, /config)
|
||||
executable_path_ = "";
|
||||
#else
|
||||
// Obtiene la ruta del ejecutable
|
||||
std::string base = SDL_GetBasePath();
|
||||
if (!base.empty() && base.back() == '/') {
|
||||
base.pop_back();
|
||||
}
|
||||
executable_path_ = base;
|
||||
#endif
|
||||
|
||||
// Crea la carpeta del sistema donde guardar datos
|
||||
createSystemFolder("jailgames");
|
||||
@@ -83,7 +88,7 @@ Director::Director() {
|
||||
// Preparar ruta al pack (en macOS bundle está en Contents/Resources/)
|
||||
std::string pack_path = executable_path_ + PREFIX + "/resources.pack";
|
||||
|
||||
#ifdef RELEASE_BUILD
|
||||
#if defined(RELEASE_BUILD) && !defined(__EMSCRIPTEN__)
|
||||
// ============================================================
|
||||
// RELEASE BUILD: Pack-first architecture
|
||||
// ============================================================
|
||||
@@ -141,6 +146,12 @@ Director::Director() {
|
||||
Options::setConfigFile(Resource::List::get()->get("config.yaml")); // NOLINT(readability-static-accessed-through-instance)
|
||||
Options::loadFromFile();
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
// A la versió web el navegador gestiona la finestra: res de fullscreen ni zoom.
|
||||
Options::video.fullscreen = false;
|
||||
Options::window.zoom = 1;
|
||||
#endif
|
||||
|
||||
// Configura la ruta y carga los presets de PostFX
|
||||
Options::setPostFXFile(Resource::List::get()->get("postfx.yaml")); // NOLINT(readability-static-accessed-through-instance)
|
||||
Options::loadPostFXFromFile();
|
||||
@@ -168,7 +179,7 @@ Director::Director() {
|
||||
Screen::get()->setNotificationsEnabled(true);
|
||||
|
||||
// Special handling for gamecontrollerdb.txt - SDL needs filesystem path
|
||||
#ifdef RELEASE_BUILD
|
||||
#if defined(RELEASE_BUILD) && !defined(__EMSCRIPTEN__)
|
||||
// In release, construct the path manually (not from Asset which has empty executable_path)
|
||||
std::string gamecontroller_db = executable_path_ + PREFIX + "/gamecontrollerdb.txt";
|
||||
Input::init(gamecontroller_db);
|
||||
@@ -192,7 +203,7 @@ Director::Director() {
|
||||
std::cout << "\n"; // Fin de inicialización de sistemas
|
||||
|
||||
// Inicializa el sistema de localización (antes de Cheevos que usa textos traducidos)
|
||||
#ifdef RELEASE_BUILD
|
||||
#if defined(RELEASE_BUILD) && !defined(__EMSCRIPTEN__)
|
||||
{
|
||||
// En release el locale está en el pack, no en el filesystem
|
||||
std::string locale_key = Resource::List::get()->get(Options::language + ".yaml"); // NOLINT(readability-static-accessed-through-instance)
|
||||
@@ -205,7 +216,7 @@ Director::Director() {
|
||||
#endif
|
||||
|
||||
// Special handling for cheevos.bin - also needs filesystem path
|
||||
#ifdef RELEASE_BUILD
|
||||
#if defined(RELEASE_BUILD) && !defined(__EMSCRIPTEN__)
|
||||
std::string cheevos_path = system_folder_ + "/cheevos.bin";
|
||||
Cheevos::init(cheevos_path);
|
||||
#else
|
||||
@@ -244,6 +255,12 @@ Director::~Director() {
|
||||
|
||||
// Crea la carpeta del sistema donde guardar datos
|
||||
void Director::createSystemFolder(const std::string& folder) { // NOLINT(readability-convert-member-functions-to-static)
|
||||
#ifdef __EMSCRIPTEN__
|
||||
// En Emscripten utilitzem MEMFS (no persistent entre sessions).
|
||||
// No cal crear directoris: MEMFS els crea automàticament en escriure-hi.
|
||||
system_folder_ = "/config/" + folder;
|
||||
return;
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
system_folder_ = std::string(getenv("APPDATA")) + "/" + folder;
|
||||
#elif __APPLE__
|
||||
@@ -295,6 +312,7 @@ void Director::createSystemFolder(const std::string& folder) { // NOLINT(readab
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // __EMSCRIPTEN__
|
||||
}
|
||||
|
||||
// Carga la configuración de assets desde assets.yaml
|
||||
@@ -390,10 +408,13 @@ auto Director::iterate() -> SDL_AppResult {
|
||||
|
||||
// SDL_AppEvent: despatxa un event a l'escena activa
|
||||
auto Director::handleEvent(const SDL_Event& event) -> SDL_AppResult {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
// A la versió web no tenim event de quit del navegador
|
||||
if (event.type == SDL_EVENT_QUIT) {
|
||||
SceneManager::current = SceneManager::Scene::QUIT;
|
||||
return SDL_APP_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (active_scene_) {
|
||||
active_scene_->handleEvent(event);
|
||||
|
||||
Reference in New Issue
Block a user