Learn C++ for Game Development. Apress" Bruce Sutherland

Similar documents
KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

The C Programming Language course syllabus associate level

C++ Programming Language

El Dorado Union High School District Educational Services

Glossary of Object Oriented Terms

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

BCS2B02: OOP Concepts and Data Structures Using C++

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)

Android Application Development Course Program

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

Java (12 Weeks) Introduction to Java Programming Language

An Introduction to Programming and Computer Science

CEC225 COURSE COMPACT

Java EE Web Development Course Program

Object Oriented Software Design II

Object Oriented Programming With C++(10CS36) Question Bank. UNIT 1: Introduction to C++

C++FA 5.1 PRACTICE MID-TERM EXAM

: provid.ir

C++ INTERVIEW QUESTIONS

C++ Language Tutorial

ALLIED PAPER : DISCRETE MATHEMATICS (for B.Sc. Computer Technology & B.Sc. Multimedia and Web Technology)

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Programming Language Pragmatics

How To Teach C++ Data Structure Programming

Curriculum Map. Discipline: Computer Science Course: C++

Fundamentals of Java Programming

OKLAHOMA SUBJECT AREA TESTS (OSAT )

Sample Syllabus (C++) CSCI 1301 Introduction to Programming Principles

Chapter 6: Programming Languages

I PUC - Computer Science. Practical s Syllabus. Contents

Java Application Developer Certificate Program Competencies

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

TECHNOLOGY Computer Programming II Grade: 9-12 Standard 2: Technology and Society Interaction

WORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Bachelor of Games and Virtual Worlds (Programming) Subject and Course Summaries

C++FA 3.1 OPTIMIZING C++

Course Title: Software Development

Java Interview Questions and Answers

C++ Support for Abstract Data Types

Java SE 8 Programming

Symbol Tables. Introduction

core. Volume I - Fundamentals Seventh Edition Sun Microsystems Press A Prentice Hall Title ULB Darmstadt

Programming and Software Development CTAG Alignments

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards

An Incomplete C++ Primer. University of Wyoming MA 5310

COMPUTER SCIENCE. 1. Computer Fundamentals and Applications

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

Course MS10975A Introduction to Programming. Length: 5 Days

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

DATA STRUCTURES USING C

16 Collection Classes

Objectif. Participant. Prérequis. Remarque. Programme. C# 3.0 Programming in the.net Framework. 1. Introduction to the.

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Certified PHP Developer VS-1054

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0

Subject Name: Object Oriented Programming in C++ Subject Code:

Domains and Competencies

RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE. CISY 105 Foundations of Computer Science

The D Programming Language

VISUAL C++.NET. How TO PROGRAM. H. M. Deitel Deitel & Associates, Inc. P. J. Deitel Deitel & Associates, Inc. J. P. Liperi Microsoft Corporation

Semester Review. CSC 301, Fall 2015

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

Applied Informatics C++ Coding Style Guide

Computer Programming I

OpenCL Static C++ Kernel Language Extension

Evolution of the Major Programming Languages

Formal Engineering for Industrial Software Development

6.088 Intro to C/C++ Day 4: Object-oriented programming in C++ Eunsuk Kang and Jean Yang

Java the UML Way: Integrating Object-Oriented Design and Programming

Crash Course in Java

Syllabus OBJECT ORIENTED PROGRAMMING C++

Semantic Analysis: Types and Type Checking

10CS35: Data Structures Using C

C# Cookbook. Stephen Teilhet andjay Hilyard. O'REILLY 8 Beijing Cambridge Farnham Köln Paris Sebastopol Taipei Tokyo '"J""'

Introduction to Programming System Design. CSCI 455x (4 Units)

CORBA Programming with TAOX11. The C++11 CORBA Implementation

Java Software Structures

Pemrograman Dasar. Basic Elements Of Java

Skills for Employment Investment Project (SEIP)

Object Oriented Software Design

Sources: On the Web: Slides will be available on:

#820 Computer Programming 1A

C++ Overloading, Constructors, Assignment operator

Syllabus for Computer Science. Proposed scheme for B.Sc Programme under Choice Based Credit System

Basic Programming and PC Skills: Basic Programming and PC Skills:

Object Oriented Software Design

The programming language C. sws1 1

Visual C# 2012 Programming

Computing Concepts with Java Essentials

AP Computer Science AB Syllabus 1

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

The Separation of Interface and Implementation in C++

Transcription:

Learn C++ for Game Development Bruce Sutherland Apress"

Contents About the Author About the Technical Reviewer Acknowledgments Introduction xv xvii xix xxi Chapter 1: Beginning C++ 1 Compilers 2 Programming Paradigms 2 Procedural Programming 2 Object-Oriented Programming 2 Generic Programming 3 C++ Game Programming 3 Our First C++ Program 3 Summary 4 Part 1: Procedural Programming 5 Chapter 2: Writing a Guessing Game with C++ Types 7 Dynamic Versus Static Typed Languages 7 V

vi Contents Declaring Variables 7 Defining Variables 8 Integers 8 Unsigned Integers 9 Two's Complement 9 Floating Point Numbers 10 Boolean Values 11 Enums 11 Switching from One Type to Another 13 static_cast 13 A Simple Guessing Game 14 Summary 16 Chapter 3: Creating Calculators with Operators 17 The Assignment Operator 17 Arithmetic Operators 18 The Addition Operator 18 The Subtraction Operator 18 The Multiplication and Division Operators 19 The Modulo Operator 19 A Simple Arithmetic Calculator 20 Relational Operators 22 Equality Operators 22 Greater-Than Operators 23 Less-Than Operators 23 Simple Comparison Calculators 23 Bitwise Operators 27 Hexadecimal Number Representation 27 The Binary & (AND) Operator 28 The Binary I (OR) Operator 30 The Binary A (Exclusive OR) Operator 30

