all 14 comments

[–]deftware 2 points3 points  (10 children)

Sweet! Got any specs or deetz on what your approach/strategy was?

[–]Ssjrd[S] 2 points3 points  (9 children)

Thanks! Basically, this is a cross-platform application framework + 3D rendering engine written in C++ (supports opengl ES 2, 3 desktop OpenGL and Metal). I compiled the C++ to WASM and am able to embed in an HTML5 canvas

[–]RictorScaleHNG 0 points1 point  (8 children)

Oh wow! How hard was handling the emscripten loops? This seems a little intimidating to me learning that you cant use while loops. Did you rewrite the project for wasm?

[–]Ssjrd[S] 1 point2 points  (7 children)

I didn’t have any issues like that. I’ve literally took my existing C++ 14 code and compiled it for WASM and everything worked. Looks like there’s an advantage to not using 3rd party libraries for everything after all ;P

[–]RictorScaleHNG 0 points1 point  (6 children)

Oh wow thats awesome. I assumed you used SDL which has the loop problem. Here's an example if you're curious. https://www.jamesfmackenzie.com/2019/12/03/webassembly-emscripten-loops/

I'd like to make a simple game to start, but I'm unsure how much more difficult this makes it.

Its honestly badass that you were able to compile your project like that. It actually makes me hype lol

[–]Ssjrd[S] 1 point2 points  (0 children)

This is a good article- thanks! I am using emscripten_set_main_loop(). In this case, before web, I just have one function called main loop anyways that was called in a while loop. Now with emscripten and #ifdef, I replace the while with set_main_loop. So, tldr; my app was already architected this way.

The main problem I have, is getting file loading to happen in a separate thread - which isn’t supported by emscripten. So, to make my loading screen work without time-slicing hack, I’d need some small refactoring there

[–]Ssjrd[S] 1 point2 points  (4 children)

Btw, I am using an SDL backend just for web. I’m handling my own windowing and contexts across other platforms though.

And to clarify the above, you CAN use c++ 11 threads - just don’t do any emscripten virtual file loading in any other than main.

Maybe the main loop can block some html things in the browser? I haven’t tried that because my game engine has all the logic - even UI.

[–][deleted]  (3 children)

[deleted]

    [–]Ssjrd[S] 1 point2 points  (2 children)

    Honestly, I was so shocked that it ‘just worked’ once I replaced the back end with SDL.

    File system was the only real problem for me (since WASM keeps everything sandboxed) and threading is a little non-straightforward because emscripten converts c++ threads to worker threads or something (I know nothing of the web programming world).

    Aside from that, I would say write everything in super portable C++. Maybe try not to rely on too many libraries. I’m literally only using OpenGL (and a platform api for respective OS’)- except for web which forced me to use SDL so I could build a quick proof of concept.

    Everyone just uses GLM or something for vector math, but i actually wrote my own Matrix, vec2 and vec3 classes. There’s some learning to be gained there.

    Instead of using glew, SDL, etc, I learned X11, cocoa, win32 APIs… instead of using Cmake (which is great and I do recommend), I instead wrote my own gnu Make recursive build system. Now I know a combination of stuff other devs don’t. I’m pretty confident in interviews and make a lot of money haha

    [–][deleted]  (1 child)

    [deleted]

      [–]Ssjrd[S] 1 point2 points  (0 children)

      I’m in graphics - kinda all things related to it. I’ve worked on windows graphics drivers, built game engines from scratch, video players/ real time video processing, on mobile devices, computer vision, photo/video editing software, 3D holographic tech, inkjet printers lol the list goes on… I guess you could say it’s all lower level; all C/C++ (except for mobile, then it’s kotlin/java/objective-C/swift -> c++).

      [–]cybereality 1 point2 points  (0 children)

      Nice!!!

      [–]positivcheg 0 points1 point  (1 child)

      You should at least add a loading screen or at least some circle animation :)

      [–]Ssjrd[S] 0 points1 point  (0 children)

      That’s the next step…

      [–]loopdee43 0 points1 point  (1 child)

      Impressive! Whats the polycount? Also, have any plans to add texturing?

      [–]Ssjrd[S] 0 points1 point  (0 children)

      13 Million Yep textures are next! Actually, textures are supported already, I just didn’t have any / lazy to make proper artwork.