Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Game Development with WebAssembly

You're reading from   Hands-On Game Development with WebAssembly Learn WebAssembly C++ programming by building a retro space game

Arrow left icon
Product type Paperback
Published in May 2019
Publisher Packt
ISBN-13 9781838644659
Length 596 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Rick Battagline Rick Battagline
Author Profile Icon Rick Battagline
Rick Battagline
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Introduction to WebAssembly and Emscripten FREE CHAPTER 2. HTML5 and WebAssembly 3. Introduction to WebGL 4. Sprite Animations in WebAssembly with SDL 5. Keyboard Input 6. Game Objects and the Game Loop 7. Collision Detection 8. Basic Particle System 9. Improved Particle Systems 10. AI and Steering Behaviors 11. Designing a 2D Camera 12. Sound FX 13. Game Physics 14. UI and Mouse Input 15. Shaders and 2D Lighting 16. Debugging and Optimization 17. Other Books You May Enjoy

A brief introduction to WebAssembly text

WebAssembly binary is not a language, but a build target similar to building for ARM or x86. The bytecode, however, is structured differently than other hardware-specific build targets. The designers of the WebAssembly bytecode had the web in mind. The aim was to create a bytecode that was compact and streamable. Another goal was that the user should be able to do a "view/source" on the WebAssembly binary to see what is going on. WebAssembly text is a companion code to the WebAssembly binary that allows the user to view the bytecode instructions in a human-readable form, similar to the way an assembly language would let you see what opcodes execute in a machine-readable form.

WebAssembly text may initially look unfamiliar to someone used to writing assembly for hardware such as ARM, x86, or 6502 (if you're old school). You write WebAssembly text in S-expressions, which has a parentheses-heavy tree structure. Some of the operations are also strikingly high level for an assembly language, such as if/else and loop opcodes. That makes a lot more sense if you remember that WebAssembly was not designed to run directly on computer hardware, but to download and translate into machine code quickly.

Another thing that will seem a little alien at first when you are dealing with WebAssembly text is the lack of registers. WebAssembly is designed to be a virtual stack machine, which is an alternative to a register machine, such as x86 and ARM, with which you might be familiar. A stack machine has the advantage of producing significantly smaller bytecode than a register machine, which is one good reason to choose a stack machine for WebAssembly. Instead of using a series of registers to store and manipulate numbers, every opcode in a stack machine pushes values on or off a stack (and sometimes does both). For example, a call to i32.add in WebAssembly pulls two 32-bit integers off the stack, adds them together, then pushes their value back on to the stack. The computer hardware can make the best use of whichever registers are available to perform this operation.

You have been reading a chapter from
Hands-On Game Development with WebAssembly
Published in: May 2019
Publisher: Packt
ISBN-13: 9781838644659
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image