Why asm.js is a big deal for game developers

I’ve been following Emscripten for a while now. It was pretty solid months ago, and it keeps getting better. Now that asm.js is beginning to show pretty impressive results and Chrome is apparently considering to implement optimisations for it, things are looking pretty good for native code in the browser these days.

So, why would anyone want native code in the browser? Legacy code, you might think, but that’s not really it. Games is the biggest reason.

C++ is the single most important language in (professional) game development, and before that it was C. Before that various assembler dialects. See the pattern? Many game developers, especially indies, use engines where they can work in higher-level languages, but you still need to run these on everything that calls itself a gaming device. And they’re of course almost all written in C or C++. So there’s really no way around native code execution if you want games on your platform, that’s why every notable mobile platform has added them, sometimes reluctantly.

Why C++?

There are numerous reasons why most of the game industry is still using C++. One is that it’s pretty much the only language you can use on every single platform that runs games, from desktop to handheld consoles. Another is that, as opposed to desktop applications, games usually have the exact same user interface across platforms. So rewriting it in the platform’s native frameworks, as is a popular approach to mobile apps these days, does not make much sense. You usually want one code base that runs everywhere. C and C++ are the only reasonable options for that right now. And even though many atrocities have been committed with C++, you can actually write nice code in it – look to the likes of Stroustrup and Carmack for that.

Why not JavaScript?

But couldn’t people just use JavaScript and ship their game with an app that embeds WebKit? Hardly. Browsers and mobile browsers are becoming faster, but the bleeding edge is still barely able to deliver the kind of games that were running fine in Flash ten years ago. Yet current desktops and smartphones are capable of so much more than that. WebGL could arguably fix this, but even if mobile browsers weren’t so slow to implement it, and Microsoft wouldn’t refuse to adopt it, you’ll still end up with significantly more overhead and stricter hardware requirements than if you just make a native game.

I’ve thought long and hard about whether I should make web-based games. I’ve been developing web applications during my day jobs for more than five years now, and JavaScript has been my main language all the time, so it seemed like a no-brainer. But I want to use proven libraries like SDL and Box2D, I want to support older operating systems and hardware, and I don’t want to spend my time optimising every little algorithm I write (which is what I ended up doing for pretty much all browser games I worked on so far). It’s C++ for me.

So, why is asm.js a big deal?

Because the browser is suddenly a feasible platform for game developers, most of which previously ignored it. It’s not a huge investment anymore, you can still ship the same code base to desktop, mobile and consoles. You can even feasibly have a web-based demo and then deliver the full game as a native application, or make an MMORPG free to play with a limited browser client, and have people pay money for the gorgeous native client. We’ll probably see all the big third party engines compile to asm.js in no time, Unreal Engine having already taken the lead. Browsers will either support WebGL or lose users. I’m betting my money on the former. This is very likely the dawn of the browser as a proper gaming platform.