James Gregory, a kick ass architect at Zynga, recently took on an investigation on cross platform technologies with a focus on how do you get c++ code to run on the web. You can read about what he did at code.zynga.com.
The core question we are wrestling with at Zynga is how to you deliver a game on a variety of platforms concurrently without compromising the user experience.
Historically this has been a fools game. The hardware on multiple platforms has been so divergent so as to make it impossible to do. But as mobile devices and in particular tablets that are turning into PC’s in terms of hardware, and PC’s turn into tablets, the potential exists to deliver ubiquitous and similar experiences.
As someone who has been in the tech industry for a long time, what’s surprising is how hard it is to write portable code given the similarity of the underlying hardware. In the 90’s on UNIX we had radically different hardware and yet writing portable code was easy. In fact, the industry worked hard to try and make software portability possible*.
What’s made it hard to get software portability has been the OS interfaces that are widely divergent and worse require different programming languages.
One particular challenge we have is that in addition to writing games that run on multiple mobile devices, we also want to have games that run within web browsers.
Which brings me to C++. (Although I find it funny that the permanent URL to this blog post is c-c-is-the-answer, dropping the ++… the Universe trying to comfort me).
C++ as a low-level cross platform technology for mobile games is awesome. C++ delivers performance, and control and with a modicum of effort it’s possible to call into the underlying native interfaces of the OS.
The other nice thing about C++ is that it’s a language the gaming industry has a long history of using and is comfortable with.
The problem has been how do you go from C++ to the web.
What has made emscripten so interesting is that it makes it possible to go from C++ to javascript using a completely open tool chain. The reason this is interesting is that it allows us to deploy the amazing C++ talents of the entire gaming industry to the problem of getting C++ to the web.
The core approach of emscripten is something we’ve believed in for a while at Zynga. That the way you get to the web and mobile is have a programming language that compiles to multiple targets where a viable target is a web virtual machine (javascript or flash). The compilation of C++ to javascript is also somewhat of a blast from the past for me … after all it’s just like cfront. In fact some of the javascript output reminds me of the cfront output I used to edit …
The emergence of this tool chain is potentially huge. With an armada of C++ programmers chipping away at the problem, because after all the entire gaming industry has the same problem, there is hope that in a very short period of time C++ will be a viable and easy to use tech for building mobile and web-apps.
Obviously we are at the early stage of this process. But the recent port of cocos-2dx via emscripten to the web is a very very encouraging first step. What it shows is that it is possible to write your game in C++ using a cross platform library and re-target that application to the web without having to rewrite anything…
* Well okay, anyone who was involved in POSIX knows that we really worked very hard to make it IMPOSSIBLE to write portable code but the government was pushing us very hard to make it easy to port their code..