Mozilla turned some heads last week when they announced BrowserQuest, an HTML5 powered MMO that runs in any compatible browser. That was just the beginning of the potential for HTML5 to power games and other applications in-browser. Of course, BrowserQuest was built from the ground up for HTML5. What about games built in stand alone executable languages like C++?
For this particular experiment, Alon Zakai of the Mozilla Emscripten team, used the open source game Me and My Shadow. It’s a puzzle/platformer game where the player controls two characters at once. The port created by using the Emscripten compiler “works almost exactly like the desktop version does on the machines and browswers” Zakai tested it on.
The particular success of this port is due to the game’s use of the SDL API. For those unaware, the SDL API is a wrapper library for basic game functionality like getting input, loading images, and rendering text. Emscripten has SDL support through the use of native canvas calls, which allows the game to run as fast in browsers as it would natively on the desktop.
There are a few problems, however, with this porting method that can be fixed by the browser creator themselves. The first problem is that typed arrays are needed to run C++ code quickly. Firefox, Chrome and Opera have the necessary typed arrays to make maximum compatibility possible. Zakai says that Safari should be fine ready soon and that Internet Explorer will be getting the capability in IE10.
The other problem comes from the Blob constructor. This is necessary for decoding the visuals and the audio of the game. Most browsers should be able to decode the visuals in the game, but the audio is where things start to fail. Zakai claims that only Firefox is currently capable of decoding the audio, but says that there may be a workaround somewhere in Chrome.
Emscripten isn’t perfect though as it still requires a bit of manual programming on the part of the person doing the port. Here’s how Zakai explained it:
Regardless of the few kinks that need to be worked out, this looks like a quick and easy way for developers to bring their games to the Web. If you want to check out Me and My Shadow running on the Web, you can play the game here.