Debian Codegraph @

docs/README_emscripten.md

raw symbols SCIP
1 # Emscripten (Wasm) Port of [fheroes2](README.md) Project
2
3 ## Current Status of this Port
4
5 Please note that this port is currently still **experimental**. You may experience various problems, crashes, or it not even working at all in particular browsers.
6
7 ## Building
8
9 ### Prerequisites
10
11 * emsdk 4.0 or later
12 * GNU gettext
13
14 ### Building using Docker
15
16 To save time, you can use a ready-made Docker image:
17
18 ```sh
19 docker run --rm -v "$(pwd):/src" emscripten/emsdk:latest sh -c "apt-get -y update; apt-get -y install gettext; emmake make -f Makefile.emscripten"
20 ```
21
22 ### Building without Docker
23
24 If you do not want to use Docker, then you will need to install all the prerequisites manually using your platform's package manager, and then run the following command:
25
26 ```sh
27 emmake make -f Makefile.emscripten
28 ```
29
30 ### Building with Additional Parameters
31
32 If you want to specify some additional ad hoc build parameters, you can use the appropriate environment variables for this. For example, the following command:
33
34 ```sh
35 FHEROES2_WITH_THREADS=ON LDFLAGS="-sMODULARIZE -sEXPORTED_RUNTIME_METHODS=run -sEXPORT_NAME=fheroes2" emmake make -f Makefile.emscripten
36 ```
37
38 will build a WebAssembly binary with multithreading support, as well as with additional parameters for creating a module.
39
40 ## Running the Wasm Port on a Web Server
41
42 ### Configuring the Web Server
43
44 Emscripten uses web workers along with `SharedArrayBuffer` to support multithreading. `SharedArrayBuffer` usage is usually protected by Cross Origin Opener Policy (COOP)
45 and Cross Origin Embedder Policy (COEP) HTTP headers, and the web server should send these headers as part of its response to a request for resources related to the Wasm
46 build:
47
48 ```text
49 Cross-Origin-Opener-Policy: same-origin
50 Cross-Origin-Embedder-Policy: require-corp
51 ```
52
53 Please see the following link for details:
54
55 <https://web.dev/coop-coep>
56
57 ### Copying Necessary Files
58
59 After the build is completed, copy the following files to the appropriate directory on your website:
60
61 ```text
62 fheroes2.data
63 fheroes2.js
64 fheroes2.wasm
65 fheroes2.wasm.map (if fheroes2 has been built in debug mode)
66 ```
67
68 If you want to use the stock launcher (pretty basic at the moment), then you will also need to copy all the files from `files/emscripten` to the same directory.