Video Game Development: Data StructuresA. Babadi 1 of 21
In The Name Of God
Video Game Development
Amin Babadi
Department of Electrical and Computer Engineering
Isfahan University of Technology
Spring 2015
Data Structures
Video Game Development: Data StructuresA. Babadi 2 of 21
Outline
 Evolution of programming languages
 Object-oriented programming (OOP)
 Common data structures
 The standard template library (STL)
Video Game Development: Data StructuresA. Babadi 3 of 21
Evolution of Programming Languages
Types Structures Classes
Evolution of programming languages.
Video Game Development: Data StructuresA. Babadi 4 of 21
1. Types
 Using the first programming languages, you could operate
integers and floating-point numbers, but that was basically it!
float x, y, z;
 In fact, many hardware platforms of yesteryear didn't even
support floating-point values!
 What about more complex data types?
Video Game Development: Data StructuresA. Babadi 5 of 21
2. Structures
 Years later, the family of structured programming languages
(C, Pascal, and so on) surfaced.
typedef struct
{
float x,y,z;
} point3D;
 Even better, types could be built incrementally!
 So what was the problem?
Video Game Development: Data StructuresA. Babadi 6 of 21
3. Classes
 Each type was allowed to include the source code for its own
access operations, so the type became a self-sufficient code
and data module. These modules were called classes.
class point3D
{
private:
float x,y,z;
public:
point(float , float, float);
~point();
point operator+(point);
point operator-(point);
};
Video Game Development: Data StructuresA. Babadi 7 of 21
Object-Oriented Programming (OOP)
 Object-oriented programming (OOP) pushed the maximum
program size to unknown boundaries.
o Programs several million lines of code in size are not uncommon these
days.
 Classes have basically become "black boxes.“
o You can share, recycle, and use with no real knowledge about their
internals.
Video Game Development: Data StructuresA. Babadi 8 of 21
Object-Oriented Programming (OOP)
 OOP benefited developers in two ways:
o It allowed them to build more structured programs that are easier to
maintain, and
o It improved team-based coding where classes could be exchanged
and shared between team members.
Video Game Development: Data StructuresA. Babadi 9 of 21
Data Structures
 For now, we will focus on reviewing those data structures that
are frequently used in game development.
1. Static arrays
2. Linked lists
3. Queues
4. Stacks
5. Tables
6. Trees
7. Priority queues
8. Graphs
Video Game Development: Data StructuresA. Babadi 10 of 21
1. Static Arrays
 Games rarely need to work with single instances of data.
o Triangles in a mesh, enemies in a game level, and so forth.
 The simplest structure to fulfill this task is the static array.
o A list of elements that will not change during the program's life cycle.
Video Game Development: Data StructuresA. Babadi 11 of 21
2. Linked Lists
 A linked list is an extension of the static array.
 The sequence can grow or shrink dynamically.
Video Game Development: Data StructuresA. Babadi 12 of 21
2. Linked Lists
Removing an element from a linked list.
Adding an element to a linked list.
Video Game Development: Data StructuresA. Babadi 13 of 21
3. Queues
 A queue is a variant of the linked list.
 A software queue resembles a real-world queue, such as a
supermarket waiting line.
Representation of a Queue with FIFO (First In
First Out) property
Video Game Development: Data StructuresA. Babadi 14 of 21
4. Stacks
 A stack is another variant of the linked list scheme with a last
in, first out (LIFO) behavior.
Simple representation of a stack.
Video Game Development: Data StructuresA. Babadi 15 of 21
5. Tables
 Tables are sequential structures that associate data elements
with an identifying key.
A small phone book as a hash table.
Video Game Development: Data StructuresA. Babadi 16 of 21
6. Trees
 A tree is a data structure consisting of a series of nodes.
A simple unordered tree.
Video Game Development: Data StructuresA. Babadi 17 of 21
7. Priority Queues
 A priority queue is an extension of the queue model that
incorporates a sense of priority.
A simple priority queue.
Video Game Development: Data StructuresA. Babadi 18 of 21
8. Graphs
 Anything that involves a group of entities and relationships
between them can effectively be represented as a graph!
A labeled graph of 6 vertices and 7 edges.
Video Game Development: Data StructuresA. Babadi 19 of 21
The Standard Template Library (STL)
 Coding these structures each time you need them is prone to
introduce errors, and thus is a risky process.
 Two solutions have been proposed:
1. Developing in-house code bases that encapsulate many fundamental
and sophisticated classes.
2. Using a ready, standard set of classes that provide good performance
and are rock solid.
 The second solution is precisely what the Standard Template
Library (STL) is all about.
Video Game Development: Data StructuresA. Babadi 20 of 21
The Standard Template Library (STL)
 The STL was introduced in the 1990s as a collection of classes
that made OOP easier.
 It is a C++ mechanism that allows a class to be parameterized.
 Another advantage of the STL is coherence.
 More information about STL is available at
http://www.cplusplus.com/.
Video Game Development: Data StructuresA. Babadi 21 of 21
References
 Sanchez-Crespo’s textbook,
 Wikipedia, and
 Some other sources on the Internet.

