MonoGame icon indicating copy to clipboard operation
MonoGame copied to clipboard

MonoGame on Web

Open harry-cpp opened this issue 10 years ago • 85 comments
trafficstars

I've been thinking on doing some work on this, even tho there is base for JSIL I would like to think of other options as well. Current options on getting C# on Web are:

  • JSIL (may translate C# badly in some cases, but it does produce files runnable even from android)
  • NaCl (requires browser plugin, but will be more precise in running C# than JSIL)
  • PNaCl (Chrome only, no plugin required)

@tomspilman @KonajuGames @dellis1972 What are your thoughts on this?

harry-cpp avatar May 30 '15 14:05 harry-cpp

I've done a little research into JSIL, and found something that I think you guys will find very interesting.

http://hildr.luminance.org/MonoGame/Platformer2D/

It looks like somebody (looks like a contributer to JSIL, actually) decided to do this already. His code can be found at https://github.com/kg/MonoGame/tree/JSIL. The fact that this produces something that we can run on android is also really fantastic.

EDIT:

Apparently we have tried to do this before, and that code never got merged because we were merging another JSIL implementation? What ever happened to that?

WardBenjamin avatar May 30 '15 15:05 WardBenjamin

@kg is the creator of JSIL....

Also in the main JSIL repo there is some code dedicated to porting MonoGame to web(https://github.com/sq/JSIL/tree/master/Libraries/MonoGame), but the way MonoGame planned to do it is a bit different(create a solution for MonoGame, and use that instead of WindowsGL dlls).

Also @WardBenjamin do "Protobuild.exe --generate Web" I think, it will generate JSIL web stuff MonoGame already has.

harry-cpp avatar May 30 '15 15:05 harry-cpp

@kg is the creator of JSIL....

I didn't know that :)

I'm going to check that out, thanks!

WardBenjamin avatar May 30 '15 16:05 WardBenjamin

A client sponsored some recent work on MonoGame & SDL2 (via p/invoke and emscripten) integration for JSIL that is almost ready to merge. I'll try to remember to mention that here when it's available.

On May 30, 2015 8:59:01 AM PDT, Harry [email protected] wrote:

@kg is the creator of JSIL....

Also in the main JSIL repo there is some code dedicated to porting MonoGame to web(https://github.com/sq/JSIL/tree/master/Libraries/MonoGame), but the way MonoGame planned to do it is a bit different(create a solution for MonoGame).

Also @WardBenjamin do Protobuild.exe --generate Web I think, it will generate JSIL web stuff MonoGame already has.


Reply to this email directly or view it on GitHub: https://github.com/mono/MonoGame/issues/3895#issuecomment-107056912

  • kg (mobile)

kg avatar May 30 '15 16:05 kg

A client sponsored some recent work on MonoGame & SDL2 (via p/invoke and emscripten) integration for JSIL that is almost ready to merge. I'll try to remember to mention that here when it's available.

@kg Sweet!!!

harry-cpp avatar May 30 '15 20:05 harry-cpp

NaCl PNaCl

I don't think either of these are good solutions as they are specific to just one or two browsers. The only path I see that works on all browsers and will be fairly fast on most of them is cross-compiling to JavaScript.

This is why we decided on JSIL in the first place.

tomspilman avatar May 30 '15 23:05 tomspilman

Ok, I'm going to wait up to a month to see what's going to happen with what @kg talked about. After that I'll start working on this using JSIL.

harry-cpp avatar May 31 '15 11:05 harry-cpp

http://www.godotengine.org/wp/webassembly-godot-on-the-web/

harry-cpp avatar Jun 22 '15 20:06 harry-cpp

It will be interesting to see when WebAssembly becomes usable... maybe a year or two if we're lucky. Until then JSIL is still a good path for us.

tomspilman avatar Jun 22 '15 20:06 tomspilman

At some point you'll be able to use WebAssembly with compilers like JSIL and GWT, hopefully. It's on the long-term agenda.

kg avatar Jun 22 '15 20:06 kg

The initial monogame work is almost complete (been doing it in my spare time and paying out of pocket since the sponsor bailed), so I'll have a demo & some associated documentation on the JSIL wiki out soon for people to use as a starting point. It's the MonoGame version of the platformer2d sample, running against a fork and using emscripten'd SDL2. Gamepad input, audio, opengl, etc all work. Getting something like this working in trunk monogame will be a challenge but once this is polished up it will be a good proof-of-concept for how to do it.

kg avatar Jul 04 '15 00:07 kg

Here's the working demo. http://hildr.luminance.org/SampleFNA/ https://github.com/sq/SampleFNA

It's using FNA instead of trunk MonoGame, because FNA's use of SDL2 as its single backend made the initial port easier. The general approach should be viable for MG, since it lets you keep all of your PInvoke-based code (that talks to GL or whatever). It's an approach that's also compatible with writing a separate web backend that reuses a subset of the existing native code, instead of reusing all of it and patching up specific spots with JS.

There are a handful of issues left to fix but it's a pretty good proof-of-concept for something like this.

kg avatar Jul 05 '15 17:07 kg

Crashes in IE11 on Win 8.1

Unhandled exception at http://hildr.luminance.org/SampleFNA/bin/JSIL/FNA,%20Version=0.0.0.1,%20Culture=neutral,%20PublicKeyToken=null.js line 11486:
Unable to get property 'bufferSubData' of undefined or null reference

shmuelie avatar Jul 06 '15 17:07 shmuelie

Last time I tested it, IE's OpenGL support was too old, check the error console. If it's something other than GL support I can fix it.

FWIW, that is a major downside to the approach of using emscripten-compiled SDL2 or otherwise: Existing graphics stacks are still pretty heavily dependent on a full GL feature set, and WebGL is more of a stripped-down, crippled GLES.

kg avatar Jul 06 '15 18:07 kg

Guessing WebGL 0.94 is too old. Aww :(

shmuelie avatar Jul 07 '15 03:07 shmuelie

@kg Just FYI about:

For Song playback to work, you'll need to convert Music.wma into an ogg vorbis file called Music.ogg, next to the Music.xnb file created by the content builder above. Sadly, the content builder cannot do this for us. (JSILc may acquire the ability to do this in the future.)

Is not correct, the newest develop branch Pipeline Tool will convert song files to .ogg files as long as platform is set to DesktopGL / WindowsGL / Linux and processor is set to Song.

harry-cpp avatar Aug 04 '15 10:08 harry-cpp

While setting up content manager with JSIL I found that: https://github.com/mono/MonoGame/blob/develop/MonoGame.Framework/Content/ContentManager.cs#L200 causes a crash.

It's not that big of a deal since I was not gonna use that part of the code anyway, but I thought it would be useful to mention it.

@kg For Xna/Fna are you loading xnb or raw(png, ogg, etc)? I started setting up raw loading of stuff.

harry-cpp avatar Dec 03 '15 12:12 harry-cpp

Fna loads raw xnbs and we kept that intact, with the exception of streaming music - I used the browser's audio decoder for that. You could call out to libvorbis I suppose but you'd need to do the emscripten port of that thing yourself.

My hand-written xna stubs used the browser's image decoders (jpeg/png etc) but that's a really bad idea as browsers tend to have really buggy/inconsistent ones.

FYI, please file JSIL bug reports about crashes that only occur in JS builds.

kg avatar Dec 03 '15 12:12 kg

Wow you are fast.

FYI, please file JSIL bug reports about crashes that only occur in JS builds.

I will, first I need to figure out a small code that can reproduce it.

harry-cpp avatar Dec 03 '15 13:12 harry-cpp

Is this still supported?

@kg your demo link crashes under the latest Chrome:

Unhandled exception at http://hildr.luminance.org/SampleFNA/SDL2.js line 4:
Uncaught TypeError: Cannot read property 'getParameter' of undefined

That being said, the RPG demo from the JSIL page runs fine.

ashes999 avatar May 30 '16 01:05 ashes999

@ashes999 Works here, just tried it. Browser vendors love to break HTML5 games, so maybe file a bug report against Chrome. SDL2.js is an emscripten-compiled version of SDL2.

kg avatar May 30 '16 01:05 kg

@kg I'm running Chrome 50.0.2661.102. How about you?

This doesn't exactly inspire me with confidence. I can imagine a fragmented user base complaining about my game crashing and/or not working, and being stuck without the ability to easily troubleshoot it.

Is there a well-defined subset that this should work with? Can I say something like "always works with the latest browser(s)"?

ashes999 avatar May 30 '16 01:05 ashes999

It probably requires WebGL and you don't have it. SDL2.js isn't something I wrote, so it's not under my control.

This doesn't exactly inspire me with confidence. I can imagine a fragmented user base complaining about my game crashing and/or not working, and being stuck without the ability to easily troubleshoot it.

Welcome to HTML5. It's not great.

kg avatar May 30 '16 02:05 kg

Just gonna mention that MonoGame has shifted to using SDL instead of OpenTK so emscripten-compiled version may be an option for MonoGame as well.

harry-cpp avatar May 30 '16 06:05 harry-cpp

@kg I worked directly on JS games in the past and experienced something similar. Thanks for clarifying. I think this is a pretty viable approach for now.

ashes999 avatar May 30 '16 13:05 ashes999

Bump. Hi all, someone on Twitter was asking about the current status of MG's Browser support. Anything I can share publically? PM me if it is not public :)

Hope everyone is well!!

D.

CartBlanche avatar Oct 21 '16 18:10 CartBlanche

@CartBlanche maybe it's not obvious, but JSIL works (with some caveats) with MonoGame. There are some good examples on the JSIL website that you can use. Whether this is stable/reliable enough for you or not, I can't say.

ashes999 avatar Oct 21 '16 18:10 ashes999

Only input is implemented, graphics/audio/loading content is not.

harry-cpp avatar Oct 21 '16 19:10 harry-cpp

In theory they could give my MonoGameJs a try?

shmuelie avatar Oct 21 '16 19:10 shmuelie

Any news about c#, monogame and web?

I would like to run my monogame projects in a browser and i do not know how.

RiuSalvi avatar Jan 04 '17 16:01 RiuSalvi