MonoGame
MonoGame copied to clipboard
MonoGame on Web
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?
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?
@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.
@kg is the creator of JSIL....
I didn't know that :)
I'm going to check that out, thanks!
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)
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!!!
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.
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.
http://www.godotengine.org/wp/webassembly-godot-on-the-web/
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.
At some point you'll be able to use WebAssembly with compilers like JSIL and GWT, hopefully. It's on the long-term agenda.
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.
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.
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
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.
Guessing WebGL 0.94 is too old. Aww :(
@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.
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.
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.
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.
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 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 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)"?
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.
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.
@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.
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 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.
Only input is implemented, graphics/audio/loading content is not.
In theory they could give my MonoGameJs a try?
Any news about c#, monogame and web?
I would like to run my monogame projects in a browser and i do not know how.