07. Data Structures

  • 1.
    Video Game Development:Data StructuresA. Babadi 1 of 21 In The Name Of God Video Game Development Amin Babadi Department of Electrical and Computer Engineering Isfahan University of Technology Spring 2015 Data Structures
  • 2.
    Video Game Development:Data StructuresA. Babadi 2 of 21 Outline  Evolution of programming languages  Object-oriented programming (OOP)  Common data structures  The standard template library (STL)
  • 3.
    Video Game Development:Data StructuresA. Babadi 3 of 21 Evolution of Programming Languages Types Structures Classes Evolution of programming languages.
  • 4.
    Video Game Development:Data StructuresA. Babadi 4 of 21 1. Types  Using the first programming languages, you could operate integers and floating-point numbers, but that was basically it! float x, y, z;  In fact, many hardware platforms of yesteryear didn't even support floating-point values!  What about more complex data types?
  • 5.
    Video Game Development:Data StructuresA. Babadi 5 of 21 2. Structures  Years later, the family of structured programming languages (C, Pascal, and so on) surfaced. typedef struct { float x,y,z; } point3D;  Even better, types could be built incrementally!  So what was the problem?
  • 6.
    Video Game Development:Data StructuresA. Babadi 6 of 21 3. Classes  Each type was allowed to include the source code for its own access operations, so the type became a self-sufficient code and data module. These modules were called classes. class point3D { private: float x,y,z; public: point(float , float, float); ~point(); point operator+(point); point operator-(point); };
  • 7.
    Video Game Development:Data StructuresA. Babadi 7 of 21 Object-Oriented Programming (OOP)  Object-oriented programming (OOP) pushed the maximum program size to unknown boundaries. o Programs several million lines of code in size are not uncommon these days.  Classes have basically become "black boxes.“ o You can share, recycle, and use with no real knowledge about their internals.
  • 8.
    Video Game Development:Data StructuresA. Babadi 8 of 21 Object-Oriented Programming (OOP)  OOP benefited developers in two ways: o It allowed them to build more structured programs that are easier to maintain, and o It improved team-based coding where classes could be exchanged and shared between team members.
  • 9.
    Video Game Development:Data StructuresA. Babadi 9 of 21 Data Structures  For now, we will focus on reviewing those data structures that are frequently used in game development. 1. Static arrays 2. Linked lists 3. Queues 4. Stacks 5. Tables 6. Trees 7. Priority queues 8. Graphs
  • 10.
    Video Game Development:Data StructuresA. Babadi 10 of 21 1. Static Arrays  Games rarely need to work with single instances of data. o Triangles in a mesh, enemies in a game level, and so forth.  The simplest structure to fulfill this task is the static array. o A list of elements that will not change during the program's life cycle.
  • 11.
    Video Game Development:Data StructuresA. Babadi 11 of 21 2. Linked Lists  A linked list is an extension of the static array.  The sequence can grow or shrink dynamically.
  • 12.
    Video Game Development:Data StructuresA. Babadi 12 of 21 2. Linked Lists Removing an element from a linked list. Adding an element to a linked list.
  • 13.
    Video Game Development:Data StructuresA. Babadi 13 of 21 3. Queues  A queue is a variant of the linked list.  A software queue resembles a real-world queue, such as a supermarket waiting line. Representation of a Queue with FIFO (First In First Out) property
  • 14.
    Video Game Development:Data StructuresA. Babadi 14 of 21 4. Stacks  A stack is another variant of the linked list scheme with a last in, first out (LIFO) behavior. Simple representation of a stack.
  • 15.
    Video Game Development:Data StructuresA. Babadi 15 of 21 5. Tables  Tables are sequential structures that associate data elements with an identifying key. A small phone book as a hash table.
  • 16.
    Video Game Development:Data StructuresA. Babadi 16 of 21 6. Trees  A tree is a data structure consisting of a series of nodes. A simple unordered tree.
  • 17.
    Video Game Development:Data StructuresA. Babadi 17 of 21 7. Priority Queues  A priority queue is an extension of the queue model that incorporates a sense of priority. A simple priority queue.
  • 18.
    Video Game Development:Data StructuresA. Babadi 18 of 21 8. Graphs  Anything that involves a group of entities and relationships between them can effectively be represented as a graph! A labeled graph of 6 vertices and 7 edges.
  • 19.
    Video Game Development:Data StructuresA. Babadi 19 of 21 The Standard Template Library (STL)  Coding these structures each time you need them is prone to introduce errors, and thus is a risky process.  Two solutions have been proposed: 1. Developing in-house code bases that encapsulate many fundamental and sophisticated classes. 2. Using a ready, standard set of classes that provide good performance and are rock solid.  The second solution is precisely what the Standard Template Library (STL) is all about.
  • 20.
    Video Game Development:Data StructuresA. Babadi 20 of 21 The Standard Template Library (STL)  The STL was introduced in the 1990s as a collection of classes that made OOP easier.  It is a C++ mechanism that allows a class to be parameterized.  Another advantage of the STL is coherence.  More information about STL is available at http://www.cplusplus.com/.
  • 21.
    Video Game Development:Data StructuresA. Babadi 21 of 21 References  Sanchez-Crespo’s textbook,  Wikipedia, and  Some other sources on the Internet.