From f114536463a1d13cda4196903621d647586a1b26 Mon Sep 17 00:00:00 2001 From: Kolyah35 Date: Sat, 21 Mar 2026 17:19:46 +0300 Subject: [PATCH] FIX: improve web port --- CMakeLists.txt | 3 +- misc/web/index.html | 172 +++++++++-------------------------------- src/AppPlatform_glfw.h | 27 ++++++- 3 files changed, 63 insertions(+), 139 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 39809fb..1711d1c 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,7 @@ if(${PLATFORM} MATCHES "Web") add_library(png INTERFACE IMPORTED) set_target_properties(png PROPERTIES + INTERFACE_COMPILE_OPTIONS "-sUSE_LIBPNG=1" INTERFACE_LINK_OPTIONS "-sUSE_LIBPNG=1" ) @@ -331,7 +332,7 @@ if(${PLATFORM} MATCHES "Web") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EM_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EM_FLAGS}") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EM_FLAGS} --preload-file ${CMAKE_SOURCE_DIR}/data@/data -sPROXY_TO_PTHREAD") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EM_FLAGS} --preload-file ${CMAKE_SOURCE_DIR}/data@/data") target_compile_options(${PROJECT_NAME} PUBLIC "-Os" diff --git a/misc/web/index.html b/misc/web/index.html index 108e109..eed3f5b 100644 --- a/misc/web/index.html +++ b/misc/web/index.html @@ -1,143 +1,43 @@ - - - - - - Emscripten-Generated Code - + + - - - -
-
emscripten
-
Downloading...
-
- -
-
- -
-
-
- Resize canvas - Lock/hide mouse pointer -     - -
+ -
- -
- - var Module = { - print(...args) { - // These replacements are necessary if you render to raw HTML - //text = text.replace(/&/g, "&"); - //text = text.replace(//g, ">"); - //text = text.replace('\n', '
', 'g'); - console.log(...args); - if (outputElement) { - var text = args.join(' '); - outputElement.value += text + "\n"; - outputElement.scrollTop = outputElement.scrollHeight; // focus on bottom - } - }, - canvas: canvasElement, - setStatus: setStatus, - totalDependencies: 0, - monitorRunDependencies(left) { - this.totalDependencies = Math.max(this.totalDependencies, left); - setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.'); - } - }; - setStatus('Downloading...'); - window.onerror = () => { - setStatus('Exception thrown, see JavaScript console'); - spinnerElement.style.display = 'none'; - setStatus = (text) => { - if (text) console.error('[post-exception status] ' + text); - }; - }; - - - + + \ No newline at end of file diff --git a/src/AppPlatform_glfw.h b/src/AppPlatform_glfw.h index 0e2e505..619ae57 100755 --- a/src/AppPlatform_glfw.h +++ b/src/AppPlatform_glfw.h @@ -20,6 +20,10 @@ #include #endif +#ifdef __EMSCRIPTEN__ + #include +#endif + static void png_funcReadFile(png_structp pngPtr, png_bytep data, png_size_t length) { ((std::istream*)png_get_io_ptr(pngPtr))->read((char*)data, length); } @@ -102,8 +106,27 @@ public: return std::string(mbstr); } - virtual int getScreenWidth() override { return 854; }; - virtual int getScreenHeight() override { return 480; }; + virtual int getScreenWidth() override { + #ifdef __EMSCRIPTEN__ + int w, h; + emscripten_get_canvas_element_size("canvas", &w, &h); + + return w; + #endif + + return 854; + }; + + virtual int getScreenHeight() override { + #ifdef __EMSCRIPTEN__ + int w, h; + emscripten_get_canvas_element_size("canvas", &w, &h); + + return h; + #endif + + return 480; + }; virtual float getPixelsPerMillimeter() override;