HTML and CSS Reference
In-Depth Information
void main_loop() {
process_input();
simulate_world();
render_graphics();
}
Note that, in Listing 18-17, the game loop is handled by the browser, allowing it to update the display and
response to input events. The loop body, however, is implemented by the game in the main_loop() function, giving
your game control over its simulation and rendering.
The Emscripten Platform
So far we've discussed Emscripten's compiler, how to access the browser's graphics, sound, and input APIs, and
how to port a C++ game to the Web with Emscripten. Now let's talk about releasing the same game on multiple
platforms.
As with any multiplatform development strategy, simply consider Emscripten as just another platform, like iOS,
Android, or Windows. Your engine will need some Emscripten-specific platform components, such as input device
detection and configuration, the ability to invoke HTML5's full screen and pointer lock APIs, and any other browser-
specific APIs. The web's capabilities come from the browser through JavaScript, but they need to be accessed through
Emscripten.
At the time of this writing, Emscripten is not a complete product; rather, it's more of a functional proof of concept.
You will likely run into gaps in the platform, though they are being addressed over time. Various platform components
may be missing, incomplete, unspecified, or subject to change. For example, even though Emscripten has built-in
support for much of SDL and OpenGL fixed-function, I had to stub out or implement the functions in Listing 18-18
when porting AstroMenace.
Listing 18-18. Unimplemented Emscripten Functions Used by AstroMenace
glPushAttrib
glPopAttrib
gluErrorString
glLightf
glMaterialfv
glLightfv
SDL_GetWMInfo
SDL_GetGammaRamp
gluBuild2DMipmaps
alIsSource
alSourceRewind
SDL_WaitEvent
Don't be intimidated, however! The rate at which Emscripten is improving is impressive. Over the period in
which I have been using Emscripten, many of its bugs and limitations have been fixed.
If you discover a gap in the platform capabilities, you can either implement said gap in Emscripten itself or
implement a stub in your own code. Of course, make sure you file a bug against Emscripten itself! The Emscripten
community is helpful and responsive, so perhaps it will be fixed before you notice.
 
Search WWH ::




Custom Search