HTML and CSS Reference
In-Depth Information
Listing 18-10. Breaking into the Debugger on Fatal Errors
void fatal_error(const char* message) {
fprintf(stderr, "fatal error: %s\n", message);
#ifdef __EMSCRIPTEN__
#elif defined(WIN32)
Since debugging Emscripten-generated code is not pleasant, I recommend maintaining a native Windows, Mac,
or Linux build of your game and using that for active development. That way, you'll know that any problems that
occur in the Emscripten build are Emscripten-related.
A Game Port
Now that we've covered Emscripten from a high level, let's take an existing game and port it to the Web. Alas, I can't
share any proprietary engine code, but there are a few open source 3D games that will provide an example of the kind
of problems you might face when bringing a C++ game to the Web with Emscripten.
Choosing a Game
For this demonstration, I chose to port the game AstroMenace. It's simple, 3D, has few dependencies, and sufficiently rich
that it provides a good example of what's possible on the Web. As you'll see, a game that didn't depend on the OpenGL
fixed function pipeline would have been much easier, so when you port your game or engine to Emscripten/WebGL, it
helps to have a pure OpenGL ES 2.0 renderer.
Getting Emscripten
To port a game to Emscripten, you need two things: the game's source code and the latest Emscripten. As a point of
detail, I am assuming you are using Linux or Mac OS X. The Emscripten compiler runs on Windows but it's a little
easier from the Linux or Mac command lines.
Many emscripten tools are written in python, and per pep 0394 ( ) ,
the emscripten tools attempt to run the python2 command by default. On most Linux distributions, python2 is a symlink
to whatever version of python 2 is installed, but on Mac you may have to create this symlink yourself with sudo ln -s
/usr/bin/python /usr/bin/python2 .
At the time of this writing, the best way to get Emscripten is to download the Emscripten SDK from . However, you may want to maintain your own local fork of the Emscripten git repository,
in case you need to modify anything during the porting effort. My local modifications for the purposes of the
AstroMenace game port are available at .
You can follow the development process, in its unfiltered fits and starts, at my git repository at .
Search WWH ::

Custom Search