The Left Shift («) Operator 31 The Right Shift (») Operator 32 Logical Operators 32 The && Operator 32 The II Operator 32 Unary Operators 33 Arithmetic Unary Operators 33 The Logical Not Unary Operator 34 The One's Complement Operator 34 Summary 35 Chapter 4: Beginning C++ Game Development with Arrays 37 The C++ Array 37 Pointers 39 Pointer Arithmetic 41 Dereferencing Pointers 41 Pointers and Arrays 41 C Style Strings in Arrays 42 Working with C Style Strings 44 Text Adventure Game 46 Summary 47 Chapter 5: Functions, the Building Blocks of C++ 49 Writing Our First Function 49 Passing Parameters to Functions 50 Return Values 51 Passing by Pointer 51 Passing by Reference 52 Structures 53 Adding Functions to Text Adventure 54 Summary 55

viii Contents Chapter 6: Making Decisions with Flow Control 57 The if Statement 57 The else and else if Statements 58 The for Loop 60 The while Loop 61 The switch Statement 62 The break and continue Keywords 64 The goto Statement 65 Adding a Game Loop to Text Adventure 66 Summary 69 Chapter 7: Organizing Projects Using Files and Namespaces 71 Source and Header Files 71 Creating Namespaces 73 Updating Text Adventure with Source Files, Header Files, and Namespaces 74 Summary 77 Part 2: Object-Oriented Programming 79 Chapter 8: Object-Oriented Programming with Classes 81 Object-Oriented Programming 81 Encapsulation 82 Constructors and Destructors 85 Method Overloading 88 Operator Overloading 90 Updating Text Adventure to Use Classes 92 Summary 95 Chapter 9: Controlling Data with Access Modifiers 97 The static Keyword 97 Creating static Local Variables 98 Using static class Member Variables 98

Using static Member Methods 101 Using static to Alter Global Scope 102 The const Keyword 103 Constant Variables 104 Constant Pointers 105 Constant Parameters 105 Constant Member Methods 105 Two More Keywords 107 The inline Keyword 107 The friend Keyword 108 Summary 109 Chapter 10: Building Games with Inheritance 111 Inheriting from a Base Class 111 Constructors and Destructors in Derived Classes 114 Method Overriding 117 Updating Text Adventure 117 Creating an Entity Class 117 Adding Inheritance to the Player Class 118 Adding Rooms 118 Moving Through Rooms 123 Summary 126 Chapter 11: Designing Game Code with Polymorphism 127 Virtual Methods 127 Downcasting and Upcasting with dynamic_cast 129 Creating Interfaces with Pure Virtual Methods... 130 Using Polymorphism in Text Adventure 131 Summary 137

x Contents Chapter 12: Copying and Assigning Data to Objects 139 Copy Constructors 139 Assignment Operators 141 Move Semantics 142 Summary 143 Part 3: The STL 145 Chapter 13: The STL String Class 147 Standard string and basic_string 147 Constructing Strings 148 Working with Strings 149 Accessing String Data Through Iterators 150 Searching Within Strings 152 Formatting Data with stringstream 153 Summary 155 Chapter 14: STL Array and Vector 157 The STL Array Template 157 The STL Vector Class 159 Sorting Arrays and Vectors 160 Summary 161 Chapter 15: STL List 163 Understanding Array and List Memory Layouts 163 Building a List Class 164 The STL List Template 166 Summary 167

Chapter 16: STL's Associative Containers 169 The STL set Container 169 The STL map Container 170 Binary Search Trees 171 Fast Data Access Using a Hash Map 173 STL unordered set and unordered map 174 Summary 176 Chapter 17: STL's Stack and Queue 177 The STL stack Container 177 The STL queue Container 178 Summary 179 Chapter 18: STL's bitset 181 Creating bitset Objects 181 Working with bitsets 182 Summary 184 Chapter 19: Using the STL in Text Adventure 185 Using STL array to Store Room Pointers 185 Using a vector and a map to Store Options 186 Adding Gameplay to Text Adventure 189 Summary 198 Part 4: Generic Programming 199 Chapter 20: Template Programming 201 Compile Versus Runtime Time Compilation 201 const Versus constexpr 203 assert Versus static assert 204 Summary 204

xii Contents Chapter 21: Practical Template Programming 205 Creating Singleton Classes with Templates 205 Implementing the EventManager Class 208 The EventHandler Interface 208 The Event Class 208 The EventManager Implementation 210 Calculating SDBM Hash Values Using a Template Metaprogram 216 Using an Event to Quit the Game 218 Summary 221 Part 5: C++ Game Programming 223 Chapter 22: Managing Memory for Game Developers 225 Static Memory 225 The C++ Stack Memory Model 226 Working with Heap Memory 228 Writing a Basic Single Threaded Memory Allocator 231 Summary 238 Chapter 23: Useful Design Patterns for Game Development 239 Using the Factory Pattern in Games 239 Decoupling with the Observer Pattern 244 Easily Adding New Functionality with the Visitor Pattern 249 Summary 251 Chapter 24: Using File 10 to Save and Load Games 253 What Is Serialization? 253 The Serialization Manager 254 Saving and Loading Text Adventure 258 Summary 265

Chapter 25: Speeding Up Games with Concurrent Programming 267 Running Text Adventure in Its Own Thread 267 Sharing Data Between Threads Using Mutexes 269 Using Futures and Promises 272 Summary 274 Chapter 26: Supporting Multiple Platforms in C++ 277 Ensuring Types Are the Same Size on Multiple Platforms 277 Using the Preprocessor to Determine Target Platform 279 Summary 283 Chapter 27: Wrapping Up 285 An Overview of Text Adventure 285 Summary 289 Index 291