-
Notifications
You must be signed in to change notification settings - Fork 162
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
Adds Emscripten platform #1423
Adds Emscripten platform #1423
Conversation
bf96636
to
f278ae8
Compare
2d1f68a
to
464e1e2
Compare
This PR adds a new build_emscripten task which uses latest Emscripten to build AGS source code. This new task has it's own artifacts, which contain:
by running ags.html on webserver and loading it in a browser, you should be able to play AGS games on it. I updated the version below with the result of the previous latest build from here: https://ericoporto.github.io/agsjs/ Only thing missing now is probably a README in the Emscripten directory, but not sure what to write on it. |
IMHO it would be nice to have all the description from the old PR here, because I had a number of questions and only found explanation in the old PR's description. So I have to refer to it too. |
@@ -82,19 +87,25 @@ void WaitForNextFrame() | |||
|
|||
auto frame_time_remaining = next_frame_timestamp - now; | |||
if (frame_time_remaining > std::chrono::milliseconds::zero()) { | |||
#if AGS_PLATFORM_OS_EMSCRIPTEN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: should not this logically check for AGS_DISABLE_THREADS?
if not, what is the reason that Emscripten can work with SDL_Delay but not std:: thread sleep?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theoretically both should work, Asyncify should work with either of them - this is the spot Asyncify should unroll the stack, allow the browser to do it's work and come back. But for some reason the result with std::thread currently is the browser getting unresponsive - which is weird since it's written by Emscripten people. SDL_Delay appears to use some JS wait function when running with Emscripten, and it's working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I forgot, you can enable threads which will run the Sound thread through a JS Worker (Emscripten pthreads), but the "main" thread runs on the browser and still requires the browser to have some time to draw and process inputs. So the SDL_Delay is just because it's Emscripten, but the sounds parts are the difference between with thread and without threads.
@ivan-mogilko did you understand the building process? I can add a bat script too if you want - with the lines in the README. |
So, I tried this, and soon got into the first problem: emsdk requires Python 3.9, which apparently does not support Windows 7 (which i'm still using). I will try on Windows 10 VM, unless there's a way to use lower version of Python with emsdk? In any case it would be nice to mention system limitations of this building process. |
I think anything above python 3.6 should be good (due to a change in SSL on GitHub/ old OpenSSL in python), but Windows specifically requires python above 3.9.2 it appears, which is only compatible with Windows 10 and 11 - in Windows 10, you just type python on the terminal once and it will prompt an install of python through the Windows package mangement system through the MS Store. Edit: I added a bit more info in the README, i can squash that and the previous commit in the other commits that create the files they edith in this branch before merge. |
Hmm, maybe it will be easier to do this on Linux, as I have git and repositories installed there. |
Ok, sorry for delay (i got distracted again), I managed to install and activate emsdk on my Windows 10 virtual machine, so will continue from there.
This does not work for me btw, I am using a stripped down version of OS, it does not have much set up; so anyway I just install everything by hand. |
Alright, the success! There were some hiccups, but eventually i've got a random ags game working in a browser. Few notes in regards to the building process.
On running.
In regards to this PR, the Emscripten readme link need to be added to the root readme, where we have all the ports listed. |
The
The engine is the same, just the html ui is different, so I added it in the same directory, you can just use the other after build instead - no need to change the command line parameters. I will add a note in the readme to clarify this.
Uhm, there may be differences depending on how python is installed, but
I don't experience this, but right at launch it downloads the ags.wasm and does the initial allocation for it - doesn't "run" it since that requires a game. I wonder if it's because you are using the browser in a VM. :/ Did you experience this in your Windows 7 machine too? Ah, yes this reminds, the port is not perfect, it has a different FreeType version and some fonts show up slightly different because of it. I could not manage porting the specific version we use. Emscripten ports has a different FreeType version and current main FreeType branch is also compatible with Emscripten (it can be built and linked directly). The newer FreeType mostly works fine. |
6881ce9
to
11e7c45
Compare
My last nitpick in this PR here is this code: https://github.com/ericoporto/ags/blob/emscripten/Engine/main/graphics_mode.cpp#L542-L548 The function When we receive SDL event SDL_WINDOWEVENT_SIZE_CHANGED, we first of all call gfxDriver->UpdateDeviceScreen, this is where graphics driver must update its display mode. Here's the Software renderer's implementation:https://github.com/ericoporto/ags/blob/emscripten/Engine/gfx/ali3dsw.cpp#L162. I.e. do something like:
Is this action actually necessary only for the software renderer, or is it just that only software renderer works for Emscripten now? |
Hey, I will look into this, if I remember correctly it's actually just other renderers except software, I think I pulled the hack from SDL renderer source - basically the browser has a delay between changing the size of the canvas and the resize of the screen/browser. I will introduce an additional change in the CI for Emscripten have it's own docker image so the dependencies, emsdk stdc++ and other stuff is prebuilt once to avoid it breaking if some upstream server is not working for whatever reason or upstream breaks something (e.g.: current fix is emscripten-core/emscripten#15985) Edit: my fix was merged upstream, once there's a release I will pin it :) |
ef527f6
to
86f5aed
Compare
aa826e4
to
c8a16cd
Compare
I dropped the resize change commit, it appears it's not needed for it work with current version of Emscripten and SDL2. I also rebased the build. Updated the build result in here: https://ericoporto.github.io/agsjs/ (but not the single game example hosted there, that one is attached to a Google Chrome bug report :/) Should we need, the original PR I kept in a different branch here: https://github.com/ericoporto/ags/tree/emscripten-orig-pr (including ericoporto@b4728de) Also, if this is merged before the sound changes PR I think that may have merge conflicts, so merge that before, rebasing and adjusting this one is much simpler. |
Sorry, looks like i missed the last comment again. This seem fine now, the changes to the engine code are minimal, and mostly under the AGS_DISABLE_THREADS macro. EDIT:
I was not certain, what PR does this refer to... |
This is for the Web Assembly + HTML + JS version of the engine for the web. Redoing of #1346
Just updating the Emscripten PR, adding CI.
It's using the latest Emscripten tools, but we can always use 2.0.16, which is "old", but may be easier to work with.
Following bugs to fix in upstream, using workaround for now:
Adding a build target on the Editor is something I would prefer to do in a later PR. Here's the preview: https://github.com/ericoporto/ags/tree/feature-webbuild
Edit: I also found a bug in Chrome for Android, it's been tracked here: https://bugs.chromium.org/p/chromium/issues/detail?id=1285389 (I can only reproduce the bug in one of my phones though, and a particular emulator config)
Fix has been commited: https://chromium.googlesource.com/v8/v8/+/ed1cd8f10505c2d8da0d9f896e7589b1299dc95b