Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add emscripten(web/wasm) build target #445

Closed
wants to merge 8 commits into from

Conversation

ololoken
Copy link

Simple way to run build

docker run --rm -v $(pwd):/src emscripten/emsdk:3.1.74 \
  sh -c 'git config --global --add safe.directory "*" && mkdir -p build && cd build && emcmake cmake ../ -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchain/Emscripten.cmake && emmake make'

Demo

Demo sources https://github.com/ololoken/fallout2-ce-ems

@roginvs
Copy link
Contributor

roginvs commented Jan 19, 2025

Nice job! I did a similar thing for https://fallout-nevada.ru but still did not make a local version (that was in my TODO). My main concern was memory requirement because if we pre-load all files into memory then it might fail on tablets or mobiles.
Here are my changes, JS part is pretty hacky but it works fallout2-ce/fallout2-ce@main...roginvs:fallout2-ce:main

Some improvements which I made in my branch:

It will be really nice to have a web build in github pages

Copy link
Contributor

@roginvs roginvs left a comment

Choose a reason for hiding this comment

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

You can also open a PR into fallout2-ce organization (https://github.com/fallout2-ce/fallout2-ce). Alexander shows up here not so often as we wish to so we created a github organization to merge some PRs and to have releases there.

We can also do a fork of your webinterface into organization if you want. Or even copy-paste web code into the repository (so it will rebuild and redeploy when fallout code changes or web page)

else()
find_package(ZLIB)
find_package(SDL2)
endif()
else()
Copy link
Contributor

Choose a reason for hiding this comment

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

What optimization level will it have by default? Using -O2 or -O3 caused my build to crash on iphone or ipad so I have to use -O1

Copy link
Author

Choose a reason for hiding this comment

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

emscripten wasm has serious issue with memory on handheld devices. This option -sALLOW_MEMORY_GROWTH creates copy of entire virtual memory when malloc requests additional block. I think we need to experiment with -sINITIAL_MEMORY to find optimal pre-allocated memory size.

@@ -57,6 +62,20 @@ int xfileClose(XFile* stream)
break;
default:
rc = fclose(stream->file);
#if defined( __EMSCRIPTEN__ )
Copy link
Contributor

Choose a reason for hiding this comment

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

Small note: In my branch I've used fsync call which causes IDBFS to write changes into the database. Also, it pauses game process (via asyncify) so when player sees "game saved" all data is actually written into idbfs

Copy link
Author

Choose a reason for hiding this comment

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

I tried to make seamless process of syncing virtual fs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe to use EM_ASYNC_JS to ensure that file is saved?

EM_ASYNC_JS(void, do_save_idbfs, (), { 
  await new Promise((resolve, reject) => FS.syncfs(err => err ? reject(err) : resolve()) 
})

CMakeLists.txt Outdated
target_link_options( ${EXECUTABLE_NAME} PRIVATE "-sEXPORTED_RUNTIME_METHODS=callMain,addRunDependency,removeRunDependency" )
target_link_options( ${EXECUTABLE_NAME} PRIVATE "-sEXPORT_ALL" )
target_link_options( ${EXECUTABLE_NAME} PRIVATE "-sEXPORT_NAME=fallout2ce" )
target_link_options( ${EXECUTABLE_NAME} PRIVATE "-gsource-map" )
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add -sCASE_INSENSITIVE_FS ? Just in case

Copy link
Author

Choose a reason for hiding this comment

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

Good catch, I will add this option.

@ololoken
Copy link
Author

ololoken commented Feb 1, 2025

Merged here fallout2-ce#32

@ololoken ololoken closed this Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants