Book Image

Beginning C++ Game Programming

Book Image

Beginning C++ Game Programming

Overview of this book

This book is all about offering you a fun introduction to the world of game programming, C++, and the OpenGL-powered SFML using three fun, fully-playable games. These games are an addictive frantic two-button tapper, a multi-level zombie survival shooter, and a split-screen multiplayer puzzle-platformer. We will start with the very basics of programming, such as variables, loops, and conditions and you will become more skillful with each game as you move through the key C++ topics, such as OOP (Object-Orientated Programming), C++ pointers, and an introduction to the Standard Template Library. While building these games, you will also learn exciting game programming concepts like particle effects, directional sound (spatialization), OpenGL programmable Shaders, spawning thousands of objects, and more.
Table of Contents (24 chapters)
Beginning C++ Game Programming
Credits
About the Author
About the Reviewer
www.PacktPub.com
Dedication
Preface
17
Before you go...

C++ References


When we pass values to a function or return values from a function, that is exactly what we are doing. Passing/returning by value. What happens is that a copy of the value held by the variable is made, and sent into the function where it is used.

The significance of this is two-fold:

  • If we want the function to make a permanent change to a variable, this system is no good to us.

  • When a copy is made, to pass in as an argument or return from the function, processing power and memory are consumed. For a simple int or even perhaps a sprite, this is fairly insignificant. However, for a complex object, perhaps an entire game world (or background), the copying process will seriously affect our game's performance.

References are the solution to these two problems. A reference is a special type of variable. A reference refers to another variable. An example will be useful:

int numZombies = 100; 
int& rNumZombies = numZombies; 

In the code above we declare and initialize a regular...