Summary
In this chapter, we ported a Tetris clone written in C++ that used SDL2 to Emscripten so it could be run in the browser with WebAssembly. We covered the rules of Tetris and how they map to the logic within the existing codebase. We also reviewed each file in the existing code base individually and which changes had to be made to successfully compile to a Wasm file and JavaScript glue code. After updating the existing code, we created the required HTML and CSS files, then configured a build step with the appropriate emcc
flags. Once built, the game was run using Emscripten's emrun
command.
In Chapter 9, Integrating with Node.js, we're going to discuss how to integrate WebAssembly into Node.js and the benefits this integration provides.