Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ default is: `navigator.hardwareConcurrency`
- AX_WASM_INITIAL_MEMORY: set the wasm initial memory size, default `1024MB`
- AX_WASM_ISA_SIMD: specify the wasm simd intrinsics type, default `none`, supports `sse`, `neon`, note the `wasm-simd` not support by axmol yet
- 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
- 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`
- AX_WASM_GENERATE_SYMBOL_FILE: Generate a symbol file for the built wasm file, default `FALSE`

## The options for axmol apps

Expand Down
30 changes: 26 additions & 4 deletions cmake/Modules/AXBuildHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,16 @@ function(ax_setup_app_config app_name)
if(WINRT)
ax_target_embed_compiled_shaders(${app_name} ${rt_output} FILES ${app_all_shaders})
else()
# --preload-file
# refer to: https://emscripten.org/docs/porting/files/packaging_files.html
target_link_options(${app_name} PRIVATE "--preload-file" ${AXSLCC_OUT_DIR}@axslc/)

set(_WASM_ASSETS_LINKER_FILE "--embed-file")

if(AX_WASM_ASSETS_PRELOAD_FILE)
# --preload-file
# refer to: https://emscripten.org/docs/porting/files/packaging_files.html
set(_WASM_ASSETS_LINKER_FILE "--preload-file")
endif()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better logic:

        if(AX_WASM_ASSETS_PRELOAD_FILE)
          # --preload-file
          # refer to: https://emscripten.org/docs/porting/files/packaging_files.html
          set(_WASM_ASSETS_LINKER_FILE "--preload-file")
        else()
          set(_WASM_ASSETS_LINKER_FILE "--embed-file")
        endif()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do this only once below the option(..)


target_link_options(${app_name} PRIVATE ${_WASM_ASSETS_LINKER_FILE} ${AXSLCC_OUT_DIR}@axslc/)
endif()
endif()
endif()
Expand All @@ -611,6 +618,10 @@ endif()

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

option(AX_WASM_ASSETS_PRELOAD_FILE "Assets are preloaded into IndexedDB from .data file" ON)

option(AX_WASM_GENERATE_SYMBOL_FILE "Symbols file for WASM is generated" OFF)

# stupid & pitfall: function not emcc not output .html
macro(ax_setup_app_props app_name)
if(WINRT)
Expand Down Expand Up @@ -641,12 +652,23 @@ macro(ax_setup_app_props app_name)
# string(APPEND EMSCRIPTEN_LINK_FLAGS " -s SEPARATE_DWARF_URL=http://127.0.0.1:6931/${app_name}.debug.wasm")
# string(APPEND EMSCRIPTEN_LINK_FLAGS " -gseparate-dwarf=${CMAKE_BINARY_DIR}/bin/${app_name}/${app_name}.debug.wasm")
# string(APPEND EMSCRIPTEN_LINK_FLAGS " -gsplit-dwarf")

if(AX_WASM_GENERATE_SYMBOL_FILE)
string(APPEND EMSCRIPTEN_LINK_FLAGS "-g --emit-symbol-map")
endif()

if(NOT DEFINED _APP_RES_FOLDER)
set(_APP_RES_FOLDER "${_APP_SOURCE_DIR}/Content")
endif()

set(_WASM_ASSETS_LINKER_FILE "--embed-file")

if(AX_WASM_ASSETS_PRELOAD_FILE)
set(_WASM_ASSETS_LINKER_FILE "--preload-file")
endif()

foreach(FOLDER IN LISTS _APP_RES_FOLDER)
string(APPEND EMSCRIPTEN_LINK_FLAGS " --preload-file ${FOLDER}/@/")
string(APPEND EMSCRIPTEN_LINK_FLAGS " ${_WASM_ASSETS_LINKER_FILE} ${FOLDER}/@/")
endforeach()

set_target_properties(${app_name} PROPERTIES LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS}")
Expand Down
2 changes: 1 addition & 1 deletion core/network/Downloader-wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace ax { namespace network {
emscripten_fetch_attr_t attr;
emscripten_fetch_attr_init(&attr);
strcpy(attr.requestMethod, "GET");
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY | EMSCRIPTEN_FETCH_PERSIST_FILE;
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
if(task->storagePath.length() == 0) {
attr.onsuccess = DownloaderEmscripten::onDataLoad;
}else{
Expand Down