Skip to content

Commit 9df65ac

Browse files
authored
[WASM] Fix Downloader storage issue, new options for wasm (#3049)
fix Downloader wasm, options for wasm
1 parent 67b0e4f commit 9df65ac

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

CMakeOptions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ default is: `navigator.hardwareConcurrency`
5252
- AX_WASM_INITIAL_MEMORY: set the wasm initial memory size, default `1024MB`
5353
- AX_WASM_ISA_SIMD: specify the wasm simd intrinsics type, default `none`, supports `sse`, `neon`, note the `wasm-simd` not support by axmol yet
5454
- AX_WASM_TIMING_USE_TIMEOUT: force the wasm emscripten loop timing to use `Timeout` with FPS value of `Application::setAnimationInterval` (app still run on focus lost), default is `FALSE` with timing `requestAnimationFrame` (no run on focus lost). See https://emscripten.org/docs/api_reference/emscripten.h.html#c.emscripten_set_main_loop_timing
55+
- AX_WASM_ASSETS_PRELOAD_FILE: Whether enable to bundle the assets to a .data file and preload them into an IndexedDB cache at first launch (`--preload-file`), otherwise bundle them into the wasm file itself and don't use the IndexedDB at all (`--embed-file`)", default `TRUE`
56+
- AX_WASM_GENERATE_SYMBOL_FILE: Generate a symbol file for the built wasm file, default `FALSE`
5557

5658
## The options for axmol apps
5759

cmake/Modules/AXBuildHelpers.cmake

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,9 +591,16 @@ function(ax_setup_app_config app_name)
591591
if(WINRT)
592592
ax_target_embed_compiled_shaders(${app_name} ${rt_output} FILES ${app_all_shaders})
593593
else()
594-
# --preload-file
595-
# refer to: https://emscripten.org/docs/porting/files/packaging_files.html
596-
target_link_options(${app_name} PRIVATE "--preload-file" ${AXSLCC_OUT_DIR}@axslc/)
594+
595+
set(_WASM_ASSETS_LINKER_FILE "--embed-file")
596+
597+
if(AX_WASM_ASSETS_PRELOAD_FILE)
598+
# --preload-file
599+
# refer to: https://emscripten.org/docs/porting/files/packaging_files.html
600+
set(_WASM_ASSETS_LINKER_FILE "--preload-file")
601+
endif()
602+
603+
target_link_options(${app_name} PRIVATE ${_WASM_ASSETS_LINKER_FILE} ${AXSLCC_OUT_DIR}@axslc/)
597604
endif()
598605
endif()
599606
endif()
@@ -611,6 +618,10 @@ endif()
611618

612619
set(AX_WASM_EXPORTS "${_AX_WASM_EXPORTS}" CACHE STRING "" FORCE)
613620

621+
option(AX_WASM_ASSETS_PRELOAD_FILE "Assets are preloaded into IndexedDB from .data file" ON)
622+
623+
option(AX_WASM_GENERATE_SYMBOL_FILE "Symbols file for WASM is generated" OFF)
624+
614625
# stupid & pitfall: function not emcc not output .html
615626
macro(ax_setup_app_props app_name)
616627
if(WINRT)
@@ -641,12 +652,23 @@ macro(ax_setup_app_props app_name)
641652
# string(APPEND EMSCRIPTEN_LINK_FLAGS " -s SEPARATE_DWARF_URL=http://127.0.0.1:6931/${app_name}.debug.wasm")
642653
# string(APPEND EMSCRIPTEN_LINK_FLAGS " -gseparate-dwarf=${CMAKE_BINARY_DIR}/bin/${app_name}/${app_name}.debug.wasm")
643654
# string(APPEND EMSCRIPTEN_LINK_FLAGS " -gsplit-dwarf")
655+
656+
if(AX_WASM_GENERATE_SYMBOL_FILE)
657+
string(APPEND EMSCRIPTEN_LINK_FLAGS "-g --emit-symbol-map")
658+
endif()
659+
644660
if(NOT DEFINED _APP_RES_FOLDER)
645661
set(_APP_RES_FOLDER "${_APP_SOURCE_DIR}/Content")
646662
endif()
647663

664+
set(_WASM_ASSETS_LINKER_FILE "--embed-file")
665+
666+
if(AX_WASM_ASSETS_PRELOAD_FILE)
667+
set(_WASM_ASSETS_LINKER_FILE "--preload-file")
668+
endif()
669+
648670
foreach(FOLDER IN LISTS _APP_RES_FOLDER)
649-
string(APPEND EMSCRIPTEN_LINK_FLAGS " --preload-file ${FOLDER}/@/")
671+
string(APPEND EMSCRIPTEN_LINK_FLAGS " ${_WASM_ASSETS_LINKER_FILE} ${FOLDER}/@/")
650672
endforeach()
651673

652674
set_target_properties(${app_name} PROPERTIES LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS}")

core/network/Downloader-wasm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ namespace ax { namespace network {
7272
emscripten_fetch_attr_t attr;
7373
emscripten_fetch_attr_init(&attr);
7474
strcpy(attr.requestMethod, "GET");
75-
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY | EMSCRIPTEN_FETCH_PERSIST_FILE;
75+
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
7676
if(task->storagePath.length() == 0) {
7777
attr.onsuccess = DownloaderEmscripten::onDataLoad;
7878
}else{

0 commit comments

Comments
 (0)