Having fun with Emscripten

Recently, I discovered a toolkit called Emscripten which basically allows you to compile your C and C++ code to JavaScript. I thought that would be impossible or at least very slow. But I was wrong. That compiled code is fast! It can run near native speeds if optimised well. It supports SDL and OpenGL ES out of the box, and they demonstrate this with a lot of included examples.

This made me think… do I have some C++ SDL game lying around ready to convert? Yes I have. Oemfoeland 5 is a perfect fit for this, and for the past few weeks I spent my free time on converting it to JavaScript. I had to do a lot of refactoring though, because I have a lot of nested mainloops. You are not allowed to call SDL_delay, and you have to organise your event loops such that it can be called by JavaScript asynchronously. A lot of swears later, you can see the result here: Play Oemfoeland 5 in your browser!!!

Please let me know if this works for you. It probably still has some small bugs, but the basics should work. I also ported the complete Level Editor. I still have to find a way to allow saving your own levels. It would be awesome to be able to share your own designs and play levels from other people. Suggestions on this part are also appreciated.

Have fun playing Oemfoeland 5!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>