Multiplayer Game Programming: Architecting Networked Games (2016)
Networked multiplayer games are a huge part of the games industry today. The number of players and amount of money involved are staggering. As of 2014, League of Legends boasts 67 million active players each month. The 2015 DoTA 2 world championship has a prize pool of over $16 million at the time of writing. The Call of Duty series, popular in part due to the multiplayer mode, regularly has new releases break $1 billion in sales within the first few days of release. Even games that have historically been single-player only, such as the Grand Theft Auto series, now include networked multiplayer components.
This book takes an in-depth look at all the major concepts necessary to program a networked multiplayer game. The book starts by covering the basics of networking—how the Internet works and how to send data to other computers. Once the fundamentals are established, the book discusses the basics of transmitting data for games—how to prepare game data to be sent over the network, how to update game objects over the network, and how to organize the computers involved in the game. The book next discusses how to compensate for unreliability and lag on the Internet, and how to design game code to scale and be secure. Chapters 12 and 13 cover integrating gamer services into and using cloud hosting for dedicated servers—two topics that are extremely important for networked games today.
This book takes a very practical approach. Most chapters not only discuss the concepts, they walk you through the actual code necessary to get your networked game working. The full source code for two different games is provided on the companion website—one game is an action game and the other is a real-time strategy (RTS). To help with the progression of topics, multiple versions of these two games are presented throughout the course of this book.
Much of the content in this book is based on curriculum developed for a multiplayer-game programming course at the University of Southern California. As such, it contains a proven method for learning how to develop multiplayer games. That being said, this book is not written solely for those in an academic setting. The approach taken by this book is just as valuable to any game programmer interested in learning how to engineer for a networked game.
Who Should Read This Book?
While Appendix A covers some aspects of modern C++ used in this book, it is assumed that the reader already is comfortable with C++. It is further assumed that the reader is familiar with the standard data structures typically covered in a CS2 course. If you are unfamiliar with C++ or want to brush up on data structures, an excellent book to refer to is Programming Abstractions in C++ by Eric Roberts.
It is further assumed that the reader already knows how to program single-player games. The reader should ideally be familiar with game loops, game object models, vector math, and basic game physics. If you are unfamiliar with these concepts, you will want to first start with an introductory game programming book such as Game Programming Algorithms and Techniques by Sanjay Madhav.
As previously mentioned, this book should be equally effective either in an academic environment or for game programmers who simply want to learn about networked games. Even game programmers in the industry who have not previously made networked games should find a host of useful information in this book.
Conventions Used in This Book
Code is always written in a fixed-point font. Small code snippets may be presented either inline or in standalone paragraphs:
std::cout << "Hello, world!" << std::endl;
Longer code segments are presented in code listings, as in Listing 0.1.
Listing 0.1 Sample Code Listing
// Hello world program!
std::cout << "Hello, world!" << std::endl;
For readability, code samples are color coded much like in an IDE.
Throughout this book, you will see some paragraphs marked as notes, tips, sidebars, and warnings. Samples of each are provided for the remainder of this section.
Notes contain useful information that is separate from the flow of the normal text of the section. Notes should almost always be read.
Tips are used to provide helpful hints when implementing specific systems in your game’s code.
Warnings are very important to read, as they contain common pitfalls or issues to watch out for, and ways to solve or work around these issues.
Sidebars contain lengthier discussions that usually are tangential to the main content of the chapter. These can provide some interesting insight to a variety of issues, but contain content that is deemed nonessential to the pedagogical goals of the chapter.
The vast majority of this book uses C++ because it is still the de facto language used in the game industry by game engine programmers. Although some engines allow a great deal of code for a game to be written in other languages, such as Unity in C#, it is important to remember that most of the lower-level code for these engines is still written in C++. Since this book is focused on writing a networked multiplayer game from the ground up, it makes the most sense to do so in the language that most game engines are written in. That being said, even if you are writing all your game’s networking code in another language, all the core concepts will still largely be the same. Still, it is recommended that you be familiar with C++, otherwise the code samples may not make much sense.