You are previewing Learn C++ for Game Development.
O'Reilly logo
Learn C++ for Game Development

Book Description

"

If you're new to C++ but understand some basic programming, then Learn C++ for Game Development lays the foundation for the C++ language and API that you'll need to build game apps and applications.

Learn C++ for Game Development will show you how to:

  • Master C++ features such as variables, pointers, flow controls, functions, I/O, classes, exceptions, templates, and the Standard Template Library (STL)
  • Use design patterns to simplify your coding and make more powerful games
  • Manage memory efficiently to get the most out of your creativity
  • Load and save games using file I/O, so that your users are never disappointed

Most of today's popular console and PC game platforms use C++ in their SDKs. Even the Android NDK and now the iOS SDK allow for C++; so C++ is growing in use for today's mobile game apps. Game apps using C++ become much more robust, better looking, more dynamic, and better performing. After reading this book, you'll have the skills to become a successful and profitable game app or applications developer in today's increasingly competitive indie game marketplace.

The next stage is to take the foundation from this book and explore SDKs such as Android/Ouya, PlayStation, Wii, Nintendo DS, DirectX, Unity3D, and GameMaker Studio to make your career really take off.

"

Table of Contents

  1. Cover
  2. Title
  3. Copyright
  4. Contents at a Glance
  5. Contents
  6. About the Author
  7. About the Technical Reviewer
  8. Acknowledgments
  9. Introduction
  10. Chapter 1: Beginning C++
    1. Compilers
    2. Programming Paradigms
      1. Procedural Programming
      2. Object-Oriented Programming
      3. Generic Programming
    3. C++ Game Programming
    4. Our First C++ Program
    5. Summary
  11. Part 1: Procedural Programming
    1. Chapter 2: Writing a Guessing Game with C++ Types
      1. Dynamic Versus Static Typed Languages
        1. Declaring Variables
        2. Defining Variables
      2. Integers
        1. Unsigned Integers
      3. Two’s Complement
      4. Floating Point Numbers
      5. Boolean Values
      6. Enums
      7. Switching from One Type to Another
        1. static_cast
      8. A Simple Guessing Game
      9. Summary
    2. Chapter 3: Creating Calculators with Operators
      1. The Assignment Operator
      2. Arithmetic Operators
        1. The Addition Operator
        2. The Subtraction Operator
        3. The Multiplication and Division Operators
        4. The Modulo Operator
      3. A Simple Arithmetic Calculator
      4. Relational Operators
        1. Equality Operators
        2. Greater-Than Operators
        3. Less-Than Operators
      5. Simple Comparison Calculators
      6. Bitwise Operators
        1. Hexadecimal Number Representation
        2. The Binary & (AND) Operator
        3. The Binary | (OR) Operator
        4. The Binary ^ (Exclusive OR) Operator
        5. The Left Shift (<<) Operator
        6. The Right Shift (>>) Operator
      7. Logical Operators
        1. The && Operator
        2. The || Operator
      8. Unary Operators
        1. Arithmetic Unary Operators
        2. The Logical Not Unary Operator
        3. The One’s Complement Operator
      9. Summary
    3. Chapter 4: Beginning C++ Game Development with Arrays
      1. The C++ Array
      2. Pointers
        1. Pointer Arithmetic
        2. Dereferencing Pointers
        3. Pointers and Arrays
      3. C Style Strings in Arrays
        1. Working with C Style Strings
      4. Text Adventure Game
      5. Summary
    4. Chapter 5: Functions, the Building Blocks of C++
      1. Writing Our First Function
      2. Passing Parameters to Functions
      3. Return Values
      4. Passing by Pointer
      5. Passing by Reference
      6. Structures
      7. Adding Functions to Text Adventure
      8. Summary
    5. Chapter 6: Making Decisions with Flow Control
      1. The if Statement
      2. The else and else if Statements
      3. The for Loop
      4. The while Loop
      5. The switch Statement
      6. The break and continue Keywords
      7. The goto Statement
      8. Adding a Game Loop to Text Adventure
      9. Summary
    6. Chapter 7: Organizing Projects Using Files and Namespaces
      1. Source and Header Files
      2. Creating Namespaces
      3. Updating Text Adventure with Source Files, Header Files, and Namespaces
      4. Summary
  12. Part 2: Object-Oriented Programming
    1. Chapter 8: Object-Oriented Programming with Classes
      1. Object-Oriented Programming
      2. Encapsulation
      3. Constructors and Destructors
      4. Method Overloading
      5. Operator Overloading
      6. Updating Text Adventure to Use Classes
      7. Summary
    2. Chapter 9: Controlling Data with Access Modifiers
      1. The static Keyword
        1. Creating static Local Variables
        2. Using static class Member Variables
        3. Using static Member Methods
        4. Using static to Alter Global Scope
      2. The const Keyword
        1. Constant Variables
        2. Constant Pointers
        3. Constant Parameters
        4. Constant Member Methods
      3. Two More Keywords
        1. The inline Keyword
        2. The friend Keyword
      4. Summary
    3. Chapter 10: Building Games with Inheritance
      1. Inheriting from a Base Class
      2. Constructors and Destructors in Derived Classes
      3. Method Overriding
      4. Updating Text Adventure
        1. Creating an Entity Class
        2. Adding Inheritance to the Player Class
        3. Adding Rooms
        4. Moving Through Rooms
      5. Summary
    4. Chapter 11: Designing Game Code with Polymorphism
      1. Virtual Methods
      2. Downcasting and Upcasting with dynamic_cast
      3. Creating Interfaces with Pure Virtual Methods
      4. Using Polymorphism in Text Adventure
      5. Summary
    5. Chapter 12: Copying and Assigning Data to Objects
      1. Copy Constructors
      2. Assignment Operators
      3. Move Semantics
      4. Summary
  13. Part 3: The STL
    1. Chapter 13: The STL String Class
      1. Standard string and basic_string
      2. Constructing Strings
      3. Working with Strings
      4. Accessing String Data Through Iterators
      5. Searching Within Strings
      6. Formatting Data with stringstream
      7. Summary
    2. Chapter 14: STL Array and Vector
      1. The STL Array Template
      2. The STL Vector Class
      3. Sorting Arrays and Vectors
      4. Summary
    3. Chapter 15: STL List
      1. Understanding Array and List Memory Layouts
      2. Building a List Class
      3. The STL List Template
      4. Summary
    4. Chapter 16: STL’s Associative Containers
      1. The STL set Container
      2. The STL map Container
      3. Binary Search Trees
      4. Fast Data Access Using a Hash Map
      5. STL unordered_set and unordered_map
      6. Summary
    5. Chapter 17: STL’s Stack and Queue
      1. The STL stack Container
      2. The STL queue Container
      3. Summary
    6. Chapter 18: STL’s bitset
      1. Creating bitset Objects
      2. Working with bitsets
      3. Summary
    7. Chapter 19: Using the STL in Text Adventure
      1. Using STL array to Store Room Pointers
      2. Using a vector and a map to Store Options
      3. Adding Gameplay to Text Adventure
      4. Summary
  14. Part 4: Generic Programming
    1. Chapter 20: Template Programming
      1. Compile Versus Runtime Time Compilation
      2. const Versus constexpr
      3. assert Versus static_assert
      4. Summary
    2. Chapter 21: Practical Template Programming
      1. Creating Singleton Classes with Templates
      2. Implementing the EventManager Class
      3. The EventHandler Interface
      4. The Event Class
        1. The EventManager Implementation
      5. Calculating SDBM Hash Values Using a Template Metaprogram
      6. Using an Event to Quit the Game
      7. Summary
  15. Part 5: C++ Game Programming
    1. Chapter 22: Managing Memory for Game Developers
      1. Static Memory
      2. The C++ Stack Memory Model
      3. Working with Heap Memory
      4. Writing a Basic Single Threaded Memory Allocator
      5. Summary
    2. Chapter 23: Useful Design Patterns for Game Development
      1. Using the Factory Pattern in Games
      2. Decoupling with the Observer Pattern
      3. Easily Adding New Functionality with the Visitor Pattern
      4. Summary
    3. Chapter 24: Using File IO to Save and Load Games
      1. What Is Serialization?
      2. The Serialization Manager
      3. Saving and Loading Text Adventure
      4. Summary
    4. Chapter 25: Speeding Up Games with Concurrent Programming
      1. Running Text Adventure in Its Own Thread
      2. Sharing Data Between Threads Using Mutexes
      3. Using Futures and Promises
      4. Summary
    5. Chapter 26: Supporting Multiple Platforms in C++
      1. Ensuring Types Are the Same Size on Multiple Platforms
      2. Using the Preprocessor to Determine Target Platform
      3. Summary
    6. Chapter 27: Wrapping Up
      1. An Overview of Text Adventure
      2. Summary
  16. Index