C++ to Web = WebAssembly. Polling for feature request

I didn’t really have time to read about WebAssembly, so my question might seem stupid, but how does it differ from emscripten?

@Boby Emscripten is a compiler (LLVM-based). WebAssembly (Wasm) can be thought of as a standardized version of asm.js. So the process would likely be fixing issues with cocos2d-x so that it (engine + 3rd party libs) can be built with Emscripten into asm.js now and in the future Wasm.

1 Like

@stevetranby Thx. for links - really interesting articles.

@Boby - In a simplified form the difference is:
Emscripten generates JavaScript that use Asm.js
WebAssembly generates bytecode that “directly” runs in browsers.

1 Like

Afaik, currently MS Edge and Safari still doesn’t support it. Only the latest Chrome (canary) and Firefox (nightly build)

It seems that there is Edge support:

Im on record as hoping for WA support

Potential benefits of WA:

  • one codebase that supports mobile, desktop, and web
  • the speed that comes from compiled code
  • access to c/c++ libraries

I think that if/when cocos2d-x starts adding more 3d support (and shouldnt we change the name to just cocos-X then?) that WA will start making more and more sense.

@SpecialWE

Yep - the message on DEMO page is “little” strange:

=========

Uh-oh! WebAssembly isn’t enabled in this browser. To get an early preview of this experimental technology, at your own risk:

  • on Chrome Canary, open chrome://flags/#enable-webassembly and enable the switch.
  • on Firefox Nightly, open about:config and set javascript.options.wasm to true.

See a preview of Microsoft Edge support and follow Safari support on WebKit’s feature status page.

But I think is just out of date.

I checked once again:
Firefox 50.0.2 (For macOS) - stable, not nightly build.
Worked - just need turn on “about:config javascript.options.wasm” flag.

Chrome 55.0.2883.75 (64-bit) (For macOS)
Worked - just need turn on “chrome://flags/#enable-webassembly” flag.

Yep - this is not all browsers - but the main is that all are working in this direction.

Any update?

Would like to upvote this feature request. Now that Chrome and Firefox have already gotten it live.

This would have to come from the community. There’s very little chance Chukong will work on this feature.
It’s probably smarter to replace the renderer with SDL or BGFX instead of trying to get the engine to compile.
If someone is already working on this with the latest 3.15 code revision that’d be great. It’s possible to get it compiling, but it may or may not take quite a bit of tedious work??

I keep looking into it, and simple OpenGL examples are easily ported to emscripten, but the cocos2d code base has a lot of extra libraries/frameworks that must support it.

Would love to hear of any progress, but I am not holding my breath. Prob smarter to move to Urho3D or other engine if it’s a feature you need. Or just port to cocos-js/creator :smiley:

Last week we tried WASM of cocos2d-x of a commit of this January. It works properly.

We are thinking of adding it back to main branch.

4 Likes

Yes @ShunLin that is great news :+1:

In a WASM capable browser does it perform better than the JS version?

Yep, i used PerformanceSpriteTest, WASM is about 50% quicker then cocos2d-html5, and takes less memory. But there is a problem that, all codes in a wasm file, and all resources in a data file which makes loading much slower than cocos2d-html5.

So not a complete win for WASM. There are always tradeoffs! Thanks @zhangxm

Now that WebAssembly support has been added to Safari, it appears that all the major browsers now support it.

I also want to upvote this feature request. My C++ App is available on all platforms except the web and too large already to be easily rewritten in Javascript. WebAssembly would be a major benefit for my App.

+1, this would be very helpful indeed

very welcomed feature…

@ShunLin so can we expect further work into it, On trello i don’t see any promising development efforts planned for c++ engine, would like to see if some one could clear a bit of air around c++ side.